';
break;
case 'grid-medium':
$content = '
';
break;
}
return $content;
}
/**
Find embedded video and use standard oembed to display it
**/
/* --------------------------------------------- second function --------------------------------------------- */
function lptw_get_first_embed_media($post_id) {
$post = get_post($post_id);
$reg = preg_match('|^\s*(https?://[^\s"]+)\s*$|im', get_the_content(), $embeds);
$embed_args = Array ( 'width' => 400, 'height' => 200 );
if( !empty($embeds) ) {
//return first embed
$embed_code = wp_oembed_get( trim($embeds[0]), $embed_args );
return $embed_code;
} else {
//No embeds found
return false;
}
}
/* --------------------------------------------- Filter video output --------------------------------------------- */
add_filter('oembed_result','lptw_oembed_result', 10, 3);
function lptw_oembed_result ($html, $url, $args) {
global $post;
// $args includes custom argument
/* ---------------- only for youtube ---------------- */
/* all arguments */
//$args = array( 'rel' => '0', 'controls' => '0', 'showinfo' => '0' );
$hide_youtube_controls = get_post_meta ($post->ID, 'hide_youtube_controls', true);
if ($hide_youtube_controls == 'on') {
/* only hide controls */
$args = array( 'controls' => 0 );
} else { $args = ''; }
if ( strpos($html, 'youtu') !== false && !empty($args) ) {
$parameters = http_build_query( $args );
// Modify video parameters
$html = str_replace( '?feature=oembed', '?feature=oembed'.'&'.$parameters, $html );
}
return $html;
}
/**
Add Shortcode Builder
**/
function lptw_register_recent_posts_menu_page(){
add_menu_page( 'Advanced Recent Posts', 'Advanced Recent Posts', 'manage_options', 'recent_posts', 'lptw_recent_posts_manage_shortcodes', 'dashicons-editor-code' );
}
add_action( 'admin_menu', 'lptw_register_recent_posts_menu_page' );
/**
Include Shortcode Builder scripts and styles
**/
function lptw_recent_posts_backend_scripts() {
$screen = get_current_screen();
$post_type = $screen->id;
if ( strpos($post_type, 'page_recent_posts') !== false || strpos($post_type, 'widgets') !== false ) {
wp_register_style('lptw-recent-posts-backend-style', plugins_url( 'backend/lptw-recent-posts-backend.css', __FILE__ ) );
wp_enqueue_style('lptw-recent-posts-backend-style' );
// Add the color picker css styles
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'lptw-shortcode-builder-script', plugins_url ( 'backend/lptw-recent-posts-shortcode-builder.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
/* chosen css & js files */
wp_register_style('chosen-style', plugins_url( 'backend/chosen/chosen.min.css', __FILE__ ) );
wp_enqueue_style('chosen-style' );
wp_enqueue_script( 'chosen-script', plugins_url ( 'backend/chosen/chosen.jquery.min.js', __FILE__ ), array(), '1.4.2', true );
} else if ( $post_type = 'post' ) {
wp_register_style('lptw-recent-posts-backend-style', plugins_url( 'backend/lptw-recent-posts-backend.css', __FILE__ ) );
wp_enqueue_style('lptw-recent-posts-backend-style' );
}
}
add_action( 'admin_enqueue_scripts', 'lptw_recent_posts_backend_scripts' );
/**
Include shortcode builder code
**/
include( plugin_dir_path( __FILE__ ) . 'backend/lptw-recent-posts-backend.php');
?>