-
Notifications
You must be signed in to change notification settings - Fork 0
/
wwd-acf-cleaner.php
71 lines (53 loc) · 1.58 KB
/
wwd-acf-cleaner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace whatwedo\AcfCleaner;
/*
Plugin Name: whatwedo ACF Cleaner
Description: Removes unused ACF meta data from the database
Version: 1.2.2
Author: whatwedo
Author URI: https://whatwedo.ch
License: MIT
*/
// If this file is called directly, abort.
if (! defined('WPINC')) {
die;
}
/**
* Constants
*/
define('WWDACFCLEANER_NAME', 'wwd-acf-cleaner');
define('WWDACFCLEANER_TITLE', 'whatwedo ACF Cleaner');
// Path
define('WWDACFCLEANER_DIR', plugin_dir_path(__FILE__));
define('WWDACFCLEANER_DIR_URL', plugin_dir_url(__FILE__));
/*
SPL Autoloading (included in PHP)
*/
spl_autoload_register(function ($class) {
$namespace = 'whatwedo\AcfCleaner\\';
if (strpos($class, $namespace) !== 0) {
return;
}
$path = explode('\\', strtolower(str_replace('whatwedo\\AcfCleaner\\', '', $class)));
$path[] = 'class-' . array_pop($path);
$file = plugin_dir_path(__FILE__) . 'class/' . implode(DIRECTORY_SEPARATOR, $path) . '.php';
require($file);
});
/**
* Init Classes
*/
add_action('plugins_loaded', function() {
if (!function_exists('get_field')) {
add_action('admin_notices', function () {
$class = 'notice notice-error';
$message = sprintf(
'Warning: You need to activate <a href="%s">Advanced Custom Fields</a> in order to use ' . WWDACFCLEANER_TITLE . '.'
, admin_url('plugins.php')
);
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), $message);
});
}
});
add_action('acf/init', function() {
new WP();
});