PluginProbe
WP Plugin Manager – Deactivate plugins per page / 1.4.15
WP Plugin Manager – Deactivate plugins per page v1.4.15
1.4.16 1.4.15 1.4.14 1.4.13 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 All 43 releases
wp-plugin-manager / plugin-main.php

plugin-main.php in WP Plugin Manager – Deactivate plugins per page 1.4.15, at plugin-main.php

351 lines 15.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: WP Plugin Manager
4 * Plugin URI: https://hasthemes.com/plugins/
5 * Description: WP Plugin Manager is a WordPress plugin that allows you to disable plugins for certain pages, posts or URI conditions.
6 * Version: 1.4.15
7 * Author: HasThemes
8 * Author URI: https://hasthemes.com/
9 * Text Domain: wp-plugin-manager
10 */
11
12 defined( 'ABSPATH' ) or die();
13
14 /**
15 * Define path
16 */
17 define( 'HTPM_PLUGIN_VERSION', '1.4.15' );
18 define( 'HTPM_ROOT_PL', __FILE__ );
19 define( 'HTPM_ROOT_URL', plugins_url('', HTPM_ROOT_PL) );
20 define( 'HTPM_ROOT_DIR', dirname( HTPM_ROOT_PL ) );
21 define( 'HTPM_PLUGIN_DIR', plugin_dir_path( __DIR__ ) );
22 define( 'HTPM_PLUGIN_BASE', plugin_basename( HTPM_ROOT_PL ) );
23 class HTPM_Main {
24
25 // Singleton instance
26 private static $_instance = null;
27
28 /**
29 * Instance
30 * Initializes a singleton instance
31 * @return self
32 */
33 public static function instance() {
34 if (is_null(self::$_instance)) {
35 self::$_instance = new self();
36 }
37 return self::$_instance;
38 }
39
40 private function __construct() {
41
42 /** Load the is_plugin_active function if it doesn't exist */
43 if (!function_exists('is_plugin_active')) {
44 include_once ABSPATH . 'wp-admin/includes/plugin.php';
45 }
46
47 register_activation_hook( HTPM_ROOT_PL, [$this, 'activation'] );
48 register_deactivation_hook( __FILE__, [$this, 'deactivation'] );
49
50 add_action('in_admin_header', [$this, 'remove_admin_notice'], 1000);
51 add_action( 'init', [$this, 'i18n'] );
52 add_action( 'plugins_loaded', [$this, 'init'] );
53
54 if( is_plugin_active('wp-plugin-manager-pro/plugin-main.php') ){
55 add_action('update_option_active_plugins', [$this, 'deactivate_pro_version']);
56 }
57
58 add_action( 'admin_enqueue_scripts', [$this, 'admin_scripts'] );
59 add_filter('admin_menu', [$this, 'pro_submenu'], 101 );
60 add_action('init', [$this, 'create_mu_file']);
61 add_action('admin_init', [$this, 'show_admin_diagnostic_data_notice'] );
62 add_action('admin_init', [$this, 'show_admin_rating_notice'] );
63 add_action('admin_init', [$this, 'show_admin_promo_notice'] );
64 }
65
66 /**
67 * Remove all Notices on admin pages.
68 * @return void
69 */
70 function remove_admin_notice(){
71 $current_screen = get_current_screen();
72 $hide_screen = ['toplevel_page_htpm-options', 'plugin-manager_page_htpm_recommendations', 'update'];
73 if( in_array( $current_screen->id, $hide_screen) ){
74 remove_all_actions('admin_notices');
75 remove_all_actions('all_admin_notices');
76 }
77 }
78
79 /**
80 * Plugin activation hook
81 */
82 function activation(){
83 if ( ! get_option( 'htpm_installed' ) ) {
84 update_option( 'htpm_installed', time() );
85 }
86 update_option('htpm_status', 'active');
87
88 // replace the old file
89 $mu_plugin_file_source_path = HTPM_ROOT_DIR . '/mu-plugin/htpm-mu-plugin.php';
90
91 $mu_plugin_file = 'htpm-mu-plugin.php';
92 if ( defined( 'WPMU_PLUGIN_DIR' ) ) {
93 $mu_plugins_path = WPMU_PLUGIN_DIR;
94 } else {
95 $mu_plugins_path = WP_CONTENT_DIR . '/' . 'mu-plugins';
96 }
97
98 $mu_plugin_file_path = $mu_plugins_path . '/htpm-mu-plugin.php';
99
100 // add mu file
101 if ( file_exists( $mu_plugins_path ) ){
102 copy( $mu_plugin_file_source_path, $mu_plugin_file_path );
103 }
104 }
105
106 /**
107 * Plugin deactivation hook
108 */
109 function deactivation(){
110 update_option('htpm_status', 'deactive');
111 }
112
113 /**
114 * Load text domain
115 */
116 function i18n() {
117 load_plugin_textdomain( 'wp-plugin-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
118 }
119
120 function init() {
121 $this->include_files();
122 }
123
124 /**
125 * Plugin deactivation pro version
126 */
127 function deactivate_pro_version(){
128 deactivate_plugins('wp-plugin-manager-pro/plugin-main.php');
129 }
130
131 /**
132 * Include files
133 */
134 function include_files() {
135 require_once HTPM_ROOT_DIR . '/includes/helper_functions.php';
136 require_once HTPM_ROOT_DIR . '/includes/plugin-options-page.php';
137 if(is_admin()){
138 include_once( HTPM_ROOT_DIR . '/includes/class-diagnostic-data.php');
139 include_once( HTPM_ROOT_DIR . '/includes/class.notices.php');
140 // include_once( HTPM_ROOT_DIR . '/includes/HTPM_Trial.php');
141 }
142 include_once( HTPM_ROOT_DIR . '/includes/api/admin-dashboard-api.php');
143 include_once( HTPM_ROOT_DIR . '/includes/api/changelog-api.php');
144 include_once( HTPM_ROOT_DIR . '/includes/api/recommended-plugins-api.php');
145 include_once( HTPM_ROOT_DIR . '/includes/api/admin-settings.php');
146
147 // Initialize REST API endpoints
148 add_action('rest_api_init', function() {
149 $plugins_api = new \HTPM\Api\Plugins();
150 $plugins_api->register_routes();
151 });
152 }
153
154 /**
155 * Enqueue admin scripts and styles.
156 */
157 function admin_scripts( $hook_suffix ) {
158 if( $hook_suffix == 'toplevel_page_htpm-options' ){
159
160 wp_enqueue_style( 'htpm-admin', HTPM_ROOT_URL . '/assets/css/admin-style.css', [], HTPM_PLUGIN_VERSION );
161 // vue settings
162 wp_enqueue_style( 'htpm-vue-settings-style', HTPM_ROOT_URL . '/assets/dist/css/style.css', array(), HTPM_PLUGIN_VERSION, 'all' );
163 wp_enqueue_script( 'htpm-vue-settings', HTPM_ROOT_URL . '/assets/dist/js/main.js', [ 'jquery' ], HTPM_PLUGIN_VERSION, true );
164
165 add_filter('script_loader_tag', function($tag, $handle, $src) {
166 if ($handle === 'htpm-vue-settings') {
167 return '<script type="module" src="' . esc_url($src) . '"></script>';
168 }
169 return $tag;
170 }, 10, 3);
171
172 $admin_settings = WP_Plugin_Manager_Settings::get_instance();
173 $localize_data = [
174 'ajaxurl' => admin_url( 'admin-ajax.php' ),
175 'adminURL' => admin_url(),
176 'pluginURL' => plugin_dir_url( __FILE__ ),
177 'assetsURL' => plugin_dir_url( __FILE__ ) . 'assets/',
178 'restUrl' => rest_url(), // This will include the wp-json prefix
179 'nonce' => wp_create_nonce('wp_rest'),
180 'licenseNonce' => wp_create_nonce( 'el-license' ),
181 'licenseEmail' => get_option( 'WPPluginManagerPro_lic_email', get_bloginfo( 'admin_email' ) ),
182 'message' =>[
183 'packagedesc'=> esc_html__( 'in this package', 'wp-plugin-manager' ),
184 'allload' => esc_html__( 'All Items have been Loaded', 'wp-plugin-manager' ),
185 'notfound' => esc_html__( 'Nothing Found', 'wp-plugin-manager' ),
186 ],
187 'buttontxt' =>[
188 'tmplibrary' => esc_html__( 'Import to Library', 'wp-plugin-manager' ),
189 'tmppage' => esc_html__( 'Import to Page', 'wp-plugin-manager' ),
190 'import' => esc_html__( 'Import', 'wp-plugin-manager' ),
191 'buynow' => esc_html__( 'Buy Now', 'wp-plugin-manager' ),
192 'buynow_link' => 'https://hasthemes.com/plugins/wp-plugin-manager-pro/?utm_source=admin&utm_medium=mainmenu&utm_campaign=free#pricing',
193 'preview' => esc_html__( 'Preview', 'wp-plugin-manager' ),
194 'installing' => esc_html__( 'Installing..', 'wp-plugin-manager' ),
195 'activating' => esc_html__( 'Activating..', 'wp-plugin-manager' ),
196 'active' => esc_html__( 'Active', 'wp-plugin-manager' ),
197 'pro' => __( 'Pro', 'wp-plugin-manager' ),
198 'modal' => [
199 'title' => __( 'BUY PRO', 'wp-plugin-manager' ),
200 'desc' => __( 'Our free version is great, but it doesn\'t have all our advanced features. The best way to unlock all of the features in our plugin is by purchasing the pro version.', 'wp-plugin-manager' )
201 ],
202 ],
203 'existingData' => get_option('htpm_options'),
204 'helpSection' => [
205 'title' => esc_html__('Need Help with Plugin Manager?', 'wp-plugin-manager'),
206 'description' => esc_html__('Our comprehensive documentation provides detailed information on how to use Plugin Manager effectively to improve your websites performance.', 'wp-plugin-manager'),
207 'documentation' => esc_html__('Documentation', 'wp-plugin-manager'),
208 'videoTutorial' => esc_html__('Video Tutorial', 'wp-plugin-manager'),
209 'support' => esc_html__('Support', 'wp-plugin-manager'),
210 'docLink' => 'https://hasthemes.com/docs/wp-plugin-manager/',
211 'videoLink' => 'https://www.youtube.com/watch?v=vrWVOEQjQe8',
212 'supportLink' => 'https://hasthemes.com/contact-us/',
213 'upgradeLink' => 'https://hasthemes.com/plugins/wp-plugin-manager-pro/?utm_source=admin&utm_medium=mainmenu&utm_campaign=free#pricing',
214 'licenseLink' => 'https://hasthemes.com/plugins/wp-plugin-manager-pro/?utm_source=admin&utm_medium=mainmenu&utm_campaign=free#pricing',
215 'recommendedPluginsLink' => 'https://hasthemes.com/plugins/',
216 ],
217 'adminSettings' => [
218 'modal_settings_fields' => $admin_settings->get_modal_settings_fields(),
219 'is_pro' => $admin_settings->is_pro(),
220 'labels_texts' => $admin_settings->get_labels_texts(),
221 'dashboard_settings' => $admin_settings->get_dashboard_settings(),
222 'menu_settings' => $admin_settings->get_menu_settings(),
223 'recommendations_plugins' => $admin_settings->get_recommendations_plugins(),
224 'backend_modal_settings' => $admin_settings->get_backend_modal_settings(),
225 'allSettings' => get_option('htpm_options') ? get_option('htpm_options') : [],
226 ],
227 ];
228 wp_localize_script( 'htpm-vue-settings', 'HTPMM', $localize_data );
229
230 }
231 }
232
233 /**
234 * Plugins Setting Page Link
235 */
236 function pro_submenu( ) {
237 add_submenu_page(
238 'htpm-options',
239 esc_html__('Upgrade to Pro', 'wp-plugin-manager'),
240 esc_html__('Upgrade to Pro', 'wp-plugin-manager'),
241 'manage_options',
242 'https://hasthemes.com/plugins/wp-plugin-manager-pro/?utm_source=admin&utm_medium=mainmenu&utm_campaign=free#pricing',
243 );
244 }
245
246
247 /**
248 * Add mu file
249 */
250 function create_mu_file(){
251 update_option('htpm_available_post_types', array_merge(array_keys(get_post_types( ['_builtin' => false, 'public' => true], 'names')), ['post', 'page']));
252 // create mu file
253 $mu_plugin_file_source_path = HTPM_ROOT_DIR . '/mu-plugin/htpm-mu-plugin.php';
254
255 if ( defined( 'WPMU_PLUGIN_DIR' ) ) {
256 $mu_plugins_path = WPMU_PLUGIN_DIR;
257 } else {
258 $mu_plugins_path = WP_CONTENT_DIR . '/' . 'mu-plugins';
259 }
260
261 $mu_plugin_file_path = $mu_plugins_path . '/htpm-mu-plugin.php';
262
263 $plugin_data = get_file_data( HTPM_ROOT_PL, array('Version'=>'Version'), 'plugin' );
264 $version = $plugin_data['Version'];
265
266 if(!is_dir( $mu_plugins_path )){
267 mkdir( $mu_plugins_path, 0755, true ); //phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_mkdir
268 copy( $mu_plugin_file_source_path, $mu_plugin_file_path );
269 }else{
270 // Always update MU plugin if main plugin version is greater than 1.0.8 or if file doesn't exist
271 if(!file_exists($mu_plugin_file_path) || version_compare($version, '1.0.8', '>') ){
272 copy( $mu_plugin_file_source_path, $mu_plugin_file_path );
273 }
274 }
275 }
276
277 function show_admin_diagnostic_data_notice() {
278 $notice_instance = HTPM_Diagnostic_Data::get_instance();
279 if ( ! $notice_instance->should_show_notice() ) {
280 return;
281 }
282 ob_start();
283 $notice_instance->show_notices();
284 $message = ob_get_clean();
285
286 if (! empty( $message ) ) {
287 HTPM_Notice::set_notice(
288 [
289 'id' => 'htpm-diagnostic-notice',
290 'type' => 'success',
291 'dismissible' => false,
292 'message_type' => 'html',
293 'message' => $message,
294 'display_after' => ( 7 * DAY_IN_SECONDS ),
295 'expire_time' => ( 0 * DAY_IN_SECONDS ),
296 'close_by' => 'transient'
297 ]
298 );
299 }
300 }
301
302 function show_admin_rating_notice() {
303 $logo_url = HTPM_ROOT_URL . "/assets/images/logo.jpg";
304 $message = '<div class="hastech-review-notice-wrap">
305 <div class="hastech-rating-notice-logo">
306 <img src="' . esc_url($logo_url) . '" alt="WP Plugin Manager" style="max-width:110px"/>
307 </div>
308 <div class="hastech-review-notice-content">
309 <h3>'.esc_html__('Thank you for choosing WP Plugin Manager to manage you plugins!','wp-plugin-manager').'</h3>
310 <p>'.esc_html__('Would you mind doing us a huge favor by providing your feedback on WordPress? Your support helps us spread the word and greatly boosts our motivation.','wp-plugin-manager').'</p>
311 <div class="hastech-review-notice-action">
312 <a href="https://wordpress.org/support/plugin/wp-plugin-manager/reviews/?filter=5#new-post" class="hastech-review-notice button-primary" target="_blank">'.esc_html__('Ok, you deserve it!','wp-plugin-manager').'</a>
313 <a href="#" class="hastech-notice-close hastech-review-notice"><span class="dashicons dashicons-calendar"></span>'.esc_html__('Maybe Later','wp-plugin-manager').'</a>
314 <a href="#" data-already-did="yes" class="hastech-notice-close hastech-review-notice"><span class="dashicons dashicons-smiley"></span>'.esc_html__('I already did','wp-plugin-manager').'</a>
315 </div>
316 </div>
317 </div>';
318
319 HTPM_Notice::set_notice(
320 [
321 'id' => 'htpm-rating-notice',
322 'type' => 'info',
323 'dismissible' => true,
324 'message_type' => 'html',
325 'message' => $message,
326 'display_after' => ( 14 * DAY_IN_SECONDS ),
327 'expire_time' => ( 20 * DAY_IN_SECONDS ),
328 'close_by' => 'transient'
329 ]
330 );
331 }
332
333
334
335 function show_admin_promo_notice() {
336 require HTPM_ROOT_DIR . '/includes/notice-manager.php';
337 $noticeManager = HTPM_Notice_Manager::instance();
338 $notices = $noticeManager->get_notices_info();
339 if(!empty($notices)) {
340 foreach ($notices as $notice) {
341 if(empty($notice['disable'])) {
342 HTPM_Notice::set_notice($notice);
343 }
344 }
345 }
346 }
347
348 }
349
350 HTPM_Main::instance();
351