WPSEO_Metabox::enqueue │ public │ Yoast 1.0
Enqueues all the needed JS and CSS.
Метод класса: WPSEO_Metabox{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
$WPSEO_Metabox = new WPSEO_Metabox(); $WPSEO_Metabox->enqueue();
Код WPSEO_Metabox::enqueue() WPSEO Metabox::enqueue Yoast 27.4
public function enqueue() {
global $pagenow;
if ( $this->readability_analysis->is_enabled() ) {
$this->editor = new WPSEO_Metabox_Editor();
$this->editor->register_hooks();
}
$asset_manager = new WPSEO_Admin_Asset_Manager();
if ( self::is_post_overview( $pagenow ) ) {
return;
}
/* Filter 'wpseo_always_register_metaboxes_on_admin' documented in wpseo-main.php */
if ( ( self::is_post_edit( $pagenow ) === false && apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) === false ) || $this->display_metabox() === false ) {
return;
}
$post_id = get_queried_object_id();
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( empty( $post_id ) && isset( $_GET['post'] ) && is_string( $_GET['post'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
$post_id = sanitize_text_field( wp_unslash( $_GET['post'] ) );
}
if ( $post_id !== 0 ) {
// Enqueue files needed for upload functionality.
wp_enqueue_media( [ 'post' => $post_id ] );
}
$asset_manager->enqueue_style( 'metabox-css' );
if ( $this->readability_analysis->is_enabled() ) {
$asset_manager->enqueue_style( 'scoring' );
}
$asset_manager->enqueue_style( 'monorepo' );
$asset_manager->enqueue_style( 'ai-generator' );
$asset_manager->enqueue_style( 'ai-fix-assessments' );
$is_block_editor = WP_Screen::get()->is_block_editor();
$post_edit_handle = 'post-edit';
if ( ! $is_block_editor ) {
$post_edit_handle = 'post-edit-classic';
}
$asset_manager->enqueue_script( $post_edit_handle );
$asset_manager->enqueue_style( 'admin-css' );
/**
* Removes 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( $post_edit_handle, 'wpseoAdminL10n', WPSEO_Utils::get_admin_l10n() );
$plugins_script_data = [
'replaceVars' => [
'replace_vars' => $this->get_replace_vars(),
'hidden_replace_vars' => $this->get_hidden_replace_vars(),
'recommended_replace_vars' => $this->get_recommended_replace_vars(),
'scope' => $this->determine_scope(),
'has_taxonomies' => $this->current_post_type_has_taxonomies(),
],
'shortcodes' => [
'wpseo_shortcode_tags' => $this->get_valid_shortcode_tags(),
'wpseo_filter_shortcodes_nonce' => wp_create_nonce( 'wpseo-filter-shortcodes' ),
],
];
$worker_script_data = [
'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(),
];
$page_on_front = (int) get_option( 'page_on_front' );
$homepage_is_page = get_option( 'show_on_front' ) === 'page';
$is_front_page = $homepage_is_page && $page_on_front === (int) $post_id;
$script_data = [
'metabox' => $this->get_metabox_script_data(),
'isPost' => true,
'isBlockEditor' => $is_block_editor,
'postId' => $post_id,
'postStatus' => get_post_status( $post_id ),
'postType' => get_post_type( $post_id ),
'isPage' => get_post_type( $post_id ) === 'page',
'usedKeywordsNonce' => wp_create_nonce( 'wpseo-keyword-usage-and-post-types' ),
'analysis' => [
'plugins' => $plugins_script_data,
'worker' => $worker_script_data,
],
'isFrontPage' => $is_front_page,
];
/**
* The website information repository.
*
* @var Website_Information_Repository $repo
*/
$repo = YoastSEO()->classes->get( Website_Information_Repository::class );
$site_information = $repo->get_post_site_information();
$site_information->set_permalink( $this->get_permalink() );
$script_data = array_merge_recursive( $site_information->get_legacy_site_information(), $script_data );
if ( ! $is_block_editor && post_type_supports( get_post_type(), 'thumbnail' ) ) {
$asset_manager->enqueue_style( 'featured-image' );
}
$asset_manager->localize_script( $post_edit_handle, 'wpseoScriptData', $script_data );
}