PluginProbe
Elementor Website Builder – more than just a page builder / 3.7.7
Elementor Website Builder – more than just a page builder v3.7.7
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / upgrade / custom-tasks-manager.php

custom-tasks-manager.php in Elementor Website Builder – more than just a page builder 3.7.7, at core/upgrade/custom-tasks-manager.php

112 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Upgrade;
3
4 use Elementor\Core\Base\Background_Task_Manager;
5 use Elementor\Plugin;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly
9 }
10
11 class Custom_Tasks_Manager extends Background_Task_Manager {
12 const TASKS_OPTION_KEY = 'elementor_custom_tasks';
13
14 const QUERY_LIMIT = 100;
15
16 public function get_name() {
17 return 'custom-task-manager';
18 }
19
20 public function get_action() {
21 return 'custom_task_manger';
22 }
23
24 public function get_plugin_name() {
25 return 'elementor';
26 }
27
28 public function get_plugin_label() {
29 return esc_html__( 'Elementor', 'elementor' );
30 }
31
32 public function get_task_runner_class() {
33 return Task::class;
34 }
35
36 public function get_query_limit() {
37 return self::QUERY_LIMIT;
38 }
39
40 protected function start_run() {
41 $custom_tasks_callbacks = $this->get_custom_tasks();
42
43 if ( empty( $custom_tasks_callbacks ) ) {
44 return;
45 }
46
47 $task_runner = $this->get_task_runner();
48
49 foreach ( $custom_tasks_callbacks as $callback ) {
50 $task_runner->push_to_queue( [
51 'callback' => $callback,
52 ] );
53 }
54
55 $this->clear_tasks_requested_to_run();
56
57 Plugin::$instance->logger->get_logger()->info( 'Elementor custom task(s) process has been queued.', [
58 'meta' => [ $custom_tasks_callbacks ],
59 ] );
60
61 $task_runner->save()->dispatch();
62 }
63
64 public function get_tasks_class() {
65 return Custom_Tasks::class;
66 }
67
68 public function get_tasks_requested_to_run() {
69 return get_option( self::TASKS_OPTION_KEY, [] );
70 }
71
72 public function clear_tasks_requested_to_run() {
73 return update_option( self::TASKS_OPTION_KEY, [], false );
74 }
75
76 public function add_tasks_requested_to_run( $tasks = [] ) {
77 $current_tasks = $this->get_tasks_requested_to_run();
78 $current_tasks = array_merge( $current_tasks, $tasks );
79
80 update_option( self::TASKS_OPTION_KEY, $current_tasks, false );
81 }
82
83 private function get_custom_tasks() {
84 $tasks_requested_to_run = $this->get_tasks_requested_to_run();
85
86 $tasks_class = $this->get_tasks_class();
87 $tasks_reflection = new \ReflectionClass( $tasks_class );
88
89 $callbacks = [];
90
91 foreach ( $tasks_reflection->getMethods() as $method ) {
92 $method_name = $method->getName();
93
94 if ( in_array( $method_name, $tasks_requested_to_run, true ) ) {
95 $callbacks[] = [ $tasks_class, $method_name ];
96 }
97 }
98
99 return $callbacks;
100 }
101
102 public function __construct() {
103 $task_runner = $this->get_task_runner();
104
105 if ( $task_runner->is_running() ) {
106 return;
107 }
108
109 $this->start_run();
110 }
111 }
112