*/ $backup_global_post = ! empty( $post ) ? clone $post : $post; $backup_wp_scripts = ! empty( $wp_scripts ) ? clone $wp_scripts : $wp_scripts; $backup_wp_styles = ! empty( $wp_styles ) ? clone $wp_styles : $wp_styles; foreach ( $preload_paths as &$path ) { if ( is_string( $path ) && ! str_starts_with( $path, '/' ) ) { $path = '/' . $path; continue; } if ( is_array( $path ) && is_string( $path[0] ) && ! str_starts_with( $path[0], '/' ) ) { $path[0] = '/' . $path[0]; } } unset( $path ); $preload_data = array_reduce( $preload_paths, 'rest_preload_api_request', array() ); // Restore the global $post, $wp_scripts, and $wp_styles as they were before API preloading. $post = $backup_global_post; $wp_scripts = $backup_wp_scripts; $wp_styles = $backup_wp_styles; wp_add_inline_script( 'wp-api-fetch', sprintf( 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', wp_json_encode( $preload_data ) ), 'after' ); } /** * Creates an array of theme styles to load into the block editor. * * @since 5.8.0 * * @global array $editor_styles * * @return array An array of theme styles for the block editor. */ function get_block_editor_theme_styles() { global $editor_styles; $styles = array(); if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) { foreach ( $editor_styles as $style ) { if ( preg_match( '~^(https?:)?//~', $style ) ) { $response = wp_remote_get( $style ); if ( ! is_wp_error( $response ) ) { $styles[] = array( 'css' => wp_remote_retrieve_body( $response ), '__unstableType' => 'theme', 'isGlobalStyles' => false, ); } } else { $file = get_theme_file_path( $style ); if ( is_file( $file ) ) { $styles[] = array( 'css' => file_get_contents( $file ), 'baseURL' => get_theme_file_uri( $style ), '__unstableType' => 'theme', 'isGlobalStyles' => false, ); } } } } return $styles; } /** * Returns the classic theme supports settings for block editor. * * @since 6.2.0 * * @return array The classic theme supports settings. */ function get_classic_theme_supports_block_editor_settings() { $theme_settings = array( 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ), 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ), 'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ), 'disableLayoutStyles' => get_theme_support( 'disable-layout-styles' ), 'enableCustomLineHeight' => get_theme_support( 'custom-line-height' ), 'enableCustomSpacing' => get_theme_support( 'custom-spacing' ), 'enableCustomUnits' => get_theme_support( 'custom-units' ), ); // Theme settings. $color_palette = current( (array) get_theme_support( 'editor-color-palette' ) ); if ( false !== $color_palette ) { $theme_settings['colors'] = $color_palette; } $font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) ); if ( false !== $font_sizes ) { $theme_settings['fontSizes'] = $font_sizes; } $gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) ); if ( false !== $gradient_presets ) { $theme_settings['gradients'] = $gradient_presets; } return $theme_settings; } ress Core from outputting a robots tag in disableWpRobotsCore(), we need to noindex/nofollow non-public sites ourselves. if ( ! get_option( 'blog_public' ) ) { $this->attributes['noindex'] = 'noindex'; $this->attributes['nofollow'] = 'nofollow'; } $this->attributes = array_filter( (array) apply_filters( 'aioseo_robots_meta', $this->attributes ) ); return $array ? $this->attributes : implode( ', ', $this->attributes ); } /** * Sets the attributes for the current post. * * @since 4.0.0 * * @param \WP_Post|null $post The post object. * @return void */ public function post( $post = null ) { $dynamicOptions = aioseo()->dynamicOptions->noConflict(); $post = aioseo()->helpers->getPost( $post ); $metaData = aioseo()->meta->metaData->getMetaData( $post ); if ( ! empty( $metaData ) && ! $metaData->robots_default ) { $this->metaValues( $metaData ); return; } if ( $dynamicOptions->searchAppearance->postTypes->has( $post->post_type ) ) { $this->globalValues( [ 'postTypes', $post->post_type ], true ); } } /** * Returns the robots meta tag value for the current term. * * @since 4.0.6 * * @param \WP_Term|null $term The term object if any. * @return void */ public function term( $term = null ) { $dynamicOptions = aioseo()->dynamicOptions->noConflict(); $term = is_a( $term, 'WP_Term' ) ? $term : get_queried_object(); if ( $dynamicOptions->searchAppearance->taxonomies->has( $term->taxonomy ) ) { $this->globalValues( [ 'taxonomies', $term->taxonomy ], true ); return; } $this->globalValues(); } /** * Sets the attributes for the current archive. * * @since 4.0.0 * * @return void */ private function archives() { $dynamicOptions = aioseo()->dynamicOptions->noConflict(); $postType = get_queried_object(); if ( ! empty( $postType->name ) && $dynamicOptions->searchAppearance->archives->has( $postType->name ) ) { $this->globalValues( [ 'archives', $postType->name ], true ); } } /** * Sets the attributes based on the global values. * * @since 4.0.0 * * @param array $optionOrder The order in which the options need to be called to get the relevant robots meta settings. * @param boolean $isDynamicOption Whether this is for a dynamic option. * @return void */ protected function globalValues( $optionOrder = [], $isDynamicOption = false ) { $robotsMeta = []; if ( count( $optionOrder ) ) { $options = $isDynamicOption ? aioseo()->dynamicOptions->noConflict( true )->searchAppearance : aioseo()->options->noConflict()->searchAppearance; foreach ( $optionOrder as $option ) { if ( ! $options->has( $option, false ) ) { return; } $options = $options->$option; } $clonedOptions = clone $options; if ( ! $clonedOptions->show ) { $this->attributes['noindex'] = 'noindex'; } $robotsMeta = $options->advanced->robotsMeta->all(); if ( $robotsMeta['default'] ) { $robotsMeta = aioseo()->options->searchAppearance->advanced->globalRobotsMeta->all(); } } else { $robotsMeta = aioseo()->options->searchAppearance->advanced->globalRobotsMeta->all(); } $this->attributes['max-image-preview'] = 'max-image-preview:large'; if ( $robotsMeta['default'] ) { return; } if ( $robotsMeta['noindex'] ) { $this->attributes['noindex'] = 'noindex'; } if ( $robotsMeta['nofollow'] ) { $this->attributes['nofollow'] = 'nofollow'; } if ( $robotsMeta['noarchive'] ) { $this->attributes['noarchive'] = 'noarchive'; } $noSnippet = $robotsMeta['nosnippet']; if ( $noSnippet ) { $this->attributes['nosnippet'] = 'nosnippet'; } if ( $robotsMeta['noodp'] ) { $this->attributes['noodp'] = 'noodp'; } if ( $robotsMeta['notranslate'] ) { $this->attributes['notranslate'] = 'notranslate'; } $maxSnippet = $robotsMeta['maxSnippet']; if ( ! $noSnippet && $maxSnippet && intval( $maxSnippet ) ) { $this->attributes['max-snippet'] = "max-snippet:$maxSnippet"; } $maxImagePreview = $robotsMeta['maxImagePreview']; $noImageIndex = $robotsMeta['noimageindex']; if ( ! $noImageIndex && $maxImagePreview && in_array( $maxImagePreview, [ 'none', 'standard', 'large' ], true ) ) { $this->attributes['max-image-preview'] = "max-image-preview:$maxImagePreview"; } $maxVideoPreview = $robotsMeta['maxVideoPreview']; if ( isset( $maxVideoPreview ) && is_numeric( $maxVideoPreview ) ) { $this->attributes['max-video-preview'] = "max-video-preview:$maxVideoPreview"; } // Check this last so that we can prevent max-image-preview from being output if noimageindex is enabled. if ( $noImageIndex ) { $this->attributes['max-image-preview'] = ''; $this->attributes['noimageindex'] = 'noimageindex'; } } /** * Sets the attributes from the meta data. * * @since 4.0.0 * * @param \AIOSEO\Plugin\Common\Models\Post|\AIOSEO\Plugin\Pro\Models\Term $metaData The post/term meta data. * @return void */ protected function metaValues( $metaData ) { if ( $metaData->robots_noindex || $this->isPasswordProtected() ) { $this->attributes['noindex'] = 'noindex'; } if ( $metaData->robots_nofollow ) { $this->attributes['nofollow'] = 'nofollow'; } if ( $metaData->robots_noarchive ) { $this->attributes['noarchive'] = 'noarchive'; } if ( $metaData->robots_nosnippet ) { $this->attributes['nosnippet'] = 'nosnippet'; } if ( $metaData->robots_noodp ) { $this->attributes['noodp'] = 'noodp'; } if ( $metaData->robots_notranslate ) { $this->attributes['notranslate'] = 'notranslate'; } if ( ! $metaData->robots_nosnippet && $metaData->robots_max_snippet && intval( $metaData->robots_max_snippet ) ) { $this->attributes['max-snippet'] = "max-snippet:$metaData->robots_max_snippet"; } if ( ! $metaData->robots_noimageindex && $metaData->robots_max_imagepreview && in_array( $metaData->robots_max_imagepreview, [ 'none', 'standard', 'large' ], true ) ) { $this->attributes['max-image-preview'] = "max-image-preview:$metaData->robots_max_imagepreview"; } if ( isset( $metaData->robots_max_videopreview ) && is_numeric( $metaData->robots_max_videopreview ) ) { $this->attributes['max-video-preview'] = "max-video-preview:$metaData->robots_max_videopreview"; } // Check this last so that we can prevent max-image-preview from being output if noimageindex is enabled. if ( $metaData->robots_noimageindex ) { $this->attributes['max-image-preview'] = ''; $this->attributes['noimageindex'] = 'noimageindex'; } } /** * Checks whether the current post is password protected. * * @since 4.0.0 * * @return bool Whether the post is password protected. */ private function isPasswordProtected() { $post = aioseo()->helpers->getPost(); return is_object( $post ) && $post->post_password; } }