← All changes
|
freemius/includes/managers/class-fs-admin-menu-manager.php
+106
-49
2.0.1
→
8.0.2
View file →
| @@ -203,11 +203,12 @@ | ||
| 203 | 203 | // 'page' |
| 204 | 204 | // ) ); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - $this->_first_time_path = $this->get_option( $menu, 'first-path', false ); | |
| 208 | - if ( ! empty( $this->_first_time_path ) && is_string( $this->_first_time_path ) ) { | |
| 209 | - $this->_first_time_path = admin_url( $this->_first_time_path, 'admin' ); | |
| 207 | + $first_path = $this->get_option( $menu, 'first-path', false ); | |
| 208 | + | |
| 209 | + if ( ! empty( $first_path ) && is_string( $first_path ) ) { | |
| 210 | + $this->_first_time_path = $first_path; | |
| 210 | 211 | } |
| 211 | 212 | } |
| 212 | 213 | } |
| 213 | 214 | |
| @@ -235,20 +236,30 @@ | ||
| 235 | 236 | return $this->_is_override_exact; |
| 236 | 237 | } |
| 237 | 238 | |
| 238 | 239 | |
| 239 | - /** | |
| 240 | - * Get the path of the page the user should be forwarded to after first activation. | |
| 241 | - * | |
| 242 | - * @author Vova Feldman (@svovaf) | |
| 243 | - * @since 1.1.3 | |
| 244 | - * | |
| 245 | - * @return string | |
| 246 | - */ | |
| 247 | - function get_first_time_path() { | |
| 248 | - return $this->_first_time_path; | |
| 249 | - } | |
| 240 | + /** | |
| 241 | + * Get the path of the page the user should be forwarded to after first activation. | |
| 242 | + * | |
| 243 | + * @author Vova Feldman (@svovaf) | |
| 244 | + * @since 1.1.3 | |
| 245 | + * | |
| 246 | + * @param bool $is_network Since 2.4.5 | |
| 247 | + * | |
| 248 | + * @return string | |
| 249 | + */ | |
| 250 | + function get_first_time_path( $is_network = false ) { | |
| 251 | + if ( empty ( $this->_first_time_path ) ) { | |
| 252 | + return $this->_first_time_path; | |
| 253 | + } | |
| 250 | 254 | |
| 255 | + if ( $is_network ) { | |
| 256 | + return network_admin_url( $this->_first_time_path ); | |
| 257 | + } else { | |
| 258 | + return admin_url( $this->_first_time_path ); | |
| 259 | + } | |
| 260 | + } | |
| 261 | + | |
| 251 | 262 | /** |
| 252 | 263 | * Check if plugin's menu item is part of a custom top level menu. |
| 253 | 264 | * |
| 254 | 265 | * @author Vova Feldman (@svovaf) |
| @@ -418,44 +429,65 @@ | ||
| 418 | 429 | $this->get_parent_slug() : |
| 419 | 430 | $this->get_raw_slug(); |
| 420 | 431 | } |
| 421 | 432 | |
| 422 | - /** | |
| 423 | - * Is user on plugin's admin activation page. | |
| 424 | - * | |
| 425 | - * @author Vova Feldman (@svovaf) | |
| 426 | - * @since 1.0.8 | |
| 427 | - * | |
| 428 | - * @return bool | |
| 429 | - */ | |
| 430 | - function is_main_settings_page() { | |
| 431 | - if ( $this->_menu_exists && | |
| 432 | - ( fs_is_plugin_page( $this->_menu_slug ) || fs_is_plugin_page( $this->_module_unique_affix ) ) | |
| 433 | - ) { | |
| 434 | - /** | |
| 435 | - * Module has a settings menu and the context page is the main settings page, so assume it's in | |
| 436 | - * activation (doesn't really check if already opted-in/skipped or not). | |
| 437 | - * | |
| 438 | - * @since 1.2.2 | |
| 439 | - */ | |
| 440 | - return true; | |
| 441 | - } | |
| 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 | + } | |
| 442 | 448 | |
| 443 | - global $pagenow; | |
| 444 | - if ( ( WP_FS__MODULE_TYPE_THEME === $this->_module_type ) && Freemius::is_themes_page() ) { | |
| 445 | - /** | |
| 446 | - * In activation only when show_optin query string param is given. | |
| 447 | - * | |
| 448 | - * @since 1.2.2 | |
| 449 | - */ | |
| 450 | - return fs_request_get_bool( $this->_module_unique_affix . '_show_optin' ); | |
| 451 | - } | |
| 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 | + } | |
| 452 | 472 | |
| 453 | - return false; | |
| 454 | - } | |
| 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 | + } | |
| 455 | 484 | |
| 456 | - #region Submenu Override | |
| 485 | + return false; | |
| 486 | + } | |
| 457 | 487 | |
| 488 | + #region Submenu Override | |
| 489 | + | |
| 458 | 490 | /** |
| 459 | 491 | * Override submenu's action. |
| 460 | 492 | * |
| 461 | 493 | * @author Vova Feldman (@svovaf) |
| @@ -666,13 +698,38 @@ | ||
| 666 | 698 | } else { |
| 667 | 699 | $menu = $this->find_main_submenu(); |
| 668 | 700 | } |
| 669 | 701 | |
| 702 | + $menu_slug = $menu['menu'][2]; | |
| 670 | 703 | $parent_slug = isset( $menu['parent_slug'] ) ? |
| 671 | - $menu['parent_slug'] : | |
| 672 | - 'admin.php'; | |
| 704 | + $menu['parent_slug'] : | |
| 705 | + 'admin.php'; | |
| 673 | 706 | |
| 674 | - 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 | + ); | |
| 675 | 732 | } |
| 676 | 733 | |
| 677 | 734 | /** |
| 678 | 735 | * @author Vova Feldman (@svovaf) |