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_option( 'pll_dismissed_notices', array() ); // Handle legacy user meta $dismissed_meta = get_user_meta( get_current_user_id(), 'pll_dismissed_notices', true ); if ( is_array( $dismissed_meta ) ) { if ( array_diff( $dismissed_meta, $dismissed ) ) { $dismissed = array_merge( $dismissed, $dismissed_meta ); update_option( 'pll_dismissed_notices', $dismissed ); } if ( ! is_multisite() ) { // Don't delete on multisite to avoid the notices to appear in other sites. delete_user_meta( get_current_user_id(), 'pll_dismissed_notices' ); } } return in_array( $notice, $dismissed ); } /** * Should we display notices on this screen? * * @since 2.3.9 * * @param string $notice The notice name. * @return bool */ protected function can_display_notice( $notice ) { $screen = get_current_screen(); $screen_id = sanitize_title( __( 'Languages', 'polylang' ) ); /** * Filter admin notices which can be displayed * * @since 2.7.0 * * @param bool $display Whether the notice should be displayed or not. * @param string $notice The notice name. */ return apply_filters( 'pll_can_display_notice', in_array( $screen->id, array( 'dashboard', 'plugins', 'toplevel_page_mlang', $screen_id . '_page_mlang_strings', $screen_id . '_page_mlang_settings', ) ), $notice ); } /** * Stores a dismissed notice in database * * @since 2.3.9 * * @param string $notice */ public static function dismiss( $notice ) { $dismissed = get_option( 'pll_dismissed_notices', array() ); if ( ! in_array( $notice, $dismissed ) ) { $dismissed[] = $notice; update_option( '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' ) ) { // Core notices if ( defined( 'WOOCOMMERCE_VERSION' ) && ! defined( 'PLLWC_VERSION' ) && $this->can_display_notice( 'pllwc' ) && ! $this->is_dismissed( 'pllwc' ) ) { $this->pllwc_notice(); } if ( ! defined( 'POLYLANG_PRO' ) && $this->can_display_notice( 'review' ) && ! $this->is_dismissed( 'review' ) && ! empty( $this->options['first_activation'] ) && time() > $this->options['first_activation'] + 15 * DAY_IN_SECONDS ) { $this->review_notice(); } // Custom notices foreach ( $this->get_notices() as $notice => $html ) { if ( $this->can_display_notice( $notice ) && ! $this->is_dismissed( $notice ) ) { ?>
', '' ); ?>
', '' ); ?>