| @@ -5,9 +5,8 @@ | ||
| 5 | 5 | * displayed only to admin, based on 'manage_options' capability |
| 6 | 6 | * and only on dashboard, plugins and Polylang admin pages |
| 7 | 7 | * |
| 8 | 8 | * @since 2.3.9 |
| 9 | - * @since 2.7 Dismissed notices are stored in an option instead of a user meta | |
| 10 | 9 | */ |
| 11 | 10 | class PLL_Admin_Notices { |
| 12 | 11 | private static $notices = array(); |
| 13 | 12 | |
| @@ -57,24 +56,10 @@ | ||
| 57 | 56 | * @param string $notice Notice name |
| 58 | 57 | * @return bool |
| 59 | 58 | */ |
| 60 | 59 | public static function is_dismissed( $notice ) { |
| 61 | - $dismissed = get_option( 'pll_dismissed_notices', array() ); | |
| 62 | - | |
| 63 | - // Handle legacy user meta | |
| 64 | - $dismissed_meta = get_user_meta( get_current_user_id(), 'pll_dismissed_notices', true ); | |
| 65 | - if ( is_array( $dismissed_meta ) ) { | |
| 66 | - if ( array_diff( $dismissed_meta, $dismissed ) ) { | |
| 67 | - $dismissed = array_merge( $dismissed, $dismissed_meta ); | |
| 68 | - update_option( 'pll_dismissed_notices', $dismissed ); | |
| 69 | - } | |
| 70 | - if ( ! is_multisite() ) { | |
| 71 | - // Don't delete on multisite to avoid the notices to appear in other sites. | |
| 72 | - delete_user_meta( get_current_user_id(), 'pll_dismissed_notices' ); | |
| 73 | - } | |
| 74 | - } | |
| 75 | - | |
| 76 | - return in_array( $notice, $dismissed ); | |
| 60 | + $dismissed = get_user_meta( get_current_user_id(), 'pll_dismissed_notices', true ); | |
| 61 | + return is_array( $dismissed ) && in_array( $notice, $dismissed ); | |
| 77 | 62 | } |
| 78 | 63 | |
| 79 | 64 | /** |
| 80 | 65 | * Should we display notices on this screen? |
| @@ -80,36 +65,23 @@ | ||
| 80 | 65 | * Should we display notices on this screen? |
| 81 | 66 | * |
| 82 | 67 | * @since 2.3.9 |
| 83 | 68 | * |
| 84 | - * @param string $notice The notice name. | |
| 85 | 69 | * @return bool |
| 86 | 70 | */ |
| 87 | - protected function can_display_notice( $notice ) { | |
| 71 | + protected function can_display_notice() { | |
| 88 | 72 | $screen = get_current_screen(); |
| 89 | 73 | $screen_id = sanitize_title( __( 'Languages', 'polylang' ) ); |
| 90 | 74 | |
| 91 | - /** | |
| 92 | - * Filter admin notices which can be displayed | |
| 93 | - * | |
| 94 | - * @since 2.7.0 | |
| 95 | - * | |
| 96 | - * @param bool $display Whether the notice should be displayed or not. | |
| 97 | - * @param string $notice The notice name. | |
| 98 | - */ | |
| 99 | - return apply_filters( | |
| 100 | - 'pll_can_display_notice', | |
| 101 | - in_array( | |
| 102 | - $screen->id, | |
| 103 | - array( | |
| 104 | - 'dashboard', | |
| 105 | - 'plugins', | |
| 106 | - 'toplevel_page_mlang', | |
| 107 | - $screen_id . '_page_mlang_strings', | |
| 108 | - $screen_id . '_page_mlang_settings', | |
| 109 | - ) | |
| 110 | - ), | |
| 111 | - $notice | |
| 75 | + return in_array( | |
| 76 | + $screen->id, | |
| 77 | + array( | |
| 78 | + 'dashboard', | |
| 79 | + 'plugins', | |
| 80 | + 'toplevel_page_mlang', | |
| 81 | + $screen_id . '_page_mlang_strings', | |
| 82 | + $screen_id . '_page_mlang_settings', | |
| 83 | + ) | |
| 112 | 84 | ); |
| 113 | 85 | } |
| 114 | 86 | |
| 115 | 87 | /** |
| @@ -119,13 +91,15 @@ | ||
| 119 | 91 | * |
| 120 | 92 | * @param string $notice |
| 121 | 93 | */ |
| 122 | 94 | public static function dismiss( $notice ) { |
| 123 | - $dismissed = get_option( 'pll_dismissed_notices', array() ); | |
| 95 | + if ( ! $dismissed = get_user_meta( get_current_user_id(), 'pll_dismissed_notices', true ) ) { | |
| 96 | + $dismissed = array(); | |
| 97 | + } | |
| 124 | 98 | |
| 125 | 99 | if ( ! in_array( $notice, $dismissed ) ) { |
| 126 | 100 | $dismissed[] = $notice; |
| 127 | - update_option( 'pll_dismissed_notices', array_unique( $dismissed ) ); | |
| 101 | + update_user_meta( get_current_user_id(), 'pll_dismissed_notices', array_unique( $dismissed ) ); | |
| 128 | 102 | } |
| 129 | 103 | } |
| 130 | 104 | |
| 131 | 105 | /** |
| @@ -148,21 +122,16 @@ | ||
| 148 | 122 | * |
| 149 | 123 | * @since 2.3.9 |
| 150 | 124 | */ |
| 151 | 125 | public function display_notices() { |
| 152 | - if ( current_user_can( 'manage_options' ) ) { | |
| 126 | + if ( current_user_can( 'manage_options' ) && $this->can_display_notice() ) { | |
| 153 | 127 | // Core notices |
| 154 | - if ( defined( 'WOOCOMMERCE_VERSION' ) && ! defined( 'PLLWC_VERSION' ) && $this->can_display_notice( 'pllwc' ) && ! $this->is_dismissed( 'pllwc' ) ) { | |
| 155 | - $this->pllwc_notice(); | |
| 156 | - } | |
| 128 | + $this->pllwc_notice(); | |
| 129 | + $this->review_notice(); | |
| 157 | 130 | |
| 158 | - 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 ) { | |
| 159 | - $this->review_notice(); | |
| 160 | - } | |
| 161 | - | |
| 162 | 131 | // Custom notices |
| 163 | 132 | foreach ( $this->get_notices() as $notice => $html ) { |
| 164 | - if ( $this->can_display_notice( $notice ) && ! $this->is_dismissed( $notice ) ) { | |
| 133 | + if ( ! $this->is_dismissed( $notice ) ) { | |
| 165 | 134 | ?> |
| 166 | 135 | <div class="pll-notice notice notice-info"> |
| 167 | 136 | <?php |
| 168 | 137 | $this->dismiss_button( $notice ); |
| @@ -196,23 +165,25 @@ | ||
| 196 | 165 | * |
| 197 | 166 | * @since 2.3.9 |
| 198 | 167 | */ |
| 199 | 168 | private function pllwc_notice() { |
| 200 | - ?> | |
| 201 | - <div class="pll-notice notice notice-warning"> | |
| 202 | - <?php $this->dismiss_button( 'pllwc' ); ?> | |
| 203 | - <p> | |
| 204 | - <?php | |
| 205 | - printf( | |
| 206 | - /* translators: %1$s is link start tag, %2$s is link end tag. */ | |
| 207 | - esc_html__( 'We have noticed that you are using Polylang with WooCommerce. To ensure compatibility, we recommend you use %1$sPolylang for WooCommerce%2$s.', 'polylang' ), | |
| 208 | - '<a href="https://polylang.pro/downloads/polylang-for-woocommerce/">', | |
| 209 | - '</a>' | |
| 210 | - ); | |
| 211 | - ?> | |
| 212 | - </p> | |
| 213 | - </div> | |
| 214 | - <?php | |
| 169 | + if ( defined( 'WOOCOMMERCE_VERSION' ) && ! defined( 'PLLWC_VERSION' ) && ! $this->is_dismissed( 'pllwc' ) ) { | |
| 170 | + ?> | |
| 171 | + <div class="pll-notice notice notice-warning"> | |
| 172 | + <?php $this->dismiss_button( 'pllwc' ); ?> | |
| 173 | + <p> | |
| 174 | + <?php | |
| 175 | + printf( | |
| 176 | + /* translators: %1$s is link start tag, %2$s is link end tag. */ | |
| 177 | + esc_html__( 'We have noticed that you are using Polylang with WooCommerce. To ensure compatibility, we recommend you use %1$sPolylang for WooCommerce%2$s.', 'polylang' ), | |
| 178 | + '<a href="https://polylang.pro/downloads/polylang-for-woocommerce/">', | |
| 179 | + '</a>' | |
| 180 | + ); | |
| 181 | + ?> | |
| 182 | + </p> | |
| 183 | + </div> | |
| 184 | + <?php | |
| 185 | + } | |
| 215 | 186 | } |
| 216 | 187 | |
| 217 | 188 | /** |
| 218 | 189 | * Displays a notice asking for a review |
| @@ -219,21 +190,23 @@ | ||
| 219 | 190 | * |
| 220 | 191 | * @since 2.3.9 |
| 221 | 192 | */ |
| 222 | 193 | private function review_notice() { |
| 223 | - ?> | |
| 224 | - <div class="pll-notice notice notice-info"> | |
| 225 | - <?php $this->dismiss_button( 'review' ); ?> | |
| 226 | - <p> | |
| 227 | - <?php | |
| 228 | - printf( | |
| 229 | - /* translators: %1$s is link start tag, %2$s is link end tag. */ | |
| 230 | - esc_html__( 'We have noticed that you have been using Polylang for some time. We hope you love it, and we would really appreciate it if you would %1$sgive us a 5 stars rating%2$s.', 'polylang' ), | |
| 231 | - '<a href="https://wordpress.org/support/plugin/polylang/reviews/?rate=5#new-post">', | |
| 232 | - '</a>' | |
| 233 | - ); | |
| 234 | - ?> | |
| 235 | - </p> | |
| 236 | - </div> | |
| 237 | - <?php | |
| 194 | + if ( ! defined( 'POLYLANG_PRO' ) && ! $this->is_dismissed( 'review' ) && ! empty( $this->options['first_activation'] ) && time() > $this->options['first_activation'] + 15 * DAY_IN_SECONDS ) { | |
| 195 | + ?> | |
| 196 | + <div class="pll-notice notice notice-info"> | |
| 197 | + <?php $this->dismiss_button( 'review' ); ?> | |
| 198 | + <p> | |
| 199 | + <?php | |
| 200 | + printf( | |
| 201 | + /* translators: %1$s is link start tag, %2$s is link end tag. */ | |
| 202 | + esc_html__( 'We have noticed that you have been using Polylang for some time. We hope you love it, and we would really appreciate it if you would %1$sgive us a 5 stars rating%2$s.', 'polylang' ), | |
| 203 | + '<a href="https://wordpress.org/support/plugin/polylang/reviews/?rate=5#new-post">', | |
| 204 | + '</a>' | |
| 205 | + ); | |
| 206 | + ?> | |
| 207 | + </p> | |
| 208 | + </div> | |
| 209 | + <?php | |
| 210 | + } | |
| 238 | 211 | } |
| 239 | 212 | } |