← All changes
|
freemius/includes/managers/class-fs-admin-menu-manager.php
+81
-35
2.3.2
→
8.0.2
View file →
| @@ -429,44 +429,65 @@ | ||
| 429 | 429 | $this->get_parent_slug() : |
| 430 | 430 | $this->get_raw_slug(); |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - /** | |
| 434 | - * Is user on plugin's admin activation page. | |
| 435 | - * | |
| 436 | - * @author Vova Feldman (@svovaf) | |
| 437 | - * @since 1.0.8 | |
| 438 | - * | |
| 439 | - * @return bool | |
| 440 | - */ | |
| 441 | - function is_main_settings_page() { | |
| 442 | - if ( $this->_menu_exists && | |
| 443 | - ( fs_is_plugin_page( $this->_menu_slug ) || fs_is_plugin_page( $this->_module_unique_affix ) ) | |
| 444 | - ) { | |
| 445 | - /** | |
| 446 | - * Module has a settings menu and the context page is the main settings page, so assume it's in | |
| 447 | - * activation (doesn't really check if already opted-in/skipped or not). | |
| 448 | - * | |
| 449 | - * @since 1.2.2 | |
| 450 | - */ | |
| 451 | - return true; | |
| 452 | - } | |
| 433 | + /** | |
| 434 | + * Is user on plugin's admin activation page. | |
| 435 | + * | |
| 436 | + * @author Vova Feldman (@svovaf) | |
| 437 | + * @since 1.0.8 | |
| 438 | + * | |
| 439 | + * @param bool $show_opt_in_on_themes_page Since 2.3.1 | |
| 440 | + * | |
| 441 | + * @return bool | |
| 442 | + * | |
| 443 | + * @deprecated Please use is_activation_page() instead. | |
| 444 | + */ | |
| 445 | + function is_main_settings_page( $show_opt_in_on_themes_page = false ) { | |
| 446 | + return $this->is_activation_page( $show_opt_in_on_themes_page ); | |
| 447 | + } | |
| 453 | 448 | |
| 454 | - global $pagenow; | |
| 455 | - if ( ( WP_FS__MODULE_TYPE_THEME === $this->_module_type ) && Freemius::is_themes_page() ) { | |
| 456 | - /** | |
| 457 | - * In activation only when show_optin query string param is given. | |
| 458 | - * | |
| 459 | - * @since 1.2.2 | |
| 460 | - */ | |
| 461 | - return fs_request_get_bool( $this->_module_unique_affix . '_show_optin' ); | |
| 462 | - } | |
| 449 | + /** | |
| 450 | + * Is user on product's admin activation page. | |
| 451 | + * | |
| 452 | + * @author Vova Feldman (@svovaf) | |
| 453 | + * @since 2.3.1 | |
| 454 | + * | |
| 455 | + * @param bool $show_opt_in_on_themes_page Since 2.3.1 | |
| 456 | + * | |
| 457 | + * @return bool | |
| 458 | + */ | |
| 459 | + function is_activation_page( $show_opt_in_on_themes_page = false ) { | |
| 460 | + if ( $show_opt_in_on_themes_page ) { | |
| 461 | + /** | |
| 462 | + * In activation only when show_optin query string param is given. | |
| 463 | + * | |
| 464 | + * @since 1.2.2 | |
| 465 | + */ | |
| 466 | + return ( | |
| 467 | + ( WP_FS__MODULE_TYPE_THEME === $this->_module_type ) && | |
| 468 | + Freemius::is_themes_page() && | |
| 469 | + fs_request_get_bool( $this->_module_unique_affix . '_show_optin' ) | |
| 470 | + ); | |
| 471 | + } | |
| 463 | 472 | |
| 464 | - return false; | |
| 465 | - } | |
| 473 | + if ( $this->_menu_exists && | |
| 474 | + ( fs_is_plugin_page( $this->_menu_slug ) || fs_is_plugin_page( $this->_module_unique_affix ) ) | |
| 475 | + ) { | |
| 476 | + /** | |
| 477 | + * Module has a settings menu and the context page is the main settings page, so assume it's in | |
| 478 | + * activation (doesn't really check if already opted-in/skipped or not). | |
| 479 | + * | |
| 480 | + * @since 1.2.2 | |
| 481 | + */ | |
| 482 | + return true; | |
| 483 | + } | |
| 466 | 484 | |
| 467 | - #region Submenu Override | |
| 485 | + return false; | |
| 486 | + } | |
| 468 | 487 | |
| 488 | + #region Submenu Override | |
| 489 | + | |
| 469 | 490 | /** |
| 470 | 491 | * Override submenu's action. |
| 471 | 492 | * |
| 472 | 493 | * @author Vova Feldman (@svovaf) |
| @@ -677,13 +698,38 @@ | ||
| 677 | 698 | } else { |
| 678 | 699 | $menu = $this->find_main_submenu(); |
| 679 | 700 | } |
| 680 | 701 | |
| 702 | + $menu_slug = $menu['menu'][2]; | |
| 681 | 703 | $parent_slug = isset( $menu['parent_slug'] ) ? |
| 682 | - $menu['parent_slug'] : | |
| 683 | - 'admin.php'; | |
| 704 | + $menu['parent_slug'] : | |
| 705 | + 'admin.php'; | |
| 684 | 706 | |
| 685 | - return admin_url( $parent_slug . '?page=' . $menu['menu'][2] ); | |
| 707 | + if ( fs_apply_filter( $this->_module_unique_affix, 'enable_cpt_advanced_menu_logic', false ) ) { | |
| 708 | + $parent_slug = 'admin.php'; | |
| 709 | + | |
| 710 | + /** | |
| 711 | + * This line and the `if` block below it are based on the `menu_page_url()` function of WordPress. | |
| 712 | + * | |
| 713 | + * @author Leo Fajardo (@leorw) | |
| 714 | + * @since 2.10.2 | |
| 715 | + */ | |
| 716 | + global $_parent_pages; | |
| 717 | + | |
| 718 | + if ( ! empty( $_parent_pages[ $menu_slug ] ) ) { | |
| 719 | + $_parent_slug = $_parent_pages[ $menu_slug ]; | |
| 720 | + $parent_slug = isset( $_parent_pages[ $_parent_slug ] ) ? | |
| 721 | + $parent_slug : | |
| 722 | + $menu['parent_slug']; | |
| 723 | + } | |
| 724 | + } | |
| 725 | + | |
| 726 | + return admin_url( | |
| 727 | + $parent_slug . | |
| 728 | + ( false === strpos( $parent_slug, '?' ) ? '?' : '&' ) . | |
| 729 | + 'page=' . | |
| 730 | + $menu_slug | |
| 731 | + ); | |
| 686 | 732 | } |
| 687 | 733 | |
| 688 | 734 | /** |
| 689 | 735 | * @author Vova Feldman (@svovaf) |