options = &$polylang->options; add_action( 'admin_init', array( $this, 'hide_notice' ) ); add_action( 'admin_notices', array( $this, 'display_notices' ) ); } /** * Add a custom notice * * @since 2.3.9 * * @param string $name Notice name * @param string $html Content of the notice */ public static function add_notice( $name, $html ) { self::$notices[ $name ] = $html; } /** * Get custom notices * * @since 2.3.9 * * @return array */ public static function get_notices() { return self::$notices; } /** * Has a notice been dismissed? * * @since 2.3.9 * * @param string $notice Notice name * @return bool */ public static function is_dismissed( $notice ) { $dismissed = get_user_meta( get_current_user_id(), 'pll_dismissed_notices', true ); return is_array( $dismissed ) && in_array( $notice, $dismissed ); } /** * Should we display notices on this screen? * * @since 2.3.9 * * @return bool */ protected function can_display_notice() { $screen = get_current_screen(); $screen_id = sanitize_title( __( 'Languages', 'polylang' ) ); return in_array( $screen->id, array( 'dashboard', 'plugins', 'toplevel_page_mlang', $screen_id . '_page_mlang_strings', $screen_id . '_page_mlang_settings', ) ); } /** * Stores a dismissed notice in database * * @since 2.3.9 * * @param string $notice */ public static function dismiss( $notice ) { if ( ! $dismissed = get_user_meta( get_current_user_id(), 'pll_dismissed_notices', true ) ) { $dismissed = array(); } if ( ! in_array( $notice, $dismissed ) ) { $dismissed[] = $notice; update_user_meta( get_current_user_id(), 'pll_dismissed_notices', array_unique( $dismissed ) ); } } /** * Handle a click on the dismiss button * * @since 2.3.9 */ public function hide_notice() { if ( isset( $_GET['pll-hide-notice'], $_GET['_pll_notice_nonce'] ) ) { $notice = sanitize_key( $_GET['pll-hide-notice'] ); check_admin_referer( $notice, '_pll_notice_nonce' ); self::dismiss( $notice ); wp_safe_redirect( remove_query_arg( array( 'pll-hide-notice', '_pll_notice_nonce' ), wp_get_referer() ) ); exit; } } /** * Displays notices * * @since 2.3.9 */ public function display_notices() { if ( current_user_can( 'manage_options' ) && $this->can_display_notice() ) { // Core notices $this->pllwc_notice(); $this->review_notice(); // Custom notices foreach ( $this->get_notices() as $notice => $html ) { if ( ! $this->is_dismissed( $notice ) ) { ?>
', '' ); ?>
', '' ); ?>