Astra_Builder_Helper::is_component_loaded( string $component_id, string $builder_type = 'header', string $device = 'both' )
Check if component placed on the builder.
Description
Parameters
- $component_id
-
(string) (Required) component id.
- $builder_type
-
(string) (Optional) builder type.
Default value: 'header'
- $device
-
(string) (Optional) Device type (mobile, desktop and both).
Default value: 'both'
Return
(bool)
Source
File: inc/core/builder/class-astra-builder-helper.php
public static function is_component_loaded( $component_id, $builder_type = 'header', $device = 'both' ) {
$loaded_components = array();
if ( is_null( self::$loaded_grid ) ) {
$grids['header_desktop'] = astra_get_option( 'header-desktop-items', array() );
$grids['header_mobile'] = astra_get_option( 'header-mobile-items', array() );
$grids['footer_both'] = astra_get_option( 'footer-desktop-items', array() );
if ( ! empty( $grids ) ) {
foreach ( $grids as $grid_row => $row_grids ) {
$components = array();
if ( ! empty( $row_grids ) ) {
foreach ( $row_grids as $row => $grid ) {
if ( ! in_array( $row, array( 'below', 'above', 'primary', 'popup' ) ) ) {
continue;
}
if ( ! is_array( $grid ) ) {
continue;
}
$result = array_values( $grid );
if ( is_array( $result ) ) {
$loaded_component = call_user_func_array( 'array_merge', $result );
$components[] = is_array( $loaded_component ) ? $loaded_component : array();
}
}
}
$loaded_components[ $grid_row ] = call_user_func_array( 'array_merge', $components );
}
}
if ( ! empty( $loaded_components ) ) {
// For both devices(mobile & desktop).
$loaded_components['header_both'] = array_merge( $loaded_components['header_desktop'], $loaded_components['header_mobile'] );
// For All device and builder type.
$all_components = call_user_func_array( 'array_merge', array_values( $loaded_components ) );
$loaded_components['all'] = array_unique( $all_components );
}
self::$loaded_grid = $loaded_components;
}
$loaded_components = self::$loaded_grid;
if ( 'all' === $builder_type && ! empty( $loaded_components['all'] ) ) {
$is_loaded = in_array( $component_id, $loaded_components['all'], true );
} else {
$is_loaded = in_array( $component_id, $loaded_components[ $builder_type . '_' . $device ], true );
}
return $is_loaded || is_customize_preview();
}
Expand full source code Collapse full source code View on Trac