first commit
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\EditorOne\Classes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Active_Menu_Resolver {
|
||||
|
||||
private const HOME_SLUG = 'elementor';
|
||||
|
||||
private Url_Matcher $url_matcher;
|
||||
|
||||
public function __construct( Url_Matcher $url_matcher ) {
|
||||
$this->url_matcher = $url_matcher;
|
||||
}
|
||||
|
||||
public function resolve( array $menu_items, array $level4_groups, string $current_page, string $current_uri ): array {
|
||||
if ( 'elementor-editor' === $current_page || Menu_Config::EDITOR_MENU_SLUG === $current_page || Menu_Config::ELEMENTOR_MENU_SLUG === $current_page ) {
|
||||
return $this->create_active_state( self::HOME_SLUG );
|
||||
}
|
||||
|
||||
$pro_post_type_match = $this->get_pro_post_type_active_state();
|
||||
|
||||
if ( $pro_post_type_match ) {
|
||||
return $pro_post_type_match;
|
||||
}
|
||||
|
||||
return $this->find_best_matching_menu_item( $menu_items, $level4_groups, $current_uri );
|
||||
}
|
||||
|
||||
public function create_active_state( string $menu_slug, string $child_slug = '', int $score = 0 ): array {
|
||||
return [
|
||||
'menu_slug' => $menu_slug,
|
||||
'child_slug' => $child_slug,
|
||||
'score' => $score,
|
||||
];
|
||||
}
|
||||
|
||||
private function find_best_matching_menu_item( array $menu_items, array $level4_groups, string $current_uri ): array {
|
||||
$best_match = $this->create_active_state( '', '', -1 );
|
||||
|
||||
foreach ( $menu_items as $item ) {
|
||||
$best_match = $this->update_best_match_from_level4(
|
||||
$item,
|
||||
$level4_groups,
|
||||
$current_uri,
|
||||
$best_match
|
||||
);
|
||||
|
||||
$score = $this->url_matcher->get_match_score( $item['url'], $current_uri );
|
||||
|
||||
if ( $score > $best_match['score'] ) {
|
||||
$best_match = $this->create_active_state( $item['slug'], '', $score );
|
||||
}
|
||||
}
|
||||
|
||||
return $this->create_active_state( $best_match['menu_slug'], $best_match['child_slug'] );
|
||||
}
|
||||
|
||||
private function update_best_match_from_level4(
|
||||
array $item,
|
||||
array $level4_groups,
|
||||
string $current_uri,
|
||||
array $best_match
|
||||
): array {
|
||||
if ( empty( $item['group_id'] ) || ! isset( $level4_groups[ $item['group_id'] ] ) ) {
|
||||
return $best_match;
|
||||
}
|
||||
|
||||
$group = $level4_groups[ $item['group_id'] ];
|
||||
|
||||
if ( empty( $group['items'] ) ) {
|
||||
return $best_match;
|
||||
}
|
||||
|
||||
foreach ( $group['items'] as $child_item ) {
|
||||
$score = $this->url_matcher->get_match_score( $child_item['url'], $current_uri );
|
||||
|
||||
if ( $score > $best_match['score'] ) {
|
||||
$best_match = $this->create_active_state( $item['slug'], $child_item['slug'], $score );
|
||||
}
|
||||
}
|
||||
|
||||
return $best_match;
|
||||
}
|
||||
|
||||
private function get_pro_post_type_active_state(): ?array {
|
||||
$current_post_type = filter_input( INPUT_GET, 'post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ?? '';
|
||||
|
||||
if ( empty( $current_post_type ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Menu_Data_Provider::get_elementor_post_types()[ $current_post_type ] ?? null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\EditorOne\Classes;
|
||||
|
||||
use Elementor\User;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Editor_One_Pointer {
|
||||
|
||||
const CURRENT_POINTER_SLUG = 'e-editor-one-notice-pointer';
|
||||
|
||||
public function __construct() {
|
||||
add_action( 'admin_print_footer_scripts', [ $this, 'admin_print_script' ] );
|
||||
}
|
||||
|
||||
public function admin_print_script() {
|
||||
if ( ! $this->is_admin_user() || $this->is_dismissed() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_script( 'wp-pointer' );
|
||||
wp_enqueue_style( 'wp-pointer' );
|
||||
|
||||
$learn_more_url = 'https://go.elementor.com/wp-dash-editor-one-learn-more/';
|
||||
$pointer_content = '<h3>' . esc_html__( 'The Editor has a new home', 'elementor' ) . '</h3>';
|
||||
$pointer_content .= sprintf(
|
||||
'<p>%s <a href="%s" target="_blank">%s</a></p>',
|
||||
esc_html__( 'Editor tools are now grouped together for quick access. Build and grow your site with everything you need in one place.', 'elementor' ),
|
||||
esc_url( $learn_more_url ),
|
||||
esc_html__( 'Learn more', 'elementor' )
|
||||
);
|
||||
|
||||
$got_it_url = Menu_Config::get_elementor_home_url();
|
||||
$pointer_content .= sprintf(
|
||||
'<p><button class="button button-primary elementor-editor-one-pointer-got-it">%s</button></p>',
|
||||
esc_html__( 'Got it', 'elementor' )
|
||||
);
|
||||
|
||||
$pointer_element_selector = '#toplevel_page_' . Menu_Config::ELEMENTOR_HOME_MENU_SLUG;
|
||||
|
||||
?>
|
||||
<script>
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
setTimeout( function () {
|
||||
function markIntroductionAsViewed( redirectUrl ) {
|
||||
elementorCommon.ajax.addRequest( 'introduction_viewed', {
|
||||
data: {
|
||||
introductionKey: '<?php echo esc_attr( self::CURRENT_POINTER_SLUG ); ?>',
|
||||
},
|
||||
success: function() {
|
||||
if ( redirectUrl ) {
|
||||
window.location.href = redirectUrl;
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
$( '<?php echo esc_js( $pointer_element_selector ); ?>' ).pointer( {
|
||||
content: <?php echo wp_json_encode( $pointer_content ); ?>,
|
||||
position: {
|
||||
edge: 'top',
|
||||
align: 'left',
|
||||
at: 'left+20 bottom',
|
||||
my: 'left top'
|
||||
},
|
||||
close: function() {
|
||||
markIntroductionAsViewed();
|
||||
}
|
||||
} ).pointer( 'open' );
|
||||
|
||||
$( document ).on( 'click', '.elementor-editor-one-pointer-got-it', function( e ) {
|
||||
e.preventDefault();
|
||||
markIntroductionAsViewed( '<?php echo esc_url( $got_it_url ); ?>' );
|
||||
} );
|
||||
}, 10 );
|
||||
} );
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
private function is_dismissed() {
|
||||
return User::get_introduction_meta( self::CURRENT_POINTER_SLUG );
|
||||
}
|
||||
|
||||
private function is_admin_user() {
|
||||
return current_user_can( 'manage_options' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\EditorOne\Classes;
|
||||
|
||||
use Elementor\Core\Admin\EditorOneMenu\Menu\Legacy_Submenu_Item;
|
||||
use Elementor\Core\Admin\EditorOneMenu\Menu\Legacy_Submenu_Item_Not_Mapped;
|
||||
use Elementor\Core\Admin\EditorOneMenu\Menu\Third_Party_Pages_Menu;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Legacy_Submenu_Interceptor {
|
||||
|
||||
private Menu_Data_Provider $menu_data_provider;
|
||||
|
||||
private Slug_Normalizer $slug_normalizer;
|
||||
|
||||
private bool $third_party_parent_menu_registered = false;
|
||||
|
||||
public function __construct( Menu_Data_Provider $menu_data_provider, Slug_Normalizer $slug_normalizer ) {
|
||||
$this->menu_data_provider = $menu_data_provider;
|
||||
$this->slug_normalizer = $slug_normalizer;
|
||||
}
|
||||
|
||||
public function intercept_all( bool $is_pro_module_enabled ): void {
|
||||
global $submenu;
|
||||
|
||||
$this->intercept_elementor_menu_items(
|
||||
$submenu[ Menu_Config::ELEMENTOR_MENU_SLUG ] ?? [],
|
||||
$is_pro_module_enabled
|
||||
);
|
||||
|
||||
if ( $is_pro_module_enabled ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->intercept_templates_menu_items(
|
||||
$submenu[ Menu_Config::LEGACY_TEMPLATES_SLUG ] ?? []
|
||||
);
|
||||
}
|
||||
|
||||
public function intercept_elementor_menu_items( array $submenu_items, bool $is_pro_module_enabled ): array {
|
||||
if ( empty( $submenu_items ) ) {
|
||||
return $submenu_items;
|
||||
}
|
||||
|
||||
$legacy_pro_mapping = Menu_Config::get_legacy_pro_mapping();
|
||||
$items_to_remove = [];
|
||||
|
||||
foreach ( $submenu_items as $index => $submenu_item ) {
|
||||
$item_slug = $submenu_item[2] ?? '';
|
||||
|
||||
if ( empty( $item_slug ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $this->menu_data_provider->is_item_already_registered( $item_slug ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$mapping_key = $this->find_mapping_key( $item_slug, $legacy_pro_mapping );
|
||||
|
||||
if ( null !== $mapping_key ) {
|
||||
if ( ! $is_pro_module_enabled ) {
|
||||
$this->register_mapped_item( $submenu_item, $mapping_key, $legacy_pro_mapping );
|
||||
}
|
||||
} else {
|
||||
$this->register_unmapped_item( $submenu_item );
|
||||
}
|
||||
|
||||
$items_to_remove[] = $index;
|
||||
}
|
||||
|
||||
foreach ( $items_to_remove as $index ) {
|
||||
unset( $submenu_items[ $index ] );
|
||||
}
|
||||
|
||||
return $submenu_items;
|
||||
}
|
||||
|
||||
public function intercept_templates_menu_items( array $submenu_items ): array {
|
||||
if ( empty( $submenu_items ) ) {
|
||||
return $submenu_items;
|
||||
}
|
||||
|
||||
$items_to_remove = [];
|
||||
|
||||
foreach ( $submenu_items as $index => $submenu_item ) {
|
||||
$item_slug = $submenu_item[2] ?? '';
|
||||
|
||||
if ( empty( $item_slug ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $this->menu_data_provider->is_item_already_registered( $item_slug ) ) {
|
||||
$items_to_remove[] = $index;
|
||||
continue;
|
||||
}
|
||||
|
||||
$submenu_item[4] = Menu_Config::TEMPLATES_GROUP_ID;
|
||||
$legacy_item = new Legacy_Submenu_Item( $submenu_item, Menu_Config::LEGACY_TEMPLATES_SLUG );
|
||||
|
||||
$this->menu_data_provider->register_menu( $legacy_item );
|
||||
|
||||
$items_to_remove[] = $index;
|
||||
}
|
||||
|
||||
foreach ( $items_to_remove as $index ) {
|
||||
unset( $submenu_items[ $index ] );
|
||||
}
|
||||
|
||||
return $submenu_items;
|
||||
}
|
||||
|
||||
public function find_mapping_key( string $item_slug, array $mapping ): ?string {
|
||||
if ( isset( $mapping[ $item_slug ] ) ) {
|
||||
return $item_slug;
|
||||
}
|
||||
|
||||
$decoded_slug = html_entity_decode( $item_slug );
|
||||
|
||||
if ( isset( $mapping[ $decoded_slug ] ) ) {
|
||||
return $decoded_slug;
|
||||
}
|
||||
|
||||
$normalized_slug = $this->slug_normalizer->normalize( $item_slug );
|
||||
|
||||
foreach ( $mapping as $key => $value ) {
|
||||
$normalized_key = $this->slug_normalizer->normalize( $key );
|
||||
|
||||
if ( $normalized_slug === $normalized_key ) {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function register_mapped_item( array $submenu_item, string $mapping_key, array $legacy_pro_mapping ): void {
|
||||
$item_slug = $submenu_item[2];
|
||||
|
||||
if ( isset( $legacy_pro_mapping[ $mapping_key ]['label'] ) ) {
|
||||
$submenu_item[0] = $legacy_pro_mapping[ $mapping_key ]['label'];
|
||||
}
|
||||
|
||||
$position = Menu_Config::get_attribute_mapping()[ $item_slug ]['position'] ?? 100;
|
||||
$group_id = $legacy_pro_mapping[ $mapping_key ]['group'];
|
||||
$submenu_item[4] = $group_id;
|
||||
|
||||
$legacy_item = new Legacy_Submenu_Item( $submenu_item, Menu_Config::ELEMENTOR_MENU_SLUG, $position );
|
||||
|
||||
$this->menu_data_provider->register_menu( $legacy_item );
|
||||
}
|
||||
|
||||
private function register_unmapped_item( array $submenu_item ): void {
|
||||
$this->ensure_third_party_parent_registered();
|
||||
|
||||
$item_slug = $submenu_item[2];
|
||||
$position = Menu_Config::get_attribute_mapping()[ $item_slug ]['position'] ?? 100;
|
||||
|
||||
$legacy_item = new Legacy_Submenu_Item_Not_Mapped( $submenu_item, Menu_Config::ELEMENTOR_MENU_SLUG, $position );
|
||||
|
||||
$this->menu_data_provider->register_menu( $legacy_item );
|
||||
}
|
||||
|
||||
private function ensure_third_party_parent_registered(): void {
|
||||
if ( $this->third_party_parent_menu_registered ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->menu_data_provider->register_menu( new Third_Party_Pages_Menu() );
|
||||
$this->third_party_parent_menu_registered = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\EditorOne\Classes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Menu_Config {
|
||||
const ELEMENTOR_MENU_SLUG = 'elementor';
|
||||
const ELEMENTOR_HOME_MENU_SLUG = 'elementor-home';
|
||||
const EDITOR_MENU_SLUG = 'elementor-editor';
|
||||
const TEMPLATES_GROUP_ID = 'elementor-editor-templates';
|
||||
const SETTINGS_GROUP_ID = 'elementor-editor-settings';
|
||||
const EDITOR_GROUP_ID = 'elementor-editor-items';
|
||||
const CUSTOM_ELEMENTS_GROUP_ID = 'elementor-editor-custom-elements';
|
||||
const SYSTEM_GROUP_ID = 'elementor-editor-system';
|
||||
const THIRD_PARTY_GROUP_ID = 'elementor-editor-third-party';
|
||||
const LEGACY_TEMPLATES_SLUG = 'edit.php?post_type=elementor_library';
|
||||
const CAPABILITY_EDIT_POSTS = 'edit_posts';
|
||||
const CAPABILITY_MANAGE_OPTIONS = 'manage_options';
|
||||
const MENU_POSITION = 58.5;
|
||||
public static function get_excluded_level4_slugs(): array {
|
||||
// add new which is automatically added to templates and categories
|
||||
$default_slugs = [
|
||||
'edit-tags.php?taxonomy=elementor_library_category&post_type=elementor_library',
|
||||
];
|
||||
|
||||
return apply_filters( 'elementor/editor-one/menu/excluded_level4_slugs', $default_slugs );
|
||||
}
|
||||
|
||||
public static function get_excluded_level3_slugs(): array {
|
||||
// elementor pro slugs
|
||||
$default_slugs = [
|
||||
'elementor-theme-builder',
|
||||
'elementor-pro-notes-proxy',
|
||||
self::EDITOR_MENU_SLUG,
|
||||
];
|
||||
|
||||
return apply_filters( 'elementor/editor-one/menu/excluded_level3_slugs', $default_slugs );
|
||||
}
|
||||
|
||||
public static function get_legacy_slug_mapping(): array {
|
||||
$default_mapping = [
|
||||
self::LEGACY_TEMPLATES_SLUG => self::TEMPLATES_GROUP_ID,
|
||||
];
|
||||
|
||||
return apply_filters( 'elementor/editor-one/menu/legacy_slug_mapping', $default_mapping );
|
||||
}
|
||||
|
||||
public static function is_elementor_home_menu_available(): bool {
|
||||
return class_exists( '\ElementorOne\Loader' );
|
||||
}
|
||||
|
||||
public static function get_legacy_pro_mapping(): array {
|
||||
$default_mapping = [
|
||||
'elementor-license' => [ 'group' => self::SYSTEM_GROUP_ID ],
|
||||
'e-form-submissions' => [ 'group' => self::EDITOR_GROUP_ID ],
|
||||
'edit.php?post_type=elementor_font' => [
|
||||
'group' => self::CUSTOM_ELEMENTS_GROUP_ID,
|
||||
'label' => __( 'Fonts', 'elementor' ),
|
||||
],
|
||||
'edit.php?post_type=elementor_icons' => [
|
||||
'group' => self::CUSTOM_ELEMENTS_GROUP_ID,
|
||||
'label' => __( 'Icons', 'elementor' ),
|
||||
],
|
||||
'edit.php?post_type=elementor_snippet' => [
|
||||
'group' => self::CUSTOM_ELEMENTS_GROUP_ID,
|
||||
'label' => __( 'Code', 'elementor' ),
|
||||
],
|
||||
'e-custom-fonts' => [
|
||||
'group' => self::CUSTOM_ELEMENTS_GROUP_ID,
|
||||
'label' => __( 'Fonts', 'elementor' ),
|
||||
],
|
||||
'e-custom-icons' => [
|
||||
'group' => self::CUSTOM_ELEMENTS_GROUP_ID,
|
||||
'label' => __( 'Icons', 'elementor' ),
|
||||
],
|
||||
'e-custom-code' => [
|
||||
'group' => self::CUSTOM_ELEMENTS_GROUP_ID,
|
||||
'label' => __( 'Code', 'elementor' ),
|
||||
],
|
||||
];
|
||||
|
||||
return apply_filters( 'elementor/editor-one/menu/legacy_pro_mapping', $default_mapping );
|
||||
}
|
||||
|
||||
public static function get_attribute_mapping(): array {
|
||||
$default_mapping = [
|
||||
'e-form-submissions' => [
|
||||
'position' => 50,
|
||||
'icon' => 'send',
|
||||
],
|
||||
];
|
||||
|
||||
return apply_filters( 'elementor/editor-one/menu/position_mapping', $default_mapping );
|
||||
}
|
||||
|
||||
public static function get_custom_code_url(): string {
|
||||
$pro_custom_code_cpt = 'elementor_snippet';
|
||||
|
||||
if ( post_type_exists( $pro_custom_code_cpt ) ) {
|
||||
$default_url = admin_url( 'edit.php?post_type=' . $pro_custom_code_cpt );
|
||||
} else {
|
||||
$default_url = admin_url( 'admin.php?page=elementor_custom_code' );
|
||||
}
|
||||
|
||||
return apply_filters( 'elementor/editor-one/menu/custom_code_url', $default_url );
|
||||
}
|
||||
|
||||
public static function get_elementor_home_url(): string {
|
||||
return admin_url( 'admin.php?page=' . self::ELEMENTOR_MENU_SLUG );
|
||||
}
|
||||
|
||||
public static function get_elementor_post_types(): array {
|
||||
$default_values = [
|
||||
'elementor_icons' => [
|
||||
'menu_slug' => 'elementor-custom-elements',
|
||||
'child_slug' => 'edit.php?post_type=elementor_icons',
|
||||
],
|
||||
'elementor_font' => [
|
||||
'menu_slug' => 'elementor-custom-elements',
|
||||
'child_slug' => 'edit.php?post_type=elementor_font',
|
||||
],
|
||||
'elementor_snippet' => [
|
||||
'menu_slug' => 'elementor-custom-elements',
|
||||
'child_slug' => 'edit.php?post_type=elementor_snippet',
|
||||
],
|
||||
];
|
||||
|
||||
return apply_filters( 'elementor/editor-one/menu/elementor_post_types', $default_values );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,574 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\EditorOne\Classes;
|
||||
|
||||
use Elementor\Core\Admin\EditorOneMenu\Interfaces\Menu_Item_Interface;
|
||||
use Elementor\Core\Admin\EditorOneMenu\Interfaces\Menu_Item_Third_Level_Interface;
|
||||
use Elementor\Core\Admin\EditorOneMenu\Interfaces\Menu_Item_With_Custom_Url_Interface;
|
||||
use Elementor\Plugin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Menu_Data_Provider {
|
||||
public const THIRD_LEVEL_EDITOR_FLYOUT = 'editor_flyout';
|
||||
public const THIRD_LEVEL_FLYOUT_MENU = 'flyout_menu';
|
||||
|
||||
private static ?Menu_Data_Provider $instance = null;
|
||||
private array $level3_items = [];
|
||||
private array $level4_items = [];
|
||||
private ?string $theme_builder_url = null;
|
||||
private ?array $cached_level3_sidebar_data = null;
|
||||
private ?array $cached_level4_sidebar_data = null;
|
||||
private ?array $cached_flyout_menu_data = null;
|
||||
private Slug_Normalizer $slug_normalizer;
|
||||
|
||||
public static function instance(): self {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
$this->slug_normalizer = new Slug_Normalizer();
|
||||
}
|
||||
|
||||
public function get_slug_normalizer(): Slug_Normalizer {
|
||||
return $this->slug_normalizer;
|
||||
}
|
||||
|
||||
public function register_menu( Menu_Item_Interface $item ): void {
|
||||
if ( ! ( $item instanceof Menu_Item_Third_Level_Interface ) ) {
|
||||
$this->register_level4_item( $item );
|
||||
return;
|
||||
}
|
||||
|
||||
$group_id = $item->get_group_id();
|
||||
$collapsible_groups = [
|
||||
Menu_Config::TEMPLATES_GROUP_ID,
|
||||
Menu_Config::CUSTOM_ELEMENTS_GROUP_ID,
|
||||
Menu_Config::SYSTEM_GROUP_ID,
|
||||
];
|
||||
|
||||
if ( in_array( $group_id, $collapsible_groups, true ) && ! $item->has_children() ) {
|
||||
$this->register_level4_item( $item );
|
||||
} else {
|
||||
$this->register_level3_item( $item );
|
||||
}
|
||||
}
|
||||
|
||||
public function register_level3_item( Menu_Item_Third_Level_Interface $item ): void {
|
||||
$group_id = $item->get_group_id();
|
||||
$item_slug = $item->get_slug();
|
||||
|
||||
if ( ! isset( $this->level3_items[ $group_id ] ) ) {
|
||||
$this->level3_items[ $group_id ] = [];
|
||||
}
|
||||
|
||||
$this->level3_items[ $group_id ][ $item_slug ] = $item;
|
||||
|
||||
$this->invalidate_cache();
|
||||
}
|
||||
|
||||
public function register_level4_item( Menu_Item_Interface $item ): void {
|
||||
$group_id = $item->get_group_id();
|
||||
$item_slug = $item->get_slug();
|
||||
|
||||
if ( ! isset( $this->level4_items[ $group_id ] ) ) {
|
||||
$this->level4_items[ $group_id ] = [];
|
||||
}
|
||||
|
||||
$this->level4_items[ $group_id ][ $item_slug ] = $item;
|
||||
$this->invalidate_cache();
|
||||
}
|
||||
|
||||
public function get_level3_items(): array {
|
||||
return $this->level3_items;
|
||||
}
|
||||
|
||||
public function get_level4_items(): array {
|
||||
return $this->level4_items;
|
||||
}
|
||||
|
||||
public function is_item_already_registered( string $item_slug ): bool {
|
||||
$all_items = array_merge( $this->level3_items, $this->level4_items );
|
||||
|
||||
foreach ( $all_items as $group_items ) {
|
||||
if ( isset( $group_items[ $item_slug ] ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_third_level_data( string $variant ): array {
|
||||
if ( self::THIRD_LEVEL_EDITOR_FLYOUT === $variant ) {
|
||||
return $this->get_third_level_data_from_cache(
|
||||
$this->cached_level3_sidebar_data,
|
||||
[ $this, 'build_level3_flyout_items' ]
|
||||
);
|
||||
}
|
||||
|
||||
if ( self::THIRD_LEVEL_FLYOUT_MENU === $variant ) {
|
||||
return $this->get_third_level_data_from_cache(
|
||||
$this->cached_flyout_menu_data,
|
||||
[ $this, 'build_flyout_items_with_expanded_third_party' ]
|
||||
);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public function get_level4_flyout_data(): array {
|
||||
if ( null !== $this->cached_level4_sidebar_data ) {
|
||||
return $this->cached_level4_sidebar_data;
|
||||
}
|
||||
|
||||
$groups = $this->build_level4_flyout_groups();
|
||||
|
||||
foreach ( $groups as $group_id => $group ) {
|
||||
if ( ! empty( $group['items'] ) ) {
|
||||
$this->sort_items_by_priority( $groups[ $group_id ]['items'] );
|
||||
}
|
||||
}
|
||||
|
||||
$this->cached_level4_sidebar_data = $groups;
|
||||
|
||||
return $this->cached_level4_sidebar_data;
|
||||
}
|
||||
|
||||
private function get_third_level_data_from_cache( ?array &$cache, callable $items_builder ): array {
|
||||
if ( null !== $cache ) {
|
||||
return $cache;
|
||||
}
|
||||
|
||||
$items = $items_builder();
|
||||
|
||||
$this->sort_items_by_priority( $items );
|
||||
|
||||
$cache = [
|
||||
'parent_slug' => Menu_Config::EDITOR_MENU_SLUG,
|
||||
'items' => $items,
|
||||
];
|
||||
|
||||
return $cache;
|
||||
}
|
||||
|
||||
public function get_theme_builder_url(): string {
|
||||
if ( null === $this->theme_builder_url ) {
|
||||
$pro_url = Plugin::$instance->app ? Plugin::$instance->app->get_settings( 'menu_url' ) : null;
|
||||
$return_to = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) );
|
||||
|
||||
if ( $pro_url ) {
|
||||
if ( false !== strpos( $pro_url, '#' ) ) {
|
||||
$url = $this->add_return_to_url( $pro_url, $return_to );
|
||||
} else {
|
||||
$url = $pro_url;
|
||||
}
|
||||
} else {
|
||||
$url = $this->add_return_to_url(
|
||||
admin_url( 'admin.php?page=elementor-app' ) . '#/site-editor/promotion',
|
||||
$return_to
|
||||
);
|
||||
}
|
||||
|
||||
$this->theme_builder_url = apply_filters( 'elementor/editor-one/menu/theme_builder_url', $url );
|
||||
}
|
||||
|
||||
return $this->theme_builder_url;
|
||||
}
|
||||
|
||||
private function add_return_to_url( string $url, string $return_to ): string {
|
||||
$hash_position = strpos( $url, '#' );
|
||||
|
||||
if ( false === $hash_position ) {
|
||||
return add_query_arg( [ 'return_to' => $return_to ], $url );
|
||||
}
|
||||
|
||||
$base_url = substr( $url, 0, $hash_position );
|
||||
$hash_fragment = substr( $url, $hash_position );
|
||||
|
||||
return add_query_arg( [ 'return_to' => $return_to ], $base_url ) . $hash_fragment;
|
||||
}
|
||||
|
||||
public function get_all_sidebar_page_slugs(): array {
|
||||
$base_slugs = [
|
||||
Menu_Config::ELEMENTOR_MENU_SLUG,
|
||||
Menu_Config::EDITOR_MENU_SLUG,
|
||||
];
|
||||
|
||||
$slugs = array_merge(
|
||||
$base_slugs,
|
||||
$this->get_dynamic_page_slugs()
|
||||
);
|
||||
|
||||
return array_values( array_unique( $slugs ) );
|
||||
}
|
||||
|
||||
public function is_elementor_editor_page(): bool {
|
||||
if ( ! get_current_screen() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ?? '';
|
||||
|
||||
if ( Menu_Config::ELEMENTOR_HOME_MENU_SLUG === $page ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( in_array( $page, $this->get_all_sidebar_page_slugs(), true ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$post_type = filter_input( INPUT_GET, 'post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ?? '';
|
||||
|
||||
return $this->is_elementor_post_type( $post_type );
|
||||
}
|
||||
|
||||
public function is_editor_one_post_edit_screen(): bool {
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( ! $screen || empty( $screen->post_type ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 'post' !== $screen->base ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$post_types = apply_filters( 'elementor/editor-one/admin-edit-post-types', [] );
|
||||
|
||||
return in_array( $screen->post_type, $post_types, true );
|
||||
}
|
||||
|
||||
public function is_editor_one_admin_page(): bool {
|
||||
return $this->is_elementor_editor_page() || $this->is_editor_one_post_edit_screen();
|
||||
}
|
||||
|
||||
private function is_elementor_post_type( string $post_type ): bool {
|
||||
if ( empty( $post_type ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isset( Menu_Config::get_elementor_post_types()[ $post_type ] );
|
||||
}
|
||||
|
||||
public static function get_elementor_post_types(): array {
|
||||
return Menu_Config::get_elementor_post_types();
|
||||
}
|
||||
|
||||
private function get_dynamic_page_slugs(): array {
|
||||
$slugs = [];
|
||||
|
||||
foreach ( $this->level3_items as $group_items ) {
|
||||
$slugs = array_merge( $slugs, array_keys( $group_items ) );
|
||||
}
|
||||
|
||||
foreach ( $this->level4_items as $group_items ) {
|
||||
foreach ( $group_items as $item_slug => $item ) {
|
||||
$slugs[] = $item_slug;
|
||||
}
|
||||
}
|
||||
|
||||
$allowed_prefixes = [ 'elementor', 'e-', 'popup_templates' ];
|
||||
|
||||
return array_values( array_filter( $slugs, function( string $slug ) use ( $allowed_prefixes ): bool {
|
||||
foreach ( $allowed_prefixes as $prefix ) {
|
||||
if ( 0 === strpos( $slug, $prefix ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} ) );
|
||||
}
|
||||
|
||||
private function build_level3_flyout_items(): array {
|
||||
return $this->build_flyout_items( false );
|
||||
}
|
||||
|
||||
private function build_flyout_items_with_expanded_third_party(): array {
|
||||
return $this->build_flyout_items( true );
|
||||
}
|
||||
|
||||
private function build_flyout_items( bool $expand_third_party ): array {
|
||||
$items = [];
|
||||
$existing_slugs = [];
|
||||
$excluded_slugs = Menu_Config::get_excluded_level3_slugs();
|
||||
$excluded_level4_slugs = $expand_third_party ? Menu_Config::get_excluded_level4_slugs() : [];
|
||||
|
||||
foreach ( $this->level3_items as $group_items ) {
|
||||
foreach ( $group_items as $item_slug => $item ) {
|
||||
if ( ! $this->should_include_flyout_item( $item, $item_slug, $existing_slugs, $excluded_slugs ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $expand_third_party && $this->is_third_party_parent_with_children( $item ) ) {
|
||||
$children = $this->level4_items[ Menu_Config::THIRD_PARTY_GROUP_ID ] ?? [];
|
||||
$is_first_child = true;
|
||||
|
||||
foreach ( $children as $child_slug => $child ) {
|
||||
if ( ! $this->is_item_accessible( $child ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $this->is_slug_excluded( $child_slug, $excluded_level4_slugs, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( in_array( $child_slug, $existing_slugs, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$child_data = $this->create_expanded_child_item_data( $child, $child_slug, $is_first_child );
|
||||
$items[] = $child_data;
|
||||
$existing_slugs[] = $child_slug;
|
||||
$is_first_child = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$items[] = $this->create_flyout_item_data( $item, $item_slug );
|
||||
$existing_slugs[] = $item_slug;
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function is_third_party_parent_with_children( Menu_Item_Interface $item ): bool {
|
||||
if ( Menu_Config::THIRD_PARTY_GROUP_ID !== $item->get_group_id() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $item->has_children() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$children = $this->level4_items[ Menu_Config::THIRD_PARTY_GROUP_ID ] ?? [];
|
||||
|
||||
return ! empty( $children );
|
||||
}
|
||||
|
||||
private function create_expanded_child_item_data( Menu_Item_Interface $item, string $item_slug, bool $is_first ): array {
|
||||
$url = $this->resolve_item_url( $item, $item_slug );
|
||||
|
||||
return [
|
||||
'slug' => $item_slug,
|
||||
'label' => $this->title_case( $item->get_label() ),
|
||||
'url' => $url,
|
||||
'group_id' => '',
|
||||
'priority' => $this->get_item_priority( $item ),
|
||||
'has_divider_before' => $is_first,
|
||||
];
|
||||
}
|
||||
|
||||
private function should_include_flyout_item( Menu_Item_Interface $item, string $item_slug, array $existing_slugs, array $excluded_slugs ): bool {
|
||||
if ( ! $this->is_item_accessible( $item ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( in_array( $item_slug, $existing_slugs, true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->is_slug_excluded( $item_slug, $excluded_slugs ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( trim( wp_strip_all_tags( $item->get_label() ) ) ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function create_flyout_item_data( Menu_Item_Interface $item, string $item_slug ): array {
|
||||
$has_children = $item->has_children();
|
||||
$group_id = $has_children ? $item->get_group_id() : '';
|
||||
$is_third_party_parent = Menu_Config::THIRD_PARTY_GROUP_ID === $item->get_group_id();
|
||||
|
||||
return [
|
||||
'slug' => $item_slug,
|
||||
'label' => $this->title_case( $item->get_label() ),
|
||||
'url' => $this->resolve_flyout_item_url( $item, $item_slug ),
|
||||
'icon' => $item->get_icon(),
|
||||
'group_id' => $group_id,
|
||||
'priority' => $this->get_item_priority( $item ),
|
||||
'has_divider_before' => $is_third_party_parent,
|
||||
];
|
||||
}
|
||||
|
||||
private function resolve_flyout_item_url( Menu_Item_Interface $item, string $item_slug ): string {
|
||||
$url = $this->resolve_item_url( $item, $item_slug );
|
||||
|
||||
if ( ! $item->has_children() ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$children = $this->get_level4_items()[ $item->get_group_id() ] ?? [];
|
||||
|
||||
if ( empty( $children ) ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$first_child_url = $this->get_first_accessible_child_url( $children );
|
||||
|
||||
return $first_child_url ?? $url;
|
||||
}
|
||||
|
||||
private function get_first_accessible_child_url( array $children ): ?string {
|
||||
$children_data = [];
|
||||
|
||||
foreach ( $children as $child_slug => $child_item ) {
|
||||
if ( ! $this->is_item_accessible( $child_item ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$children_data[] = [
|
||||
'url' => $this->resolve_item_url( $child_item, $child_slug ),
|
||||
'priority' => $this->get_item_priority( $child_item ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( empty( $children_data ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->sort_items_by_priority( $children_data );
|
||||
|
||||
return $children_data[0]['url'];
|
||||
}
|
||||
|
||||
private function build_level4_flyout_groups(): array {
|
||||
$groups = [];
|
||||
$excluded_slugs = Menu_Config::get_excluded_level4_slugs();
|
||||
|
||||
foreach ( $this->level4_items as $group_id => $items ) {
|
||||
$groups[ $group_id ] = [ 'items' => [] ];
|
||||
$existing_labels = [];
|
||||
|
||||
foreach ( $items as $item_slug => $item ) {
|
||||
if ( ! $this->is_item_accessible( $item ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $this->is_slug_excluded( $item_slug, $excluded_slugs, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$label = $item->get_label();
|
||||
$label_lower = strtolower( $label );
|
||||
|
||||
if ( in_array( $label_lower, $existing_labels, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$url = $this->resolve_item_url( $item, $item_slug );
|
||||
|
||||
$groups[ $group_id ]['items'][] = [
|
||||
'slug' => $item_slug,
|
||||
'label' => $this->title_case( $item->get_label() ),
|
||||
'url' => $url,
|
||||
'priority' => $this->get_item_priority( $item ),
|
||||
];
|
||||
|
||||
$existing_labels[] = $label_lower;
|
||||
}
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
public function is_item_accessible( Menu_Item_Interface $item ): bool {
|
||||
return $item->is_visible() && current_user_can( $item->get_capability() );
|
||||
}
|
||||
|
||||
private function get_item_url( string $item_slug, ?string $parent_slug = null ): string {
|
||||
$admin_path_prefixes = [ 'edit.php', 'post-new.php', 'admin.php' ];
|
||||
|
||||
foreach ( $admin_path_prefixes as $prefix ) {
|
||||
if ( 0 === strpos( $item_slug, $prefix ) ) {
|
||||
return admin_url( $item_slug );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 === strpos( $item_slug, 'http' ) ) {
|
||||
return $item_slug;
|
||||
}
|
||||
|
||||
if ( $parent_slug && 0 === strpos( $parent_slug, 'edit.php' ) ) {
|
||||
return admin_url( $parent_slug . '&page=' . $item_slug );
|
||||
}
|
||||
|
||||
return admin_url( 'admin.php?page=' . $item_slug );
|
||||
}
|
||||
|
||||
private function resolve_item_url( Menu_Item_Interface $item, string $item_slug ): string {
|
||||
if ( $item instanceof Menu_Item_With_Custom_Url_Interface ) {
|
||||
return $item->get_menu_url();
|
||||
}
|
||||
|
||||
return $this->get_item_url( $item_slug, $item->get_parent_slug() );
|
||||
}
|
||||
|
||||
private function get_item_priority( Menu_Item_Interface $item ): int {
|
||||
return $item->get_position() ?? 100;
|
||||
}
|
||||
|
||||
private function is_slug_excluded( string $item_slug, array $excluded_slugs, bool $use_normalizer = false ): bool {
|
||||
if ( $use_normalizer ) {
|
||||
return $this->slug_normalizer->is_excluded( $item_slug, $excluded_slugs );
|
||||
}
|
||||
|
||||
return in_array( $item_slug, $excluded_slugs, true );
|
||||
}
|
||||
|
||||
private function sort_items_by_priority( array &$items ): void {
|
||||
usort( $items, function ( array $a, array $b ): int {
|
||||
return ( $a['priority'] ?? 100 ) <=> ( $b['priority'] ?? 100 );
|
||||
} );
|
||||
}
|
||||
|
||||
private function title_case( string $text ): string {
|
||||
if ( function_exists( 'mb_convert_case' ) ) {
|
||||
return mb_convert_case( $text, MB_CASE_TITLE, 'UTF-8' );
|
||||
}
|
||||
|
||||
return ucwords( strtolower( $text ) );
|
||||
}
|
||||
|
||||
private function invalidate_cache(): void {
|
||||
$this->cached_level3_sidebar_data = null;
|
||||
$this->cached_level4_sidebar_data = null;
|
||||
$this->cached_flyout_menu_data = null;
|
||||
}
|
||||
|
||||
public static function get_current_user_capabilities(): array {
|
||||
$user = wp_get_current_user();
|
||||
|
||||
if ( ! $user || ! $user->exists() ) {
|
||||
return [
|
||||
'user' => null,
|
||||
'has_edit_posts' => false,
|
||||
'has_manage_options' => false,
|
||||
'is_edit_posts_user' => false,
|
||||
];
|
||||
}
|
||||
|
||||
$has_edit_posts = isset( $user->allcaps[ Menu_Config::CAPABILITY_EDIT_POSTS ] ) && $user->allcaps[ Menu_Config::CAPABILITY_EDIT_POSTS ];
|
||||
$has_manage_options = isset( $user->allcaps[ Menu_Config::CAPABILITY_MANAGE_OPTIONS ] ) && $user->allcaps[ Menu_Config::CAPABILITY_MANAGE_OPTIONS ];
|
||||
$is_edit_posts_user = $has_edit_posts && ! $has_manage_options;
|
||||
|
||||
return [
|
||||
'user' => $user,
|
||||
'has_edit_posts' => $has_edit_posts,
|
||||
'has_manage_options' => $has_manage_options,
|
||||
'is_edit_posts_user' => $is_edit_posts_user,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\EditorOne\Classes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Slug_Normalizer {
|
||||
|
||||
public function normalize( string $slug ): string {
|
||||
if ( 0 !== strpos( $slug, 'http' ) ) {
|
||||
return $slug;
|
||||
}
|
||||
|
||||
$parsed = wp_parse_url( $slug );
|
||||
$path = basename( $parsed['path'] ?? '' );
|
||||
|
||||
if ( ! empty( $parsed['query'] ) ) {
|
||||
$path .= '?' . $parsed['query'];
|
||||
}
|
||||
|
||||
if ( ! empty( $parsed['fragment'] ) ) {
|
||||
$path .= '#' . $parsed['fragment'];
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function is_excluded( string $item_slug, array $excluded_slugs ): bool {
|
||||
if ( in_array( $item_slug, $excluded_slugs, true ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$normalized_slug = $this->normalize( $item_slug );
|
||||
|
||||
return in_array( $normalized_slug, $excluded_slugs, true );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\EditorOne\Classes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Url_Matcher {
|
||||
|
||||
public function get_match_score( string $menu_url, string $current_uri ): int {
|
||||
$menu_parsed = wp_parse_url( $menu_url );
|
||||
|
||||
if ( empty( $menu_parsed['path'] ) ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
$current_parsed = wp_parse_url( $current_uri );
|
||||
|
||||
if ( empty( $current_parsed['path'] ) ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( basename( $menu_parsed['path'] ) !== basename( $current_parsed['path'] ) ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
$menu_query = $this->parse_query_string( $menu_parsed['query'] ?? '' );
|
||||
$current_query = $this->parse_query_string( $current_parsed['query'] ?? '' );
|
||||
|
||||
if ( ! $this->query_params_match( $menu_query, $current_query ) ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return count( $menu_query );
|
||||
}
|
||||
|
||||
public function parse_query_string( string $query ): array {
|
||||
$params = [];
|
||||
|
||||
if ( '' !== $query ) {
|
||||
parse_str( $query, $params );
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function query_params_match( array $required, array $actual ): bool {
|
||||
foreach ( $required as $key => $value ) {
|
||||
if ( ! isset( $actual[ $key ] ) || $actual[ $key ] !== $value ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\EditorOne\Components;
|
||||
|
||||
use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
|
||||
use Elementor\Modules\EditorOne\Classes\Active_Menu_Resolver;
|
||||
use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
|
||||
use Elementor\Modules\EditorOne\Classes\Url_Matcher;
|
||||
use Elementor\Modules\EditorOne\Classes\Menu_Config;
|
||||
use Elementor\Utils;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Sidebar_Navigation_Handler {
|
||||
|
||||
private const PROMOTION_URL = 'https://go.elementor.com/go-pro-upgrade-wp-editor-inner-menu/';
|
||||
|
||||
private Menu_Data_Provider $menu_data_provider;
|
||||
|
||||
private Active_Menu_Resolver $active_menu_resolver;
|
||||
|
||||
public function __construct() {
|
||||
$this->menu_data_provider = Menu_Data_Provider::instance();
|
||||
$this->active_menu_resolver = new Active_Menu_Resolver( new Url_Matcher() );
|
||||
$this->register_actions();
|
||||
}
|
||||
|
||||
private function register_actions(): void {
|
||||
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_sidebar_assets' ] );
|
||||
add_action( 'in_admin_header', [ $this, 'render_sidebar_container' ] );
|
||||
add_filter( 'admin_body_class', [ $this, 'add_body_class' ] );
|
||||
}
|
||||
|
||||
public function add_body_class( string $classes ): string {
|
||||
if ( ! $this->menu_data_provider->is_editor_one_admin_page() ) {
|
||||
return $classes;
|
||||
}
|
||||
|
||||
$classes .= ' e-has-sidebar-navigation';
|
||||
|
||||
if ( Menu_Config::is_elementor_home_menu_available() ) {
|
||||
$classes .= ' e-has-elementor-home-menu';
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
public function enqueue_sidebar_assets(): void {
|
||||
if ( ! $this->menu_data_provider->is_editor_one_admin_page() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$min_suffix = Utils::is_script_debug() ? '' : '.min';
|
||||
|
||||
wp_enqueue_style(
|
||||
'elementor-sidebar-navigation',
|
||||
ELEMENTOR_ASSETS_URL . 'css/modules/editor-one/sidebar-navigation' . $min_suffix . '.css',
|
||||
[],
|
||||
ELEMENTOR_VERSION
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'editor-one-sidebar-navigation',
|
||||
ELEMENTOR_ASSETS_URL . 'js/editor-one-sidebar-navigation' . $min_suffix . '.js',
|
||||
[
|
||||
'react',
|
||||
'react-dom',
|
||||
'elementor-common',
|
||||
'elementor-v2-ui',
|
||||
'elementor-v2-icons',
|
||||
],
|
||||
ELEMENTOR_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'editor-one-sidebar-navigation',
|
||||
'editorOneSidebarConfig',
|
||||
$this->get_sidebar_config()
|
||||
);
|
||||
|
||||
wp_set_script_translations( 'editor-one-sidebar-navigation', 'elementor' );
|
||||
}
|
||||
|
||||
public function render_sidebar_container(): void {
|
||||
if ( ! $this->menu_data_provider->is_editor_one_admin_page() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div id="editor-one-sidebar-navigation"></div>';
|
||||
}
|
||||
|
||||
private function get_sidebar_config(): array {
|
||||
$flyout_data = $this->menu_data_provider->get_third_level_data(
|
||||
Menu_Data_Provider::THIRD_LEVEL_EDITOR_FLYOUT
|
||||
);
|
||||
$level4_groups = $this->menu_data_provider->get_level4_flyout_data();
|
||||
$promotion = $this->get_promotion_data();
|
||||
$active_state = $this->get_active_menu_state( $flyout_data['items'], $level4_groups );
|
||||
|
||||
return [
|
||||
'menuItems' => $flyout_data['items'],
|
||||
'level4Groups' => $level4_groups,
|
||||
'activeMenuSlug' => $active_state['menu_slug'],
|
||||
'activeChildSlug' => $active_state['child_slug'],
|
||||
'siteTitle' => esc_html__( 'Editor', 'elementor' ),
|
||||
'hasPro' => Utils::has_pro(),
|
||||
'upgradeUrl' => $promotion['url'],
|
||||
'upgradeText' => $promotion['text'],
|
||||
];
|
||||
}
|
||||
|
||||
private function get_promotion_data(): array {
|
||||
return Filtered_Promotions_Manager::get_filtered_promotion_data(
|
||||
[
|
||||
'text' => esc_html__( 'Upgrade plan', 'elementor' ),
|
||||
'url' => self::PROMOTION_URL,
|
||||
],
|
||||
'elementor/sidebar/promotion',
|
||||
'url'
|
||||
);
|
||||
}
|
||||
|
||||
private function get_active_menu_state( array $menu_items, array $level4_groups ): array {
|
||||
$current_page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ?? '';
|
||||
$current_uri = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) );
|
||||
|
||||
return $this->active_menu_resolver->resolve( $menu_items, $level4_groups, $current_page, $current_uri );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\EditorOne\Components;
|
||||
|
||||
use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
|
||||
use Elementor\Utils;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Top_Bar_Handler {
|
||||
|
||||
private Menu_Data_Provider $menu_data_provider;
|
||||
|
||||
public function __construct() {
|
||||
$this->menu_data_provider = Menu_Data_Provider::instance();
|
||||
$this->register_actions();
|
||||
}
|
||||
|
||||
private function register_actions(): void {
|
||||
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
|
||||
add_action( 'in_admin_header', [ $this, 'render_top_bar_container' ] );
|
||||
}
|
||||
|
||||
public function enqueue_assets(): void {
|
||||
if ( ! $this->menu_data_provider->is_editor_one_admin_page() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$min_suffix = Utils::is_script_debug() ? '' : '.min';
|
||||
|
||||
wp_enqueue_style(
|
||||
'elementor-one-top-bar',
|
||||
ELEMENTOR_ASSETS_URL . 'css/modules/editor-one/top-bar' . $min_suffix . '.css',
|
||||
[],
|
||||
ELEMENTOR_VERSION
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'editor-one-top-bar',
|
||||
ELEMENTOR_ASSETS_URL . 'js/editor-one-top-bar' . $min_suffix . '.js',
|
||||
[
|
||||
'react',
|
||||
'react-dom',
|
||||
'elementor-common',
|
||||
'elementor-v2-ui',
|
||||
'elementor-v2-icons',
|
||||
],
|
||||
ELEMENTOR_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'editor-one-top-bar',
|
||||
'elementorOneTopBarConfig',
|
||||
[
|
||||
'version' => ELEMENTOR_VERSION,
|
||||
'title' => __( 'website builder', 'elementor' ),
|
||||
'environment' => apply_filters( 'elementor/environment', 'production' ),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function render_top_bar_container(): void {
|
||||
if ( ! $this->menu_data_provider->is_editor_one_admin_page() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div id="editor-one-top-bar"></div>';
|
||||
}
|
||||
}
|
||||
131
wp-content/plugins/elementor/modules/editor-one/module.php
Normal file
131
wp-content/plugins/elementor/modules/editor-one/module.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\EditorOne;
|
||||
|
||||
use Elementor\Core\Admin\EditorOneMenu\Elementor_One_Menu_Manager;
|
||||
use Elementor\Core\Base\Module as BaseModule;
|
||||
use Elementor\Core\Experiments\Manager as Experiments_Manager;
|
||||
use Elementor\Modules\EditorOne\Classes\Editor_One_Pointer;
|
||||
use Elementor\Modules\EditorOne\Classes\Menu_Config;
|
||||
use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
|
||||
use Elementor\Modules\EditorOne\Components\Sidebar_Navigation_Handler;
|
||||
use Elementor\Modules\EditorOne\Components\Top_Bar_Handler;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
class Module extends BaseModule {
|
||||
|
||||
const EXPERIMENT_NAME = 'e_editor_one';
|
||||
|
||||
const CUSTOM_REACT_APP_PAGES = [
|
||||
'elementor-element-manager',
|
||||
];
|
||||
|
||||
public function get_name(): string {
|
||||
return 'editor-one';
|
||||
}
|
||||
|
||||
public static function is_active(): bool {
|
||||
return Menu_Config::is_elementor_home_menu_available();
|
||||
}
|
||||
|
||||
public static function get_experimental_data(): array {
|
||||
return [
|
||||
'name' => static::EXPERIMENT_NAME,
|
||||
'title' => esc_html__( 'Editor one', 'elementor' ),
|
||||
'description' => esc_html__( 'General', 'elementor' ),
|
||||
'hidden' => true,
|
||||
'default' => Experiments_Manager::STATE_ACTIVE,
|
||||
'release_status' => Experiments_Manager::RELEASE_STATUS_STABLE,
|
||||
'mutable' => false,
|
||||
];
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
if ( is_admin() ) {
|
||||
$this->add_component( 'editor-one-menu-manager', new Elementor_One_Menu_Manager() );
|
||||
$this->add_component( 'sidebar-navigation-handler', new Sidebar_Navigation_Handler() );
|
||||
$this->add_component( 'top-bar-handler', new Top_Bar_Handler() );
|
||||
$this->add_component( 'editor-one-pointer', new Editor_One_Pointer() );
|
||||
}
|
||||
|
||||
add_action( 'current_screen', function () {
|
||||
$menu_data_provider = Menu_Data_Provider::instance();
|
||||
|
||||
if ( ! $menu_data_provider->is_editor_one_admin_page() || ! static::is_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'admin_enqueue_scripts', function () {
|
||||
$this->enqueue_styles();
|
||||
} );
|
||||
} );
|
||||
|
||||
add_filter( 'elementor/admin-top-bar/is-active', function ( $is_active ) {
|
||||
return static::is_active() ? false : $is_active;
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current page has a custom React app that uses @elementor/ui
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_custom_react_app_page() {
|
||||
$current_screen = get_current_screen();
|
||||
|
||||
if ( ! $current_screen ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( self::CUSTOM_REACT_APP_PAGES as $page_slug ) {
|
||||
if ( str_contains( $current_screen->id ?? '', $page_slug ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue admin styles
|
||||
*/
|
||||
private function enqueue_styles() {
|
||||
|
||||
wp_enqueue_style( 'elementor-admin' );
|
||||
|
||||
wp_enqueue_style(
|
||||
'elementor-editor-one-common',
|
||||
$this->get_css_assets_url( 'editor-one-common' ),
|
||||
[ 'elementor-admin' ],
|
||||
ELEMENTOR_VERSION
|
||||
);
|
||||
|
||||
if ( ! $this->is_custom_react_app_page() ) {
|
||||
wp_enqueue_style(
|
||||
'elementor-editor-one-elements',
|
||||
$this->get_css_assets_url( 'editor-one-elements' ),
|
||||
[ 'elementor-editor-one-common' ],
|
||||
ELEMENTOR_VERSION
|
||||
);
|
||||
|
||||
wp_enqueue_style(
|
||||
'elementor-editor-one-tables',
|
||||
$this->get_css_assets_url( 'editor-one-tables' ),
|
||||
[ 'elementor-editor-one-common' ],
|
||||
ELEMENTOR_VERSION
|
||||
);
|
||||
}
|
||||
|
||||
wp_enqueue_script(
|
||||
'editor-one-admin',
|
||||
$this->get_js_assets_url( 'editor-one-admin' ),
|
||||
[ 'jquery' ],
|
||||
ELEMENTOR_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user