@@ -11,94 +11,94 @@ |
||
| 11 | 11 | |
| 12 | 12 | class All_Posts_Task implements Task { |
| 13 | 13 | |
| 14 | - private $callable; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * @var string|null |
|
| 18 | - */ |
|
| 19 | - private $post_type; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var string|null |
|
| 23 | - */ |
|
| 24 | - private $id; |
|
| 25 | - |
|
| 26 | - public function __construct( $callable, $post_type = null, $id = null ) { |
|
| 27 | - $this->callable = $callable; |
|
| 28 | - $this->post_type = $post_type; |
|
| 29 | - $this->id = $id; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - public function get_id() { |
|
| 33 | - return isset( $this->id ) ? $this->id : sha1( get_class( $this ) ); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function starting() { |
|
| 37 | - global $wpdb; |
|
| 38 | - |
|
| 39 | - // Try to get the count from transient, or load it from database. |
|
| 40 | - $key = $this->get_transient_key(); |
|
| 41 | - $count = get_transient( $key ); |
|
| 42 | - if ( false === $count ) { |
|
| 43 | - $count = $wpdb->get_var( |
|
| 44 | - "SELECT COUNT( 1 ) |
|
| 14 | + private $callable; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @var string|null |
|
| 18 | + */ |
|
| 19 | + private $post_type; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var string|null |
|
| 23 | + */ |
|
| 24 | + private $id; |
|
| 25 | + |
|
| 26 | + public function __construct( $callable, $post_type = null, $id = null ) { |
|
| 27 | + $this->callable = $callable; |
|
| 28 | + $this->post_type = $post_type; |
|
| 29 | + $this->id = $id; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + public function get_id() { |
|
| 33 | + return isset( $this->id ) ? $this->id : sha1( get_class( $this ) ); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public function starting() { |
|
| 37 | + global $wpdb; |
|
| 38 | + |
|
| 39 | + // Try to get the count from transient, or load it from database. |
|
| 40 | + $key = $this->get_transient_key(); |
|
| 41 | + $count = get_transient( $key ); |
|
| 42 | + if ( false === $count ) { |
|
| 43 | + $count = $wpdb->get_var( |
|
| 44 | + "SELECT COUNT( 1 ) |
|
| 45 | 45 | FROM $wpdb->posts " |
| 46 | - . $this->where( $this->add_post_type_filter() ) ); |
|
| 47 | - set_transient( $key, $count, HOUR_IN_SECONDS ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - return $count; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param $value mixed The incoming value. |
|
| 55 | - * @param $args { |
|
| 56 | - * |
|
| 57 | - * @type int $offset The index of the current item. |
|
| 58 | - * @type int $count The total number of items as provided by the `starting` function. |
|
| 59 | - * @type int $batch_size The number of items to process within this call. |
|
| 60 | - * } |
|
| 61 | - * |
|
| 62 | - * @return void |
|
| 63 | - */ |
|
| 64 | - public function tick( $value, $args ) { |
|
| 65 | - global $wpdb; |
|
| 66 | - |
|
| 67 | - $ids = $wpdb->get_col( |
|
| 68 | - $wpdb->prepare( |
|
| 69 | - "SELECT ID FROM $wpdb->posts " |
|
| 70 | - . $this->where( $this->add_post_type_filter() ) |
|
| 71 | - . " ORDER BY ID LIMIT %d,%d", |
|
| 72 | - $args['offset'], |
|
| 73 | - $args['batch_size'] |
|
| 74 | - ) |
|
| 75 | - ); |
|
| 76 | - |
|
| 77 | - foreach ( $ids as $id ) { |
|
| 78 | - call_user_func( $this->callable, $id ); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - private function add_post_type_filter() { |
|
| 84 | - global $wpdb; |
|
| 85 | - if ( isset( $this->post_type ) ) { |
|
| 86 | - return $wpdb->prepare( ' post_type = %s ', $this->post_type ); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return ''; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - private function where( $filter ) { |
|
| 93 | - if ( ! empty( $filter ) ) { |
|
| 94 | - return " WHERE $filter"; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return ''; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - private function get_transient_key() { |
|
| 101 | - return '_wl_task__all_posts_task__count' . ( isset( $this->post_type ) ? '__' . $this->post_type : '' ); |
|
| 102 | - } |
|
| 46 | + . $this->where( $this->add_post_type_filter() ) ); |
|
| 47 | + set_transient( $key, $count, HOUR_IN_SECONDS ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + return $count; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param $value mixed The incoming value. |
|
| 55 | + * @param $args { |
|
| 56 | + * |
|
| 57 | + * @type int $offset The index of the current item. |
|
| 58 | + * @type int $count The total number of items as provided by the `starting` function. |
|
| 59 | + * @type int $batch_size The number of items to process within this call. |
|
| 60 | + * } |
|
| 61 | + * |
|
| 62 | + * @return void |
|
| 63 | + */ |
|
| 64 | + public function tick( $value, $args ) { |
|
| 65 | + global $wpdb; |
|
| 66 | + |
|
| 67 | + $ids = $wpdb->get_col( |
|
| 68 | + $wpdb->prepare( |
|
| 69 | + "SELECT ID FROM $wpdb->posts " |
|
| 70 | + . $this->where( $this->add_post_type_filter() ) |
|
| 71 | + . " ORDER BY ID LIMIT %d,%d", |
|
| 72 | + $args['offset'], |
|
| 73 | + $args['batch_size'] |
|
| 74 | + ) |
|
| 75 | + ); |
|
| 76 | + |
|
| 77 | + foreach ( $ids as $id ) { |
|
| 78 | + call_user_func( $this->callable, $id ); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + private function add_post_type_filter() { |
|
| 84 | + global $wpdb; |
|
| 85 | + if ( isset( $this->post_type ) ) { |
|
| 86 | + return $wpdb->prepare( ' post_type = %s ', $this->post_type ); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return ''; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + private function where( $filter ) { |
|
| 93 | + if ( ! empty( $filter ) ) { |
|
| 94 | + return " WHERE $filter"; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return ''; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + private function get_transient_key() { |
|
| 101 | + return '_wl_task__all_posts_task__count' . ( isset( $this->post_type ) ? '__' . $this->post_type : '' ); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | } |
@@ -23,14 +23,14 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | private $id; |
| 25 | 25 | |
| 26 | - public function __construct( $callable, $post_type = null, $id = null ) { |
|
| 26 | + public function __construct($callable, $post_type = null, $id = null) { |
|
| 27 | 27 | $this->callable = $callable; |
| 28 | 28 | $this->post_type = $post_type; |
| 29 | 29 | $this->id = $id; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function get_id() { |
| 33 | - return isset( $this->id ) ? $this->id : sha1( get_class( $this ) ); |
|
| 33 | + return isset($this->id) ? $this->id : sha1(get_class($this)); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | public function starting() { |
@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | // Try to get the count from transient, or load it from database. |
| 40 | 40 | $key = $this->get_transient_key(); |
| 41 | - $count = get_transient( $key ); |
|
| 42 | - if ( false === $count ) { |
|
| 41 | + $count = get_transient($key); |
|
| 42 | + if (false === $count) { |
|
| 43 | 43 | $count = $wpdb->get_var( |
| 44 | 44 | "SELECT COUNT( 1 ) |
| 45 | 45 | FROM $wpdb->posts " |
| 46 | - . $this->where( $this->add_post_type_filter() ) ); |
|
| 47 | - set_transient( $key, $count, HOUR_IN_SECONDS ); |
|
| 46 | + . $this->where($this->add_post_type_filter()) ); |
|
| 47 | + set_transient($key, $count, HOUR_IN_SECONDS); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | return $count; |
@@ -61,36 +61,36 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return void |
| 63 | 63 | */ |
| 64 | - public function tick( $value, $args ) { |
|
| 64 | + public function tick($value, $args) { |
|
| 65 | 65 | global $wpdb; |
| 66 | 66 | |
| 67 | 67 | $ids = $wpdb->get_col( |
| 68 | 68 | $wpdb->prepare( |
| 69 | 69 | "SELECT ID FROM $wpdb->posts " |
| 70 | - . $this->where( $this->add_post_type_filter() ) |
|
| 70 | + . $this->where($this->add_post_type_filter()) |
|
| 71 | 71 | . " ORDER BY ID LIMIT %d,%d", |
| 72 | 72 | $args['offset'], |
| 73 | 73 | $args['batch_size'] |
| 74 | 74 | ) |
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | - foreach ( $ids as $id ) { |
|
| 78 | - call_user_func( $this->callable, $id ); |
|
| 77 | + foreach ($ids as $id) { |
|
| 78 | + call_user_func($this->callable, $id); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | private function add_post_type_filter() { |
| 84 | 84 | global $wpdb; |
| 85 | - if ( isset( $this->post_type ) ) { |
|
| 86 | - return $wpdb->prepare( ' post_type = %s ', $this->post_type ); |
|
| 85 | + if (isset($this->post_type)) { |
|
| 86 | + return $wpdb->prepare(' post_type = %s ', $this->post_type); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | return ''; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - private function where( $filter ) { |
|
| 93 | - if ( ! empty( $filter ) ) { |
|
| 92 | + private function where($filter) { |
|
| 93 | + if ( ! empty($filter)) { |
|
| 94 | 94 | return " WHERE $filter"; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | private function get_transient_key() { |
| 101 | - return '_wl_task__all_posts_task__count' . ( isset( $this->post_type ) ? '__' . $this->post_type : '' ); |
|
| 101 | + return '_wl_task__all_posts_task__count'.(isset($this->post_type) ? '__'.$this->post_type : ''); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | } |
@@ -7,119 +7,119 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Background_Task extends Wordlift_Plugin_WP_Background_Process { |
| 9 | 9 | |
| 10 | - const STATE_STARTED = 'started'; |
|
| 11 | - const STATE_STOPPED = 'stopped'; |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * The current state of the task, started or stopped. |
|
| 15 | - * |
|
| 16 | - * @var Background_Task_State $state |
|
| 17 | - */ |
|
| 18 | - private $state; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * The actual task. |
|
| 22 | - * |
|
| 23 | - * @var Task $task |
|
| 24 | - */ |
|
| 25 | - private $task; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * The prefix to store the state and other information in WP's options table, determined at instantiation. |
|
| 29 | - * |
|
| 30 | - * @var string $option_prefix |
|
| 31 | - */ |
|
| 32 | - private $option_prefix; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @param Task $task |
|
| 36 | - */ |
|
| 37 | - public function __construct( $task ) { |
|
| 38 | - $this->action = $task->get_id(); |
|
| 39 | - $this->option_prefix = "_{$this->action}_"; |
|
| 40 | - |
|
| 41 | - parent::__construct(); |
|
| 42 | - |
|
| 43 | - // Set the current state. |
|
| 44 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
| 45 | - $this->state = new Background_Task_Started_State( $this, $task ); |
|
| 46 | - } else { |
|
| 47 | - $this->state = new Background_Task_Stopped_State( $this ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - $this->task = $task; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public static function create( $task ) { |
|
| 54 | - return new self( $task ); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function get_option_prefix() { |
|
| 58 | - return $this->option_prefix; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * This function is called: |
|
| 63 | - * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
| 64 | - * - To synchronize a post, by passing a numeric ID. |
|
| 65 | - * |
|
| 66 | - * This function returns the parameter for the next call or NULL if there are no more posts to process. |
|
| 67 | - * |
|
| 68 | - * @param mixed $item Queue item to iterate over. |
|
| 69 | - * |
|
| 70 | - * @return int[]|false The next post IDs or false if there are no more. |
|
| 71 | - */ |
|
| 72 | - protected function task( $item ) { |
|
| 73 | - |
|
| 74 | - return $this->state->task( $item ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Transition to the started state. |
|
| 79 | - */ |
|
| 80 | - public function start() { |
|
| 81 | - $this->state->leave(); |
|
| 82 | - $this->state = new Background_Task_Started_State( $this, $this->task ); |
|
| 83 | - $this->state->enter(); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Transition to the stopped state. |
|
| 88 | - */ |
|
| 89 | - public function stop() { |
|
| 90 | - $this->state->leave(); |
|
| 91 | - $this->state = new Background_Task_Stopped_State( $this ); |
|
| 92 | - $this->state->enter(); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function resume() { |
|
| 96 | - $this->state->resume(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Get the current state. |
|
| 101 | - * |
|
| 102 | - * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
| 103 | - */ |
|
| 104 | - public function get_state() { |
|
| 105 | - return get_option( $this->option_prefix . 'state', self::STATE_STOPPED ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Persist the current state. |
|
| 110 | - * |
|
| 111 | - * @param string $value |
|
| 112 | - * |
|
| 113 | - * @return bool |
|
| 114 | - */ |
|
| 115 | - public function set_state( $value ) { |
|
| 116 | - return null === $value |
|
| 117 | - ? delete_option( $this->option_prefix . 'state' ) |
|
| 118 | - : update_option( $this->option_prefix . 'state', $value, true ); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - public function get_info() { |
|
| 122 | - return $this->state->get_info(); |
|
| 123 | - } |
|
| 10 | + const STATE_STARTED = 'started'; |
|
| 11 | + const STATE_STOPPED = 'stopped'; |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * The current state of the task, started or stopped. |
|
| 15 | + * |
|
| 16 | + * @var Background_Task_State $state |
|
| 17 | + */ |
|
| 18 | + private $state; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * The actual task. |
|
| 22 | + * |
|
| 23 | + * @var Task $task |
|
| 24 | + */ |
|
| 25 | + private $task; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * The prefix to store the state and other information in WP's options table, determined at instantiation. |
|
| 29 | + * |
|
| 30 | + * @var string $option_prefix |
|
| 31 | + */ |
|
| 32 | + private $option_prefix; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @param Task $task |
|
| 36 | + */ |
|
| 37 | + public function __construct( $task ) { |
|
| 38 | + $this->action = $task->get_id(); |
|
| 39 | + $this->option_prefix = "_{$this->action}_"; |
|
| 40 | + |
|
| 41 | + parent::__construct(); |
|
| 42 | + |
|
| 43 | + // Set the current state. |
|
| 44 | + if ( self::STATE_STARTED === $this->get_state() ) { |
|
| 45 | + $this->state = new Background_Task_Started_State( $this, $task ); |
|
| 46 | + } else { |
|
| 47 | + $this->state = new Background_Task_Stopped_State( $this ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + $this->task = $task; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public static function create( $task ) { |
|
| 54 | + return new self( $task ); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function get_option_prefix() { |
|
| 58 | + return $this->option_prefix; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * This function is called: |
|
| 63 | + * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
| 64 | + * - To synchronize a post, by passing a numeric ID. |
|
| 65 | + * |
|
| 66 | + * This function returns the parameter for the next call or NULL if there are no more posts to process. |
|
| 67 | + * |
|
| 68 | + * @param mixed $item Queue item to iterate over. |
|
| 69 | + * |
|
| 70 | + * @return int[]|false The next post IDs or false if there are no more. |
|
| 71 | + */ |
|
| 72 | + protected function task( $item ) { |
|
| 73 | + |
|
| 74 | + return $this->state->task( $item ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Transition to the started state. |
|
| 79 | + */ |
|
| 80 | + public function start() { |
|
| 81 | + $this->state->leave(); |
|
| 82 | + $this->state = new Background_Task_Started_State( $this, $this->task ); |
|
| 83 | + $this->state->enter(); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Transition to the stopped state. |
|
| 88 | + */ |
|
| 89 | + public function stop() { |
|
| 90 | + $this->state->leave(); |
|
| 91 | + $this->state = new Background_Task_Stopped_State( $this ); |
|
| 92 | + $this->state->enter(); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function resume() { |
|
| 96 | + $this->state->resume(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Get the current state. |
|
| 101 | + * |
|
| 102 | + * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
| 103 | + */ |
|
| 104 | + public function get_state() { |
|
| 105 | + return get_option( $this->option_prefix . 'state', self::STATE_STOPPED ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Persist the current state. |
|
| 110 | + * |
|
| 111 | + * @param string $value |
|
| 112 | + * |
|
| 113 | + * @return bool |
|
| 114 | + */ |
|
| 115 | + public function set_state( $value ) { |
|
| 116 | + return null === $value |
|
| 117 | + ? delete_option( $this->option_prefix . 'state' ) |
|
| 118 | + : update_option( $this->option_prefix . 'state', $value, true ); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + public function get_info() { |
|
| 122 | + return $this->state->get_info(); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | } |
@@ -34,24 +34,24 @@ discard block |
||
| 34 | 34 | /** |
| 35 | 35 | * @param Task $task |
| 36 | 36 | */ |
| 37 | - public function __construct( $task ) { |
|
| 37 | + public function __construct($task) { |
|
| 38 | 38 | $this->action = $task->get_id(); |
| 39 | 39 | $this->option_prefix = "_{$this->action}_"; |
| 40 | 40 | |
| 41 | 41 | parent::__construct(); |
| 42 | 42 | |
| 43 | 43 | // Set the current state. |
| 44 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
| 45 | - $this->state = new Background_Task_Started_State( $this, $task ); |
|
| 44 | + if (self::STATE_STARTED === $this->get_state()) { |
|
| 45 | + $this->state = new Background_Task_Started_State($this, $task); |
|
| 46 | 46 | } else { |
| 47 | - $this->state = new Background_Task_Stopped_State( $this ); |
|
| 47 | + $this->state = new Background_Task_Stopped_State($this); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | $this->task = $task; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - public static function create( $task ) { |
|
| 54 | - return new self( $task ); |
|
| 53 | + public static function create($task) { |
|
| 54 | + return new self($task); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | public function get_option_prefix() { |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @return int[]|false The next post IDs or false if there are no more. |
| 71 | 71 | */ |
| 72 | - protected function task( $item ) { |
|
| 72 | + protected function task($item) { |
|
| 73 | 73 | |
| 74 | - return $this->state->task( $item ); |
|
| 74 | + return $this->state->task($item); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function start() { |
| 81 | 81 | $this->state->leave(); |
| 82 | - $this->state = new Background_Task_Started_State( $this, $this->task ); |
|
| 82 | + $this->state = new Background_Task_Started_State($this, $this->task); |
|
| 83 | 83 | $this->state->enter(); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function stop() { |
| 90 | 90 | $this->state->leave(); |
| 91 | - $this->state = new Background_Task_Stopped_State( $this ); |
|
| 91 | + $this->state = new Background_Task_Stopped_State($this); |
|
| 92 | 92 | $this->state->enter(); |
| 93 | 93 | } |
| 94 | 94 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
| 103 | 103 | */ |
| 104 | 104 | public function get_state() { |
| 105 | - return get_option( $this->option_prefix . 'state', self::STATE_STOPPED ); |
|
| 105 | + return get_option($this->option_prefix.'state', self::STATE_STOPPED); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -112,10 +112,10 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @return bool |
| 114 | 114 | */ |
| 115 | - public function set_state( $value ) { |
|
| 115 | + public function set_state($value) { |
|
| 116 | 116 | return null === $value |
| 117 | - ? delete_option( $this->option_prefix . 'state' ) |
|
| 118 | - : update_option( $this->option_prefix . 'state', $value, true ); |
|
| 117 | + ? delete_option($this->option_prefix.'state') |
|
| 118 | + : update_option($this->option_prefix.'state', $value, true); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | public function get_info() { |
@@ -18,172 +18,172 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Install_Service { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * A {@link Wordlift_Log_Service} instance. |
|
| 23 | - * |
|
| 24 | - * @since 3.18.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 27 | - */ |
|
| 28 | - private $log; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * The singleton instance. |
|
| 32 | - * |
|
| 33 | - * @since 3.18.0 |
|
| 34 | - * @access private |
|
| 35 | - * @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance. |
|
| 36 | - */ |
|
| 37 | - private static $instance; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - private $installs; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Wordlift_Install_Service constructor. |
|
| 46 | - * |
|
| 47 | - * @since 3.18.0 |
|
| 48 | - */ |
|
| 49 | - public function __construct() { |
|
| 50 | - |
|
| 51 | - /** Installs. */ |
|
| 52 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install.php'; |
|
| 53 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-1-0-0.php'; |
|
| 54 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-10-0.php'; |
|
| 55 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-12-0.php'; |
|
| 56 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-14-0.php'; |
|
| 57 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-15-0.php'; |
|
| 58 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-0.php'; |
|
| 59 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-3.php'; |
|
| 60 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-19-5.php'; |
|
| 61 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-20-0.php'; |
|
| 62 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-23-4.php'; |
|
| 63 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-24-2.php'; |
|
| 64 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-all-entity-types.php'; |
|
| 65 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-package-type.php'; |
|
| 66 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-25-0.php'; |
|
| 67 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-0.php'; |
|
| 68 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-1.php'; |
|
| 69 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-28-0.php'; |
|
| 70 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-32-0.php'; |
|
| 71 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-33-9.php'; |
|
| 72 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-36-0.php'; |
|
| 73 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-38-5.php'; |
|
| 74 | - // Get the install services. |
|
| 75 | - $this->installs = array( |
|
| 76 | - new Wordlift_Install_1_0_0(), |
|
| 77 | - new Wordlift_Install_3_10_0(), |
|
| 78 | - new Wordlift_Install_3_12_0(), |
|
| 79 | - new Wordlift_Install_3_14_0(), |
|
| 80 | - new Wordlift_Install_3_15_0(), |
|
| 81 | - new Wordlift_Install_3_18_0(), |
|
| 82 | - new Wordlift_Install_3_18_3(), |
|
| 83 | - new Wordlift_Install_3_19_5(), |
|
| 84 | - new Wordlift_Install_3_20_0(), |
|
| 85 | - |
|
| 86 | - /* |
|
| 21 | + /** |
|
| 22 | + * A {@link Wordlift_Log_Service} instance. |
|
| 23 | + * |
|
| 24 | + * @since 3.18.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 27 | + */ |
|
| 28 | + private $log; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * The singleton instance. |
|
| 32 | + * |
|
| 33 | + * @since 3.18.0 |
|
| 34 | + * @access private |
|
| 35 | + * @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance. |
|
| 36 | + */ |
|
| 37 | + private static $instance; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + private $installs; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Wordlift_Install_Service constructor. |
|
| 46 | + * |
|
| 47 | + * @since 3.18.0 |
|
| 48 | + */ |
|
| 49 | + public function __construct() { |
|
| 50 | + |
|
| 51 | + /** Installs. */ |
|
| 52 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install.php'; |
|
| 53 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-1-0-0.php'; |
|
| 54 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-10-0.php'; |
|
| 55 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-12-0.php'; |
|
| 56 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-14-0.php'; |
|
| 57 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-15-0.php'; |
|
| 58 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-0.php'; |
|
| 59 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-3.php'; |
|
| 60 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-19-5.php'; |
|
| 61 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-20-0.php'; |
|
| 62 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-23-4.php'; |
|
| 63 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-24-2.php'; |
|
| 64 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-all-entity-types.php'; |
|
| 65 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-package-type.php'; |
|
| 66 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-25-0.php'; |
|
| 67 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-0.php'; |
|
| 68 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-1.php'; |
|
| 69 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-28-0.php'; |
|
| 70 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-32-0.php'; |
|
| 71 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-33-9.php'; |
|
| 72 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-36-0.php'; |
|
| 73 | + require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-38-5.php'; |
|
| 74 | + // Get the install services. |
|
| 75 | + $this->installs = array( |
|
| 76 | + new Wordlift_Install_1_0_0(), |
|
| 77 | + new Wordlift_Install_3_10_0(), |
|
| 78 | + new Wordlift_Install_3_12_0(), |
|
| 79 | + new Wordlift_Install_3_14_0(), |
|
| 80 | + new Wordlift_Install_3_15_0(), |
|
| 81 | + new Wordlift_Install_3_18_0(), |
|
| 82 | + new Wordlift_Install_3_18_3(), |
|
| 83 | + new Wordlift_Install_3_19_5(), |
|
| 84 | + new Wordlift_Install_3_20_0(), |
|
| 85 | + |
|
| 86 | + /* |
|
| 87 | 87 | * This should be enabled with #852. |
| 88 | 88 | */ |
| 89 | - new Wordlift_Install_Package_Type(), |
|
| 90 | - new Wordlift_Install_3_23_4(), |
|
| 91 | - new Wordlift_Install_3_24_2(), |
|
| 92 | - new Wordlift_Install_3_25_0(), |
|
| 93 | - new Wordlift_Install_3_27_0(), |
|
| 94 | - new Wordlift_Install_3_27_1(), |
|
| 95 | - new Wordlift_Install_3_28_0(), |
|
| 96 | - // Add column to represent term |
|
| 97 | - new Wordlift_Install_3_32_0(), |
|
| 98 | - // Add the entities table. |
|
| 99 | - new Wordlift_Install_3_33_9(), |
|
| 100 | - // When woocommerce extension installed, acf4so should be installed automatically. |
|
| 101 | - new Wordlift_Install_3_36_0(), |
|
| 102 | - |
|
| 103 | - new Wordlift_Install_3_38_5(), |
|
| 104 | - ); |
|
| 105 | - self::$instance = $this; |
|
| 106 | - |
|
| 107 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 108 | - |
|
| 109 | - add_action( 'init', array( $this, 'install' ) ); |
|
| 110 | - |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Get the singleton instance. |
|
| 115 | - * |
|
| 116 | - * @since 3.18.0 |
|
| 117 | - */ |
|
| 118 | - public static function get_instance() { |
|
| 119 | - |
|
| 120 | - return self::$instance; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Loop thought all versions and install the updates. |
|
| 125 | - * |
|
| 126 | - * @return void |
|
| 127 | - * @since 3.18.0 |
|
| 128 | - * |
|
| 129 | - * @since 3.20.0 use a transient to avoid concurrent installation calls. |
|
| 130 | - */ |
|
| 131 | - public function install() { |
|
| 132 | - |
|
| 133 | - $version = null; |
|
| 134 | - |
|
| 135 | - if ( $this->install_required() && false === get_transient( '_wl_installing' ) ) { |
|
| 136 | - set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS ); |
|
| 137 | - /** @var Wordlift_Install $install */ |
|
| 138 | - foreach ( $this->installs as $install ) { |
|
| 139 | - // Get the install version. |
|
| 140 | - $version = $install->get_version(); |
|
| 141 | - |
|
| 142 | - if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 143 | - || $install->must_install() ) { |
|
| 144 | - $class_name = get_class( $install ); |
|
| 145 | - |
|
| 146 | - $this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." ); |
|
| 147 | - // Install version. |
|
| 148 | - $install->install(); |
|
| 149 | - |
|
| 150 | - $this->log->info( "$class_name installed." ); |
|
| 151 | - |
|
| 152 | - // Bump the version. |
|
| 153 | - update_option( 'wl_db_version', $version ); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 158 | - @delete_transient( '_wl_installing' ); |
|
| 159 | - |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - private function install_required() { |
|
| 165 | - |
|
| 166 | - /** @var Wordlift_Install $install */ |
|
| 167 | - foreach ( $this->installs as $install ) { |
|
| 168 | - // Get the install version. |
|
| 169 | - $version = $install->get_version(); |
|
| 170 | - |
|
| 171 | - if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 172 | - || $install->must_install() ) { |
|
| 173 | - return true; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Retrieve the current db version. |
|
| 182 | - * |
|
| 183 | - * @return type |
|
| 184 | - */ |
|
| 185 | - private function get_current_version() { |
|
| 186 | - return get_option( 'wl_db_version', '0.0.0' ); |
|
| 187 | - } |
|
| 89 | + new Wordlift_Install_Package_Type(), |
|
| 90 | + new Wordlift_Install_3_23_4(), |
|
| 91 | + new Wordlift_Install_3_24_2(), |
|
| 92 | + new Wordlift_Install_3_25_0(), |
|
| 93 | + new Wordlift_Install_3_27_0(), |
|
| 94 | + new Wordlift_Install_3_27_1(), |
|
| 95 | + new Wordlift_Install_3_28_0(), |
|
| 96 | + // Add column to represent term |
|
| 97 | + new Wordlift_Install_3_32_0(), |
|
| 98 | + // Add the entities table. |
|
| 99 | + new Wordlift_Install_3_33_9(), |
|
| 100 | + // When woocommerce extension installed, acf4so should be installed automatically. |
|
| 101 | + new Wordlift_Install_3_36_0(), |
|
| 102 | + |
|
| 103 | + new Wordlift_Install_3_38_5(), |
|
| 104 | + ); |
|
| 105 | + self::$instance = $this; |
|
| 106 | + |
|
| 107 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 108 | + |
|
| 109 | + add_action( 'init', array( $this, 'install' ) ); |
|
| 110 | + |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Get the singleton instance. |
|
| 115 | + * |
|
| 116 | + * @since 3.18.0 |
|
| 117 | + */ |
|
| 118 | + public static function get_instance() { |
|
| 119 | + |
|
| 120 | + return self::$instance; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Loop thought all versions and install the updates. |
|
| 125 | + * |
|
| 126 | + * @return void |
|
| 127 | + * @since 3.18.0 |
|
| 128 | + * |
|
| 129 | + * @since 3.20.0 use a transient to avoid concurrent installation calls. |
|
| 130 | + */ |
|
| 131 | + public function install() { |
|
| 132 | + |
|
| 133 | + $version = null; |
|
| 134 | + |
|
| 135 | + if ( $this->install_required() && false === get_transient( '_wl_installing' ) ) { |
|
| 136 | + set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS ); |
|
| 137 | + /** @var Wordlift_Install $install */ |
|
| 138 | + foreach ( $this->installs as $install ) { |
|
| 139 | + // Get the install version. |
|
| 140 | + $version = $install->get_version(); |
|
| 141 | + |
|
| 142 | + if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 143 | + || $install->must_install() ) { |
|
| 144 | + $class_name = get_class( $install ); |
|
| 145 | + |
|
| 146 | + $this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." ); |
|
| 147 | + // Install version. |
|
| 148 | + $install->install(); |
|
| 149 | + |
|
| 150 | + $this->log->info( "$class_name installed." ); |
|
| 151 | + |
|
| 152 | + // Bump the version. |
|
| 153 | + update_option( 'wl_db_version', $version ); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 158 | + @delete_transient( '_wl_installing' ); |
|
| 159 | + |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + private function install_required() { |
|
| 165 | + |
|
| 166 | + /** @var Wordlift_Install $install */ |
|
| 167 | + foreach ( $this->installs as $install ) { |
|
| 168 | + // Get the install version. |
|
| 169 | + $version = $install->get_version(); |
|
| 170 | + |
|
| 171 | + if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 172 | + || $install->must_install() ) { |
|
| 173 | + return true; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Retrieve the current db version. |
|
| 182 | + * |
|
| 183 | + * @return type |
|
| 184 | + */ |
|
| 185 | + private function get_current_version() { |
|
| 186 | + return get_option( 'wl_db_version', '0.0.0' ); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | 189 | } |
@@ -49,28 +49,28 @@ discard block |
||
| 49 | 49 | public function __construct() { |
| 50 | 50 | |
| 51 | 51 | /** Installs. */ |
| 52 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install.php'; |
|
| 53 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-1-0-0.php'; |
|
| 54 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-10-0.php'; |
|
| 55 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-12-0.php'; |
|
| 56 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-14-0.php'; |
|
| 57 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-15-0.php'; |
|
| 58 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-0.php'; |
|
| 59 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-3.php'; |
|
| 60 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-19-5.php'; |
|
| 61 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-20-0.php'; |
|
| 62 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-23-4.php'; |
|
| 63 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-24-2.php'; |
|
| 64 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-all-entity-types.php'; |
|
| 65 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-package-type.php'; |
|
| 66 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-25-0.php'; |
|
| 67 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-0.php'; |
|
| 68 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-1.php'; |
|
| 69 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-28-0.php'; |
|
| 70 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-32-0.php'; |
|
| 71 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-33-9.php'; |
|
| 72 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-36-0.php'; |
|
| 73 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-38-5.php'; |
|
| 52 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install.php'; |
|
| 53 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-1-0-0.php'; |
|
| 54 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-10-0.php'; |
|
| 55 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-12-0.php'; |
|
| 56 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-14-0.php'; |
|
| 57 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-15-0.php'; |
|
| 58 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-18-0.php'; |
|
| 59 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-18-3.php'; |
|
| 60 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-19-5.php'; |
|
| 61 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-20-0.php'; |
|
| 62 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-23-4.php'; |
|
| 63 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-24-2.php'; |
|
| 64 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-all-entity-types.php'; |
|
| 65 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-package-type.php'; |
|
| 66 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-25-0.php'; |
|
| 67 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-27-0.php'; |
|
| 68 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-27-1.php'; |
|
| 69 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-28-0.php'; |
|
| 70 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-32-0.php'; |
|
| 71 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-33-9.php'; |
|
| 72 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-36-0.php'; |
|
| 73 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-38-5.php'; |
|
| 74 | 74 | // Get the install services. |
| 75 | 75 | $this->installs = array( |
| 76 | 76 | new Wordlift_Install_1_0_0(), |
@@ -104,9 +104,9 @@ discard block |
||
| 104 | 104 | ); |
| 105 | 105 | self::$instance = $this; |
| 106 | 106 | |
| 107 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 107 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
| 108 | 108 | |
| 109 | - add_action( 'init', array( $this, 'install' ) ); |
|
| 109 | + add_action('init', array($this, 'install')); |
|
| 110 | 110 | |
| 111 | 111 | } |
| 112 | 112 | |
@@ -132,30 +132,30 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | $version = null; |
| 134 | 134 | |
| 135 | - if ( $this->install_required() && false === get_transient( '_wl_installing' ) ) { |
|
| 136 | - set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS ); |
|
| 135 | + if ($this->install_required() && false === get_transient('_wl_installing')) { |
|
| 136 | + set_transient('_wl_installing', true, 5 * MINUTE_IN_SECONDS); |
|
| 137 | 137 | /** @var Wordlift_Install $install */ |
| 138 | - foreach ( $this->installs as $install ) { |
|
| 138 | + foreach ($this->installs as $install) { |
|
| 139 | 139 | // Get the install version. |
| 140 | 140 | $version = $install->get_version(); |
| 141 | 141 | |
| 142 | - if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 143 | - || $install->must_install() ) { |
|
| 144 | - $class_name = get_class( $install ); |
|
| 142 | + if (version_compare($version, $this->get_current_version(), '>') |
|
| 143 | + || $install->must_install()) { |
|
| 144 | + $class_name = get_class($install); |
|
| 145 | 145 | |
| 146 | - $this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." ); |
|
| 146 | + $this->log->info("Current version is {$this->get_current_version()}, installing $class_name..."); |
|
| 147 | 147 | // Install version. |
| 148 | 148 | $install->install(); |
| 149 | 149 | |
| 150 | - $this->log->info( "$class_name installed." ); |
|
| 150 | + $this->log->info("$class_name installed."); |
|
| 151 | 151 | |
| 152 | 152 | // Bump the version. |
| 153 | - update_option( 'wl_db_version', $version ); |
|
| 153 | + update_option('wl_db_version', $version); |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 158 | - @delete_transient( '_wl_installing' ); |
|
| 158 | + @delete_transient('_wl_installing'); |
|
| 159 | 159 | |
| 160 | 160 | } |
| 161 | 161 | |
@@ -164,12 +164,12 @@ discard block |
||
| 164 | 164 | private function install_required() { |
| 165 | 165 | |
| 166 | 166 | /** @var Wordlift_Install $install */ |
| 167 | - foreach ( $this->installs as $install ) { |
|
| 167 | + foreach ($this->installs as $install) { |
|
| 168 | 168 | // Get the install version. |
| 169 | 169 | $version = $install->get_version(); |
| 170 | 170 | |
| 171 | - if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 172 | - || $install->must_install() ) { |
|
| 171 | + if (version_compare($version, $this->get_current_version(), '>') |
|
| 172 | + || $install->must_install()) { |
|
| 173 | 173 | return true; |
| 174 | 174 | } |
| 175 | 175 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @return type |
| 184 | 184 | */ |
| 185 | 185 | private function get_current_version() { |
| 186 | - return get_option( 'wl_db_version', '0.0.0' ); |
|
| 186 | + return get_option('wl_db_version', '0.0.0'); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | } |
@@ -7,27 +7,27 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Wordlift_Install_3_38_5 extends Wordlift_Install { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * {@inheritdoc} |
|
| 12 | - */ |
|
| 13 | - protected static $version = '3.38.5'; |
|
| 10 | + /** |
|
| 11 | + * {@inheritdoc} |
|
| 12 | + */ |
|
| 13 | + protected static $version = '3.38.5'; |
|
| 14 | 14 | |
| 15 | - public function install() { |
|
| 16 | - global $wpdb; |
|
| 15 | + public function install() { |
|
| 16 | + global $wpdb; |
|
| 17 | 17 | |
| 18 | - $wpdb->query( |
|
| 19 | - $wpdb->prepare( |
|
| 20 | - "DELETE FROM $wpdb->postmeta |
|
| 18 | + $wpdb->query( |
|
| 19 | + $wpdb->prepare( |
|
| 20 | + "DELETE FROM $wpdb->postmeta |
|
| 21 | 21 | WHERE meta_key = %s |
| 22 | 22 | AND meta_value NOT LIKE '%\"@id\":%' |
| 23 | 23 | ", |
| 24 | - '_wl_main_ingredient_jsonld' |
|
| 25 | - ) |
|
| 26 | - ); |
|
| 24 | + '_wl_main_ingredient_jsonld' |
|
| 25 | + ) |
|
| 26 | + ); |
|
| 27 | 27 | |
| 28 | - // Flush the JSON-LD caches. |
|
| 29 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
| 28 | + // Flush the JSON-LD caches. |
|
| 29 | + do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
| 30 | 30 | |
| 31 | - } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | ); |
| 27 | 27 | |
| 28 | 28 | // Flush the JSON-LD caches. |
| 29 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
| 29 | + do_action('wl_ttl_cache_cleaner__flush'); |
|
| 30 | 30 | |
| 31 | 31 | } |
| 32 | 32 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | // If this file is called directly, abort. |
| 35 | 35 | if ( ! defined( 'WPINC' ) ) { |
| 36 | - die; |
|
| 36 | + die; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | define( 'WORDLIFT_VERSION', '3.38.5' ); |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @since 3.33.6 |
| 45 | 45 | */ |
| 46 | 46 | if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
| 47 | - return; |
|
| 47 | + return; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
@@ -73,29 +73,29 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | function activate_wordlift() { |
| 75 | 75 | |
| 76 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 77 | - |
|
| 78 | - $log->info( 'Activating WordLift...' ); |
|
| 79 | - |
|
| 80 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 81 | - Wordlift_Activator::activate(); |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
| 85 | - * |
|
| 86 | - * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
| 87 | - * @since 3.19.2 |
|
| 88 | - */ |
|
| 89 | - Wordlift_Http_Api::activate(); |
|
| 90 | - |
|
| 91 | - // Ensure the post type is registered before flushing the rewrite rules. |
|
| 92 | - Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 93 | - flush_rewrite_rules(); |
|
| 94 | - /** |
|
| 95 | - * @since 3.27.7 |
|
| 96 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
| 97 | - */ |
|
| 98 | - Top_Entities::activate(); |
|
| 76 | + $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 77 | + |
|
| 78 | + $log->info( 'Activating WordLift...' ); |
|
| 79 | + |
|
| 80 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 81 | + Wordlift_Activator::activate(); |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
| 85 | + * |
|
| 86 | + * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
| 87 | + * @since 3.19.2 |
|
| 88 | + */ |
|
| 89 | + Wordlift_Http_Api::activate(); |
|
| 90 | + |
|
| 91 | + // Ensure the post type is registered before flushing the rewrite rules. |
|
| 92 | + Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 93 | + flush_rewrite_rules(); |
|
| 94 | + /** |
|
| 95 | + * @since 3.27.7 |
|
| 96 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
| 97 | + */ |
|
| 98 | + Top_Entities::activate(); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -104,21 +104,21 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | function deactivate_wordlift() { |
| 106 | 106 | |
| 107 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 108 | - Wordlift_Deactivator::deactivate(); |
|
| 109 | - Wordlift_Http_Api::deactivate(); |
|
| 110 | - Ttl_Cache_Cleaner::deactivate(); |
|
| 111 | - /** |
|
| 112 | - * @since 3.27.7 |
|
| 113 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
| 114 | - */ |
|
| 115 | - Top_Entities::deactivate(); |
|
| 116 | - /** |
|
| 117 | - * @since 3.27.8 |
|
| 118 | - * Remove notification flag on deactivation. |
|
| 119 | - */ |
|
| 120 | - Key_Validation_Notice::remove_notification_flag(); |
|
| 121 | - flush_rewrite_rules(); |
|
| 107 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 108 | + Wordlift_Deactivator::deactivate(); |
|
| 109 | + Wordlift_Http_Api::deactivate(); |
|
| 110 | + Ttl_Cache_Cleaner::deactivate(); |
|
| 111 | + /** |
|
| 112 | + * @since 3.27.7 |
|
| 113 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
| 114 | + */ |
|
| 115 | + Top_Entities::deactivate(); |
|
| 116 | + /** |
|
| 117 | + * @since 3.27.8 |
|
| 118 | + * Remove notification flag on deactivation. |
|
| 119 | + */ |
|
| 120 | + Key_Validation_Notice::remove_notification_flag(); |
|
| 121 | + flush_rewrite_rules(); |
|
| 122 | 122 | |
| 123 | 123 | } |
| 124 | 124 | |
@@ -141,84 +141,84 @@ discard block |
||
| 141 | 141 | * @since 1.0.0 |
| 142 | 142 | */ |
| 143 | 143 | function run_wordlift() { |
| 144 | - /** |
|
| 145 | - * Filter: wl_feature__enable__widgets. |
|
| 146 | - * |
|
| 147 | - * @param bool whether the widgets needed to be registered, defaults to true. |
|
| 148 | - * |
|
| 149 | - * @return bool |
|
| 150 | - * @since 3.27.6 |
|
| 151 | - */ |
|
| 152 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
| 153 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
| 154 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
| 155 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
| 156 | - } |
|
| 157 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Filter: wl_feature__enable__analysis |
|
| 161 | - * |
|
| 162 | - * @param bool Whether to send api request to analysis or not |
|
| 163 | - * |
|
| 164 | - * @return bool |
|
| 165 | - * @since 3.27.6 |
|
| 166 | - */ |
|
| 167 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
| 168 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
| 169 | - } else { |
|
| 170 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - $plugin = new Wordlift(); |
|
| 174 | - $plugin->run(); |
|
| 175 | - |
|
| 176 | - // Initialize the TTL Cache Cleaner. |
|
| 177 | - new Ttl_Cache_Cleaner(); |
|
| 178 | - |
|
| 179 | - // Load the new Post Adapter. |
|
| 180 | - new Post_Adapter(); |
|
| 181 | - |
|
| 182 | - // Load the API Data Hooks. |
|
| 183 | - new Api_Data_Hooks(); |
|
| 184 | - |
|
| 185 | - add_action( |
|
| 186 | - 'plugins_loaded', |
|
| 187 | - function () { |
|
| 188 | - // All features from registry should be initialized here. |
|
| 189 | - $features_registry = Features_Registry::get_instance(); |
|
| 190 | - $features_registry->initialize_all_features(); |
|
| 191 | - }, |
|
| 192 | - 5 |
|
| 193 | - ); |
|
| 194 | - |
|
| 195 | - add_action( |
|
| 196 | - 'plugins_loaded', |
|
| 197 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
| 198 | - function () use ( $plugin ) { |
|
| 199 | - |
|
| 200 | - new Wordlift_Products_Navigator_Shortcode_REST(); |
|
| 201 | - |
|
| 202 | - // Register the Dataset module, requires `$api_service`. |
|
| 203 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
| 204 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
| 205 | - |
|
| 206 | - /* |
|
| 144 | + /** |
|
| 145 | + * Filter: wl_feature__enable__widgets. |
|
| 146 | + * |
|
| 147 | + * @param bool whether the widgets needed to be registered, defaults to true. |
|
| 148 | + * |
|
| 149 | + * @return bool |
|
| 150 | + * @since 3.27.6 |
|
| 151 | + */ |
|
| 152 | + if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
| 153 | + add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
| 154 | + add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
| 155 | + add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
| 156 | + } |
|
| 157 | + add_filter( 'widget_text', 'do_shortcode' ); |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Filter: wl_feature__enable__analysis |
|
| 161 | + * |
|
| 162 | + * @param bool Whether to send api request to analysis or not |
|
| 163 | + * |
|
| 164 | + * @return bool |
|
| 165 | + * @since 3.27.6 |
|
| 166 | + */ |
|
| 167 | + if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
| 168 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
| 169 | + } else { |
|
| 170 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + $plugin = new Wordlift(); |
|
| 174 | + $plugin->run(); |
|
| 175 | + |
|
| 176 | + // Initialize the TTL Cache Cleaner. |
|
| 177 | + new Ttl_Cache_Cleaner(); |
|
| 178 | + |
|
| 179 | + // Load the new Post Adapter. |
|
| 180 | + new Post_Adapter(); |
|
| 181 | + |
|
| 182 | + // Load the API Data Hooks. |
|
| 183 | + new Api_Data_Hooks(); |
|
| 184 | + |
|
| 185 | + add_action( |
|
| 186 | + 'plugins_loaded', |
|
| 187 | + function () { |
|
| 188 | + // All features from registry should be initialized here. |
|
| 189 | + $features_registry = Features_Registry::get_instance(); |
|
| 190 | + $features_registry->initialize_all_features(); |
|
| 191 | + }, |
|
| 192 | + 5 |
|
| 193 | + ); |
|
| 194 | + |
|
| 195 | + add_action( |
|
| 196 | + 'plugins_loaded', |
|
| 197 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
| 198 | + function () use ( $plugin ) { |
|
| 199 | + |
|
| 200 | + new Wordlift_Products_Navigator_Shortcode_REST(); |
|
| 201 | + |
|
| 202 | + // Register the Dataset module, requires `$api_service`. |
|
| 203 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
| 204 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
| 205 | + |
|
| 206 | + /* |
|
| 207 | 207 | * Require the Entity annotation cleanup module. |
| 208 | 208 | * |
| 209 | 209 | * @since 3.34.6 |
| 210 | 210 | */ |
| 211 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
| 211 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
| 212 | 212 | |
| 213 | - /* |
|
| 213 | + /* |
|
| 214 | 214 | * Import LOD entities. |
| 215 | 215 | * |
| 216 | 216 | * @since 3.35.0 |
| 217 | 217 | */ |
| 218 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
| 218 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
| 219 | 219 | |
| 220 | - } |
|
| 221 | - ); |
|
| 220 | + } |
|
| 221 | + ); |
|
| 222 | 222 | |
| 223 | 223 | } |
| 224 | 224 | |
@@ -232,45 +232,45 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | function wordlift_plugin_autoload_register() { |
| 234 | 234 | |
| 235 | - spl_autoload_register( |
|
| 236 | - function ( $class_name ) { |
|
| 235 | + spl_autoload_register( |
|
| 236 | + function ( $class_name ) { |
|
| 237 | 237 | |
| 238 | - // Bail out if these are not our classes. |
|
| 239 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
| 240 | - return false; |
|
| 241 | - } |
|
| 238 | + // Bail out if these are not our classes. |
|
| 239 | + if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
| 240 | + return false; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
| 243 | + $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
| 244 | 244 | |
| 245 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
| 245 | + preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
| 246 | 246 | |
| 247 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
| 248 | - $file = 'class-' . $matches[2] . '.php'; |
|
| 247 | + $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
| 248 | + $file = 'class-' . $matches[2] . '.php'; |
|
| 249 | 249 | |
| 250 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
| 250 | + $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
| 251 | 251 | |
| 252 | - if ( ! file_exists( $full_path ) ) { |
|
| 253 | - return false; |
|
| 254 | - } |
|
| 252 | + if ( ! file_exists( $full_path ) ) { |
|
| 253 | + return false; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - require_once $full_path; |
|
| 256 | + require_once $full_path; |
|
| 257 | 257 | |
| 258 | - return true; |
|
| 259 | - } |
|
| 260 | - ); |
|
| 258 | + return true; |
|
| 259 | + } |
|
| 260 | + ); |
|
| 261 | 261 | |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | function wl_block_categories( $categories ) { |
| 265 | - return array_merge( |
|
| 266 | - $categories, |
|
| 267 | - array( |
|
| 268 | - array( |
|
| 269 | - 'slug' => 'wordlift', |
|
| 270 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
| 271 | - ), |
|
| 272 | - ) |
|
| 273 | - ); |
|
| 265 | + return array_merge( |
|
| 266 | + $categories, |
|
| 267 | + array( |
|
| 268 | + array( |
|
| 269 | + 'slug' => 'wordlift', |
|
| 270 | + 'title' => __( 'WordLift', 'wordlift' ), |
|
| 271 | + ), |
|
| 272 | + ) |
|
| 273 | + ); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -278,19 +278,19 @@ discard block |
||
| 278 | 278 | * this has to be removed when removing the legacy fields from the ui. |
| 279 | 279 | */ |
| 280 | 280 | function wl_enqueue_leaflet( $in_footer = false ) { |
| 281 | - // Leaflet. |
|
| 282 | - wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
| 283 | - wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
| 281 | + // Leaflet. |
|
| 282 | + wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
| 283 | + wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | add_filter( 'block_categories', 'wl_block_categories', 10 ); |
| 287 | 287 | |
| 288 | 288 | // Temporary fix for a typo in WooCommerce Extension. |
| 289 | 289 | add_filter( |
| 290 | - 'wl_feature__enable__dataset', |
|
| 291 | - function ( $value ) { |
|
| 292 | - return apply_filters( 'wl_features__enable__dataset', $value ); |
|
| 293 | - } |
|
| 290 | + 'wl_feature__enable__dataset', |
|
| 291 | + function ( $value ) { |
|
| 292 | + return apply_filters( 'wl_features__enable__dataset', $value ); |
|
| 293 | + } |
|
| 294 | 294 | ); |
| 295 | 295 | |
| 296 | 296 | require_once __DIR__ . '/modules/food-kg/load.php'; |
@@ -32,22 +32,22 @@ discard block |
||
| 32 | 32 | use Wordlift\Post\Post_Adapter; |
| 33 | 33 | |
| 34 | 34 | // If this file is called directly, abort. |
| 35 | -if ( ! defined( 'WPINC' ) ) { |
|
| 35 | +if ( ! defined('WPINC')) { |
|
| 36 | 36 | die; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | -define( 'WORDLIFT_VERSION', '3.38.5' ); |
|
| 39 | +define('WORDLIFT_VERSION', '3.38.5'); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Filter to disable WLP on any request, defaults to true. |
| 43 | 43 | * |
| 44 | 44 | * @since 3.33.6 |
| 45 | 45 | */ |
| 46 | -if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
|
| 46 | +if ( ! apply_filters('wl_is_enabled', true)) { |
|
| 47 | 47 | return; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | -require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
|
| 50 | +require_once plugin_dir_path(__FILE__).'vendor/autoload.php'; |
|
| 51 | 51 | |
| 52 | 52 | /* |
| 53 | 53 | * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http. |
@@ -57,15 +57,15 @@ discard block |
||
| 57 | 57 | wordlift_plugin_autoload_register(); |
| 58 | 58 | |
| 59 | 59 | // Include WordLift constants. |
| 60 | -require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php'; |
|
| 60 | +require_once plugin_dir_path(__FILE__).'wordlift-constants.php'; |
|
| 61 | 61 | |
| 62 | 62 | // Load modules. |
| 63 | -require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php'; |
|
| 63 | +require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php'; |
|
| 64 | 64 | |
| 65 | -require_once plugin_dir_path( __FILE__ ) . 'deprecations.php'; |
|
| 65 | +require_once plugin_dir_path(__FILE__).'deprecations.php'; |
|
| 66 | 66 | |
| 67 | 67 | // Load early to enable/disable features. |
| 68 | -require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php'; |
|
| 68 | +require_once plugin_dir_path(__FILE__).'wordlift/features/index.php'; |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * The code that runs during plugin activation. |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | function activate_wordlift() { |
| 75 | 75 | |
| 76 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 76 | + $log = Wordlift_Log_Service::get_logger('activate_wordlift'); |
|
| 77 | 77 | |
| 78 | - $log->info( 'Activating WordLift...' ); |
|
| 78 | + $log->info('Activating WordLift...'); |
|
| 79 | 79 | |
| 80 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 80 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
| 81 | 81 | Wordlift_Activator::activate(); |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | function deactivate_wordlift() { |
| 106 | 106 | |
| 107 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 107 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
| 108 | 108 | Wordlift_Deactivator::deactivate(); |
| 109 | 109 | Wordlift_Http_Api::deactivate(); |
| 110 | 110 | Ttl_Cache_Cleaner::deactivate(); |
@@ -122,14 +122,14 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
| 126 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
| 125 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
| 126 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | 129 | * The core plugin class that is used to define internationalization, |
| 130 | 130 | * admin-specific hooks, and public-facing site hooks. |
| 131 | 131 | */ |
| 132 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
| 132 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | 135 | * Begins execution of the plugin. |
@@ -149,12 +149,12 @@ discard block |
||
| 149 | 149 | * @return bool |
| 150 | 150 | * @since 3.27.6 |
| 151 | 151 | */ |
| 152 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
| 153 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
| 154 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
| 155 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
| 152 | + if (apply_filters('wl_feature__enable__widgets', true)) { |
|
| 153 | + add_action('widgets_init', 'wl_register_chord_widget'); |
|
| 154 | + add_action('widgets_init', 'wl_register_geo_widget'); |
|
| 155 | + add_action('widgets_init', 'wl_register_timeline_widget'); |
|
| 156 | 156 | } |
| 157 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
| 157 | + add_filter('widget_text', 'do_shortcode'); |
|
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | 160 | * Filter: wl_feature__enable__analysis |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | * @return bool |
| 165 | 165 | * @since 3.27.6 |
| 166 | 166 | */ |
| 167 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
| 168 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
| 167 | + if (apply_filters('wl_feature__enable__analysis', true)) { |
|
| 168 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action'); |
|
| 169 | 169 | } else { |
| 170 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
| 170 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action'); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | $plugin = new Wordlift(); |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | add_action( |
| 186 | 186 | 'plugins_loaded', |
| 187 | - function () { |
|
| 187 | + function() { |
|
| 188 | 188 | // All features from registry should be initialized here. |
| 189 | 189 | $features_registry = Features_Registry::get_instance(); |
| 190 | 190 | $features_registry->initialize_all_features(); |
@@ -195,27 +195,27 @@ discard block |
||
| 195 | 195 | add_action( |
| 196 | 196 | 'plugins_loaded', |
| 197 | 197 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 198 | - function () use ( $plugin ) { |
|
| 198 | + function() use ($plugin) { |
|
| 199 | 199 | |
| 200 | 200 | new Wordlift_Products_Navigator_Shortcode_REST(); |
| 201 | 201 | |
| 202 | 202 | // Register the Dataset module, requires `$api_service`. |
| 203 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
| 204 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
| 203 | + require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php'; |
|
| 204 | + require_once plugin_dir_path(__FILE__).'wordlift/shipping-data/index.php'; |
|
| 205 | 205 | |
| 206 | 206 | /* |
| 207 | 207 | * Require the Entity annotation cleanup module. |
| 208 | 208 | * |
| 209 | 209 | * @since 3.34.6 |
| 210 | 210 | */ |
| 211 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
| 211 | + require_once plugin_dir_path(__FILE__).'wordlift/cleanup/index.php'; |
|
| 212 | 212 | |
| 213 | 213 | /* |
| 214 | 214 | * Import LOD entities. |
| 215 | 215 | * |
| 216 | 216 | * @since 3.35.0 |
| 217 | 217 | */ |
| 218 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
| 218 | + require_once plugin_dir_path(__FILE__).'wordlift/lod-import/index.php'; |
|
| 219 | 219 | |
| 220 | 220 | } |
| 221 | 221 | ); |
@@ -233,23 +233,23 @@ discard block |
||
| 233 | 233 | function wordlift_plugin_autoload_register() { |
| 234 | 234 | |
| 235 | 235 | spl_autoload_register( |
| 236 | - function ( $class_name ) { |
|
| 236 | + function($class_name) { |
|
| 237 | 237 | |
| 238 | 238 | // Bail out if these are not our classes. |
| 239 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
| 239 | + if (0 !== strpos($class_name, 'Wordlift\\')) { |
|
| 240 | 240 | return false; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
| 243 | + $class_name_lc = strtolower(str_replace('_', '-', $class_name)); |
|
| 244 | 244 | |
| 245 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
| 245 | + preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches); |
|
| 246 | 246 | |
| 247 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
| 248 | - $file = 'class-' . $matches[2] . '.php'; |
|
| 247 | + $path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]); |
|
| 248 | + $file = 'class-'.$matches[2].'.php'; |
|
| 249 | 249 | |
| 250 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
| 250 | + $full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file; |
|
| 251 | 251 | |
| 252 | - if ( ! file_exists( $full_path ) ) { |
|
| 252 | + if ( ! file_exists($full_path)) { |
|
| 253 | 253 | return false; |
| 254 | 254 | } |
| 255 | 255 | |
@@ -261,13 +261,13 @@ discard block |
||
| 261 | 261 | |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | -function wl_block_categories( $categories ) { |
|
| 264 | +function wl_block_categories($categories) { |
|
| 265 | 265 | return array_merge( |
| 266 | 266 | $categories, |
| 267 | 267 | array( |
| 268 | 268 | array( |
| 269 | 269 | 'slug' => 'wordlift', |
| 270 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
| 270 | + 'title' => __('WordLift', 'wordlift'), |
|
| 271 | 271 | ), |
| 272 | 272 | ) |
| 273 | 273 | ); |
@@ -277,22 +277,22 @@ discard block |
||
| 277 | 277 | * This function is created temporarily to handle the legacy library, |
| 278 | 278 | * this has to be removed when removing the legacy fields from the ui. |
| 279 | 279 | */ |
| 280 | -function wl_enqueue_leaflet( $in_footer = false ) { |
|
| 280 | +function wl_enqueue_leaflet($in_footer = false) { |
|
| 281 | 281 | // Leaflet. |
| 282 | - wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
| 283 | - wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
| 282 | + wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0'); |
|
| 283 | + wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | -add_filter( 'block_categories', 'wl_block_categories', 10 ); |
|
| 286 | +add_filter('block_categories', 'wl_block_categories', 10); |
|
| 287 | 287 | |
| 288 | 288 | // Temporary fix for a typo in WooCommerce Extension. |
| 289 | 289 | add_filter( |
| 290 | 290 | 'wl_feature__enable__dataset', |
| 291 | - function ( $value ) { |
|
| 292 | - return apply_filters( 'wl_features__enable__dataset', $value ); |
|
| 291 | + function($value) { |
|
| 292 | + return apply_filters('wl_features__enable__dataset', $value); |
|
| 293 | 293 | } |
| 294 | 294 | ); |
| 295 | 295 | |
| 296 | -require_once __DIR__ . '/modules/food-kg/load.php'; |
|
| 297 | -require_once __DIR__ . '/modules/acf4so/load.php'; |
|
| 298 | -require_once __DIR__ . '/modules/pods/load.php'; |
|
| 296 | +require_once __DIR__.'/modules/food-kg/load.php'; |
|
| 297 | +require_once __DIR__.'/modules/acf4so/load.php'; |
|
| 298 | +require_once __DIR__.'/modules/pods/load.php'; |
|
@@ -20,79 +20,79 @@ |
||
| 20 | 20 | use Wordlift\Task\Background\Background_Task_Route; |
| 21 | 21 | |
| 22 | 22 | if ( ! defined( 'ABSPATH' ) ) { |
| 23 | - exit; |
|
| 23 | + exit; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | define( 'WL_FOOD_KG_FILE', __FILE__ ); |
| 27 | 27 | define( 'WL_FOOD_KG_DIR_PATH', dirname( WL_FOOD_KG_FILE ) ); |
| 28 | 28 | |
| 29 | 29 | function __wl_foodkg__load() { |
| 30 | - // Autoloader for dependencies. |
|
| 31 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 32 | - require WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php'; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - // Autoloader for plugin itself. |
|
| 36 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php' ) ) { |
|
| 37 | - require WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php'; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - $container_builder = new ContainerBuilder(); |
|
| 41 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 42 | - $loader->load( 'services.yml' ); |
|
| 43 | - $container_builder->compile(); |
|
| 44 | - |
|
| 45 | - $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
| 46 | - $notices->register_hooks(); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var Preconditions $preconditions |
|
| 50 | - */ |
|
| 51 | - $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
| 52 | - if ( ! $preconditions->pass() ) { |
|
| 53 | - return; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Meta Box. |
|
| 57 | - $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
| 58 | - $meta_box->register_hooks(); |
|
| 59 | - |
|
| 60 | - $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
| 61 | - $module->register_hooks(); |
|
| 62 | - |
|
| 63 | - /** @var Jsonld $jsonld */ |
|
| 64 | - $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
| 65 | - $jsonld->register_hooks(); |
|
| 66 | - |
|
| 67 | - /** @var Main_Ingredient_Jsonld $jsonld */ |
|
| 68 | - $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
| 69 | - $main_ingredient_jsonld->register_hooks(); |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** Prepare the background task. */ |
|
| 73 | - $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
| 74 | - $task = new All_Posts_Task( |
|
| 75 | - array( |
|
| 76 | - $main_ingredient_recipe_lift, |
|
| 77 | - 'process' |
|
| 78 | - ), |
|
| 79 | - 'wprm_recipe', |
|
| 80 | - 'sync-main-ingredient' |
|
| 81 | - ); |
|
| 82 | - $background_task = Background_Task::create( $task ); |
|
| 83 | - $background_task_route = Background_Task_Route::create( $background_task, '/main-ingredient' ); |
|
| 84 | - Background_Task_Page::create( __( 'Synchronize Main Ingredient', 'wordlift' ), 'sync-main-ingredient', $background_task_route ); |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - if ( is_admin() ) { |
|
| 88 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
| 89 | - $page->register_hooks(); |
|
| 90 | - |
|
| 91 | - // Download Ingredients Data. |
|
| 92 | - $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
| 93 | - $download_ingredients_data->register_hooks(); |
|
| 94 | - |
|
| 95 | - } |
|
| 30 | + // Autoloader for dependencies. |
|
| 31 | + if ( file_exists( WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 32 | + require WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php'; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + // Autoloader for plugin itself. |
|
| 36 | + if ( file_exists( WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php' ) ) { |
|
| 37 | + require WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php'; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + $container_builder = new ContainerBuilder(); |
|
| 41 | + $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 42 | + $loader->load( 'services.yml' ); |
|
| 43 | + $container_builder->compile(); |
|
| 44 | + |
|
| 45 | + $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
| 46 | + $notices->register_hooks(); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var Preconditions $preconditions |
|
| 50 | + */ |
|
| 51 | + $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
| 52 | + if ( ! $preconditions->pass() ) { |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Meta Box. |
|
| 57 | + $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
| 58 | + $meta_box->register_hooks(); |
|
| 59 | + |
|
| 60 | + $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
| 61 | + $module->register_hooks(); |
|
| 62 | + |
|
| 63 | + /** @var Jsonld $jsonld */ |
|
| 64 | + $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
| 65 | + $jsonld->register_hooks(); |
|
| 66 | + |
|
| 67 | + /** @var Main_Ingredient_Jsonld $jsonld */ |
|
| 68 | + $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
| 69 | + $main_ingredient_jsonld->register_hooks(); |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** Prepare the background task. */ |
|
| 73 | + $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
| 74 | + $task = new All_Posts_Task( |
|
| 75 | + array( |
|
| 76 | + $main_ingredient_recipe_lift, |
|
| 77 | + 'process' |
|
| 78 | + ), |
|
| 79 | + 'wprm_recipe', |
|
| 80 | + 'sync-main-ingredient' |
|
| 81 | + ); |
|
| 82 | + $background_task = Background_Task::create( $task ); |
|
| 83 | + $background_task_route = Background_Task_Route::create( $background_task, '/main-ingredient' ); |
|
| 84 | + Background_Task_Page::create( __( 'Synchronize Main Ingredient', 'wordlift' ), 'sync-main-ingredient', $background_task_route ); |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + if ( is_admin() ) { |
|
| 88 | + $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
| 89 | + $page->register_hooks(); |
|
| 90 | + |
|
| 91 | + // Download Ingredients Data. |
|
| 92 | + $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
| 93 | + $download_ingredients_data->register_hooks(); |
|
| 94 | + |
|
| 95 | + } |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | add_action( 'plugins_loaded', '__wl_foodkg__load' ); |
@@ -19,58 +19,58 @@ discard block |
||
| 19 | 19 | use Wordlift\Task\Background\Background_Task_Page; |
| 20 | 20 | use Wordlift\Task\Background\Background_Task_Route; |
| 21 | 21 | |
| 22 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 22 | +if ( ! defined('ABSPATH')) { |
|
| 23 | 23 | exit; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | -define( 'WL_FOOD_KG_FILE', __FILE__ ); |
|
| 27 | -define( 'WL_FOOD_KG_DIR_PATH', dirname( WL_FOOD_KG_FILE ) ); |
|
| 26 | +define('WL_FOOD_KG_FILE', __FILE__); |
|
| 27 | +define('WL_FOOD_KG_DIR_PATH', dirname(WL_FOOD_KG_FILE)); |
|
| 28 | 28 | |
| 29 | 29 | function __wl_foodkg__load() { |
| 30 | 30 | // Autoloader for dependencies. |
| 31 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 32 | - require WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php'; |
|
| 31 | + if (file_exists(WL_FOOD_KG_DIR_PATH.'/third-party/vendor/scoper-autoload.php')) { |
|
| 32 | + require WL_FOOD_KG_DIR_PATH.'/third-party/vendor/scoper-autoload.php'; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | // Autoloader for plugin itself. |
| 36 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php' ) ) { |
|
| 37 | - require WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php'; |
|
| 36 | + if (file_exists(WL_FOOD_KG_DIR_PATH.'/includes/vendor/autoload.php')) { |
|
| 37 | + require WL_FOOD_KG_DIR_PATH.'/includes/vendor/autoload.php'; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $container_builder = new ContainerBuilder(); |
| 41 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 42 | - $loader->load( 'services.yml' ); |
|
| 41 | + $loader = new YamlFileLoader($container_builder, new FileLocator(__DIR__)); |
|
| 42 | + $loader->load('services.yml'); |
|
| 43 | 43 | $container_builder->compile(); |
| 44 | 44 | |
| 45 | - $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
| 45 | + $notices = $container_builder->get('Wordlift\Modules\Food_Kg\Notices'); |
|
| 46 | 46 | $notices->register_hooks(); |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * @var Preconditions $preconditions |
| 50 | 50 | */ |
| 51 | - $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
| 52 | - if ( ! $preconditions->pass() ) { |
|
| 51 | + $preconditions = $container_builder->get('Wordlift\Modules\Food_Kg\Preconditions'); |
|
| 52 | + if ( ! $preconditions->pass()) { |
|
| 53 | 53 | return; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // Meta Box. |
| 57 | - $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
| 57 | + $meta_box = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Meta_Box'); |
|
| 58 | 58 | $meta_box->register_hooks(); |
| 59 | 59 | |
| 60 | - $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
| 60 | + $module = $container_builder->get('Wordlift\Modules\Food_Kg\Module'); |
|
| 61 | 61 | $module->register_hooks(); |
| 62 | 62 | |
| 63 | 63 | /** @var Jsonld $jsonld */ |
| 64 | - $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
| 64 | + $jsonld = $container_builder->get('Wordlift\Modules\Food_Kg\Jsonld'); |
|
| 65 | 65 | $jsonld->register_hooks(); |
| 66 | 66 | |
| 67 | 67 | /** @var Main_Ingredient_Jsonld $jsonld */ |
| 68 | - $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
| 68 | + $main_ingredient_jsonld = $container_builder->get('Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld'); |
|
| 69 | 69 | $main_ingredient_jsonld->register_hooks(); |
| 70 | 70 | |
| 71 | 71 | |
| 72 | 72 | /** Prepare the background task. */ |
| 73 | - $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
| 73 | + $main_ingredient_recipe_lift = $container_builder->get('Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy'); |
|
| 74 | 74 | $task = new All_Posts_Task( |
| 75 | 75 | array( |
| 76 | 76 | $main_ingredient_recipe_lift, |
@@ -79,21 +79,21 @@ discard block |
||
| 79 | 79 | 'wprm_recipe', |
| 80 | 80 | 'sync-main-ingredient' |
| 81 | 81 | ); |
| 82 | - $background_task = Background_Task::create( $task ); |
|
| 83 | - $background_task_route = Background_Task_Route::create( $background_task, '/main-ingredient' ); |
|
| 84 | - Background_Task_Page::create( __( 'Synchronize Main Ingredient', 'wordlift' ), 'sync-main-ingredient', $background_task_route ); |
|
| 82 | + $background_task = Background_Task::create($task); |
|
| 83 | + $background_task_route = Background_Task_Route::create($background_task, '/main-ingredient'); |
|
| 84 | + Background_Task_Page::create(__('Synchronize Main Ingredient', 'wordlift'), 'sync-main-ingredient', $background_task_route); |
|
| 85 | 85 | |
| 86 | 86 | |
| 87 | - if ( is_admin() ) { |
|
| 88 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
| 87 | + if (is_admin()) { |
|
| 88 | + $page = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Page'); |
|
| 89 | 89 | $page->register_hooks(); |
| 90 | 90 | |
| 91 | 91 | // Download Ingredients Data. |
| 92 | - $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
| 92 | + $download_ingredients_data = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data'); |
|
| 93 | 93 | $download_ingredients_data->register_hooks(); |
| 94 | 94 | |
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | -add_action( 'plugins_loaded', '__wl_foodkg__load' ); |
|
| 98 | +add_action('plugins_loaded', '__wl_foodkg__load'); |
|
| 99 | 99 | |
@@ -3,43 +3,43 @@ discard block |
||
| 3 | 3 | namespace Wordlift\Modules\Food_Kg\Admin; |
| 4 | 4 | |
| 5 | 5 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 6 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 6 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | use WP_List_Table; |
| 10 | 10 | |
| 11 | 11 | class Main_Ingredient_List_Table extends WP_List_Table { |
| 12 | 12 | |
| 13 | - public function prepare_items() { |
|
| 14 | - global $wpdb; // This is used only if making any database queries |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * REQUIRED. Now we need to define our column headers. This includes a complete |
|
| 18 | - * array of columns to be displayed (slugs & titles), a list of columns |
|
| 19 | - * to keep hidden, and a list of columns that are sortable. Each of these |
|
| 20 | - * can be defined in another method (as we've done here) before being |
|
| 21 | - * used to build the value for our _column_headers property. |
|
| 22 | - */ |
|
| 23 | - $columns = $this->get_columns(); |
|
| 24 | - $hidden = array(); |
|
| 25 | - $sortable = $this->get_sortable_columns(); |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * REQUIRED. Finally, we build an array to be used by the class for column |
|
| 29 | - * headers. The $this->_column_headers property takes an array which contains |
|
| 30 | - * 3 other arrays. One for all columns, one for hidden columns, and one |
|
| 31 | - * for sortable columns. |
|
| 32 | - */ |
|
| 33 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 34 | - |
|
| 35 | - // Pagination. |
|
| 36 | - $per_page = 20; |
|
| 37 | - $current_page = $this->get_pagenum(); |
|
| 38 | - $total_items = $this->count(); |
|
| 39 | - |
|
| 40 | - $this->items = $wpdb->get_results( |
|
| 41 | - $wpdb->prepare( |
|
| 42 | - "SELECT p1.ID AS recipe_ID, |
|
| 13 | + public function prepare_items() { |
|
| 14 | + global $wpdb; // This is used only if making any database queries |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * REQUIRED. Now we need to define our column headers. This includes a complete |
|
| 18 | + * array of columns to be displayed (slugs & titles), a list of columns |
|
| 19 | + * to keep hidden, and a list of columns that are sortable. Each of these |
|
| 20 | + * can be defined in another method (as we've done here) before being |
|
| 21 | + * used to build the value for our _column_headers property. |
|
| 22 | + */ |
|
| 23 | + $columns = $this->get_columns(); |
|
| 24 | + $hidden = array(); |
|
| 25 | + $sortable = $this->get_sortable_columns(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * REQUIRED. Finally, we build an array to be used by the class for column |
|
| 29 | + * headers. The $this->_column_headers property takes an array which contains |
|
| 30 | + * 3 other arrays. One for all columns, one for hidden columns, and one |
|
| 31 | + * for sortable columns. |
|
| 32 | + */ |
|
| 33 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 34 | + |
|
| 35 | + // Pagination. |
|
| 36 | + $per_page = 20; |
|
| 37 | + $current_page = $this->get_pagenum(); |
|
| 38 | + $total_items = $this->count(); |
|
| 39 | + |
|
| 40 | + $this->items = $wpdb->get_results( |
|
| 41 | + $wpdb->prepare( |
|
| 42 | + "SELECT p1.ID AS recipe_ID, |
|
| 43 | 43 | p1.post_title AS recipe_name, |
| 44 | 44 | p2.ID AS post_ID, |
| 45 | 45 | p2.post_title, |
@@ -53,29 +53,29 @@ discard block |
||
| 53 | 53 | WHERE p1.post_type = 'wprm_recipe' |
| 54 | 54 | LIMIT %d |
| 55 | 55 | OFFSET %d", |
| 56 | - $per_page, |
|
| 57 | - ( $current_page - 1 ) * $per_page |
|
| 58 | - ) |
|
| 59 | - ); |
|
| 56 | + $per_page, |
|
| 57 | + ( $current_page - 1 ) * $per_page |
|
| 58 | + ) |
|
| 59 | + ); |
|
| 60 | 60 | |
| 61 | - $this->set_pagination_args( |
|
| 62 | - array( |
|
| 63 | - 'total_items' => $total_items, |
|
| 64 | - 'per_page' => $per_page, |
|
| 65 | - 'total_pages' => ceil( $total_items / $per_page ), |
|
| 66 | - ) |
|
| 67 | - ); |
|
| 68 | - } |
|
| 61 | + $this->set_pagination_args( |
|
| 62 | + array( |
|
| 63 | + 'total_items' => $total_items, |
|
| 64 | + 'per_page' => $per_page, |
|
| 65 | + 'total_pages' => ceil( $total_items / $per_page ), |
|
| 66 | + ) |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - private function count() { |
|
| 71 | - global $wpdb; |
|
| 70 | + private function count() { |
|
| 71 | + global $wpdb; |
|
| 72 | 72 | |
| 73 | - $count = get_transient( '_wl_main_ingredient_list_table__count' ); |
|
| 73 | + $count = get_transient( '_wl_main_ingredient_list_table__count' ); |
|
| 74 | 74 | |
| 75 | - if ( ! $count ) { |
|
| 75 | + if ( ! $count ) { |
|
| 76 | 76 | |
| 77 | - $count = $wpdb->get_var( |
|
| 78 | - "SELECT COUNT( 1 ) |
|
| 77 | + $count = $wpdb->get_var( |
|
| 78 | + "SELECT COUNT( 1 ) |
|
| 79 | 79 | FROM {$wpdb->posts} p1 |
| 80 | 80 | INNER JOIN {$wpdb->postmeta} pm1 ON pm1.post_ID = p1.ID |
| 81 | 81 | AND pm1.meta_key = '_wl_main_ingredient_jsonld' |
@@ -83,60 +83,60 @@ discard block |
||
| 83 | 83 | ON p2.post_content LIKE CONCAT( '%<!--WPRM Recipe ', p1.ID,'-->%' ) |
| 84 | 84 | AND p2.post_status = 'publish' |
| 85 | 85 | WHERE p1.post_type = 'wprm_recipe'" |
| 86 | - ); |
|
| 87 | - |
|
| 88 | - set_transient( '_wl_main_ingredient_list_table__count', $count, 60 ); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return $count; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - public function no_items() { |
|
| 95 | - esc_html_e( 'No main ingredients found.', 'wordlift' ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - public function get_columns() { |
|
| 99 | - return array( |
|
| 100 | - 'ingredient_name' => __( 'Ingredient Name', 'wordlift' ), |
|
| 101 | - 'recipe_name' => __( 'Recipe Name', 'wordlift' ), |
|
| 102 | - 'post_title' => __( 'Post Title', 'wordlift' ), |
|
| 103 | - 'url' => __( 'Post URL', 'wordlift' ), |
|
| 104 | - 'actions' => '', |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function column_ingredient_name( $item ) { |
|
| 109 | - $recipe_json_ld = get_post_meta( $item->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 110 | - $recipe = json_decode( $recipe_json_ld, true ); |
|
| 111 | - |
|
| 112 | - return $recipe ? $recipe['name'] : 'null'; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - public function column_recipe_name( $item ) { |
|
| 116 | - return $item->recipe_name; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function column_post_title( $item ) { |
|
| 120 | - return sprintf( '<a href="%s">%s</a>', get_edit_post_link( $item->post_ID ), $item->post_title ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - public function column_url( $item ) { |
|
| 124 | - return get_permalink( $item->post_ID ); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - public function column_actions( $item ) { |
|
| 128 | - |
|
| 129 | - $url = admin_url( |
|
| 130 | - sprintf( 'admin.php?page=wl_ingredients&modal_window=true&id=%d&TB_iframe=true', $item->recipe_ID ) // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 131 | - ); |
|
| 132 | - |
|
| 133 | - return sprintf( |
|
| 134 | - '<a href="%s" class="button alignright thickbox open-plugin-details-modal" data-title="%s" type="button">%s</a>', |
|
| 135 | - $url, |
|
| 136 | - esc_attr( $item->post_title ), |
|
| 137 | - esc_html__( 'JSON-LD', 'wordlift' ) |
|
| 138 | - ); |
|
| 139 | - } |
|
| 86 | + ); |
|
| 87 | + |
|
| 88 | + set_transient( '_wl_main_ingredient_list_table__count', $count, 60 ); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return $count; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + public function no_items() { |
|
| 95 | + esc_html_e( 'No main ingredients found.', 'wordlift' ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + public function get_columns() { |
|
| 99 | + return array( |
|
| 100 | + 'ingredient_name' => __( 'Ingredient Name', 'wordlift' ), |
|
| 101 | + 'recipe_name' => __( 'Recipe Name', 'wordlift' ), |
|
| 102 | + 'post_title' => __( 'Post Title', 'wordlift' ), |
|
| 103 | + 'url' => __( 'Post URL', 'wordlift' ), |
|
| 104 | + 'actions' => '', |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function column_ingredient_name( $item ) { |
|
| 109 | + $recipe_json_ld = get_post_meta( $item->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 110 | + $recipe = json_decode( $recipe_json_ld, true ); |
|
| 111 | + |
|
| 112 | + return $recipe ? $recipe['name'] : 'null'; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + public function column_recipe_name( $item ) { |
|
| 116 | + return $item->recipe_name; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function column_post_title( $item ) { |
|
| 120 | + return sprintf( '<a href="%s">%s</a>', get_edit_post_link( $item->post_ID ), $item->post_title ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + public function column_url( $item ) { |
|
| 124 | + return get_permalink( $item->post_ID ); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + public function column_actions( $item ) { |
|
| 128 | + |
|
| 129 | + $url = admin_url( |
|
| 130 | + sprintf( 'admin.php?page=wl_ingredients&modal_window=true&id=%d&TB_iframe=true', $item->recipe_ID ) // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 131 | + ); |
|
| 132 | + |
|
| 133 | + return sprintf( |
|
| 134 | + '<a href="%s" class="button alignright thickbox open-plugin-details-modal" data-title="%s" type="button">%s</a>', |
|
| 135 | + $url, |
|
| 136 | + esc_attr( $item->post_title ), |
|
| 137 | + esc_html__( 'JSON-LD', 'wordlift' ) |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | 141 | } |
| 142 | 142 | |
@@ -2,8 +2,8 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace Wordlift\Modules\Food_Kg\Admin; |
| 4 | 4 | |
| 5 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 6 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 5 | +if ( ! class_exists('WP_List_Table')) { |
|
| 6 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | use WP_List_Table; |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * 3 other arrays. One for all columns, one for hidden columns, and one |
| 31 | 31 | * for sortable columns. |
| 32 | 32 | */ |
| 33 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 33 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
| 34 | 34 | |
| 35 | 35 | // Pagination. |
| 36 | 36 | $per_page = 20; |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | LIMIT %d |
| 55 | 55 | OFFSET %d", |
| 56 | 56 | $per_page, |
| 57 | - ( $current_page - 1 ) * $per_page |
|
| 57 | + ($current_page - 1) * $per_page |
|
| 58 | 58 | ) |
| 59 | 59 | ); |
| 60 | 60 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | array( |
| 63 | 63 | 'total_items' => $total_items, |
| 64 | 64 | 'per_page' => $per_page, |
| 65 | - 'total_pages' => ceil( $total_items / $per_page ), |
|
| 65 | + 'total_pages' => ceil($total_items / $per_page), |
|
| 66 | 66 | ) |
| 67 | 67 | ); |
| 68 | 68 | } |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | private function count() { |
| 71 | 71 | global $wpdb; |
| 72 | 72 | |
| 73 | - $count = get_transient( '_wl_main_ingredient_list_table__count' ); |
|
| 73 | + $count = get_transient('_wl_main_ingredient_list_table__count'); |
|
| 74 | 74 | |
| 75 | - if ( ! $count ) { |
|
| 75 | + if ( ! $count) { |
|
| 76 | 76 | |
| 77 | 77 | $count = $wpdb->get_var( |
| 78 | 78 | "SELECT COUNT( 1 ) |
@@ -85,56 +85,56 @@ discard block |
||
| 85 | 85 | WHERE p1.post_type = 'wprm_recipe'" |
| 86 | 86 | ); |
| 87 | 87 | |
| 88 | - set_transient( '_wl_main_ingredient_list_table__count', $count, 60 ); |
|
| 88 | + set_transient('_wl_main_ingredient_list_table__count', $count, 60); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | return $count; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | public function no_items() { |
| 95 | - esc_html_e( 'No main ingredients found.', 'wordlift' ); |
|
| 95 | + esc_html_e('No main ingredients found.', 'wordlift'); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | public function get_columns() { |
| 99 | 99 | return array( |
| 100 | - 'ingredient_name' => __( 'Ingredient Name', 'wordlift' ), |
|
| 101 | - 'recipe_name' => __( 'Recipe Name', 'wordlift' ), |
|
| 102 | - 'post_title' => __( 'Post Title', 'wordlift' ), |
|
| 103 | - 'url' => __( 'Post URL', 'wordlift' ), |
|
| 100 | + 'ingredient_name' => __('Ingredient Name', 'wordlift'), |
|
| 101 | + 'recipe_name' => __('Recipe Name', 'wordlift'), |
|
| 102 | + 'post_title' => __('Post Title', 'wordlift'), |
|
| 103 | + 'url' => __('Post URL', 'wordlift'), |
|
| 104 | 104 | 'actions' => '', |
| 105 | 105 | ); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - public function column_ingredient_name( $item ) { |
|
| 109 | - $recipe_json_ld = get_post_meta( $item->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 110 | - $recipe = json_decode( $recipe_json_ld, true ); |
|
| 108 | + public function column_ingredient_name($item) { |
|
| 109 | + $recipe_json_ld = get_post_meta($item->recipe_ID, '_wl_main_ingredient_jsonld', true); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 110 | + $recipe = json_decode($recipe_json_ld, true); |
|
| 111 | 111 | |
| 112 | 112 | return $recipe ? $recipe['name'] : 'null'; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - public function column_recipe_name( $item ) { |
|
| 115 | + public function column_recipe_name($item) { |
|
| 116 | 116 | return $item->recipe_name; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - public function column_post_title( $item ) { |
|
| 120 | - return sprintf( '<a href="%s">%s</a>', get_edit_post_link( $item->post_ID ), $item->post_title ); |
|
| 119 | + public function column_post_title($item) { |
|
| 120 | + return sprintf('<a href="%s">%s</a>', get_edit_post_link($item->post_ID), $item->post_title); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - public function column_url( $item ) { |
|
| 124 | - return get_permalink( $item->post_ID ); |
|
| 123 | + public function column_url($item) { |
|
| 124 | + return get_permalink($item->post_ID); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - public function column_actions( $item ) { |
|
| 127 | + public function column_actions($item) { |
|
| 128 | 128 | |
| 129 | 129 | $url = admin_url( |
| 130 | - sprintf( 'admin.php?page=wl_ingredients&modal_window=true&id=%d&TB_iframe=true', $item->recipe_ID ) // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 130 | + sprintf('admin.php?page=wl_ingredients&modal_window=true&id=%d&TB_iframe=true', $item->recipe_ID) // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 131 | 131 | ); |
| 132 | 132 | |
| 133 | 133 | return sprintf( |
| 134 | 134 | '<a href="%s" class="button alignright thickbox open-plugin-details-modal" data-title="%s" type="button">%s</a>', |
| 135 | 135 | $url, |
| 136 | - esc_attr( $item->post_title ), |
|
| 137 | - esc_html__( 'JSON-LD', 'wordlift' ) |
|
| 136 | + esc_attr($item->post_title), |
|
| 137 | + esc_html__('JSON-LD', 'wordlift') |
|
| 138 | 138 | ); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -14,9 +14,9 @@ |
||
| 14 | 14 | </div> |
| 15 | 15 | <?php |
| 16 | 16 | |
| 17 | - // Prepare Table of elements |
|
| 18 | - $main_ingredient_list_table = new Main_Ingredient_List_Table(); |
|
| 19 | - $main_ingredient_list_table->prepare_items(); |
|
| 20 | - $main_ingredient_list_table->display(); |
|
| 21 | - ?> |
|
| 17 | + // Prepare Table of elements |
|
| 18 | + $main_ingredient_list_table = new Main_Ingredient_List_Table(); |
|
| 19 | + $main_ingredient_list_table->prepare_items(); |
|
| 20 | + $main_ingredient_list_table->display(); |
|
| 21 | + ?> |
|
| 22 | 22 | </div> |
@@ -8,9 +8,9 @@ |
||
| 8 | 8 | |
| 9 | 9 | <div class="wrap"> |
| 10 | 10 | <div class="wl-ingredients"> |
| 11 | - <h1><?php esc_html_e( 'Main Ingredients', 'wordlift' ); ?></h1> |
|
| 12 | - <a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_download_ingredients_data&_wpnonce=' . wp_create_nonce( 'wl-dl-ingredients-data-nonce' ) ) ); ?>" |
|
| 13 | - class="wl-ingredients__btn-copy-table"><?php esc_html_e( 'Download Ingredients Data', 'wordlift' ); ?></a> |
|
| 11 | + <h1><?php esc_html_e('Main Ingredients', 'wordlift'); ?></h1> |
|
| 12 | + <a href="<?php echo esc_url(admin_url('admin-ajax.php?action=wl_download_ingredients_data&_wpnonce='.wp_create_nonce('wl-dl-ingredients-data-nonce'))); ?>" |
|
| 13 | + class="wl-ingredients__btn-copy-table"><?php esc_html_e('Download Ingredients Data', 'wordlift'); ?></a> |
|
| 14 | 14 | </div> |
| 15 | 15 | <?php |
| 16 | 16 | |
@@ -4,22 +4,22 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class Download_Ingredients_Data { |
| 6 | 6 | |
| 7 | - public function register_hooks() { |
|
| 8 | - add_action( 'wp_ajax_wl_download_ingredients_data', array( $this, 'wl_download_ingredients_data' ) ); |
|
| 9 | - } |
|
| 7 | + public function register_hooks() { |
|
| 8 | + add_action( 'wp_ajax_wl_download_ingredients_data', array( $this, 'wl_download_ingredients_data' ) ); |
|
| 9 | + } |
|
| 10 | 10 | |
| 11 | - public function wl_download_ingredients_data() { |
|
| 11 | + public function wl_download_ingredients_data() { |
|
| 12 | 12 | |
| 13 | - check_ajax_referer( 'wl-dl-ingredients-data-nonce' ); |
|
| 13 | + check_ajax_referer( 'wl-dl-ingredients-data-nonce' ); |
|
| 14 | 14 | |
| 15 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 16 | - wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wordlift' ) ); |
|
| 17 | - } |
|
| 15 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 16 | + wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wordlift' ) ); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - global $wpdb; |
|
| 19 | + global $wpdb; |
|
| 20 | 20 | |
| 21 | - $items = $wpdb->get_results( |
|
| 22 | - "SELECT p1.ID AS recipe_ID, |
|
| 21 | + $items = $wpdb->get_results( |
|
| 22 | + "SELECT p1.ID AS recipe_ID, |
|
| 23 | 23 | p1.post_title AS recipe_name, |
| 24 | 24 | p2.ID AS post_ID, |
| 25 | 25 | p2.post_title, |
@@ -31,56 +31,56 @@ discard block |
||
| 31 | 31 | ON p2.post_content LIKE CONCAT( '%<!--WPRM Recipe ', p1.ID,'-->%' ) |
| 32 | 32 | AND p2.post_status = 'publish' |
| 33 | 33 | WHERE p1.post_type = 'wprm_recipe'" |
| 34 | - ); |
|
| 35 | - |
|
| 36 | - if ( ! $items ) { |
|
| 37 | - wp_send_json_error( __( 'No main ingredients found.', 'wordlift' ) ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - // Generate unique filename using current timestamp. |
|
| 41 | - $filename = 'wl-main-ingredients-data-' . gmdate( 'Y-m-d-H-i-s' ) . '.tsv'; |
|
| 42 | - |
|
| 43 | - header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
| 44 | - header( 'Content-Type: text/text/tab-separated-values; charset=' . get_bloginfo( 'charset' ) ); |
|
| 45 | - |
|
| 46 | - // Do not cache the file. |
|
| 47 | - header( 'Pragma: no-cache' ); |
|
| 48 | - header( 'Expires: 0' ); |
|
| 49 | - |
|
| 50 | - $output = fopen( 'php://output', 'w' ); |
|
| 51 | - |
|
| 52 | - // Insert Header. |
|
| 53 | - fputcsv( |
|
| 54 | - $output, |
|
| 55 | - array( |
|
| 56 | - __( 'Ingredient Name', 'wordlift' ), |
|
| 57 | - __( 'Recipe Name', 'wordlift' ), |
|
| 58 | - __( 'Recipe ID', 'wordlift' ), |
|
| 59 | - __( 'Post Name', 'wordlift' ), |
|
| 60 | - __( 'Post ID', 'wordlift' ), |
|
| 61 | - __( 'Post URL', 'wordlift' ), |
|
| 62 | - ), |
|
| 63 | - "\t" |
|
| 64 | - ); |
|
| 65 | - |
|
| 66 | - // Insert Data. |
|
| 67 | - foreach ( $items as $item ) { |
|
| 68 | - $recipe_json_ld = get_post_meta( $item->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 69 | - $recipe = json_decode( $recipe_json_ld, true ); |
|
| 70 | - fputcsv( |
|
| 71 | - $output, |
|
| 72 | - array( |
|
| 73 | - $recipe ? $recipe['name'] : 'null', |
|
| 74 | - $item->recipe_name, |
|
| 75 | - $item->recipe_ID, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 76 | - $item->post_title, |
|
| 77 | - $item->post_ID, |
|
| 78 | - esc_url( get_the_permalink( $item->post_ID ) ), |
|
| 79 | - ), |
|
| 80 | - "\t" |
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - wp_die(); |
|
| 85 | - } |
|
| 34 | + ); |
|
| 35 | + |
|
| 36 | + if ( ! $items ) { |
|
| 37 | + wp_send_json_error( __( 'No main ingredients found.', 'wordlift' ) ); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + // Generate unique filename using current timestamp. |
|
| 41 | + $filename = 'wl-main-ingredients-data-' . gmdate( 'Y-m-d-H-i-s' ) . '.tsv'; |
|
| 42 | + |
|
| 43 | + header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
| 44 | + header( 'Content-Type: text/text/tab-separated-values; charset=' . get_bloginfo( 'charset' ) ); |
|
| 45 | + |
|
| 46 | + // Do not cache the file. |
|
| 47 | + header( 'Pragma: no-cache' ); |
|
| 48 | + header( 'Expires: 0' ); |
|
| 49 | + |
|
| 50 | + $output = fopen( 'php://output', 'w' ); |
|
| 51 | + |
|
| 52 | + // Insert Header. |
|
| 53 | + fputcsv( |
|
| 54 | + $output, |
|
| 55 | + array( |
|
| 56 | + __( 'Ingredient Name', 'wordlift' ), |
|
| 57 | + __( 'Recipe Name', 'wordlift' ), |
|
| 58 | + __( 'Recipe ID', 'wordlift' ), |
|
| 59 | + __( 'Post Name', 'wordlift' ), |
|
| 60 | + __( 'Post ID', 'wordlift' ), |
|
| 61 | + __( 'Post URL', 'wordlift' ), |
|
| 62 | + ), |
|
| 63 | + "\t" |
|
| 64 | + ); |
|
| 65 | + |
|
| 66 | + // Insert Data. |
|
| 67 | + foreach ( $items as $item ) { |
|
| 68 | + $recipe_json_ld = get_post_meta( $item->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 69 | + $recipe = json_decode( $recipe_json_ld, true ); |
|
| 70 | + fputcsv( |
|
| 71 | + $output, |
|
| 72 | + array( |
|
| 73 | + $recipe ? $recipe['name'] : 'null', |
|
| 74 | + $item->recipe_name, |
|
| 75 | + $item->recipe_ID, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 76 | + $item->post_title, |
|
| 77 | + $item->post_ID, |
|
| 78 | + esc_url( get_the_permalink( $item->post_ID ) ), |
|
| 79 | + ), |
|
| 80 | + "\t" |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + wp_die(); |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -5,15 +5,15 @@ discard block |
||
| 5 | 5 | class Download_Ingredients_Data { |
| 6 | 6 | |
| 7 | 7 | public function register_hooks() { |
| 8 | - add_action( 'wp_ajax_wl_download_ingredients_data', array( $this, 'wl_download_ingredients_data' ) ); |
|
| 8 | + add_action('wp_ajax_wl_download_ingredients_data', array($this, 'wl_download_ingredients_data')); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | public function wl_download_ingredients_data() { |
| 12 | 12 | |
| 13 | - check_ajax_referer( 'wl-dl-ingredients-data-nonce' ); |
|
| 13 | + check_ajax_referer('wl-dl-ingredients-data-nonce'); |
|
| 14 | 14 | |
| 15 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 16 | - wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wordlift' ) ); |
|
| 15 | + if ( ! current_user_can('manage_options')) { |
|
| 16 | + wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'wordlift')); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | global $wpdb; |
@@ -33,40 +33,40 @@ discard block |
||
| 33 | 33 | WHERE p1.post_type = 'wprm_recipe'" |
| 34 | 34 | ); |
| 35 | 35 | |
| 36 | - if ( ! $items ) { |
|
| 37 | - wp_send_json_error( __( 'No main ingredients found.', 'wordlift' ) ); |
|
| 36 | + if ( ! $items) { |
|
| 37 | + wp_send_json_error(__('No main ingredients found.', 'wordlift')); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // Generate unique filename using current timestamp. |
| 41 | - $filename = 'wl-main-ingredients-data-' . gmdate( 'Y-m-d-H-i-s' ) . '.tsv'; |
|
| 41 | + $filename = 'wl-main-ingredients-data-'.gmdate('Y-m-d-H-i-s').'.tsv'; |
|
| 42 | 42 | |
| 43 | - header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
| 44 | - header( 'Content-Type: text/text/tab-separated-values; charset=' . get_bloginfo( 'charset' ) ); |
|
| 43 | + header('Content-Disposition: attachment; filename='.$filename); |
|
| 44 | + header('Content-Type: text/text/tab-separated-values; charset='.get_bloginfo('charset')); |
|
| 45 | 45 | |
| 46 | 46 | // Do not cache the file. |
| 47 | - header( 'Pragma: no-cache' ); |
|
| 48 | - header( 'Expires: 0' ); |
|
| 47 | + header('Pragma: no-cache'); |
|
| 48 | + header('Expires: 0'); |
|
| 49 | 49 | |
| 50 | - $output = fopen( 'php://output', 'w' ); |
|
| 50 | + $output = fopen('php://output', 'w'); |
|
| 51 | 51 | |
| 52 | 52 | // Insert Header. |
| 53 | 53 | fputcsv( |
| 54 | 54 | $output, |
| 55 | 55 | array( |
| 56 | - __( 'Ingredient Name', 'wordlift' ), |
|
| 57 | - __( 'Recipe Name', 'wordlift' ), |
|
| 58 | - __( 'Recipe ID', 'wordlift' ), |
|
| 59 | - __( 'Post Name', 'wordlift' ), |
|
| 60 | - __( 'Post ID', 'wordlift' ), |
|
| 61 | - __( 'Post URL', 'wordlift' ), |
|
| 56 | + __('Ingredient Name', 'wordlift'), |
|
| 57 | + __('Recipe Name', 'wordlift'), |
|
| 58 | + __('Recipe ID', 'wordlift'), |
|
| 59 | + __('Post Name', 'wordlift'), |
|
| 60 | + __('Post ID', 'wordlift'), |
|
| 61 | + __('Post URL', 'wordlift'), |
|
| 62 | 62 | ), |
| 63 | 63 | "\t" |
| 64 | 64 | ); |
| 65 | 65 | |
| 66 | 66 | // Insert Data. |
| 67 | - foreach ( $items as $item ) { |
|
| 68 | - $recipe_json_ld = get_post_meta( $item->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 69 | - $recipe = json_decode( $recipe_json_ld, true ); |
|
| 67 | + foreach ($items as $item) { |
|
| 68 | + $recipe_json_ld = get_post_meta($item->recipe_ID, '_wl_main_ingredient_jsonld', true); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 69 | + $recipe = json_decode($recipe_json_ld, true); |
|
| 70 | 70 | fputcsv( |
| 71 | 71 | $output, |
| 72 | 72 | array( |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $item->recipe_ID, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
| 76 | 76 | $item->post_title, |
| 77 | 77 | $item->post_ID, |
| 78 | - esc_url( get_the_permalink( $item->post_ID ) ), |
|
| 78 | + esc_url(get_the_permalink($item->post_ID)), |
|
| 79 | 79 | ), |
| 80 | 80 | "\t" |
| 81 | 81 | ); |