MonsterInsights_Notice_Admin

The Google Analytics for WordPress by MonsterInsights MonsterInsights Notice Admin class.

Defined (1)

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

/includes/admin/notice.php  
  1. final class MonsterInsights_Notice_Admin { 
  2.  
  3. /** 
  4. * Holds all dismissed notices 
  5. * @access public 
  6. * @since 6.0.0 
  7. * @var array $notices Array of dismissed notices. 
  8. */ 
  9. public $notices; 
  10.  
  11. /** 
  12. * Primary class constructor. 
  13. * @access public 
  14. * @since 6.0.0 
  15. */ 
  16. public function __construct() { 
  17.  
  18. // Populate $notices 
  19. $this->notices = get_option( 'monsterinsights_notices' ); 
  20. if ( ! is_array( $this->notices ) ) { 
  21. $this->notices = array(); 
  22.  
  23.  
  24. /** 
  25. * Checks if a given notice has been dismissed or not 
  26. * @access public 
  27. * @since 6.0.0 
  28. *  
  29. * @param string $notice Programmatic Notice Name 
  30. * @return bool Notice Dismissed 
  31. */ 
  32.  
  33. public function is_dismissed( $notice ) { 
  34. if ( ! isset( $this->notices[ $notice ] ) ) { 
  35. return false; 
  36. return true; 
  37.  
  38.  
  39. /** 
  40. * Marks the given notice as dismissed 
  41. * @access public 
  42. * @since 6.0.0 
  43. *  
  44. * @param string $notice Programmatic Notice Name 
  45. * @return null 
  46. */ 
  47. public function dismiss( $notice ) { 
  48. $this->notices[ $notice ] = true; 
  49. update_option( 'monsterinsights_notices', $this->notices ); 
  50.  
  51.  
  52.  
  53. /** 
  54. * Marks a notice as not dismissed 
  55. * @access public 
  56. * @since 6.0.0 
  57. * @param string $notice Programmatic Notice Name 
  58. * @return null 
  59. */ 
  60. public function undismiss( $notice ) { 
  61. unset( $this->notices[ $notice ] ); 
  62. update_option( 'monsterinsights_notices', $this->notices ); 
  63.  
  64.  
  65. /** 
  66. * Displays an inline notice with some MonsterInsights styling. 
  67. * @access public 
  68. * @since 6.0.0 
  69. * @param string $notice Programmatic Notice Name 
  70. * @param string $title Title 
  71. * @param string $message Message 
  72. * @param string $type Message Type (updated|warning|error) - green, yellow/orange and red respectively. 
  73. * @param string $button_text Button Text (optional) 
  74. * @param string $button_url Button URL (optional) 
  75. * @param bool $is_dismissible User can Dismiss Message (default: false) 
  76. */  
  77. public function display_inline_notice( $name, $title, $message, $type = 'success', $is_dismissible = false, $args = array() ) { 
  78. /** Available/Planned $args options 
  79. * $args = array( 
  80. * 'primary' => array( 
  81. * 'text' => '',  
  82. * 'url' => '',  
  83. * 'target' => '',  
  84. * 'class' => 'button button-primary',  
  85. * ),  
  86. * 'secondary' => array( 
  87. * 'text' => '',  
  88. * 'url' => '',  
  89. * 'target' => '',  
  90. * 'class' => 'button button-secondary',  
  91. * ),  
  92. * 'skip_message_escape' => true // note: This param is for internal use only. Do not use as a developer. 
  93. * ); 
  94. */ 
  95.  
  96.  
  97. // Check if the notice is dismissible, and if so has been dismissed. 
  98. if ( $is_dismissible && $this->is_dismissed( $name ) ) { 
  99. // Nothing to show here, return! 
  100. return ''; 
  101.  
  102. $dismissible = ( $is_dismissible ) ? ' is-dismissible': ''; 
  103.  
  104. // Display inline notice 
  105. ob_start(); 
  106. ?> 
  107. <div class="monsterinsights-notice <?php echo 'monsterinsights-' . esc_attr( $type ) . '-notice' . $dismissible; ?>" data-notice="<?php echo esc_attr( $name ); ?>"> 
  108. <div class="monsterinsights-notice-icon <?php echo 'monsterinsights-' . esc_attr( $type ) . '-notice-icon'?>"> 
  109. <?php 
  110. if ( $type === 'success' ) { 
  111. echo '<i class="fa fa-check" aria-hidden="true"></i>'; 
  112. } else if ( $type === 'alert' ) { 
  113. echo '<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>'; 
  114. } else if ( $type === 'info' ) { 
  115. echo '<i class="fa fa-info" aria-hidden="true"></i>'; 
  116. } else { 
  117. echo'<i class="fa fa-times" aria-hidden="true"></i>'; 
  118. ?> 
  119. </div> 
  120. <div class="monsterinsights-notice-text <?php echo 'monsterinsights-' . esc_attr( $type ) . '-notice-text'?>"> 
  121. <?php 
  122. // Title 
  123. if ( ! empty ( $title ) ) { 
  124. ?> 
  125. <p class="monsterinsights-notice-title"><?php echo esc_html( $title ); ?></p> 
  126. <?php 
  127.  
  128. // Message 
  129. if ( ! empty( $message ) ) { 
  130. if ( empty( $args['skip_message_escape'] ) ) { 
  131. ?> 
  132. <p class="monsterinsights-notice-message"><?php echo esc_html( $message ); ?></p> 
  133. <?php 
  134. } else { 
  135. ?> 
  136. <p class="monsterinsights-notice-message"><?php echo $message; ?></p> 
  137. <?php 
  138.  
  139. // Primary Button 
  140. if ( ! empty( $args['primary']['text'] ) ) { 
  141.  
  142. $text = ''; 
  143. if ( ! empty( $args['primary']['text'] ) ) { 
  144. $text = $args['primary']['text']; 
  145.  
  146. $url = '#'; 
  147. if ( ! empty( $args['primary']['url'] ) ) { 
  148. $url = $args['primary']['url']; 
  149.  
  150. $target = ''; 
  151. if ( ! empty( $args['primary']['target'] ) && $args['primary']['target'] === 'blank') { 
  152. $target = ' target="_blank" rel="noopener noreferrer"'; 
  153.  
  154. $class = 'button button-primary'; 
  155. if ( ! empty( $args['primary']['class'] ) ) { 
  156. $class = ' class="'. $args['primary']['class'] . '"'; 
  157. ?> 
  158. <a href="<?php echo esc_attr( $url ); ?>"<?php echo $target; ?><?php echo $class;?>><?php echo esc_html( $text ); ?></a> 
  159. <?php 
  160.  
  161. // Secondary Button 
  162. if ( ! empty( $args['secondary']['text'] ) ) { 
  163.  
  164. $text = ''; 
  165. if ( ! empty( $args['secondary']['text'] ) ) { 
  166. $text = $args['secondary']['text']; 
  167.  
  168. $url = '#'; 
  169. if ( ! empty( $args['secondary']['url'] ) ) { 
  170. $url = $args['secondary']['url']; 
  171. }  
  172.  
  173. $target = ''; 
  174. if ( ! empty( $args['secondary']['target'] ) && $args['secondary']['target'] === 'blank') { 
  175. $target = ' target="_blank" rel="noopener noreferrer"'; 
  176.  
  177. $class = 'button button-secondary'; 
  178. if ( ! empty( $args['secondary']['class'] ) ) { 
  179. $class = ' class="'. $args['secondary']['class'] . '"'; 
  180. ?> 
  181. <a href="<?php echo esc_attr( $url ); ?>"<?php echo $target; ?><?php echo $class;?>><?php echo esc_html( $text ); ?></a> 
  182. <?php 
  183.  
  184. // Dismiss Button 
  185. if ( $is_dismissible ) { 
  186. ?> 
  187. <button type="button" class="notice-dismiss<?php echo $dismissible; ?>"> 
  188. <span class="screen-reader-text"> 
  189. <?php esc_html_e( 'Dismiss this notice', 'google-analytics-for-wordpress' ); ?> 
  190. </span> 
  191. </button> 
  192. <?php 
  193. ?> 
  194. </div> 
  195. </div> 
  196. <?php 
  197. return ob_get_clean();