-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclass-themeforest-check.php
200 lines (163 loc) · 4.58 KB
/
class-themeforest-check.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/**
* ThemeForest-Check
*
* @package ThemeForest_Check
* @author Japh <[email protected]>
* @license GPL-2.0+
* @link http://themeforest.net
* @copyright 2013 Japh
*/
/**
* ThemeForest-Check class
*
* @package ThemeForest_Check
* @author Japh <[email protected]>
*/
class ThemeForest_Check {
/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 1.0.0
*
* @var string
*/
protected $version = '1.0.4';
/**
* Unique identifier for your plugin.
*
* Use this value (not the variable name) as the text domain when internationalizing strings of text. It should
* match the Text Domain file header in the main plugin file.
*
* @since 1.0.0
*
* @var string
*/
protected $plugin_slug = 'themeforest-check';
/**
* Instance of this class.
*
* @since 1.0.0
*
* @var object
*/
protected static $instance = null;
/**
* Slug of the plugin screen.
*
* @since 1.0.0
*
* @var string
*/
protected $plugin_screen_hook_suffix = null;
/**
* Initialize the plugin by setting localization, filters, and administration functions.
*
* @since 1.0.0
*/
private function __construct() {
// Load plugin text domain
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
// Load admin style sheet and JavaScript.
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
add_action( 'themecheck_checks_loaded', array( $this, 'disable_checks' ) );
add_action( 'themecheck_checks_loaded', array( $this, 'add_checks' ) );
}
/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
$domain = $this->plugin_slug;
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
}
/**
* Disable Theme-Check checks that aren't relevant for ThemeForest themes
*
* @since 1.0.0
*/
function disable_checks() {
global $themechecks;
$checks_to_disable = array(
'IncludeCheck',
'I18NCheck',
'AdminMenu',
'Bad_Checks',
'MalwareCheck',
'Theme_Support',
'CustomCheck',
'EditorStyleCheck',
'IframeCheck',
);
foreach ( $themechecks as $keyindex => $check ) {
if ( $check instanceof themecheck ) {
$check_class = get_class( $check );
if ( in_array( $check_class, $checks_to_disable ) ) {
unset( $themechecks[$keyindex] );
}
}
}
}
/**
* Disable Theme-Check checks that aren't relevant for ThemeForest themes
*
* @since 1.0.0
*/
function add_checks() {
global $themechecks;
// load all the checks in the checks directory
$dir = 'checks';
foreach ( glob( dirname( __FILE__ ) . '/' .$dir . '/*.php' ) as $file ) {
include ( $file );
}
}
/**
* Register and enqueue admin-specific style sheet.
*
* @since 1.0.1
*/
public function enqueue_admin_styles() {
$screen = get_current_screen();
if ( 'appearance_page_themecheck' == $screen->id ) {
if ( ! isset( $_POST[ 'themename' ] ) ) {
wp_enqueue_style( $this->plugin_slug .'-admin-styles', plugins_url( 'css/admin.css', __FILE__ ), array(), $this->version );
}
}
}
/**
* Register and enqueue admin-specific JavaScript.
*
* @since 1.0.1
*/
public function enqueue_admin_scripts() {
$screen = get_current_screen();
if ( 'appearance_page_themecheck' == $screen->id ) {
wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ), $this->version );
if ( ! isset( $_POST[ 'themename' ] ) ) {
$intro = '';
$intro .= '<h2><img src="' . plugins_url( 'img/themeforest-logo-mini.png', __FILE__ ) . '" /> ThemeForest-Check</h2>';
$intro .= '<p>A supplement to the Theme-Check plugin that adds checks for ThemeForest\'s WordPress Theme Submission Requirements, and removes checks that aren\'t required.</p>';
$tfc_intro['text'] = $intro;
wp_localize_script( $this->plugin_slug . '-admin-script', 'tfc_intro', $tfc_intro );
}
}
}
}