Youtube channel shortcode
I try and avoid plugins unless it means re-inventing the wheel, so when I needed to create a slider of content from a users youtube channel, this shortcode function came in very handy
Read More
add_filter( 'wp_get_attachment_image_attributes', 'my_no_image_title' );
function my_no_image_title ( $attr ) {
unset( $attr['title'] );
return $attr;
}
$u = new WP_User( $userID ); // Remove role $u->remove_role( 'subscriber' ); // Add role $u->add_role( 'editor' );
function exclude_thumbnail_from_gallery($null, $attr)
{
if (!$thumbnail_ID = get_post_thumbnail_id())
return $null; // no point carrying on if no thumbnail ID
// temporarily remove the filter, otherwise endless loop!
remove_filter('post_gallery', 'exclude_thumbnail_from_gallery');
// pop in our excluded thumbnail
if (!isset($attr['exclude']) || empty($attr['exclude']))
$attr['exclude'] = array($thumbnail_ID);
elseif (is_array($attr['exclude']))
$attr['exclude'][] = $thumbnail_ID;
// now manually invoke the shortcode handler
$gallery = gallery_shortcode($attr);
// add the filter back
add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);
// return output to the calling instance of gallery_shortcode()
return $gallery;
}
add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);
<?php
//add this to functions.php of your theme
function remove_opt_start($adddiv) {
$gettitle = array('#<h3>Personal Options</h3>#');
$adddiv = preg_replace($gettitle, '<div class="hidden">', $adddiv,1);
return $adddiv;
}
function start_remove_opt_start() { ob_start("remove_opt_start"); }
function end_remove_opt_start() { ob_end_flush(); }
function remove_opt_end($addend) {
$getname = array('#<h3>Name</h3>#');
$addend = preg_replace($getname, '</div><h3>Name</h3>',$addend,1);
return $addend;
}
function start_remove_opt_end() { ob_start("remove_opt_end"); }
function end_remove_opt_end() { ob_end_flush(); }
add_action('admin_head','start_remove_opt_start');
add_action('admin_head','start_remove_opt_end');
add_action('admin_footer','end_remove_opt_start');
add_action('admin_footer','end_remove_opt_end');
?>
<?php
/**
* only in admin area
*
* @param string $cat_name
*/
if ( is_admin() && category_exists('uncategorized') ) // cat_slug, cat_name
return true;
/**
* outside admin area
*
* is_term($term, $taxonomy = '')
* @param int|string $term The term to check
* @param string $taxonomy The taxonomy name to use
*/
if ( is_term( 'uncategorized' , 'category' ) ) // cat_slug, cat_name
return true;
else
return false;
/**
* outside admin area
*
* get_category( $category, $output = OBJECT, $filter = 'raw' )
* @param int|object $category Category ID or Category row object
* @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
* @param string $filter Optional. Default is raw or no WordPress defined filter will applied.
*/
$cat = get_category(1); // cat_ID
if ( !empty( $cat ) )
return true;
?>
/*redirect any user*/
<?php wp_redirect('http://example.com/'); exit; ?>
/*checks whether or not the current user is logged in, and redirects them to the Login Page if not. By default, the user will be redirected back to the page from whence they came (e.g., the downloads page)*/
<?php auth_redirect(); ?>
/*logout*/
/*Logout & redirect to the home page*/
<a href="<?php echo wp_logout_url(home_url()); ?>">Logout</a>
/*Logout & redirect to current page*/
<a href="<?php echo wp_logout_url(get_permalink()); ?>">Logout</a>
/*Logout & redirect to specific URL*/
<a href="<?php echo wp_logout_url('http://example.com/'); ?>">Logout</a>
/* redirect to current page */
<a href="<?php echo wp_login_url(get_permalink()); ?>" title="Login">Login to view</a>
/* redirect to home page */
<a href="<?php echo wp_login_url(get_bloginfo('wpurl')); ?>" title="Login">Login to view</a>
/* redirect to some other URL */
<a href="<?php echo wp_login_url('http://www.google.com'); ?>" title="Login">Login to view</a>
<?php // Disable PHP Timeout example // http://php.snippetdb.com //set php script timeout, 0 to disable set_time_limit(0); // your time consuming code //don't forget to reset to 30 seconds. set_time_limit(30); ?>
function sidebar_loginform(){
if (!(current_user_can('level_0'))){
$content = '
<form action="' . get_option( 'home' ) . '/wp-login.php" method="post">
<input type="text" name="log" id="log" value="' . wp_specialchars( stripslashes($user_login), 1 ) . '" size="20" />
<input type="password" name="pwd" id="pwd" size="20" />
<input type="submit" name="submit" value="login" class="button" />
<p>
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label>
<input type="hidden" name="redirect_to" value="' . $_SERVER['REQUEST_URI'] . '" />
</p>
</form>';
} else {
$content = '
<a href="' . wp_logout_url( urlencode( $_SERVER['REQUEST_URI'] ) ) . '">logout</a><br />
<a href="' . get_option('home') . '/secret-page/">secret page</a>';
}
return $content;
}
I try and avoid plugins unless it means re-inventing the wheel, so when I needed to create a slider of content from a users youtube channel, this shortcode function came in very handy
Read More