rest_preloader = $rest_preloader; } /** * Check whether the conditional object is currently needed. * * @return bool Whether the conditional object is needed. */ public static function is_needed() { global $pagenow; return ( is_admin() && Services::get( 'dependency_support' )->has_support() && ! is_network_admin() && 'plugins.php' === $pagenow && ( ! empty( $_GET['activate'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended || ! empty( $_GET['activate-multi'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended ) && AMP_Validation_Manager::has_cap() ); } /** * Get the action to use for registering the service. * * @return string Registration action to use. */ public static function get_registration_action() { return 'admin_init'; } /** * Runs on instantiation. */ public function register() { add_action( 'pre_current_active_plugins', [ $this, 'render_notice' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] ); } /** * Render an admin notice that will do an async Site Scan. */ public function render_notice() { ?>
$this->get_amp_compatible_plugins_url(), 'APP_ROOT_ID' => self::APP_ROOT_ID, 'OPTIONS_REST_PATH' => '/amp/v1/options', 'SETTINGS_LINK' => menu_page_url( AMP_Options_Manager::OPTION_NAME, false ), 'SCANNABLE_URLS_REST_PATH' => '/amp/v1/scannable-urls', 'VALIDATE_NONCE' => AMP_Validation_Manager::has_cap() ? AMP_Validation_Manager::get_amp_validate_nonce() : '', ]; wp_add_inline_script( self::ASSET_HANDLE, sprintf( 'var ampSiteScanNotice = %s;', wp_json_encode( $data ) ), 'before' ); $this->add_preload_rest_paths(); } /** * Get a URL to AMP compatible plugins directory. * * For users capable of installing plugins, the link should lead to the Plugin install page. * Other users will be directed to the plugins page on amp-wp.org. * * @return string URL to AMP compatible plugins directory. */ protected function get_amp_compatible_plugins_url() { if ( current_user_can( 'install_plugins' ) ) { return admin_url( '/plugin-install.php?tab=amp-compatible' ); } return 'https://amp-wp.org/ecosystem/plugins/'; } /** * Adds REST paths to preload. */ protected function add_preload_rest_paths() { $paths = [ '/amp/v1/options', add_query_arg( [ '_fields' => [ 'url', 'amp_url', 'type', 'label' ], ], '/amp/v1/scannable-urls' ), add_query_arg( '_fields', [ 'author', 'name', 'plugin', 'status', 'version' ], '/wp/v2/plugins' ), '/wp/v2/users/me', ]; foreach ( $paths as $path ) { $this->rest_preloader->add_preloaded_path( $path ); } } }