jetpack
/
jetpack_vendor
/
automattic
/
jetpack-forms
/
src
/
dashboard
/
class-dashboard-view-switch.php
class-dashboard-view-switch.php
122 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Jetpack forms dashboard view switch. |
| 4 | * |
| 5 | * @package automattic/jetpack-forms |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Forms\Dashboard; |
| 9 | |
| 10 | use Automattic\Jetpack\Forms\Jetpack_Forms; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit( 0 ); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Understands switching between classic and redesigned versions of the feedback admin area. |
| 18 | * |
| 19 | * @deprecated 6.6.0 This class is no longer needed and has been removed from active use. |
| 20 | */ |
| 21 | class Dashboard_View_Switch { |
| 22 | |
| 23 | /** |
| 24 | * Returns true if the current screen is the Jetpack Forms admin page. |
| 25 | * |
| 26 | * @deprecated 6.6.0 Use Dashboard::is_jetpack_forms_admin_page() instead. |
| 27 | * |
| 28 | * @return boolean |
| 29 | */ |
| 30 | public function is_jetpack_forms_admin_page() { |
| 31 | _deprecated_function( __METHOD__, 'jetpack-6.6.0', 'Dashboard::is_jetpack_forms_admin_page' ); |
| 32 | |
| 33 | if ( ! function_exists( 'get_current_screen' ) ) { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | $screen = get_current_screen(); |
| 38 | return $screen && $screen->id === 'jetpack_page_jetpack-forms-admin'; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns url of forms admin page. |
| 43 | * |
| 44 | * @deprecated 6.6.0 Use Dashboard::get_forms_admin_url() instead. |
| 45 | * |
| 46 | * @param string|null $tab Tab to open in the forms admin page. |
| 47 | * |
| 48 | * @return string |
| 49 | */ |
| 50 | public function get_forms_admin_url( $tab = null ) { |
| 51 | _deprecated_function( __METHOD__, 'jetpack-6.6.0', 'Dashboard::get_forms_admin_url' ); |
| 52 | $base_url = get_admin_url() . 'admin.php?page=jetpack-forms-admin'; |
| 53 | |
| 54 | return self::append_tab_to_url( $base_url, $tab ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Appends the appropriate tab parameter to the URL based on the view type. |
| 59 | * |
| 60 | * @param string $url Base URL to append to. |
| 61 | * @param string $tab Tab to open. |
| 62 | * |
| 63 | * @return string |
| 64 | */ |
| 65 | private static function append_tab_to_url( $url, $tab ) { |
| 66 | if ( ! $tab ) { |
| 67 | return $url; |
| 68 | } |
| 69 | |
| 70 | $status_map = array( |
| 71 | 'spam' => 'spam', |
| 72 | 'inbox' => 'inbox', |
| 73 | 'trash' => 'trash', |
| 74 | ); |
| 75 | |
| 76 | if ( ! isset( $status_map[ $tab ] ) ) { |
| 77 | return $url; |
| 78 | } |
| 79 | |
| 80 | return $url . '#/responses?status=' . $status_map[ $tab ]; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Returns true if the new Jetpack Forms admin page is available. |
| 85 | * |
| 86 | * @deprecated 6.6.0 Use Dashboard::is_jetpack_forms_admin_page_available() instead. |
| 87 | * |
| 88 | * @return boolean |
| 89 | */ |
| 90 | public static function is_jetpack_forms_admin_page_available() { |
| 91 | _deprecated_function( __METHOD__, 'jetpack-6.6.0', 'Dashboard::is_jetpack_forms_admin_page_available' ); |
| 92 | return apply_filters( 'jetpack_forms_use_new_menu_parent', true ); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Returns true if the view switch is available. |
| 97 | * |
| 98 | * @return boolean |
| 99 | */ |
| 100 | public static function is_jetpack_forms_view_switch_available() { |
| 101 | return ! apply_filters( 'jetpack_forms_retire_view_switch', true ); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Returns true if the new Jetpack Forms admin page is announcing the new menu. |
| 106 | * |
| 107 | * @return boolean |
| 108 | */ |
| 109 | public static function is_jetpack_forms_announcing_new_menu() { |
| 110 | return apply_filters( 'jetpack_forms_announce_new_menu', true ); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Returns true if the classic view is available. |
| 115 | * |
| 116 | * @return boolean |
| 117 | */ |
| 118 | public static function is_classic_view_available() { |
| 119 | return ! Jetpack_Forms::is_legacy_menu_item_retired(); |
| 120 | } |
| 121 | } |
| 122 |