PluginProbe
YayMail – WooCommerce Email Customizer / 3.4
YayMail – WooCommerce Email Customizer v3.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 / includes / YayCommerceMenu / RegisterMenu.php

RegisterMenu.php in YayMail – WooCommerce Email Customizer 3.4, at includes/YayCommerceMenu/RegisterMenu.php

181 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 * Add YayCommerce menu or submenu in admin
4 *
5 * @package YayMail\Admin
6 */
7
8 namespace YayMail\YayCommerceMenu;
9
10 use YayMail\License\LicenseHandler;
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * Declare class
16 */
17 class RegisterMenu {
18
19 /**
20 * Contains intance of class
21 */
22 protected static $instance = null;
23
24 /**
25 * Contains position of the menu
26 *
27 * @var int
28 */
29 public static $position = 55.5;
30
31 /**
32 * Contains capability of YayCommerce menu
33 *
34 * @var string
35 */
36 public static $capability = 'manage_options';
37
38 /**
39 * Get instance - singleton pattern
40 */
41 public static function get_instance() {
42 if ( empty( self::$instance ) ) {
43 self::$instance = new self();
44 }
45 return self::$instance;
46 }
47
48 /**
49 * Constructor
50 */
51 public function __construct() {
52 if ( ! defined( 'YAYMAIL_MENU_ORDER' ) ) {
53 define( 'YAYMAIL_MENU_ORDER', 1 );
54 }
55 if ( ! defined( 'YAYMAIL_MENU_PRIORITY' ) ) {
56 define( 'YAYMAIL_MENU_PRIORITY', 100 );
57 }
58 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_yaycommerce_menu_scripts' ) );
59 add_action( 'admin_menu', array( $this, 'settings_menu' ) );
60 add_action( 'admin_menu', array( $this, 'add_placeholder_menu' ), YAYMAIL_MENU_PRIORITY + 1 );
61 OtherPluginsMenu::get_instance();
62 }
63
64 /**
65 * Add YayCommerce menus
66 */
67 public function settings_menu() {
68 global $admin_page_hooks;
69 if ( ! isset( $admin_page_hooks['yaycommerce'] ) ) {
70 add_menu_page( 'yaycommerce', 'YayCommerce', self::$capability, 'yaycommerce', null, self::get_logo_url(), self::$position );
71
72 $this->add_submenus();
73 self::delete_yaycommerce_nav();
74 }
75 }
76
77 public function get_submenus() {
78 $submenus['yaycommerce-help'] = array(
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 = 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'] = array(
114 'parent' => 'yaycommerce',
115 'name' => __( 'Licenses', 'yaycommerce' ),
116 'capability' => 'manage_options',
117 'render_callback' => array( '\YayMail\YayCommerceMenu\LicensesMenu', 'render' ),
118 'load_data_callback' => array( '\YayMail\YayCommerceMenu\LicensesMenu', 'load_data' ),
119 );
120 }
121
122 $submenus['yaycommerce-other-plugins'] = array(
123 'parent' => 'yaycommerce',
124 'name' => __( 'Other plugins', 'yaycommerce' ),
125 'capability' => 'manage_options',
126 'render_callback' => array( '\YayMail\YayCommerceMenu\OtherPluginsMenu', 'render' ),
127 'load_data_callback' => array( '\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', array( '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 add_submenu_page( 'yaycommerce', __( 'Email Builder Settings', 'yaymail' ), __( 'YayMail', 'yaymail' ), 'manage_woocommerce', 'yaymail-settings', array( $this, 'render_placeholder_menu' ), 0 );
173 }
174 }
175
176 public function render_placeholder_menu() {
177 wp_safe_redirect( admin_url( 'admin.php?page="yaycommerce-licenses"' ) );
178 }
179
180 }
181