PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.3
Elementor Website Builder – more than just a page builder v4.2.3
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 4.2.3, at modules/checklist/steps/step-base.php

209 lines 5.4 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\Core\Isolation\Elementor_Adapter;
8 use Elementor\Core\Isolation\Elementor_Adapter_Interface;
9 use Elementor\Modules\Checklist\Module as Checklist_Module;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 abstract class Step_Base {
16 /**
17 * @var string
18 * 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
19 */
20 const IS_COMPLETION_IMMUTABLE = 'is_completion_immutable';
21 const MARKED_AS_COMPLETED_KEY = 'is_marked_completed';
22 const IMMUTABLE_COMPLETION_KEY = 'is_immutable_completed';
23 const ABSOLUTE_COMPLETION_KEY = 'is_absolute_completed';
24
25 private array $user_progress;
26 protected Wordpress_Adapter_Interface $wordpress_adapter;
27 protected Elementor_Adapter_Interface $elementor_adapter;
28 protected ?array $promotion_data;
29 protected Checklist_Module $module;
30
31 /**
32 * Returns a steps current completion status
33 *
34 * @return bool
35 */
36 abstract protected function is_absolute_completed(): bool;
37
38 /**
39 * @return string
40 */
41 abstract public function get_id(): string;
42
43 /**
44 * @return string
45 */
46 abstract public function get_title(): string;
47
48 /**
49 * @return string
50 */
51 abstract public function get_description(): string;
52
53 /**
54 * For instance; 'Create 3 pages'
55 *
56 * @return string
57 */
58 abstract public function get_cta_text(): string;
59
60 /**
61 * @return string
62 */
63 abstract public function get_cta_url(): string;
64
65 /**
66 * @return bool
67 */
68 abstract public function get_is_completion_immutable(): bool;
69
70 /**
71 * @return string
72 */
73 abstract public function get_image_src(): string;
74
75 /**
76 * Step_Base constructor.
77 *
78 * @param Checklist_Module $module
79 * @param ?Wordpress_Adapter_Interface $wordpress_adapter
80 * @param ?Elementor_Adapter_Interface $elementor_adapter
81 * @return void
82 */
83 public function __construct( Checklist_Module $module, ?Wordpress_Adapter_Interface $wordpress_adapter = null, ?Elementor_Adapter_Interface $elementor_adapter = null, $promotion_data = null ) {
84 $this->module = $module;
85 $this->wordpress_adapter = $wordpress_adapter ?? new Wordpress_Adapter();
86 $this->elementor_adapter = $elementor_adapter ?? new Elementor_Adapter();
87 $this->promotion_data = $promotion_data;
88
89 $this->user_progress = $module->get_step_progress( $this->get_id() ) ?? $this->get_step_initial_progress();
90 }
91
92 /**
93 * Returns step visibility (by-default step is visible)
94 *
95 * @return bool
96 */
97 public function is_visible(): bool {
98 return true;
99 }
100
101 public function get_learn_more_text(): string {
102 return esc_html__( 'Learn more', 'elementor' );
103 }
104
105 public function get_learn_more_url(): string {
106 return 'https://go.elementor.com/getting-started-with-elementor/';
107 }
108
109 public function update_step( array $step_data ): void {
110 $allowed_properties = [
111 self::MARKED_AS_COMPLETED_KEY => $step_data[ self::MARKED_AS_COMPLETED_KEY ] ?? null,
112 self::IMMUTABLE_COMPLETION_KEY => $step_data[ self::IMMUTABLE_COMPLETION_KEY ] ?? null,
113 self::ABSOLUTE_COMPLETION_KEY => $step_data[ self::ABSOLUTE_COMPLETION_KEY ] ?? null,
114 ];
115
116 foreach ( $allowed_properties as $key => $value ) {
117 if ( null !== $value ) {
118 $this->user_progress[ $key ] = $value;
119 }
120 }
121
122 $this->set_step_progress();
123 }
124
125 /**
126 * Marking a step as completed based on user's desire
127 *
128 * @return void
129 */
130 public function mark_as_completed(): void {
131 $this->update_step( [ self::MARKED_AS_COMPLETED_KEY => true ] );
132 }
133
134 /**
135 * Unmarking a step as completed based on user's desire
136 *
137 * @return void
138 */
139 public function unmark_as_completed(): void {
140 $this->update_step( [ self::MARKED_AS_COMPLETED_KEY => false ] );
141 }
142
143 /**
144 * Marking a step as completed if it was completed once, and it's suffice to marketing's requirements
145 *
146 * @return void
147 */
148 public function maybe_immutably_mark_as_completed(): void {
149 $is_immutable_completed = $this->user_progress[ self::IMMUTABLE_COMPLETION_KEY ] ?? false;
150
151 if ( ! $is_immutable_completed && $this->get_is_completion_immutable() && $this->is_absolute_completed() ) {
152 $this->update_step( [
153 self::MARKED_AS_COMPLETED_KEY => false,
154 self::IMMUTABLE_COMPLETION_KEY => true,
155 ] );
156 }
157 }
158
159 /**
160 * Returns the step marked as completed value
161 *
162 * @return bool
163 */
164 public function is_marked_as_completed(): bool {
165 return $this->user_progress[ self::MARKED_AS_COMPLETED_KEY ];
166 }
167
168 /**
169 * Returns the step completed value
170 *
171 * @return bool
172 */
173 public function is_immutable_completed(): bool {
174 return $this->get_is_completion_immutable() && $this->user_progress[ self::IMMUTABLE_COMPLETION_KEY ] ?? false;
175 }
176
177 /**
178 * Sets and returns the initial progress of the step
179 *
180 * @return array
181 */
182 public function get_step_initial_progress(): array {
183 $initial_progress = [
184 self::MARKED_AS_COMPLETED_KEY => false,
185 self::IMMUTABLE_COMPLETION_KEY => false,
186 ];
187
188 $this->module->set_step_progress( $this->get_id(), $initial_progress );
189
190 return $initial_progress;
191 }
192
193 /**
194 * @return ?array
195 */
196 public function get_promotion_data(): ?array {
197 return $this->promotion_data;
198 }
199
200 /**
201 * Sets the step progress
202 *
203 * @return void
204 */
205 private function set_step_progress(): void {
206 $this->module->set_step_progress( $this->get_id(), $this->user_progress );
207 }
208 }
209