@@ -23,11 +23,11 @@ |
||
| 23 | 23 | * @param string $class_name Storage class name. |
| 24 | 24 | * @return RWMB_Storage_Interface |
| 25 | 25 | */ |
| 26 | - public function get( $class_name ) { |
|
| 27 | - if ( empty( $this->storages[ $class_name ] ) ) { |
|
| 28 | - $this->storages[ $class_name ] = new $class_name(); |
|
| 26 | + public function get($class_name) { |
|
| 27 | + if (empty($this->storages[$class_name])) { |
|
| 28 | + $this->storages[$class_name] = new $class_name(); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - return $this->storages[ $class_name ]; |
|
| 31 | + return $this->storages[$class_name]; |
|
| 32 | 32 | } |
| 33 | 33 | } |
@@ -3,19 +3,19 @@ |
||
| 3 | 3 | * Storage registry class |
| 4 | 4 | */ |
| 5 | 5 | class RWMB_Storage_Registry { |
| 6 | - protected $storages = []; |
|
| 6 | + protected $storages = []; |
|
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * Get storage instance. |
|
| 10 | - * |
|
| 11 | - * @param string $class_name Storage class name. |
|
| 12 | - * @return RWMB_Storage_Interface |
|
| 13 | - */ |
|
| 14 | - public function get( $class_name ) { |
|
| 15 | - if ( empty( $this->storages[ $class_name ] ) ) { |
|
| 16 | - $this->storages[ $class_name ] = new $class_name(); |
|
| 17 | - } |
|
| 8 | + /** |
|
| 9 | + * Get storage instance. |
|
| 10 | + * |
|
| 11 | + * @param string $class_name Storage class name. |
|
| 12 | + * @return RWMB_Storage_Interface |
|
| 13 | + */ |
|
| 14 | + public function get( $class_name ) { |
|
| 15 | + if ( empty( $this->storages[ $class_name ] ) ) { |
|
| 16 | + $this->storages[ $class_name ] = new $class_name(); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - return $this->storages[ $class_name ]; |
|
| 20 | - } |
|
| 19 | + return $this->storages[ $class_name ]; |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -22,11 +22,11 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @return array |
| 24 | 24 | */ |
| 25 | - public static function normalize( $field ) { |
|
| 26 | - $field = parent::normalize( $field ); |
|
| 25 | + public static function normalize($field) { |
|
| 26 | + $field = parent::normalize($field); |
|
| 27 | 27 | $field['multiple'] = true; |
| 28 | 28 | $field['field_name'] = $field['id']; |
| 29 | - if ( ! $field['clone'] ) { |
|
| 29 | + if (!$field['clone']) { |
|
| 30 | 30 | $field['field_name'] .= '[]'; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | - public static function format_single_value( $field, $value, $args, $post_id ) { |
|
| 47 | - return $field['options'][ $value ]; |
|
| 46 | + public static function format_single_value($field, $value, $args, $post_id) { |
|
| 47 | + return $field['options'][$value]; |
|
| 48 | 48 | } |
| 49 | 49 | } |
@@ -9,35 +9,35 @@ |
||
| 9 | 9 | * - Otherwise value is saved as multiple entries |
| 10 | 10 | */ |
| 11 | 11 | abstract class RWMB_Multiple_Values_Field extends RWMB_Field { |
| 12 | - /** |
|
| 13 | - * Normalize parameters for field. |
|
| 14 | - * |
|
| 15 | - * @param array $field Field parameters. |
|
| 16 | - * |
|
| 17 | - * @return array |
|
| 18 | - */ |
|
| 19 | - public static function normalize( $field ) { |
|
| 20 | - $field = parent::normalize( $field ); |
|
| 21 | - $field['multiple'] = true; |
|
| 22 | - $field['field_name'] = $field['id']; |
|
| 23 | - if ( ! $field['clone'] ) { |
|
| 24 | - $field['field_name'] .= '[]'; |
|
| 25 | - } |
|
| 12 | + /** |
|
| 13 | + * Normalize parameters for field. |
|
| 14 | + * |
|
| 15 | + * @param array $field Field parameters. |
|
| 16 | + * |
|
| 17 | + * @return array |
|
| 18 | + */ |
|
| 19 | + public static function normalize( $field ) { |
|
| 20 | + $field = parent::normalize( $field ); |
|
| 21 | + $field['multiple'] = true; |
|
| 22 | + $field['field_name'] = $field['id']; |
|
| 23 | + if ( ! $field['clone'] ) { |
|
| 24 | + $field['field_name'] .= '[]'; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - return $field; |
|
| 28 | - } |
|
| 27 | + return $field; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary. |
|
| 32 | - * |
|
| 33 | - * @param array $field Field parameters. |
|
| 34 | - * @param string $value The value. |
|
| 35 | - * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
| 36 | - * @param int|null $post_id Post ID. null for current post. Optional. |
|
| 37 | - * |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - public static function format_single_value( $field, $value, $args, $post_id ) { |
|
| 41 | - return $field['options'][ $value ]; |
|
| 42 | - } |
|
| 30 | + /** |
|
| 31 | + * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary. |
|
| 32 | + * |
|
| 33 | + * @param array $field Field parameters. |
|
| 34 | + * @param string $value The value. |
|
| 35 | + * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
| 36 | + * @param int|null $post_id Post ID. null for current post. Optional. |
|
| 37 | + * |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + public static function format_single_value( $field, $value, $args, $post_id ) { |
|
| 41 | + return $field['options'][ $value ]; |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -15,9 +15,9 @@ |
||
| 15 | 15 | * @param array $field Field parameters. |
| 16 | 16 | * @return array |
| 17 | 17 | */ |
| 18 | - public static function normalize( $field ) { |
|
| 18 | + public static function normalize($field) { |
|
| 19 | 19 | $field['multiple'] = true; |
| 20 | - $field = parent::normalize( $field ); |
|
| 20 | + $field = parent::normalize($field); |
|
| 21 | 21 | |
| 22 | 22 | return $field; |
| 23 | 23 | } |
@@ -3,16 +3,16 @@ |
||
| 3 | 3 | * The checkbox list field which shows a list of choices and allow users to select multiple options. |
| 4 | 4 | */ |
| 5 | 5 | class RWMB_Checkbox_List_Field extends RWMB_Input_List_Field { |
| 6 | - /** |
|
| 7 | - * Normalize parameters for field. |
|
| 8 | - * |
|
| 9 | - * @param array $field Field parameters. |
|
| 10 | - * @return array |
|
| 11 | - */ |
|
| 12 | - public static function normalize( $field ) { |
|
| 13 | - $field['multiple'] = true; |
|
| 14 | - $field = parent::normalize( $field ); |
|
| 6 | + /** |
|
| 7 | + * Normalize parameters for field. |
|
| 8 | + * |
|
| 9 | + * @param array $field Field parameters. |
|
| 10 | + * @return array |
|
| 11 | + */ |
|
| 12 | + public static function normalize( $field ) { |
|
| 13 | + $field['multiple'] = true; |
|
| 14 | + $field = parent::normalize( $field ); |
|
| 15 | 15 | |
| 16 | - return $field; |
|
| 17 | - } |
|
| 16 | + return $field; |
|
| 17 | + } |
|
| 18 | 18 | } |
@@ -18,8 +18,8 @@ |
||
| 18 | 18 | * @param array $field The field parameters. |
| 19 | 19 | * @return string |
| 20 | 20 | */ |
| 21 | - public static function value( $new, $old, $post_id, $field ) { |
|
| 22 | - $new = $new !== $old ? wp_hash_password( $new ) : $new; |
|
| 21 | + public static function value($new, $old, $post_id, $field) { |
|
| 22 | + $new = $new !== $old ? wp_hash_password($new) : $new; |
|
| 23 | 23 | return $new; |
| 24 | 24 | } |
| 25 | 25 | } |
@@ -3,17 +3,17 @@ |
||
| 3 | 3 | * The secured password field. |
| 4 | 4 | */ |
| 5 | 5 | class RWMB_Password_Field extends RWMB_Input_Field { |
| 6 | - /** |
|
| 7 | - * Store secured password in the database. |
|
| 8 | - * |
|
| 9 | - * @param mixed $new The submitted meta value. |
|
| 10 | - * @param mixed $old The existing meta value. |
|
| 11 | - * @param int $post_id The post ID. |
|
| 12 | - * @param array $field The field parameters. |
|
| 13 | - * @return string |
|
| 14 | - */ |
|
| 15 | - public static function value( $new, $old, $post_id, $field ) { |
|
| 16 | - $new = $new !== $old ? wp_hash_password( $new ) : $new; |
|
| 17 | - return $new; |
|
| 18 | - } |
|
| 6 | + /** |
|
| 7 | + * Store secured password in the database. |
|
| 8 | + * |
|
| 9 | + * @param mixed $new The submitted meta value. |
|
| 10 | + * @param mixed $old The existing meta value. |
|
| 11 | + * @param int $post_id The post ID. |
|
| 12 | + * @param array $field The field parameters. |
|
| 13 | + * @return string |
|
| 14 | + */ |
|
| 15 | + public static function value( $new, $old, $post_id, $field ) { |
|
| 16 | + $new = $new !== $old ? wp_hash_password( $new ) : $new; |
|
| 17 | + return $new; |
|
| 18 | + } |
|
| 19 | 19 | } |
@@ -10,10 +10,10 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class RWMB_Post_Storage extends RWMB_Base_Storage { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Object type. |
|
| 15 | - * |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - protected $object_type = 'post'; |
|
| 13 | + /** |
|
| 14 | + * Object type. |
|
| 15 | + * |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + protected $object_type = 'post'; |
|
| 19 | 19 | } |
@@ -31,14 +31,14 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @see get_metadata() |
| 33 | 33 | */ |
| 34 | - public function get( $object_id, $meta_key, $args = false ) { |
|
| 35 | - if ( is_array( $args ) ) { |
|
| 36 | - $single = ! empty( $args['single'] ); |
|
| 34 | + public function get($object_id, $meta_key, $args = false) { |
|
| 35 | + if (is_array($args)) { |
|
| 36 | + $single = !empty($args['single']); |
|
| 37 | 37 | } else { |
| 38 | 38 | $single = (bool) $args; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - return get_metadata( $this->object_type, $object_id, $meta_key, $single ); |
|
| 41 | + return get_metadata($this->object_type, $object_id, $meta_key, $single); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @see add_metadata() |
| 57 | 57 | */ |
| 58 | - public function add( $object_id, $meta_key, $meta_value, $unique = false ) { |
|
| 59 | - return add_metadata( $this->object_type, $object_id, $meta_key, $meta_value, $unique ); |
|
| 58 | + public function add($object_id, $meta_key, $meta_value, $unique = false) { |
|
| 59 | + return add_metadata($this->object_type, $object_id, $meta_key, $meta_value, $unique); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @see update_metadata() |
| 73 | 73 | */ |
| 74 | - public function update( $object_id, $meta_key, $meta_value, $prev_value = '' ) { |
|
| 75 | - return update_metadata( $this->object_type, $object_id, $meta_key, $meta_value, $prev_value ); |
|
| 74 | + public function update($object_id, $meta_key, $meta_value, $prev_value = '') { |
|
| 75 | + return update_metadata($this->object_type, $object_id, $meta_key, $meta_value, $prev_value); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @see delete_metadata() |
| 94 | 94 | */ |
| 95 | - public function delete( $object_id, $meta_key, $meta_value = '', $delete_all = false ) { |
|
| 96 | - return delete_metadata( $this->object_type, $object_id, $meta_key, $meta_value, $delete_all ); |
|
| 95 | + public function delete($object_id, $meta_key, $meta_value = '', $delete_all = false) { |
|
| 96 | + return delete_metadata($this->object_type, $object_id, $meta_key, $meta_value, $delete_all); |
|
| 97 | 97 | } |
| 98 | 98 | } |
@@ -3,89 +3,89 @@ |
||
| 3 | 3 | * Base storage. |
| 4 | 4 | */ |
| 5 | 5 | class RWMB_Base_Storage implements RWMB_Storage_Interface { |
| 6 | - /** |
|
| 7 | - * Object type. |
|
| 8 | - * |
|
| 9 | - * @var string |
|
| 10 | - */ |
|
| 11 | - protected $object_type; |
|
| 6 | + /** |
|
| 7 | + * Object type. |
|
| 8 | + * |
|
| 9 | + * @var string |
|
| 10 | + */ |
|
| 11 | + protected $object_type; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Retrieve metadata for the specified object. |
|
| 15 | - * |
|
| 16 | - * @param int $object_id ID of the object metadata is for. |
|
| 17 | - * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for |
|
| 18 | - * the specified object. |
|
| 19 | - * @param bool|array $args Optional, default is false. |
|
| 20 | - * If true, return only the first value of the specified meta_key. |
|
| 21 | - * If is array, use the `single` element. |
|
| 22 | - * This parameter has no effect if meta_key is not specified. |
|
| 23 | - * @return mixed Single metadata value, or array of values. |
|
| 24 | - * |
|
| 25 | - * @see get_metadata() |
|
| 26 | - */ |
|
| 27 | - public function get( $object_id, $meta_key, $args = false ) { |
|
| 28 | - if ( is_array( $args ) ) { |
|
| 29 | - $single = ! empty( $args['single'] ); |
|
| 30 | - } else { |
|
| 31 | - $single = (bool) $args; |
|
| 32 | - } |
|
| 13 | + /** |
|
| 14 | + * Retrieve metadata for the specified object. |
|
| 15 | + * |
|
| 16 | + * @param int $object_id ID of the object metadata is for. |
|
| 17 | + * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for |
|
| 18 | + * the specified object. |
|
| 19 | + * @param bool|array $args Optional, default is false. |
|
| 20 | + * If true, return only the first value of the specified meta_key. |
|
| 21 | + * If is array, use the `single` element. |
|
| 22 | + * This parameter has no effect if meta_key is not specified. |
|
| 23 | + * @return mixed Single metadata value, or array of values. |
|
| 24 | + * |
|
| 25 | + * @see get_metadata() |
|
| 26 | + */ |
|
| 27 | + public function get( $object_id, $meta_key, $args = false ) { |
|
| 28 | + if ( is_array( $args ) ) { |
|
| 29 | + $single = ! empty( $args['single'] ); |
|
| 30 | + } else { |
|
| 31 | + $single = (bool) $args; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - return get_metadata( $this->object_type, $object_id, $meta_key, $single ); |
|
| 35 | - } |
|
| 34 | + return get_metadata( $this->object_type, $object_id, $meta_key, $single ); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Add metadata |
|
| 39 | - * |
|
| 40 | - * @param int $object_id ID of the object metadata is for. |
|
| 41 | - * @param string $meta_key Metadata key. |
|
| 42 | - * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
|
| 43 | - * @param bool $unique Optional, default is false. |
|
| 44 | - * Whether the specified metadata key should be unique for the object. |
|
| 45 | - * If true, and the object already has a value for the specified metadata key, |
|
| 46 | - * no change will be made. |
|
| 47 | - * @return int|false The meta ID on success, false on failure. |
|
| 48 | - * |
|
| 49 | - * @see add_metadata() |
|
| 50 | - */ |
|
| 51 | - public function add( $object_id, $meta_key, $meta_value, $unique = false ) { |
|
| 52 | - return add_metadata( $this->object_type, $object_id, $meta_key, $meta_value, $unique ); |
|
| 53 | - } |
|
| 37 | + /** |
|
| 38 | + * Add metadata |
|
| 39 | + * |
|
| 40 | + * @param int $object_id ID of the object metadata is for. |
|
| 41 | + * @param string $meta_key Metadata key. |
|
| 42 | + * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
|
| 43 | + * @param bool $unique Optional, default is false. |
|
| 44 | + * Whether the specified metadata key should be unique for the object. |
|
| 45 | + * If true, and the object already has a value for the specified metadata key, |
|
| 46 | + * no change will be made. |
|
| 47 | + * @return int|false The meta ID on success, false on failure. |
|
| 48 | + * |
|
| 49 | + * @see add_metadata() |
|
| 50 | + */ |
|
| 51 | + public function add( $object_id, $meta_key, $meta_value, $unique = false ) { |
|
| 52 | + return add_metadata( $this->object_type, $object_id, $meta_key, $meta_value, $unique ); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Update metadata. |
|
| 57 | - * |
|
| 58 | - * @param int $object_id ID of the object metadata is for. |
|
| 59 | - * @param string $meta_key Metadata key. |
|
| 60 | - * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
|
| 61 | - * @param mixed $prev_value Optional. If specified, only update existing metadata entries with |
|
| 62 | - * the specified value. Otherwise, update all entries. |
|
| 63 | - * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
|
| 64 | - * |
|
| 65 | - * @see update_metadata() |
|
| 66 | - */ |
|
| 67 | - public function update( $object_id, $meta_key, $meta_value, $prev_value = '' ) { |
|
| 68 | - return update_metadata( $this->object_type, $object_id, $meta_key, $meta_value, $prev_value ); |
|
| 69 | - } |
|
| 55 | + /** |
|
| 56 | + * Update metadata. |
|
| 57 | + * |
|
| 58 | + * @param int $object_id ID of the object metadata is for. |
|
| 59 | + * @param string $meta_key Metadata key. |
|
| 60 | + * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
|
| 61 | + * @param mixed $prev_value Optional. If specified, only update existing metadata entries with |
|
| 62 | + * the specified value. Otherwise, update all entries. |
|
| 63 | + * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
|
| 64 | + * |
|
| 65 | + * @see update_metadata() |
|
| 66 | + */ |
|
| 67 | + public function update( $object_id, $meta_key, $meta_value, $prev_value = '' ) { |
|
| 68 | + return update_metadata( $this->object_type, $object_id, $meta_key, $meta_value, $prev_value ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Delete metadata. |
|
| 73 | - * |
|
| 74 | - * @param int $object_id ID of the object metadata is for. |
|
| 75 | - * @param string $meta_key Metadata key. |
|
| 76 | - * @param mixed $meta_value Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete |
|
| 77 | - * metadata entries with this value. Otherwise, delete all entries with the specified meta_key. |
|
| 78 | - * Pass `null, `false`, or an empty string to skip this check. (For backward compatibility, |
|
| 79 | - * it is not possible to pass an empty string to delete those entries with an empty string |
|
| 80 | - * for a value). |
|
| 81 | - * @param bool $delete_all Optional, default is false. If true, delete matching metadata entries for all objects, |
|
| 82 | - * ignoring the specified object_id. Otherwise, only delete matching metadata entries for |
|
| 83 | - * the specified object_id. |
|
| 84 | - * @return bool True on successful delete, false on failure. |
|
| 85 | - * |
|
| 86 | - * @see delete_metadata() |
|
| 87 | - */ |
|
| 88 | - public function delete( $object_id, $meta_key, $meta_value = '', $delete_all = false ) { |
|
| 89 | - return delete_metadata( $this->object_type, $object_id, $meta_key, $meta_value, $delete_all ); |
|
| 90 | - } |
|
| 71 | + /** |
|
| 72 | + * Delete metadata. |
|
| 73 | + * |
|
| 74 | + * @param int $object_id ID of the object metadata is for. |
|
| 75 | + * @param string $meta_key Metadata key. |
|
| 76 | + * @param mixed $meta_value Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete |
|
| 77 | + * metadata entries with this value. Otherwise, delete all entries with the specified meta_key. |
|
| 78 | + * Pass `null, `false`, or an empty string to skip this check. (For backward compatibility, |
|
| 79 | + * it is not possible to pass an empty string to delete those entries with an empty string |
|
| 80 | + * for a value). |
|
| 81 | + * @param bool $delete_all Optional, default is false. If true, delete matching metadata entries for all objects, |
|
| 82 | + * ignoring the specified object_id. Otherwise, only delete matching metadata entries for |
|
| 83 | + * the specified object_id. |
|
| 84 | + * @return bool True on successful delete, false on failure. |
|
| 85 | + * |
|
| 86 | + * @see delete_metadata() |
|
| 87 | + */ |
|
| 88 | + public function delete( $object_id, $meta_key, $meta_value = '', $delete_all = false ) { |
|
| 89 | + return delete_metadata( $this->object_type, $object_id, $meta_key, $meta_value, $delete_all ); |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -9,28 +9,28 @@ |
||
| 9 | 9 | <div id="getting-started" class="gt-tab-pane gt-is-active"> |
| 10 | 10 | <div class="two"> |
| 11 | 11 | <div class="col"> |
| 12 | - <h3><?php esc_html_e( 'Getting Started With Online Generator', 'meta-box' ); ?></h3> |
|
| 13 | - <p><?php esc_html_e( 'Online Generator is a free tool to help you create and set up custom fields using a simple, friendly user interface. With it, you can add fields, set options and generate needed code that\'s ready to copy and paste.', 'meta-box' ); ?></p> |
|
| 12 | + <h3><?php esc_html_e('Getting Started With Online Generator', 'meta-box'); ?></h3> |
|
| 13 | + <p><?php esc_html_e('Online Generator is a free tool to help you create and set up custom fields using a simple, friendly user interface. With it, you can add fields, set options and generate needed code that\'s ready to copy and paste.', 'meta-box'); ?></p> |
|
| 14 | 14 | |
| 15 | - <a target="_blank" class="screenshot" href="https://metabox.io/online-generator/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><img src="<?php echo esc_url( RWMB_URL . 'inc/about/images/online-generator.png' ); ?>" alt="<?php esc_attr_e( 'online generator', 'meta-box' ); ?>"></a> |
|
| 15 | + <a target="_blank" class="screenshot" href="https://metabox.io/online-generator/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><img src="<?php echo esc_url(RWMB_URL . 'inc/about/images/online-generator.png'); ?>" alt="<?php esc_attr_e('online generator', 'meta-box'); ?>"></a> |
|
| 16 | 16 | |
| 17 | - <p><a class="button" target="_blank" href="https://metabox.io/online-generator/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><?php esc_html_e( 'Go to Online Generator', 'meta-box' ); ?></a></p> |
|
| 17 | + <p><a class="button" target="_blank" href="https://metabox.io/online-generator/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><?php esc_html_e('Go to Online Generator', 'meta-box'); ?></a></p> |
|
| 18 | 18 | </div> |
| 19 | 19 | |
| 20 | 20 | <div class="col"> |
| 21 | - <h3><?php esc_html_e( 'Extensions', 'meta-box' ); ?></h3> |
|
| 22 | - <p><?php esc_html_e( 'Wanna see more features that transform your WordPress website into a powerful CMS? Check out some extensions below:', 'meta-box' ); ?><p> |
|
| 21 | + <h3><?php esc_html_e('Extensions', 'meta-box'); ?></h3> |
|
| 22 | + <p><?php esc_html_e('Wanna see more features that transform your WordPress website into a powerful CMS? Check out some extensions below:', 'meta-box'); ?><p> |
|
| 23 | 23 | <ul> |
| 24 | - <li><a target="_blank" href="https://metabox.io/plugins/meta-box-builder/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><?php esc_html_e( 'Meta Box Builder', 'meta-box' ); ?></a> - <?php esc_html_e( 'Build meta boxes and fields with UI.', 'meta-box' ); ?></li> |
|
| 25 | - <li><a target="_blank" href="https://metabox.io/plugins/meta-box-group/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><?php esc_html_e( 'Meta Box Group', 'meta-box' ); ?></a> - <?php esc_html_e( 'Organize fields into repeatable groups.', 'meta-box' ); ?></li> |
|
| 26 | - <li><a target="_blank" href="https://metabox.io/plugins/meta-box-conditional-logic/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><?php esc_html_e( 'Meta Box Conditional Logic', 'meta-box' ); ?></a> - <?php esc_html_e( 'Control the visibility of fields.', 'meta-box' ); ?></li> |
|
| 27 | - <li><a target="_blank" href="https://metabox.io/plugins/mb-settings-page/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><?php esc_html_e( 'MB Settings Page', 'meta-box' ); ?></a> - <?php esc_html_e( 'Create settings pages/Customizer options.', 'meta-box' ); ?></li> |
|
| 24 | + <li><a target="_blank" href="https://metabox.io/plugins/meta-box-builder/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><?php esc_html_e('Meta Box Builder', 'meta-box'); ?></a> - <?php esc_html_e('Build meta boxes and fields with UI.', 'meta-box'); ?></li> |
|
| 25 | + <li><a target="_blank" href="https://metabox.io/plugins/meta-box-group/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><?php esc_html_e('Meta Box Group', 'meta-box'); ?></a> - <?php esc_html_e('Organize fields into repeatable groups.', 'meta-box'); ?></li> |
|
| 26 | + <li><a target="_blank" href="https://metabox.io/plugins/meta-box-conditional-logic/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><?php esc_html_e('Meta Box Conditional Logic', 'meta-box'); ?></a> - <?php esc_html_e('Control the visibility of fields.', 'meta-box'); ?></li> |
|
| 27 | + <li><a target="_blank" href="https://metabox.io/plugins/mb-settings-page/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><?php esc_html_e('MB Settings Page', 'meta-box'); ?></a> - <?php esc_html_e('Create settings pages/Customizer options.', 'meta-box'); ?></li> |
|
| 28 | 28 | </ul> |
| 29 | 29 | |
| 30 | 30 | <div class="youtube-video-container"> |
| 31 | 31 | <iframe width="560" height="315" src="https://www.youtube.com/embed/M0nEF7b0woU" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> |
| 32 | 32 | </div> |
| 33 | - <p><a class="button" target="_blank" href="https://metabox.io/plugins/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><?php esc_html_e( 'More Extensions', 'meta-box' ); ?></a></p> |
|
| 33 | + <p><a class="button" target="_blank" href="https://metabox.io/plugins/?utm_source=WordPress&utm_medium=link&utm_campaign=plugin"><?php esc_html_e('More Extensions', 'meta-box'); ?></a></p> |
|
| 34 | 34 | </div> |
| 35 | 35 | </div> |
| 36 | 36 | </div> |
@@ -9,41 +9,41 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class ActionScheduler_OptionLock extends ActionScheduler_Lock { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * Set a lock using options for a given amount of time (60 seconds by default). |
|
| 14 | - * |
|
| 15 | - * Using an autoloaded option avoids running database queries or other resource intensive tasks |
|
| 16 | - * on frequently triggered hooks, like 'init' or 'shutdown'. |
|
| 17 | - * |
|
| 18 | - * For example, ActionScheduler_QueueRunner->maybe_dispatch_async_request() uses a lock to avoid |
|
| 19 | - * calling ActionScheduler_QueueRunner->has_maximum_concurrent_batches() every time the 'shutdown', |
|
| 20 | - * hook is triggered, because that method calls ActionScheduler_QueueRunner->store->get_claim_count() |
|
| 21 | - * to find the current number of claims in the database. |
|
| 22 | - * |
|
| 23 | - * @param string $lock_type A string to identify different lock types. |
|
| 24 | - * @bool True if lock value has changed, false if not or if set failed. |
|
| 25 | - */ |
|
| 26 | - public function set( $lock_type ) { |
|
| 27 | - return update_option( $this->get_key( $lock_type ), time() + $this->get_duration( $lock_type ) ); |
|
| 28 | - } |
|
| 12 | + /** |
|
| 13 | + * Set a lock using options for a given amount of time (60 seconds by default). |
|
| 14 | + * |
|
| 15 | + * Using an autoloaded option avoids running database queries or other resource intensive tasks |
|
| 16 | + * on frequently triggered hooks, like 'init' or 'shutdown'. |
|
| 17 | + * |
|
| 18 | + * For example, ActionScheduler_QueueRunner->maybe_dispatch_async_request() uses a lock to avoid |
|
| 19 | + * calling ActionScheduler_QueueRunner->has_maximum_concurrent_batches() every time the 'shutdown', |
|
| 20 | + * hook is triggered, because that method calls ActionScheduler_QueueRunner->store->get_claim_count() |
|
| 21 | + * to find the current number of claims in the database. |
|
| 22 | + * |
|
| 23 | + * @param string $lock_type A string to identify different lock types. |
|
| 24 | + * @bool True if lock value has changed, false if not or if set failed. |
|
| 25 | + */ |
|
| 26 | + public function set( $lock_type ) { |
|
| 27 | + return update_option( $this->get_key( $lock_type ), time() + $this->get_duration( $lock_type ) ); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * If a lock is set, return the timestamp it was set to expiry. |
|
| 32 | - * |
|
| 33 | - * @param string $lock_type A string to identify different lock types. |
|
| 34 | - * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. |
|
| 35 | - */ |
|
| 36 | - public function get_expiration( $lock_type ) { |
|
| 37 | - return get_option( $this->get_key( $lock_type ) ); |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * If a lock is set, return the timestamp it was set to expiry. |
|
| 32 | + * |
|
| 33 | + * @param string $lock_type A string to identify different lock types. |
|
| 34 | + * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. |
|
| 35 | + */ |
|
| 36 | + public function get_expiration( $lock_type ) { |
|
| 37 | + return get_option( $this->get_key( $lock_type ) ); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Get the key to use for storing the lock in the transient |
|
| 42 | - * |
|
| 43 | - * @param string $lock_type A string to identify different lock types. |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - protected function get_key( $lock_type ) { |
|
| 47 | - return sprintf( 'action_scheduler_lock_%s', $lock_type ); |
|
| 48 | - } |
|
| 40 | + /** |
|
| 41 | + * Get the key to use for storing the lock in the transient |
|
| 42 | + * |
|
| 43 | + * @param string $lock_type A string to identify different lock types. |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + protected function get_key( $lock_type ) { |
|
| 47 | + return sprintf( 'action_scheduler_lock_%s', $lock_type ); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | * @param string $lock_type A string to identify different lock types. |
| 24 | 24 | * @bool True if lock value has changed, false if not or if set failed. |
| 25 | 25 | */ |
| 26 | - public function set( $lock_type ) { |
|
| 27 | - return update_option( $this->get_key( $lock_type ), time() + $this->get_duration( $lock_type ) ); |
|
| 26 | + public function set($lock_type) { |
|
| 27 | + return update_option($this->get_key($lock_type), time() + $this->get_duration($lock_type)); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | * @param string $lock_type A string to identify different lock types. |
| 34 | 34 | * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. |
| 35 | 35 | */ |
| 36 | - public function get_expiration( $lock_type ) { |
|
| 37 | - return get_option( $this->get_key( $lock_type ) ); |
|
| 36 | + public function get_expiration($lock_type) { |
|
| 37 | + return get_option($this->get_key($lock_type)); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @param string $lock_type A string to identify different lock types. |
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | - protected function get_key( $lock_type ) { |
|
| 47 | - return sprintf( 'action_scheduler_lock_%s', $lock_type ); |
|
| 46 | + protected function get_key($lock_type) { |
|
| 47 | + return sprintf('action_scheduler_lock_%s', $lock_type); |
|
| 48 | 48 | } |
| 49 | 49 | } |
@@ -5,154 +5,154 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class ActionScheduler_QueueCleaner { |
| 7 | 7 | |
| 8 | - /** @var int */ |
|
| 9 | - protected $batch_size; |
|
| 10 | - |
|
| 11 | - /** @var ActionScheduler_Store */ |
|
| 12 | - private $store = null; |
|
| 13 | - |
|
| 14 | - /** |
|
| 15 | - * 31 days in seconds. |
|
| 16 | - * |
|
| 17 | - * @var int |
|
| 18 | - */ |
|
| 19 | - private $month_in_seconds = 2678400; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * ActionScheduler_QueueCleaner constructor. |
|
| 23 | - * |
|
| 24 | - * @param ActionScheduler_Store $store The store instance. |
|
| 25 | - * @param int $batch_size The batch size. |
|
| 26 | - */ |
|
| 27 | - public function __construct( ActionScheduler_Store $store = null, $batch_size = 20 ) { |
|
| 28 | - $this->store = $store ? $store : ActionScheduler_Store::instance(); |
|
| 29 | - $this->batch_size = $batch_size; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - public function delete_old_actions() { |
|
| 33 | - $lifespan = apply_filters( 'action_scheduler_retention_period', $this->month_in_seconds ); |
|
| 34 | - $cutoff = as_get_datetime_object($lifespan.' seconds ago'); |
|
| 35 | - |
|
| 36 | - $statuses_to_purge = array( |
|
| 37 | - ActionScheduler_Store::STATUS_COMPLETE, |
|
| 38 | - ActionScheduler_Store::STATUS_CANCELED, |
|
| 39 | - ); |
|
| 40 | - |
|
| 41 | - foreach ( $statuses_to_purge as $status ) { |
|
| 42 | - $actions_to_delete = $this->store->query_actions( array( |
|
| 43 | - 'status' => $status, |
|
| 44 | - 'modified' => $cutoff, |
|
| 45 | - 'modified_compare' => '<=', |
|
| 46 | - 'per_page' => $this->get_batch_size(), |
|
| 47 | - 'orderby' => 'none', |
|
| 48 | - ) ); |
|
| 49 | - |
|
| 50 | - foreach ( $actions_to_delete as $action_id ) { |
|
| 51 | - try { |
|
| 52 | - $this->store->delete_action( $action_id ); |
|
| 53 | - } catch ( Exception $e ) { |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Notify 3rd party code of exceptions when deleting a completed action older than the retention period |
|
| 57 | - * |
|
| 58 | - * This hook provides a way for 3rd party code to log or otherwise handle exceptions relating to their |
|
| 59 | - * actions. |
|
| 60 | - * |
|
| 61 | - * @since 2.0.0 |
|
| 62 | - * |
|
| 63 | - * @param int $action_id The scheduled actions ID in the data store |
|
| 64 | - * @param Exception $e The exception thrown when attempting to delete the action from the data store |
|
| 65 | - * @param int $lifespan The retention period, in seconds, for old actions |
|
| 66 | - * @param int $count_of_actions_to_delete The number of old actions being deleted in this batch |
|
| 67 | - */ |
|
| 68 | - do_action( 'action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count( $actions_to_delete ) ); |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Unclaim pending actions that have not been run within a given time limit. |
|
| 76 | - * |
|
| 77 | - * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed |
|
| 78 | - * as a parameter is 10x the time limit used for queue processing. |
|
| 79 | - * |
|
| 80 | - * @param int $time_limit The number of seconds to allow a queue to run before unclaiming its pending actions. Default 300 (5 minutes). |
|
| 81 | - */ |
|
| 82 | - public function reset_timeouts( $time_limit = 300 ) { |
|
| 83 | - $timeout = apply_filters( 'action_scheduler_timeout_period', $time_limit ); |
|
| 84 | - if ( $timeout < 0 ) { |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - $cutoff = as_get_datetime_object($timeout.' seconds ago'); |
|
| 88 | - $actions_to_reset = $this->store->query_actions( array( |
|
| 89 | - 'status' => ActionScheduler_Store::STATUS_PENDING, |
|
| 90 | - 'modified' => $cutoff, |
|
| 91 | - 'modified_compare' => '<=', |
|
| 92 | - 'claimed' => true, |
|
| 93 | - 'per_page' => $this->get_batch_size(), |
|
| 94 | - 'orderby' => 'none', |
|
| 95 | - ) ); |
|
| 96 | - |
|
| 97 | - foreach ( $actions_to_reset as $action_id ) { |
|
| 98 | - $this->store->unclaim_action( $action_id ); |
|
| 99 | - do_action( 'action_scheduler_reset_action', $action_id ); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Mark actions that have been running for more than a given time limit as failed, based on |
|
| 105 | - * the assumption some uncatachable and unloggable fatal error occurred during processing. |
|
| 106 | - * |
|
| 107 | - * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed |
|
| 108 | - * as a parameter is 10x the time limit used for queue processing. |
|
| 109 | - * |
|
| 110 | - * @param int $time_limit The number of seconds to allow an action to run before it is considered to have failed. Default 300 (5 minutes). |
|
| 111 | - */ |
|
| 112 | - public function mark_failures( $time_limit = 300 ) { |
|
| 113 | - $timeout = apply_filters( 'action_scheduler_failure_period', $time_limit ); |
|
| 114 | - if ( $timeout < 0 ) { |
|
| 115 | - return; |
|
| 116 | - } |
|
| 117 | - $cutoff = as_get_datetime_object($timeout.' seconds ago'); |
|
| 118 | - $actions_to_reset = $this->store->query_actions( array( |
|
| 119 | - 'status' => ActionScheduler_Store::STATUS_RUNNING, |
|
| 120 | - 'modified' => $cutoff, |
|
| 121 | - 'modified_compare' => '<=', |
|
| 122 | - 'per_page' => $this->get_batch_size(), |
|
| 123 | - 'orderby' => 'none', |
|
| 124 | - ) ); |
|
| 125 | - |
|
| 126 | - foreach ( $actions_to_reset as $action_id ) { |
|
| 127 | - $this->store->mark_failure( $action_id ); |
|
| 128 | - do_action( 'action_scheduler_failed_action', $action_id, $timeout ); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Do all of the cleaning actions. |
|
| 134 | - * |
|
| 135 | - * @param int $time_limit The number of seconds to use as the timeout and failure period. Default 300 (5 minutes). |
|
| 136 | - * @author Jeremy Pry |
|
| 137 | - */ |
|
| 138 | - public function clean( $time_limit = 300 ) { |
|
| 139 | - $this->delete_old_actions(); |
|
| 140 | - $this->reset_timeouts( $time_limit ); |
|
| 141 | - $this->mark_failures( $time_limit ); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Get the batch size for cleaning the queue. |
|
| 146 | - * |
|
| 147 | - * @author Jeremy Pry |
|
| 148 | - * @return int |
|
| 149 | - */ |
|
| 150 | - protected function get_batch_size() { |
|
| 151 | - /** |
|
| 152 | - * Filter the batch size when cleaning the queue. |
|
| 153 | - * |
|
| 154 | - * @param int $batch_size The number of actions to clean in one batch. |
|
| 155 | - */ |
|
| 156 | - return absint( apply_filters( 'action_scheduler_cleanup_batch_size', $this->batch_size ) ); |
|
| 157 | - } |
|
| 8 | + /** @var int */ |
|
| 9 | + protected $batch_size; |
|
| 10 | + |
|
| 11 | + /** @var ActionScheduler_Store */ |
|
| 12 | + private $store = null; |
|
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * 31 days in seconds. |
|
| 16 | + * |
|
| 17 | + * @var int |
|
| 18 | + */ |
|
| 19 | + private $month_in_seconds = 2678400; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * ActionScheduler_QueueCleaner constructor. |
|
| 23 | + * |
|
| 24 | + * @param ActionScheduler_Store $store The store instance. |
|
| 25 | + * @param int $batch_size The batch size. |
|
| 26 | + */ |
|
| 27 | + public function __construct( ActionScheduler_Store $store = null, $batch_size = 20 ) { |
|
| 28 | + $this->store = $store ? $store : ActionScheduler_Store::instance(); |
|
| 29 | + $this->batch_size = $batch_size; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + public function delete_old_actions() { |
|
| 33 | + $lifespan = apply_filters( 'action_scheduler_retention_period', $this->month_in_seconds ); |
|
| 34 | + $cutoff = as_get_datetime_object($lifespan.' seconds ago'); |
|
| 35 | + |
|
| 36 | + $statuses_to_purge = array( |
|
| 37 | + ActionScheduler_Store::STATUS_COMPLETE, |
|
| 38 | + ActionScheduler_Store::STATUS_CANCELED, |
|
| 39 | + ); |
|
| 40 | + |
|
| 41 | + foreach ( $statuses_to_purge as $status ) { |
|
| 42 | + $actions_to_delete = $this->store->query_actions( array( |
|
| 43 | + 'status' => $status, |
|
| 44 | + 'modified' => $cutoff, |
|
| 45 | + 'modified_compare' => '<=', |
|
| 46 | + 'per_page' => $this->get_batch_size(), |
|
| 47 | + 'orderby' => 'none', |
|
| 48 | + ) ); |
|
| 49 | + |
|
| 50 | + foreach ( $actions_to_delete as $action_id ) { |
|
| 51 | + try { |
|
| 52 | + $this->store->delete_action( $action_id ); |
|
| 53 | + } catch ( Exception $e ) { |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Notify 3rd party code of exceptions when deleting a completed action older than the retention period |
|
| 57 | + * |
|
| 58 | + * This hook provides a way for 3rd party code to log or otherwise handle exceptions relating to their |
|
| 59 | + * actions. |
|
| 60 | + * |
|
| 61 | + * @since 2.0.0 |
|
| 62 | + * |
|
| 63 | + * @param int $action_id The scheduled actions ID in the data store |
|
| 64 | + * @param Exception $e The exception thrown when attempting to delete the action from the data store |
|
| 65 | + * @param int $lifespan The retention period, in seconds, for old actions |
|
| 66 | + * @param int $count_of_actions_to_delete The number of old actions being deleted in this batch |
|
| 67 | + */ |
|
| 68 | + do_action( 'action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count( $actions_to_delete ) ); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Unclaim pending actions that have not been run within a given time limit. |
|
| 76 | + * |
|
| 77 | + * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed |
|
| 78 | + * as a parameter is 10x the time limit used for queue processing. |
|
| 79 | + * |
|
| 80 | + * @param int $time_limit The number of seconds to allow a queue to run before unclaiming its pending actions. Default 300 (5 minutes). |
|
| 81 | + */ |
|
| 82 | + public function reset_timeouts( $time_limit = 300 ) { |
|
| 83 | + $timeout = apply_filters( 'action_scheduler_timeout_period', $time_limit ); |
|
| 84 | + if ( $timeout < 0 ) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + $cutoff = as_get_datetime_object($timeout.' seconds ago'); |
|
| 88 | + $actions_to_reset = $this->store->query_actions( array( |
|
| 89 | + 'status' => ActionScheduler_Store::STATUS_PENDING, |
|
| 90 | + 'modified' => $cutoff, |
|
| 91 | + 'modified_compare' => '<=', |
|
| 92 | + 'claimed' => true, |
|
| 93 | + 'per_page' => $this->get_batch_size(), |
|
| 94 | + 'orderby' => 'none', |
|
| 95 | + ) ); |
|
| 96 | + |
|
| 97 | + foreach ( $actions_to_reset as $action_id ) { |
|
| 98 | + $this->store->unclaim_action( $action_id ); |
|
| 99 | + do_action( 'action_scheduler_reset_action', $action_id ); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Mark actions that have been running for more than a given time limit as failed, based on |
|
| 105 | + * the assumption some uncatachable and unloggable fatal error occurred during processing. |
|
| 106 | + * |
|
| 107 | + * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed |
|
| 108 | + * as a parameter is 10x the time limit used for queue processing. |
|
| 109 | + * |
|
| 110 | + * @param int $time_limit The number of seconds to allow an action to run before it is considered to have failed. Default 300 (5 minutes). |
|
| 111 | + */ |
|
| 112 | + public function mark_failures( $time_limit = 300 ) { |
|
| 113 | + $timeout = apply_filters( 'action_scheduler_failure_period', $time_limit ); |
|
| 114 | + if ( $timeout < 0 ) { |
|
| 115 | + return; |
|
| 116 | + } |
|
| 117 | + $cutoff = as_get_datetime_object($timeout.' seconds ago'); |
|
| 118 | + $actions_to_reset = $this->store->query_actions( array( |
|
| 119 | + 'status' => ActionScheduler_Store::STATUS_RUNNING, |
|
| 120 | + 'modified' => $cutoff, |
|
| 121 | + 'modified_compare' => '<=', |
|
| 122 | + 'per_page' => $this->get_batch_size(), |
|
| 123 | + 'orderby' => 'none', |
|
| 124 | + ) ); |
|
| 125 | + |
|
| 126 | + foreach ( $actions_to_reset as $action_id ) { |
|
| 127 | + $this->store->mark_failure( $action_id ); |
|
| 128 | + do_action( 'action_scheduler_failed_action', $action_id, $timeout ); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Do all of the cleaning actions. |
|
| 134 | + * |
|
| 135 | + * @param int $time_limit The number of seconds to use as the timeout and failure period. Default 300 (5 minutes). |
|
| 136 | + * @author Jeremy Pry |
|
| 137 | + */ |
|
| 138 | + public function clean( $time_limit = 300 ) { |
|
| 139 | + $this->delete_old_actions(); |
|
| 140 | + $this->reset_timeouts( $time_limit ); |
|
| 141 | + $this->mark_failures( $time_limit ); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Get the batch size for cleaning the queue. |
|
| 146 | + * |
|
| 147 | + * @author Jeremy Pry |
|
| 148 | + * @return int |
|
| 149 | + */ |
|
| 150 | + protected function get_batch_size() { |
|
| 151 | + /** |
|
| 152 | + * Filter the batch size when cleaning the queue. |
|
| 153 | + * |
|
| 154 | + * @param int $batch_size The number of actions to clean in one batch. |
|
| 155 | + */ |
|
| 156 | + return absint( apply_filters( 'action_scheduler_cleanup_batch_size', $this->batch_size ) ); |
|
| 157 | + } |
|
| 158 | 158 | } |
@@ -24,33 +24,33 @@ discard block |
||
| 24 | 24 | * @param ActionScheduler_Store $store The store instance. |
| 25 | 25 | * @param int $batch_size The batch size. |
| 26 | 26 | */ |
| 27 | - public function __construct( ActionScheduler_Store $store = null, $batch_size = 20 ) { |
|
| 27 | + public function __construct(ActionScheduler_Store $store = null, $batch_size = 20) { |
|
| 28 | 28 | $this->store = $store ? $store : ActionScheduler_Store::instance(); |
| 29 | 29 | $this->batch_size = $batch_size; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function delete_old_actions() { |
| 33 | - $lifespan = apply_filters( 'action_scheduler_retention_period', $this->month_in_seconds ); |
|
| 34 | - $cutoff = as_get_datetime_object($lifespan.' seconds ago'); |
|
| 33 | + $lifespan = apply_filters('action_scheduler_retention_period', $this->month_in_seconds); |
|
| 34 | + $cutoff = as_get_datetime_object($lifespan . ' seconds ago'); |
|
| 35 | 35 | |
| 36 | 36 | $statuses_to_purge = array( |
| 37 | 37 | ActionScheduler_Store::STATUS_COMPLETE, |
| 38 | 38 | ActionScheduler_Store::STATUS_CANCELED, |
| 39 | 39 | ); |
| 40 | 40 | |
| 41 | - foreach ( $statuses_to_purge as $status ) { |
|
| 42 | - $actions_to_delete = $this->store->query_actions( array( |
|
| 41 | + foreach ($statuses_to_purge as $status) { |
|
| 42 | + $actions_to_delete = $this->store->query_actions(array( |
|
| 43 | 43 | 'status' => $status, |
| 44 | 44 | 'modified' => $cutoff, |
| 45 | 45 | 'modified_compare' => '<=', |
| 46 | 46 | 'per_page' => $this->get_batch_size(), |
| 47 | 47 | 'orderby' => 'none', |
| 48 | - ) ); |
|
| 48 | + )); |
|
| 49 | 49 | |
| 50 | - foreach ( $actions_to_delete as $action_id ) { |
|
| 50 | + foreach ($actions_to_delete as $action_id) { |
|
| 51 | 51 | try { |
| 52 | - $this->store->delete_action( $action_id ); |
|
| 53 | - } catch ( Exception $e ) { |
|
| 52 | + $this->store->delete_action($action_id); |
|
| 53 | + } catch (Exception $e) { |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Notify 3rd party code of exceptions when deleting a completed action older than the retention period |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @param int $lifespan The retention period, in seconds, for old actions |
| 66 | 66 | * @param int $count_of_actions_to_delete The number of old actions being deleted in this batch |
| 67 | 67 | */ |
| 68 | - do_action( 'action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count( $actions_to_delete ) ); |
|
| 68 | + do_action('action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count($actions_to_delete)); |
|
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -79,24 +79,24 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @param int $time_limit The number of seconds to allow a queue to run before unclaiming its pending actions. Default 300 (5 minutes). |
| 81 | 81 | */ |
| 82 | - public function reset_timeouts( $time_limit = 300 ) { |
|
| 83 | - $timeout = apply_filters( 'action_scheduler_timeout_period', $time_limit ); |
|
| 84 | - if ( $timeout < 0 ) { |
|
| 82 | + public function reset_timeouts($time_limit = 300) { |
|
| 83 | + $timeout = apply_filters('action_scheduler_timeout_period', $time_limit); |
|
| 84 | + if ($timeout < 0) { |
|
| 85 | 85 | return; |
| 86 | 86 | } |
| 87 | - $cutoff = as_get_datetime_object($timeout.' seconds ago'); |
|
| 88 | - $actions_to_reset = $this->store->query_actions( array( |
|
| 87 | + $cutoff = as_get_datetime_object($timeout . ' seconds ago'); |
|
| 88 | + $actions_to_reset = $this->store->query_actions(array( |
|
| 89 | 89 | 'status' => ActionScheduler_Store::STATUS_PENDING, |
| 90 | 90 | 'modified' => $cutoff, |
| 91 | 91 | 'modified_compare' => '<=', |
| 92 | 92 | 'claimed' => true, |
| 93 | 93 | 'per_page' => $this->get_batch_size(), |
| 94 | 94 | 'orderby' => 'none', |
| 95 | - ) ); |
|
| 95 | + )); |
|
| 96 | 96 | |
| 97 | - foreach ( $actions_to_reset as $action_id ) { |
|
| 98 | - $this->store->unclaim_action( $action_id ); |
|
| 99 | - do_action( 'action_scheduler_reset_action', $action_id ); |
|
| 97 | + foreach ($actions_to_reset as $action_id) { |
|
| 98 | + $this->store->unclaim_action($action_id); |
|
| 99 | + do_action('action_scheduler_reset_action', $action_id); |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
@@ -109,23 +109,23 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @param int $time_limit The number of seconds to allow an action to run before it is considered to have failed. Default 300 (5 minutes). |
| 111 | 111 | */ |
| 112 | - public function mark_failures( $time_limit = 300 ) { |
|
| 113 | - $timeout = apply_filters( 'action_scheduler_failure_period', $time_limit ); |
|
| 114 | - if ( $timeout < 0 ) { |
|
| 112 | + public function mark_failures($time_limit = 300) { |
|
| 113 | + $timeout = apply_filters('action_scheduler_failure_period', $time_limit); |
|
| 114 | + if ($timeout < 0) { |
|
| 115 | 115 | return; |
| 116 | 116 | } |
| 117 | - $cutoff = as_get_datetime_object($timeout.' seconds ago'); |
|
| 118 | - $actions_to_reset = $this->store->query_actions( array( |
|
| 117 | + $cutoff = as_get_datetime_object($timeout . ' seconds ago'); |
|
| 118 | + $actions_to_reset = $this->store->query_actions(array( |
|
| 119 | 119 | 'status' => ActionScheduler_Store::STATUS_RUNNING, |
| 120 | 120 | 'modified' => $cutoff, |
| 121 | 121 | 'modified_compare' => '<=', |
| 122 | 122 | 'per_page' => $this->get_batch_size(), |
| 123 | 123 | 'orderby' => 'none', |
| 124 | - ) ); |
|
| 124 | + )); |
|
| 125 | 125 | |
| 126 | - foreach ( $actions_to_reset as $action_id ) { |
|
| 127 | - $this->store->mark_failure( $action_id ); |
|
| 128 | - do_action( 'action_scheduler_failed_action', $action_id, $timeout ); |
|
| 126 | + foreach ($actions_to_reset as $action_id) { |
|
| 127 | + $this->store->mark_failure($action_id); |
|
| 128 | + do_action('action_scheduler_failed_action', $action_id, $timeout); |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | * @param int $time_limit The number of seconds to use as the timeout and failure period. Default 300 (5 minutes). |
| 136 | 136 | * @author Jeremy Pry |
| 137 | 137 | */ |
| 138 | - public function clean( $time_limit = 300 ) { |
|
| 138 | + public function clean($time_limit = 300) { |
|
| 139 | 139 | $this->delete_old_actions(); |
| 140 | - $this->reset_timeouts( $time_limit ); |
|
| 141 | - $this->mark_failures( $time_limit ); |
|
| 140 | + $this->reset_timeouts($time_limit); |
|
| 141 | + $this->mark_failures($time_limit); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -153,6 +153,6 @@ discard block |
||
| 153 | 153 | * |
| 154 | 154 | * @param int $batch_size The number of actions to clean in one batch. |
| 155 | 155 | */ |
| 156 | - return absint( apply_filters( 'action_scheduler_cleanup_batch_size', $this->batch_size ) ); |
|
| 156 | + return absint(apply_filters('action_scheduler_cleanup_batch_size', $this->batch_size)); |
|
| 157 | 157 | } |
| 158 | 158 | } |