PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.1
Elementor Website Builder – more than just a page builder v4.2.1
4.3.0-beta3 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 All 452 releases
← All changes | modules/variables/services/variables-service.php +33 -0 4.1.04.2.1 View file →
@@ -23,8 +23,41 @@
23 23 public function get_variables_list(): array {
24 24 return $this->load()['data'];
25 25 }
26 26
27 + public function find_by_label_or_id( string $needle ): ?array {
28 + $needle = trim( $needle );
29 + $needle = ltrim( $needle, '-' );
30 +
31 + if ( '' === $needle ) {
32 + return null;
33 + }
34 +
35 + $variables = $this->get_variables_list();
36 +
37 + if ( isset( $variables[ $needle ] ) ) {
38 + $variable = $variables[ $needle ];
39 +
40 + if ( ! empty( $variable['deleted'] ) ) {
41 + return null;
42 + }
43 +
44 + return array_merge( [ 'id' => $needle ], $variable );
45 + }
46 +
47 + foreach ( $variables as $id => $variable ) {
48 + if ( ! empty( $variable['deleted'] ) ) {
49 + continue;
50 + }
51 +
52 + if ( strcasecmp( $variable['label'] ?? '', $needle ) === 0 ) {
53 + return array_merge( [ 'id' => $id ], $variable );
54 + }
55 + }
56 +
57 + return null;
58 + }
59 +
27 60 public function load() {
28 61 $collection = $this->repo->load()->serialize( true );
29 62 foreach ( $collection['data'] as $id => $variable ) {
30 63 if ( ! ElementorUtils::has_pro() && Size_Variable_Prop_Type::get_key() === $variable['type'] ) {