WPSEO_Taxonomy::admin_enqueue_scripts()publicYoast 1.5.0

Queue assets for taxonomy screens.

Метод класса: WPSEO_Taxonomy{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$WPSEO_Taxonomy = new WPSEO_Taxonomy();
$WPSEO_Taxonomy->admin_enqueue_scripts();

Список изменений

С версии 1.5.0 Введена.

Код WPSEO_Taxonomy::admin_enqueue_scripts() Yoast 22.4

public function admin_enqueue_scripts() {

	$pagenow = $GLOBALS['pagenow'];

	if ( ! ( self::is_term_edit( $pagenow ) || self::is_term_overview( $pagenow ) ) ) {
		return;
	}

	$asset_manager = new WPSEO_Admin_Asset_Manager();
	$asset_manager->enqueue_style( 'scoring' );
	$asset_manager->enqueue_style( 'monorepo' );

	$tag_id = $this::get_tag_id();

	if (
		self::is_term_edit( $pagenow )
		&& ! is_null( $tag_id )
	) {
		wp_enqueue_media(); // Enqueue files needed for upload functionality.

		$asset_manager->enqueue_style( 'metabox-css' );
		$asset_manager->enqueue_style( 'ai-generator' );
		$asset_manager->enqueue_script( 'term-edit' );

		/**
		 * Remove the emoji script as it is incompatible with both React and any
		 * contenteditable fields.
		 */
		remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );

		$asset_manager->localize_script( 'term-edit', 'wpseoAdminL10n', WPSEO_Utils::get_admin_l10n() );

		$script_data = [
			'analysis'              => [
				'plugins' => [
					'replaceVars' => [
						'no_parent_text'           => __( '(no parent)', 'wordpress-seo' ),
						'replace_vars'             => $this->get_replace_vars(),
						'recommended_replace_vars' => $this->get_recommended_replace_vars(),
						'scope'                    => $this->determine_scope(),
					],
					'shortcodes' => [
						'wpseo_shortcode_tags'          => $this->get_valid_shortcode_tags(),
						'wpseo_filter_shortcodes_nonce' => wp_create_nonce( 'wpseo-filter-shortcodes' ),
					],
				],
				'worker'  => [
					'url'                     => YoastSEO()->helpers->asset->get_asset_url( 'yoast-seo-analysis-worker' ),
					'dependencies'            => YoastSEO()->helpers->asset->get_dependency_urls_by_handle( 'yoast-seo-analysis-worker' ),
					'keywords_assessment_url' => YoastSEO()->helpers->asset->get_asset_url( 'yoast-seo-used-keywords-assessment' ),
					'log_level'               => WPSEO_Utils::get_analysis_worker_log_level(),
				],
			],
			'media'                 => [
				// @todo replace this translation with JavaScript translations.
				'choose_image' => __( 'Use Image', 'wordpress-seo' ),
			],
			'metabox'               => $this->localize_term_scraper_script( $tag_id ),
			'userLanguageCode'      => WPSEO_Language_Utils::get_language( get_user_locale() ),
			'isTerm'                => true,
			'postId'                => $tag_id,
			'termType'              => $this->get_taxonomy(),
			'usedKeywordsNonce'     => wp_create_nonce( 'wpseo-keyword-usage' ),
			'linkParams'            => WPSEO_Shortlinker::get_query_params(),
			'pluginUrl'             => plugins_url( '', WPSEO_FILE ),
			'wistiaEmbedPermission' => YoastSEO()->classes->get( Wistia_Embed_Permission_Repository::class )->get_value_for_user( get_current_user_id() ),
		];
		$asset_manager->localize_script( 'term-edit', 'wpseoScriptData', $script_data );
		$asset_manager->enqueue_user_language_script();
	}

	if ( self::is_term_overview( $pagenow ) ) {
		$asset_manager->enqueue_script( 'edit-page' );
	}
}