PluginProbe
Elementor Website Builder – more than just a page builder / 3.24.8
Elementor Website Builder – more than just a page builder v3.24.8
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 / modules / checklist / steps / step-base.php

step-base.php in Elementor Website Builder – more than just a page builder 3.24.8, at modules/checklist/steps/step-base.php

164 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\Checklist\Steps;
4
5 use Elementor\Core\Isolation\Wordpress_Adapter;
6 use Elementor\Core\Isolation\Wordpress_Adapter_Interface;
7 use Elementor\Modules\Checklist\Module as Checklist_Module;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 abstract class Step_Base {
14
15 /**
16 * @var string
17 * This is the key to be set to true if the step can be completed, and still be considered completed even if the user later did something to the should have it marked as not completed
18 */
19 const IS_COMPLETION_IMMUTABLE = 'is_completion_immutable';
20 const MARKED_AS_COMPLETED_KEY = 'is_marked_completed';
21 const IMMUTABLE_COMPLETION_KEY = 'is_completed';
22
23 protected array $user_progress;
24 protected Wordpress_Adapter_Interface $wordpress_adapter;
25 protected Checklist_Module $module;
26
27 /**
28 * Returns a steps current completion status
29 *
30 * @return bool
31 */
32 abstract protected function is_absolute_completed() : bool;
33
34 /**
35 * @return string
36 */
37 abstract public function get_id() : string;
38
39 /**
40 * @return string
41 */
42 abstract public function get_title() : string;
43
44 /**
45 * @return string
46 */
47 abstract public function get_description() : string;
48
49 /**
50 * For instance; 'Create 3 pages'
51 * @return string
52 */
53 abstract public function get_cta_text() : string;
54
55 /**
56 * @return string
57 */
58 abstract public function get_cta_url() : string;
59
60 /**
61 * @return bool
62 */
63 abstract public function get_is_completion_immutable() : bool;
64
65 /**
66 * Step_Base constructor.
67 *
68 * @param Checklist_Module $module
69 * @param ?Wordpress_Adapter_Interface $wordpress_adapter
70
71 * @return void
72 */
73 public function __construct( Checklist_Module $module, ?Wordpress_Adapter_Interface $wordpress_adapter = null ) {
74 $this->module = $module;
75 $this->wordpress_adapter = $wordpress_adapter ?? new Wordpress_Adapter();
76 $this->user_progress = $module->get_step_progress( $this->get_id() ) ?? $this->get_step_initial_progress();
77 }
78
79 public function get_learn_more_text() : string {
80 return esc_html__( 'Learn more', 'elementor' );
81 }
82
83 public function get_learn_more_url() : string {
84 return 'https://go.elementor.com/getting-started-with-elementor/';
85 }
86
87 /**
88 * Marking a step as completed based on user's desire
89 *
90 * @return void
91 */
92 public function mark_as_completed() : void {
93 $this->user_progress[ self::MARKED_AS_COMPLETED_KEY ] = true;
94 $this->set_step_progress();
95 }
96
97 /**
98 * Unmarking a step as completed based on user's desire
99 *
100 * @return void
101 */
102 public function unmark_as_completed() : void {
103 $this->user_progress[ self::MARKED_AS_COMPLETED_KEY ] = false;
104 $this->set_step_progress();
105 }
106
107 /**
108 * Marking a step as completed if it was completed once, and it's suffice to marketing's requirements
109 *
110 * @return void
111 */
112 public function maybe_mark_as_completed() : void {
113 $is_immutable_completed = $this->user_progress[ self::IMMUTABLE_COMPLETION_KEY ] ?? false;
114
115 if ( ! $is_immutable_completed && $this->get_is_completion_immutable() && $this->is_absolute_completed() ) {
116 $this->user_progress[ self::IMMUTABLE_COMPLETION_KEY ] = true;
117 $this->set_step_progress();
118 }
119 }
120
121 /**
122 * Returns the step marked as completed value
123 *
124 * @return bool
125 */
126 public function is_marked_as_completed() : bool {
127 return $this->user_progress[ self::MARKED_AS_COMPLETED_KEY ];
128 }
129
130 /**
131 * Returns the step completed value
132 *
133 * @return bool
134 */
135 public function is_immutable_completed() : bool {
136 return $this->user_progress[ self::IMMUTABLE_COMPLETION_KEY ];
137 }
138
139 /**
140 * Sets and returns the initial progress of the step
141 *
142 * @return array
143 */
144 public function get_step_initial_progress() : array {
145 $initial_progress = [
146 self::MARKED_AS_COMPLETED_KEY => false,
147 self::IMMUTABLE_COMPLETION_KEY => false,
148 ];
149
150 $this->module->set_step_progress( $this->get_id(), $initial_progress );
151
152 return $initial_progress;
153 }
154
155 /**
156 * Sets the step progress
157 *
158 * @return void
159 */
160 private function set_step_progress() : void {
161 $this->module->set_step_progress( $this->get_id(), $this->user_progress );
162 }
163 }
164