get_base64_logo(); return add_menu_page( 'Jetpack', 'Jetpack', 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), $icon, 3 ); } /** * Add page action. * * @param string $hook Hook of current page. * @return void */ public function add_page_actions( $hook ) { /** This action is documented in class.jetpack-admin.php */ do_action( 'jetpack_admin_menu', $hook ); if ( ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return; } $page = sanitize_text_field( wp_unslash( $_GET['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( 'jetpack' !== $page ) { if ( strpos( $page, 'jetpack/' ) === 0 ) { $section = substr( $page, 8 ); wp_safe_redirect( admin_url( 'admin.php?page=jetpack#/' . $section ) ); exit( 0 ); } return; // No need to handle the fallback redirection if we are not on the Jetpack page. } // Adding a redirect meta tag if the REST API is disabled. if ( ! $this->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' ); } } /** * Remove the main Jetpack submenu if a site is in offline mode or connected. * At that point, admins can access the Jetpack Dashboard instead. * * @since 13.8 */ public function remove_jetpack_menu() { if ( ( new Status() )->is_offline_mode() || Jetpack::is_connection_ready() ) { remove_submenu_page( 'jetpack', 'jetpack' ); } } /** * 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 */ public function jetpack_add_dashboard_sub_nav_item() { if ( ( new Status() )->is_offline_mode() || Jetpack::is_connection_ready() ) { Admin_Menu::add_menu( __( 'Dashboard', 'jetpack' ), __( 'Dashboard', 'jetpack' ), 'jetpack_admin_page', Jetpack::admin_url( array( 'page' => 'jetpack#/dashboard' ) ), null, // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal -- See https://core.trac.wordpress.org/ticket/52539. 14 ); } } /** * 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' ) && ( Publicize_Script_Data::has_feature_flag( 'admin-page' ) || ! Jetpack::is_module_active( 'publicize' ) || ! current_user_can( 'publish_posts' ) ) ) { 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 */ public function jetpack_add_settings_sub_nav_item() { if ( $this->can_access_settings() ) { Admin_Menu::add_menu( __( 'Settings', 'jetpack' ), __( 'Settings', 'jetpack' ), 'jetpack_admin_page', Jetpack::admin_url( array( 'page' => 'jetpack#/settings' ) ), null, // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal -- See https://core.trac.wordpress.org/ticket/52539. 13 ); } } /** * Fallback redirect meta tag if the REST API is disabled. * * @return void */ public function add_fallback_head_meta() { echo ''; } /** * Fallback meta tag wrapped in noscript tags for all browsers in case they have JavaScript disabled. * * @return void */ public function add_noscript_head_meta() { echo ''; } /** * Add action to render page specific HTML. * * @return void */ public function page_render() { /** This action is already documented in class.jetpack-admin-page.php */ do_action( 'jetpack_notices' ); // Fetch static.html. $static_html = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static.html' ); //phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents, Not fetching a remote file. 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 && pnpm jetpack build plugins/jetpack
';
echo '