PluginProbe
QuadMenu – Mega Menu / 3.3.8
QuadMenu – Mega Menu v3.3.8
3.3.8 3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 88 releases
quadmenu / jetpack_vendor / quadlayers / wp-notice-plugin-required / src / Load.php

Load.php in QuadMenu – Mega Menu 3.3.8, at jetpack_vendor/quadlayers/wp-notice-plugin-required/src/Load.php

119 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * QuadLayers WP Notice Plugin Required
4 *
5 * @package quadlayers/wp-notice-plugin-required
6 * @link https://github.com/quadlayers/wp-notice-plugin-required
7 */
8
9 namespace QuadLayers\WP_Notice_Plugin_Required;
10
11 /**
12 * Class Load
13 *
14 * @package QuadLayers\WP_Notice_Plugin_Required
15 */
16 class Load {
17
18 /**
19 * Required Plugins.
20 *
21 * @var array
22 */
23 protected $plugins;
24 /**
25 * Current Plugin name.
26 *
27 * @var string
28 */
29 protected $current_plugin_name = '';
30
31 /**
32 * Load constructor.
33 *
34 * @param string $current_plugin_name Current Plugin name.
35 * @param array $plugins Required Plugins.
36 */
37 public function __construct( $current_plugin_name, array $plugins = array() ) {
38 $this->current_plugin_name = $current_plugin_name;
39 $this->plugins = $plugins;
40 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
41 }
42
43 /**
44 * Add admin notice.
45 *
46 * @return void
47 */
48 public function admin_notices() {
49
50 $screen = get_current_screen();
51
52 if ( isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id ) {
53 return;
54 }
55
56 foreach ( $this->plugins as $plugin ) {
57
58 if ( ! isset( $plugin['slug'], $plugin['name'] ) ) {
59 continue;
60 }
61
62 $plugin = Plugin::get_instance( $plugin['slug'], $plugin['name'] );
63
64 $notice = $this->add_notice( $plugin );
65
66 /**
67 * If notice is added then return.
68 * This will prevent multiple notices for same plugin.
69 */
70 if ( $notice ) {
71 return;
72 }
73 }
74 }
75
76 /**
77 * Add notice.
78 *
79 * @param Plugin $plugin Plugin.
80 *
81 * @return bool
82 */
83 private function add_notice( Plugin $plugin ) {
84
85 if ( $plugin->is_plugin_activated() ) {
86 return false;
87 }
88
89 if ( $plugin->is_plugin_installed() ) {
90 if ( ! current_user_can( 'activate_plugins' ) ) {
91 return false;
92 }
93 ?>
94 <div class="error">
95 <p>
96 <a href="<?php echo esc_url( $plugin->get_plugin_activate_link() ); ?>" class='button button - secondary'><?php printf( esc_html__( 'Activate % s', 'wp-notice-plugin-required' ), esc_html( $plugin->get_plugin_name() ) ); ?></a>
97 <?php printf( esc_html__( 'The %1$s is not working because you need to activate the %2$s plugin. ', 'wp-notice-plugin-required' ), esc_html( $this->current_plugin_name ), esc_html( $plugin->get_plugin_name() ) ); ?>
98 </p>
99 </div>
100 <?php
101 return true;
102 }
103
104 if ( ! current_user_can( 'install_plugins' ) ) {
105 return false;
106 }
107 ?>
108 <div class="error">
109 <p>
110 <a href="<?php echo esc_url( $plugin->get_plugin_install_link() ); ?>" class='button button - secondary'><?php printf( esc_html__( 'Install % s', 'wp-notice-plugin-required' ), esc_html( $plugin->get_plugin_name() ) ); ?></a>
111 <?php printf( esc_html__( 'The %1$s is not working because you need to install the %2$s plugin. ', 'wp-notice-plugin-required' ), esc_html( $this->current_plugin_name ), esc_html( $plugin->get_plugin_name() ) ); ?>
112 </p>
113 </div>
114 <?php
115 return true;
116 }
117
118 }
119