';
return $o;
}
/**
* Called in not singular post format gallery.
* Turn gallery into a slideshow.
*
* @since 0.1.0
* @access public
* @return do_shortcode(gallery-carousel)
*/
function bearded_gallery_carousel() {
global $post;
$content = $post->post_content;
/* Finds matches for shortcodes in the content. */
preg_match_all( '/' . get_shortcode_regex() . '/s', $content , $matches, PREG_SET_ORDER );
/* If matches are found, loop through them and check if they match one of WP's media shortcodes. */
if ( !empty( $matches ) ) {
foreach ( $matches as $shortcode ) {
/* Call the method related to the specific shortcode found and break out of the loop. */
if ( in_array( $shortcode[2], array( 'embed', 'gallery' ) ) ) {
$original_media = array_shift( $shortcode );
if( shortcode_exists('gallery-carousel') ) {
$original_media = str_replace('[gallery', '[gallery-carousel', $original_media);
}
echo apply_atomic_shortcode('gallery_carousel', $original_media );
break;
}
}
}
}
/**
* Filter and add metabox to Portfolio Info
*
* @since 0.1.0
* @access public
* @param $object OBJECT
* @param $box optional
* @return void
*/
function bearded_portfolio_metabox( $object, $box ) {
$client = esc_attr(get_post_meta( $object->ID, 'ccp-portfolio-item-client', true));
$date = esc_attr(get_post_meta( $object->ID, 'ccp-portfolio-item-date', true));
wp_nonce_field( basename( __FILE__ ), 'ccp-portfolio-item-detail-nonce' ); ?>
sanitize_text_field( esc_attr( $_POST['ccp-portfolio-item-client'] ) ),
'ccp-portfolio-item-date' => sanitize_text_field( esc_attr( $_POST['ccp-portfolio-item-date'] ) ),
);
foreach ( $meta as $meta_key => $new_meta_value ) {
/* Get the meta value of the custom field key. */
$meta_value = get_post_meta( $post_id, $meta_key, true );
/* If there is no new meta value but an old value exists, delete it. */
if ( current_user_can( 'delete_post_meta', $post_id, $meta_key ) && '' == $new_meta_value && $meta_value )
delete_post_meta( $post_id, $meta_key, $meta_value );
/* If a new meta value was added and there was no previous value, add it. */
elseif ( current_user_can( 'add_post_meta', $post_id, $meta_key ) && $new_meta_value && '' == $meta_value )
add_post_meta( $post_id, $meta_key, $new_meta_value, true );
/* If the new meta value does not match the old value, update it. */
elseif ( current_user_can( 'edit_post_meta', $post_id, $meta_key ) && $new_meta_value && $new_meta_value != $meta_value )
update_post_meta( $post_id, $meta_key, $new_meta_value );
}
}
/**
* Enqueue scripts for use in portfolio_item post type to make the date input field into datepicker
*
* @since 0.1.0
* @access public
* @return void
*/
function bearded_enqueue_portfolio_script( $hook ) {
global $post;
if( ($hook == 'post-new.php' || $hook == 'post.php') && $post->post_type === 'portfolio_item') {
wp_register_style('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
wp_enqueue_style( 'jquery-ui' );
wp_enqueue_script( 'bearded-portfolio-admin', trailingslashit( BEARDED_JS ) . 'admin/portfolio.js', array('jquery', 'jquery-ui-datepicker') , '1.0' );
}
}
/**
* Disables sidebars if viewing a one-column page.
*
* @since 0.1.0
* @param array $sidebars_widgets A multidimensional array of sidebars and widgets.
* @return array $sidebars_widgets
*/
function bearded_disable_sidebars( $sidebars_widgets ) {
global $wp_customize;
$customize = ( is_object( $wp_customize ) && $wp_customize->is_preview() ) ? true : false;
if ( (!is_admin() && !$customize && '1c' == get_theme_mod( 'theme_layout' )) || is_page_template( 'page-templates/home.php' ) ) {
$sidebars_widgets['primary'] = false;
$sidebars_widgets['shop'] = false;
}
return $sidebars_widgets;
}
/**
* Function for deciding which pages should have a one-column layout.
*
* @since 0.1.0
* @access public
* @return void
*/
function bearded_set_column() {
if( function_exists('is_woocommerce') && is_woocommerce() && !is_active_sidebar('shop') ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_one_column' );
}
elseif( ( function_exists( 'is_cart' ) && is_cart() ) || ( function_exists( 'is_checkout' ) && is_checkout() ) ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_one_column' );
}
elseif( function_exists( 'is_account_page') && is_account_page() && !is_active_sidebar('shop') ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_one_column' );
}
elseif ( !is_active_sidebar( 'primary' ) && !is_active_sidebar( 'secondary' ) ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_one_column' );
}
elseif ( is_attachment() && wp_attachment_is_image() ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_one_column' );
}
elseif ( is_page_template( 'page-templates/portfolio-3.php' ) || is_page_template( 'page-templates/portfolio-4.php' ) ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_one_column' );
}
elseif ( is_singular() && 'default' === get_post_layout( get_queried_object_id() ) ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_default_column' );
}
elseif( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
add_filter( 'theme_mod_theme_layout', 'bearded_woocommerce_column' );
}
}
/**
* Filters custom woocommerce page.
*
* @since 0.1.4
* @return boolean
*/
function bearded_is_woopage() {
if( ( function_exists( 'is_cart' ) && is_cart() ) || ( function_exists( 'is_checkout' ) && is_checkout() ) || ( function_exists( 'is_account_page' ) && is_account_page() ) ) {
return true;
}
}
function bearded_woocommerce_column() {
$layout = get_post_layout( wc_get_page_id( 'shop' ) );
return $layout;
}
/**
* Filters 'get_theme_layout' by returning 'layout-1c'.
*
* @since 0.1.0
* @param string $layout The layout of the current page.
* @return string
*/
function bearded_theme_layout_one_column( $layout ) {
return '1c';
}
function bearded_theme_layout_default_column( $layout ) {
return '2c-l';
}
/**
* Overwrites the default widths for embeds. This is especially useful for making sure videos properly
* expand the full width on video pages. This function overwrites what the $content_width variable handles
* with context-based widths.
*
* @since 0.1.0
* @access public
* @param array $args
* @return array
*/
function bearded_embed_defaults( $args ) {
$args['width'] = 570;
if ( current_theme_supports( 'theme-layouts' ) && '1c' == get_theme_mod( 'theme_layout' ) )
$args['width'] = 930;
return $args;
}
/**
* Output the featured image post thumbnail base on layout size and post format.
*
* @since 0.1.0
* @access public
* @return string html
*/
function bearded_post_thumbnail() {
$o = '';
$layout = get_theme_mod('theme_layout');
if( current_theme_supports('get-the-image') ) {
if($layout === '1c') {
if( get_post_format() === 'image' ) {
$o = get_the_image( array( 'meta_key' => false, 'link_to_post' => false, 'before' => '
';
} else {
return $content;
}
}
function bearded_color_mod($color, $shade, $amount) {
//remove # from the begiining if available and make sure that it gets appended again at the end if it was found
$newcolor = "";
$prepend = "";
if(strpos($color,'#') !== false)
{
$prepend = "#";
$color = substr($color, 1, strlen($color));
}
//iterate over each character and increment or decrement it based on the passed settings
$nr = 0;
while (isset($color[$nr]))
{
$char = strtolower($color[$nr]);
for($i = $amount; $i > 0; $i--)
{
if($shade == 'lighter')
{
switch($char)
{
case 9: $char = 'a'; break;
case 'f': $char = 'f'; break;
default: $char++;
}
}
else if($shade == 'darker')
{
switch($char)
{
case 'a': $char = '9'; break;
case '0': $char = '0'; break;
default: $char = chr(ord($char) - 1 );
}
}
}
$nr ++;
$newcolor.= $char;
}
$newcolor = $prepend.$newcolor;
return $newcolor;
}
/**
* @since 1.0
* Show admin bar only for role above subscriber
*
*/
function bearded_setup_admin_bar() {
if (!current_user_can('delete_posts') ) {
show_admin_bar(false);
}
}
/**
* @since 1.0.3
* Show admin bar only for role above subscriber
*
*/
function bearded_add_menu_id( $page_markup ) {
preg_match('/^