Redux_Functions

Redux Functions Class Class of useful functions that can/should be shared among all Redux files.

Defined (1)

The class is defined in the following location(s).

/inc/ReduxFramework/ReduxCore/inc/class.redux_functions.php  
  1. class Redux_Functions { 
  2.  
  3. static public $_parent; 
  4.  
  5. public static function isMin() { 
  6. $min = ''; 
  7.  
  8. if ( false == self::$_parent->args['dev_mode'] ) { 
  9. $min = '.min'; 
  10.  
  11. return $min; 
  12.  
  13. /** 
  14. * Parse CSS from output/compiler array 
  15. * @since 3.2.8 
  16. * @access private 
  17. * @return $css CSS string 
  18. */ 
  19. public static function parseCSS( $cssArray = array(), $style = '', $value = '' ) { 
  20.  
  21. // Something wrong happened 
  22. if ( count( $cssArray ) == 0 ) { 
  23. return; 
  24. } else { //if ( count( $cssArray ) >= 1 ) { 
  25. $css = ''; 
  26.  
  27. foreach ( $cssArray as $element => $selector ) { 
  28.  
  29. // The old way 
  30. if ( $element === 0 ) { 
  31. $css = self::theOldWay( $cssArray, $style ); 
  32.  
  33. return $css; 
  34.  
  35. // New way continued 
  36. $cssStyle = $element . ':' . $value . ';'; 
  37.  
  38. $css .= $selector . '{' . $cssStyle . '}'; 
  39.  
  40. return $css; 
  41.  
  42. private static function theOldWay( $cssArray, $style ) { 
  43. $keys = implode( ", ", $cssArray ); 
  44. $css = $keys . "{" . $style . '}'; 
  45.  
  46. return $css; 
  47.  
  48. /** 
  49. * initWpFilesystem - Initialized the Wordpress filesystem, if it already isn't. 
  50. * @since 3.2.3 
  51. * @access public 
  52. * @return void 
  53. */ 
  54. public static function initWpFilesystem() { 
  55. global $wp_filesystem; 
  56.  
  57. // Initialize the Wordpress filesystem, no more using file_put_contents function 
  58. if ( empty( $wp_filesystem ) ) { 
  59. require_once( ABSPATH . '/wp-admin/includes/file.php' ); 
  60. WP_Filesystem(); 
  61.  
  62. /** 
  63. * modRewriteCheck - Check for the installation of apache mod_rewrite 
  64. * @since 3.2.3 
  65. * @access public 
  66. * @return void 
  67. */ 
  68. public static function modRewriteCheck() { 
  69. if ( function_exists( 'apache_get_modules' ) ) { 
  70. if ( ! in_array( 'mod_rewrite', apache_get_modules() ) ) { 
  71. self::$_parent->admin_notices[] = array( 
  72. 'type' => 'error',  
  73. 'msg' => '<strong><center>The Apache mod_rewrite module is not enabled on your server.</center></strong> 
  74. <br/> 
  75. Both Wordpress and Redux require the enabling of the Apache mod_rewrite module to function properly. Please contact whomever provides support for your server and ask them to enable the mod_rewrite module',  
  76. 'id' => 'mod_rewrite_notice_',  
  77. 'dismiss' => false 
  78. ); 
  79.  
  80. /** 
  81. * verFromGit - Retrives latest Redux version from GIT 
  82. * @since 3.2.0 
  83. * @access private 
  84. * @return string $ver 
  85. */ 
  86. private static function verFromGit() { 
  87. // Get the raw framework.php from github 
  88. $gitpage = wp_remote_get( 
  89. 'https://raw.github.com/ReduxFramework/redux-framework/master/ReduxCore/framework.php', array( 
  90. 'headers' => array( 
  91. 'Accept-Encoding' => '' 
  92. ),  
  93. 'sslverify' => true,  
  94. 'timeout' => 300 
  95. ) ); 
  96.  
  97. // Is the response code the corect one? 
  98. if ( ! is_wp_error( $gitpage ) ) { 
  99. if ( isset( $gitpage['body'] ) ) { 
  100. // Get the page text. 
  101. $body = $gitpage['body']; 
  102.  
  103. // Find version line in framework.php 
  104. $needle = 'public static $_version ='; 
  105. $pos = strpos( $body, $needle ); 
  106.  
  107. // If it's there, continue. We don't want errors if $pos = 0. 
  108. if ( $pos > 0 ) { 
  109.  
  110. // Look for the semi-colon at the end of the version line 
  111. $semi = strpos( $body, ";", $pos ); 
  112.  
  113. // Error avoidance. If the semi-colon is there, continue. 
  114. if ( $semi > 0 ) { 
  115.  
  116. // Extract the version line 
  117. $text = substr( $body, $pos, ( $semi - $pos ) ); 
  118.  
  119. // Find the first quote around the veersion number. 
  120. $quote = strpos( $body, "'", $pos ); 
  121.  
  122. // Extract the version number 
  123. $ver = substr( $body, $quote, ( $semi - $quote ) ); 
  124.  
  125. // Strip off quotes. 
  126. $ver = str_replace( "'", '', $ver ); 
  127.  
  128. return $ver; 
  129.  
  130. /** 
  131. * updateCheck - Checks for updates to Redux Framework 
  132. * @since 3.2.0 
  133. * @access public 
  134. * @param string $curVer Current version of Redux Framework 
  135. * @return void - Admin notice is diaplyed if new version is found 
  136. */ 
  137. public static function updateCheck( $curVer ) { 
  138.  
  139. // If no cookie, check for new ver 
  140. if ( ! isset( $_COOKIE['redux_update_check'] ) ) { // || 1 == strcmp($_COOKIE['redux_update_check'], self::$_version)) { 
  141. // actual ver number from git repo 
  142. $ver = self::verFromGit(); 
  143.  
  144. // hour long cookie. 
  145. setcookie( "redux_update_check", $ver, time() + 3600, '/' ); 
  146. } else { 
  147.  
  148. // saved value from cookie. If it's different from current ver 
  149. // we can still show the update notice. 
  150. $ver = $_COOKIE['redux_update_check']; 
  151.  
  152. // Set up admin notice on new version 
  153. //if ( 1 == strcmp( $ver, $curVer ) ) { 
  154. if ( version_compare( $ver, $curVer, '>' ) ) { 
  155. self::$_parent->admin_notices[] = array( 
  156. 'type' => 'updated',  
  157. 'msg' => '<strong>A new build of Redux is now available!</strong><br/><br/>Your version: <strong>' . $curVer . '</strong><br/>New version: <strong><span style="color: red;">' . $ver . '</span></strong><br/><br/><em>If you are not a developer, your theme/plugin author shipped with <code>dev_mode</code> on. Contact them to fix it, but in the meantime you can use our <a href="' . 'https://' . 'wordpress.org/plugins/redux-developer-mode-disabler/" target="_blank">dev_mode disabler</a>.</em><br /><br /><a href="' . 'https://' . 'github.com/ReduxFramework/redux-framework">Get it now</a>  |',  
  158. 'id' => 'dev_notice_' . $ver,  
  159. 'dismiss' => true,  
  160. ); 
  161.  
  162. /** 
  163. * adminNotices - Evaluates user dismiss option for displaying admin notices 
  164. * @since 3.2.0 
  165. * @access public 
  166. * @return void 
  167. */ 
  168. public static function adminNotices() { 
  169. global $current_user, $pagenow; 
  170.  
  171. // Check for an active admin notice array 
  172. if ( ! empty( self::$_parent->admin_notices ) ) { 
  173.  
  174. // Enum admin notices 
  175. foreach ( self::$_parent->admin_notices as $notice ) { 
  176. if ( true == $notice['dismiss'] ) { 
  177.  
  178. // Get user ID 
  179. $userid = $current_user->ID; 
  180.  
  181. if ( ! get_user_meta( $userid, 'ignore_' . $notice['id'] ) ) { 
  182.  
  183. // Check if we are on admin.php. If we are, we have 
  184. // to get the current page slug and tab, so we can 
  185. // feed it back to Wordpress. Why> admin.php cannot 
  186. // be accessed without the page parameter. We add the 
  187. // tab to return the user to the last panel they were 
  188. // on. 
  189. $pageName = ''; 
  190. $curTab = ''; 
  191. if ( $pagenow == 'admin.php' || $pagenow == 'themes.php' ) { 
  192.  
  193. // Get the current page. To avoid errors, we'll set 
  194. // the redux page slug if the GET is empty. 
  195. $pageName = empty( $_GET['page'] ) ? '&page=' . self::$_parent->args['page_slug'] : '&page=' . $_GET['page']; 
  196.  
  197. // Ditto for the current tab. 
  198. $curTab = empty( $_GET['tab'] ) ? '&tab=0' : '&tab=' . $_GET['tab']; 
  199.  
  200. // Print the notice with the dismiss link 
  201. echo '<div class="' . $notice['type'] . '"><p>' . $notice['msg'] . '  <a href="?dismiss=true&id=' . $notice['id'] . $pageName . $curTab . '">' . __( 'Dismiss', 'redux-framework' ) . '</a>.</p></div>'; 
  202. } else { 
  203.  
  204. // Standard notice 
  205. echo '<div class="' . $notice['type'] . '"><p>' . $notice['msg'] . '</a>.</p></div>'; 
  206.  
  207. // Clear the admin notice array 
  208. self::$_parent->admin_notices = array(); 
  209.  
  210. /** 
  211. * dismissAdminNotice - Updates user meta to store dismiss notice preference 
  212. * @since 3.2.0 
  213. * @access public 
  214. * @return void 
  215. */ 
  216. public static function dismissAdminNotice() { 
  217. global $current_user; 
  218.  
  219. // Verify the dismiss and id parameters are present. 
  220. if ( isset( $_GET['dismiss'] ) && isset( $_GET['id'] ) ) { 
  221. if ( 'true' == $_GET['dismiss'] || 'false' == $_GET['dismiss'] ) { 
  222.  
  223. // Get the user id 
  224. $userid = $current_user->ID; 
  225.  
  226. // Get the notice id 
  227. $id = $_GET['id']; 
  228. $val = $_GET['dismiss']; 
  229.  
  230. // Add the dismiss request to the user meta. 
  231. update_user_meta( $userid, 'ignore_' . $id, $val );