PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.7
Elementor Website Builder – more than just a page builder v4.0.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 / modules / atomic-widgets / utils / utils.php

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

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