/** * Returns the featured video html, ready to echo. * * @since 1.0.0 * * @param int $post_id * @param string|array $size */ public function get_the_post_video($post_id = null, $size = null) { $post_id = null === $post_id ? get_the_ID() : $post_id; if (!has_post_video($post_id)) { return ''; } $meta = get_post_meta($post_id, '_fvp_video', true); $options = get_option('fvp-settings'); // Extract default and default->general options for easy access. $defaults = !empty($options['default_args']) ? $options['default_args'] : array(); $general = !empty($defaults['general']) ? $defaults['general'] : array(); // Autoplay option. Suppressed when viewing admin. $general['autoplay'] = (defined('DOING_AJAX') && DOING_AJAX || !is_admin()) && !empty($general['autoplay']) && $general['autoplay'] ? '1' : null; // Responsive scaling option. Not used when viewing the admin screen. $responsive = !empty($options['sizing']['responsive']) && $options['sizing']['responsive'] && (defined('DOING_AJAX') && DOING_AJAX || !is_admin()); // Alignment option $align = !empty($options['alignment']) ? $options['alignment'] : 'center'; $args = array('id' => !empty($meta['id']) ? $meta['id'] : null, 'provider' => !empty($meta['provider']) ? $meta['provider'] : null); $provider = $args['provider']; switch ($provider) { case 'local': $img_meta = wp_get_attachment_metadata($meta['id']); $size = $this->get_size($size, array('width' => !empty($img_meta['width']) ? $img_meta['width'] : null, 'height' => !empty($img_meta['height']) ? $img_meta['height'] : null)); $atts = array('src' => wp_get_attachment_url($meta['id']), 'autoplay' => $general['autoplay'] ? 'on' : null, 'loop' => !empty($general['loop']) ? 'on' : null, 'width' => $responsive ? $size['width'] * 8 : $size['width'], 'height' => $responsive ? $size['height'] * 8 : $size['height']); $args = array_merge($args, $atts); $embed = wp_video_shortcode($atts); $embed = apply_filters('fvp-local', $embed, $args); break; case 'raw': $embed = $meta['full']; break; default: $atts = array_merge($general, $this->get_size($size), !empty($defaults[$provider]) ? $defaults[$provider] : array(), isset($meta['parameters']) ? $meta['parameters'] : array()); $args = array_merge($args, $atts); $embed = $this->oembed->get_html($meta['full'], $atts, $provider); $embed = apply_filters('fvp-oembed', $embed, $args); break; } if (empty($embed)) { return ''; } $classnames = array('featured-video-plus' => true, 'post-thumbnail' => true, 'fvp-responsive' => $responsive); $classnames['fvp-' . $provider] = !empty($provider); $classnames['fvp-' . $align] = !empty($align); $embed = sprintf("<!-- Featured Video Plus v%s -->\n<div%s>%s</div>\n\n", FVP_VERSION, FVP_HTML::class_names($classnames, true, true), $embed); return $embed; }
public static function add_screens($screens = array()) { if (empty(self::$screens) && !empty($screens)) { add_action('admin_enqueue_scripts', array(get_class(), 'enqueue')); } self::$screens = array_merge((array) self::$screens, (array) $screens); }
/** * FVP Shortcode help tab. */ public function shortcode() { $screen = get_current_screen(); $title = esc_html__('Featured Video Plus: Shortcode', 'featured-video-plus'); $content = array(); // Tab Headline $content[] = FVP_HTML::html('h3', $title); $content[] = FVP_HTML::unordered_list(array('<code>[featured-video-plus]</code><br />' . '<span>' . esc_html__('Displays the video in its default size.', 'featured-video-plus') . '</span>', '<code>[featured-video-plus width=560]</code><br />' . '<span>' . esc_html__('Displays the video with a width of 300 pixel. Height will be fitted such that the aspect ratio is preserved.', 'featured-video-plus') . '</span>', '<code>[featured-video-plus width=560 height=315]</code><br />' . '<span>' . esc_html__('Displays the video with a fixed width and height.', 'featured-video-plus') . '</span>')); // Register tab. $screen->add_help_tab(array('id' => 'fvp_help_shortcode', 'title' => $title, 'content' => implode('', $content))); }
/** * Callback function of the metabox; generates the HTML content. * * @since 1.0.0 */ public function metabox_content() { wp_nonce_field(FVP_NAME . FVP_VERSION, 'fvp_nonce'); // Get current post's id. $post_id = isset($_GET['post']) ? $_GET['post'] : $GLOBALS['post']->ID; $options = get_option('fvp-settings'); $meta = get_post_meta($post_id, '_fvp_video', true); $has_post_video = has_post_video($post_id); $content = ''; // Current featured video. $content .= sprintf('<div class="fvp-current-video"%s>%s</div>', FVP_HTML::inline_styles(array('height: 0px' => !$has_post_video), true, true), get_the_post_video($post_id, array(256, 144))); // Input box containing the featured video URL input. $full = $has_post_video ? get_the_post_video_url($post_id) : ''; // Media gallery wrapper. $content .= sprintf('<div class="fvp-input-wrapper" data-target=".fvp-video" data-title="%1$s" data-button="%1$s">', esc_attr__('Set Featured Video', 'featured-video-plus')); // Video input. $content .= sprintf('<textarea class="fvp-video" name="fvp_video" type="text" placeholder="%s">%s</textarea>', esc_attr__('Video URL', 'featured-video-plus'), $full); // Media gallery button. $content .= sprintf('<a href="#" class="fvp-video-choose">' . '<span class="fvp-media-icon"%s></span>' . '</a>', FVP_HTML::inline_styles(array('background-image' => sprintf('url(%s/wp-admin/images/media-button.png)', get_bloginfo('wpurl'))), true, true)); // Close media gallery wrapper. $content .= '</div>'; // 'Current theme does not support Featured Images' warning. if (!current_theme_supports('post-thumbnails') && 'manual' !== $options['mode']) { $content .= '<p class="fvp-warning description">'; $content .= sprintf('<span style="font-weight: bold;">%s</span> ', esc_html__('The current theme does not support Featured Images', 'featured-video-plus')); $content .= sprintf(esc_html__('To display Featured Videos you need to use the %1$sShortcode%2$s or %1$sPHP functions%2$s. To hide this notice deactivate %3$sReplace Featured Images%4$s in the %5$sMedia Settings%6$s.', 'featured-video-plus'), '<code>', '</code>', '"<em>', '</em>"', '<a href="' . esc_attr(get_admin_url(null, '/options-media.php')) . '">', '</a>'); '</p>'; } echo "\n\n\n<!-- Featured Video Plus Metabox -->\n"; echo $content; echo "<!-- Featured Video Plus Metabox End-->\n\n\n"; }
/** * Message about support forums, rating and donating. * * @since 1.0 */ public function message() { echo FVP_HTML::html('p', sprintf(esc_html__('If you have found a bug or think a specific feature is missing, %slet me know%s in the support forum. Like this plugin? %sRate it%s or %sbuy me a cookie%s!', 'featured-video-plus'), '<a href="https://wordpress.org/support/plugin/featured-video-plus#plugin-title" title="Featured Video Plus Support Forum on WordPress.org" target="_blank" style="font-weight: bold;">', '</a>', '<a href="https://wordpress.org/support/view/plugin-reviews/featured-video-plus#plugin-title" title="Rate Featured Video Plus on WordPress.org" target="_blank" style="font-weight: bold;">', '</a>', '<a href="https://paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=AD8UKMQW2DMM6" title="Gift to the developer!" target="_blank" style="font-weight: bold;">', '</a>')); }