@@ -4,31 +4,31 @@ |
||
4 | 4 | |
5 | 5 | class Background_Task_Stopped_State extends Abstract_Background_Task_State { |
6 | 6 | |
7 | - /** |
|
8 | - * @var Background_Task |
|
9 | - */ |
|
10 | - private $context; |
|
7 | + /** |
|
8 | + * @var Background_Task |
|
9 | + */ |
|
10 | + private $context; |
|
11 | 11 | |
12 | - public function __construct( $context ) { |
|
13 | - parent::__construct( $context, Background_Task::STATE_STOPPED ); |
|
12 | + public function __construct( $context ) { |
|
13 | + parent::__construct( $context, Background_Task::STATE_STOPPED ); |
|
14 | 14 | |
15 | - $this->context = $context; |
|
16 | - } |
|
15 | + $this->context = $context; |
|
16 | + } |
|
17 | 17 | |
18 | - public function enter() { |
|
19 | - $this->context->set_state( Background_Task::STATE_STOPPED ); |
|
20 | - } |
|
18 | + public function enter() { |
|
19 | + $this->context->set_state( Background_Task::STATE_STOPPED ); |
|
20 | + } |
|
21 | 21 | |
22 | - public function leave() { |
|
23 | - $this->context->set_state( null ); |
|
24 | - } |
|
22 | + public function leave() { |
|
23 | + $this->context->set_state( null ); |
|
24 | + } |
|
25 | 25 | |
26 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
27 | - public function task( $value ) { |
|
26 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
27 | + public function task( $value ) { |
|
28 | 28 | |
29 | - $this->context->cancel_process(); |
|
29 | + $this->context->cancel_process(); |
|
30 | 30 | |
31 | - return false; |
|
32 | - } |
|
31 | + return false; |
|
32 | + } |
|
33 | 33 | |
34 | 34 | } |
@@ -9,22 +9,22 @@ |
||
9 | 9 | */ |
10 | 10 | private $context; |
11 | 11 | |
12 | - public function __construct( $context ) { |
|
13 | - parent::__construct( $context, Background_Task::STATE_STOPPED ); |
|
12 | + public function __construct($context) { |
|
13 | + parent::__construct($context, Background_Task::STATE_STOPPED); |
|
14 | 14 | |
15 | 15 | $this->context = $context; |
16 | 16 | } |
17 | 17 | |
18 | 18 | public function enter() { |
19 | - $this->context->set_state( Background_Task::STATE_STOPPED ); |
|
19 | + $this->context->set_state(Background_Task::STATE_STOPPED); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function leave() { |
23 | - $this->context->set_state( null ); |
|
23 | + $this->context->set_state(null); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
27 | - public function task( $value ) { |
|
27 | + public function task($value) { |
|
28 | 28 | |
29 | 29 | $this->context->cancel_process(); |
30 | 30 |
@@ -8,73 +8,73 @@ discard block |
||
8 | 8 | |
9 | 9 | class Background_Task_Page { |
10 | 10 | |
11 | - private $title; |
|
12 | - |
|
13 | - private $menu_slug; |
|
14 | - |
|
15 | - /** |
|
16 | - * @var Background_Task_Route $background_task_route |
|
17 | - */ |
|
18 | - private $background_task_route; |
|
19 | - |
|
20 | - /** |
|
21 | - * @throws Exception if one or more parameters are invalid. |
|
22 | - */ |
|
23 | - public function __construct( $title, $menu_slug, $background_task_route ) { |
|
24 | - Assertions::not_empty( $title, '`$title` cannot be empty.' ); |
|
25 | - Assertions::not_empty( $menu_slug, '`$menu_slug` cannot be empty.' ); |
|
26 | - Assertions::is_a( $background_task_route, 'Wordlift\Task\Background\Background_Task_Route', '`Background_Task_Route` must be of type `Wordlift\Task\Background\Background_Route`.' ); |
|
27 | - |
|
28 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
29 | - |
|
30 | - $this->title = $title; |
|
31 | - $this->menu_slug = $menu_slug; |
|
32 | - $this->background_task_route = $background_task_route; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @throws Exception if one or more parameters are invalid. |
|
37 | - */ |
|
38 | - public static function create( $title, $menu_slug, $background_route ) { |
|
39 | - return new self( $title, $menu_slug, $background_route ); |
|
40 | - } |
|
41 | - |
|
42 | - public function admin_menu() { |
|
43 | - |
|
44 | - add_submenu_page( |
|
45 | - 'wl_admin_menu', |
|
46 | - $this->title, |
|
47 | - $this->title, |
|
48 | - 'manage_options', |
|
49 | - $this->menu_slug, |
|
50 | - array( |
|
51 | - $this, |
|
52 | - 'render', |
|
53 | - ) |
|
54 | - ); |
|
55 | - |
|
56 | - } |
|
57 | - |
|
58 | - public function render() { |
|
59 | - |
|
60 | - wp_enqueue_style( |
|
61 | - 'wl-task-page', |
|
62 | - plugin_dir_url( __FILE__ ) . 'assets/task-page.css', |
|
63 | - array(), |
|
64 | - Wordlift::get_instance()->get_version(), |
|
65 | - 'all' |
|
66 | - ); |
|
67 | - |
|
68 | - wp_enqueue_script( |
|
69 | - 'wl-task-page', |
|
70 | - plugin_dir_url( __FILE__ ) . 'assets/task-page.js', |
|
71 | - array( 'wp-api' ), |
|
72 | - WORDLIFT_VERSION, |
|
73 | - false |
|
74 | - ); |
|
75 | - |
|
76 | - wp_localize_script( 'wl-task-page', '_wlTaskPageSettings', array( 'rest_path' => $this->background_task_route->get_rest_path() ) ); |
|
77 | - ?> |
|
11 | + private $title; |
|
12 | + |
|
13 | + private $menu_slug; |
|
14 | + |
|
15 | + /** |
|
16 | + * @var Background_Task_Route $background_task_route |
|
17 | + */ |
|
18 | + private $background_task_route; |
|
19 | + |
|
20 | + /** |
|
21 | + * @throws Exception if one or more parameters are invalid. |
|
22 | + */ |
|
23 | + public function __construct( $title, $menu_slug, $background_task_route ) { |
|
24 | + Assertions::not_empty( $title, '`$title` cannot be empty.' ); |
|
25 | + Assertions::not_empty( $menu_slug, '`$menu_slug` cannot be empty.' ); |
|
26 | + Assertions::is_a( $background_task_route, 'Wordlift\Task\Background\Background_Task_Route', '`Background_Task_Route` must be of type `Wordlift\Task\Background\Background_Route`.' ); |
|
27 | + |
|
28 | + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
29 | + |
|
30 | + $this->title = $title; |
|
31 | + $this->menu_slug = $menu_slug; |
|
32 | + $this->background_task_route = $background_task_route; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @throws Exception if one or more parameters are invalid. |
|
37 | + */ |
|
38 | + public static function create( $title, $menu_slug, $background_route ) { |
|
39 | + return new self( $title, $menu_slug, $background_route ); |
|
40 | + } |
|
41 | + |
|
42 | + public function admin_menu() { |
|
43 | + |
|
44 | + add_submenu_page( |
|
45 | + 'wl_admin_menu', |
|
46 | + $this->title, |
|
47 | + $this->title, |
|
48 | + 'manage_options', |
|
49 | + $this->menu_slug, |
|
50 | + array( |
|
51 | + $this, |
|
52 | + 'render', |
|
53 | + ) |
|
54 | + ); |
|
55 | + |
|
56 | + } |
|
57 | + |
|
58 | + public function render() { |
|
59 | + |
|
60 | + wp_enqueue_style( |
|
61 | + 'wl-task-page', |
|
62 | + plugin_dir_url( __FILE__ ) . 'assets/task-page.css', |
|
63 | + array(), |
|
64 | + Wordlift::get_instance()->get_version(), |
|
65 | + 'all' |
|
66 | + ); |
|
67 | + |
|
68 | + wp_enqueue_script( |
|
69 | + 'wl-task-page', |
|
70 | + plugin_dir_url( __FILE__ ) . 'assets/task-page.js', |
|
71 | + array( 'wp-api' ), |
|
72 | + WORDLIFT_VERSION, |
|
73 | + false |
|
74 | + ); |
|
75 | + |
|
76 | + wp_localize_script( 'wl-task-page', '_wlTaskPageSettings', array( 'rest_path' => $this->background_task_route->get_rest_path() ) ); |
|
77 | + ?> |
|
78 | 78 | <div class="wrap"> |
79 | 79 | <h2><?php echo esc_html( $this->title ); ?></h2> |
80 | 80 | |
@@ -85,17 +85,17 @@ discard block |
||
85 | 85 | |
86 | 86 | <button id="wl-start-btn" type="button" class="button button-large button-primary"> |
87 | 87 | <?php |
88 | - esc_html_e( 'Start', 'wordlift' ); |
|
89 | - ?> |
|
88 | + esc_html_e( 'Start', 'wordlift' ); |
|
89 | + ?> |
|
90 | 90 | </button> |
91 | 91 | <button id="wl-stop-btn" type="button" class="button button-large button-primary hidden"> |
92 | 92 | <?php |
93 | - esc_html_e( 'Stop', 'wordlift' ); |
|
94 | - ?> |
|
93 | + esc_html_e( 'Stop', 'wordlift' ); |
|
94 | + ?> |
|
95 | 95 | </button> |
96 | 96 | |
97 | 97 | </div> |
98 | 98 | <?php |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | } |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * @throws Exception if one or more parameters are invalid. |
22 | 22 | */ |
23 | - public function __construct( $title, $menu_slug, $background_task_route ) { |
|
24 | - Assertions::not_empty( $title, '`$title` cannot be empty.' ); |
|
25 | - Assertions::not_empty( $menu_slug, '`$menu_slug` cannot be empty.' ); |
|
26 | - Assertions::is_a( $background_task_route, 'Wordlift\Task\Background\Background_Task_Route', '`Background_Task_Route` must be of type `Wordlift\Task\Background\Background_Route`.' ); |
|
23 | + public function __construct($title, $menu_slug, $background_task_route) { |
|
24 | + Assertions::not_empty($title, '`$title` cannot be empty.'); |
|
25 | + Assertions::not_empty($menu_slug, '`$menu_slug` cannot be empty.'); |
|
26 | + Assertions::is_a($background_task_route, 'Wordlift\Task\Background\Background_Task_Route', '`Background_Task_Route` must be of type `Wordlift\Task\Background\Background_Route`.'); |
|
27 | 27 | |
28 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
28 | + add_action('admin_menu', array($this, 'admin_menu')); |
|
29 | 29 | |
30 | 30 | $this->title = $title; |
31 | 31 | $this->menu_slug = $menu_slug; |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @throws Exception if one or more parameters are invalid. |
37 | 37 | */ |
38 | - public static function create( $title, $menu_slug, $background_route ) { |
|
39 | - return new self( $title, $menu_slug, $background_route ); |
|
38 | + public static function create($title, $menu_slug, $background_route) { |
|
39 | + return new self($title, $menu_slug, $background_route); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function admin_menu() { |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | wp_enqueue_style( |
61 | 61 | 'wl-task-page', |
62 | - plugin_dir_url( __FILE__ ) . 'assets/task-page.css', |
|
62 | + plugin_dir_url(__FILE__).'assets/task-page.css', |
|
63 | 63 | array(), |
64 | 64 | Wordlift::get_instance()->get_version(), |
65 | 65 | 'all' |
@@ -67,16 +67,16 @@ discard block |
||
67 | 67 | |
68 | 68 | wp_enqueue_script( |
69 | 69 | 'wl-task-page', |
70 | - plugin_dir_url( __FILE__ ) . 'assets/task-page.js', |
|
71 | - array( 'wp-api' ), |
|
70 | + plugin_dir_url(__FILE__).'assets/task-page.js', |
|
71 | + array('wp-api'), |
|
72 | 72 | WORDLIFT_VERSION, |
73 | 73 | false |
74 | 74 | ); |
75 | 75 | |
76 | - wp_localize_script( 'wl-task-page', '_wlTaskPageSettings', array( 'rest_path' => $this->background_task_route->get_rest_path() ) ); |
|
76 | + wp_localize_script('wl-task-page', '_wlTaskPageSettings', array('rest_path' => $this->background_task_route->get_rest_path())); |
|
77 | 77 | ?> |
78 | 78 | <div class="wrap"> |
79 | - <h2><?php echo esc_html( $this->title ); ?></h2> |
|
79 | + <h2><?php echo esc_html($this->title); ?></h2> |
|
80 | 80 | |
81 | 81 | <div class="wl-task__progress" style="border: 1px solid #23282D; height: 20px; margin: 8px 0;"> |
82 | 82 | <div class="wl-task__progress__bar" |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | |
86 | 86 | <button id="wl-start-btn" type="button" class="button button-large button-primary"> |
87 | 87 | <?php |
88 | - esc_html_e( 'Start', 'wordlift' ); |
|
88 | + esc_html_e('Start', 'wordlift'); |
|
89 | 89 | ?> |
90 | 90 | </button> |
91 | 91 | <button id="wl-stop-btn" type="button" class="button button-large button-primary hidden"> |
92 | 92 | <?php |
93 | - esc_html_e( 'Stop', 'wordlift' ); |
|
93 | + esc_html_e('Stop', 'wordlift'); |
|
94 | 94 | ?> |
95 | 95 | </button> |
96 | 96 |
@@ -8,87 +8,87 @@ |
||
8 | 8 | |
9 | 9 | class Background_Task_Route { |
10 | 10 | |
11 | - const VERSION_STRING = 'wordlift/v1'; |
|
12 | - |
|
13 | - /** |
|
14 | - * @var Background_Task |
|
15 | - */ |
|
16 | - private $background_task; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - private $route_name; |
|
22 | - |
|
23 | - public function __construct( $background_task, $route_name ) { |
|
24 | - $this->background_task = $background_task; |
|
25 | - $this->route_name = $route_name; |
|
26 | - } |
|
27 | - |
|
28 | - public static function create( $task, $route_name ) { |
|
29 | - $route = new self( $task, $route_name ); |
|
30 | - |
|
31 | - add_action( 'rest_api_init', array( $route, 'register' ) ); |
|
32 | - |
|
33 | - return $route; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * @throws Exception if the input value is invalid. |
|
38 | - */ |
|
39 | - public function register() { |
|
40 | - Assertions::starts_with( $this->route_name, '/', 'The route name must start with a slash.' ); |
|
41 | - |
|
42 | - register_rest_route( |
|
43 | - self::VERSION_STRING, |
|
44 | - $this->route_name, |
|
45 | - array( |
|
46 | - 'methods' => WP_REST_Server::CREATABLE, |
|
47 | - 'callback' => array( $this->background_task, 'start' ), |
|
48 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
49 | - ) |
|
50 | - ); |
|
51 | - |
|
52 | - register_rest_route( |
|
53 | - self::VERSION_STRING, |
|
54 | - $this->route_name, |
|
55 | - array( |
|
56 | - 'methods' => WP_REST_Server::READABLE, |
|
57 | - 'callback' => array( $this->background_task, 'get_info' ), |
|
58 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
59 | - ) |
|
60 | - ); |
|
61 | - |
|
62 | - register_rest_route( |
|
63 | - self::VERSION_STRING, |
|
64 | - $this->route_name, |
|
65 | - array( |
|
66 | - 'methods' => WP_REST_Server::DELETABLE, |
|
67 | - 'callback' => array( $this->background_task, 'stop' ), |
|
68 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
69 | - ) |
|
70 | - ); |
|
71 | - |
|
72 | - register_rest_route( |
|
73 | - self::VERSION_STRING, |
|
74 | - $this->route_name, |
|
75 | - array( |
|
76 | - 'methods' => 'PUT', |
|
77 | - 'callback' => array( $this->background_task, 'resume' ), |
|
78 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
79 | - ) |
|
80 | - ); |
|
81 | - |
|
82 | - } |
|
83 | - |
|
84 | - public function permission_callback() { |
|
85 | - $user = wp_get_current_user(); |
|
86 | - |
|
87 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
88 | - } |
|
89 | - |
|
90 | - public function get_rest_path() { |
|
91 | - return self::VERSION_STRING . $this->route_name; |
|
92 | - } |
|
11 | + const VERSION_STRING = 'wordlift/v1'; |
|
12 | + |
|
13 | + /** |
|
14 | + * @var Background_Task |
|
15 | + */ |
|
16 | + private $background_task; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + private $route_name; |
|
22 | + |
|
23 | + public function __construct( $background_task, $route_name ) { |
|
24 | + $this->background_task = $background_task; |
|
25 | + $this->route_name = $route_name; |
|
26 | + } |
|
27 | + |
|
28 | + public static function create( $task, $route_name ) { |
|
29 | + $route = new self( $task, $route_name ); |
|
30 | + |
|
31 | + add_action( 'rest_api_init', array( $route, 'register' ) ); |
|
32 | + |
|
33 | + return $route; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * @throws Exception if the input value is invalid. |
|
38 | + */ |
|
39 | + public function register() { |
|
40 | + Assertions::starts_with( $this->route_name, '/', 'The route name must start with a slash.' ); |
|
41 | + |
|
42 | + register_rest_route( |
|
43 | + self::VERSION_STRING, |
|
44 | + $this->route_name, |
|
45 | + array( |
|
46 | + 'methods' => WP_REST_Server::CREATABLE, |
|
47 | + 'callback' => array( $this->background_task, 'start' ), |
|
48 | + 'permission_callback' => array( $this, 'permission_callback' ), |
|
49 | + ) |
|
50 | + ); |
|
51 | + |
|
52 | + register_rest_route( |
|
53 | + self::VERSION_STRING, |
|
54 | + $this->route_name, |
|
55 | + array( |
|
56 | + 'methods' => WP_REST_Server::READABLE, |
|
57 | + 'callback' => array( $this->background_task, 'get_info' ), |
|
58 | + 'permission_callback' => array( $this, 'permission_callback' ), |
|
59 | + ) |
|
60 | + ); |
|
61 | + |
|
62 | + register_rest_route( |
|
63 | + self::VERSION_STRING, |
|
64 | + $this->route_name, |
|
65 | + array( |
|
66 | + 'methods' => WP_REST_Server::DELETABLE, |
|
67 | + 'callback' => array( $this->background_task, 'stop' ), |
|
68 | + 'permission_callback' => array( $this, 'permission_callback' ), |
|
69 | + ) |
|
70 | + ); |
|
71 | + |
|
72 | + register_rest_route( |
|
73 | + self::VERSION_STRING, |
|
74 | + $this->route_name, |
|
75 | + array( |
|
76 | + 'methods' => 'PUT', |
|
77 | + 'callback' => array( $this->background_task, 'resume' ), |
|
78 | + 'permission_callback' => array( $this, 'permission_callback' ), |
|
79 | + ) |
|
80 | + ); |
|
81 | + |
|
82 | + } |
|
83 | + |
|
84 | + public function permission_callback() { |
|
85 | + $user = wp_get_current_user(); |
|
86 | + |
|
87 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
88 | + } |
|
89 | + |
|
90 | + public function get_rest_path() { |
|
91 | + return self::VERSION_STRING . $this->route_name; |
|
92 | + } |
|
93 | 93 | |
94 | 94 | } |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | */ |
21 | 21 | private $route_name; |
22 | 22 | |
23 | - public function __construct( $background_task, $route_name ) { |
|
23 | + public function __construct($background_task, $route_name) { |
|
24 | 24 | $this->background_task = $background_task; |
25 | 25 | $this->route_name = $route_name; |
26 | 26 | } |
27 | 27 | |
28 | - public static function create( $task, $route_name ) { |
|
29 | - $route = new self( $task, $route_name ); |
|
28 | + public static function create($task, $route_name) { |
|
29 | + $route = new self($task, $route_name); |
|
30 | 30 | |
31 | - add_action( 'rest_api_init', array( $route, 'register' ) ); |
|
31 | + add_action('rest_api_init', array($route, 'register')); |
|
32 | 32 | |
33 | 33 | return $route; |
34 | 34 | } |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | * @throws Exception if the input value is invalid. |
38 | 38 | */ |
39 | 39 | public function register() { |
40 | - Assertions::starts_with( $this->route_name, '/', 'The route name must start with a slash.' ); |
|
40 | + Assertions::starts_with($this->route_name, '/', 'The route name must start with a slash.'); |
|
41 | 41 | |
42 | 42 | register_rest_route( |
43 | 43 | self::VERSION_STRING, |
44 | 44 | $this->route_name, |
45 | 45 | array( |
46 | 46 | 'methods' => WP_REST_Server::CREATABLE, |
47 | - 'callback' => array( $this->background_task, 'start' ), |
|
48 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
47 | + 'callback' => array($this->background_task, 'start'), |
|
48 | + 'permission_callback' => array($this, 'permission_callback'), |
|
49 | 49 | ) |
50 | 50 | ); |
51 | 51 | |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | $this->route_name, |
55 | 55 | array( |
56 | 56 | 'methods' => WP_REST_Server::READABLE, |
57 | - 'callback' => array( $this->background_task, 'get_info' ), |
|
58 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
57 | + 'callback' => array($this->background_task, 'get_info'), |
|
58 | + 'permission_callback' => array($this, 'permission_callback'), |
|
59 | 59 | ) |
60 | 60 | ); |
61 | 61 | |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | $this->route_name, |
65 | 65 | array( |
66 | 66 | 'methods' => WP_REST_Server::DELETABLE, |
67 | - 'callback' => array( $this->background_task, 'stop' ), |
|
68 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
67 | + 'callback' => array($this->background_task, 'stop'), |
|
68 | + 'permission_callback' => array($this, 'permission_callback'), |
|
69 | 69 | ) |
70 | 70 | ); |
71 | 71 | |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | $this->route_name, |
75 | 75 | array( |
76 | 76 | 'methods' => 'PUT', |
77 | - 'callback' => array( $this->background_task, 'resume' ), |
|
78 | - 'permission_callback' => array( $this, 'permission_callback' ), |
|
77 | + 'callback' => array($this->background_task, 'resume'), |
|
78 | + 'permission_callback' => array($this, 'permission_callback'), |
|
79 | 79 | ) |
80 | 80 | ); |
81 | 81 | |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | public function permission_callback() { |
85 | 85 | $user = wp_get_current_user(); |
86 | 86 | |
87 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
87 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | public function get_rest_path() { |
91 | - return self::VERSION_STRING . $this->route_name; |
|
91 | + return self::VERSION_STRING.$this->route_name; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | } |
@@ -4,79 +4,79 @@ |
||
4 | 4 | |
5 | 5 | class Background_Task_Started_State extends Abstract_Background_Task_State { |
6 | 6 | |
7 | - /** |
|
8 | - * @var Background_Task |
|
9 | - */ |
|
10 | - private $context; |
|
7 | + /** |
|
8 | + * @var Background_Task |
|
9 | + */ |
|
10 | + private $context; |
|
11 | 11 | |
12 | - private $batch_size = 5; |
|
12 | + private $batch_size = 5; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @var Task |
|
16 | - */ |
|
17 | - private $task; |
|
14 | + /** |
|
15 | + * @var Task |
|
16 | + */ |
|
17 | + private $task; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Back_Started_State constructor. |
|
21 | - * |
|
22 | - * @param Background_Task $context |
|
23 | - */ |
|
24 | - public function __construct( $context, $task ) { |
|
25 | - parent::__construct( $context, Background_Task::STATE_STARTED ); |
|
19 | + /** |
|
20 | + * Back_Started_State constructor. |
|
21 | + * |
|
22 | + * @param Background_Task $context |
|
23 | + */ |
|
24 | + public function __construct( $context, $task ) { |
|
25 | + parent::__construct( $context, Background_Task::STATE_STARTED ); |
|
26 | 26 | |
27 | - $this->context = $context; |
|
28 | - $this->task = $task; |
|
29 | - } |
|
27 | + $this->context = $context; |
|
28 | + $this->task = $task; |
|
29 | + } |
|
30 | 30 | |
31 | - public function enter() { |
|
31 | + public function enter() { |
|
32 | 32 | |
33 | - $count = $this->task->starting(); |
|
33 | + $count = $this->task->starting(); |
|
34 | 34 | |
35 | - update_option( $this->context->get_option_prefix() . 'count', $count, true ); |
|
36 | - update_option( $this->context->get_option_prefix() . 'offset', 0, true ); |
|
37 | - update_option( $this->context->get_option_prefix() . 'started', time(), true ); |
|
38 | - update_option( $this->context->get_option_prefix() . 'updated', time(), true ); |
|
35 | + update_option( $this->context->get_option_prefix() . 'count', $count, true ); |
|
36 | + update_option( $this->context->get_option_prefix() . 'offset', 0, true ); |
|
37 | + update_option( $this->context->get_option_prefix() . 'started', time(), true ); |
|
38 | + update_option( $this->context->get_option_prefix() . 'updated', time(), true ); |
|
39 | 39 | |
40 | - $this->context->set_state( Background_Task::STATE_STARTED ); |
|
40 | + $this->context->set_state( Background_Task::STATE_STARTED ); |
|
41 | 41 | |
42 | - $this->resume(); |
|
43 | - } |
|
42 | + $this->resume(); |
|
43 | + } |
|
44 | 44 | |
45 | - public function resume() { |
|
46 | - $this->context->push_to_queue( true ); |
|
47 | - $this->context->save()->dispatch(); |
|
48 | - } |
|
45 | + public function resume() { |
|
46 | + $this->context->push_to_queue( true ); |
|
47 | + $this->context->save()->dispatch(); |
|
48 | + } |
|
49 | 49 | |
50 | - public function leave() { |
|
51 | - $this->context->set_state( null ); |
|
52 | - } |
|
50 | + public function leave() { |
|
51 | + $this->context->set_state( null ); |
|
52 | + } |
|
53 | 53 | |
54 | - public function task( $value ) { |
|
55 | - $offset = get_option( $this->context->get_option_prefix() . 'offset' ); |
|
56 | - $count = get_option( $this->context->get_option_prefix() . 'count' ); |
|
54 | + public function task( $value ) { |
|
55 | + $offset = get_option( $this->context->get_option_prefix() . 'offset' ); |
|
56 | + $count = get_option( $this->context->get_option_prefix() . 'count' ); |
|
57 | 57 | |
58 | - $this->task->tick( |
|
59 | - $value, |
|
60 | - array( |
|
61 | - 'offset' => $offset, |
|
62 | - 'count' => $count, |
|
63 | - 'batch_size' => $this->batch_size, |
|
64 | - ) |
|
65 | - ); |
|
58 | + $this->task->tick( |
|
59 | + $value, |
|
60 | + array( |
|
61 | + 'offset' => $offset, |
|
62 | + 'count' => $count, |
|
63 | + 'batch_size' => $this->batch_size, |
|
64 | + ) |
|
65 | + ); |
|
66 | 66 | |
67 | - update_option( $this->context->get_option_prefix() . 'updated', time(), true ); |
|
67 | + update_option( $this->context->get_option_prefix() . 'updated', time(), true ); |
|
68 | 68 | |
69 | - // Increase the offset. |
|
70 | - if ( ( $offset + $this->batch_size ) < $count ) { |
|
71 | - update_option( $this->context->get_option_prefix() . 'offset', $offset + $this->batch_size, true ); |
|
69 | + // Increase the offset. |
|
70 | + if ( ( $offset + $this->batch_size ) < $count ) { |
|
71 | + update_option( $this->context->get_option_prefix() . 'offset', $offset + $this->batch_size, true ); |
|
72 | 72 | |
73 | - return true; |
|
74 | - } |
|
73 | + return true; |
|
74 | + } |
|
75 | 75 | |
76 | - // Stop processing. |
|
77 | - $this->context->stop(); |
|
76 | + // Stop processing. |
|
77 | + $this->context->stop(); |
|
78 | 78 | |
79 | - return false; |
|
80 | - } |
|
79 | + return false; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param Background_Task $context |
23 | 23 | */ |
24 | - public function __construct( $context, $task ) { |
|
25 | - parent::__construct( $context, Background_Task::STATE_STARTED ); |
|
24 | + public function __construct($context, $task) { |
|
25 | + parent::__construct($context, Background_Task::STATE_STARTED); |
|
26 | 26 | |
27 | 27 | $this->context = $context; |
28 | 28 | $this->task = $task; |
@@ -32,28 +32,28 @@ discard block |
||
32 | 32 | |
33 | 33 | $count = $this->task->starting(); |
34 | 34 | |
35 | - update_option( $this->context->get_option_prefix() . 'count', $count, true ); |
|
36 | - update_option( $this->context->get_option_prefix() . 'offset', 0, true ); |
|
37 | - update_option( $this->context->get_option_prefix() . 'started', time(), true ); |
|
38 | - update_option( $this->context->get_option_prefix() . 'updated', time(), true ); |
|
35 | + update_option($this->context->get_option_prefix().'count', $count, true); |
|
36 | + update_option($this->context->get_option_prefix().'offset', 0, true); |
|
37 | + update_option($this->context->get_option_prefix().'started', time(), true); |
|
38 | + update_option($this->context->get_option_prefix().'updated', time(), true); |
|
39 | 39 | |
40 | - $this->context->set_state( Background_Task::STATE_STARTED ); |
|
40 | + $this->context->set_state(Background_Task::STATE_STARTED); |
|
41 | 41 | |
42 | 42 | $this->resume(); |
43 | 43 | } |
44 | 44 | |
45 | 45 | public function resume() { |
46 | - $this->context->push_to_queue( true ); |
|
46 | + $this->context->push_to_queue(true); |
|
47 | 47 | $this->context->save()->dispatch(); |
48 | 48 | } |
49 | 49 | |
50 | 50 | public function leave() { |
51 | - $this->context->set_state( null ); |
|
51 | + $this->context->set_state(null); |
|
52 | 52 | } |
53 | 53 | |
54 | - public function task( $value ) { |
|
55 | - $offset = get_option( $this->context->get_option_prefix() . 'offset' ); |
|
56 | - $count = get_option( $this->context->get_option_prefix() . 'count' ); |
|
54 | + public function task($value) { |
|
55 | + $offset = get_option($this->context->get_option_prefix().'offset'); |
|
56 | + $count = get_option($this->context->get_option_prefix().'count'); |
|
57 | 57 | |
58 | 58 | $this->task->tick( |
59 | 59 | $value, |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | ) |
65 | 65 | ); |
66 | 66 | |
67 | - update_option( $this->context->get_option_prefix() . 'updated', time(), true ); |
|
67 | + update_option($this->context->get_option_prefix().'updated', time(), true); |
|
68 | 68 | |
69 | 69 | // Increase the offset. |
70 | - if ( ( $offset + $this->batch_size ) < $count ) { |
|
71 | - update_option( $this->context->get_option_prefix() . 'offset', $offset + $this->batch_size, true ); |
|
70 | + if (($offset + $this->batch_size) < $count) { |
|
71 | + update_option($this->context->get_option_prefix().'offset', $offset + $this->batch_size, true); |
|
72 | 72 | |
73 | 73 | return true; |
74 | 74 | } |
@@ -4,32 +4,32 @@ |
||
4 | 4 | |
5 | 5 | abstract class Abstract_Background_Task_State implements Background_Task_State { |
6 | 6 | |
7 | - /** |
|
8 | - * @var Background_Task_State |
|
9 | - */ |
|
10 | - private $state; |
|
11 | - |
|
12 | - /** |
|
13 | - * @var Background_Task |
|
14 | - */ |
|
15 | - private $context; |
|
16 | - |
|
17 | - public function __construct( $context, $state ) { |
|
18 | - $this->state = $state; |
|
19 | - $this->context = $context; |
|
20 | - } |
|
21 | - |
|
22 | - public function get_info() { |
|
23 | - $started = get_option( $this->context->get_option_prefix() . 'started' ); |
|
24 | - $offset = get_option( $this->context->get_option_prefix() . 'offset' ); |
|
25 | - $count = get_option( $this->context->get_option_prefix() . 'count', array( 0 ) ); |
|
26 | - $last_update = get_option( $this->context->get_option_prefix() . 'updated' ); |
|
27 | - |
|
28 | - return new Background_Task_Info( $this->state, $started, $offset, $count, $last_update ); |
|
29 | - } |
|
30 | - |
|
31 | - public function resume() { |
|
32 | - // do nothing. |
|
33 | - } |
|
7 | + /** |
|
8 | + * @var Background_Task_State |
|
9 | + */ |
|
10 | + private $state; |
|
11 | + |
|
12 | + /** |
|
13 | + * @var Background_Task |
|
14 | + */ |
|
15 | + private $context; |
|
16 | + |
|
17 | + public function __construct( $context, $state ) { |
|
18 | + $this->state = $state; |
|
19 | + $this->context = $context; |
|
20 | + } |
|
21 | + |
|
22 | + public function get_info() { |
|
23 | + $started = get_option( $this->context->get_option_prefix() . 'started' ); |
|
24 | + $offset = get_option( $this->context->get_option_prefix() . 'offset' ); |
|
25 | + $count = get_option( $this->context->get_option_prefix() . 'count', array( 0 ) ); |
|
26 | + $last_update = get_option( $this->context->get_option_prefix() . 'updated' ); |
|
27 | + |
|
28 | + return new Background_Task_Info( $this->state, $started, $offset, $count, $last_update ); |
|
29 | + } |
|
30 | + |
|
31 | + public function resume() { |
|
32 | + // do nothing. |
|
33 | + } |
|
34 | 34 | |
35 | 35 | } |
@@ -14,18 +14,18 @@ |
||
14 | 14 | */ |
15 | 15 | private $context; |
16 | 16 | |
17 | - public function __construct( $context, $state ) { |
|
17 | + public function __construct($context, $state) { |
|
18 | 18 | $this->state = $state; |
19 | 19 | $this->context = $context; |
20 | 20 | } |
21 | 21 | |
22 | 22 | public function get_info() { |
23 | - $started = get_option( $this->context->get_option_prefix() . 'started' ); |
|
24 | - $offset = get_option( $this->context->get_option_prefix() . 'offset' ); |
|
25 | - $count = get_option( $this->context->get_option_prefix() . 'count', array( 0 ) ); |
|
26 | - $last_update = get_option( $this->context->get_option_prefix() . 'updated' ); |
|
23 | + $started = get_option($this->context->get_option_prefix().'started'); |
|
24 | + $offset = get_option($this->context->get_option_prefix().'offset'); |
|
25 | + $count = get_option($this->context->get_option_prefix().'count', array(0)); |
|
26 | + $last_update = get_option($this->context->get_option_prefix().'updated'); |
|
27 | 27 | |
28 | - return new Background_Task_Info( $this->state, $started, $offset, $count, $last_update ); |
|
28 | + return new Background_Task_Info($this->state, $started, $offset, $count, $last_update); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | public function resume() { |
@@ -4,29 +4,29 @@ |
||
4 | 4 | |
5 | 5 | interface Background_Task_State { |
6 | 6 | |
7 | - public function enter(); |
|
8 | - |
|
9 | - public function leave(); |
|
10 | - |
|
11 | - /** |
|
12 | - * Task |
|
13 | - * |
|
14 | - * Override this method to perform any actions required on each |
|
15 | - * queue item. Return the modified item for further processing |
|
16 | - * in the next pass through. Or, return false to remove the |
|
17 | - * item from the queue. |
|
18 | - * |
|
19 | - * @param mixed $item Queue item to iterate over. |
|
20 | - * |
|
21 | - * @return mixed |
|
22 | - */ |
|
23 | - public function task( $item ); |
|
24 | - |
|
25 | - public function get_info(); |
|
26 | - |
|
27 | - /** |
|
28 | - * Try to resume an interrupted task. |
|
29 | - */ |
|
30 | - public function resume(); |
|
7 | + public function enter(); |
|
8 | + |
|
9 | + public function leave(); |
|
10 | + |
|
11 | + /** |
|
12 | + * Task |
|
13 | + * |
|
14 | + * Override this method to perform any actions required on each |
|
15 | + * queue item. Return the modified item for further processing |
|
16 | + * in the next pass through. Or, return false to remove the |
|
17 | + * item from the queue. |
|
18 | + * |
|
19 | + * @param mixed $item Queue item to iterate over. |
|
20 | + * |
|
21 | + * @return mixed |
|
22 | + */ |
|
23 | + public function task( $item ); |
|
24 | + |
|
25 | + public function get_info(); |
|
26 | + |
|
27 | + /** |
|
28 | + * Try to resume an interrupted task. |
|
29 | + */ |
|
30 | + public function resume(); |
|
31 | 31 | |
32 | 32 | } |
@@ -20,7 +20,7 @@ |
||
20 | 20 | * |
21 | 21 | * @return mixed |
22 | 22 | */ |
23 | - public function task( $item ); |
|
23 | + public function task($item); |
|
24 | 24 | |
25 | 25 | public function get_info(); |
26 | 26 |
@@ -11,53 +11,53 @@ |
||
11 | 11 | |
12 | 12 | class All_Posts_Task implements Task { |
13 | 13 | |
14 | - private $callable; |
|
15 | - |
|
16 | - public function __construct( $callable ) { |
|
17 | - $this->callable = $callable; |
|
18 | - } |
|
19 | - |
|
20 | - public function starting() { |
|
21 | - global $wpdb; |
|
22 | - |
|
23 | - // Try to get the count from transient, or load it from database. |
|
24 | - $count = get_transient( '_wl_task__all_posts_task__count' ); |
|
25 | - if ( false === $count ) { |
|
26 | - $count = $wpdb->get_var( "SELECT COUNT( 1 ) FROM $wpdb->posts" ); |
|
27 | - set_transient( '_wl_task__all_posts_task__count', $count, HOUR_IN_SECONDS ); |
|
28 | - } |
|
29 | - |
|
30 | - return $count; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @param $value mixed The incoming value. |
|
35 | - * @param $args { |
|
36 | - * |
|
37 | - * @type int $offset The index of the current item. |
|
38 | - * @type int $count The total number of items as provided by the `starting` function. |
|
39 | - * @type int $batch_size The number of items to process within this call. |
|
40 | - * } |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function tick( $value, $args ) { |
|
45 | - global $wpdb; |
|
46 | - |
|
47 | - $ids = $wpdb->get_col( |
|
48 | - $wpdb->prepare( |
|
49 | - ' |
|
14 | + private $callable; |
|
15 | + |
|
16 | + public function __construct( $callable ) { |
|
17 | + $this->callable = $callable; |
|
18 | + } |
|
19 | + |
|
20 | + public function starting() { |
|
21 | + global $wpdb; |
|
22 | + |
|
23 | + // Try to get the count from transient, or load it from database. |
|
24 | + $count = get_transient( '_wl_task__all_posts_task__count' ); |
|
25 | + if ( false === $count ) { |
|
26 | + $count = $wpdb->get_var( "SELECT COUNT( 1 ) FROM $wpdb->posts" ); |
|
27 | + set_transient( '_wl_task__all_posts_task__count', $count, HOUR_IN_SECONDS ); |
|
28 | + } |
|
29 | + |
|
30 | + return $count; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @param $value mixed The incoming value. |
|
35 | + * @param $args { |
|
36 | + * |
|
37 | + * @type int $offset The index of the current item. |
|
38 | + * @type int $count The total number of items as provided by the `starting` function. |
|
39 | + * @type int $batch_size The number of items to process within this call. |
|
40 | + * } |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function tick( $value, $args ) { |
|
45 | + global $wpdb; |
|
46 | + |
|
47 | + $ids = $wpdb->get_col( |
|
48 | + $wpdb->prepare( |
|
49 | + ' |
|
50 | 50 | SELECT ID FROM wp_posts ORDER BY ID LIMIT %d,%d; |
51 | 51 | ', |
52 | - $args['offset'], |
|
53 | - $args['batch_size'] |
|
54 | - ) |
|
55 | - ); |
|
52 | + $args['offset'], |
|
53 | + $args['batch_size'] |
|
54 | + ) |
|
55 | + ); |
|
56 | 56 | |
57 | - foreach ( $ids as $id ) { |
|
58 | - call_user_func( $this->callable, $id ); |
|
59 | - } |
|
57 | + foreach ( $ids as $id ) { |
|
58 | + call_user_func( $this->callable, $id ); |
|
59 | + } |
|
60 | 60 | |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | 63 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | private $callable; |
15 | 15 | |
16 | - public function __construct( $callable ) { |
|
16 | + public function __construct($callable) { |
|
17 | 17 | $this->callable = $callable; |
18 | 18 | } |
19 | 19 | |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | global $wpdb; |
22 | 22 | |
23 | 23 | // Try to get the count from transient, or load it from database. |
24 | - $count = get_transient( '_wl_task__all_posts_task__count' ); |
|
25 | - if ( false === $count ) { |
|
26 | - $count = $wpdb->get_var( "SELECT COUNT( 1 ) FROM $wpdb->posts" ); |
|
27 | - set_transient( '_wl_task__all_posts_task__count', $count, HOUR_IN_SECONDS ); |
|
24 | + $count = get_transient('_wl_task__all_posts_task__count'); |
|
25 | + if (false === $count) { |
|
26 | + $count = $wpdb->get_var("SELECT COUNT( 1 ) FROM $wpdb->posts"); |
|
27 | + set_transient('_wl_task__all_posts_task__count', $count, HOUR_IN_SECONDS); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | return $count; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return void |
43 | 43 | */ |
44 | - public function tick( $value, $args ) { |
|
44 | + public function tick($value, $args) { |
|
45 | 45 | global $wpdb; |
46 | 46 | |
47 | 47 | $ids = $wpdb->get_col( |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | ) |
55 | 55 | ); |
56 | 56 | |
57 | - foreach ( $ids as $id ) { |
|
58 | - call_user_func( $this->callable, $id ); |
|
57 | + foreach ($ids as $id) { |
|
58 | + call_user_func($this->callable, $id); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | } |
@@ -19,70 +19,70 @@ |
||
19 | 19 | |
20 | 20 | class Scripts_Helper { |
21 | 21 | |
22 | - /** |
|
23 | - * This function loads the javascript file according to the WordPress version. |
|
24 | - * |
|
25 | - * For WordPress < 5.0 it'll load the javascript file using the `.full` suffix i.e. the file that embeds all the |
|
26 | - * dependencies. |
|
27 | - * |
|
28 | - * For WordPress >= 5.0 it'll load the stripped down js. |
|
29 | - * |
|
30 | - * @param string $handle The handle name. |
|
31 | - * @param string $script_name The full script URL without the `.js` extension. |
|
32 | - * @param array $dependencies An array of dependencies to be added only in WordPress > 5.0. |
|
33 | - */ |
|
34 | - public static function enqueue_based_on_wordpress_version( $handle, $script_name, $dependencies, $in_footer = false ) { |
|
35 | - global $wp_version; |
|
22 | + /** |
|
23 | + * This function loads the javascript file according to the WordPress version. |
|
24 | + * |
|
25 | + * For WordPress < 5.0 it'll load the javascript file using the `.full` suffix i.e. the file that embeds all the |
|
26 | + * dependencies. |
|
27 | + * |
|
28 | + * For WordPress >= 5.0 it'll load the stripped down js. |
|
29 | + * |
|
30 | + * @param string $handle The handle name. |
|
31 | + * @param string $script_name The full script URL without the `.js` extension. |
|
32 | + * @param array $dependencies An array of dependencies to be added only in WordPress > 5.0. |
|
33 | + */ |
|
34 | + public static function enqueue_based_on_wordpress_version( $handle, $script_name, $dependencies, $in_footer = false ) { |
|
35 | + global $wp_version; |
|
36 | 36 | |
37 | - if ( version_compare( $wp_version, '5.0', '<' ) ) { |
|
38 | - $actual_script_name = "$script_name.full.js"; |
|
39 | - $actual_dependencies = array(); |
|
40 | - } else { |
|
41 | - $actual_script_name = "$script_name.js"; |
|
42 | - $actual_dependencies = $dependencies; |
|
43 | - } |
|
37 | + if ( version_compare( $wp_version, '5.0', '<' ) ) { |
|
38 | + $actual_script_name = "$script_name.full.js"; |
|
39 | + $actual_dependencies = array(); |
|
40 | + } else { |
|
41 | + $actual_script_name = "$script_name.js"; |
|
42 | + $actual_dependencies = $dependencies; |
|
43 | + } |
|
44 | 44 | |
45 | - $wordlift = \Wordlift::get_instance(); |
|
46 | - wp_enqueue_script( $handle, $actual_script_name, $actual_dependencies, $wordlift->get_version(), $in_footer ); |
|
45 | + $wordlift = \Wordlift::get_instance(); |
|
46 | + wp_enqueue_script( $handle, $actual_script_name, $actual_dependencies, $wordlift->get_version(), $in_footer ); |
|
47 | 47 | |
48 | - } |
|
49 | - /** |
|
50 | - * This function registers the javascript file according to the WordPress version. |
|
51 | - * |
|
52 | - * For WordPress < 5.0 it'll register the javascript file using the `.full` suffix i.e. the file that embeds all the |
|
53 | - * dependencies. |
|
54 | - * |
|
55 | - * For WordPress >= 5.0 it'll register the stripped down js. |
|
56 | - * |
|
57 | - * @param string $handle The handle name. |
|
58 | - * @param string $script_name The full script URL without the `.js` extension. |
|
59 | - * @param array $dependencies An array of dependencies to be added only in WordPress > 5.0. |
|
60 | - */ |
|
61 | - public static function register_based_on_wordpress_version( |
|
62 | - $handle, |
|
63 | - $script_name, |
|
64 | - $dependencies, |
|
65 | - $action = 'wp_enqueue_scripts', |
|
66 | - $in_footer = false |
|
67 | - ) { |
|
68 | - global $wp_version; |
|
48 | + } |
|
49 | + /** |
|
50 | + * This function registers the javascript file according to the WordPress version. |
|
51 | + * |
|
52 | + * For WordPress < 5.0 it'll register the javascript file using the `.full` suffix i.e. the file that embeds all the |
|
53 | + * dependencies. |
|
54 | + * |
|
55 | + * For WordPress >= 5.0 it'll register the stripped down js. |
|
56 | + * |
|
57 | + * @param string $handle The handle name. |
|
58 | + * @param string $script_name The full script URL without the `.js` extension. |
|
59 | + * @param array $dependencies An array of dependencies to be added only in WordPress > 5.0. |
|
60 | + */ |
|
61 | + public static function register_based_on_wordpress_version( |
|
62 | + $handle, |
|
63 | + $script_name, |
|
64 | + $dependencies, |
|
65 | + $action = 'wp_enqueue_scripts', |
|
66 | + $in_footer = false |
|
67 | + ) { |
|
68 | + global $wp_version; |
|
69 | 69 | |
70 | - if ( version_compare( $wp_version, '5.0', '<' ) ) { |
|
71 | - $actual_script_name = "$script_name.full.js"; |
|
72 | - $actual_dependencies = array(); |
|
73 | - } else { |
|
74 | - $actual_script_name = "$script_name.js"; |
|
75 | - $actual_dependencies = $dependencies; |
|
76 | - } |
|
70 | + if ( version_compare( $wp_version, '5.0', '<' ) ) { |
|
71 | + $actual_script_name = "$script_name.full.js"; |
|
72 | + $actual_dependencies = array(); |
|
73 | + } else { |
|
74 | + $actual_script_name = "$script_name.js"; |
|
75 | + $actual_dependencies = $dependencies; |
|
76 | + } |
|
77 | 77 | |
78 | - $wordlift = \Wordlift::get_instance(); |
|
79 | - add_action( |
|
80 | - $action, |
|
81 | - function () use ( $handle, $actual_script_name, $actual_dependencies, $wordlift, $in_footer ) { |
|
82 | - wp_register_script( $handle, $actual_script_name, $actual_dependencies, $wordlift->get_version(), $in_footer ); |
|
83 | - } |
|
84 | - ); |
|
78 | + $wordlift = \Wordlift::get_instance(); |
|
79 | + add_action( |
|
80 | + $action, |
|
81 | + function () use ( $handle, $actual_script_name, $actual_dependencies, $wordlift, $in_footer ) { |
|
82 | + wp_register_script( $handle, $actual_script_name, $actual_dependencies, $wordlift->get_version(), $in_footer ); |
|
83 | + } |
|
84 | + ); |
|
85 | 85 | |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | * @param string $script_name The full script URL without the `.js` extension. |
32 | 32 | * @param array $dependencies An array of dependencies to be added only in WordPress > 5.0. |
33 | 33 | */ |
34 | - public static function enqueue_based_on_wordpress_version( $handle, $script_name, $dependencies, $in_footer = false ) { |
|
34 | + public static function enqueue_based_on_wordpress_version($handle, $script_name, $dependencies, $in_footer = false) { |
|
35 | 35 | global $wp_version; |
36 | 36 | |
37 | - if ( version_compare( $wp_version, '5.0', '<' ) ) { |
|
37 | + if (version_compare($wp_version, '5.0', '<')) { |
|
38 | 38 | $actual_script_name = "$script_name.full.js"; |
39 | 39 | $actual_dependencies = array(); |
40 | 40 | } else { |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | $wordlift = \Wordlift::get_instance(); |
46 | - wp_enqueue_script( $handle, $actual_script_name, $actual_dependencies, $wordlift->get_version(), $in_footer ); |
|
46 | + wp_enqueue_script($handle, $actual_script_name, $actual_dependencies, $wordlift->get_version(), $in_footer); |
|
47 | 47 | |
48 | 48 | } |
49 | 49 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | ) { |
68 | 68 | global $wp_version; |
69 | 69 | |
70 | - if ( version_compare( $wp_version, '5.0', '<' ) ) { |
|
70 | + if (version_compare($wp_version, '5.0', '<')) { |
|
71 | 71 | $actual_script_name = "$script_name.full.js"; |
72 | 72 | $actual_dependencies = array(); |
73 | 73 | } else { |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | $wordlift = \Wordlift::get_instance(); |
79 | 79 | add_action( |
80 | 80 | $action, |
81 | - function () use ( $handle, $actual_script_name, $actual_dependencies, $wordlift, $in_footer ) { |
|
82 | - wp_register_script( $handle, $actual_script_name, $actual_dependencies, $wordlift->get_version(), $in_footer ); |
|
81 | + function() use ($handle, $actual_script_name, $actual_dependencies, $wordlift, $in_footer) { |
|
82 | + wp_register_script($handle, $actual_script_name, $actual_dependencies, $wordlift->get_version(), $in_footer); |
|
83 | 83 | } |
84 | 84 | ); |
85 | 85 |
@@ -17,33 +17,33 @@ |
||
17 | 17 | */ |
18 | 18 | class Templates_Ajax_Endpoint { |
19 | 19 | |
20 | - /** |
|
21 | - * Templates_Ajax_Endpoint constructor. |
|
22 | - * |
|
23 | - * Hook to `wl_templates` Ajax action. |
|
24 | - */ |
|
25 | - public function __construct() { |
|
20 | + /** |
|
21 | + * Templates_Ajax_Endpoint constructor. |
|
22 | + * |
|
23 | + * Hook to `wl_templates` Ajax action. |
|
24 | + */ |
|
25 | + public function __construct() { |
|
26 | 26 | |
27 | - add_action( 'wp_ajax_wl_templates', array( $this, 'template' ) ); |
|
27 | + add_action( 'wp_ajax_wl_templates', array( $this, 'template' ) ); |
|
28 | 28 | |
29 | - } |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Display the requested template. The template is searched in wp-content/wordlift/templates/wordlift-widget-be/ |
|
33 | - * |
|
34 | - * Non alphanumeric names (including `-`) are considered invalid. |
|
35 | - */ |
|
36 | - public function template() { |
|
31 | + /** |
|
32 | + * Display the requested template. The template is searched in wp-content/wordlift/templates/wordlift-widget-be/ |
|
33 | + * |
|
34 | + * Non alphanumeric names (including `-`) are considered invalid. |
|
35 | + */ |
|
36 | + public function template() { |
|
37 | 37 | |
38 | - $name = filter_input( INPUT_GET, 'name' ); |
|
38 | + $name = filter_input( INPUT_GET, 'name' ); |
|
39 | 39 | |
40 | - if ( 1 !== preg_match( '|^[a-z0-9\-]+$|', $name ) ) { |
|
41 | - return wp_send_json_error( 'Invalid name.' ); |
|
42 | - } |
|
40 | + if ( 1 !== preg_match( '|^[a-z0-9\-]+$|', $name ) ) { |
|
41 | + return wp_send_json_error( 'Invalid name.' ); |
|
42 | + } |
|
43 | 43 | |
44 | - require dirname( dirname( __DIR__ ) ) . "/templates/wordlift-widget-be/$name.html"; |
|
44 | + require dirname( dirname( __DIR__ ) ) . "/templates/wordlift-widget-be/$name.html"; |
|
45 | 45 | |
46 | - die(); |
|
47 | - } |
|
46 | + die(); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct() { |
26 | 26 | |
27 | - add_action( 'wp_ajax_wl_templates', array( $this, 'template' ) ); |
|
27 | + add_action('wp_ajax_wl_templates', array($this, 'template')); |
|
28 | 28 | |
29 | 29 | } |
30 | 30 | |
@@ -35,13 +35,13 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function template() { |
37 | 37 | |
38 | - $name = filter_input( INPUT_GET, 'name' ); |
|
38 | + $name = filter_input(INPUT_GET, 'name'); |
|
39 | 39 | |
40 | - if ( 1 !== preg_match( '|^[a-z0-9\-]+$|', $name ) ) { |
|
41 | - return wp_send_json_error( 'Invalid name.' ); |
|
40 | + if (1 !== preg_match('|^[a-z0-9\-]+$|', $name)) { |
|
41 | + return wp_send_json_error('Invalid name.'); |
|
42 | 42 | } |
43 | 43 | |
44 | - require dirname( dirname( __DIR__ ) ) . "/templates/wordlift-widget-be/$name.html"; |
|
44 | + require dirname(dirname(__DIR__))."/templates/wordlift-widget-be/$name.html"; |
|
45 | 45 | |
46 | 46 | die(); |
47 | 47 | } |