@@ -7,56 +7,56 @@ |
||
7 | 7 | */ |
8 | 8 | abstract class ActionScheduler_Lock { |
9 | 9 | |
10 | - /** @var ActionScheduler_Lock */ |
|
11 | - private static $locker = NULL; |
|
12 | - |
|
13 | - /** @var int */ |
|
14 | - protected static $lock_duration = MINUTE_IN_SECONDS; |
|
15 | - |
|
16 | - /** |
|
17 | - * Check if a lock is set for a given lock type. |
|
18 | - * |
|
19 | - * @param string $lock_type A string to identify different lock types. |
|
20 | - * @return bool |
|
21 | - */ |
|
22 | - public function is_locked( $lock_type ) { |
|
23 | - return ( $this->get_expiration( $lock_type ) >= time() ); |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * Set a lock. |
|
28 | - * |
|
29 | - * @param string $lock_type A string to identify different lock types. |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - abstract public function set( $lock_type ); |
|
33 | - |
|
34 | - /** |
|
35 | - * If a lock is set, return the timestamp it was set to expiry. |
|
36 | - * |
|
37 | - * @param string $lock_type A string to identify different lock types. |
|
38 | - * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. |
|
39 | - */ |
|
40 | - abstract public function get_expiration( $lock_type ); |
|
41 | - |
|
42 | - /** |
|
43 | - * Get the amount of time to set for a given lock. 60 seconds by default. |
|
44 | - * |
|
45 | - * @param string $lock_type A string to identify different lock types. |
|
46 | - * @return int |
|
47 | - */ |
|
48 | - protected function get_duration( $lock_type ) { |
|
49 | - return apply_filters( 'action_scheduler_lock_duration', self::$lock_duration, $lock_type ); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @return ActionScheduler_Lock |
|
54 | - */ |
|
55 | - public static function instance() { |
|
56 | - if ( empty( self::$locker ) ) { |
|
57 | - $class = apply_filters( 'action_scheduler_lock_class', 'ActionScheduler_OptionLock' ); |
|
58 | - self::$locker = new $class(); |
|
59 | - } |
|
60 | - return self::$locker; |
|
61 | - } |
|
10 | + /** @var ActionScheduler_Lock */ |
|
11 | + private static $locker = NULL; |
|
12 | + |
|
13 | + /** @var int */ |
|
14 | + protected static $lock_duration = MINUTE_IN_SECONDS; |
|
15 | + |
|
16 | + /** |
|
17 | + * Check if a lock is set for a given lock type. |
|
18 | + * |
|
19 | + * @param string $lock_type A string to identify different lock types. |
|
20 | + * @return bool |
|
21 | + */ |
|
22 | + public function is_locked( $lock_type ) { |
|
23 | + return ( $this->get_expiration( $lock_type ) >= time() ); |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * Set a lock. |
|
28 | + * |
|
29 | + * @param string $lock_type A string to identify different lock types. |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + abstract public function set( $lock_type ); |
|
33 | + |
|
34 | + /** |
|
35 | + * If a lock is set, return the timestamp it was set to expiry. |
|
36 | + * |
|
37 | + * @param string $lock_type A string to identify different lock types. |
|
38 | + * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. |
|
39 | + */ |
|
40 | + abstract public function get_expiration( $lock_type ); |
|
41 | + |
|
42 | + /** |
|
43 | + * Get the amount of time to set for a given lock. 60 seconds by default. |
|
44 | + * |
|
45 | + * @param string $lock_type A string to identify different lock types. |
|
46 | + * @return int |
|
47 | + */ |
|
48 | + protected function get_duration( $lock_type ) { |
|
49 | + return apply_filters( 'action_scheduler_lock_duration', self::$lock_duration, $lock_type ); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @return ActionScheduler_Lock |
|
54 | + */ |
|
55 | + public static function instance() { |
|
56 | + if ( empty( self::$locker ) ) { |
|
57 | + $class = apply_filters( 'action_scheduler_lock_class', 'ActionScheduler_OptionLock' ); |
|
58 | + self::$locker = new $class(); |
|
59 | + } |
|
60 | + return self::$locker; |
|
61 | + } |
|
62 | 62 | } |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | * @param string $lock_type A string to identify different lock types. |
20 | 20 | * @return bool |
21 | 21 | */ |
22 | - public function is_locked( $lock_type ) { |
|
23 | - return ( $this->get_expiration( $lock_type ) >= time() ); |
|
22 | + public function is_locked($lock_type) { |
|
23 | + return ($this->get_expiration($lock_type) >= time()); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param string $lock_type A string to identify different lock types. |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | - abstract public function set( $lock_type ); |
|
32 | + abstract public function set($lock_type); |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * If a lock is set, return the timestamp it was set to expiry. |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param string $lock_type A string to identify different lock types. |
38 | 38 | * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. |
39 | 39 | */ |
40 | - abstract public function get_expiration( $lock_type ); |
|
40 | + abstract public function get_expiration($lock_type); |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Get the amount of time to set for a given lock. 60 seconds by default. |
@@ -45,16 +45,16 @@ discard block |
||
45 | 45 | * @param string $lock_type A string to identify different lock types. |
46 | 46 | * @return int |
47 | 47 | */ |
48 | - protected function get_duration( $lock_type ) { |
|
49 | - return apply_filters( 'action_scheduler_lock_duration', self::$lock_duration, $lock_type ); |
|
48 | + protected function get_duration($lock_type) { |
|
49 | + return apply_filters('action_scheduler_lock_duration', self::$lock_duration, $lock_type); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @return ActionScheduler_Lock |
54 | 54 | */ |
55 | 55 | public static function instance() { |
56 | - if ( empty( self::$locker ) ) { |
|
57 | - $class = apply_filters( 'action_scheduler_lock_class', 'ActionScheduler_OptionLock' ); |
|
56 | + if (empty(self::$locker)) { |
|
57 | + $class = apply_filters('action_scheduler_lock_class', 'ActionScheduler_OptionLock'); |
|
58 | 58 | self::$locker = new $class(); |
59 | 59 | } |
60 | 60 | return self::$locker; |
@@ -8,268 +8,268 @@ |
||
8 | 8 | * @codeCoverageIgnore |
9 | 9 | */ |
10 | 10 | abstract class ActionScheduler { |
11 | - private static $plugin_file = ''; |
|
12 | - /** @var ActionScheduler_ActionFactory */ |
|
13 | - private static $factory = NULL; |
|
14 | - |
|
15 | - public static function factory() { |
|
16 | - if ( !isset(self::$factory) ) { |
|
17 | - self::$factory = new ActionScheduler_ActionFactory(); |
|
18 | - } |
|
19 | - return self::$factory; |
|
20 | - } |
|
21 | - |
|
22 | - public static function store() { |
|
23 | - return ActionScheduler_Store::instance(); |
|
24 | - } |
|
25 | - |
|
26 | - public static function lock() { |
|
27 | - return ActionScheduler_Lock::instance(); |
|
28 | - } |
|
29 | - |
|
30 | - public static function logger() { |
|
31 | - return ActionScheduler_Logger::instance(); |
|
32 | - } |
|
33 | - |
|
34 | - public static function runner() { |
|
35 | - return ActionScheduler_QueueRunner::instance(); |
|
36 | - } |
|
37 | - |
|
38 | - public static function admin_view() { |
|
39 | - return ActionScheduler_AdminView::instance(); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Get the absolute system path to the plugin directory, or a file therein |
|
44 | - * @static |
|
45 | - * @param string $path |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public static function plugin_path( $path ) { |
|
49 | - $base = dirname(self::$plugin_file); |
|
50 | - if ( $path ) { |
|
51 | - return trailingslashit($base).$path; |
|
52 | - } else { |
|
53 | - return untrailingslashit($base); |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Get the absolute URL to the plugin directory, or a file therein |
|
59 | - * @static |
|
60 | - * @param string $path |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public static function plugin_url( $path ) { |
|
64 | - return plugins_url($path, self::$plugin_file); |
|
65 | - } |
|
66 | - |
|
67 | - public static function autoload( $class ) { |
|
68 | - $d = DIRECTORY_SEPARATOR; |
|
69 | - $classes_dir = self::plugin_path( 'classes' . $d ); |
|
70 | - $separator = strrpos( $class, '\\' ); |
|
71 | - if ( false !== $separator ) { |
|
72 | - if ( 0 !== strpos( $class, 'Action_Scheduler' ) ) { |
|
73 | - return; |
|
74 | - } |
|
75 | - $class = substr( $class, $separator + 1 ); |
|
76 | - } |
|
77 | - |
|
78 | - if ( 'Deprecated' === substr( $class, -10 ) ) { |
|
79 | - $dir = self::plugin_path( 'deprecated' . $d ); |
|
80 | - } elseif ( self::is_class_abstract( $class ) ) { |
|
81 | - $dir = $classes_dir . 'abstracts' . $d; |
|
82 | - } elseif ( self::is_class_migration( $class ) ) { |
|
83 | - $dir = $classes_dir . 'migration' . $d; |
|
84 | - } elseif ( 'Schedule' === substr( $class, -8 ) ) { |
|
85 | - $dir = $classes_dir . 'schedules' . $d; |
|
86 | - } elseif ( 'Action' === substr( $class, -6 ) ) { |
|
87 | - $dir = $classes_dir . 'actions' . $d; |
|
88 | - } elseif ( 'Schema' === substr( $class, -6 ) ) { |
|
89 | - $dir = $classes_dir . 'schema' . $d; |
|
90 | - } elseif ( strpos( $class, 'ActionScheduler' ) === 0 ) { |
|
91 | - $segments = explode( '_', $class ); |
|
92 | - $type = isset( $segments[ 1 ] ) ? $segments[ 1 ] : ''; |
|
93 | - |
|
94 | - switch ( $type ) { |
|
95 | - case 'WPCLI': |
|
96 | - $dir = $classes_dir . 'WP_CLI' . $d; |
|
97 | - break; |
|
98 | - case 'DBLogger': |
|
99 | - case 'DBStore': |
|
100 | - case 'HybridStore': |
|
101 | - case 'wpPostStore': |
|
102 | - case 'wpCommentLogger': |
|
103 | - $dir = $classes_dir . 'data-stores' . $d; |
|
104 | - break; |
|
105 | - default: |
|
106 | - $dir = $classes_dir; |
|
107 | - break; |
|
108 | - } |
|
109 | - } elseif ( self::is_class_cli( $class ) ) { |
|
110 | - $dir = $classes_dir . 'WP_CLI' . $d; |
|
111 | - } elseif ( strpos( $class, 'CronExpression' ) === 0 ) { |
|
112 | - $dir = self::plugin_path( 'lib' . $d . 'cron-expression' . $d ); |
|
113 | - } elseif ( strpos( $class, 'WP_Async_Request' ) === 0 ) { |
|
114 | - $dir = self::plugin_path( 'lib' . $d ); |
|
115 | - } else { |
|
116 | - return; |
|
117 | - } |
|
118 | - |
|
119 | - if ( file_exists( "{$dir}{$class}.php" ) ) { |
|
120 | - include( "{$dir}{$class}.php" ); |
|
121 | - return; |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Initialize the plugin |
|
127 | - * |
|
128 | - * @static |
|
129 | - * @param string $plugin_file |
|
130 | - */ |
|
131 | - public static function init( $plugin_file ) { |
|
132 | - self::$plugin_file = $plugin_file; |
|
133 | - spl_autoload_register( array( __CLASS__, 'autoload' ) ); |
|
134 | - |
|
135 | - /** |
|
136 | - * Fires in the early stages of Action Scheduler init hook. |
|
137 | - */ |
|
138 | - do_action( 'action_scheduler_pre_init' ); |
|
139 | - |
|
140 | - require_once( self::plugin_path( 'functions.php' ) ); |
|
141 | - ActionScheduler_DataController::init(); |
|
142 | - |
|
143 | - $store = self::store(); |
|
144 | - $logger = self::logger(); |
|
145 | - $runner = self::runner(); |
|
146 | - $admin_view = self::admin_view(); |
|
147 | - |
|
148 | - // Ensure initialization on plugin activation. |
|
149 | - if ( ! did_action( 'init' ) ) { |
|
150 | - add_action( 'init', array( $admin_view, 'init' ), 0, 0 ); // run before $store::init() |
|
151 | - add_action( 'init', array( $store, 'init' ), 1, 0 ); |
|
152 | - add_action( 'init', array( $logger, 'init' ), 1, 0 ); |
|
153 | - add_action( 'init', array( $runner, 'init' ), 1, 0 ); |
|
154 | - } else { |
|
155 | - $admin_view->init(); |
|
156 | - $store->init(); |
|
157 | - $logger->init(); |
|
158 | - $runner->init(); |
|
159 | - } |
|
160 | - |
|
161 | - if ( apply_filters( 'action_scheduler_load_deprecated_functions', true ) ) { |
|
162 | - require_once( self::plugin_path( 'deprecated/functions.php' ) ); |
|
163 | - } |
|
164 | - |
|
165 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
166 | - WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Scheduler_command' ); |
|
167 | - if ( ! ActionScheduler_DataController::is_migration_complete() && Controller::instance()->allow_migration() ) { |
|
168 | - $command = new Migration_Command(); |
|
169 | - $command->register(); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Handle WP comment cleanup after migration. |
|
175 | - */ |
|
176 | - if ( is_a( $logger, 'ActionScheduler_DBLogger' ) && ActionScheduler_DataController::is_migration_complete() && ActionScheduler_WPCommentCleaner::has_logs() ) { |
|
177 | - ActionScheduler_WPCommentCleaner::init(); |
|
178 | - } |
|
179 | - |
|
180 | - add_action( 'action_scheduler/migration_complete', 'ActionScheduler_WPCommentCleaner::maybe_schedule_cleanup' ); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Determine if the class is one of our abstract classes. |
|
185 | - * |
|
186 | - * @since 3.0.0 |
|
187 | - * |
|
188 | - * @param string $class The class name. |
|
189 | - * |
|
190 | - * @return bool |
|
191 | - */ |
|
192 | - protected static function is_class_abstract( $class ) { |
|
193 | - static $abstracts = array( |
|
194 | - 'ActionScheduler' => true, |
|
195 | - 'ActionScheduler_Abstract_ListTable' => true, |
|
196 | - 'ActionScheduler_Abstract_QueueRunner' => true, |
|
197 | - 'ActionScheduler_Abstract_Schedule' => true, |
|
198 | - 'ActionScheduler_Abstract_RecurringSchedule' => true, |
|
199 | - 'ActionScheduler_Lock' => true, |
|
200 | - 'ActionScheduler_Logger' => true, |
|
201 | - 'ActionScheduler_Abstract_Schema' => true, |
|
202 | - 'ActionScheduler_Store' => true, |
|
203 | - 'ActionScheduler_TimezoneHelper' => true, |
|
204 | - ); |
|
205 | - |
|
206 | - return isset( $abstracts[ $class ] ) && $abstracts[ $class ]; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Determine if the class is one of our migration classes. |
|
211 | - * |
|
212 | - * @since 3.0.0 |
|
213 | - * |
|
214 | - * @param string $class The class name. |
|
215 | - * |
|
216 | - * @return bool |
|
217 | - */ |
|
218 | - protected static function is_class_migration( $class ) { |
|
219 | - static $migration_segments = array( |
|
220 | - 'ActionMigrator' => true, |
|
221 | - 'BatchFetcher' => true, |
|
222 | - 'DBStoreMigrator' => true, |
|
223 | - 'DryRun' => true, |
|
224 | - 'LogMigrator' => true, |
|
225 | - 'Config' => true, |
|
226 | - 'Controller' => true, |
|
227 | - 'Runner' => true, |
|
228 | - 'Scheduler' => true, |
|
229 | - ); |
|
230 | - |
|
231 | - $segments = explode( '_', $class ); |
|
232 | - $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class; |
|
233 | - |
|
234 | - return isset( $migration_segments[ $segment ] ) && $migration_segments[ $segment ]; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Determine if the class is one of our WP CLI classes. |
|
239 | - * |
|
240 | - * @since 3.0.0 |
|
241 | - * |
|
242 | - * @param string $class The class name. |
|
243 | - * |
|
244 | - * @return bool |
|
245 | - */ |
|
246 | - protected static function is_class_cli( $class ) { |
|
247 | - static $cli_segments = array( |
|
248 | - 'QueueRunner' => true, |
|
249 | - 'Command' => true, |
|
250 | - 'ProgressBar' => true, |
|
251 | - ); |
|
252 | - |
|
253 | - $segments = explode( '_', $class ); |
|
254 | - $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class; |
|
255 | - |
|
256 | - return isset( $cli_segments[ $segment ] ) && $cli_segments[ $segment ]; |
|
257 | - } |
|
258 | - |
|
259 | - final public function __clone() { |
|
260 | - trigger_error("Singleton. No cloning allowed!", E_USER_ERROR); |
|
261 | - } |
|
262 | - |
|
263 | - final public function __wakeup() { |
|
264 | - trigger_error("Singleton. No serialization allowed!", E_USER_ERROR); |
|
265 | - } |
|
266 | - |
|
267 | - final private function __construct() {} |
|
268 | - |
|
269 | - /** Deprecated **/ |
|
270 | - |
|
271 | - public static function get_datetime_object( $when = null, $timezone = 'UTC' ) { |
|
272 | - _deprecated_function( __METHOD__, '2.0', 'wcs_add_months()' ); |
|
273 | - return as_get_datetime_object( $when, $timezone ); |
|
274 | - } |
|
11 | + private static $plugin_file = ''; |
|
12 | + /** @var ActionScheduler_ActionFactory */ |
|
13 | + private static $factory = NULL; |
|
14 | + |
|
15 | + public static function factory() { |
|
16 | + if ( !isset(self::$factory) ) { |
|
17 | + self::$factory = new ActionScheduler_ActionFactory(); |
|
18 | + } |
|
19 | + return self::$factory; |
|
20 | + } |
|
21 | + |
|
22 | + public static function store() { |
|
23 | + return ActionScheduler_Store::instance(); |
|
24 | + } |
|
25 | + |
|
26 | + public static function lock() { |
|
27 | + return ActionScheduler_Lock::instance(); |
|
28 | + } |
|
29 | + |
|
30 | + public static function logger() { |
|
31 | + return ActionScheduler_Logger::instance(); |
|
32 | + } |
|
33 | + |
|
34 | + public static function runner() { |
|
35 | + return ActionScheduler_QueueRunner::instance(); |
|
36 | + } |
|
37 | + |
|
38 | + public static function admin_view() { |
|
39 | + return ActionScheduler_AdminView::instance(); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Get the absolute system path to the plugin directory, or a file therein |
|
44 | + * @static |
|
45 | + * @param string $path |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public static function plugin_path( $path ) { |
|
49 | + $base = dirname(self::$plugin_file); |
|
50 | + if ( $path ) { |
|
51 | + return trailingslashit($base).$path; |
|
52 | + } else { |
|
53 | + return untrailingslashit($base); |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Get the absolute URL to the plugin directory, or a file therein |
|
59 | + * @static |
|
60 | + * @param string $path |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public static function plugin_url( $path ) { |
|
64 | + return plugins_url($path, self::$plugin_file); |
|
65 | + } |
|
66 | + |
|
67 | + public static function autoload( $class ) { |
|
68 | + $d = DIRECTORY_SEPARATOR; |
|
69 | + $classes_dir = self::plugin_path( 'classes' . $d ); |
|
70 | + $separator = strrpos( $class, '\\' ); |
|
71 | + if ( false !== $separator ) { |
|
72 | + if ( 0 !== strpos( $class, 'Action_Scheduler' ) ) { |
|
73 | + return; |
|
74 | + } |
|
75 | + $class = substr( $class, $separator + 1 ); |
|
76 | + } |
|
77 | + |
|
78 | + if ( 'Deprecated' === substr( $class, -10 ) ) { |
|
79 | + $dir = self::plugin_path( 'deprecated' . $d ); |
|
80 | + } elseif ( self::is_class_abstract( $class ) ) { |
|
81 | + $dir = $classes_dir . 'abstracts' . $d; |
|
82 | + } elseif ( self::is_class_migration( $class ) ) { |
|
83 | + $dir = $classes_dir . 'migration' . $d; |
|
84 | + } elseif ( 'Schedule' === substr( $class, -8 ) ) { |
|
85 | + $dir = $classes_dir . 'schedules' . $d; |
|
86 | + } elseif ( 'Action' === substr( $class, -6 ) ) { |
|
87 | + $dir = $classes_dir . 'actions' . $d; |
|
88 | + } elseif ( 'Schema' === substr( $class, -6 ) ) { |
|
89 | + $dir = $classes_dir . 'schema' . $d; |
|
90 | + } elseif ( strpos( $class, 'ActionScheduler' ) === 0 ) { |
|
91 | + $segments = explode( '_', $class ); |
|
92 | + $type = isset( $segments[ 1 ] ) ? $segments[ 1 ] : ''; |
|
93 | + |
|
94 | + switch ( $type ) { |
|
95 | + case 'WPCLI': |
|
96 | + $dir = $classes_dir . 'WP_CLI' . $d; |
|
97 | + break; |
|
98 | + case 'DBLogger': |
|
99 | + case 'DBStore': |
|
100 | + case 'HybridStore': |
|
101 | + case 'wpPostStore': |
|
102 | + case 'wpCommentLogger': |
|
103 | + $dir = $classes_dir . 'data-stores' . $d; |
|
104 | + break; |
|
105 | + default: |
|
106 | + $dir = $classes_dir; |
|
107 | + break; |
|
108 | + } |
|
109 | + } elseif ( self::is_class_cli( $class ) ) { |
|
110 | + $dir = $classes_dir . 'WP_CLI' . $d; |
|
111 | + } elseif ( strpos( $class, 'CronExpression' ) === 0 ) { |
|
112 | + $dir = self::plugin_path( 'lib' . $d . 'cron-expression' . $d ); |
|
113 | + } elseif ( strpos( $class, 'WP_Async_Request' ) === 0 ) { |
|
114 | + $dir = self::plugin_path( 'lib' . $d ); |
|
115 | + } else { |
|
116 | + return; |
|
117 | + } |
|
118 | + |
|
119 | + if ( file_exists( "{$dir}{$class}.php" ) ) { |
|
120 | + include( "{$dir}{$class}.php" ); |
|
121 | + return; |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Initialize the plugin |
|
127 | + * |
|
128 | + * @static |
|
129 | + * @param string $plugin_file |
|
130 | + */ |
|
131 | + public static function init( $plugin_file ) { |
|
132 | + self::$plugin_file = $plugin_file; |
|
133 | + spl_autoload_register( array( __CLASS__, 'autoload' ) ); |
|
134 | + |
|
135 | + /** |
|
136 | + * Fires in the early stages of Action Scheduler init hook. |
|
137 | + */ |
|
138 | + do_action( 'action_scheduler_pre_init' ); |
|
139 | + |
|
140 | + require_once( self::plugin_path( 'functions.php' ) ); |
|
141 | + ActionScheduler_DataController::init(); |
|
142 | + |
|
143 | + $store = self::store(); |
|
144 | + $logger = self::logger(); |
|
145 | + $runner = self::runner(); |
|
146 | + $admin_view = self::admin_view(); |
|
147 | + |
|
148 | + // Ensure initialization on plugin activation. |
|
149 | + if ( ! did_action( 'init' ) ) { |
|
150 | + add_action( 'init', array( $admin_view, 'init' ), 0, 0 ); // run before $store::init() |
|
151 | + add_action( 'init', array( $store, 'init' ), 1, 0 ); |
|
152 | + add_action( 'init', array( $logger, 'init' ), 1, 0 ); |
|
153 | + add_action( 'init', array( $runner, 'init' ), 1, 0 ); |
|
154 | + } else { |
|
155 | + $admin_view->init(); |
|
156 | + $store->init(); |
|
157 | + $logger->init(); |
|
158 | + $runner->init(); |
|
159 | + } |
|
160 | + |
|
161 | + if ( apply_filters( 'action_scheduler_load_deprecated_functions', true ) ) { |
|
162 | + require_once( self::plugin_path( 'deprecated/functions.php' ) ); |
|
163 | + } |
|
164 | + |
|
165 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
166 | + WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Scheduler_command' ); |
|
167 | + if ( ! ActionScheduler_DataController::is_migration_complete() && Controller::instance()->allow_migration() ) { |
|
168 | + $command = new Migration_Command(); |
|
169 | + $command->register(); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Handle WP comment cleanup after migration. |
|
175 | + */ |
|
176 | + if ( is_a( $logger, 'ActionScheduler_DBLogger' ) && ActionScheduler_DataController::is_migration_complete() && ActionScheduler_WPCommentCleaner::has_logs() ) { |
|
177 | + ActionScheduler_WPCommentCleaner::init(); |
|
178 | + } |
|
179 | + |
|
180 | + add_action( 'action_scheduler/migration_complete', 'ActionScheduler_WPCommentCleaner::maybe_schedule_cleanup' ); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Determine if the class is one of our abstract classes. |
|
185 | + * |
|
186 | + * @since 3.0.0 |
|
187 | + * |
|
188 | + * @param string $class The class name. |
|
189 | + * |
|
190 | + * @return bool |
|
191 | + */ |
|
192 | + protected static function is_class_abstract( $class ) { |
|
193 | + static $abstracts = array( |
|
194 | + 'ActionScheduler' => true, |
|
195 | + 'ActionScheduler_Abstract_ListTable' => true, |
|
196 | + 'ActionScheduler_Abstract_QueueRunner' => true, |
|
197 | + 'ActionScheduler_Abstract_Schedule' => true, |
|
198 | + 'ActionScheduler_Abstract_RecurringSchedule' => true, |
|
199 | + 'ActionScheduler_Lock' => true, |
|
200 | + 'ActionScheduler_Logger' => true, |
|
201 | + 'ActionScheduler_Abstract_Schema' => true, |
|
202 | + 'ActionScheduler_Store' => true, |
|
203 | + 'ActionScheduler_TimezoneHelper' => true, |
|
204 | + ); |
|
205 | + |
|
206 | + return isset( $abstracts[ $class ] ) && $abstracts[ $class ]; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Determine if the class is one of our migration classes. |
|
211 | + * |
|
212 | + * @since 3.0.0 |
|
213 | + * |
|
214 | + * @param string $class The class name. |
|
215 | + * |
|
216 | + * @return bool |
|
217 | + */ |
|
218 | + protected static function is_class_migration( $class ) { |
|
219 | + static $migration_segments = array( |
|
220 | + 'ActionMigrator' => true, |
|
221 | + 'BatchFetcher' => true, |
|
222 | + 'DBStoreMigrator' => true, |
|
223 | + 'DryRun' => true, |
|
224 | + 'LogMigrator' => true, |
|
225 | + 'Config' => true, |
|
226 | + 'Controller' => true, |
|
227 | + 'Runner' => true, |
|
228 | + 'Scheduler' => true, |
|
229 | + ); |
|
230 | + |
|
231 | + $segments = explode( '_', $class ); |
|
232 | + $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class; |
|
233 | + |
|
234 | + return isset( $migration_segments[ $segment ] ) && $migration_segments[ $segment ]; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Determine if the class is one of our WP CLI classes. |
|
239 | + * |
|
240 | + * @since 3.0.0 |
|
241 | + * |
|
242 | + * @param string $class The class name. |
|
243 | + * |
|
244 | + * @return bool |
|
245 | + */ |
|
246 | + protected static function is_class_cli( $class ) { |
|
247 | + static $cli_segments = array( |
|
248 | + 'QueueRunner' => true, |
|
249 | + 'Command' => true, |
|
250 | + 'ProgressBar' => true, |
|
251 | + ); |
|
252 | + |
|
253 | + $segments = explode( '_', $class ); |
|
254 | + $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class; |
|
255 | + |
|
256 | + return isset( $cli_segments[ $segment ] ) && $cli_segments[ $segment ]; |
|
257 | + } |
|
258 | + |
|
259 | + final public function __clone() { |
|
260 | + trigger_error("Singleton. No cloning allowed!", E_USER_ERROR); |
|
261 | + } |
|
262 | + |
|
263 | + final public function __wakeup() { |
|
264 | + trigger_error("Singleton. No serialization allowed!", E_USER_ERROR); |
|
265 | + } |
|
266 | + |
|
267 | + final private function __construct() {} |
|
268 | + |
|
269 | + /** Deprecated **/ |
|
270 | + |
|
271 | + public static function get_datetime_object( $when = null, $timezone = 'UTC' ) { |
|
272 | + _deprecated_function( __METHOD__, '2.0', 'wcs_add_months()' ); |
|
273 | + return as_get_datetime_object( $when, $timezone ); |
|
274 | + } |
|
275 | 275 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | private static $factory = NULL; |
14 | 14 | |
15 | 15 | public static function factory() { |
16 | - if ( !isset(self::$factory) ) { |
|
16 | + if (!isset(self::$factory)) { |
|
17 | 17 | self::$factory = new ActionScheduler_ActionFactory(); |
18 | 18 | } |
19 | 19 | return self::$factory; |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | * @param string $path |
46 | 46 | * @return string |
47 | 47 | */ |
48 | - public static function plugin_path( $path ) { |
|
48 | + public static function plugin_path($path) { |
|
49 | 49 | $base = dirname(self::$plugin_file); |
50 | - if ( $path ) { |
|
51 | - return trailingslashit($base).$path; |
|
50 | + if ($path) { |
|
51 | + return trailingslashit($base) . $path; |
|
52 | 52 | } else { |
53 | 53 | return untrailingslashit($base); |
54 | 54 | } |
@@ -60,38 +60,38 @@ discard block |
||
60 | 60 | * @param string $path |
61 | 61 | * @return string |
62 | 62 | */ |
63 | - public static function plugin_url( $path ) { |
|
63 | + public static function plugin_url($path) { |
|
64 | 64 | return plugins_url($path, self::$plugin_file); |
65 | 65 | } |
66 | 66 | |
67 | - public static function autoload( $class ) { |
|
67 | + public static function autoload($class) { |
|
68 | 68 | $d = DIRECTORY_SEPARATOR; |
69 | - $classes_dir = self::plugin_path( 'classes' . $d ); |
|
70 | - $separator = strrpos( $class, '\\' ); |
|
71 | - if ( false !== $separator ) { |
|
72 | - if ( 0 !== strpos( $class, 'Action_Scheduler' ) ) { |
|
69 | + $classes_dir = self::plugin_path('classes' . $d); |
|
70 | + $separator = strrpos($class, '\\'); |
|
71 | + if (false !== $separator) { |
|
72 | + if (0 !== strpos($class, 'Action_Scheduler')) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | - $class = substr( $class, $separator + 1 ); |
|
75 | + $class = substr($class, $separator + 1); |
|
76 | 76 | } |
77 | 77 | |
78 | - if ( 'Deprecated' === substr( $class, -10 ) ) { |
|
79 | - $dir = self::plugin_path( 'deprecated' . $d ); |
|
80 | - } elseif ( self::is_class_abstract( $class ) ) { |
|
78 | + if ('Deprecated' === substr($class, -10)) { |
|
79 | + $dir = self::plugin_path('deprecated' . $d); |
|
80 | + } elseif (self::is_class_abstract($class)) { |
|
81 | 81 | $dir = $classes_dir . 'abstracts' . $d; |
82 | - } elseif ( self::is_class_migration( $class ) ) { |
|
82 | + } elseif (self::is_class_migration($class)) { |
|
83 | 83 | $dir = $classes_dir . 'migration' . $d; |
84 | - } elseif ( 'Schedule' === substr( $class, -8 ) ) { |
|
84 | + } elseif ('Schedule' === substr($class, -8)) { |
|
85 | 85 | $dir = $classes_dir . 'schedules' . $d; |
86 | - } elseif ( 'Action' === substr( $class, -6 ) ) { |
|
86 | + } elseif ('Action' === substr($class, -6)) { |
|
87 | 87 | $dir = $classes_dir . 'actions' . $d; |
88 | - } elseif ( 'Schema' === substr( $class, -6 ) ) { |
|
88 | + } elseif ('Schema' === substr($class, -6)) { |
|
89 | 89 | $dir = $classes_dir . 'schema' . $d; |
90 | - } elseif ( strpos( $class, 'ActionScheduler' ) === 0 ) { |
|
91 | - $segments = explode( '_', $class ); |
|
92 | - $type = isset( $segments[ 1 ] ) ? $segments[ 1 ] : ''; |
|
90 | + } elseif (strpos($class, 'ActionScheduler') === 0) { |
|
91 | + $segments = explode('_', $class); |
|
92 | + $type = isset($segments[1]) ? $segments[1] : ''; |
|
93 | 93 | |
94 | - switch ( $type ) { |
|
94 | + switch ($type) { |
|
95 | 95 | case 'WPCLI': |
96 | 96 | $dir = $classes_dir . 'WP_CLI' . $d; |
97 | 97 | break; |
@@ -106,18 +106,18 @@ discard block |
||
106 | 106 | $dir = $classes_dir; |
107 | 107 | break; |
108 | 108 | } |
109 | - } elseif ( self::is_class_cli( $class ) ) { |
|
109 | + } elseif (self::is_class_cli($class)) { |
|
110 | 110 | $dir = $classes_dir . 'WP_CLI' . $d; |
111 | - } elseif ( strpos( $class, 'CronExpression' ) === 0 ) { |
|
112 | - $dir = self::plugin_path( 'lib' . $d . 'cron-expression' . $d ); |
|
113 | - } elseif ( strpos( $class, 'WP_Async_Request' ) === 0 ) { |
|
114 | - $dir = self::plugin_path( 'lib' . $d ); |
|
111 | + } elseif (strpos($class, 'CronExpression') === 0) { |
|
112 | + $dir = self::plugin_path('lib' . $d . 'cron-expression' . $d); |
|
113 | + } elseif (strpos($class, 'WP_Async_Request') === 0) { |
|
114 | + $dir = self::plugin_path('lib' . $d); |
|
115 | 115 | } else { |
116 | 116 | return; |
117 | 117 | } |
118 | 118 | |
119 | - if ( file_exists( "{$dir}{$class}.php" ) ) { |
|
120 | - include( "{$dir}{$class}.php" ); |
|
119 | + if (file_exists("{$dir}{$class}.php")) { |
|
120 | + include("{$dir}{$class}.php"); |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | } |
@@ -128,16 +128,16 @@ discard block |
||
128 | 128 | * @static |
129 | 129 | * @param string $plugin_file |
130 | 130 | */ |
131 | - public static function init( $plugin_file ) { |
|
131 | + public static function init($plugin_file) { |
|
132 | 132 | self::$plugin_file = $plugin_file; |
133 | - spl_autoload_register( array( __CLASS__, 'autoload' ) ); |
|
133 | + spl_autoload_register(array(__CLASS__, 'autoload')); |
|
134 | 134 | |
135 | 135 | /** |
136 | 136 | * Fires in the early stages of Action Scheduler init hook. |
137 | 137 | */ |
138 | - do_action( 'action_scheduler_pre_init' ); |
|
138 | + do_action('action_scheduler_pre_init'); |
|
139 | 139 | |
140 | - require_once( self::plugin_path( 'functions.php' ) ); |
|
140 | + require_once(self::plugin_path('functions.php')); |
|
141 | 141 | ActionScheduler_DataController::init(); |
142 | 142 | |
143 | 143 | $store = self::store(); |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | $admin_view = self::admin_view(); |
147 | 147 | |
148 | 148 | // Ensure initialization on plugin activation. |
149 | - if ( ! did_action( 'init' ) ) { |
|
150 | - add_action( 'init', array( $admin_view, 'init' ), 0, 0 ); // run before $store::init() |
|
151 | - add_action( 'init', array( $store, 'init' ), 1, 0 ); |
|
152 | - add_action( 'init', array( $logger, 'init' ), 1, 0 ); |
|
153 | - add_action( 'init', array( $runner, 'init' ), 1, 0 ); |
|
149 | + if (!did_action('init')) { |
|
150 | + add_action('init', array($admin_view, 'init'), 0, 0); // run before $store::init() |
|
151 | + add_action('init', array($store, 'init'), 1, 0); |
|
152 | + add_action('init', array($logger, 'init'), 1, 0); |
|
153 | + add_action('init', array($runner, 'init'), 1, 0); |
|
154 | 154 | } else { |
155 | 155 | $admin_view->init(); |
156 | 156 | $store->init(); |
@@ -158,13 +158,13 @@ discard block |
||
158 | 158 | $runner->init(); |
159 | 159 | } |
160 | 160 | |
161 | - if ( apply_filters( 'action_scheduler_load_deprecated_functions', true ) ) { |
|
162 | - require_once( self::plugin_path( 'deprecated/functions.php' ) ); |
|
161 | + if (apply_filters('action_scheduler_load_deprecated_functions', true)) { |
|
162 | + require_once(self::plugin_path('deprecated/functions.php')); |
|
163 | 163 | } |
164 | 164 | |
165 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
166 | - WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Scheduler_command' ); |
|
167 | - if ( ! ActionScheduler_DataController::is_migration_complete() && Controller::instance()->allow_migration() ) { |
|
165 | + if (defined('WP_CLI') && WP_CLI) { |
|
166 | + WP_CLI::add_command('action-scheduler', 'ActionScheduler_WPCLI_Scheduler_command'); |
|
167 | + if (!ActionScheduler_DataController::is_migration_complete() && Controller::instance()->allow_migration()) { |
|
168 | 168 | $command = new Migration_Command(); |
169 | 169 | $command->register(); |
170 | 170 | } |
@@ -173,11 +173,11 @@ discard block |
||
173 | 173 | /** |
174 | 174 | * Handle WP comment cleanup after migration. |
175 | 175 | */ |
176 | - if ( is_a( $logger, 'ActionScheduler_DBLogger' ) && ActionScheduler_DataController::is_migration_complete() && ActionScheduler_WPCommentCleaner::has_logs() ) { |
|
176 | + if (is_a($logger, 'ActionScheduler_DBLogger') && ActionScheduler_DataController::is_migration_complete() && ActionScheduler_WPCommentCleaner::has_logs()) { |
|
177 | 177 | ActionScheduler_WPCommentCleaner::init(); |
178 | 178 | } |
179 | 179 | |
180 | - add_action( 'action_scheduler/migration_complete', 'ActionScheduler_WPCommentCleaner::maybe_schedule_cleanup' ); |
|
180 | + add_action('action_scheduler/migration_complete', 'ActionScheduler_WPCommentCleaner::maybe_schedule_cleanup'); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * |
190 | 190 | * @return bool |
191 | 191 | */ |
192 | - protected static function is_class_abstract( $class ) { |
|
192 | + protected static function is_class_abstract($class) { |
|
193 | 193 | static $abstracts = array( |
194 | 194 | 'ActionScheduler' => true, |
195 | 195 | 'ActionScheduler_Abstract_ListTable' => true, |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | 'ActionScheduler_TimezoneHelper' => true, |
204 | 204 | ); |
205 | 205 | |
206 | - return isset( $abstracts[ $class ] ) && $abstracts[ $class ]; |
|
206 | + return isset($abstracts[$class]) && $abstracts[$class]; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return bool |
217 | 217 | */ |
218 | - protected static function is_class_migration( $class ) { |
|
218 | + protected static function is_class_migration($class) { |
|
219 | 219 | static $migration_segments = array( |
220 | 220 | 'ActionMigrator' => true, |
221 | 221 | 'BatchFetcher' => true, |
@@ -228,10 +228,10 @@ discard block |
||
228 | 228 | 'Scheduler' => true, |
229 | 229 | ); |
230 | 230 | |
231 | - $segments = explode( '_', $class ); |
|
232 | - $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class; |
|
231 | + $segments = explode('_', $class); |
|
232 | + $segment = isset($segments[1]) ? $segments[1] : $class; |
|
233 | 233 | |
234 | - return isset( $migration_segments[ $segment ] ) && $migration_segments[ $segment ]; |
|
234 | + return isset($migration_segments[$segment]) && $migration_segments[$segment]; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -243,17 +243,17 @@ discard block |
||
243 | 243 | * |
244 | 244 | * @return bool |
245 | 245 | */ |
246 | - protected static function is_class_cli( $class ) { |
|
246 | + protected static function is_class_cli($class) { |
|
247 | 247 | static $cli_segments = array( |
248 | 248 | 'QueueRunner' => true, |
249 | 249 | 'Command' => true, |
250 | 250 | 'ProgressBar' => true, |
251 | 251 | ); |
252 | 252 | |
253 | - $segments = explode( '_', $class ); |
|
254 | - $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class; |
|
253 | + $segments = explode('_', $class); |
|
254 | + $segment = isset($segments[1]) ? $segments[1] : $class; |
|
255 | 255 | |
256 | - return isset( $cli_segments[ $segment ] ) && $cli_segments[ $segment ]; |
|
256 | + return isset($cli_segments[$segment]) && $cli_segments[$segment]; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | final public function __clone() { |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | |
269 | 269 | /** Deprecated **/ |
270 | 270 | |
271 | - public static function get_datetime_object( $when = null, $timezone = 'UTC' ) { |
|
272 | - _deprecated_function( __METHOD__, '2.0', 'wcs_add_months()' ); |
|
273 | - return as_get_datetime_object( $when, $timezone ); |
|
271 | + public static function get_datetime_object($when = null, $timezone = 'UTC') { |
|
272 | + _deprecated_function(__METHOD__, '2.0', 'wcs_add_months()'); |
|
273 | + return as_get_datetime_object($when, $timezone); |
|
274 | 274 | } |
275 | 275 | } |
@@ -12,124 +12,124 @@ |
||
12 | 12 | */ |
13 | 13 | abstract class ActionScheduler_Abstract_Schema { |
14 | 14 | |
15 | - /** |
|
16 | - * @var int Increment this value in derived class to trigger a schema update. |
|
17 | - */ |
|
18 | - protected $schema_version = 1; |
|
19 | - |
|
20 | - /** |
|
21 | - * @var array Names of tables that will be registered by this class. |
|
22 | - */ |
|
23 | - protected $tables = []; |
|
24 | - |
|
25 | - /** |
|
26 | - * Register tables with WordPress, and create them if needed. |
|
27 | - * |
|
28 | - * @param bool $force_update Optional. Default false. Use true to always run the schema update. |
|
29 | - * |
|
30 | - * @return void |
|
31 | - */ |
|
32 | - public function register_tables( $force_update = false ) { |
|
33 | - global $wpdb; |
|
34 | - |
|
35 | - // make WP aware of our tables |
|
36 | - foreach ( $this->tables as $table ) { |
|
37 | - $wpdb->tables[] = $table; |
|
38 | - $name = $this->get_full_table_name( $table ); |
|
39 | - $wpdb->$table = $name; |
|
40 | - } |
|
41 | - |
|
42 | - // create the tables |
|
43 | - if ( $this->schema_update_required() || $force_update ) { |
|
44 | - foreach ( $this->tables as $table ) { |
|
45 | - $this->update_table( $table ); |
|
46 | - } |
|
47 | - $this->mark_schema_update_complete(); |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * @param string $table The name of the table |
|
53 | - * |
|
54 | - * @return string The CREATE TABLE statement, suitable for passing to dbDelta |
|
55 | - */ |
|
56 | - abstract protected function get_table_definition( $table ); |
|
57 | - |
|
58 | - /** |
|
59 | - * Determine if the database schema is out of date |
|
60 | - * by comparing the integer found in $this->schema_version |
|
61 | - * with the option set in the WordPress options table |
|
62 | - * |
|
63 | - * @return bool |
|
64 | - */ |
|
65 | - private function schema_update_required() { |
|
66 | - $option_name = 'schema-' . static::class; |
|
67 | - $version_found_in_db = get_option( $option_name, 0 ); |
|
68 | - |
|
69 | - // Check for schema option stored by the Action Scheduler Custom Tables plugin in case site has migrated from that plugin with an older schema |
|
70 | - if ( 0 === $version_found_in_db ) { |
|
71 | - |
|
72 | - $plugin_option_name = 'schema-'; |
|
73 | - |
|
74 | - switch ( static::class ) { |
|
75 | - case 'ActionScheduler_StoreSchema' : |
|
76 | - $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Store_Table_Maker'; |
|
77 | - break; |
|
78 | - case 'ActionScheduler_LoggerSchema' : |
|
79 | - $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Logger_Table_Maker'; |
|
80 | - break; |
|
81 | - } |
|
82 | - |
|
83 | - $version_found_in_db = get_option( $plugin_option_name, 0 ); |
|
84 | - |
|
85 | - delete_option( $plugin_option_name ); |
|
86 | - } |
|
87 | - |
|
88 | - return version_compare( $version_found_in_db, $this->schema_version, '<' ); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Update the option in WordPress to indicate that |
|
93 | - * our schema is now up to date |
|
94 | - * |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - private function mark_schema_update_complete() { |
|
98 | - $option_name = 'schema-' . static::class; |
|
99 | - |
|
100 | - // work around race conditions and ensure that our option updates |
|
101 | - $value_to_save = (string) $this->schema_version . '.0.' . time(); |
|
102 | - |
|
103 | - update_option( $option_name, $value_to_save ); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Update the schema for the given table |
|
108 | - * |
|
109 | - * @param string $table The name of the table to update |
|
110 | - * |
|
111 | - * @return void |
|
112 | - */ |
|
113 | - private function update_table( $table ) { |
|
114 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
115 | - $definition = $this->get_table_definition( $table ); |
|
116 | - if ( $definition ) { |
|
117 | - $updated = dbDelta( $definition ); |
|
118 | - foreach ( $updated as $updated_table => $update_description ) { |
|
119 | - if ( strpos( $update_description, 'Created table' ) === 0 ) { |
|
120 | - do_action( 'action_scheduler/created_table', $updated_table, $table ); |
|
121 | - } |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @param string $table |
|
128 | - * |
|
129 | - * @return string The full name of the table, including the |
|
130 | - * table prefix for the current blog |
|
131 | - */ |
|
132 | - protected function get_full_table_name( $table ) { |
|
133 | - return $GLOBALS[ 'wpdb' ]->prefix . $table; |
|
134 | - } |
|
15 | + /** |
|
16 | + * @var int Increment this value in derived class to trigger a schema update. |
|
17 | + */ |
|
18 | + protected $schema_version = 1; |
|
19 | + |
|
20 | + /** |
|
21 | + * @var array Names of tables that will be registered by this class. |
|
22 | + */ |
|
23 | + protected $tables = []; |
|
24 | + |
|
25 | + /** |
|
26 | + * Register tables with WordPress, and create them if needed. |
|
27 | + * |
|
28 | + * @param bool $force_update Optional. Default false. Use true to always run the schema update. |
|
29 | + * |
|
30 | + * @return void |
|
31 | + */ |
|
32 | + public function register_tables( $force_update = false ) { |
|
33 | + global $wpdb; |
|
34 | + |
|
35 | + // make WP aware of our tables |
|
36 | + foreach ( $this->tables as $table ) { |
|
37 | + $wpdb->tables[] = $table; |
|
38 | + $name = $this->get_full_table_name( $table ); |
|
39 | + $wpdb->$table = $name; |
|
40 | + } |
|
41 | + |
|
42 | + // create the tables |
|
43 | + if ( $this->schema_update_required() || $force_update ) { |
|
44 | + foreach ( $this->tables as $table ) { |
|
45 | + $this->update_table( $table ); |
|
46 | + } |
|
47 | + $this->mark_schema_update_complete(); |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * @param string $table The name of the table |
|
53 | + * |
|
54 | + * @return string The CREATE TABLE statement, suitable for passing to dbDelta |
|
55 | + */ |
|
56 | + abstract protected function get_table_definition( $table ); |
|
57 | + |
|
58 | + /** |
|
59 | + * Determine if the database schema is out of date |
|
60 | + * by comparing the integer found in $this->schema_version |
|
61 | + * with the option set in the WordPress options table |
|
62 | + * |
|
63 | + * @return bool |
|
64 | + */ |
|
65 | + private function schema_update_required() { |
|
66 | + $option_name = 'schema-' . static::class; |
|
67 | + $version_found_in_db = get_option( $option_name, 0 ); |
|
68 | + |
|
69 | + // Check for schema option stored by the Action Scheduler Custom Tables plugin in case site has migrated from that plugin with an older schema |
|
70 | + if ( 0 === $version_found_in_db ) { |
|
71 | + |
|
72 | + $plugin_option_name = 'schema-'; |
|
73 | + |
|
74 | + switch ( static::class ) { |
|
75 | + case 'ActionScheduler_StoreSchema' : |
|
76 | + $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Store_Table_Maker'; |
|
77 | + break; |
|
78 | + case 'ActionScheduler_LoggerSchema' : |
|
79 | + $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Logger_Table_Maker'; |
|
80 | + break; |
|
81 | + } |
|
82 | + |
|
83 | + $version_found_in_db = get_option( $plugin_option_name, 0 ); |
|
84 | + |
|
85 | + delete_option( $plugin_option_name ); |
|
86 | + } |
|
87 | + |
|
88 | + return version_compare( $version_found_in_db, $this->schema_version, '<' ); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Update the option in WordPress to indicate that |
|
93 | + * our schema is now up to date |
|
94 | + * |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + private function mark_schema_update_complete() { |
|
98 | + $option_name = 'schema-' . static::class; |
|
99 | + |
|
100 | + // work around race conditions and ensure that our option updates |
|
101 | + $value_to_save = (string) $this->schema_version . '.0.' . time(); |
|
102 | + |
|
103 | + update_option( $option_name, $value_to_save ); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Update the schema for the given table |
|
108 | + * |
|
109 | + * @param string $table The name of the table to update |
|
110 | + * |
|
111 | + * @return void |
|
112 | + */ |
|
113 | + private function update_table( $table ) { |
|
114 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
115 | + $definition = $this->get_table_definition( $table ); |
|
116 | + if ( $definition ) { |
|
117 | + $updated = dbDelta( $definition ); |
|
118 | + foreach ( $updated as $updated_table => $update_description ) { |
|
119 | + if ( strpos( $update_description, 'Created table' ) === 0 ) { |
|
120 | + do_action( 'action_scheduler/created_table', $updated_table, $table ); |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @param string $table |
|
128 | + * |
|
129 | + * @return string The full name of the table, including the |
|
130 | + * table prefix for the current blog |
|
131 | + */ |
|
132 | + protected function get_full_table_name( $table ) { |
|
133 | + return $GLOBALS[ 'wpdb' ]->prefix . $table; |
|
134 | + } |
|
135 | 135 | } |
136 | 136 | \ No newline at end of file |
@@ -29,20 +29,20 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return void |
31 | 31 | */ |
32 | - public function register_tables( $force_update = false ) { |
|
32 | + public function register_tables($force_update = false) { |
|
33 | 33 | global $wpdb; |
34 | 34 | |
35 | 35 | // make WP aware of our tables |
36 | - foreach ( $this->tables as $table ) { |
|
36 | + foreach ($this->tables as $table) { |
|
37 | 37 | $wpdb->tables[] = $table; |
38 | - $name = $this->get_full_table_name( $table ); |
|
38 | + $name = $this->get_full_table_name($table); |
|
39 | 39 | $wpdb->$table = $name; |
40 | 40 | } |
41 | 41 | |
42 | 42 | // create the tables |
43 | - if ( $this->schema_update_required() || $force_update ) { |
|
44 | - foreach ( $this->tables as $table ) { |
|
45 | - $this->update_table( $table ); |
|
43 | + if ($this->schema_update_required() || $force_update) { |
|
44 | + foreach ($this->tables as $table) { |
|
45 | + $this->update_table($table); |
|
46 | 46 | } |
47 | 47 | $this->mark_schema_update_complete(); |
48 | 48 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return string The CREATE TABLE statement, suitable for passing to dbDelta |
55 | 55 | */ |
56 | - abstract protected function get_table_definition( $table ); |
|
56 | + abstract protected function get_table_definition($table); |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * Determine if the database schema is out of date |
@@ -64,14 +64,14 @@ discard block |
||
64 | 64 | */ |
65 | 65 | private function schema_update_required() { |
66 | 66 | $option_name = 'schema-' . static::class; |
67 | - $version_found_in_db = get_option( $option_name, 0 ); |
|
67 | + $version_found_in_db = get_option($option_name, 0); |
|
68 | 68 | |
69 | 69 | // Check for schema option stored by the Action Scheduler Custom Tables plugin in case site has migrated from that plugin with an older schema |
70 | - if ( 0 === $version_found_in_db ) { |
|
70 | + if (0 === $version_found_in_db) { |
|
71 | 71 | |
72 | 72 | $plugin_option_name = 'schema-'; |
73 | 73 | |
74 | - switch ( static::class ) { |
|
74 | + switch (static::class) { |
|
75 | 75 | case 'ActionScheduler_StoreSchema' : |
76 | 76 | $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Store_Table_Maker'; |
77 | 77 | break; |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | break; |
81 | 81 | } |
82 | 82 | |
83 | - $version_found_in_db = get_option( $plugin_option_name, 0 ); |
|
83 | + $version_found_in_db = get_option($plugin_option_name, 0); |
|
84 | 84 | |
85 | - delete_option( $plugin_option_name ); |
|
85 | + delete_option($plugin_option_name); |
|
86 | 86 | } |
87 | 87 | |
88 | - return version_compare( $version_found_in_db, $this->schema_version, '<' ); |
|
88 | + return version_compare($version_found_in_db, $this->schema_version, '<'); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | // work around race conditions and ensure that our option updates |
101 | 101 | $value_to_save = (string) $this->schema_version . '.0.' . time(); |
102 | 102 | |
103 | - update_option( $option_name, $value_to_save ); |
|
103 | + update_option($option_name, $value_to_save); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,14 +110,14 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return void |
112 | 112 | */ |
113 | - private function update_table( $table ) { |
|
114 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
115 | - $definition = $this->get_table_definition( $table ); |
|
116 | - if ( $definition ) { |
|
117 | - $updated = dbDelta( $definition ); |
|
118 | - foreach ( $updated as $updated_table => $update_description ) { |
|
119 | - if ( strpos( $update_description, 'Created table' ) === 0 ) { |
|
120 | - do_action( 'action_scheduler/created_table', $updated_table, $table ); |
|
113 | + private function update_table($table) { |
|
114 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
115 | + $definition = $this->get_table_definition($table); |
|
116 | + if ($definition) { |
|
117 | + $updated = dbDelta($definition); |
|
118 | + foreach ($updated as $updated_table => $update_description) { |
|
119 | + if (strpos($update_description, 'Created table') === 0) { |
|
120 | + do_action('action_scheduler/created_table', $updated_table, $table); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @return string The full name of the table, including the |
130 | 130 | * table prefix for the current blog |
131 | 131 | */ |
132 | - protected function get_full_table_name( $table ) { |
|
133 | - return $GLOBALS[ 'wpdb' ]->prefix . $table; |
|
132 | + protected function get_full_table_name($table) { |
|
133 | + return $GLOBALS['wpdb']->prefix . $table; |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | \ No newline at end of file |
@@ -5,95 +5,95 @@ |
||
5 | 5 | */ |
6 | 6 | class ActionScheduler_Compatibility { |
7 | 7 | |
8 | - /** |
|
9 | - * Converts a shorthand byte value to an integer byte value. |
|
10 | - * |
|
11 | - * Wrapper for wp_convert_hr_to_bytes(), moved to load.php in WordPress 4.6 from media.php |
|
12 | - * |
|
13 | - * @link https://secure.php.net/manual/en/function.ini-get.php |
|
14 | - * @link https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes |
|
15 | - * |
|
16 | - * @param string $value A (PHP ini) byte value, either shorthand or ordinary. |
|
17 | - * @return int An integer byte value. |
|
18 | - */ |
|
19 | - public static function convert_hr_to_bytes( $value ) { |
|
20 | - if ( function_exists( 'wp_convert_hr_to_bytes' ) ) { |
|
21 | - return wp_convert_hr_to_bytes( $value ); |
|
22 | - } |
|
8 | + /** |
|
9 | + * Converts a shorthand byte value to an integer byte value. |
|
10 | + * |
|
11 | + * Wrapper for wp_convert_hr_to_bytes(), moved to load.php in WordPress 4.6 from media.php |
|
12 | + * |
|
13 | + * @link https://secure.php.net/manual/en/function.ini-get.php |
|
14 | + * @link https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes |
|
15 | + * |
|
16 | + * @param string $value A (PHP ini) byte value, either shorthand or ordinary. |
|
17 | + * @return int An integer byte value. |
|
18 | + */ |
|
19 | + public static function convert_hr_to_bytes( $value ) { |
|
20 | + if ( function_exists( 'wp_convert_hr_to_bytes' ) ) { |
|
21 | + return wp_convert_hr_to_bytes( $value ); |
|
22 | + } |
|
23 | 23 | |
24 | - $value = strtolower( trim( $value ) ); |
|
25 | - $bytes = (int) $value; |
|
24 | + $value = strtolower( trim( $value ) ); |
|
25 | + $bytes = (int) $value; |
|
26 | 26 | |
27 | - if ( false !== strpos( $value, 'g' ) ) { |
|
28 | - $bytes *= GB_IN_BYTES; |
|
29 | - } elseif ( false !== strpos( $value, 'm' ) ) { |
|
30 | - $bytes *= MB_IN_BYTES; |
|
31 | - } elseif ( false !== strpos( $value, 'k' ) ) { |
|
32 | - $bytes *= KB_IN_BYTES; |
|
33 | - } |
|
27 | + if ( false !== strpos( $value, 'g' ) ) { |
|
28 | + $bytes *= GB_IN_BYTES; |
|
29 | + } elseif ( false !== strpos( $value, 'm' ) ) { |
|
30 | + $bytes *= MB_IN_BYTES; |
|
31 | + } elseif ( false !== strpos( $value, 'k' ) ) { |
|
32 | + $bytes *= KB_IN_BYTES; |
|
33 | + } |
|
34 | 34 | |
35 | - // Deal with large (float) values which run into the maximum integer size. |
|
36 | - return min( $bytes, PHP_INT_MAX ); |
|
37 | - } |
|
35 | + // Deal with large (float) values which run into the maximum integer size. |
|
36 | + return min( $bytes, PHP_INT_MAX ); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Attempts to raise the PHP memory limit for memory intensive processes. |
|
41 | - * |
|
42 | - * Only allows raising the existing limit and prevents lowering it. |
|
43 | - * |
|
44 | - * Wrapper for wp_raise_memory_limit(), added in WordPress v4.6.0 |
|
45 | - * |
|
46 | - * @return bool|int|string The limit that was set or false on failure. |
|
47 | - */ |
|
48 | - public static function raise_memory_limit() { |
|
49 | - if ( function_exists( 'wp_raise_memory_limit' ) ) { |
|
50 | - return wp_raise_memory_limit( 'admin' ); |
|
51 | - } |
|
39 | + /** |
|
40 | + * Attempts to raise the PHP memory limit for memory intensive processes. |
|
41 | + * |
|
42 | + * Only allows raising the existing limit and prevents lowering it. |
|
43 | + * |
|
44 | + * Wrapper for wp_raise_memory_limit(), added in WordPress v4.6.0 |
|
45 | + * |
|
46 | + * @return bool|int|string The limit that was set or false on failure. |
|
47 | + */ |
|
48 | + public static function raise_memory_limit() { |
|
49 | + if ( function_exists( 'wp_raise_memory_limit' ) ) { |
|
50 | + return wp_raise_memory_limit( 'admin' ); |
|
51 | + } |
|
52 | 52 | |
53 | - $current_limit = @ini_get( 'memory_limit' ); |
|
54 | - $current_limit_int = self::convert_hr_to_bytes( $current_limit ); |
|
53 | + $current_limit = @ini_get( 'memory_limit' ); |
|
54 | + $current_limit_int = self::convert_hr_to_bytes( $current_limit ); |
|
55 | 55 | |
56 | - if ( -1 === $current_limit_int ) { |
|
57 | - return false; |
|
58 | - } |
|
56 | + if ( -1 === $current_limit_int ) { |
|
57 | + return false; |
|
58 | + } |
|
59 | 59 | |
60 | - $wp_max_limit = WP_MAX_MEMORY_LIMIT; |
|
61 | - $wp_max_limit_int = self::convert_hr_to_bytes( $wp_max_limit ); |
|
62 | - $filtered_limit = apply_filters( 'admin_memory_limit', $wp_max_limit ); |
|
63 | - $filtered_limit_int = self::convert_hr_to_bytes( $filtered_limit ); |
|
60 | + $wp_max_limit = WP_MAX_MEMORY_LIMIT; |
|
61 | + $wp_max_limit_int = self::convert_hr_to_bytes( $wp_max_limit ); |
|
62 | + $filtered_limit = apply_filters( 'admin_memory_limit', $wp_max_limit ); |
|
63 | + $filtered_limit_int = self::convert_hr_to_bytes( $filtered_limit ); |
|
64 | 64 | |
65 | - if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) { |
|
66 | - if ( false !== @ini_set( 'memory_limit', $filtered_limit ) ) { |
|
67 | - return $filtered_limit; |
|
68 | - } else { |
|
69 | - return false; |
|
70 | - } |
|
71 | - } elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) { |
|
72 | - if ( false !== @ini_set( 'memory_limit', $wp_max_limit ) ) { |
|
73 | - return $wp_max_limit; |
|
74 | - } else { |
|
75 | - return false; |
|
76 | - } |
|
77 | - } |
|
78 | - return false; |
|
79 | - } |
|
65 | + if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) { |
|
66 | + if ( false !== @ini_set( 'memory_limit', $filtered_limit ) ) { |
|
67 | + return $filtered_limit; |
|
68 | + } else { |
|
69 | + return false; |
|
70 | + } |
|
71 | + } elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) { |
|
72 | + if ( false !== @ini_set( 'memory_limit', $wp_max_limit ) ) { |
|
73 | + return $wp_max_limit; |
|
74 | + } else { |
|
75 | + return false; |
|
76 | + } |
|
77 | + } |
|
78 | + return false; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Attempts to raise the PHP timeout for time intensive processes. |
|
83 | - * |
|
84 | - * Only allows raising the existing limit and prevents lowering it. Wrapper for wc_set_time_limit(), when available. |
|
85 | - * |
|
86 | - * @param int The time limit in seconds. |
|
87 | - */ |
|
88 | - public static function raise_time_limit( $limit = 0 ) { |
|
89 | - if ( $limit < ini_get( 'max_execution_time' ) ) { |
|
90 | - return; |
|
91 | - } |
|
81 | + /** |
|
82 | + * Attempts to raise the PHP timeout for time intensive processes. |
|
83 | + * |
|
84 | + * Only allows raising the existing limit and prevents lowering it. Wrapper for wc_set_time_limit(), when available. |
|
85 | + * |
|
86 | + * @param int The time limit in seconds. |
|
87 | + */ |
|
88 | + public static function raise_time_limit( $limit = 0 ) { |
|
89 | + if ( $limit < ini_get( 'max_execution_time' ) ) { |
|
90 | + return; |
|
91 | + } |
|
92 | 92 | |
93 | - if ( function_exists( 'wc_set_time_limit' ) ) { |
|
94 | - wc_set_time_limit( $limit ); |
|
95 | - } elseif ( function_exists( 'set_time_limit' ) && false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
96 | - @set_time_limit( $limit ); |
|
97 | - } |
|
98 | - } |
|
93 | + if ( function_exists( 'wc_set_time_limit' ) ) { |
|
94 | + wc_set_time_limit( $limit ); |
|
95 | + } elseif ( function_exists( 'set_time_limit' ) && false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
96 | + @set_time_limit( $limit ); |
|
97 | + } |
|
98 | + } |
|
99 | 99 | } |
@@ -16,24 +16,24 @@ discard block |
||
16 | 16 | * @param string $value A (PHP ini) byte value, either shorthand or ordinary. |
17 | 17 | * @return int An integer byte value. |
18 | 18 | */ |
19 | - public static function convert_hr_to_bytes( $value ) { |
|
20 | - if ( function_exists( 'wp_convert_hr_to_bytes' ) ) { |
|
21 | - return wp_convert_hr_to_bytes( $value ); |
|
19 | + public static function convert_hr_to_bytes($value) { |
|
20 | + if (function_exists('wp_convert_hr_to_bytes')) { |
|
21 | + return wp_convert_hr_to_bytes($value); |
|
22 | 22 | } |
23 | 23 | |
24 | - $value = strtolower( trim( $value ) ); |
|
24 | + $value = strtolower(trim($value)); |
|
25 | 25 | $bytes = (int) $value; |
26 | 26 | |
27 | - if ( false !== strpos( $value, 'g' ) ) { |
|
27 | + if (false !== strpos($value, 'g')) { |
|
28 | 28 | $bytes *= GB_IN_BYTES; |
29 | - } elseif ( false !== strpos( $value, 'm' ) ) { |
|
29 | + } elseif (false !== strpos($value, 'm')) { |
|
30 | 30 | $bytes *= MB_IN_BYTES; |
31 | - } elseif ( false !== strpos( $value, 'k' ) ) { |
|
31 | + } elseif (false !== strpos($value, 'k')) { |
|
32 | 32 | $bytes *= KB_IN_BYTES; |
33 | 33 | } |
34 | 34 | |
35 | 35 | // Deal with large (float) values which run into the maximum integer size. |
36 | - return min( $bytes, PHP_INT_MAX ); |
|
36 | + return min($bytes, PHP_INT_MAX); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -46,30 +46,30 @@ discard block |
||
46 | 46 | * @return bool|int|string The limit that was set or false on failure. |
47 | 47 | */ |
48 | 48 | public static function raise_memory_limit() { |
49 | - if ( function_exists( 'wp_raise_memory_limit' ) ) { |
|
50 | - return wp_raise_memory_limit( 'admin' ); |
|
49 | + if (function_exists('wp_raise_memory_limit')) { |
|
50 | + return wp_raise_memory_limit('admin'); |
|
51 | 51 | } |
52 | 52 | |
53 | - $current_limit = @ini_get( 'memory_limit' ); |
|
54 | - $current_limit_int = self::convert_hr_to_bytes( $current_limit ); |
|
53 | + $current_limit = @ini_get('memory_limit'); |
|
54 | + $current_limit_int = self::convert_hr_to_bytes($current_limit); |
|
55 | 55 | |
56 | 56 | if ( -1 === $current_limit_int ) { |
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $wp_max_limit = WP_MAX_MEMORY_LIMIT; |
61 | - $wp_max_limit_int = self::convert_hr_to_bytes( $wp_max_limit ); |
|
62 | - $filtered_limit = apply_filters( 'admin_memory_limit', $wp_max_limit ); |
|
63 | - $filtered_limit_int = self::convert_hr_to_bytes( $filtered_limit ); |
|
61 | + $wp_max_limit_int = self::convert_hr_to_bytes($wp_max_limit); |
|
62 | + $filtered_limit = apply_filters('admin_memory_limit', $wp_max_limit); |
|
63 | + $filtered_limit_int = self::convert_hr_to_bytes($filtered_limit); |
|
64 | 64 | |
65 | - if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) { |
|
66 | - if ( false !== @ini_set( 'memory_limit', $filtered_limit ) ) { |
|
65 | + if ( -1 === $filtered_limit_int || ($filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int) ) { |
|
66 | + if (false !== @ini_set('memory_limit', $filtered_limit)) { |
|
67 | 67 | return $filtered_limit; |
68 | 68 | } else { |
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | } elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) { |
72 | - if ( false !== @ini_set( 'memory_limit', $wp_max_limit ) ) { |
|
72 | + if (false !== @ini_set('memory_limit', $wp_max_limit)) { |
|
73 | 73 | return $wp_max_limit; |
74 | 74 | } else { |
75 | 75 | return false; |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @param int The time limit in seconds. |
87 | 87 | */ |
88 | - public static function raise_time_limit( $limit = 0 ) { |
|
89 | - if ( $limit < ini_get( 'max_execution_time' ) ) { |
|
88 | + public static function raise_time_limit($limit = 0) { |
|
89 | + if ($limit < ini_get('max_execution_time')) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
93 | - if ( function_exists( 'wc_set_time_limit' ) ) { |
|
94 | - wc_set_time_limit( $limit ); |
|
95 | - } elseif ( function_exists( 'set_time_limit' ) && false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
96 | - @set_time_limit( $limit ); |
|
93 | + if (function_exists('wc_set_time_limit')) { |
|
94 | + wc_set_time_limit($limit); |
|
95 | + } elseif (function_exists('set_time_limit') && false === strpos(ini_get('disable_functions'), 'set_time_limit') && !ini_get('safe_mode')) { |
|
96 | + @set_time_limit($limit); |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 | } |
@@ -14,157 +14,157 @@ |
||
14 | 14 | |
15 | 15 | if ( ! class_exists( 'WP_Async_Request' ) ) { |
16 | 16 | |
17 | - /** |
|
18 | - * Abstract WP_Async_Request class. |
|
19 | - * |
|
20 | - * @abstract |
|
21 | - */ |
|
22 | - abstract class WP_Async_Request { |
|
23 | - |
|
24 | - /** |
|
25 | - * Prefix |
|
26 | - * |
|
27 | - * (default value: 'wp') |
|
28 | - * |
|
29 | - * @var string |
|
30 | - * @access protected |
|
31 | - */ |
|
32 | - protected $prefix = 'wp'; |
|
33 | - |
|
34 | - /** |
|
35 | - * Action |
|
36 | - * |
|
37 | - * (default value: 'async_request') |
|
38 | - * |
|
39 | - * @var string |
|
40 | - * @access protected |
|
41 | - */ |
|
42 | - protected $action = 'async_request'; |
|
43 | - |
|
44 | - /** |
|
45 | - * Identifier |
|
46 | - * |
|
47 | - * @var mixed |
|
48 | - * @access protected |
|
49 | - */ |
|
50 | - protected $identifier; |
|
51 | - |
|
52 | - /** |
|
53 | - * Data |
|
54 | - * |
|
55 | - * (default value: array()) |
|
56 | - * |
|
57 | - * @var array |
|
58 | - * @access protected |
|
59 | - */ |
|
60 | - protected $data = array(); |
|
61 | - |
|
62 | - /** |
|
63 | - * Initiate new async request |
|
64 | - */ |
|
65 | - public function __construct() { |
|
66 | - $this->identifier = $this->prefix . '_' . $this->action; |
|
67 | - |
|
68 | - add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); |
|
69 | - add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Set data used during the request |
|
74 | - * |
|
75 | - * @param array $data Data. |
|
76 | - * |
|
77 | - * @return $this |
|
78 | - */ |
|
79 | - public function data( $data ) { |
|
80 | - $this->data = $data; |
|
81 | - |
|
82 | - return $this; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Dispatch the async request |
|
87 | - * |
|
88 | - * @return array|WP_Error |
|
89 | - */ |
|
90 | - public function dispatch() { |
|
91 | - $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); |
|
92 | - $args = $this->get_post_args(); |
|
93 | - |
|
94 | - return wp_remote_post( esc_url_raw( $url ), $args ); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Get query args |
|
99 | - * |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - protected function get_query_args() { |
|
103 | - if ( property_exists( $this, 'query_args' ) ) { |
|
104 | - return $this->query_args; |
|
105 | - } |
|
106 | - |
|
107 | - return array( |
|
108 | - 'action' => $this->identifier, |
|
109 | - 'nonce' => wp_create_nonce( $this->identifier ), |
|
110 | - ); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Get query URL |
|
115 | - * |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - protected function get_query_url() { |
|
119 | - if ( property_exists( $this, 'query_url' ) ) { |
|
120 | - return $this->query_url; |
|
121 | - } |
|
122 | - |
|
123 | - return admin_url( 'admin-ajax.php' ); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Get post args |
|
128 | - * |
|
129 | - * @return array |
|
130 | - */ |
|
131 | - protected function get_post_args() { |
|
132 | - if ( property_exists( $this, 'post_args' ) ) { |
|
133 | - return $this->post_args; |
|
134 | - } |
|
135 | - |
|
136 | - return array( |
|
137 | - 'timeout' => 0.01, |
|
138 | - 'blocking' => false, |
|
139 | - 'body' => $this->data, |
|
140 | - 'cookies' => $_COOKIE, |
|
141 | - 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), |
|
142 | - ); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Maybe handle |
|
147 | - * |
|
148 | - * Check for correct nonce and pass to handler. |
|
149 | - */ |
|
150 | - public function maybe_handle() { |
|
151 | - // Don't lock up other requests while processing |
|
152 | - session_write_close(); |
|
153 | - |
|
154 | - check_ajax_referer( $this->identifier, 'nonce' ); |
|
155 | - |
|
156 | - $this->handle(); |
|
157 | - |
|
158 | - wp_die(); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Handle |
|
163 | - * |
|
164 | - * Override this method to perform any actions required |
|
165 | - * during the async request. |
|
166 | - */ |
|
167 | - abstract protected function handle(); |
|
168 | - |
|
169 | - } |
|
17 | + /** |
|
18 | + * Abstract WP_Async_Request class. |
|
19 | + * |
|
20 | + * @abstract |
|
21 | + */ |
|
22 | + abstract class WP_Async_Request { |
|
23 | + |
|
24 | + /** |
|
25 | + * Prefix |
|
26 | + * |
|
27 | + * (default value: 'wp') |
|
28 | + * |
|
29 | + * @var string |
|
30 | + * @access protected |
|
31 | + */ |
|
32 | + protected $prefix = 'wp'; |
|
33 | + |
|
34 | + /** |
|
35 | + * Action |
|
36 | + * |
|
37 | + * (default value: 'async_request') |
|
38 | + * |
|
39 | + * @var string |
|
40 | + * @access protected |
|
41 | + */ |
|
42 | + protected $action = 'async_request'; |
|
43 | + |
|
44 | + /** |
|
45 | + * Identifier |
|
46 | + * |
|
47 | + * @var mixed |
|
48 | + * @access protected |
|
49 | + */ |
|
50 | + protected $identifier; |
|
51 | + |
|
52 | + /** |
|
53 | + * Data |
|
54 | + * |
|
55 | + * (default value: array()) |
|
56 | + * |
|
57 | + * @var array |
|
58 | + * @access protected |
|
59 | + */ |
|
60 | + protected $data = array(); |
|
61 | + |
|
62 | + /** |
|
63 | + * Initiate new async request |
|
64 | + */ |
|
65 | + public function __construct() { |
|
66 | + $this->identifier = $this->prefix . '_' . $this->action; |
|
67 | + |
|
68 | + add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); |
|
69 | + add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Set data used during the request |
|
74 | + * |
|
75 | + * @param array $data Data. |
|
76 | + * |
|
77 | + * @return $this |
|
78 | + */ |
|
79 | + public function data( $data ) { |
|
80 | + $this->data = $data; |
|
81 | + |
|
82 | + return $this; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Dispatch the async request |
|
87 | + * |
|
88 | + * @return array|WP_Error |
|
89 | + */ |
|
90 | + public function dispatch() { |
|
91 | + $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); |
|
92 | + $args = $this->get_post_args(); |
|
93 | + |
|
94 | + return wp_remote_post( esc_url_raw( $url ), $args ); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Get query args |
|
99 | + * |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + protected function get_query_args() { |
|
103 | + if ( property_exists( $this, 'query_args' ) ) { |
|
104 | + return $this->query_args; |
|
105 | + } |
|
106 | + |
|
107 | + return array( |
|
108 | + 'action' => $this->identifier, |
|
109 | + 'nonce' => wp_create_nonce( $this->identifier ), |
|
110 | + ); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Get query URL |
|
115 | + * |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + protected function get_query_url() { |
|
119 | + if ( property_exists( $this, 'query_url' ) ) { |
|
120 | + return $this->query_url; |
|
121 | + } |
|
122 | + |
|
123 | + return admin_url( 'admin-ajax.php' ); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Get post args |
|
128 | + * |
|
129 | + * @return array |
|
130 | + */ |
|
131 | + protected function get_post_args() { |
|
132 | + if ( property_exists( $this, 'post_args' ) ) { |
|
133 | + return $this->post_args; |
|
134 | + } |
|
135 | + |
|
136 | + return array( |
|
137 | + 'timeout' => 0.01, |
|
138 | + 'blocking' => false, |
|
139 | + 'body' => $this->data, |
|
140 | + 'cookies' => $_COOKIE, |
|
141 | + 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), |
|
142 | + ); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Maybe handle |
|
147 | + * |
|
148 | + * Check for correct nonce and pass to handler. |
|
149 | + */ |
|
150 | + public function maybe_handle() { |
|
151 | + // Don't lock up other requests while processing |
|
152 | + session_write_close(); |
|
153 | + |
|
154 | + check_ajax_referer( $this->identifier, 'nonce' ); |
|
155 | + |
|
156 | + $this->handle(); |
|
157 | + |
|
158 | + wp_die(); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Handle |
|
163 | + * |
|
164 | + * Override this method to perform any actions required |
|
165 | + * during the async request. |
|
166 | + */ |
|
167 | + abstract protected function handle(); |
|
168 | + |
|
169 | + } |
|
170 | 170 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | License URI: https://github.com/deliciousbrains/wp-background-processing/commit/126d7945dd3d39f39cb6488ca08fe1fb66cb351a |
13 | 13 | */ |
14 | 14 | |
15 | -if ( ! class_exists( 'WP_Async_Request' ) ) { |
|
15 | +if (!class_exists('WP_Async_Request')) { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Abstract WP_Async_Request class. |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | public function __construct() { |
66 | 66 | $this->identifier = $this->prefix . '_' . $this->action; |
67 | 67 | |
68 | - add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); |
|
69 | - add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); |
|
68 | + add_action('wp_ajax_' . $this->identifier, array($this, 'maybe_handle')); |
|
69 | + add_action('wp_ajax_nopriv_' . $this->identifier, array($this, 'maybe_handle')); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return $this |
78 | 78 | */ |
79 | - public function data( $data ) { |
|
79 | + public function data($data) { |
|
80 | 80 | $this->data = $data; |
81 | 81 | |
82 | 82 | return $this; |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | * @return array|WP_Error |
89 | 89 | */ |
90 | 90 | public function dispatch() { |
91 | - $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); |
|
91 | + $url = add_query_arg($this->get_query_args(), $this->get_query_url()); |
|
92 | 92 | $args = $this->get_post_args(); |
93 | 93 | |
94 | - return wp_remote_post( esc_url_raw( $url ), $args ); |
|
94 | + return wp_remote_post(esc_url_raw($url), $args); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -100,13 +100,13 @@ discard block |
||
100 | 100 | * @return array |
101 | 101 | */ |
102 | 102 | protected function get_query_args() { |
103 | - if ( property_exists( $this, 'query_args' ) ) { |
|
103 | + if (property_exists($this, 'query_args')) { |
|
104 | 104 | return $this->query_args; |
105 | 105 | } |
106 | 106 | |
107 | 107 | return array( |
108 | 108 | 'action' => $this->identifier, |
109 | - 'nonce' => wp_create_nonce( $this->identifier ), |
|
109 | + 'nonce' => wp_create_nonce($this->identifier), |
|
110 | 110 | ); |
111 | 111 | } |
112 | 112 | |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | * @return string |
117 | 117 | */ |
118 | 118 | protected function get_query_url() { |
119 | - if ( property_exists( $this, 'query_url' ) ) { |
|
119 | + if (property_exists($this, 'query_url')) { |
|
120 | 120 | return $this->query_url; |
121 | 121 | } |
122 | 122 | |
123 | - return admin_url( 'admin-ajax.php' ); |
|
123 | + return admin_url('admin-ajax.php'); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @return array |
130 | 130 | */ |
131 | 131 | protected function get_post_args() { |
132 | - if ( property_exists( $this, 'post_args' ) ) { |
|
132 | + if (property_exists($this, 'post_args')) { |
|
133 | 133 | return $this->post_args; |
134 | 134 | } |
135 | 135 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | 'blocking' => false, |
139 | 139 | 'body' => $this->data, |
140 | 140 | 'cookies' => $_COOKIE, |
141 | - 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), |
|
141 | + 'sslverify' => apply_filters('https_local_ssl_verify', false), |
|
142 | 142 | ); |
143 | 143 | } |
144 | 144 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | // Don't lock up other requests while processing |
152 | 152 | session_write_close(); |
153 | 153 | |
154 | - check_ajax_referer( $this->identifier, 'nonce' ); |
|
154 | + check_ajax_referer($this->identifier, 'nonce'); |
|
155 | 155 | |
156 | 156 | $this->handle(); |
157 | 157 |
@@ -89,7 +89,7 @@ |
||
89 | 89 | return false; |
90 | 90 | } |
91 | 91 | |
92 | - for ($i = $offset; $i <= $to; $i+= $stepSize) { |
|
92 | + for ($i = $offset; $i <= $to; $i += $stepSize) { |
|
93 | 93 | if ($i == $dateValue) { |
94 | 94 | return true; |
95 | 95 | } |
@@ -240,7 +240,7 @@ |
||
240 | 240 | $currentTime = new DateTime($currentTime); |
241 | 241 | $currentTime->setTime($currentTime->format('H'), $currentTime->format('i'), 0); |
242 | 242 | $currentDate = $currentTime->format('Y-m-d H:i'); |
243 | - $currentTime = (int)($currentTime->getTimestamp()); |
|
243 | + $currentTime = (int) ($currentTime->getTimestamp()); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return $this->getNextRunDate($currentDate, 0, true)->getTimestamp() == $currentTime; |
@@ -1,30 +1,30 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | class WPInv_Meta_Box_Details { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | $currency_symbol = wpinv_currency_symbol(); |
10 | - $statuses = wpinv_get_invoice_statuses( true ); |
|
10 | + $statuses = wpinv_get_invoice_statuses(true); |
|
11 | 11 | |
12 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
13 | - $invoice = new WPInv_Invoice( $post_id ); |
|
12 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
13 | + $invoice = new WPInv_Invoice($post_id); |
|
14 | 14 | |
15 | - $status = $invoice->get_status( false ); // Current status |
|
15 | + $status = $invoice->get_status(false); // Current status |
|
16 | 16 | $discount = $invoice->get_discount(); |
17 | 17 | $discount_code = $discount > 0 ? $invoice->get_discount_code() : ''; |
18 | 18 | $invoice_number = $invoice->get_number(); |
19 | 19 | |
20 | 20 | $date_created = $invoice->get_created_date(); |
21 | - $datetime_created = strtotime( $date_created ); |
|
22 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : ''; |
|
21 | + $datetime_created = strtotime($date_created); |
|
22 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : ''; |
|
23 | 23 | $date_completed = $invoice->get_completed_date(); |
24 | - $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a'; |
|
25 | - $title['status'] = __( 'Invoice Status:', 'invoicing' ); |
|
26 | - $title['number'] = __( 'Invoice Number:', 'invoicing' ); |
|
27 | - $mail_notice = esc_attr__( 'After saving invoice, this will send a copy of the invoice to the user’s email address.', 'invoicing' ); |
|
24 | + $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($date_completed)) : 'n/a'; |
|
25 | + $title['status'] = __('Invoice Status:', 'invoicing'); |
|
26 | + $title['number'] = __('Invoice Number:', 'invoicing'); |
|
27 | + $mail_notice = esc_attr__('After saving invoice, this will send a copy of the invoice to the user’s email address.', 'invoicing'); |
|
28 | 28 | |
29 | 29 | $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice); |
30 | 30 | $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice); |
@@ -34,36 +34,36 @@ discard block |
||
34 | 34 | <div class="gdmbx2-wrap form-table"> |
35 | 35 | <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details"> |
36 | 36 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created"> |
37 | - <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div> |
|
38 | - <div class="gdmbx-td"><?php echo $date_created;?></div> |
|
37 | + <div class="gdmbx-th"><label><?php _e('Date Created:', 'invoicing'); ?></label></div> |
|
38 | + <div class="gdmbx-td"><?php echo $date_created; ?></div> |
|
39 | 39 | </div> |
40 | - <?php if ( $invoice->post_type == 'wpi_invoice' && wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft', 'draft' ) ) ) ) { ?> |
|
40 | + <?php if ($invoice->post_type == 'wpi_invoice' && wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft', 'draft')))) { ?> |
|
41 | 41 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue"> |
42 | - <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div> |
|
42 | + <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div> |
|
43 | 43 | <div class="gdmbx-td"> |
44 | - <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd"> |
|
45 | - <p class="wpi-meta-row wpi-meta-desc"><?php _e( 'Leave blank to disable sending auto reminder for this invoice.', 'invoicing' );?></p> |
|
44 | + <input type="text" placeholder="<?php esc_attr_e('Y-m-d', 'invoicing'); ?>" value="<?php echo esc_attr($invoice->get_due_date()); ?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr(date_i18n('Y-m-d', $datetime_created)); ?>" data-dateFormat="yy-mm-dd"> |
|
45 | + <p class="wpi-meta-row wpi-meta-desc"><?php _e('Leave blank to disable sending auto reminder for this invoice.', 'invoicing'); ?></p> |
|
46 | 46 | </div> |
47 | 47 | </div> |
48 | 48 | <?php } ?> |
49 | - <?php do_action( 'wpinv_meta_box_details_after_due_date', $post_id ); ?> |
|
50 | - <?php if ( $date_completed && $date_completed != 'n/a' ) { ?> |
|
49 | + <?php do_action('wpinv_meta_box_details_after_due_date', $post_id); ?> |
|
50 | + <?php if ($date_completed && $date_completed != 'n/a') { ?> |
|
51 | 51 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed"> |
52 | - <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div> |
|
53 | - <div class="gdmbx-td"><?php echo $date_completed;?></div> |
|
52 | + <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div> |
|
53 | + <div class="gdmbx-td"><?php echo $date_completed; ?></div> |
|
54 | 54 | </div> |
55 | 55 | <?php } ?> |
56 | - <?php $is_viewed = wpinv_is_invoice_viewed( $post_id ); ?> |
|
56 | + <?php $is_viewed = wpinv_is_invoice_viewed($post_id); ?> |
|
57 | 57 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-customer-viewed"> |
58 | - <div class="gdmbx-th"><label><?php _e( 'Viewed by Customer:', 'invoicing' );?></label></div> |
|
59 | - <div class="gdmbx-td"><?php ( 1 == $is_viewed ) ? _e( 'Yes', 'invoicing' ) : _e( 'No', 'invoicing' ); ?></div> |
|
58 | + <div class="gdmbx-th"><label><?php _e('Viewed by Customer:', 'invoicing'); ?></label></div> |
|
59 | + <div class="gdmbx-td"><?php (1 == $is_viewed) ? _e('Yes', 'invoicing') : _e('No', 'invoicing'); ?></div> |
|
60 | 60 | </div> |
61 | 61 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status"> |
62 | 62 | <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div> |
63 | 63 | <div class="gdmbx-td"> |
64 | 64 | <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select wpi_select2"> |
65 | - <?php foreach ( $statuses as $value => $label ) { ?> |
|
66 | - <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option> |
|
65 | + <?php foreach ($statuses as $value => $label) { ?> |
|
66 | + <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option> |
|
67 | 67 | <?php } ?> |
68 | 68 | </select> |
69 | 69 | </div> |
@@ -71,117 +71,117 @@ discard block |
||
71 | 71 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout"> |
72 | 72 | <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div> |
73 | 73 | <div class="gdmbx-td"> |
74 | - <input type="text" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly> |
|
74 | + <input type="text" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly> |
|
75 | 75 | </div> |
76 | 76 | </div> |
77 | - <?php do_action( 'wpinv_meta_box_details_inner', $post_id ); |
|
77 | + <?php do_action('wpinv_meta_box_details_inner', $post_id); |
|
78 | 78 | $disable_discount = apply_filters('wpinv_disable_apply_discount', false, $invoice, $post_id); |
79 | 79 | ?> |
80 | - <?php if ( !( $is_paid = ( $invoice->is_paid() || $invoice->is_refunded() ) ) && !$disable_discount || $discount_code ) { ?> |
|
80 | + <?php if (!($is_paid = ($invoice->is_paid() || $invoice->is_refunded())) && !$disable_discount || $discount_code) { ?> |
|
81 | 81 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout"> |
82 | - <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div> |
|
82 | + <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div> |
|
83 | 83 | <div class="gdmbx-td"> |
84 | - <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid && !$disable_discount ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
|
84 | + <input type="text" value="<?php echo esc_attr($discount_code); ?>" id="wpinv_discount" class="medium-text" <?php echo ($discount_code ? 'readonly' : ''); ?> /><?php if (!$is_paid && !$disable_discount) { ?><input value="<?php echo esc_attr_e('Apply', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-hide' : 'wpi-inlineb'); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e('Remove', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-inlineb' : 'wpi-hide'); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
|
85 | 85 | </div> |
86 | 86 | </div> |
87 | 87 | <?php } ?> |
88 | 88 | </div> |
89 | 89 | </div> |
90 | 90 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout"> |
91 | - <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__( 'Send %s:', 'invoicing' ),$post_obj->labels->singular_name) ; ?></label> |
|
91 | + <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__('Send %s:', 'invoicing'), $post_obj->labels->singular_name); ?></label> |
|
92 | 92 | <select id="wpi_save_send" name="wpi_save_send" class="wpi_select2"> |
93 | - <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option> |
|
94 | - <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option> |
|
93 | + <option value="1"><?php _e('Yes', 'invoicing'); ?></option> |
|
94 | + <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option> |
|
95 | 95 | </select> |
96 | 96 | </p> |
97 | 97 | <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p> |
98 | 98 | </div> |
99 | -<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?> |
|
99 | +<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?> |
|
100 | 100 | <?php |
101 | 101 | } |
102 | 102 | |
103 | - public static function resend_invoice( $post ) { |
|
103 | + public static function resend_invoice($post) { |
|
104 | 104 | global $wpi_mb_invoice; |
105 | 105 | |
106 | - if ( empty( $wpi_mb_invoice ) ) { |
|
106 | + if (empty($wpi_mb_invoice)) { |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | |
110 | 110 | $text = array( |
111 | - 'message' => esc_attr__( 'This will send a copy of the invoice to the customer’s email address.', 'invoicing' ), |
|
112 | - 'button_text' => __( 'Resend Invoice', 'invoicing' ), |
|
111 | + 'message' => esc_attr__('This will send a copy of the invoice to the customer’s email address.', 'invoicing'), |
|
112 | + 'button_text' => __('Resend Invoice', 'invoicing'), |
|
113 | 113 | ); |
114 | 114 | |
115 | 115 | $text = apply_filters('wpinv_resend_invoice_metabox_text', $text); |
116 | - do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice ); |
|
116 | + do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice); |
|
117 | 117 | |
118 | - if ( $email = $wpi_mb_invoice->get_email() ) { |
|
118 | + if ($email = $wpi_mb_invoice->get_email()) { |
|
119 | 119 | $email_actions = array(); |
120 | - $email_actions['email_url'] = remove_query_arg( 'wpinv-message', add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ); |
|
121 | - $email_actions['reminder_url'] = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) ); |
|
120 | + $email_actions['email_url'] = remove_query_arg('wpinv-message', add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))); |
|
121 | + $email_actions['reminder_url'] = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID)); |
|
122 | 122 | |
123 | - $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions ); |
|
123 | + $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions); |
|
124 | 124 | ?> |
125 | 125 | <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p> |
126 | - <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url( $email_actions['email_url'] ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
127 | - <?php if ( wpinv_get_option( 'overdue_active' ) && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?> |
|
128 | - <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_actions['reminder_url'] ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p> |
|
126 | + <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url($email_actions['email_url']); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
127 | + <?php if (wpinv_get_option('overdue_active') && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?> |
|
128 | + <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo esc_url($email_actions['reminder_url']); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p> |
|
129 | 129 | <?php } ?> |
130 | 130 | <?php |
131 | 131 | } |
132 | 132 | |
133 | - do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice ); |
|
133 | + do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice); |
|
134 | 134 | } |
135 | 135 | |
136 | - public static function subscriptions( $post ) { |
|
137 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
136 | + public static function subscriptions($post) { |
|
137 | + $invoice = wpinv_get_invoice($post->ID); |
|
138 | 138 | |
139 | - if ( ! empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) { |
|
140 | - $subscription = wpinv_get_subscription( $invoice ); |
|
139 | + if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) { |
|
140 | + $subscription = wpinv_get_subscription($invoice); |
|
141 | 141 | |
142 | - if ( empty( $subscription ) ) { |
|
142 | + if (empty($subscription)) { |
|
143 | 143 | ?> |
144 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( 'New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing' ), '<a href="' . admin_url( 'admin.php?page=wpinv-subscriptions' ).'">', '</a>' ); ?></p> |
|
144 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing'), '<a href="' . admin_url('admin.php?page=wpinv-subscriptions') . '">', '</a>'); ?></p> |
|
145 | 145 | <?php |
146 | 146 | return; |
147 | 147 | } |
148 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, $subscription->frequency ); |
|
149 | - $billing = wpinv_price(wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency; |
|
150 | - $initial = wpinv_price(wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ); |
|
148 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency); |
|
149 | + $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)) . ' / ' . $frequency; |
|
150 | + $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)); |
|
151 | 151 | $payments = $subscription->get_child_payments(); |
152 | 152 | ?> |
153 | 153 | <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . $subscription->status; ?>"><?php _e('Recurring Payment', 'invoicing'); ?></p> |
154 | - <?php if ( ! empty( $subscription ) && ! empty( $subscription->id ) ) { ?> |
|
154 | + <?php if (!empty($subscription) && !empty($subscription->id)) { ?> |
|
155 | 155 | <p class="wpi-meta-row wpi-sub-id"> |
156 | - <label><?php _e( 'Subscription ID:', 'invoicing' ); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p> |
|
156 | + <label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p> |
|
157 | 157 | <?php } ?> |
158 | 158 | <p class="wpi-meta-row wpi-bill-cycle"> |
159 | - <label><?php _e( 'Billing Cycle:', 'invoicing'); ?> </label><?php printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); ?> |
|
159 | + <label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); ?> |
|
160 | 160 | </p> |
161 | 161 | <p class="wpi-meta-row wpi-billed-times"> |
162 | - <label><?php _e( 'Times Billed:', 'invoicing' ); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? 'Until Cancelled' : $subscription->bill_times ); ?> |
|
162 | + <label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? 'Until Cancelled' : $subscription->bill_times); ?> |
|
163 | 163 | </p> |
164 | 164 | <p class="wpi-meta-row wpi-start-date"> |
165 | - <label><?php _e( 'Start Date:', 'invoicing' ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?> |
|
165 | + <label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->created, current_time('timestamp'))); ?> |
|
166 | 166 | </p> |
167 | 167 | <p class="wpi-meta-row wpi-end-date"> |
168 | - <label><?php echo ( 'trialling' == $subscription->status ? __( 'Trialling Until:', 'invoicing' ) : __( 'Expiration Date:', 'invoicing' ) ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration, current_time( 'timestamp' ) ) ); ?> |
|
168 | + <label><?php echo ('trialling' == $subscription->status ? __('Trialling Until:', 'invoicing') : __('Expiration Date:', 'invoicing')); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->expiration, current_time('timestamp'))); ?> |
|
169 | 169 | </p> |
170 | - <?php if ( $subscription->status ) { ?> |
|
170 | + <?php if ($subscription->status) { ?> |
|
171 | 171 | <p class="wpi-meta-row wpi-sub-status"> |
172 | - <label><?php _e( 'Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?> |
|
172 | + <label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?> |
|
173 | 173 | </p> |
174 | 174 | <?php } ?> |
175 | - <?php if ( !empty( $payments ) ) { ?> |
|
176 | - <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p> |
|
175 | + <?php if (!empty($payments)) { ?> |
|
176 | + <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p> |
|
177 | 177 | <ul id="wpi-sub-payments"> |
178 | - <?php foreach ( $payments as $payment ) { |
|
178 | + <?php foreach ($payments as $payment) { |
|
179 | 179 | $invoice_id = $payment->ID; |
180 | 180 | ?> |
181 | 181 | <li> |
182 | - <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a> – |
|
183 | - <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?> – </span> |
|
184 | - <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span> |
|
182 | + <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a> – |
|
183 | + <span><?php echo wpinv_get_invoice_date($invoice_id); ?> – </span> |
|
184 | + <span><?php echo wpinv_payment_total($invoice_id, true); ?></span> |
|
185 | 185 | </li> |
186 | 186 | <?php } ?> |
187 | 187 | </ul> |
@@ -189,16 +189,16 @@ discard block |
||
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
192 | - public static function renewals( $post ) { |
|
193 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
192 | + public static function renewals($post) { |
|
193 | + $invoice = wpinv_get_invoice($post->ID); |
|
194 | 194 | |
195 | - if ( wpinv_is_subscription_payment( $invoice ) ) { |
|
196 | - $parent_url = get_edit_post_link( $invoice->parent_invoice ); |
|
197 | - $parent_id = wpinv_get_invoice_number( $invoice->parent_invoice ); |
|
198 | - $subscription = wpinv_get_subscription( $invoice ); |
|
195 | + if (wpinv_is_subscription_payment($invoice)) { |
|
196 | + $parent_url = get_edit_post_link($invoice->parent_invoice); |
|
197 | + $parent_id = wpinv_get_invoice_number($invoice->parent_invoice); |
|
198 | + $subscription = wpinv_get_subscription($invoice); |
|
199 | 199 | ?> |
200 | - <?php if ( ! empty( $subscription ) ) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?> |
|
201 | - <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p> |
|
200 | + <?php if (!empty($subscription)) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?> |
|
201 | + <p class="wpi-meta-row wpi-parent-id"><label><?php _e('Parent Invoice:', 'invoicing'); ?> </label><a href="<?php echo esc_url($parent_url); ?>"><?php echo $parent_id; ?></a></p> |
|
202 | 202 | <?php |
203 | 203 | } |
204 | 204 | } |
@@ -206,47 +206,47 @@ discard block |
||
206 | 206 | /** |
207 | 207 | * Renders a metabox to edit a payment form. |
208 | 208 | */ |
209 | - public static function payment_form( $post ) { |
|
210 | - WPInv_Meta_Box_Form_Items::output_options( $post ); |
|
209 | + public static function payment_form($post) { |
|
210 | + WPInv_Meta_Box_Form_Items::output_options($post); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | 214 | * Renders a metabox to select items. |
215 | 215 | */ |
216 | - public static function payment_form_items( $post ) { |
|
217 | - WPInv_Meta_Box_Form_Items::output( $post ); |
|
216 | + public static function payment_form_items($post) { |
|
217 | + WPInv_Meta_Box_Form_Items::output($post); |
|
218 | 218 | } |
219 | 219 | |
220 | - public static function payment_meta( $post ) { |
|
220 | + public static function payment_meta($post) { |
|
221 | 221 | global $wpi_mb_invoice; |
222 | 222 | |
223 | - $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false; |
|
224 | - if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded() ) { |
|
223 | + $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false; |
|
224 | + if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded()) { |
|
225 | 225 | $set_dateway = true; |
226 | 226 | } |
227 | 227 | |
228 | 228 | ?> |
229 | 229 | <p class="wpi-meta-row"> |
230 | - <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?> |
|
231 | - <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label> |
|
230 | + <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?> |
|
231 | + <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label> |
|
232 | 232 | <select required="required" id="wpinv_gateway" class="wpi_select2" name="wpinv_gateway"> |
233 | - <?php foreach ( $gateways as $name => $gateway ) { |
|
234 | - if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) { |
|
233 | + <?php foreach ($gateways as $name => $gateway) { |
|
234 | + if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) { |
|
235 | 235 | continue; |
236 | 236 | } |
237 | 237 | ?> |
238 | - <option value="<?php echo $name;?>" <?php selected( $wpi_mb_invoice->gateway, $name );?>><?php echo !empty( $gateway['admin_label'] ) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option> |
|
238 | + <option value="<?php echo $name; ?>" <?php selected($wpi_mb_invoice->gateway, $name); ?>><?php echo !empty($gateway['admin_label']) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option> |
|
239 | 239 | <?php } ?> |
240 | 240 | </select> |
241 | 241 | <?php } else { |
242 | - echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_admin_label( $wpi_mb_invoice->gateway ) ); |
|
242 | + echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_admin_label($wpi_mb_invoice->gateway)); |
|
243 | 243 | } ?> |
244 | 244 | </p> |
245 | - <?php if ( $key = $wpi_mb_invoice->get_key() ) { ?> |
|
246 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $key ); ?></p> |
|
245 | + <?php if ($key = $wpi_mb_invoice->get_key()) { ?> |
|
246 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $key); ?></p> |
|
247 | 247 | <?php } ?> |
248 | - <?php if ( $wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded() ) { ?> |
|
249 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p> |
|
248 | + <?php if ($wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded()) { ?> |
|
249 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p> |
|
250 | 250 | <?php } ?> |
251 | 251 | <?php |
252 | 252 | } |
@@ -12,19 +12,19 @@ |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // MUST have WordPress. |
15 | -if ( !defined( 'WPINC' ) ) { |
|
16 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
15 | +if (!defined('WPINC')) { |
|
16 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
17 | 17 | } |
18 | 18 | |
19 | -if ( !defined( 'WPINV_VERSION' ) ) { |
|
20 | - define( 'WPINV_VERSION', '1.0.18' ); |
|
19 | +if (!defined('WPINV_VERSION')) { |
|
20 | + define('WPINV_VERSION', '1.0.18'); |
|
21 | 21 | } |
22 | 22 | |
23 | -if ( !defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
24 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
23 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
24 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
25 | 25 | } |
26 | 26 | |
27 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wpinv.php'; |
|
27 | +require plugin_dir_path(__FILE__) . 'includes/class-wpinv.php'; |
|
28 | 28 | |
29 | 29 | function wpinv_run() { |
30 | 30 | global $invoicing; |