@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | |
15 | 15 | <?php |
16 | 16 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable |
17 | - foreach ( $this->task_ajax_adapters_registry->get_task_ajax_adapters() as $task_ajax_adapter ) { |
|
18 | - $task = $task_ajax_adapter->get_task(); |
|
19 | - ?> |
|
17 | + foreach ( $this->task_ajax_adapters_registry->get_task_ajax_adapters() as $task_ajax_adapter ) { |
|
18 | + $task = $task_ajax_adapter->get_task(); |
|
19 | + ?> |
|
20 | 20 | <div class="wl-task"> |
21 | 21 | <h2><?php esc_html( $task->get_label() ); ?></h2> |
22 | 22 | <div class="wl-task__progress" style="border: 1px solid #23282D; height: 20px; margin: 8px 0;"> |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | </div> |
35 | 35 | <?php |
36 | - } |
|
37 | - ?> |
|
36 | + } |
|
37 | + ?> |
|
38 | 38 | |
39 | 39 | </div> |
@@ -10,15 +10,15 @@ discard block |
||
10 | 10 | |
11 | 11 | ?> |
12 | 12 | <div class="wrap"> |
13 | - <h1><?php esc_html_e( 'Tasks', 'wordlift' ); ?></h1> |
|
13 | + <h1><?php esc_html_e('Tasks', 'wordlift'); ?></h1> |
|
14 | 14 | |
15 | 15 | <?php |
16 | 16 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable |
17 | - foreach ( $this->task_ajax_adapters_registry->get_task_ajax_adapters() as $task_ajax_adapter ) { |
|
17 | + foreach ($this->task_ajax_adapters_registry->get_task_ajax_adapters() as $task_ajax_adapter) { |
|
18 | 18 | $task = $task_ajax_adapter->get_task(); |
19 | 19 | ?> |
20 | 20 | <div class="wl-task"> |
21 | - <h2><?php esc_html( $task->get_label() ); ?></h2> |
|
21 | + <h2><?php esc_html($task->get_label()); ?></h2> |
|
22 | 22 | <div class="wl-task__progress" style="border: 1px solid #23282D; height: 20px; margin: 8px 0;"> |
23 | 23 | <div class="wl-task__progress__bar" |
24 | 24 | style="width:0;background: #0073AA; text-align: center; height: 100%; color: #fff;"></div> |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | <button |
28 | 28 | type="button" |
29 | 29 | class="button button-large button-primary" |
30 | - data-action="<?php echo esc_attr( $task->get_id() ); ?>" |
|
31 | - data-nonce="<?php echo esc_attr( wp_create_nonce( $task->get_id() ) ); ?>" |
|
32 | - ><?php esc_html_e( 'Start', 'wordlift' ); ?></button> |
|
30 | + data-action="<?php echo esc_attr($task->get_id()); ?>" |
|
31 | + data-nonce="<?php echo esc_attr(wp_create_nonce($task->get_id())); ?>" |
|
32 | + ><?php esc_html_e('Start', 'wordlift'); ?></button> |
|
33 | 33 | |
34 | 34 | </div> |
35 | 35 | <?php |
@@ -17,72 +17,72 @@ |
||
17 | 17 | |
18 | 18 | class Tasks_Page extends Submenu_Page_Base { |
19 | 19 | |
20 | - /** |
|
21 | - * The ID of this admin page. |
|
22 | - * |
|
23 | - * @since 1.0.0 |
|
24 | - * @access private |
|
25 | - * @var string $menu_slug The ID of this page. |
|
26 | - */ |
|
27 | - private $menu_slug = 'wl_tasks_page'; |
|
20 | + /** |
|
21 | + * The ID of this admin page. |
|
22 | + * |
|
23 | + * @since 1.0.0 |
|
24 | + * @access private |
|
25 | + * @var string $menu_slug The ID of this page. |
|
26 | + */ |
|
27 | + private $menu_slug = 'wl_tasks_page'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Used when enqueueing styles or scripts as the version string. |
|
31 | - * |
|
32 | - * @since 1.0.0 |
|
33 | - * @access private |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - private $asset_version = '1.0.0'; |
|
29 | + /** |
|
30 | + * Used when enqueueing styles or scripts as the version string. |
|
31 | + * |
|
32 | + * @since 1.0.0 |
|
33 | + * @access private |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + private $asset_version = '1.0.0'; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var Task_Ajax_Adapters_Registry |
|
40 | - */ |
|
41 | - private $task_ajax_adapters_registry; |
|
38 | + /** |
|
39 | + * @var Task_Ajax_Adapters_Registry |
|
40 | + */ |
|
41 | + private $task_ajax_adapters_registry; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Define the {@link Wordlift_Admin_Page} constructor. |
|
45 | - * |
|
46 | - * @param Task_Ajax_Adapters_Registry $task_ajax_adapters_registry |
|
47 | - * |
|
48 | - * @since 1.0.0 |
|
49 | - */ |
|
50 | - public function __construct( $task_ajax_adapters_registry ) { |
|
51 | - parent::__construct( $this->menu_slug, __( 'Tasks', 'wordlift' ), 'manage_options', 'wl_admin_menu', __( 'Tasks', 'wordlift' ) ); |
|
43 | + /** |
|
44 | + * Define the {@link Wordlift_Admin_Page} constructor. |
|
45 | + * |
|
46 | + * @param Task_Ajax_Adapters_Registry $task_ajax_adapters_registry |
|
47 | + * |
|
48 | + * @since 1.0.0 |
|
49 | + */ |
|
50 | + public function __construct( $task_ajax_adapters_registry ) { |
|
51 | + parent::__construct( $this->menu_slug, __( 'Tasks', 'wordlift' ), 'manage_options', 'wl_admin_menu', __( 'Tasks', 'wordlift' ) ); |
|
52 | 52 | |
53 | - $this->task_ajax_adapters_registry = $task_ajax_adapters_registry; |
|
53 | + $this->task_ajax_adapters_registry = $task_ajax_adapters_registry; |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Register the stylesheets and scripts for the admin area. |
|
59 | - * |
|
60 | - * @since 1.0.0 |
|
61 | - */ |
|
62 | - public function enqueue_scripts() { |
|
63 | - wp_enqueue_style( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.css', array(), $this->asset_version, 'all' ); |
|
64 | - wp_enqueue_script( |
|
65 | - $this->menu_slug, |
|
66 | - plugin_dir_url( __FILE__ ) . 'assets/tasks-page.js', |
|
67 | - array( |
|
68 | - 'jquery', |
|
69 | - 'wp-util', |
|
70 | - ), |
|
71 | - $this->asset_version, |
|
72 | - true |
|
73 | - ); |
|
74 | - } |
|
57 | + /** |
|
58 | + * Register the stylesheets and scripts for the admin area. |
|
59 | + * |
|
60 | + * @since 1.0.0 |
|
61 | + */ |
|
62 | + public function enqueue_scripts() { |
|
63 | + wp_enqueue_style( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.css', array(), $this->asset_version, 'all' ); |
|
64 | + wp_enqueue_script( |
|
65 | + $this->menu_slug, |
|
66 | + plugin_dir_url( __FILE__ ) . 'assets/tasks-page.js', |
|
67 | + array( |
|
68 | + 'jquery', |
|
69 | + 'wp-util', |
|
70 | + ), |
|
71 | + $this->asset_version, |
|
72 | + true |
|
73 | + ); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Render the page. |
|
78 | - * |
|
79 | - * @since 1.0.0 |
|
80 | - */ |
|
81 | - public function render() { |
|
76 | + /** |
|
77 | + * Render the page. |
|
78 | + * |
|
79 | + * @since 1.0.0 |
|
80 | + */ |
|
81 | + public function render() { |
|
82 | 82 | |
83 | - // Include the partial. |
|
84 | - include plugin_dir_path( __FILE__ ) . 'assets/tasks-page.php'; |
|
83 | + // Include the partial. |
|
84 | + include plugin_dir_path( __FILE__ ) . 'assets/tasks-page.php'; |
|
85 | 85 | |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @since 1.0.0 |
49 | 49 | */ |
50 | - public function __construct( $task_ajax_adapters_registry ) { |
|
51 | - parent::__construct( $this->menu_slug, __( 'Tasks', 'wordlift' ), 'manage_options', 'wl_admin_menu', __( 'Tasks', 'wordlift' ) ); |
|
50 | + public function __construct($task_ajax_adapters_registry) { |
|
51 | + parent::__construct($this->menu_slug, __('Tasks', 'wordlift'), 'manage_options', 'wl_admin_menu', __('Tasks', 'wordlift')); |
|
52 | 52 | |
53 | 53 | $this->task_ajax_adapters_registry = $task_ajax_adapters_registry; |
54 | 54 | |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | * @since 1.0.0 |
61 | 61 | */ |
62 | 62 | public function enqueue_scripts() { |
63 | - wp_enqueue_style( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.css', array(), $this->asset_version, 'all' ); |
|
63 | + wp_enqueue_style($this->menu_slug, plugin_dir_url(__FILE__).'assets/tasks-page.css', array(), $this->asset_version, 'all'); |
|
64 | 64 | wp_enqueue_script( |
65 | 65 | $this->menu_slug, |
66 | - plugin_dir_url( __FILE__ ) . 'assets/tasks-page.js', |
|
66 | + plugin_dir_url(__FILE__).'assets/tasks-page.js', |
|
67 | 67 | array( |
68 | 68 | 'jquery', |
69 | 69 | 'wp-util', |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | public function render() { |
82 | 82 | |
83 | 83 | // Include the partial. |
84 | - include plugin_dir_path( __FILE__ ) . 'assets/tasks-page.php'; |
|
84 | + include plugin_dir_path(__FILE__).'assets/tasks-page.php'; |
|
85 | 85 | |
86 | 86 | } |
87 | 87 |
@@ -15,15 +15,15 @@ |
||
15 | 15 | */ |
16 | 16 | interface Task_Runner { |
17 | 17 | |
18 | - /** |
|
19 | - * Start the task. |
|
20 | - * |
|
21 | - * @param int $limit The maximum number of items to process. |
|
22 | - * @param int $offset The starting offset (zero-based). |
|
23 | - * |
|
24 | - * @return mixed |
|
25 | - * @since 1.0.0 |
|
26 | - */ |
|
27 | - public function start( $limit = 0, $offset = 0 ); |
|
18 | + /** |
|
19 | + * Start the task. |
|
20 | + * |
|
21 | + * @param int $limit The maximum number of items to process. |
|
22 | + * @param int $offset The starting offset (zero-based). |
|
23 | + * |
|
24 | + * @return mixed |
|
25 | + * @since 1.0.0 |
|
26 | + */ |
|
27 | + public function start( $limit = 0, $offset = 0 ); |
|
28 | 28 | |
29 | 29 | } |
@@ -24,6 +24,6 @@ |
||
24 | 24 | * @return mixed |
25 | 25 | * @since 1.0.0 |
26 | 26 | */ |
27 | - public function start( $limit = 0, $offset = 0 ); |
|
27 | + public function start($limit = 0, $offset = 0); |
|
28 | 28 | |
29 | 29 | } |
@@ -16,30 +16,30 @@ |
||
16 | 16 | */ |
17 | 17 | interface Task_Progress { |
18 | 18 | |
19 | - /** |
|
20 | - * The total number of elements to process. |
|
21 | - * |
|
22 | - * @param int $value The total number of elements to process. |
|
23 | - * |
|
24 | - * @since 1.0.0 |
|
25 | - */ |
|
26 | - public function set_count( $value ); |
|
19 | + /** |
|
20 | + * The total number of elements to process. |
|
21 | + * |
|
22 | + * @param int $value The total number of elements to process. |
|
23 | + * |
|
24 | + * @since 1.0.0 |
|
25 | + */ |
|
26 | + public function set_count( $value ); |
|
27 | 27 | |
28 | - /** |
|
29 | - * Set the current processed item. |
|
30 | - * |
|
31 | - * @param int $counter The current item. |
|
32 | - * @param mixed $item The current item. |
|
33 | - * |
|
34 | - * @since 1.0.0 |
|
35 | - */ |
|
36 | - public function set_progress( $counter, $item ); |
|
28 | + /** |
|
29 | + * Set the current processed item. |
|
30 | + * |
|
31 | + * @param int $counter The current item. |
|
32 | + * @param mixed $item The current item. |
|
33 | + * |
|
34 | + * @since 1.0.0 |
|
35 | + */ |
|
36 | + public function set_progress( $counter, $item ); |
|
37 | 37 | |
38 | - /** |
|
39 | - * Set the operation as complete. |
|
40 | - * |
|
41 | - * @since 1.0.0 |
|
42 | - */ |
|
43 | - public function finish(); |
|
38 | + /** |
|
39 | + * Set the operation as complete. |
|
40 | + * |
|
41 | + * @since 1.0.0 |
|
42 | + */ |
|
43 | + public function finish(); |
|
44 | 44 | |
45 | 45 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @since 1.0.0 |
25 | 25 | */ |
26 | - public function set_count( $value ); |
|
26 | + public function set_count($value); |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Set the current processed item. |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @since 1.0.0 |
35 | 35 | */ |
36 | - public function set_progress( $counter, $item ); |
|
36 | + public function set_progress($counter, $item); |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Set the operation as complete. |
@@ -16,64 +16,64 @@ |
||
16 | 16 | */ |
17 | 17 | class Task_Ajax_Adapter { |
18 | 18 | |
19 | - /** |
|
20 | - * @var Task |
|
21 | - */ |
|
22 | - private $task; |
|
19 | + /** |
|
20 | + * @var Task |
|
21 | + */ |
|
22 | + private $task; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var string $action_name The action name. |
|
26 | - */ |
|
27 | - private $action_name; |
|
24 | + /** |
|
25 | + * @var string $action_name The action name. |
|
26 | + */ |
|
27 | + private $action_name; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Task_Ajax_Adapter constructor. |
|
31 | - * |
|
32 | - * @param Task $task |
|
33 | - */ |
|
34 | - public function __construct( $task ) { |
|
29 | + /** |
|
30 | + * Task_Ajax_Adapter constructor. |
|
31 | + * |
|
32 | + * @param Task $task |
|
33 | + */ |
|
34 | + public function __construct( $task ) { |
|
35 | 35 | |
36 | - $this->task = $task; |
|
36 | + $this->task = $task; |
|
37 | 37 | |
38 | - $this->action_name = $task->get_id(); |
|
39 | - add_action( 'wp_ajax_' . $this->action_name, array( $this, 'start' ) ); |
|
38 | + $this->action_name = $task->get_id(); |
|
39 | + add_action( 'wp_ajax_' . $this->action_name, array( $this, 'start' ) ); |
|
40 | 40 | |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - public function start() { |
|
43 | + public function start() { |
|
44 | 44 | |
45 | - // First check if there is a valid nonce. |
|
46 | - check_ajax_referer( $this->action_name ); |
|
45 | + // First check if there is a valid nonce. |
|
46 | + check_ajax_referer( $this->action_name ); |
|
47 | 47 | |
48 | - // Get the offset. |
|
49 | - $offset = filter_input( INPUT_POST, 'offset', FILTER_SANITIZE_NUMBER_INT ); |
|
50 | - $offset = $offset ? $offset : 0; |
|
48 | + // Get the offset. |
|
49 | + $offset = filter_input( INPUT_POST, 'offset', FILTER_SANITIZE_NUMBER_INT ); |
|
50 | + $offset = $offset ? $offset : 0; |
|
51 | 51 | |
52 | - // Compatibility fix for FacetWP, which somewhere in some filter checks for the $_POST array. |
|
53 | - unset( $_POST['offset'] ); |
|
52 | + // Compatibility fix for FacetWP, which somewhere in some filter checks for the $_POST array. |
|
53 | + unset( $_POST['offset'] ); |
|
54 | 54 | |
55 | - // Create an AJAX progress. The AJAX progress returns the progress data to the AJAX client, which |
|
56 | - // in turn calls the next batch. |
|
57 | - $ajax_progress = new Task_Ajax_Progress( $this->action_name ); |
|
55 | + // Create an AJAX progress. The AJAX progress returns the progress data to the AJAX client, which |
|
56 | + // in turn calls the next batch. |
|
57 | + $ajax_progress = new Task_Ajax_Progress( $this->action_name ); |
|
58 | 58 | |
59 | - // Finally create the task runner and start it. |
|
60 | - $task_runner = new Task_Single_Instance_Task_Runner( $this->task, true, array( $ajax_progress ) ); |
|
59 | + // Finally create the task runner and start it. |
|
60 | + $task_runner = new Task_Single_Instance_Task_Runner( $this->task, true, array( $ajax_progress ) ); |
|
61 | 61 | |
62 | - try { |
|
63 | - // Start the task runner, 1 item at a time. |
|
64 | - $task_runner->start( 1, $offset ); |
|
65 | - } catch ( Task_Another_Instance_Is_Running_Exception $e ) { |
|
66 | - wp_send_json_error( 'A task is already running.' ); |
|
67 | - } |
|
62 | + try { |
|
63 | + // Start the task runner, 1 item at a time. |
|
64 | + $task_runner->start( 1, $offset ); |
|
65 | + } catch ( Task_Another_Instance_Is_Running_Exception $e ) { |
|
66 | + wp_send_json_error( 'A task is already running.' ); |
|
67 | + } |
|
68 | 68 | |
69 | - } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @return Task |
|
73 | - */ |
|
74 | - public function get_task() { |
|
71 | + /** |
|
72 | + * @return Task |
|
73 | + */ |
|
74 | + public function get_task() { |
|
75 | 75 | |
76 | - return $this->task; |
|
77 | - } |
|
76 | + return $this->task; |
|
77 | + } |
|
78 | 78 | |
79 | 79 | } |
@@ -31,39 +31,39 @@ |
||
31 | 31 | * |
32 | 32 | * @param Task $task |
33 | 33 | */ |
34 | - public function __construct( $task ) { |
|
34 | + public function __construct($task) { |
|
35 | 35 | |
36 | 36 | $this->task = $task; |
37 | 37 | |
38 | 38 | $this->action_name = $task->get_id(); |
39 | - add_action( 'wp_ajax_' . $this->action_name, array( $this, 'start' ) ); |
|
39 | + add_action('wp_ajax_'.$this->action_name, array($this, 'start')); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
43 | 43 | public function start() { |
44 | 44 | |
45 | 45 | // First check if there is a valid nonce. |
46 | - check_ajax_referer( $this->action_name ); |
|
46 | + check_ajax_referer($this->action_name); |
|
47 | 47 | |
48 | 48 | // Get the offset. |
49 | - $offset = filter_input( INPUT_POST, 'offset', FILTER_SANITIZE_NUMBER_INT ); |
|
49 | + $offset = filter_input(INPUT_POST, 'offset', FILTER_SANITIZE_NUMBER_INT); |
|
50 | 50 | $offset = $offset ? $offset : 0; |
51 | 51 | |
52 | 52 | // Compatibility fix for FacetWP, which somewhere in some filter checks for the $_POST array. |
53 | - unset( $_POST['offset'] ); |
|
53 | + unset($_POST['offset']); |
|
54 | 54 | |
55 | 55 | // Create an AJAX progress. The AJAX progress returns the progress data to the AJAX client, which |
56 | 56 | // in turn calls the next batch. |
57 | - $ajax_progress = new Task_Ajax_Progress( $this->action_name ); |
|
57 | + $ajax_progress = new Task_Ajax_Progress($this->action_name); |
|
58 | 58 | |
59 | 59 | // Finally create the task runner and start it. |
60 | - $task_runner = new Task_Single_Instance_Task_Runner( $this->task, true, array( $ajax_progress ) ); |
|
60 | + $task_runner = new Task_Single_Instance_Task_Runner($this->task, true, array($ajax_progress)); |
|
61 | 61 | |
62 | 62 | try { |
63 | 63 | // Start the task runner, 1 item at a time. |
64 | - $task_runner->start( 1, $offset ); |
|
65 | - } catch ( Task_Another_Instance_Is_Running_Exception $e ) { |
|
66 | - wp_send_json_error( 'A task is already running.' ); |
|
64 | + $task_runner->start(1, $offset); |
|
65 | + } catch (Task_Another_Instance_Is_Running_Exception $e) { |
|
66 | + wp_send_json_error('A task is already running.'); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | } |
@@ -18,86 +18,86 @@ |
||
18 | 18 | */ |
19 | 19 | class Task_Ajax_Progress implements Task_Progress { |
20 | 20 | |
21 | - /** |
|
22 | - * The AJAX action, used to generate new nonces. |
|
23 | - * |
|
24 | - * @since 1.0.0 |
|
25 | - * @access private |
|
26 | - * @var string $action The AJAX action. |
|
27 | - */ |
|
28 | - private $action; |
|
29 | - |
|
30 | - /** |
|
31 | - * The total number of items to process. |
|
32 | - * |
|
33 | - * @since 1.0.0 |
|
34 | - * @access private |
|
35 | - * @var int The total number of items to process. |
|
36 | - */ |
|
37 | - private $count; |
|
38 | - |
|
39 | - /** |
|
40 | - * The current item index. |
|
41 | - * |
|
42 | - * @since 1.0.0 |
|
43 | - * @access private |
|
44 | - * @var int $index The current item index. |
|
45 | - */ |
|
46 | - private $index; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var Wordlift_Log_Service |
|
50 | - */ |
|
51 | - private $log; |
|
52 | - |
|
53 | - /** |
|
54 | - * Create a Task_Ajax_Progress instance with the specified |
|
55 | - * AJAX action. |
|
56 | - * |
|
57 | - * @param string $action The AJAX action. |
|
58 | - * |
|
59 | - * @since 1.0.0 |
|
60 | - */ |
|
61 | - public function __construct( $action ) { |
|
62 | - |
|
63 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
64 | - |
|
65 | - $this->action = $action; |
|
66 | - |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * {@inheritDoc} |
|
71 | - */ |
|
72 | - public function set_count( $value ) { |
|
73 | - |
|
74 | - $this->log->debug( "New count $value for action $this->action..." ); |
|
75 | - |
|
76 | - $this->count = $value; |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * {@inheritDoc} |
|
82 | - */ |
|
83 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
84 | - public function set_progress( $index, $item ) { |
|
85 | - $this->index = $index; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * {@inheritDoc} |
|
90 | - */ |
|
91 | - public function finish() { |
|
92 | - wp_send_json_success( |
|
93 | - array( |
|
94 | - 'count' => $this->count, |
|
95 | - 'index' => $this->index, |
|
96 | - // $this->index is zero based. |
|
97 | - 'complete' => $this->index >= $this->count - 1, |
|
98 | - 'nonce' => wp_create_nonce( $this->action ), |
|
99 | - ) |
|
100 | - ); |
|
101 | - } |
|
21 | + /** |
|
22 | + * The AJAX action, used to generate new nonces. |
|
23 | + * |
|
24 | + * @since 1.0.0 |
|
25 | + * @access private |
|
26 | + * @var string $action The AJAX action. |
|
27 | + */ |
|
28 | + private $action; |
|
29 | + |
|
30 | + /** |
|
31 | + * The total number of items to process. |
|
32 | + * |
|
33 | + * @since 1.0.0 |
|
34 | + * @access private |
|
35 | + * @var int The total number of items to process. |
|
36 | + */ |
|
37 | + private $count; |
|
38 | + |
|
39 | + /** |
|
40 | + * The current item index. |
|
41 | + * |
|
42 | + * @since 1.0.0 |
|
43 | + * @access private |
|
44 | + * @var int $index The current item index. |
|
45 | + */ |
|
46 | + private $index; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var Wordlift_Log_Service |
|
50 | + */ |
|
51 | + private $log; |
|
52 | + |
|
53 | + /** |
|
54 | + * Create a Task_Ajax_Progress instance with the specified |
|
55 | + * AJAX action. |
|
56 | + * |
|
57 | + * @param string $action The AJAX action. |
|
58 | + * |
|
59 | + * @since 1.0.0 |
|
60 | + */ |
|
61 | + public function __construct( $action ) { |
|
62 | + |
|
63 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
64 | + |
|
65 | + $this->action = $action; |
|
66 | + |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * {@inheritDoc} |
|
71 | + */ |
|
72 | + public function set_count( $value ) { |
|
73 | + |
|
74 | + $this->log->debug( "New count $value for action $this->action..." ); |
|
75 | + |
|
76 | + $this->count = $value; |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * {@inheritDoc} |
|
82 | + */ |
|
83 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
84 | + public function set_progress( $index, $item ) { |
|
85 | + $this->index = $index; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * {@inheritDoc} |
|
90 | + */ |
|
91 | + public function finish() { |
|
92 | + wp_send_json_success( |
|
93 | + array( |
|
94 | + 'count' => $this->count, |
|
95 | + 'index' => $this->index, |
|
96 | + // $this->index is zero based. |
|
97 | + 'complete' => $this->index >= $this->count - 1, |
|
98 | + 'nonce' => wp_create_nonce( $this->action ), |
|
99 | + ) |
|
100 | + ); |
|
101 | + } |
|
102 | 102 | |
103 | 103 | } |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @since 1.0.0 |
60 | 60 | */ |
61 | - public function __construct( $action ) { |
|
61 | + public function __construct($action) { |
|
62 | 62 | |
63 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
63 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
64 | 64 | |
65 | 65 | $this->action = $action; |
66 | 66 | |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | /** |
70 | 70 | * {@inheritDoc} |
71 | 71 | */ |
72 | - public function set_count( $value ) { |
|
72 | + public function set_count($value) { |
|
73 | 73 | |
74 | - $this->log->debug( "New count $value for action $this->action..." ); |
|
74 | + $this->log->debug("New count $value for action $this->action..."); |
|
75 | 75 | |
76 | 76 | $this->count = $value; |
77 | 77 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * {@inheritDoc} |
82 | 82 | */ |
83 | 83 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
84 | - public function set_progress( $index, $item ) { |
|
84 | + public function set_progress($index, $item) { |
|
85 | 85 | $this->index = $index; |
86 | 86 | } |
87 | 87 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | 'index' => $this->index, |
96 | 96 | // $this->index is zero based. |
97 | 97 | 'complete' => $this->index >= $this->count - 1, |
98 | - 'nonce' => wp_create_nonce( $this->action ), |
|
98 | + 'nonce' => wp_create_nonce($this->action), |
|
99 | 99 | ) |
100 | 100 | ); |
101 | 101 | } |
@@ -19,13 +19,13 @@ discard block |
||
19 | 19 | * @package Wordlift |
20 | 20 | */ |
21 | 21 | class Wordlift_Metabox_Field_Integer extends Wl_Metabox_Field { |
22 | - /** |
|
23 | - * @inheritdoc |
|
24 | - */ |
|
25 | - public function html_input( $text ) { |
|
22 | + /** |
|
23 | + * @inheritdoc |
|
24 | + */ |
|
25 | + public function html_input( $text ) { |
|
26 | 26 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
27 | - @ob_start(); |
|
28 | - ?> |
|
27 | + @ob_start(); |
|
28 | + ?> |
|
29 | 29 | <div class="wl-input-wrapper"> |
30 | 30 | <input |
31 | 31 | type="number" |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | </div> |
46 | 46 | |
47 | 47 | <?php |
48 | - $html = ob_get_clean(); |
|
48 | + $html = ob_get_clean(); |
|
49 | 49 | |
50 | - return $html; |
|
51 | - } |
|
50 | + return $html; |
|
51 | + } |
|
52 | 52 | } |
@@ -22,23 +22,23 @@ |
||
22 | 22 | /** |
23 | 23 | * @inheritdoc |
24 | 24 | */ |
25 | - public function html_input( $text ) { |
|
25 | + public function html_input($text) { |
|
26 | 26 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
27 | 27 | @ob_start(); |
28 | 28 | ?> |
29 | 29 | <div class="wl-input-wrapper"> |
30 | 30 | <input |
31 | 31 | type="number" |
32 | - id="<?php echo esc_attr( $this->meta_name ); ?>" |
|
33 | - class="<?php echo esc_attr( $this->meta_name ); ?>" |
|
34 | - value="<?php echo esc_attr( $text ); ?>" |
|
35 | - name="wl_metaboxes[<?php echo esc_attr( $this->meta_name ); ?>][]" |
|
32 | + id="<?php echo esc_attr($this->meta_name); ?>" |
|
33 | + class="<?php echo esc_attr($this->meta_name); ?>" |
|
34 | + value="<?php echo esc_attr($text); ?>" |
|
35 | + name="wl_metaboxes[<?php echo esc_attr($this->meta_name); ?>][]" |
|
36 | 36 | style="width:88%" |
37 | 37 | min="0" |
38 | 38 | /> |
39 | 39 | |
40 | 40 | <button class="button wl-remove-input wl-button" type="button"> |
41 | - <?php esc_html_e( 'Remove', 'wordlift' ); ?> |
|
41 | + <?php esc_html_e('Remove', 'wordlift'); ?> |
|
42 | 42 | </button> |
43 | 43 | |
44 | 44 | <div class="wl-input-notice"></div> |
@@ -21,140 +21,140 @@ discard block |
||
21 | 21 | // phpcs:ignore PEAR.NamingConventions.ValidClassName.Invalid |
22 | 22 | class Wl_Metabox_Field_uri extends Wl_Metabox_Field { |
23 | 23 | |
24 | - /** |
|
25 | - * Only accept URIs or local entity IDs. |
|
26 | - * Build new entity if the user inputted a name that is not present in DB. |
|
27 | - * |
|
28 | - * @param mixed $value The value to sanitize. |
|
29 | - * |
|
30 | - * @return int|mixed|WP_Error |
|
31 | - */ |
|
32 | - public function sanitize_data_filter( $value ) { |
|
33 | - |
|
34 | - if ( empty( $value ) ) { |
|
35 | - return null; |
|
36 | - } |
|
37 | - |
|
38 | - // Check that the inserted URI, ID or name does not point to a saved |
|
39 | - // entity or when the editor types a string in the input box, we try to |
|
40 | - // find an entity with that title and, if not found, we create that entity. |
|
41 | - $absent_from_db = is_numeric( $value ) |
|
42 | - ? get_post( $value ) === null |
|
43 | - : ! $this->exists( $value ); |
|
44 | - |
|
45 | - // Is it an URI? |
|
46 | - $name_is_uri = strpos( $value, 'http' ) === 0; |
|
47 | - |
|
48 | - // We create a new entity only if the entity is not present in the DB. |
|
49 | - // In the case of an external uri, we just save the uri. |
|
50 | - if ( $absent_from_db && ! $name_is_uri ) { |
|
51 | - |
|
52 | - // ...we create a new entity! |
|
53 | - $new_entity_id = wp_insert_post( |
|
54 | - array( |
|
55 | - 'post_status' => 'publish', |
|
56 | - 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
57 | - 'post_title' => $value, |
|
58 | - ) |
|
59 | - ); |
|
60 | - |
|
61 | - $type = 'http://schema.org/' . ( isset( $this->expected_uri_type ) ? $this->expected_uri_type[0] : 'Thing' ); |
|
62 | - |
|
63 | - wl_set_entity_main_type( $new_entity_id, $type ); |
|
64 | - |
|
65 | - // Update the value that will be saved as meta. |
|
66 | - $value = $new_entity_id; |
|
67 | - } |
|
68 | - |
|
69 | - return $value; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Check whether an entity exists given a value. |
|
74 | - * |
|
75 | - * @param string $value An entity URI or a title string.. |
|
76 | - * |
|
77 | - * @return bool True if the entity exists otherwise false. |
|
78 | - * @since 3.15.0 |
|
79 | - */ |
|
80 | - private function exists( $value ) { |
|
81 | - |
|
82 | - // When the editor types a string in the input box, we try to find |
|
83 | - // an entity with that title and, if not found, we create that entity. |
|
84 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
85 | - |
|
86 | - // Try looking for an entity by URI. |
|
87 | - $found_by_uri = null !== $entity_service->get_entity_post_by_uri( $value ); |
|
88 | - |
|
89 | - // Return true if found. |
|
90 | - if ( $found_by_uri ) { |
|
91 | - $this->log->debug( "Found entity for $value." ); |
|
92 | - |
|
93 | - return true; |
|
94 | - } |
|
95 | - |
|
96 | - // Try looking for an entity by title, get any potential candidate. |
|
97 | - $candidate = get_page_by_title( $value, OBJECT, Wordlift_Entity_Service::valid_entity_post_types() ); |
|
98 | - |
|
99 | - // If a candidate has been found and it's an entity. |
|
100 | - return null !== $candidate && $entity_service->is_entity( $candidate->ID ); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @inheritdoc |
|
105 | - */ |
|
106 | - public function html_wrapper_open() { |
|
107 | - |
|
108 | - // The containing <div> contains info on cardinality and expected types. |
|
109 | - $html = "<div class='wl-field' data-cardinality='$this->cardinality'"; |
|
110 | - |
|
111 | - if ( isset( $this->expected_uri_type ) && $this->expected_uri_type !== null ) { |
|
112 | - |
|
113 | - if ( is_array( $this->expected_uri_type ) ) { |
|
114 | - $html .= " data-expected-types='" . implode( ',', $this->expected_uri_type ) . "'"; |
|
115 | - } else { |
|
116 | - $html .= " data-expected-types='$this->expected_uri_type'"; |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - $html .= '>'; |
|
121 | - |
|
122 | - return $html; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @inheritdoc |
|
127 | - */ |
|
128 | - public function html_input( $default_entity_identifier ) { |
|
129 | - if ( empty( $default_entity_identifier ) ) { |
|
130 | - $entity = null; |
|
131 | - } elseif ( is_numeric( $default_entity_identifier ) ) { |
|
132 | - $entity = get_post( $default_entity_identifier ); |
|
133 | - } else { |
|
134 | - // @todo: we cannot be so sure this is a URI. |
|
135 | - // It is an URI |
|
136 | - $entity = Wordlift_Entity_Service::get_instance() |
|
137 | - ->get_entity_post_by_uri( $default_entity_identifier ); |
|
138 | - } |
|
139 | - |
|
140 | - // Bail out if an entity id has been provided by the entity is not found. |
|
141 | - // |
|
142 | - // See https://github.com/insideout10/wordlift-plugin/issues/818 |
|
143 | - if ( ! empty( $default_entity_identifier ) && $entity === null ) { |
|
144 | - return ''; |
|
145 | - } |
|
146 | - |
|
147 | - $label = $entity === null ? '' : $entity->post_title; |
|
148 | - $value = $entity === null ? '' : $entity->ID; |
|
149 | - |
|
150 | - // Write saved value in page |
|
151 | - // The <input> tags host the meta value. |
|
152 | - // The visible <input> has the human readable value (i.e. entity name or uri) |
|
153 | - // and is accompained by an hidden <input> tag, passed to the server, |
|
154 | - // that contains the raw value (i.e. the uri or entity id). |
|
24 | + /** |
|
25 | + * Only accept URIs or local entity IDs. |
|
26 | + * Build new entity if the user inputted a name that is not present in DB. |
|
27 | + * |
|
28 | + * @param mixed $value The value to sanitize. |
|
29 | + * |
|
30 | + * @return int|mixed|WP_Error |
|
31 | + */ |
|
32 | + public function sanitize_data_filter( $value ) { |
|
33 | + |
|
34 | + if ( empty( $value ) ) { |
|
35 | + return null; |
|
36 | + } |
|
37 | + |
|
38 | + // Check that the inserted URI, ID or name does not point to a saved |
|
39 | + // entity or when the editor types a string in the input box, we try to |
|
40 | + // find an entity with that title and, if not found, we create that entity. |
|
41 | + $absent_from_db = is_numeric( $value ) |
|
42 | + ? get_post( $value ) === null |
|
43 | + : ! $this->exists( $value ); |
|
44 | + |
|
45 | + // Is it an URI? |
|
46 | + $name_is_uri = strpos( $value, 'http' ) === 0; |
|
47 | + |
|
48 | + // We create a new entity only if the entity is not present in the DB. |
|
49 | + // In the case of an external uri, we just save the uri. |
|
50 | + if ( $absent_from_db && ! $name_is_uri ) { |
|
51 | + |
|
52 | + // ...we create a new entity! |
|
53 | + $new_entity_id = wp_insert_post( |
|
54 | + array( |
|
55 | + 'post_status' => 'publish', |
|
56 | + 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
57 | + 'post_title' => $value, |
|
58 | + ) |
|
59 | + ); |
|
60 | + |
|
61 | + $type = 'http://schema.org/' . ( isset( $this->expected_uri_type ) ? $this->expected_uri_type[0] : 'Thing' ); |
|
62 | + |
|
63 | + wl_set_entity_main_type( $new_entity_id, $type ); |
|
64 | + |
|
65 | + // Update the value that will be saved as meta. |
|
66 | + $value = $new_entity_id; |
|
67 | + } |
|
68 | + |
|
69 | + return $value; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Check whether an entity exists given a value. |
|
74 | + * |
|
75 | + * @param string $value An entity URI or a title string.. |
|
76 | + * |
|
77 | + * @return bool True if the entity exists otherwise false. |
|
78 | + * @since 3.15.0 |
|
79 | + */ |
|
80 | + private function exists( $value ) { |
|
81 | + |
|
82 | + // When the editor types a string in the input box, we try to find |
|
83 | + // an entity with that title and, if not found, we create that entity. |
|
84 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
85 | + |
|
86 | + // Try looking for an entity by URI. |
|
87 | + $found_by_uri = null !== $entity_service->get_entity_post_by_uri( $value ); |
|
88 | + |
|
89 | + // Return true if found. |
|
90 | + if ( $found_by_uri ) { |
|
91 | + $this->log->debug( "Found entity for $value." ); |
|
92 | + |
|
93 | + return true; |
|
94 | + } |
|
95 | + |
|
96 | + // Try looking for an entity by title, get any potential candidate. |
|
97 | + $candidate = get_page_by_title( $value, OBJECT, Wordlift_Entity_Service::valid_entity_post_types() ); |
|
98 | + |
|
99 | + // If a candidate has been found and it's an entity. |
|
100 | + return null !== $candidate && $entity_service->is_entity( $candidate->ID ); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @inheritdoc |
|
105 | + */ |
|
106 | + public function html_wrapper_open() { |
|
107 | + |
|
108 | + // The containing <div> contains info on cardinality and expected types. |
|
109 | + $html = "<div class='wl-field' data-cardinality='$this->cardinality'"; |
|
110 | + |
|
111 | + if ( isset( $this->expected_uri_type ) && $this->expected_uri_type !== null ) { |
|
112 | + |
|
113 | + if ( is_array( $this->expected_uri_type ) ) { |
|
114 | + $html .= " data-expected-types='" . implode( ',', $this->expected_uri_type ) . "'"; |
|
115 | + } else { |
|
116 | + $html .= " data-expected-types='$this->expected_uri_type'"; |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + $html .= '>'; |
|
121 | + |
|
122 | + return $html; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @inheritdoc |
|
127 | + */ |
|
128 | + public function html_input( $default_entity_identifier ) { |
|
129 | + if ( empty( $default_entity_identifier ) ) { |
|
130 | + $entity = null; |
|
131 | + } elseif ( is_numeric( $default_entity_identifier ) ) { |
|
132 | + $entity = get_post( $default_entity_identifier ); |
|
133 | + } else { |
|
134 | + // @todo: we cannot be so sure this is a URI. |
|
135 | + // It is an URI |
|
136 | + $entity = Wordlift_Entity_Service::get_instance() |
|
137 | + ->get_entity_post_by_uri( $default_entity_identifier ); |
|
138 | + } |
|
139 | + |
|
140 | + // Bail out if an entity id has been provided by the entity is not found. |
|
141 | + // |
|
142 | + // See https://github.com/insideout10/wordlift-plugin/issues/818 |
|
143 | + if ( ! empty( $default_entity_identifier ) && $entity === null ) { |
|
144 | + return ''; |
|
145 | + } |
|
146 | + |
|
147 | + $label = $entity === null ? '' : $entity->post_title; |
|
148 | + $value = $entity === null ? '' : $entity->ID; |
|
149 | + |
|
150 | + // Write saved value in page |
|
151 | + // The <input> tags host the meta value. |
|
152 | + // The visible <input> has the human readable value (i.e. entity name or uri) |
|
153 | + // and is accompained by an hidden <input> tag, passed to the server, |
|
154 | + // that contains the raw value (i.e. the uri or entity id). |
|
155 | 155 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
156 | - @ob_start(); |
|
157 | - ?> |
|
156 | + @ob_start(); |
|
157 | + ?> |
|
158 | 158 | <div class="wl-input-wrapper wl-autocomplete-wrapper"> |
159 | 159 | <input |
160 | 160 | type="text" |
@@ -176,9 +176,9 @@ discard block |
||
176 | 176 | <div class="wl-input-notice"></div> |
177 | 177 | </div> |
178 | 178 | <?php |
179 | - $html = ob_get_clean(); |
|
179 | + $html = ob_get_clean(); |
|
180 | 180 | |
181 | - return $html; |
|
182 | - } |
|
181 | + return $html; |
|
182 | + } |
|
183 | 183 | |
184 | 184 | } |
@@ -29,25 +29,25 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return int|mixed|WP_Error |
31 | 31 | */ |
32 | - public function sanitize_data_filter( $value ) { |
|
32 | + public function sanitize_data_filter($value) { |
|
33 | 33 | |
34 | - if ( empty( $value ) ) { |
|
34 | + if (empty($value)) { |
|
35 | 35 | return null; |
36 | 36 | } |
37 | 37 | |
38 | 38 | // Check that the inserted URI, ID or name does not point to a saved |
39 | 39 | // entity or when the editor types a string in the input box, we try to |
40 | 40 | // find an entity with that title and, if not found, we create that entity. |
41 | - $absent_from_db = is_numeric( $value ) |
|
42 | - ? get_post( $value ) === null |
|
43 | - : ! $this->exists( $value ); |
|
41 | + $absent_from_db = is_numeric($value) |
|
42 | + ? get_post($value) === null |
|
43 | + : ! $this->exists($value); |
|
44 | 44 | |
45 | 45 | // Is it an URI? |
46 | - $name_is_uri = strpos( $value, 'http' ) === 0; |
|
46 | + $name_is_uri = strpos($value, 'http') === 0; |
|
47 | 47 | |
48 | 48 | // We create a new entity only if the entity is not present in the DB. |
49 | 49 | // In the case of an external uri, we just save the uri. |
50 | - if ( $absent_from_db && ! $name_is_uri ) { |
|
50 | + if ($absent_from_db && ! $name_is_uri) { |
|
51 | 51 | |
52 | 52 | // ...we create a new entity! |
53 | 53 | $new_entity_id = wp_insert_post( |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | ) |
59 | 59 | ); |
60 | 60 | |
61 | - $type = 'http://schema.org/' . ( isset( $this->expected_uri_type ) ? $this->expected_uri_type[0] : 'Thing' ); |
|
61 | + $type = 'http://schema.org/'.(isset($this->expected_uri_type) ? $this->expected_uri_type[0] : 'Thing'); |
|
62 | 62 | |
63 | - wl_set_entity_main_type( $new_entity_id, $type ); |
|
63 | + wl_set_entity_main_type($new_entity_id, $type); |
|
64 | 64 | |
65 | 65 | // Update the value that will be saved as meta. |
66 | 66 | $value = $new_entity_id; |
@@ -77,27 +77,27 @@ discard block |
||
77 | 77 | * @return bool True if the entity exists otherwise false. |
78 | 78 | * @since 3.15.0 |
79 | 79 | */ |
80 | - private function exists( $value ) { |
|
80 | + private function exists($value) { |
|
81 | 81 | |
82 | 82 | // When the editor types a string in the input box, we try to find |
83 | 83 | // an entity with that title and, if not found, we create that entity. |
84 | 84 | $entity_service = Wordlift_Entity_Service::get_instance(); |
85 | 85 | |
86 | 86 | // Try looking for an entity by URI. |
87 | - $found_by_uri = null !== $entity_service->get_entity_post_by_uri( $value ); |
|
87 | + $found_by_uri = null !== $entity_service->get_entity_post_by_uri($value); |
|
88 | 88 | |
89 | 89 | // Return true if found. |
90 | - if ( $found_by_uri ) { |
|
91 | - $this->log->debug( "Found entity for $value." ); |
|
90 | + if ($found_by_uri) { |
|
91 | + $this->log->debug("Found entity for $value."); |
|
92 | 92 | |
93 | 93 | return true; |
94 | 94 | } |
95 | 95 | |
96 | 96 | // Try looking for an entity by title, get any potential candidate. |
97 | - $candidate = get_page_by_title( $value, OBJECT, Wordlift_Entity_Service::valid_entity_post_types() ); |
|
97 | + $candidate = get_page_by_title($value, OBJECT, Wordlift_Entity_Service::valid_entity_post_types()); |
|
98 | 98 | |
99 | 99 | // If a candidate has been found and it's an entity. |
100 | - return null !== $candidate && $entity_service->is_entity( $candidate->ID ); |
|
100 | + return null !== $candidate && $entity_service->is_entity($candidate->ID); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | // The containing <div> contains info on cardinality and expected types. |
109 | 109 | $html = "<div class='wl-field' data-cardinality='$this->cardinality'"; |
110 | 110 | |
111 | - if ( isset( $this->expected_uri_type ) && $this->expected_uri_type !== null ) { |
|
111 | + if (isset($this->expected_uri_type) && $this->expected_uri_type !== null) { |
|
112 | 112 | |
113 | - if ( is_array( $this->expected_uri_type ) ) { |
|
114 | - $html .= " data-expected-types='" . implode( ',', $this->expected_uri_type ) . "'"; |
|
113 | + if (is_array($this->expected_uri_type)) { |
|
114 | + $html .= " data-expected-types='".implode(',', $this->expected_uri_type)."'"; |
|
115 | 115 | } else { |
116 | 116 | $html .= " data-expected-types='$this->expected_uri_type'"; |
117 | 117 | } |
@@ -125,22 +125,22 @@ discard block |
||
125 | 125 | /** |
126 | 126 | * @inheritdoc |
127 | 127 | */ |
128 | - public function html_input( $default_entity_identifier ) { |
|
129 | - if ( empty( $default_entity_identifier ) ) { |
|
128 | + public function html_input($default_entity_identifier) { |
|
129 | + if (empty($default_entity_identifier)) { |
|
130 | 130 | $entity = null; |
131 | - } elseif ( is_numeric( $default_entity_identifier ) ) { |
|
132 | - $entity = get_post( $default_entity_identifier ); |
|
131 | + } elseif (is_numeric($default_entity_identifier)) { |
|
132 | + $entity = get_post($default_entity_identifier); |
|
133 | 133 | } else { |
134 | 134 | // @todo: we cannot be so sure this is a URI. |
135 | 135 | // It is an URI |
136 | 136 | $entity = Wordlift_Entity_Service::get_instance() |
137 | - ->get_entity_post_by_uri( $default_entity_identifier ); |
|
137 | + ->get_entity_post_by_uri($default_entity_identifier); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | // Bail out if an entity id has been provided by the entity is not found. |
141 | 141 | // |
142 | 142 | // See https://github.com/insideout10/wordlift-plugin/issues/818 |
143 | - if ( ! empty( $default_entity_identifier ) && $entity === null ) { |
|
143 | + if ( ! empty($default_entity_identifier) && $entity === null) { |
|
144 | 144 | return ''; |
145 | 145 | } |
146 | 146 | |
@@ -158,19 +158,19 @@ discard block |
||
158 | 158 | <div class="wl-input-wrapper wl-autocomplete-wrapper"> |
159 | 159 | <input |
160 | 160 | type="text" |
161 | - class="<?php echo esc_attr( $this->meta_name ); ?> wl-autocomplete" |
|
162 | - value="<?php echo esc_attr( $label ); ?>" |
|
161 | + class="<?php echo esc_attr($this->meta_name); ?> wl-autocomplete" |
|
162 | + value="<?php echo esc_attr($label); ?>" |
|
163 | 163 | style="width:88%" |
164 | 164 | /> |
165 | 165 | <input |
166 | 166 | type="hidden" |
167 | - class="<?php echo esc_attr( $this->meta_name ); ?>" |
|
168 | - name="wl_metaboxes[<?php echo esc_attr( $this->meta_name ); ?>][]" |
|
169 | - value="<?php echo esc_attr( $value ); ?>" |
|
167 | + class="<?php echo esc_attr($this->meta_name); ?>" |
|
168 | + name="wl_metaboxes[<?php echo esc_attr($this->meta_name); ?>][]" |
|
169 | + value="<?php echo esc_attr($value); ?>" |
|
170 | 170 | /> |
171 | 171 | |
172 | 172 | <button class="button wl-remove-input wl-button" type="button"> |
173 | - <?php esc_html_e( 'Remove', 'wordlift' ); ?> |
|
173 | + <?php esc_html_e('Remove', 'wordlift'); ?> |
|
174 | 174 | </button> |
175 | 175 | |
176 | 176 | <div class="wl-input-notice"></div> |
@@ -20,42 +20,42 @@ |
||
20 | 20 | */ |
21 | 21 | class Wordlift_Metabox_Field_Duration extends Wl_Metabox_Field_date { |
22 | 22 | |
23 | - /** |
|
24 | - * {@inheritdoc} |
|
25 | - */ |
|
26 | - public function __construct( $args, $id, $type ) { |
|
27 | - parent::__construct( $args, $id, $type ); |
|
28 | - |
|
29 | - $this->date_format = 'H:i'; |
|
30 | - $this->timepicker = true; |
|
31 | - $this->no_calendar = true; |
|
32 | - |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Sanitize a single value. Called from $this->sanitize_data. Default sanitization excludes empty values. |
|
37 | - * make sure the value is either empty, an integer representing valid number of minutes |
|
38 | - * or an HH:MM time format. |
|
39 | - * |
|
40 | - * @param mixed $value The value being sanitized. |
|
41 | - * |
|
42 | - * @return mixed Returns sanitized value, or null. |
|
43 | - */ |
|
44 | - public function sanitize_data_filter( $value ) { |
|
45 | - |
|
46 | - if ( $value !== null && '' !== $value ) { // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ . |
|
47 | - preg_match( |
|
48 | - '#((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}#', |
|
49 | - trim( $value ), |
|
50 | - $matches |
|
51 | - ); |
|
52 | - |
|
53 | - if ( count( $matches ) > 0 ) { |
|
54 | - return $matches[0]; |
|
55 | - } |
|
56 | - } |
|
57 | - |
|
58 | - return null; |
|
59 | - } |
|
23 | + /** |
|
24 | + * {@inheritdoc} |
|
25 | + */ |
|
26 | + public function __construct( $args, $id, $type ) { |
|
27 | + parent::__construct( $args, $id, $type ); |
|
28 | + |
|
29 | + $this->date_format = 'H:i'; |
|
30 | + $this->timepicker = true; |
|
31 | + $this->no_calendar = true; |
|
32 | + |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Sanitize a single value. Called from $this->sanitize_data. Default sanitization excludes empty values. |
|
37 | + * make sure the value is either empty, an integer representing valid number of minutes |
|
38 | + * or an HH:MM time format. |
|
39 | + * |
|
40 | + * @param mixed $value The value being sanitized. |
|
41 | + * |
|
42 | + * @return mixed Returns sanitized value, or null. |
|
43 | + */ |
|
44 | + public function sanitize_data_filter( $value ) { |
|
45 | + |
|
46 | + if ( $value !== null && '' !== $value ) { // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ . |
|
47 | + preg_match( |
|
48 | + '#((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}#', |
|
49 | + trim( $value ), |
|
50 | + $matches |
|
51 | + ); |
|
52 | + |
|
53 | + if ( count( $matches ) > 0 ) { |
|
54 | + return $matches[0]; |
|
55 | + } |
|
56 | + } |
|
57 | + |
|
58 | + return null; |
|
59 | + } |
|
60 | 60 | |
61 | 61 | } |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * {@inheritdoc} |
25 | 25 | */ |
26 | - public function __construct( $args, $id, $type ) { |
|
27 | - parent::__construct( $args, $id, $type ); |
|
26 | + public function __construct($args, $id, $type) { |
|
27 | + parent::__construct($args, $id, $type); |
|
28 | 28 | |
29 | 29 | $this->date_format = 'H:i'; |
30 | 30 | $this->timepicker = true; |
@@ -41,16 +41,16 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return mixed Returns sanitized value, or null. |
43 | 43 | */ |
44 | - public function sanitize_data_filter( $value ) { |
|
44 | + public function sanitize_data_filter($value) { |
|
45 | 45 | |
46 | - if ( $value !== null && '' !== $value ) { // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ . |
|
46 | + if ($value !== null && '' !== $value) { // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ . |
|
47 | 47 | preg_match( |
48 | 48 | '#((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}#', |
49 | - trim( $value ), |
|
49 | + trim($value), |
|
50 | 50 | $matches |
51 | 51 | ); |
52 | 52 | |
53 | - if ( count( $matches ) > 0 ) { |
|
53 | + if (count($matches) > 0) { |
|
54 | 54 | return $matches[0]; |
55 | 55 | } |
56 | 56 | } |