PluginProbe
YayMail – WooCommerce Email Customizer / 3.3.7
YayMail – WooCommerce Email Customizer v3.3.7
4.4.6 4.4.5 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 All 57 releases
yaymail / includes / YayCommerceMenu / RegisterMenu.php

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

167 lines 5.7 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 $licensing_plugins = LicenseHandler::get_licensing_plugins();
87 $licensing_plugins_yay_pricing = array();
88 $licensing_plugins_yay_currency = array();
89
90 if ( function_exists( 'YAYDP\\load_plugin' ) && class_exists( '\YAYDP\License\License_Handler' ) ) {
91 $licensing_plugins_yay_pricing = \YAYDP\License\License_Handler::get_licensing_plugins();
92 }
93
94 if ( function_exists( 'Yay_Currency\\plugin_init' ) && class_exists( '\Yay_Currency\License\LicenseHandler' ) ) {
95 $licensing_plugins_yay_currency = \Yay_Currency\License\LicenseHandler::get_licensing_plugins();
96 }
97
98 if ( ! empty( $licensing_plugins ) || ! empty( $licensing_plugins_yay_pricing ) || ! empty( $licensing_plugins_yay_currency ) ) {
99 $submenus['yaycommerce-licenses'] = array(
100 'parent' => 'yaycommerce',
101 'name' => __( 'Licenses', 'yaycommerce' ),
102 'capability' => 'manage_options',
103 'render_callback' => array( '\YayMail\YayCommerceMenu\LicensesMenu', 'render' ),
104 'load_data_callback' => array( '\YayMail\YayCommerceMenu\LicensesMenu', 'load_data' ),
105 );
106 }
107
108 $submenus['yaycommerce-other-plugins'] = array(
109 'parent' => 'yaycommerce',
110 'name' => __( 'Other plugins', 'yaycommerce' ),
111 'capability' => 'manage_options',
112 'render_callback' => array( '\YayMail\YayCommerceMenu\OtherPluginsMenu', 'render' ),
113 'load_data_callback' => array( '\YayMail\YayCommerceMenu\OtherPluginsMenu', 'load_data' ),
114 );
115
116 return $submenus;
117 }
118
119 public function add_submenus() {
120 foreach ( $this->get_submenus() as $id => $submenu ) {
121 $page_id = add_submenu_page(
122 $submenu['parent'],
123 $submenu['name'],
124 $submenu['name'],
125 $submenu['capability'],
126 $id,
127 $submenu['render_callback'],
128 isset( $submenu['position'] ) ? $submenu['position'] : null
129 );
130 add_action( 'load-' . $page_id, $submenu['load_data_callback'] );
131 }
132 }
133
134 public function enqueue_yaycommerce_menu_scripts() {
135 wp_enqueue_script( 'yaycommerce-menu', plugin_dir_url( __FILE__ ) . 'assets/js/yaycommerce-menu.js', array( 'jquery' ), '1.0', true );
136 }
137
138 public static function get_logo_url() {
139 return 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTQ2LjI0NzYgNi40MDg5NkM0Ni4yNDc2IDkuOTQ4MTYgNDMuMzc3OCAxMi44MTc5IDM5LjgzODYgMTIuODE3OUMzNi4yOTk0IDEyLjgxNzkgMzMuNDI5NyA5Ljk0ODE2IDMzLjQyOTcgNi40MDg5NkMzMy40Mjk3IDIuODY5NzYgMzYuMjk4MSAwIDM5LjgzODYgMEM0My4zNzkxIDAgNDYuMjQ3NiAyLjg2OTc2IDQ2LjI0NzYgNi40MDg5NlpNMS4xNjQ3MSAyMi45OTI2Qy0wLjIxODk3MiAyMy4xMzIyIC0wLjQzNzg1MiAyNS4wNTg2IDAuODc5MjY4IDI1LjUwNEM5LjI1NDMxIDI4LjMzNjYgMjEuMzAwNCAzMC45OTUyIDI3LjI0OTggMzIuMjM0MkMyOS4yOTkxIDMyLjY2MDUgMzAuNjIzOSAzNC42NDgzIDMwLjI0MTIgMzYuNzA2NkMyOC41NDUyIDQ1LjgwNjEgMjUuMzc4NSA1NS41Mjc3IDIzLjM2ODkgNjIuMzM0N0MyMi45ODYyIDYzLjYzMTQgMjQuNTk5IDY0LjU3MjIgMjUuNTM4NSA2My42MDA2QzQ3LjIxMDIgNDEuMjAxOSA1OS4zODk0IDE4LjE5OSA2My44Njk0IDguNzIzMkM2NC40MjM2IDcuNTUwNzIgNjMuMTAwMSA2LjM4NzIgNjIuMDA0NCA3LjA4MDk2QzQ1LjM5MTMgMTcuNjA2NCAxMy44NTU5IDIxLjcxNzggMS4xNjQ3MSAyMi45OTI2WiIgZmlsbD0iI0E3QUFBRCIvPgo8L3N2Zz4=';
140 }
141
142 public static function delete_yaycommerce_nav() {
143 remove_submenu_page( 'yaycommerce', 'yaycommerce' );
144 }
145
146 public function add_placeholder_menu() {
147 global $submenu;
148 if ( ! isset( $submenu['yaycommerce'] ) ) {
149 return;
150 }
151 $has_plugin_menu = false;
152 foreach ( $submenu['yaycommerce'] as $item ) {
153 if ( 'yaymail-settings' === $item[2] ) {
154 $has_plugin_menu = true;
155 }
156 }
157 if ( ! $has_plugin_menu ) {
158 add_submenu_page( 'yaycommerce', __( 'Email Builder Settings', 'yaymail' ), __( 'YayMail', 'yaymail' ), 'manage_woocommerce', 'yaymail-settings', array( $this, 'render_placeholder_menu' ), 0 );
159 }
160 }
161
162 public function render_placeholder_menu() {
163 wp_safe_redirect( admin_url( 'admin.php?page="yaycommerce-licenses"' ) );
164 }
165
166 }
167