PluginProbe
Media Hygiene: Remove or Delete Unused Images and More! / trunk
Media Hygiene: Remove or Delete Unused Images and More! vtrunk
6.0.0 trunk 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 2.0.0 3.0.0 3.0.1 3.0.2 3.0.3 4.0.0 4.0.1 4.0.2 5.0.0
media-hygiene / media-hygiene.php

media-hygiene.php in Media Hygiene: Remove or Delete Unused Images and More! trunk, at media-hygiene.php

124 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 Plugin Name: Media Hygiene
5 Plugin URI: https://mediahygiene.com/
6 Description: A plugin to remove unused media from WordPress and free up space on hosting.
7 Version: 6.0.0
8 Requires PHP: 8.0
9 Author: Media Hygiene
10 Author URI: https://mediahygiene.com
11 License: Custom license, no Distribution allowed
12 */
13
14 defined('ABSPATH') or die('Plugin file cannot be accessed directly.');
15
16 class media_hygiene
17 {
18
19 public function __construct()
20 {
21 /* define */
22 define('MEDIA_HYGIENE', 'media-hygiene');
23 define('MH_FILE_VERSION', '6.0.0');
24 define('MH_PREFIX', 'wmh_');
25 define('MH_FILE_PATH', plugin_dir_path(__FILE__));
26 define('MH_FILE_URL', plugin_dir_url(__FILE__));
27 define('MH_BASE_NAME', 'media-hygiene/media-hygiene.php');
28
29 /* on activate plugin */
30 /* add_action('activated_plugin', array($this, 'fn_wmh_active_plugin')); */
31 /* update plugin */
32 add_action('init', array($this, 'fn_wmh_update_plugin_for_free'));
33 /* admin footer, feedback popup on deactive */
34 add_action('admin_footer', array($this, 'fn_wmh_deactivation_plugin_feedback_popup'));
35 /* enqueue script and style for jquery ui dialog */
36 add_action('admin_enqueue_scripts', array($this, 'fn_wmh_enqueue_scripts'));
37 /* init function */
38 $this->fn_wmh_init();
39 }
40
41 public function fn_wmh_active_plugin($plugin)
42 {
43 /* if media hygiene is active then it will take to the home Page */
44 if ($plugin == plugin_basename(__FILE__)) {
45 /* redirect page */
46 $redirect_page = 'admin.php?page=wmh-media-hygiene';
47 exit(wp_redirect(admin_url($redirect_page)));
48 }
49 }
50
51 public function fn_wmh_update_plugin_for_free()
52 {
53 if (get_option('wmh_plugin_db_version') === false) {
54 update_option('wmh_plugin_db_version', '2.0.0');
55 }
56
57 /* One-time migration: existing users who had analytics silently enabled by default
58 * never gave explicit consent. Reset them to 'pending' so they see the opt-in notice.
59 * Only fires until the user completes the new opt-in flow (sets wmh_analytics_consent_explicit). */
60 if (!get_option('wmh_analytics_consent_explicit')) {
61 if (get_option('wmh_send_data_to_server_permission') === 'on') {
62 update_option('wmh_send_data_to_server_permission', 'pending', 'no');
63 }
64 }
65 }
66
67 public function fn_wmh_init()
68 {
69
70 /* include */
71 include_once('includes/wmh-general.php');
72 include_once('includes/wmh-scan.php');
73 include_once('includes/wmh-settings.php');
74 include_once('includes/wmh-dashboard.php');
75 include_once('includes/wmh-download-unused-media.php');
76 include_once('includes/wmh-error-log.php');
77 include_once('includes/wmh-deleted-media.php');
78 include_once('includes/wmh-plugin-feedback.php');
79 include_once('includes/wmh-my-cron-job.php');
80
81 /* class */
82 include_once('class/admin/wmh-elementor.php');
83 include_once('class/admin/wmh-divi.php');
84 include_once('class/admin/wmh-bricks.php');
85 include_once('class/admin/wmh-enfold.php');
86 include_once('class/admin/wmh-vc.php');
87 include_once('class/admin/wmh-ocean-wp.php');
88
89 /* register activation hook for create custom table in database */
90 register_activation_hook(__FILE__, array($wmh_general, 'fn_wmh_create_table'));
91 }
92
93 public function fn_wmh_deactivation_plugin_feedback_popup()
94 {
95 $wmh_general = new wmh_general();
96 $wmh_general->fn_wmh_get_template('wmh-plugin-feedback-view.php');
97 }
98
99 public function fn_wmh_enqueue_scripts()
100 {
101 /* register */
102 wp_register_style('wmh-custom-feedback-css', MH_FILE_URL . '/assets/css/wmh-custom-feedback.css', false, MH_FILE_VERSION, 'all');
103 wp_register_script('wmh-custom-feedback-js', MH_FILE_URL . '/assets/js/wmh-custom-feedback.js', array('jquery'), MH_FILE_VERSION, true);
104
105 /* enqueue */
106 wp_enqueue_style('wp-jquery-ui-dialog');
107 wp_enqueue_style('wmh-custom-feedback-css');
108 wp_enqueue_script('jquery-ui-dialog');
109 wp_enqueue_script('wmh-custom-feedback-js');
110
111 /* localize script for wmh-custom-feedback-js. */
112 wp_localize_script(
113 'wmh-custom-feedback-js',
114 'wmhFeedbackObj',
115 array(
116 'ajaxurl' => admin_url('admin-ajax.php'),
117 'nonce' => wp_create_nonce('wmh_customer_feedback'),
118 )
119 );
120 }
121 }
122
123 $media_hygiene = new media_hygiene();
124