Redux_Admin_Notices

Redux API Class Simple API for Redux Framework.

Defined (1)

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

/admin/core/lib/ReduxFramework/ReduxCore/inc/class.redux_admin_notices.php  
  1. class Redux_Admin_Notices { 
  2.  
  3. static public $_parent; 
  4.  
  5. public static function load() { 
  6. add_action( 'wp_ajax_redux_hide_admin_notice', array( 
  7. 'Redux_Admin_Notices',  
  8. 'dismissAdminNoticeAJAX' 
  9. ) ); 
  10.  
  11. /** 
  12. * adminNotices - Evaluates user dismiss option for displaying admin notices 
  13. * @since 3.2.0 
  14. * @access public 
  15. * @return void 
  16. */ 
  17. public static function adminNotices( $notices = array() ) { 
  18. global $current_user, $pagenow; 
  19.  
  20. // Check for an active admin notice array 
  21. if ( ! empty( $notices ) ) { 
  22.  
  23. // Enum admin notices 
  24. foreach ( $notices as $notice ) { 
  25.  
  26. $add_style = ''; 
  27. if ( strpos( $notice['type'], 'redux-message' ) != false ) { 
  28. $add_style = 'style="border-left: 4px solid ' . esc_attr( $notice['color'] ) . '!important;"'; 
  29.  
  30. if ( true == $notice['dismiss'] ) { 
  31.  
  32. // Get user ID 
  33. $userid = $current_user->ID; 
  34.  
  35. if ( ! get_user_meta( $userid, 'ignore_' . $notice['id'] ) ) { 
  36.  
  37. // Check if we are on admin.php. If we are, we have 
  38. // to get the current page slug and tab, so we can 
  39. // feed it back to Wordpress. Why> admin.php cannot 
  40. // be accessed without the page parameter. We add the 
  41. // tab to return the user to the last panel they were 
  42. // on. 
  43. $pageName = ''; 
  44. $curTab = ''; 
  45. if ( $pagenow == 'admin.php' || $pagenow == 'themes.php' ) { 
  46.  
  47. // Get the current page. To avoid errors, we'll set 
  48. // the redux page slug if the GET is empty. 
  49. $pageName = empty( $_GET['page'] ) ? '&page=' . self::$_parent->args['page_slug'] : '&page=' . esc_attr( $_GET['page'] ); 
  50.  
  51. // Ditto for the current tab. 
  52. $curTab = empty( $_GET['tab'] ) ? '&tab=0' : '&tab=' . esc_attr( $_GET['tab'] ); 
  53.  
  54. global $wp_version; 
  55. // Print the notice with the dismiss link 
  56. if ( version_compare( $wp_version, '4.2', '>' ) ) { 
  57. $output = ""; 
  58. $css_id = esc_attr( $notice['id'] ) . $pageName . $curTab; 
  59. $css_class = esc_attr( $notice['type'] ) . ' redux-notice notice is-dismissible redux-notice'; 
  60. $output .= "<div {$add_style} id='$css_id' class='$css_class'> \n"; 
  61. $nonce = wp_create_nonce( $notice['id'] . $userid . 'nonce' ); 
  62. $output .= "<input type='hidden' class='dismiss_data' id='" . esc_attr( $notice['id'] ) . $pageName . $curTab . "' value='{$nonce}'> \n"; 
  63. $output .= '<p>' . wp_kses_post( $notice['msg'] ) . '</p>'; 
  64. $output .= "</div> \n"; 
  65. echo $output; 
  66. } else { 
  67. echo '<div ' . $add_style . ' class="' . esc_attr( $notice['type'] ) . ' notice is-dismissable"><p>' . wp_kses_post( $notice['msg'] ) . '  <a href="?dismiss=true&id=' . esc_attr( $notice['id'] ) . $pageName . $curTab . '">' . esc_html__( 'Dismiss', 'redux-framework' ) . '</a>.</p></div>'; 
  68. } else { 
  69. // Standard notice 
  70. echo '<div ' . $add_style . ' class="' . esc_attr( $notice['type'] ) . ' notice"><p>' . wp_kses_post( $notice['msg'] ) . '</a>.</p></div>'; 
  71. ?> 
  72. <script> 
  73. jQuery( document ).ready( 
  74. function( $ ) { 
  75. $( 'body' ).on( 
  76. 'click', '.redux-notice.is-dismissible .notice-dismiss', function( event ) { 
  77. var $data = $( this ).parent().find( '.dismiss_data' ); 
  78. $.post( 
  79. ajaxurl, { 
  80. action: 'redux_hide_admin_notice',  
  81. id: $data.attr( 'id' ),  
  82. nonce: $data.val() 
  83. ); 
  84. ); 
  85. ); 
  86. </script> 
  87. <?php 
  88. /** 
  89.   
  90. */ 
  91.  
  92.  
  93.  
  94. // Clear the admin notice array 
  95. self::$_parent->admin_notices = array(); 
  96.  
  97. /** 
  98. * dismissAdminNotice - Updates user meta to store dismiss notice preference 
  99. * @since 3.2.0 
  100. * @access public 
  101. * @return void 
  102. */ 
  103. public static function dismissAdminNotice() { 
  104. global $current_user; 
  105.  
  106. // Verify the dismiss and id parameters are present. 
  107. if ( isset( $_GET['dismiss'] ) && isset( $_GET['id'] ) ) { 
  108. if ( 'true' == $_GET['dismiss'] || 'false' == $_GET['dismiss'] ) { 
  109.  
  110. // Get the user id 
  111. $userid = $current_user->ID; 
  112.  
  113. // Get the notice id 
  114. $id = esc_attr( $_GET['id'] ); 
  115. $val = esc_attr( $_GET['dismiss'] ); 
  116.  
  117. // Add the dismiss request to the user meta. 
  118. update_user_meta( $userid, 'ignore_' . $id, $val ); 
  119.  
  120. /** 
  121. * dismissAdminNotice - Updates user meta to store dismiss notice preference 
  122. * @since 3.2.0 
  123. * @access public 
  124. * @return void 
  125. */ 
  126. public static function dismissAdminNoticeAJAX() { 
  127. global $current_user; 
  128.  
  129. // Get the notice id 
  130. $id = explode( '&', $_POST['id'] ); 
  131. $id = $id[0]; 
  132. // Get the user id 
  133. $userid = $current_user->ID; 
  134.  
  135. if ( ! wp_verify_nonce( $_POST['nonce'], $id . $userid . 'nonce' ) ) { 
  136. die( 0 ); 
  137. } else { 
  138. // Add the dismiss request to the user meta. 
  139. update_user_meta( $userid, 'ignore_' . $id, true );