/** * Filter a Movie's Metadata slug to handle aliases. * * @since 1.1 * * @param string $slug Metadata slug * * @return string Filtered slug */ public static function filter_movie_meta_aliases($slug) { $aliases = WPMOLY_Settings::get_supported_movie_meta_aliases(); $_slug = str_replace('movie_', '', $slug); if (isset($aliases[$_slug])) { $slug = $aliases[$_slug]; } return $slug; }
/** * Movie Meta shortcode. Display various movie metas with or * without label. This shortcode supports aliases. * * @since 1.1 * * @param array Shortcode attributes * @param string Shortcode content * @param string Shortcode tag name * * @return string Shortcode display */ public static function movie_meta_shortcode($atts = array(), $content = null, $tag = null) { // Is this an alias? if (!is_null($tag) && "{$tag}_shortcode" != __FUNCTION__) { $tag = apply_filters('wpmoly_filter_movie_meta_aliases', $tag); $atts['key'] = str_replace('movie_', '', $tag); } $atts = self::filter_shortcode_atts('movie_meta', $atts); if ('' == $atts['key']) { return $content; } $movie_id = WPMOLY_Shortcodes::find_movie_id($atts['id'], $atts['title']); if (is_null($movie_id)) { return $content; } $atts['movie_id'] = $movie_id; // Caching $name = apply_filters('wpmoly_cache_name', 'movie_meta_shortcode', $atts); $content = WPMOLY_Cache::output($name, function () use($atts, $content) { extract($atts); $_meta = WPMOLY_Settings::get_supported_movie_meta(); $alias = WPMOLY_Settings::get_supported_movie_meta_aliases(); if (!isset($_meta[$key]) && isset($alias[$key])) { $key = $alias[$key]; } $meta = wpmoly_get_movie_meta($movie_id, $key); $meta = apply_filters("wpmoly_format_movie_{$key}", $meta); $meta = apply_filters("wpmoly_format_movie_field", $meta); $view = 'shortcodes/metadata.php'; $attributes = array('key' => $key, 'meta' => $meta); if ($label) { $attributes['title'] = __($_meta[$key]['title'], 'wpmovielibrary'); $view = 'shortcodes/metadata-label.php'; } $content = WPMovieLibrary::render_template($view, $attributes, $require = 'always'); return $content; }, $echo = false); return $content; }