| 1 |
<?php |
| 2 |
|
| 3 |
namespace HelloPlus\Classes; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
use HelloPlus\Includes\Utils as Theme_Utils; |
| 10 |
|
| 11 |
class Widget_Utils { |
| 12 |
|
| 13 |
public static function get_configured_breakpoints(): array { |
| 14 |
$active_devices = Theme_Utils::elementor()->breakpoints->get_active_devices_list( [ 'reverse' => true ] ); |
| 15 |
$active_breakpoint_instances = Theme_Utils::elementor()->breakpoints->get_active_breakpoints(); |
| 16 |
|
| 17 |
$devices_options = []; |
| 18 |
|
| 19 |
foreach ( $active_devices as $device_key ) { |
| 20 |
$device_label = 'desktop' === $device_key ? esc_html__( 'Desktop', 'hello-plus' ) : $active_breakpoint_instances[ $device_key ]->get_label(); |
| 21 |
$devices_options[ $device_key ] = $device_label; |
| 22 |
} |
| 23 |
|
| 24 |
return [ |
| 25 |
'active_devices' => $active_devices, |
| 26 |
'devices_options' => $devices_options, |
| 27 |
]; |
| 28 |
} |
| 29 |
|
| 30 |
public static function maybe_render_text_html( |
| 31 |
\Elementor\Widget_Base $context, |
| 32 |
string $render_key, |
| 33 |
string $css_class, |
| 34 |
string $settings_text, |
| 35 |
string $settings_tag = 'p' |
| 36 |
): void { |
| 37 |
if ( '' === $settings_text ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
$context->add_render_attribute( $render_key, 'class', $css_class ); |
| 42 |
|
| 43 |
$element_html = sprintf( |
| 44 |
'<%1$s %2$s>%3$s</%1$s>', |
| 45 |
\Elementor\Utils::validate_html_tag( $settings_tag ), |
| 46 |
$context->get_render_attribute_string( $render_key ), |
| 47 |
$settings_text, |
| 48 |
); |
| 49 |
|
| 50 |
echo wp_kses_post( $element_html ); |
| 51 |
} |
| 52 |
|
| 53 |
public static function get_available_menus(): array { |
| 54 |
$menus = wp_get_nav_menus(); |
| 55 |
|
| 56 |
$options = []; |
| 57 |
|
| 58 |
foreach ( $menus as $menu ) { |
| 59 |
$options[ $menu->slug ] = $menu->name; |
| 60 |
} |
| 61 |
|
| 62 |
return $options; |
| 63 |
} |
| 64 |
|
| 65 |
public static function get_empty_menus(): array { |
| 66 |
$menus = wp_get_nav_menus(); |
| 67 |
|
| 68 |
$options = []; |
| 69 |
|
| 70 |
foreach ( $menus as $menu ) { |
| 71 |
$menu_items = wp_get_nav_menu_items( $menu->term_id ); |
| 72 |
|
| 73 |
if ( empty( $menu_items ) ) { |
| 74 |
$options[ $menu->term_id ] = $menu->slug; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
return $options; |
| 79 |
} |
| 80 |
} |
| 81 |
|