admin-bar-menu.php
3 years ago
ajax-pagination.php
2 years ago
class-ecs-core.php
2 months ago
class-ecs-module-base.php
1 month ago
class-ecs-modules-manager.php
2 months ago
dynamic-style.php
3 years ago
ecs-dependencies.php
6 years ago
ecs-notices.php
6 years ago
enqueue-styles.php
2 years ago
pro-features.php
2 months ago
pro-preview.php
6 years ago
admin-bar-menu.php
91 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 | |
| 5 | class ECS_Admin_Bar_Menu { |
| 6 | |
| 7 | private static $admin_bar_edit_documents = []; |
| 8 | private static $wp_admin_bar=[]; |
| 9 | |
| 10 | public static function instance() { |
| 11 | |
| 12 | if ( is_null( self::$_instance ) ) { |
| 13 | self::$_instance = new self(); |
| 14 | } |
| 15 | return self::$_instance; |
| 16 | |
| 17 | } |
| 18 | |
| 19 | public function __construct() { |
| 20 | |
| 21 | $this->init(); |
| 22 | |
| 23 | } |
| 24 | |
| 25 | public function init() { |
| 26 | |
| 27 | } |
| 28 | |
| 29 | public static function add_document( $post_id ) { |
| 30 | if ( post_password_required( $post_id ) ) { |
| 31 | return ''; |
| 32 | } |
| 33 | |
| 34 | if ( ! get_post_meta( $post_id, '_elementor_edit_mode', true ) ) { |
| 35 | return ''; |
| 36 | } |
| 37 | |
| 38 | $document = \Elementor\Plugin::$instance->documents->get_doc_for_frontend( $post_id ); |
| 39 | |
| 40 | // Change the current post, so widgets can use `documents->get_current`. |
| 41 | \Elementor\Plugin::$instance->documents->switch_to_document( $document ); |
| 42 | |
| 43 | if ( $document->is_editable_by_current_user() ) { |
| 44 | self::$admin_bar_edit_documents[ $document->get_main_id() ] = $document; |
| 45 | } |
| 46 | \Elementor\Plugin::$instance->documents->restore_document(); |
| 47 | } |
| 48 | |
| 49 | private static function add_menu_in_admin_bar() { |
| 50 | if ( empty( self::$admin_bar_edit_documents ) ) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | $queried_object_id = get_queried_object_id(); |
| 55 | |
| 56 | |
| 57 | if ( is_singular() && isset( self::$admin_bar_edit_documents[ $queried_object_id ] ) ) { |
| 58 | $menu_args['href'] = self::$admin_bar_edit_documents[ $queried_object_id ]->get_edit_url(); |
| 59 | unset( self::$admin_bar_edit_documents[ $queried_object_id ] ); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | |
| 64 | foreach ( self::$admin_bar_edit_documents as $document ) { |
| 65 | self::$wp_admin_bar[] = [ |
| 66 | 'id' => 'wp-admin-bar-elementor_edit_doc_' . $document->get_main_id(), |
| 67 | 'parent' => 'wp-admin-bar-elementor_edit_page-default', |
| 68 | 'title' => sprintf( '<span class="elementor-edit-link-title">%s</span><span class="elementor-edit-link-type">%s</span>', $document->get_post()->post_title, $document::get_title() ), |
| 69 | 'href' => $document->get_edit_url(), |
| 70 | ] ; |
| 71 | } |
| 72 | } |
| 73 | public static function get_menu_args(){ |
| 74 | self::add_menu_in_admin_bar(); |
| 75 | return json_encode(self::$wp_admin_bar); |
| 76 | } |
| 77 | |
| 78 | public static function write_js(){ |
| 79 | if(is_admin_bar_showing()){ |
| 80 | |
| 81 | echo '<script src="'.ELECS_URL.'assets/js/ecs_admin_bar_menu.js"></script><script>'; |
| 82 | echo 'ECS_update_admin_bar_menu('.self::get_menu_args().');'; |
| 83 | echo '</script>'; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | } |
| 88 | |
| 89 | add_action('wp_footer',function(){ |
| 90 | ECS_Admin_Bar_Menu::write_js(); |
| 91 | }); |