PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 4.7.4
Responsive Menu – Create Mobile-Friendly Menu v4.7.4
4.7.4 4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 All 91 releases
responsive-menu / v4.0.0 / inc / classes / class-plugin.php

class-plugin.php in Responsive Menu – Create Mobile-Friendly Menu 4.7.4, at v4.0.0/inc/classes/class-plugin.php

261 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin manifest class.
4 *
5 * @package responsive-menu
6 */
7
8 namespace RMP\Features\Inc;
9
10 use RMP\Features\Inc\Elementor\Elementor_Manager;
11 use RMP\Features\Inc\Traits\Singleton;
12
13 /**
14 * Class Plugin
15 */
16 class Plugin {
17
18 use Singleton;
19
20 /**
21 * Construct method.
22 */
23 protected function __construct() {
24 // Load plugin classes.
25 Admin::get_instance();
26 Assets::get_instance();
27 Editor::get_instance();
28 Editor_Manager::get_instance();
29 Preview::get_instance();
30 Control_Manager::get_instance();
31 Theme_Manager::get_instance();
32 Option_Manager::get_instance();
33 Style_Manager::get_instance();
34 UI_Manager::get_instance();
35 RMP_Migration::get_instance();
36 Elementor_Manager::get_instance();
37
38 $this->setup_hooks();
39 }
40
41 /**
42 * To setup action/filter.
43 *
44 * @return void
45 */
46 protected function setup_hooks() {
47 add_action( 'plugins_loaded', array( $this, 'rmp_load_plugin_text_domain' ) );
48 add_action( 'admin_notices', array( $this, 'rmp_deactivate_paid_version_notice' ) );
49
50 //Hiding upgrade to pro notice for v3 users
51 global $wpdb;
52 $table_name = $wpdb->prefix . 'responsive_menu';
53 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
54 if ( ! $wpdb->get_var( $query ) == $table_name ) {
55 add_action( 'admin_notices', array( $this, 'rmp_upgrade_pro_admin_notice' ) );
56 }
57 add_action( 'plugin_action_links_' . plugin_basename( RMP_PLUGIN_FILE ), array( $this, 'rmp_upgrade_pro_plugin_link' ) );
58 add_action( 'wp_ajax_rmp_upgrade_admin_notice_dismiss', array( $this, 'rmp_upgrade_pro_notice_dismiss' ) );
59 add_action( 'admin_notices', array( $this, 'no_menu_admin_notice' ) );
60
61 // Check current config and environment support wp_body_open or not.
62 if ( $this->has_support( 'wp_body_open' ) ) {
63 add_action( 'wp_body_open', array( $this, 'menu_render_on_frontend' ) );
64 } else {
65 add_action( 'wp_footer', array( $this, 'menu_render_on_frontend' ) );
66 }
67 }
68
69 /**
70 * Function to show the admin notice when no menu exist.
71 *
72 * @since 4.1.0
73 *
74 * @return void
75 */
76 public function no_menu_admin_notice() {
77
78 // Check post type.
79 $post_type = get_post_type();
80 if ( empty( $post_type ) && ! empty( $_GET['post_type'] ) ) {
81 // A post type is a slug, not a number: intval() made this always 0.
82 // is_scalar() because ?post_type[]=x would otherwise reach strtolower( array ).
83 $post_type = is_scalar( $_GET['post_type'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
84 ? sanitize_key( wp_unslash( $_GET['post_type'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
85 : '';
86 }
87
88 if ( 'rmp_menu' !== $post_type || ! empty( $_GET['page'] ) ) {
89 return;
90 }
91
92 // Count all post which are in list except trash.
93 $post_count = 0;
94 foreach ( wp_count_posts( 'rmp_menu' ) as $status => $count ) {
95 if ( 'trash' == $status ) {
96 continue;
97 }
98
99 $post_count += $count;
100 }
101
102 if ( $post_count >= 1 ) {
103 return;
104 } ?>
105 <div class="notice notice-error">
106 <p>
107 <?php
108 /* translators: %s: HTML tag */
109 echo sprintf( esc_html__( 'Responsive menu list is empty. Create a menu by clicking the %1$sCreate New Menu%2$s button. For more details visit ', 'responsive-menu' ), '<b>', '</b>' );
110 ?>
111 <a target="_blank" rel="noopener" href="<?php echo esc_url( 'https://responsive.menu/knowledgebase/responsive-menu-4-0-overview/' ); ?>"> <?php esc_html_e( 'Documentation', 'responsive-menu' ); ?></a>
112 </p>
113 </div>
114 <?php
115 }
116
117 /**
118 * Add plugin upgrade link.
119 *
120 * Add a link to the settings page on the responsive menu page.
121 *
122 * @param array $links List of existing plugin action links.
123 * @return array List of modified plugin action links.
124 */
125 public function rmp_upgrade_pro_plugin_link( $links ) {
126 $links = array_merge(
127 $links,
128 array( '<a class="responsive-menu-license-upgrade-link" target="_blank" rel="noopener" href="https://responsive.menu/pricing/">' . esc_html__( 'Upgrade', 'responsive-menu' ) . '</a>' )
129 );
130
131 return $links;
132 }
133
134 /**
135 * Function to add the admin notice to upgrade as pro.
136 *
137 * @version 4.1.0
138 */
139 public function rmp_upgrade_pro_admin_notice() {
140 $post_type = get_post_type();
141 if ( empty( $post_type ) && ! empty( $_GET['post_type'] ) ) {
142 // A post type is a slug, not a number: intval() made this always 0.
143 // is_scalar() because ?post_type[]=x would otherwise reach strtolower( array ).
144 $post_type = is_scalar( $_GET['post_type'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
145 ? sanitize_key( wp_unslash( $_GET['post_type'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
146 : '';
147 }
148
149 if ( 'rmp_menu' !== $post_type ) {
150 return;
151 }
152
153 $user_id = get_current_user_id();
154 if ( ! empty( get_user_meta( $user_id, 'rmp_upgrade_pro_admin_notice' ) ) ) {
155 return;
156 }
157
158 include_once RMP_PLUGIN_PATH_V4 . '/templates/admin-notices.php';
159 }
160
161 /**
162 * Function to hide the admin notice permanent.
163 */
164 public function rmp_upgrade_pro_notice_dismiss() {
165 $user_id = get_current_user_id();
166 update_user_meta( $user_id, 'rmp_upgrade_pro_admin_notice', true );
167 }
168
169 /**
170 * Function to show the admin notice if plugin deactivate.
171 *
172 * @return void
173 */
174 public function rmp_deactivate_paid_version_notice() {
175 if ( get_transient( 'og-admin-notice-activation' ) ) {
176 ?>
177 <div class="notice notice-error is-dismissible">
178 <p><?php esc_html_e( 'Responsive Menu has been deactivated', 'responsive-menu' ); ?></p>
179 </div>
180 <?php
181 delete_transient( 'og-admin-notice-activation-pro' );
182 }
183 }
184
185 /**
186 * Load plugin text domain.
187 *
188 * @version 4.0.0
189 *
190 * @return void
191 */
192 public function rmp_load_plugin_text_domain() {
193 load_plugin_textdomain( 'responsive-menu', false, RMP_PLUGIN_DIR_NAME . '/v4.0.0/languages' );
194 }
195
196 /**
197 * Function to render the nenu on frontend.
198 *
199 * @version 4.0.0
200 */
201 public function menu_render_on_frontend() {
202 $option_manager = Option_Manager::get_instance();
203 $menu_ids = get_all_rmp_menu_ids();
204
205 if ( empty( $menu_ids ) ) {
206 return;
207 }
208
209 foreach ( $menu_ids as $menu_id ) {
210 $menu_show_on = $option_manager->get_option( $menu_id, 'menu_display_on' );
211
212 if ( ! empty( $menu_show_on ) && 'shortcode' === $menu_show_on ) {
213 continue;
214 }
215
216 $menu = new \RMP\Features\Inc\RMP_Menu( $menu_id );
217 $menu->build_menu();
218 }
219 }
220
221 /**
222 * Check support of wp_body_open for plugins and themes.
223 *
224 * @since 4.0.0
225 *
226 * @param string $hook Name of hook.
227 * @return boolean
228 */
229 public function has_support( $hook ) {
230
231 // Check wp footer option is enabled.
232 $option_manager = Option_Manager::get_instance();
233 if ( 'wp_body_open' === $hook && 'on' === $option_manager->get_global_option( 'rmp_wp_footer_hook' ) ) {
234 return false;
235 }
236
237 // Check wp core support wp_body_open hook or not.
238 if ( ! has_action( $hook ) ) {
239 return false;
240 }
241
242 // If is_plugin_active function not exist then add plugin.php file from core.
243 if ( ! function_exists( 'is_plugin_active' ) ) {
244 include_once ABSPATH . 'wp-admin/includes/plugin.php';
245 }
246
247 // List of unsupported themes and plugins.
248 $unsupported_extensions = array(
249 'oxygen/functions.php',
250 );
251
252 foreach ( $unsupported_extensions as $extension ) {
253 if ( is_plugin_active( $extension ) ) {
254 return false;
255 }
256 }
257
258 return true;
259 }
260 }
261