PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.3
Elementor Website Builder – more than just a page builder v3.32.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 / atomic-widgets / utils.php

utils.php in Elementor Website Builder – more than just a page builder 3.32.3, at modules/atomic-widgets/utils.php

51 lines 1.2 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\AtomicWidgets;
4
5 use Elementor\Plugin;
6 use Elementor\Modules\AtomicWidgets\Elements\Atomic_Element_Base;
7 use Elementor\Modules\AtomicWidgets\Elements\Atomic_Widget_Base;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 class Utils {
14 public static function is_atomic( $element_instance ): bool {
15 return $element_instance instanceof Atomic_Element_Base ||
16 $element_instance instanceof Atomic_Widget_Base;
17 }
18
19 public static function generate_id( string $prefix = '', $existing_ids = [] ): string {
20 do {
21 $generated = substr(
22 bin2hex( random_bytes( 4 ) ),
23 0,
24 7
25 );
26
27 $id = "$prefix{$generated}";
28 } while ( in_array( $id, $existing_ids, true ) );
29
30 return $id;
31 }
32
33 public static function traverse_post_elements( string $post_id, callable $callback ): void {
34 $document = Plugin::$instance->documents->get_doc_for_frontend( $post_id );
35
36 if ( ! $document ) {
37 return;
38 }
39
40 $elements_data = $document->get_elements_data();
41
42 if ( empty( $elements_data ) ) {
43 return;
44 }
45
46 Plugin::$instance->db->iterate_data( $elements_data, function( $element_data ) use ( $callback ) {
47 call_user_func( $callback, $element_data );
48 } );
49 }
50 }
51