PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.0
Elementor Website Builder – more than just a page builder v4.1.0
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / admin / menu / base.php

base.php in Elementor Website Builder – more than just a page builder 4.1.0, at core/admin/menu/base.php

90 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Admin\Menu;
3
4 use Elementor\Core\Base\Base_Object;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10 abstract class Base extends Base_Object {
11
12 private $args;
13
14 private $submenus = [];
15
16 abstract protected function get_init_args();
17
18 public function __construct() {
19 $this->init_args();
20
21 add_action( 'admin_menu', function() {
22 $this->register();
23 } );
24 }
25
26 public function get_args( $arg = null ) {
27 return self::get_items( $this->args, $arg );
28 }
29
30 public function add_submenu( $submenu_args ) {
31 $default_submenu_args = [
32 'page_title' => '',
33 'capability' => $this->args['capability'],
34 'function' => null,
35 'index' => null,
36 ];
37
38 $this->submenus[] = array_merge( $default_submenu_args, $submenu_args );
39 }
40
41 protected function register_default_submenus() {}
42
43 protected function register() {
44 $args = $this->args;
45
46 add_menu_page( $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'], $args['icon_url'], $args['position'] );
47
48 $this->register_default_submenus();
49
50 do_action( 'elementor/admin/menu_registered/' . $args['menu_slug'], $this );
51
52 usort( $this->submenus, function( $a, $b ) {
53 return $a['index'] - $b['index'];
54 } );
55
56 foreach ( $this->submenus as $index => $submenu_item ) {
57 $submenu_args = [
58 $args['menu_slug'],
59 $submenu_item['page_title'],
60 $submenu_item['menu_title'],
61 $submenu_item['capability'],
62 $submenu_item['menu_slug'],
63 $submenu_item['function'],
64 ];
65
66 if ( 0 === $submenu_item['index'] ) {
67 $submenu_args[] = 0;
68 }
69
70 add_submenu_page( ...$submenu_args );
71
72 if ( ! empty( $submenu_item['class'] ) ) {
73 global $submenu;
74
75 $submenu[ $args['menu_slug'] ][ $index + 1 ][4] = $submenu_item['class']; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
76 }
77 }
78 }
79
80 private function init_args() {
81 $default_args = [
82 'function' => null,
83 'icon_url' => null,
84 'position' => null,
85 ];
86
87 $this->args = array_merge( $default_args, $this->get_init_args() );
88 }
89 }
90