'list/default.php', 'list' => 'list/default.php', 'missionary' => 'list/missionary.php', 'minimal' => 'list/minimal.php' ];
$file = ABPET_Function::template_path( $templates[ $style ] ?? $templates['grid'] );
$hook_name = ( $style == 'grid' || $style == 'list' ) ? 'default' : $style;
?>
'list/default.php',
'list' => 'list/default.php',
'missionary' => 'list/missionary.php',
'minimal' => 'list/minimal.php',
];
$file = ABPET_Function::template_path( $templates[ $style ] ?? $templates['grid'] );
$hook_name = ( $style == 'grid' || $style == 'list' ) ? 'default' : $style;
?>
'',
"cat_id" => '',
"loc_id" => '',
"organizer_id" => '',
"brand_id" => '',
"speaker_id" => '',
"style" => 'grid',
"slider_style" => 'gallery',
"show" => '',
"column" => 3,
'sort' => 'ASC',
"pagination" => "yes",
"pagination-style" => "live",
'form' => 'inline',
'filter' => '',
);
}
/**
* Map the shortcode `filter` tokens to the canonical taxonomy keys.
*
* @return array
*/
public static function filter_aliases(): array {
return array(
'category' => 'category',
'categories' => 'category',
'cat' => 'category',
'cat_id' => 'category',
'location' => 'location',
'locations' => 'location',
'loc' => 'location',
'loc_id' => 'location',
'organizer' => 'organizer',
'organizers' => 'organizer',
'org' => 'organizer',
'organizer_id' => 'organizer',
'brand' => 'brand',
'brands' => 'brand',
'brand_id' => 'brand',
'speaker' => 'speaker',
'speakers' => 'speaker',
'speaker_id' => 'speaker',
);
}
/**
* Resolve the `filter` shortcode attribute into a list of taxonomy keys.
*
* Supported values:
* "" / "all" -> every globally enabled taxonomy
* "none" -> no taxonomy filter dropdowns
* "category,location" -> only the listed taxonomies
* "-speaker" / "all,-speaker" -> every taxonomy except the listed ones
*
* @param mixed $value Raw shortcode attribute.
* @return array
*/
public static function normalize_filter_taxonomies( $value ): array {
$all = array( 'category', 'location', 'organizer', 'brand', 'speaker' );
$value = is_array( $value ) ? implode( ',', $value ) : (string) $value;
$value = strtolower( trim( $value ) );
if ( '' === $value || 'all' === $value || '*' === $value ) {
return $all;
}
if ( in_array( $value, array( 'none', 'no', 'off', 'false', '0' ), true ) ) {
return array();
}
$aliases = self::filter_aliases();
$included = array();
$excluded = array();
foreach ( array_map( 'trim', explode( ',', $value ) ) as $token ) {
if ( '' === $token ) {
continue;
}
$exclude = false;
if ( 0 === strpos( $token, '-' ) ) {
$exclude = true;
$token = ltrim( $token, '-' );
}
$token = $aliases[ $token ] ?? '';
if ( '' === $token ) {
continue;
}
if ( $exclude ) {
$excluded[] = $token;
} else {
$included[] = $token;
}
}
$included = array_values( array_unique( $included ) );
$excluded = array_values( array_unique( $excluded ) );
if ( empty( $included ) && empty( $excluded ) ) {
return $all;
}
if ( empty( $included ) ) {
return array_values( array_diff( $all, $excluded ) );
}
$included = array_values( array_diff( $included, $excluded ) );
return array_values( array_intersect( $all, $included ) );
}
private static function normalize_attributes( $attribute ): array {
$params = shortcode_atts( self::default_attribute(), is_array( $attribute ) ? $attribute : array() );
$params['post_id'] = absint( $params['post_id'] );
$params['cat_id'] = absint( $params['cat_id'] );
$params['loc_id'] = absint( $params['loc_id'] );
$params['organizer_id'] = absint( $params['organizer_id'] );
$params['brand_id'] = absint( $params['brand_id'] );
$params['speaker_id'] = absint( $params['speaker_id'] );
$params['column'] = min( 10, max( 1, absint( $params['column'] ) ?: 3 ) );
$params['show'] = min( 100, max( 0, absint( $params['show'] ) ) );
$params['style'] = in_array( $params['style'], array( 'grid', 'list', 'missionary', 'minimal' ), true ) ? $params['style'] : 'grid';
$params['slider_style'] = in_array( $params['slider_style'], array( 'gallery', 'slider' ), true ) ? $params['slider_style'] : 'gallery';
$params['sort'] = strtoupper( (string) $params['sort'] ) === 'DESC' ? 'DESC' : 'ASC';
$params['pagination'] = in_array( strtolower( (string) $params['pagination'] ), array( 'no', 'false', 'off', '0' ), true ) ? 'no' : 'yes';
$params['pagination_style'] = in_array( $params['pagination-style'], array( 'live', 'number' ), true ) ? $params['pagination-style'] : 'live';
$params['filter'] = is_string( $params['filter'] ) ? sanitize_text_field( $params['filter'] ) : '';
$params['filter_taxonomies'] = self::normalize_filter_taxonomies( $params['filter'] );
return $params;
}
}
new ABPET_Shortcodes();
}