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 22.4
public function enqueue() { global $pagenow; $asset_manager = new WPSEO_Admin_Asset_Manager(); $is_editor = self::is_post_overview( $pagenow ) || self::is_post_edit( $pagenow ); if ( self::is_post_overview( $pagenow ) ) { $asset_manager->enqueue_style( 'edit-page' ); $asset_manager->enqueue_script( 'edit-page' ); return; } /* Filter 'wpseo_always_register_metaboxes_on_admin' documented in wpseo-main.php */ if ( ( $is_editor === 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' ); $asset_manager->enqueue_style( 'scoring' ); $asset_manager->enqueue_style( 'monorepo' ); $asset_manager->enqueue_style( 'ai-generator' ); $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' => [ 'no_parent_text' => __( '(no parent)', 'wordpress-seo' ), '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(), ]; $alert_dismissal_action = YoastSEO()->classes->get( Alert_Dismissal_Action::class ); $dismissed_alerts = $alert_dismissal_action->all_dismissed(); $woocommerce_conditional = new WooCommerce_Conditional(); $woocommerce_active = $woocommerce_conditional->is_met(); $wpseo_plugin_availability_checker = new WPSEO_Plugin_Availability(); $woocommerce_seo_file = 'wpseo-woocommerce/wpseo-woocommerce.php'; $woocommerce_seo_active = $wpseo_plugin_availability_checker->is_active( $woocommerce_seo_file ); $script_data = [ // @todo replace this translation with JavaScript translations. 'media' => [ 'choose_image' => __( 'Use Image', 'wordpress-seo' ) ], 'metabox' => $this->get_metabox_script_data(), 'userLanguageCode' => WPSEO_Language_Utils::get_language( get_user_locale() ), 'isPost' => true, 'isBlockEditor' => $is_block_editor, 'postId' => $post_id, 'postStatus' => get_post_status( $post_id ), 'postType' => get_post_type( $post_id ), 'usedKeywordsNonce' => wp_create_nonce( 'wpseo-keyword-usage-and-post-types' ), 'analysis' => [ 'plugins' => $plugins_script_data, 'worker' => $worker_script_data, ], 'dismissedAlerts' => $dismissed_alerts, 'currentPromotions' => YoastSEO()->classes->get( Promotion_Manager::class )->get_current_promotions(), 'webinarIntroBlockEditorUrl' => WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-block-editor' ), 'blackFridayBlockEditorUrl' => ( YoastSEO()->classes->get( Promotion_Manager::class )->is( 'black-friday-2023-checklist' ) ) ? WPSEO_Shortlinker::get( 'https://yoa.st/black-friday-checklist' ) : '', 'isJetpackBoostActive' => ( $is_block_editor ) ? YoastSEO()->classes->get( Jetpack_Boost_Active_Conditional::class )->is_met() : false, 'isJetpackBoostNotPremium' => ( $is_block_editor ) ? YoastSEO()->classes->get( Jetpack_Boost_Not_Premium_Conditional::class )->is_met() : false, 'isWooCommerceSeoActive' => $woocommerce_seo_active, 'isWooCommerceActive' => $woocommerce_active, 'woocommerceUpsell' => get_post_type( $post_id ) === 'product' && ! $woocommerce_seo_active && $woocommerce_active, '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() ), ]; if ( post_type_supports( get_post_type(), 'thumbnail' ) ) { $asset_manager->enqueue_style( 'featured-image' ); // @todo replace this translation with JavaScript translations. $script_data['featuredImage'] = [ 'featured_image_notice' => __( 'SEO issue: The featured image should be at least 200 by 200 pixels to be picked up by Facebook and other social media sites.', 'wordpress-seo' ), ]; } $asset_manager->localize_script( $post_edit_handle, 'wpseoScriptData', $script_data ); $asset_manager->enqueue_user_language_script(); }