| 1 |
<?php |
| 2 |
namespace Elementor\Core\Editor\Loader; |
| 3 |
|
| 4 |
use Elementor\Api; |
| 5 |
use Elementor\Core\Debug\Loading_Inspection_Manager; |
| 6 |
use Elementor\Core\Settings\Manager as SettingsManager; |
| 7 |
use Elementor\Group_Control_Typography; |
| 8 |
use Elementor\Icons_Manager; |
| 9 |
use Elementor\Modules\Apps\Module as AppsModule; |
| 10 |
use Elementor\Core\Common\Modules\EventsManager\Module as EditorEventsModule; |
| 11 |
use Elementor\Modules\Home\Module as Home_Module; |
| 12 |
use Elementor\Plugin; |
| 13 |
use Elementor\Settings; |
| 14 |
use Elementor\Shapes; |
| 15 |
use Elementor\Tools; |
| 16 |
use Elementor\User; |
| 17 |
use Elementor\Utils; |
| 18 |
use Elementor\Core\Utils\Hints; |
| 19 |
use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager; |
| 20 |
|
| 21 |
if ( ! defined( 'ABSPATH' ) ) { |
| 22 |
exit; // Exit if accessed directly. |
| 23 |
} |
| 24 |
|
| 25 |
class Editor_Scripts_Settings { |
| 26 |
public static function get() { |
| 27 |
$settings = SettingsManager::get_settings_managers_config(); |
| 28 |
// Moved to document since 2.9.0. |
| 29 |
unset( $settings['page'] ); |
| 30 |
|
| 31 |
$document = Plugin::$instance->documents->get_doc_or_auto_save( Plugin::$instance->editor->get_post_id() ); |
| 32 |
$kits_manager = Plugin::$instance->kits_manager; |
| 33 |
|
| 34 |
$page_title_selector = $kits_manager->get_current_settings( 'page_title_selector' ); |
| 35 |
$top_bar_connect_app = Plugin::$instance->common->get_component( 'connect' )->get_app( 'activate' ) ?? Plugin::$instance->common->get_component( 'connect' )->get_app( 'library' ); |
| 36 |
|
| 37 |
$page_title_selector .= ', .elementor-page-title .elementor-heading-title'; |
| 38 |
|
| 39 |
$client_env = [ |
| 40 |
'initial_document' => $document->get_config(), |
| 41 |
'version' => ELEMENTOR_VERSION, |
| 42 |
'home_url' => home_url(), |
| 43 |
'admin_settings_url' => admin_url( 'admin.php?page=' . Home_Module::get_elementor_settings_page_id() ), |
| 44 |
'admin_tools_url' => admin_url( 'admin.php?page=' . Tools::PAGE_ID ), |
| 45 |
'admin_apps_url' => admin_url( 'admin.php?page=' . AppsModule::PAGE_ID ), |
| 46 |
'autosave_interval' => AUTOSAVE_INTERVAL, |
| 47 |
'tabs' => Plugin::$instance->controls_manager->get_tabs(), |
| 48 |
'controls' => Plugin::$instance->controls_manager->get_controls_data(), |
| 49 |
'elements' => Plugin::$instance->elements_manager->get_element_types_config(), |
| 50 |
'globals' => [ |
| 51 |
'defaults_enabled' => [ |
| 52 |
'colors' => $kits_manager->is_custom_colors_enabled(), |
| 53 |
'typography' => $kits_manager->is_custom_typography_enabled(), |
| 54 |
], |
| 55 |
], |
| 56 |
'icons' => [ |
| 57 |
'libraries' => Icons_Manager::get_icon_manager_tabs_config(), |
| 58 |
'goProURL' => 'https://go.elementor.com/go-pro-icon-library/', |
| 59 |
], |
| 60 |
'fa4_to_fa5_mapping_url' => ELEMENTOR_ASSETS_URL . 'lib/font-awesome/migration/mapping.js', |
| 61 |
'settings' => $settings, |
| 62 |
'wp_editor' => static::get_wp_editor_config(), |
| 63 |
'settings_page_link' => Settings::get_url(), |
| 64 |
'tools_page_link' => Tools::get_url(), |
| 65 |
'tools_page_nonce' => wp_create_nonce( 'tools-page-from-editor' ), |
| 66 |
'elementor_site' => 'https://go.elementor.com/about-elementor/', |
| 67 |
'docs_elementor_site' => 'https://go.elementor.com/docs/', |
| 68 |
'help_the_content_url' => 'https://go.elementor.com/the-content-missing/', |
| 69 |
'help_flexbox_bc_url' => 'https://go.elementor.com/flexbox-layout-bc/', |
| 70 |
'elementPromotionURL' => 'https://go.elementor.com/go-pro-%s', |
| 71 |
'dynamicPromotionURL' => 'https://go.elementor.com/go-pro-dynamic-tag', |
| 72 |
'additional_shapes' => Shapes::get_additional_shapes_for_config(), |
| 73 |
'user' => [ |
| 74 |
'restrictions' => Plugin::$instance->role_manager->get_user_restrictions_array(), |
| 75 |
'is_administrator' => current_user_can( 'manage_options' ), |
| 76 |
'introduction' => User::get_introduction_meta(), |
| 77 |
'dismissed_editor_notices' => User::get_dismissed_editor_notices(), |
| 78 |
'locale' => get_user_locale(), |
| 79 |
'top_bar' => [ |
| 80 |
'connect_url' => $top_bar_connect_app->get_admin_url( 'authorize', [ |
| 81 |
'utm_source' => 'editor-app', |
| 82 |
'utm_campaign' => 'connect-account', |
| 83 |
'utm_medium' => 'wp-dash', |
| 84 |
'utm_term' => '1.0.0', |
| 85 |
'utm_content' => 'cta-link', |
| 86 |
'source' => 'generic', |
| 87 |
'mode' => 'popup', |
| 88 |
] ), |
| 89 |
'my_elementor_url' => 'https://go.elementor.com/wp-dash-top-bar-account/', |
| 90 |
], |
| 91 |
], |
| 92 |
'preview' => [ |
| 93 |
'help_preview_error_url' => 'https://go.elementor.com/preview-not-loaded/', |
| 94 |
'help_preview_http_error_url' => 'https://go.elementor.com/preview-not-loaded/#permissions', |
| 95 |
'help_preview_http_error_500_url' => 'https://go.elementor.com/500-error/', |
| 96 |
'debug_data' => Loading_Inspection_Manager::instance()->run_inspections(), |
| 97 |
], |
| 98 |
'locale' => get_locale(), |
| 99 |
'rich_editing_enabled' => filter_var( get_user_meta( get_current_user_id(), 'rich_editing', true ), FILTER_VALIDATE_BOOLEAN ), |
| 100 |
'page_title_selector' => $page_title_selector, |
| 101 |
'tinymceHasCustomConfig' => class_exists( 'Tinymce_Advanced' ) || class_exists( 'Advanced_Editor_Tools' ), |
| 102 |
'inlineEditing' => Plugin::$instance->widgets_manager->get_inline_editing_config(), |
| 103 |
'dynamicTags' => Plugin::$instance->dynamic_tags->get_config(), |
| 104 |
'ui' => [ |
| 105 |
'defaultGenericFonts' => $kits_manager->get_current_settings( 'default_generic_fonts' ), |
| 106 |
], |
| 107 |
// Empty array for BC to avoid errors. |
| 108 |
'i18n' => [], |
| 109 |
// 'responsive' contains the custom breakpoints config introduced in Elementor v3.2.0 |
| 110 |
'responsive' => [ |
| 111 |
'breakpoints' => Plugin::$instance->breakpoints->get_breakpoints_config(), |
| 112 |
'icons_map' => Plugin::$instance->breakpoints->get_responsive_icons_classes_map(), |
| 113 |
], |
| 114 |
'promotion' => [ |
| 115 |
'elements' => Plugin::$instance->editor->promotion->get_elements_promotion(), |
| 116 |
'integration' => [ |
| 117 |
'ally-accessibility' => Hints::get_ally_action_data(), |
| 118 |
], |
| 119 |
], |
| 120 |
'editor_events' => EditorEventsModule::get_editor_events_config(), |
| 121 |
'promotions' => [ |
| 122 |
'notes' => Filtered_Promotions_Manager::get_filtered_promotion_data( |
| 123 |
[ 'upgrade_url' => 'https://go.elementor.com/go-pro-notes/' ], |
| 124 |
'elementor/panel/notes/custom_promotion', |
| 125 |
'upgrade_url' |
| 126 |
), |
| 127 |
], |
| 128 |
'fontVariableRanges' => Group_Control_Typography::get_font_variable_ranges(), |
| 129 |
]; |
| 130 |
|
| 131 |
if ( Plugin::$instance->experiments->is_feature_active( 'container' ) ) { |
| 132 |
$client_env['elementsPresets'] = Plugin::$instance->editor->get_elements_presets(); |
| 133 |
} |
| 134 |
|
| 135 |
$is_admin_user_without_pro = current_user_can( 'manage_options' ) && ! Utils::has_pro(); |
| 136 |
if ( $is_admin_user_without_pro ) { |
| 137 |
$client_env['integrationWidgets'] = array_merge( |
| 138 |
( isset( $client_env['integrationWidgets'] ) && is_array( $client_env['integrationWidgets'] ) ? |
| 139 |
$client_env['integrationWidgets'] : |
| 140 |
[] ), [ |
| 141 |
[ |
| 142 |
'categories' => '[ "general" ]', |
| 143 |
'icon' => 'eicon-accessibility', |
| 144 |
'name' => 'ally-accessibility', |
| 145 |
'title' => esc_html__( 'Ally Accessibility', 'elementor' ), |
| 146 |
'keywords' => [ |
| 147 |
'Accessibility', |
| 148 |
'Usability', |
| 149 |
'Inclusive', |
| 150 |
'Statement', |
| 151 |
'WCAG', |
| 152 |
'Ally', |
| 153 |
'Compliance', |
| 154 |
], |
| 155 |
], |
| 156 |
], |
| 157 |
); |
| 158 |
} |
| 159 |
|
| 160 |
static::bc_move_document_filters(); |
| 161 |
|
| 162 |
/** |
| 163 |
* Localize editor settings. |
| 164 |
* |
| 165 |
* Filters the editor localized settings. |
| 166 |
* |
| 167 |
* @since 1.0.0 |
| 168 |
* |
| 169 |
* @param array $client_env Editor configuration. |
| 170 |
* @param int $post_id The ID of the current post being edited. |
| 171 |
*/ |
| 172 |
$client_env = apply_filters( 'elementor/editor/localize_settings', $client_env ); |
| 173 |
|
| 174 |
if ( $is_admin_user_without_pro ) { |
| 175 |
$client_env = self::ensure_pro_widgets( $client_env ); |
| 176 |
} |
| 177 |
|
| 178 |
if ( ! empty( $client_env['promotionWidgets'] ) && is_array( $client_env['promotionWidgets'] ) ) { |
| 179 |
$client_env['promotionWidgets'] = self::ensure_numeric_keys( $client_env['promotionWidgets'] ); |
| 180 |
} |
| 181 |
|
| 182 |
return $client_env; |
| 183 |
} |
| 184 |
|
| 185 |
private static function ensure_pro_widgets( array $client_env ) { |
| 186 |
$pro_widgets = Api::get_promotion_widgets(); |
| 187 |
if ( ! isset( $client_env['promotionWidgets'] ) ) { |
| 188 |
$client_env['promotionWidgets'] = $pro_widgets; |
| 189 |
} else { |
| 190 |
$client_env['promotionWidgets'] = array_merge( $pro_widgets, $client_env['promotionWidgets'] ); |
| 191 |
} |
| 192 |
return $client_env; |
| 193 |
} |
| 194 |
|
| 195 |
private static function ensure_numeric_keys( array $base_array ) { |
| 196 |
return array_values( $base_array ); |
| 197 |
} |
| 198 |
|
| 199 |
private static function bc_move_document_filters() { |
| 200 |
global $wp_filter; |
| 201 |
|
| 202 |
$old_tag = 'elementor/editor/localize_settings'; |
| 203 |
$new_tag = 'elementor/document/config'; |
| 204 |
|
| 205 |
if ( ! has_filter( $old_tag ) ) { |
| 206 |
return; |
| 207 |
} |
| 208 |
|
| 209 |
foreach ( $wp_filter[ $old_tag ] as $priority => $filters ) { |
| 210 |
foreach ( $filters as $filter_id => $filter_args ) { |
| 211 |
if ( 2 === $filter_args['accepted_args'] ) { |
| 212 |
remove_filter( $old_tag, $filter_id, $priority ); |
| 213 |
|
| 214 |
add_filter( $new_tag, $filter_args['function'], $priority, 2 ); |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
/** |
| 221 |
* Get WordPress editor config. |
| 222 |
* |
| 223 |
* Config the default WordPress editor with custom settings for Elementor use. |
| 224 |
* |
| 225 |
* @since 1.9.0 |
| 226 |
* @access private |
| 227 |
*/ |
| 228 |
private static function get_wp_editor_config() { |
| 229 |
// Remove all TinyMCE plugins. |
| 230 |
remove_all_filters( 'mce_buttons', 10 ); |
| 231 |
remove_all_filters( 'mce_external_plugins', 10 ); |
| 232 |
|
| 233 |
if ( ! class_exists( '\_WP_Editors', false ) ) { |
| 234 |
require ABSPATH . WPINC . '/class-wp-editor.php'; |
| 235 |
} |
| 236 |
|
| 237 |
// WordPress 4.8 and higher |
| 238 |
if ( method_exists( '\_WP_Editors', 'print_tinymce_scripts' ) ) { |
| 239 |
\_WP_Editors::print_default_editor_scripts(); |
| 240 |
\_WP_Editors::print_tinymce_scripts(); |
| 241 |
} |
| 242 |
ob_start(); |
| 243 |
|
| 244 |
wp_editor( |
| 245 |
'%%EDITORCONTENT%%', |
| 246 |
'elementorwpeditor', |
| 247 |
[ |
| 248 |
'editor_class' => 'elementor-wp-editor', |
| 249 |
'editor_height' => 250, |
| 250 |
'drag_drop_upload' => true, |
| 251 |
] |
| 252 |
); |
| 253 |
|
| 254 |
$config = ob_get_clean(); |
| 255 |
|
| 256 |
// Don't call \_WP_Editors methods again |
| 257 |
remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'editor_js' ], 50 ); |
| 258 |
remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'print_default_editor_scripts' ], 45 ); |
| 259 |
|
| 260 |
\_WP_Editors::editor_js(); |
| 261 |
|
| 262 |
return $config; |
| 263 |
} |
| 264 |
} |
| 265 |
|