is_rest_api_enabled() ) { $this->is_redirecting = true; add_action( 'admin_head', array( $this, 'add_fallback_head_meta' ) ); } // Adding a redirect meta tag wrapped in noscript tags for all browsers in case they have JavaScript disabled add_action( 'admin_head', array( $this, 'add_noscript_head_meta' ) ); // If this is the first time the user is viewing the admin, don't show JITMs. // This filter is added just in time because this function is called on admin_menu // and JITMs are initialized on admin_init if ( Jetpack::is_connection_ready() && ! Jetpack_Options::get_option( 'first_admin_view', false ) ) { Jetpack_Options::update_option( 'first_admin_view', true ); add_filter( 'jetpack_just_in_time_msgs', '__return_false' ); } } /** * Add Jetpack Dashboard sub-link and point it to AAG if the user can view stats, manage modules or if Protect is active. * * Works in Dev Mode or when user is connected. * * @since 4.3.0 */ function jetpack_add_dashboard_sub_nav_item() { if ( ( new Status() )->is_offline_mode() || Jetpack::is_connection_ready() ) { add_submenu_page( 'jetpack', __( 'Dashboard', 'jetpack' ), __( 'Dashboard', 'jetpack' ), 'jetpack_admin_page', 'jetpack#/dashboard', '__return_null' ); remove_submenu_page( 'jetpack', 'jetpack' ); } } /** * Determine whether a user can access the Jetpack Settings page. * * Rules are: * - user is allowed to see the Jetpack Admin * - site is connected or in offline mode * - non-admins only need access to the settings when there are modules they can manage. * * @return bool $can_access_settings Can the user access settings. */ private function can_access_settings() { $connection = new Connection_Manager( 'jetpack' ); $status = new Status(); // User must have the necessary permissions to see the Jetpack settings pages. if ( ! current_user_can( 'edit_posts' ) ) { return false; } // In offline mode, allow access to admins. if ( $status->is_offline_mode() && current_user_can( 'manage_options' ) ) { return true; } // If not in offline mode but site is not connected, bail. if ( ! Jetpack::is_connection_ready() ) { return false; } /* * Additional checks for non-admins. */ if ( ! current_user_can( 'manage_options' ) ) { // If the site isn't connected at all, bail. if ( ! $connection->has_connected_owner() ) { return false; } /* * If they haven't connected their own account yet, * they have no use for the settings page. * They will not be able to manage any settings. */ if ( ! $connection->is_user_connected() ) { return false; } /* * Non-admins only have access to settings * for the following modules: * - Publicize * - Post By Email * If those modules are not available, bail. */ if ( ! Jetpack::is_module_active( 'post-by-email' ) && ! Jetpack::is_module_active( 'publicize' ) ) { return false; } } // fallback. return true; } /** * Jetpack Settings sub-link. * * @since 4.3.0 * @since 9.7.0 If Connection does not have an owner, restrict it to admins */ function jetpack_add_settings_sub_nav_item() { if ( $this->can_access_settings() ) { add_submenu_page( 'jetpack', __( 'Settings', 'jetpack' ), __( 'Settings', 'jetpack' ), 'jetpack_admin_page', 'jetpack#/settings', '__return_null' ); } } function add_fallback_head_meta() { echo ''; } function add_noscript_head_meta() { echo ''; } /** * Custom menu order. * * @deprecated since 9.2.0 * @param array $menu_order Menu order. * @return array */ function jetpack_menu_order( $menu_order ) { _deprecated_function( __METHOD__, 'jetpack-9.2' ); return $menu_order; } function page_render() { /** This action is already documented in views/admin/admin-page.php */ do_action( 'jetpack_notices' ); // Try fetching by patch $static_html = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static.html' ); if ( false === $static_html ) { // If we still have nothing, display an error echo '
';
esc_html_e( 'Error fetching static.html. Try running: ', 'jetpack' );
echo 'pnpm run distclean && pnpx jetpack build plugins/jetpack';
echo '