'wishlist', 'label' => __( 'Wishlist', 'ai-eshop-optimizer' ) ),
array( 'slug' => 'cart', 'label' => __( 'Cart', 'ai-eshop-optimizer' ) ),
array( 'slug' => 'account', 'label' => __( 'My account', 'ai-eshop-optimizer' ) ),
array( 'slug' => 'stores', 'label' => __( 'Stores', 'ai-eshop-optimizer' ) ),
array( 'slug' => 'search', 'label' => __( 'Search', 'ai-eshop-optimizer' ) ),
array( 'slug' => 'menu', 'label' => __( 'Menu', 'ai-eshop-optimizer' ) ),
);
}
public static function device_defaults( $device ) {
if ( 'desktop' === $device ) {
return array(
array( 'slug' => 'stores', 'enabled' => true, 'label' => true ),
array( 'slug' => 'account', 'enabled' => true, 'label' => true ),
array( 'slug' => 'wishlist', 'enabled' => true, 'label' => false ),
array( 'slug' => 'cart', 'enabled' => true, 'label' => false ),
array( 'slug' => 'search', 'enabled' => false, 'label' => false ),
array( 'slug' => 'menu', 'enabled' => false, 'label' => false ),
);
}
return array(
array( 'slug' => 'wishlist', 'enabled' => true, 'label' => false ),
array( 'slug' => 'cart', 'enabled' => true, 'label' => false ),
array( 'slug' => 'menu', 'enabled' => true, 'label' => false ),
array( 'slug' => 'account', 'enabled' => false, 'label' => false ),
array( 'slug' => 'stores', 'enabled' => false, 'label' => false ),
array( 'slug' => 'search', 'enabled' => false, 'label' => false ),
);
}
public static function style_defaults( $device ) {
return array( 'gap' => '', 'color' => '', 'hover' => '' );
}
public static function resolve_config( $device ) {
$device = in_array( $device, self::devices(), true ) ? $device : 'mobile';
$catalog = self::items_catalog();
$label_of = array();
foreach ( $catalog as $g ) {
$label_of[ $g['slug'] ] = $g['label'];
}
$defaults = self::device_defaults( $device );
$def_by = array();
foreach ( $defaults as $d ) {
$def_by[ $d['slug'] ] = $d;
}
$opt = get_option( self::OPTION_KEY, array() );
$saved = ( is_array( $opt ) && isset( $opt[ $device ] ) && is_array( $opt[ $device ] ) ) ? $opt[ $device ] : array();
$rows = ( isset( $saved['items'] ) && is_array( $saved['items'] ) ) ? $saved['items'] : array();
$items = array();
$seen = array();
foreach ( $rows as $row ) {
if ( ! is_array( $row ) || empty( $row['slug'] ) ) {
continue;
}
$slug = sanitize_key( $row['slug'] );
if ( ! isset( $label_of[ $slug ] ) || isset( $seen[ $slug ] ) ) {
continue;
}
$items[] = array(
'slug' => $slug,
'label_text' => $label_of[ $slug ],
'enabled' => isset( $row['enabled'] ) ? (bool) $row['enabled'] : (bool) $def_by[ $slug ]['enabled'],
'label' => isset( $row['label'] ) ? (bool) $row['label'] : ! empty( $def_by[ $slug ]['label'] ),
);
$seen[ $slug ] = true;
}
foreach ( $defaults as $d ) {
if ( isset( $seen[ $d['slug'] ] ) ) {
continue;
}
$items[] = array(
'slug' => $d['slug'],
'label_text' => $label_of[ $d['slug'] ],
'enabled' => (bool) $d['enabled'],
'label' => ! empty( $d['label'] ),
);
}
$sd = self::style_defaults( $device );
$style = array(
'gap' => isset( $saved['gap'] ) ? (string) $saved['gap'] : $sd['gap'],
'color' => isset( $saved['color'] ) ? (string) $saved['color'] : $sd['color'],
'hover' => isset( $saved['hover'] ) ? (string) $saved['hover'] : $sd['hover'],
);
return array( 'items' => $items, 'style' => $style );
}
public function register_block() {
if ( ! function_exists( 'register_block_type' ) ) {
return;
}
if ( class_exists( 'AIEO_Engine_Blocks', false ) && AIEO_Engine_Blocks::none_rendered() ) { return; }
if ( class_exists( 'WP_Block_Type_Registry' ) && WP_Block_Type_Registry::get_instance()->is_registered( self::BLOCK_NAME ) ) {
return;
}
$base = dirname( __DIR__ );
$css_rel = 'assets/css/aieo-header-actions.css';
$js_rel = 'assets/js/aieo-header-actions.js';
if ( is_file( $base . '/' . $css_rel ) && ! wp_style_is( 'aieo-header-actions', 'registered' ) ) {
wp_register_style( 'aieo-header-actions', plugins_url( $css_rel, $base . '/plugin.php' ), array(), (string) filemtime( $base . '/' . $css_rel ) );
wp_style_add_data( 'aieo-header-actions', 'path', wp_normalize_path( $base . '/' . $css_rel ) );
}
if ( is_file( $base . '/' . $js_rel ) && ! wp_script_is( 'aieo-header-actions', 'registered' ) ) {
wp_register_script( 'aieo-header-actions', plugins_url( $js_rel, $base . '/plugin.php' ), array(), (string) filemtime( $base . '/' . $js_rel ), array( 'in_footer' => true, 'strategy' => 'defer' ) );
}
register_block_type( self::BLOCK_NAME, array(
'api_version' => 3,
'title' => __( 'Rooster One Header Actions', 'ai-eshop-optimizer' ),
'category' => 'theme',
'icon' => 'menu-alt',
'description' => __( 'The header icon row (wishlist, cart, account, stores, search, menu). Configure per device under DMM → Header icons.', 'ai-eshop-optimizer' ),
'keywords' => array( 'header', 'menu', 'burger', 'navigator', 'cart', 'wishlist', 'search', 'aieo' ),
'attributes' => array(
'device' => array( 'type' => 'string', 'default' => 'mobile' ),
),
'supports' => array( 'html' => false ),
'style_handles' => array( 'aieo-header-actions' ),
'view_script_handles' => array( 'aieo-header-actions' ),
'render_callback' => array( $this, 'render_block' ),
) );
}
private function svg( $paths, $device, $label_on, $round = false ) {
$size = $label_on ? 20 : 22;
$stroke = ( 'mobile' === $device ) ? '2' : '1.6';
$caps = $round ? ' stroke-linecap="round" stroke-linejoin="round"' : '';
return '';
}
private function svg_for( $slug ) {
switch ( $slug ) {
case 'wishlist':
return '