| @@ -6,109 +6,8 @@ | ||
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | - * Add wpLingua admin menu when API Key is not registered | |
| 11 | - * | |
| 12 | - * @return void | |
| 13 | - */ | |
| 14 | -function wplng_create_menu_register() { | |
| 15 | - | |
| 16 | - add_menu_page( | |
| 17 | - __( 'wpLingua: Register', 'wplingua' ), | |
| 18 | - __( 'wpLingua', 'wplingua' ), | |
| 19 | - 'edit_posts', | |
| 20 | - 'wplingua-settings', | |
| 21 | - 'wplng_option_page_register', | |
| 22 | - 'dashicons-translation', | |
| 23 | - 31 | |
| 24 | - ); | |
| 25 | -} | |
| 26 | - | |
| 27 | - | |
| 28 | -/** | |
| 29 | - * Add wpLingua admin menu when key is registered | |
| 30 | - * | |
| 31 | - * @return void | |
| 32 | - */ | |
| 33 | -function wplng_create_menu() { | |
| 34 | - | |
| 35 | - add_menu_page( | |
| 36 | - __( 'wpLingua: Settings', 'wplingua' ), | |
| 37 | - __( 'wpLingua', 'wplingua' ), | |
| 38 | - 'edit_posts', | |
| 39 | - 'wplingua-settings', | |
| 40 | - '', | |
| 41 | - 'dashicons-translation', | |
| 42 | - 31 | |
| 43 | - ); | |
| 44 | - | |
| 45 | - add_submenu_page( | |
| 46 | - 'wplingua-settings', | |
| 47 | - __( 'wpLingua: Settings', 'wplingua' ), | |
| 48 | - __( 'General settings', 'wplingua' ), | |
| 49 | - 'edit_posts', | |
| 50 | - 'wplingua-settings', | |
| 51 | - 'wplng_option_page_settings' | |
| 52 | - ); | |
| 53 | - | |
| 54 | - add_submenu_page( | |
| 55 | - 'wplingua-settings', | |
| 56 | - __( 'wpLingua: Switcher', 'wplingua' ), | |
| 57 | - __( 'Switcher', 'wplingua' ), | |
| 58 | - 'edit_posts', | |
| 59 | - 'wplingua-switcher', | |
| 60 | - 'wplng_option_page_switcher' | |
| 61 | - ); | |
| 62 | - | |
| 63 | - add_submenu_page( | |
| 64 | - 'wplingua-settings', | |
| 65 | - __( 'wpLingua: Exclusion', 'wplingua' ), | |
| 66 | - __( 'Exclusion', 'wplingua' ), | |
| 67 | - 'edit_posts', | |
| 68 | - 'wplingua-exclusions', | |
| 69 | - 'wplng_option_page_exclusions' | |
| 70 | - ); | |
| 71 | - | |
| 72 | - add_submenu_page( | |
| 73 | - 'wplingua-settings', | |
| 74 | - __( 'wpLingua: Dictionary', 'wplingua' ), | |
| 75 | - __( 'Dictionary', 'wplingua' ), | |
| 76 | - 'edit_posts', | |
| 77 | - 'wplingua-dictionary', | |
| 78 | - 'wplng_option_page_dictionary' | |
| 79 | - ); | |
| 80 | - | |
| 81 | - add_submenu_page( | |
| 82 | - 'wplingua-settings', | |
| 83 | - __( 'wplingua: Links & Medias', 'wplingua' ), | |
| 84 | - __( 'Links & Medias', 'wplingua' ), | |
| 85 | - 'edit_posts', | |
| 86 | - 'wplingua-link-media', | |
| 87 | - 'wplng_option_page_link_media' | |
| 88 | - ); | |
| 89 | - | |
| 90 | - add_submenu_page( | |
| 91 | - 'wplingua-settings', | |
| 92 | - __( 'wpLingua: Website slugs', 'wplingua' ), | |
| 93 | - __( 'Website slugs', 'wplingua' ), | |
| 94 | - 'edit_posts', | |
| 95 | - 'edit.php?post_type=wplng_slug', | |
| 96 | - false | |
| 97 | - ); | |
| 98 | - | |
| 99 | - add_submenu_page( | |
| 100 | - 'wplingua-settings', | |
| 101 | - __( 'wpLingua: Translations', 'wplingua' ), | |
| 102 | - __( 'All translations', 'wplingua' ), | |
| 103 | - 'edit_posts', | |
| 104 | - 'edit.php?post_type=wplng_translation', | |
| 105 | - false | |
| 106 | - ); | |
| 107 | -} | |
| 108 | - | |
| 109 | - | |
| 110 | -/** | |
| 111 | 10 | * Register wpLingua settings |
| 112 | 11 | * |
| 113 | 12 | * @return void |
| 114 | 13 | */ |
| @@ -147,8 +46,32 @@ | ||
| 147 | 46 | } |
| 148 | 47 | |
| 149 | 48 | |
| 150 | 49 | /** |
| 50 | + * Determine whether the current page is one of | |
| 51 | + * wpLingua's hidden option pages. | |
| 52 | + */ | |
| 53 | +function wplng_is_wplingua_settings_page() { | |
| 54 | + | |
| 55 | + if ( empty( $_GET['page'] ) ) { | |
| 56 | + return false; | |
| 57 | + } | |
| 58 | + | |
| 59 | + return in_array( | |
| 60 | + sanitize_key( $_GET['page'] ), | |
| 61 | + array( | |
| 62 | + 'wplingua-settings', | |
| 63 | + 'wplingua-switcher', | |
| 64 | + 'wplingua-exclusions', | |
| 65 | + 'wplingua-dictionary', | |
| 66 | + 'wplingua-link-media', | |
| 67 | + ), | |
| 68 | + true | |
| 69 | + ); | |
| 70 | +} | |
| 71 | + | |
| 72 | + | |
| 73 | +/** | |
| 151 | 74 | * Return true if is a wpLingua Admin page |
| 152 | 75 | * |
| 153 | 76 | * @return bool Is a wpLingua Admin page |
| 154 | 77 | */ |
| @@ -208,8 +131,267 @@ | ||
| 208 | 131 | } |
| 209 | 132 | |
| 210 | 133 | |
| 211 | 134 | /** |
| 135 | + * Add wpLingua admin menu when API Key is not registered | |
| 136 | + * | |
| 137 | + * @return void | |
| 138 | + */ | |
| 139 | +function wplng_create_menu_register() { | |
| 140 | + | |
| 141 | + add_menu_page( | |
| 142 | + __( 'wpLingua: Register', 'wplingua' ), | |
| 143 | + __( 'wpLingua', 'wplingua' ), | |
| 144 | + 'edit_posts', | |
| 145 | + 'wplingua-settings', | |
| 146 | + 'wplng_option_page_register', | |
| 147 | + 'dashicons-translation', | |
| 148 | + 31 | |
| 149 | + ); | |
| 150 | +} | |
| 151 | + | |
| 152 | + | |
| 153 | +/** | |
| 154 | + * Create wpLingua admin menu. | |
| 155 | + */ | |
| 156 | +function wplng_create_menu() { | |
| 157 | + | |
| 158 | + /* | |
| 159 | + * Main wpLingua menu | |
| 160 | + */ | |
| 161 | + add_menu_page( | |
| 162 | + __( 'wpLingua: Settings', 'wplingua' ), | |
| 163 | + __( 'wpLingua', 'wplingua' ), | |
| 164 | + 'edit_posts', | |
| 165 | + 'wplingua-settings', | |
| 166 | + '', | |
| 167 | + 'dashicons-translation', | |
| 168 | + 31 | |
| 169 | + ); | |
| 170 | + | |
| 171 | + | |
| 172 | + /* | |
| 173 | + * Settings | |
| 174 | + * | |
| 175 | + * This is the visible entry used as the parent | |
| 176 | + * for all wpLingua option pages. | |
| 177 | + */ | |
| 178 | + add_submenu_page( | |
| 179 | + 'wplingua-settings', | |
| 180 | + __( 'wpLingua: Settings', 'wplingua' ), | |
| 181 | + __( 'Settings', 'wplingua' ), | |
| 182 | + 'edit_posts', | |
| 183 | + 'wplingua-settings', | |
| 184 | + 'wplng_option_page_settings' | |
| 185 | + ); | |
| 186 | + | |
| 187 | + | |
| 188 | + /* | |
| 189 | + * Hidden option pages | |
| 190 | + * | |
| 191 | + * These pages remain registered as children of | |
| 192 | + * wplingua-settings, but their menu entries are | |
| 193 | + * hidden later with CSS. | |
| 194 | + */ | |
| 195 | + | |
| 196 | + add_submenu_page( | |
| 197 | + 'wplingua-settings', | |
| 198 | + __( 'wpLingua: Switcher', 'wplingua' ), | |
| 199 | + __( 'Switcher', 'wplingua' ), | |
| 200 | + 'edit_posts', | |
| 201 | + 'wplingua-switcher', | |
| 202 | + 'wplng_option_page_switcher' | |
| 203 | + ); | |
| 204 | + | |
| 205 | + add_submenu_page( | |
| 206 | + 'wplingua-settings', | |
| 207 | + __( 'wpLingua: Exclusion', 'wplingua' ), | |
| 208 | + __( 'Exclusion', 'wplingua' ), | |
| 209 | + 'edit_posts', | |
| 210 | + 'wplingua-exclusions', | |
| 211 | + 'wplng_option_page_exclusions' | |
| 212 | + ); | |
| 213 | + | |
| 214 | + add_submenu_page( | |
| 215 | + 'wplingua-settings', | |
| 216 | + __( 'wpLingua: Dictionary', 'wplingua' ), | |
| 217 | + __( 'Dictionary', 'wplingua' ), | |
| 218 | + 'edit_posts', | |
| 219 | + 'wplingua-dictionary', | |
| 220 | + 'wplng_option_page_dictionary' | |
| 221 | + ); | |
| 222 | + | |
| 223 | + add_submenu_page( | |
| 224 | + 'wplingua-settings', | |
| 225 | + __( 'wplingua: Links & Medias', 'wplingua' ), | |
| 226 | + __( 'Links & Medias', 'wplingua' ), | |
| 227 | + 'edit_posts', | |
| 228 | + 'wplingua-link-media', | |
| 229 | + 'wplng_option_page_link_media' | |
| 230 | + ); | |
| 231 | + | |
| 232 | + | |
| 233 | + /* | |
| 234 | + * Visible custom post type pages | |
| 235 | + */ | |
| 236 | + | |
| 237 | + add_submenu_page( | |
| 238 | + 'wplingua-settings', | |
| 239 | + __( 'wpLingua: Website slugs', 'wplingua' ), | |
| 240 | + __( 'Website slugs', 'wplingua' ), | |
| 241 | + 'edit_posts', | |
| 242 | + 'edit.php?post_type=wplng_slug', | |
| 243 | + false | |
| 244 | + ); | |
| 245 | + | |
| 246 | + add_submenu_page( | |
| 247 | + 'wplingua-settings', | |
| 248 | + __( 'wpLingua: Translations', 'wplingua' ), | |
| 249 | + __( 'All translations', 'wplingua' ), | |
| 250 | + 'edit_posts', | |
| 251 | + 'edit.php?post_type=wplng_translation', | |
| 252 | + false | |
| 253 | + ); | |
| 254 | +} | |
| 255 | + | |
| 256 | + | |
| 257 | +/** | |
| 258 | + * Keep wpLingua as the active parent menu | |
| 259 | + * on all wpLingua option pages. | |
| 260 | + * | |
| 261 | + * @param string $parent_file The current parent menu file. | |
| 262 | + * | |
| 263 | + * @return string The parent menu file. | |
| 264 | + */ | |
| 265 | +function wplng_option_page_parent_file( $parent_file ) { | |
| 266 | + | |
| 267 | + if ( wplng_is_wplingua_settings_page() ) { | |
| 268 | + return 'wplingua-settings'; | |
| 269 | + } | |
| 270 | + | |
| 271 | + return $parent_file; | |
| 272 | +} | |
| 273 | + | |
| 274 | + | |
| 275 | +/** | |
| 276 | + * Keep "Settings" as the active submenu | |
| 277 | + * on all wpLingua option pages. | |
| 278 | + * | |
| 279 | + * @param string $submenu_file The current submenu file. | |
| 280 | + * | |
| 281 | + * @return string The submenu file. | |
| 282 | + */ | |
| 283 | +function wplng_option_page_submenu_file( $submenu_file ) { | |
| 284 | + | |
| 285 | + if ( wplng_is_wplingua_settings_page() ) { | |
| 286 | + return 'wplingua-settings'; | |
| 287 | + } | |
| 288 | + | |
| 289 | + return $submenu_file; | |
| 290 | +} | |
| 291 | + | |
| 292 | + | |
| 293 | +/** | |
| 294 | + * Hide the option pages from the wpLingua submenu. | |
| 295 | + * | |
| 296 | + * The pages themselves remain registered in WordPress. | |
| 297 | + * Therefore, they are still accessible directly by URL | |
| 298 | + * and remain correctly associated with the wpLingua menu. | |
| 299 | + */ | |
| 300 | +function wplng_option_page_hide_submenu() { | |
| 301 | + | |
| 302 | + $css = '<style>'; | |
| 303 | + $css .= '#adminmenu .wp-submenu a[href*="page=wplingua-switcher"], '; | |
| 304 | + $css .= '#adminmenu .wp-submenu a[href*="page=wplingua-exclusions"], '; | |
| 305 | + $css .= '#adminmenu .wp-submenu a[href*="page=wplingua-dictionary"], '; | |
| 306 | + $css .= '#adminmenu .wp-submenu a[href*="page=wplingua-link-media"] {'; | |
| 307 | + $css .= 'display: none;'; | |
| 308 | + $css .= '}'; | |
| 309 | + $css .= '</style>'; | |
| 310 | + | |
| 311 | + echo $css; | |
| 312 | +} | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | +/** | |
| 317 | + * Generates the navigation menu for wpLingua option pages. | |
| 318 | + * | |
| 319 | + * Creates a list of links to the different wpLingua settings pages, | |
| 320 | + * highlighting the current page with the `button-primary` class. | |
| 321 | + * | |
| 322 | + * @param bool $display_none Whether to hide the menu by default. | |
| 323 | + * | |
| 324 | + * @return string The HTML markup for the option pages navigation menu. | |
| 325 | + */ | |
| 326 | +function wplng_option_page_settings_menu( $display_none = false ) { | |
| 327 | + | |
| 328 | + $data = array( | |
| 329 | + array( | |
| 330 | + 'page' => 'wplingua-settings', | |
| 331 | + 'title' => __( 'General settings', 'wplingua' ), | |
| 332 | + 'dashicon' => 'dashicons-admin-generic', | |
| 333 | + ), | |
| 334 | + array( | |
| 335 | + 'page' => 'wplingua-switcher', | |
| 336 | + 'title' => __( 'Language switcher', 'wplingua' ), | |
| 337 | + 'dashicon' => 'dashicons-admin-settings', | |
| 338 | + ), | |
| 339 | + array( | |
| 340 | + 'page' => 'wplingua-exclusions', | |
| 341 | + 'title' => __( 'Exclusion', 'wplingua' ), | |
| 342 | + 'dashicon' => 'dashicons-filter', | |
| 343 | + ), | |
| 344 | + array( | |
| 345 | + 'page' => 'wplingua-dictionary', | |
| 346 | + 'title' => __( 'Dictionary', 'wplingua' ), | |
| 347 | + 'dashicon' => 'dashicons-book', | |
| 348 | + ), | |
| 349 | + array( | |
| 350 | + 'page' => 'wplingua-link-media', | |
| 351 | + 'title' => __( 'Links & Medias', 'wplingua' ), | |
| 352 | + 'dashicon' => 'dashicons-format-gallery', | |
| 353 | + ), | |
| 354 | + ); | |
| 355 | + | |
| 356 | + $style = ''; | |
| 357 | + if ( $display_none === true ) { | |
| 358 | + $style = ' style="display: none;"'; | |
| 359 | + } | |
| 360 | + | |
| 361 | + $html = '<div class="wplng-option-page-menu"' . $style . '>'; | |
| 362 | + $html .= '<ul>'; | |
| 363 | + | |
| 364 | + foreach ( $data as $value ) { | |
| 365 | + | |
| 366 | + $url = add_query_arg( | |
| 367 | + 'page', | |
| 368 | + $value['page'], | |
| 369 | + admin_url( 'admin.php' ) | |
| 370 | + ); | |
| 371 | + | |
| 372 | + $class_attr = ''; | |
| 373 | + if ( $_GET['page'] === $value['page'] ) { | |
| 374 | + $class_attr = ' button-primary'; | |
| 375 | + } | |
| 376 | + | |
| 377 | + $html .= '<li>'; | |
| 378 | + $html .= '<a href="' . esc_url( $url ) . '" class="button' . $class_attr . '">'; | |
| 379 | + $html .= '<span class="dashicons ' . esc_attr( $value['dashicon'] ) . '">'; | |
| 380 | + $html .= '</span> '; | |
| 381 | + $html .= esc_html( $value['title'] ); | |
| 382 | + $html .= '</a>'; | |
| 383 | + $html .= '</li>'; | |
| 384 | + } | |
| 385 | + | |
| 386 | + $html .= '</ul>'; | |
| 387 | + $html .= '</div>'; // End .wplng-option-page-menu | |
| 388 | + | |
| 389 | + return $html; | |
| 390 | +} | |
| 391 | + | |
| 392 | + | |
| 393 | +/** | |
| 212 | 394 | * Customize the admin footer text displayed on wpLingua option pages. |
| 213 | 395 | * |
| 214 | 396 | * @param string $text The default footer text. |
| 215 | 397 | * @return string The customized footer text for wpLingua pages. |
| @@ -224,9 +406,9 @@ | ||
| 224 | 406 | $text .= esc_html__( 'Thank you for choosing wpLingua!', 'wplingua' ); |
| 225 | 407 | } else { |
| 226 | 408 | $text .= sprintf( |
| 227 | 409 | esc_html__( 'If you like wpLingua please leave us a %1$s rating. A huge thanks!', 'wplingua' ), |
| 228 | - '<a href="https://wordpress.org/support/plugin/wplingua/reviews/?filter=5" target="_blank" class="wc-rating-link" aria-label="' . esc_attr__( 'five stars', 'wplingua' ) . '">★★★★★</a>' | |
| 410 | + '<a href="https://wordpress.org/support/plugin/wplingua/reviews/?filter=5" target="_blank" rel="noopener noreferrer" aria-label="' . esc_attr__( 'five stars', 'wplingua' ) . '">★★★★★</a>' | |
| 229 | 411 | ); |
| 230 | 412 | } |
| 231 | 413 | } |
| 232 | 414 | |
| @@ -242,12 +424,12 @@ | ||
| 242 | 424 | */ |
| 243 | 425 | function wplng_update_footer( $text ) { |
| 244 | 426 | |
| 245 | 427 | if ( wplng_is_wplingua_admin_page() ) { |
| 246 | - $text = '<a href="https://wplingua.com/" target="_blank">'; | |
| 428 | + $text = '<a href="https://wplingua.com/" target="_blank" rel="noopener noreferrer">'; | |
| 247 | 429 | $text .= 'wplingua.com'; |
| 248 | 430 | $text .= '</a> | '; |
| 249 | - $text .= '<a href="https://github.com/julien-jacob/wplingua" target="_blank">'; | |
| 431 | + $text .= '<a href="https://github.com/julien-jacob/wplingua" target="_blank" rel="noopener noreferrer">'; | |
| 250 | 432 | $text .= 'GitHub'; |
| 251 | 433 | $text .= '</a> | '; |
| 252 | 434 | $text .= esc_html__( 'Version', 'wplingua' ); |
| 253 | 435 | $text .= ' ' . esc_html( WPLNG_PLUGIN_VERSION ); |
| @@ -465,10 +647,10 @@ | ||
| 465 | 647 | |
| 466 | 648 | // Advanced users can bypass the multisite incompatibility notice by |
| 467 | 649 | // returning true to this filter. Note that bypassing does NOT make |
| 468 | 650 | // wpLingua officially compatible with multisite installations. |
| 469 | - if ( ! is_multisite() | |
| 470 | - || apply_filters( 'wplng_bypass_multisite_incompatibility', false ) | |
| 651 | + if ( ! is_multisite() | |
| 652 | + || apply_filters( 'wplng_bypass_multisite_incompatibility', false ) | |
| 471 | 653 | ) { |
| 472 | 654 | return; |
| 473 | 655 | } |
| 474 | 656 | |
| @@ -644,4 +826,57 @@ | ||
| 644 | 826 | $html .= '</div>'; // End .notice |
| 645 | 827 | |
| 646 | 828 | echo $html; |
| 647 | 829 | } |
| 830 | + | |
| 831 | + | |
| 832 | +/** | |
| 833 | + * Display a notice for obtaining the PRO version of the plugin | |
| 834 | + * - Only for non free user | |
| 835 | + * - Only on wpLingua option's pages | |
| 836 | + * - Only if PRO plugin not already activated | |
| 837 | + * | |
| 838 | + * @return void|string Outputs the admin notice if applicable, or returns void if no notice is required. | |
| 839 | + */ | |
| 840 | +function wplng_admin_notice_get_pro_version() { | |
| 841 | + | |
| 842 | + if ( is_plugin_active( 'wplingua-pro/wplingua-pro.php' ) ) { | |
| 843 | + return; | |
| 844 | + } | |
| 845 | + | |
| 846 | + $data = wplng_get_api_data(); | |
| 847 | + | |
| 848 | + if ( empty( $data['status'] ) | |
| 849 | + || $data['status'] === 'FREE' | |
| 850 | + ) { | |
| 851 | + return; | |
| 852 | + } | |
| 853 | + | |
| 854 | + $html = '<div'; | |
| 855 | + $html .= ' class="wplng-notice notice notice-warning is-dismissible"'; | |
| 856 | + $html .= ' style="text-align: center;"'; | |
| 857 | + $html .= '>'; | |
| 858 | + $html .= '<p style="font-weight: 600;">'; | |
| 859 | + $html .= '<span class="dashicons dashicons-translation"></span> '; | |
| 860 | + $html .= esc_html__( 'wpLingua - Unlock PRO Features', 'wplingua' ); | |
| 861 | + $html .= '</p>'; | |
| 862 | + $html .= '<hr>'; | |
| 863 | + $html .= '<p>'; | |
| 864 | + $html .= esc_html__( 'Extend wpLingua with additional features and advanced translation capabilities.', 'wplingua' ); | |
| 865 | + $html .= '</p>'; | |
| 866 | + $html .= '<p>'; | |
| 867 | + $html .= esc_html__( 'Download and install wpLingua PRO to access the features included with your wpLingua plan.', 'wplingua' ); | |
| 868 | + $html .= '</p>'; | |
| 869 | + | |
| 870 | + $html .= '<br>'; | |
| 871 | + $html .= '<a'; | |
| 872 | + $html .= ' href="https://wplingua.com/download/"'; | |
| 873 | + $html .= ' target="_blank"'; | |
| 874 | + $html .= ' rel="noopener noreferrer"'; | |
| 875 | + $html .= ' class="button button-primary"'; | |
| 876 | + $html .= '>'; | |
| 877 | + $html .= esc_html__( 'wpLingua.com : Download PRO plugin', 'wplingua' ); | |
| 878 | + $html .= '</a>'; | |
| 879 | + $html .= '</div>'; // End .notice | |
| 880 | + | |
| 881 | + echo $html; | |
| 882 | +} | |