PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.4
YayMail – WooCommerce Email Customizer v4.3.4
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / YayCommerceMenu / RegisterMenu.php

RegisterMenu.php in YayMail – WooCommerce Email Customizer 4.3.4, at src/YayCommerceMenu/RegisterMenu.php

182 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Add YayCommerce menu or submenu in admin
4 *
5 * @package YayMail\Admin
6 */
7
8 namespace YayMail\YayCommerceMenu;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Declare class
14 */
15 class RegisterMenu {
16
17 /**
18 * Contains intance of class
19 */
20 protected static $instance = null;
21
22 /**
23 * Contains position of the menu
24 *
25 * @var int
26 */
27 public static $position = 56;
28 // After WooCommerce menu
29
30 /**
31 * Contains capability of YayCommerce menu
32 *
33 * @var string
34 */
35 public static $capability = 'manage_options';
36
37 /**
38 * Get instance - singleton pattern
39 */
40 public static function get_instance() {
41 if ( empty( self::$instance ) ) {
42 self::$instance = new self();
43 }
44 return self::$instance;
45 }
46
47 /**
48 * Constructor
49 */
50 public function __construct() {
51 if ( ! defined( 'YAYMAIL_MENU_ORDER' ) ) {
52 define( 'YAYMAIL_MENU_ORDER', 1 );
53 }
54 if ( ! defined( 'YAYMAIL_MENU_PRIORITY' ) ) {
55 define( 'YAYMAIL_MENU_PRIORITY', 100 );
56 }
57 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_yaycommerce_menu_scripts' ] );
58 add_action( 'admin_menu', [ $this, 'settings_menu' ] );
59 add_action( 'admin_menu', [ $this, 'add_placeholder_menu' ], YAYMAIL_MENU_PRIORITY + 1 );
60 OtherPluginsMenu::get_instance();
61 }
62
63 /**
64 * Add YayCommerce menus
65 */
66 public function settings_menu() {
67 global $admin_page_hooks;
68 if ( ! isset( $admin_page_hooks['yaycommerce'] ) ) {
69 add_menu_page( 'yaycommerce', 'YayCommerce', self::$capability, 'yaycommerce', null, self::get_logo_url(), self::$position );
70
71 $this->add_submenus();
72 self::delete_yaycommerce_nav();
73 }
74 }
75
76 public function get_submenus() {
77
78 $submenus['yaycommerce-help'] = [
79 'parent' => 'yaycommerce',
80 'name' => __( 'Help', 'yaycommerce' ),
81 'capability' => 'manage_options',
82 'render_callback' => false,
83 'load_data_callback' => false,
84 ];
85
86 /**
87 * Temporarily until all Yay plugins has the same code
88 */
89 if ( function_exists( 'YAYDP\\load_plugin' ) && class_exists( '\YAYDP\License\License_Handler' ) ) {
90 $licensing_plugins_yay_pricing = \YAYDP\License\License_Handler::get_licensing_plugins();
91 }
92
93 if ( function_exists( 'Yay_Currency\\plugin_init' ) && class_exists( '\Yay_Currency\License\LicenseHandler' ) ) {
94 $licensing_plugins_yay_currency = \Yay_Currency\License\LicenseHandler::get_licensing_plugins();
95 }
96
97 if ( function_exists( 'Yay_Swatches\\init' ) && class_exists( '\Yay_Swatches\License\LicenseHandler' ) ) {
98 $licensing_plugins_yay_swatches = \Yay_Swatches\License\LicenseHandler::get_licensing_plugins();
99 }
100 if ( function_exists( 'YayExtra\\plugins_loaded' ) && class_exists( '\YayExtra\License\LicenseHandler' ) ) {
101 $licensing_plugins_yay_extra = \YayExtra\License\LicenseHandler::get_licensing_plugins();
102 }
103
104 if ( function_exists( 'YaySMTP\\init' ) && class_exists( '\YaySMTP\License\LicenseHandler' ) ) {
105 $licensing_plugins_yay_smtp = \YaySMTP\License\LicenseHandler::get_licensing_plugins();
106 }
107 /** -------- */
108
109 $yaymail_licensing_plugins = \YayMail\License\LicenseHandler::get_licensing_plugins();
110 $yay_licensing_plugins = apply_filters( 'yaycommerce_licensing_plugins', [] );
111
112 if ( ! empty( $yaymail_licensing_plugins ) || ! empty( $licensing_plugins_yay_pricing ) || ! empty( $licensing_plugins_yay_currency ) || ! empty( $licensing_plugins_yay_swatches ) || ! empty( $licensing_plugins_yay_extra ) || ! empty( $licensing_plugins_yay_smtp ) || ! empty( $yay_licensing_plugins ) ) {
113 $submenus['yaycommerce-licenses'] = [
114 'parent' => 'yaycommerce',
115 'name' => __( 'Licenses', 'yaycommerce' ),
116 'capability' => 'manage_options',
117 'render_callback' => [ '\YayMail\YayCommerceMenu\LicensesMenu', 'render' ],
118 'load_data_callback' => [ '\YayMail\YayCommerceMenu\LicensesMenu', 'load_data' ],
119 ];
120 }
121
122 $submenus['yaycommerce-other-plugins'] = [
123 'parent' => 'yaycommerce',
124 'name' => __( 'Other plugins', 'yaycommerce' ),
125 'capability' => 'manage_options',
126 'render_callback' => [ '\YayMail\YayCommerceMenu\OtherPluginsMenu', 'render' ],
127 'load_data_callback' => [ '\YayMail\YayCommerceMenu\OtherPluginsMenu', 'load_data' ],
128 ];
129
130 return $submenus;
131 }
132
133 public function add_submenus() {
134 foreach ( $this->get_submenus() as $id => $submenu ) {
135 $page_id = add_submenu_page(
136 $submenu['parent'],
137 $submenu['name'],
138 $submenu['name'],
139 $submenu['capability'],
140 $id,
141 $submenu['render_callback'],
142 isset( $submenu['position'] ) ? $submenu['position'] : null
143 );
144 add_action( 'load-' . $page_id, $submenu['load_data_callback'] );
145 }
146 }
147
148 public function enqueue_yaycommerce_menu_scripts() {
149 wp_enqueue_script( 'yaycommerce-menu', plugin_dir_url( __FILE__ ) . 'assets/js/yaycommerce-menu.js', [ 'jquery' ], '1.0', true );
150 }
151
152 public static function get_logo_url() {
153 return 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTQ2LjI0NzYgNi40MDg5NkM0Ni4yNDc2IDkuOTQ4MTYgNDMuMzc3OCAxMi44MTc5IDM5LjgzODYgMTIuODE3OUMzNi4yOTk0IDEyLjgxNzkgMzMuNDI5NyA5Ljk0ODE2IDMzLjQyOTcgNi40MDg5NkMzMy40Mjk3IDIuODY5NzYgMzYuMjk4MSAwIDM5LjgzODYgMEM0My4zNzkxIDAgNDYuMjQ3NiAyLjg2OTc2IDQ2LjI0NzYgNi40MDg5NlpNMS4xNjQ3MSAyMi45OTI2Qy0wLjIxODk3MiAyMy4xMzIyIC0wLjQzNzg1MiAyNS4wNTg2IDAuODc5MjY4IDI1LjUwNEM5LjI1NDMxIDI4LjMzNjYgMjEuMzAwNCAzMC45OTUyIDI3LjI0OTggMzIuMjM0MkMyOS4yOTkxIDMyLjY2MDUgMzAuNjIzOSAzNC42NDgzIDMwLjI0MTIgMzYuNzA2NkMyOC41NDUyIDQ1LjgwNjEgMjUuMzc4NSA1NS41Mjc3IDIzLjM2ODkgNjIuMzM0N0MyMi45ODYyIDYzLjYzMTQgMjQuNTk5IDY0LjU3MjIgMjUuNTM4NSA2My42MDA2QzQ3LjIxMDIgNDEuMjAxOSA1OS4zODk0IDE4LjE5OSA2My44Njk0IDguNzIzMkM2NC40MjM2IDcuNTUwNzIgNjMuMTAwMSA2LjM4NzIgNjIuMDA0NCA3LjA4MDk2QzQ1LjM5MTMgMTcuNjA2NCAxMy44NTU5IDIxLjcxNzggMS4xNjQ3MSAyMi45OTI2WiIgZmlsbD0iI0E3QUFBRCIvPgo8L3N2Zz4=';
154 }
155
156 public static function delete_yaycommerce_nav() {
157 remove_submenu_page( 'yaycommerce', 'yaycommerce' );
158 }
159
160 public function add_placeholder_menu() {
161 global $submenu;
162 if ( ! isset( $submenu['yaycommerce'] ) ) {
163 return;
164 }
165 $has_plugin_menu = false;
166 foreach ( $submenu['yaycommerce'] as $item ) {
167 if ( 'yaymail-settings' === $item[2] ) {
168 $has_plugin_menu = true;
169 }
170 }
171 if ( ! $has_plugin_menu ) {
172 $page_id = add_submenu_page( 'yaycommerce', __( 'Email Builder Settings', 'yaymail' ), __( 'YayMail', 'yaymail' ), 'manage_woocommerce', 'yaymail-settings', '__return_false', 0 );
173 add_action( 'load-' . $page_id, [ $this, 'redirect_to_licenses_menu' ] );
174 }
175 }
176
177 public function redirect_to_licenses_menu() {
178 wp_safe_redirect( admin_url( 'admin.php?page=yaycommerce-licenses' ) );
179 exit;
180 }
181 }
182