Skip to content

Commit 3fea9c8

Browse files
committed
enqueue language script only when one of the analysis related features is enabled
1 parent ca7047a commit 3fea9c8

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

admin/class-config.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ public function config_page_scripts() {
119119
}
120120

121121
$this->asset_manager->localize_script( 'settings', 'wpseoScriptData', $script_data );
122-
$this->asset_manager->enqueue_user_language_script();
123122
}
124123

125124
/**

admin/metabox/class-metabox.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ class WPSEO_Metabox extends WPSEO_Meta {
6363
*/
6464
protected $is_advanced_metadata_enabled;
6565

66+
/**
67+
* Whether the insights feature is enabled.
68+
*
69+
* @var bool
70+
*/
71+
protected $is_insights_enabled;
72+
73+
/**
74+
* Whether the cornerstone content feature is enabled.
75+
*
76+
* @var bool
77+
*/
78+
protected $is_cornerstone_enabled;
79+
6680
/**
6781
* Class constructor.
6882
*/
@@ -85,6 +99,8 @@ public function __construct() {
8599
$this->seo_analysis = new WPSEO_Metabox_Analysis_SEO();
86100
$this->readability_analysis = new WPSEO_Metabox_Analysis_Readability();
87101
$this->inclusive_language_analysis = new WPSEO_Metabox_Analysis_Inclusive_Language();
102+
$this->is_insights_enabled = WPSEO_Options::get( 'enable_metabox_insights', false );
103+
$this->is_cornerstone_enabled = WPSEO_Options::get( 'enable_cornerstone_content', false );
88104
}
89105

90106
/**
@@ -912,7 +928,10 @@ public function enqueue() {
912928
}
913929

914930
$asset_manager->localize_script( $post_edit_handle, 'wpseoScriptData', $script_data );
915-
$asset_manager->enqueue_user_language_script();
931+
932+
if ( $this->readability_analysis->is_enabled() || $this->inclusive_language_analysis->is_enabled() || $this->seo_analysis->is_enabled() || $this->is_insights_enabled || $this->is_cornerstone_enabled ) {
933+
$asset_manager->enqueue_user_language_script();
934+
}
916935
}
917936

918937
/**

admin/taxonomy/class-taxonomy.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ class WPSEO_Taxonomy {
4141
*/
4242
private $analysis_inclusive_language;
4343

44+
/**
45+
* Whether the insights feature is enabled.
46+
*
47+
* @var bool
48+
*/
49+
protected $is_insights_enabled;
50+
51+
/**
52+
* Whether the cornerstone content feature is enabled.
53+
*
54+
* @var bool
55+
*/
56+
protected $is_cornerstone_enabled;
57+
4458
/**
4559
* Class constructor.
4660
*/
@@ -57,6 +71,8 @@ public function __construct() {
5771
$this->analysis_seo = new WPSEO_Metabox_Analysis_SEO();
5872
$this->analysis_readability = new WPSEO_Metabox_Analysis_Readability();
5973
$this->analysis_inclusive_language = new WPSEO_Metabox_Analysis_Inclusive_Language();
74+
$this->is_insights_enabled = WPSEO_Options::get( 'enable_metabox_insights', false );
75+
$this->is_cornerstone_enabled = WPSEO_Options::get( 'enable_cornerstone_content', false );
6076
}
6177

6278
/**
@@ -201,8 +217,10 @@ public function admin_enqueue_scripts() {
201217
$script_data = array_merge_recursive( $term_information->get_legacy_site_information(), $script_data );
202218

203219
$asset_manager->localize_script( 'term-edit', 'wpseoScriptData', $script_data );
204-
$asset_manager->enqueue_user_language_script();
205220

221+
if ( $this->analysis_readability->is_enabled() || $this->analysis_inclusive_language->is_enabled() || $this->analysis_seo->is_enabled() || $this->is_insights_enabled || $this->is_cornerstone_enabled ) {
222+
$asset_manager->enqueue_user_language_script();
223+
}
206224
}
207225

208226
if ( self::is_term_overview( $pagenow ) ) {

src/integrations/third-party/elementor.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ class Elementor implements Integration_Interface {
105105
*/
106106
protected $promotion_manager;
107107

108+
/**
109+
* Whether the insights feature is enabled.
110+
*
111+
* @var bool
112+
*/
113+
protected $is_insights_enabled;
114+
115+
/**
116+
* Whether the cornerstone content feature is enabled.
117+
*
118+
* @var bool
119+
*/
120+
protected $is_cornerstone_enabled;
121+
108122
/**
109123
* Returns the conditionals based in which this loadable should be active.
110124
*
@@ -138,6 +152,8 @@ public function __construct(
138152
$this->inclusive_language_analysis = new WPSEO_Metabox_Analysis_Inclusive_Language();
139153
$this->social_is_enabled = $this->options->get( 'opengraph', false ) || $this->options->get( 'twitter', false );
140154
$this->is_advanced_metadata_enabled = $this->capability->current_user_can( 'wpseo_edit_advanced_metadata' ) || $this->options->get( 'disableadvanced_meta' ) === false;
155+
$this->is_insights_enabled = $this->options->get( 'enable_metabox_insights', false );
156+
$this->is_cornerstone_enabled = $this->options->get( 'enable_cornerstone_content', false );
141157
}
142158

143159
/**
@@ -439,7 +455,9 @@ public function enqueue() {
439455
$script_data = \array_merge_recursive( $site_information->get_legacy_site_information(), $script_data );
440456

441457
$this->asset_manager->localize_script( 'elementor', 'wpseoScriptData', $script_data );
442-
$this->asset_manager->enqueue_user_language_script();
458+
if ( $this->readability_analysis->is_enabled() || $this->inclusive_language_analysis->is_enabled() || $this->seo_analysis->is_enabled() || $this->is_insights_enabled || $this->is_cornerstone_enabled ) {
459+
$asset_manager->enqueue_user_language_script();
460+
}
443461
}
444462

445463
/**

0 commit comments

Comments
 (0)