PluginProbe
Sky Addons for Elementor / trunk
Sky Addons for Elementor vtrunk
4.0.0 3.8.5 3.8.4 3.8.3 3.8.2 3.8.0 3.8.1 3.3.3 3.3.2 trunk 1.0.0 1.0.10 1.0.2 1.0.6 1.0.7 1.0.8 1.0.9 1.5.0 2.0.0 2.0.8 2.5.10 2.5.11 2.5.12 2.5.13 2.5.15 All 53 releases
sky-elementor-addons / includes / admin / class-menu.php

class-menu.php in Sky Addons for Elementor trunk, at includes/admin/class-menu.php

209 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Menu class
4 *
5 * @package Sky_Addons\Admin
6 * @since 2.7.0
7 */
8
9 namespace Sky_Addons\Admin;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Description of Menu
17 *
18 * @since 2.7.0
19 */
20 class Menu {
21 /**
22 * Constructor
23 *
24 * @return void
25 * @since 2.7.0
26 */
27 public function __construct() {
28 add_action( 'admin_menu', [ $this, 'admin_menu' ] );
29 add_filter( 'custom_menu_order', '__return_true' );
30 add_filter( 'menu_order', [ $this, 'place_after_elementor' ], 999 );
31 add_filter( 'plugin_action_links_' . plugin_basename( SKY_ADDONS__FILE__ ), [ $this, 'add_action_links' ] );
32 }
33
34 /**
35 * Keep Sky Addons directly below Elementor in the admin menu.
36 *
37 * A fixed position cannot do this. Elementor's legacy menu sits at 58.5, its
38 * Editor One menu (`elementor-home`) lands elsewhere, and themes or admin tools
39 * can reorder the whole menu on top of that. Following Elementor's slug keeps
40 * the Elementor group together wherever it ends up.
41 *
42 * @param array $menu_order Top-level menu slugs, in display order.
43 * @return array
44 * @since 4.0.0
45 */
46 public function place_after_elementor( $menu_order ) {
47 if ( ! is_array( $menu_order ) ) {
48 return $menu_order;
49 }
50
51 $sky_index = array_search( 'sky-addons', $menu_order, true );
52 if ( false === $sky_index ) {
53 return $menu_order;
54 }
55
56 $without_sky = array_values( array_diff( $menu_order, [ 'sky-addons' ] ) );
57
58 // Last Elementor top-level item, so Sky Addons follows the whole group.
59 $elementor_index = false;
60 foreach ( $without_sky as $index => $slug ) {
61 if ( in_array( $slug, [ 'elementor', 'elementor-home' ], true ) ) {
62 $elementor_index = $index;
63 }
64 }
65
66 // No Elementor menu for this user: leave the order untouched.
67 if ( false === $elementor_index ) {
68 return $menu_order;
69 }
70
71 array_splice( $without_sky, $elementor_index + 1, 0, [ 'sky-addons' ] );
72
73 return $without_sky;
74 }
75
76 /**
77 * Register admin menu
78 *
79 * @return void
80 * @since 2.6.5
81 */
82 public function admin_menu() {
83 $parent_slug = 'sky-addons';
84 $capability = 'manage_options';
85 // Sky Addons Pro's White Label can change both. Defaults stay when it is off or Pro is absent.
86 $menu_title = apply_filters( 'sky_addons/white_label/menu_title', 'Sky Addons' );
87 $menu_icon = apply_filters( 'sky_addons/white_label/menu_icon', $this->get_b64_icon() );
88 add_menu_page( $menu_title, $menu_title, $capability, $parent_slug, [ $this, 'plugin_layout' ], $menu_icon, 59 );
89
90 // add_menu_page() derives every submenu hook name from the title (`{sanitize_title( title )}_page_{slug}`).
91 // Pin it to the default so a White Label title never changes a `sky-addons_page_*` hook name.
92 global $admin_page_hooks;
93 $admin_page_hooks[ $parent_slug ] = 'sky-addons';
94
95 add_submenu_page( $parent_slug, esc_html__( 'Dashboard', 'sky-elementor-addons' ), esc_html__( 'Dashboard', 'sky-elementor-addons' ), $capability, $parent_slug, [
96 $this,
97 'plugin_layout',
98 ] );
99
100 add_submenu_page( $parent_slug, esc_html__( 'Widgets', 'sky-elementor-addons' ), esc_html__( 'Widgets', 'sky-elementor-addons' ), $capability, $parent_slug . '#widgets', [
101 $this,
102 'plugin_layout',
103 ] );
104
105 add_submenu_page( $parent_slug, esc_html__( 'Extensions', 'sky-elementor-addons' ), esc_html__( 'Extensions', 'sky-elementor-addons' ), $capability, $parent_slug . '#extensions', [
106 $this,
107 'plugin_layout',
108 ] );
109
110 add_submenu_page( $parent_slug, esc_html__( 'Integrations', 'sky-elementor-addons' ), esc_html__( 'Integrations', 'sky-elementor-addons' ), $capability, $parent_slug . '#thirdparty', [
111 $this,
112 'plugin_layout',
113 ] );
114
115 add_submenu_page( $parent_slug, esc_html__( 'API Settings', 'sky-elementor-addons' ), esc_html__( 'API Settings', 'sky-elementor-addons' ), $capability, $parent_slug . '#api', [
116 $this,
117 'plugin_layout',
118 ] );
119
120 add_submenu_page( $parent_slug, esc_html__( 'Theme Builder', 'sky-elementor-addons' ), esc_html__( 'Theme Builder', 'sky-elementor-addons' ), $capability, $parent_slug . '#theme_builder', [
121 $this,
122 'plugin_layout',
123 ] );
124
125 add_submenu_page( $parent_slug, esc_html__( 'Custom Scripts', 'sky-elementor-addons' ), esc_html__( 'Custom Scripts', 'sky-elementor-addons' ), $capability, $parent_slug . '#custom_scripts', [
126 $this,
127 'plugin_layout',
128 ] );
129
130 add_submenu_page( $parent_slug, esc_html__( 'Advanced', 'sky-elementor-addons' ), esc_html__( 'Advanced', 'sky-elementor-addons' ), $capability, $parent_slug . '#advanced', [
131 $this,
132 'plugin_layout',
133 ] );
134
135 if ( ! _is_sky_addons_pro_activated() ) {
136 add_submenu_page( $parent_slug, esc_html__( 'Get PRO', 'sky-elementor-addons' ), esc_html__( 'Get PRO', 'sky-elementor-addons' ), $capability, $parent_slug . '#license', [
137 $this,
138 'plugin_layout',
139 ] );
140 }
141
142 if ( _is_sky_addons_pro_activated() ) {
143 add_submenu_page( $parent_slug, esc_html__( 'License', 'sky-elementor-addons' ), esc_html__( 'License', 'sky-elementor-addons' ), $capability, $parent_slug . '#license', [
144 $this,
145 'plugin_layout',
146 ] );
147 }
148
149 add_submenu_page( $parent_slug, esc_html__( 'Help & Support', 'sky-elementor-addons' ), esc_html__( 'Help & Support', 'sky-elementor-addons' ), $capability, $parent_slug . '#faqs', [
150 $this,
151 'plugin_layout',
152 ] );
153 }
154
155 /**
156 * Plugin Layout
157 *
158 * @return void
159 * @since 1.0.0
160 */
161 public function plugin_layout() {
162 echo '<div id="sky-addons" class="wrap sky-addons"> <h2>Loading...</h2> </div>';
163 }
164
165 public static function get_dashboard_link( $suffix = '#' ) {
166 return add_query_arg( [ 'page' => 'sky-addons' . $suffix ], admin_url( 'admin.php' ) );
167 }
168
169 public static function get_b64_icon() {
170 static $icon = null;
171 if ( null === $icon ) {
172 $icon = 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( SKY_ADDONS_ASSETS_PATH . 'images/icon-mono.svg' ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions
173 }
174 return $icon;
175 }
176
177 /**
178 * @param $suffix
179 */
180 public static function dashboard_link( $suffix = '' ) {
181 return add_query_arg( [ 'page' => 'sky-addons' . $suffix ], admin_url( 'admin.php' ) );
182 }
183
184 public static function add_action_links( $links ) {
185 if ( ! current_user_can( 'manage_options' ) ) {
186 return $links;
187 }
188
189 $links = array_merge( [
190 sprintf(
191 '<a href="%s">%s</a>',
192 self::dashboard_link(),
193 esc_html__( 'Settings', 'sky-elementor-addons' )
194 ),
195 ], $links );
196 if ( sky_addons_init_pro() !== true ) {
197 $links = array_merge( $links, [
198 sprintf(
199 '<a target="_blank" style="color:#E0528D; font-weight: bold;" href="%s" title="%s">%s</a>',
200 'https://skyaddons.com/pricing/?coupon=SKYADDONS30',
201 esc_html__( 'Get 30% OFF!', 'sky-elementor-addons' ),
202 esc_html__( 'Get Pro', 'sky-elementor-addons' )
203 ),
204 ] );
205 }
206 return $links;
207 }
208 }
209