ID );
?>
__('Featured', 'blogsquare')]);
});
add_action('manage_post_posts_custom_column', function($column_key, $post_id) {
if ($column_key == 'blogsquare-featured') {
$blogsquare_featured = get_post_meta($post_id, 'blogsquare-featured', 'yes');
if ($blogsquare_featured == 'yes') {
echo '';
} else {
echo '';
}
}
}, 10, 2);
add_filter('manage_edit-post_sortable_columns', function($columns) {
$columns['blogsquare-featured'] = 'blogsquare-featured';
return $columns;
});
add_action('pre_get_posts', function($query) {
if (!is_admin()) {
return;
}
$orderby = $query->get('orderby');
if ($orderby == 'blogsquare-featured') {
$query->set('meta_key', 'blogsquare-featured');
$query->set('meta_value', 'yes');
$query->set('orderby', 'date');
$query->set('order', 'DESC');
}
});
/**
* Search Filter
*/
if ( ! function_exists( 'blogsquare_search_filter' ) && ( ! is_admin() ) ) :
function blogsquare_search_filter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','blogsquare_search_filter');
endif;
/**
* Filter the except length to 27 characters.
*
* @param int $length Excerpt length.
* @return int (Maybe) modified excerpt length.
*/
if ( ! function_exists( 'blogsquare_custom_excerpt_length' ) ) :
function blogsquare_custom_excerpt_length( $length ) {
if ( is_admin() ) {
return $length;
} else {
return '28';
}
}
add_filter( 'excerpt_length', 'blogsquare_custom_excerpt_length', 999 );
endif;
/**
* Customize excerpt more.
*/
if ( ! function_exists( 'blogsquare_excerpt_more' ) ) :
function blogsquare_excerpt_more( $more ) {
if ( is_admin() ) {
return $more;
} else {
return '... ';
}
}
add_filter( 'excerpt_more', 'blogsquare_excerpt_more' );
endif;
/**
* Display the first (single) category of post.
*/
if ( ! function_exists( 'blogsquare_first_category' ) ) :
function blogsquare_first_category() {
$category = get_the_category();
if ($category) {
echo '' . esc_html( $category[0]->name ) .' ';
}
}
endif;
/**
* Flush out the transients used in blogsquare_categorized_blog.
*/
if ( ! function_exists( 'blogsquare_category_transient_flusher' ) ) :
function blogsquare_category_transient_flusher() {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Like, beat it. Dig?
delete_transient( 'blogsquare_categories' );
}
add_action( 'edit_category', 'blogsquare_category_transient_flusher' );
add_action( 'save_post', 'blogsquare_category_transient_flusher' );
endif;
/**
* Disable specified widgets.
*/
if ( ! function_exists( 'blogsquare_disable_specified_widgets' ) ) :
function blogsquare_disable_specified_widgets( $sidebars_widgets ) {
if ( isset($sidebars_widgets['header-ad']) ) {
if ( is_array($sidebars_widgets['header-ad']) ) {
foreach($sidebars_widgets['header-ad'] as $i => $widget) {
if( (strpos($widget, 'wpenjoy-') === false) ) {
unset($sidebars_widgets['header-ad'][$i]);
}
}
}
}
if ( isset($sidebars_widgets['content-ad']) ) {
if ( is_array($sidebars_widgets['content-ad']) ) {
foreach($sidebars_widgets['content-ad'] as $i => $widget) {
if( (strpos($widget, 'wpenjoy-') === false) ) {
unset($sidebars_widgets['content-ad'][$i]);
}
}
}
}
return $sidebars_widgets;
}
add_filter( 'sidebars_widgets', 'blogsquare_disable_specified_widgets' );
endif;
/*
* Limit Tags Count
*/
//Register tag cloud filter callback
add_filter('widget_tag_cloud_args', 'blogsquare_tag_widget_limit');
//Limit number of tags inside widget
function blogsquare_tag_widget_limit($args){
//Check if taxonomy option inside widget is set to tags
if(isset($args['taxonomy']) && $args['taxonomy'] == 'post_tag'){
$args['number'] = '30'; //Limit number of tags
}
return $args;
}
/**
* Fix skip link focus in IE11.
*
* This does not enqueue the script because it is tiny and because it is only for IE11,
* thus it does not warrant having an entire dedicated blocking script being loaded.
*
* @link https://git.io/vWdr2
*/
function blogsquare_skip_link_focus_fix() {
// The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
?>
array(
'class' => true,
'xmlns' => true,
'width' => true,
'height' => true,
'viewbox' => true,
'aria-hidden' => true,
'role' => true,
'focusable' => true,
),
'path' => array(
'fill' => true,
'fill-rule' => true,
'd' => true,
'transform' => true,
),
'polygon' => array(
'fill' => true,
'fill-rule' => true,
'points' => true,
'transform' => true,
'focusable' => true,
),
)
);
if ( ! $svg ) {
return false;
}
return $svg;
}
}
/**
* Miscellaneous
*/
/**
* Toggles animation duration in milliseconds.
*
* @return int Duration in milliseconds
*/
function blogsquare_toggle_duration() {
/**
* Filters the animation duration/speed used usually for submenu toggles.
*
* @since BlogSquare 1.0
*
* @param int $duration Duration in milliseconds.
*/
$duration = apply_filters( 'blogsquare_toggle_duration', 250 );
return $duration;
}
/**
* Menus
*/
/**
* Filters classes of wp_list_pages items to match menu items.
*
* Filter the class applied to wp_list_pages() items with children to match the menu class, to simplify.
* styling of sub levels in the fallback. Only applied if the match_menu_classes argument is set.
*
* @param string[] $css_class An array of CSS classes to be applied to each list item.
* @param WP_Post $page Page data object.
* @param int $depth Depth of page, used for padding.
* @param array $args An array of arguments.
* @param int $current_page ID of the current page.
* @return array CSS class names.
*/
function blogsquare_filter_wp_list_pages_item_classes( $css_class, $page, $depth, $args, $current_page ) {
// Only apply to wp_list_pages() calls with match_menu_classes set to true.
$match_menu_classes = isset( $args['match_menu_classes'] );
if ( ! $match_menu_classes ) {
return $css_class;
}
// Add current menu item class.
if ( in_array( 'current_page_item', $css_class, true ) ) {
$css_class[] = 'current-menu-item';
}
// Add menu item has children class.
if ( in_array( 'page_item_has_children', $css_class, true ) ) {
$css_class[] = 'menu-item-has-children';
}
return $css_class;
}
add_filter( 'blogsquare_page_css_class', 'blogsquare_filter_wp_list_pages_item_classes', 10, 5 );
/**
* Adds a Sub Nav Toggle to the Expanded Menu and Mobile Menu.
*
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @return stdClass An object of wp_nav_menu() arguments.
*/
function blogsquare_add_sub_toggles_to_main_menu( $args, $item, $depth ) {
// Add sub menu toggles to the Expanded Menu with toggles.
if ( isset( $args->show_toggles ) && $args->show_toggles ) {
// Wrap the menu item link contents in a div, used for positioning.
$args->before = '';
$args->after = '';
// Add a toggle to items with children.
if ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
$toggle_target_string = '.menu-modal .menu-item-' . $item->ID . ' > .sub-menu';
$toggle_duration = blogsquare_toggle_duration();
// Add the sub menu toggle.
$args->after .= '';
}
// Close the wrapper.
$args->after .= '
';
// Add sub menu icons to the primary menu without toggles.
} elseif ( 'primary' === $args->theme_location ) {
if ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
$args->after = '';
} else {
$args->after = '';
}
}
return $args;
}
add_filter( 'nav_menu_item_args', 'blogsquare_add_sub_toggles_to_main_menu', 10, 3 );
/*
* Customize archive title
*/
add_filter( 'get_the_archive_title', function ($title) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '' . get_the_author() . '' ;
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
} elseif (is_post_type_archive()) {
$title = post_type_archive_title( '', false );
}
return $title;
});
/*
* Remove parentheses from categories widget
*/
function blogsquare_categories_postcount_filter ($variable) {
$variable = str_replace('(', ' ', $variable);
$variable = str_replace(')', ' ', $variable);
return $variable;
}
add_filter('wp_list_categories','blogsquare_categories_postcount_filter');
/*
* Admin Notice
*/
function blogsquare_notice() {
global $current_user;
$theme = wp_get_theme();
$user_id = $current_user->ID;
if (!get_user_meta($user_id, 'blogsquare_notice_ignore')) {
echo '';
}
}
add_action('admin_notices', 'blogsquare_notice');
/*
* Admin Notice Ignore
*/
function blogsquare_notice_ignore() {
global $current_user;
$user_id = $current_user->ID;
if (isset($_GET['blogsquare-ignore-notice'])) {
add_user_meta($user_id, 'blogsquare_notice_ignore', 'true', true);
}
}
add_action('admin_init', 'blogsquare_notice_ignore');
/* Add Menu Link to Admin Bar */
function blogsquare_custom_toolbar_link($wp_admin_bar) {
$args = array(
'id' => 'blogsquare-pro',
'title' => esc_html('Upgrade to PRO Theme', 'blogsquare'),
'href' => esc_url( wp_get_theme()->get( 'AuthorURI' ) . '/themes/blogsquare-pro' ),
'meta' => array(
'target'=> '_blank',
)
);
$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'blogsquare_custom_toolbar_link', 999);
/* Admin Style */
function blogsquare_admin_init() {
if ( is_admin() ) {
wp_enqueue_style("blogsquare-admin-css", get_template_directory_uri() . "/assets/css/admin-style.css", false, "1.0", "all");
}
}
add_action( 'admin_enqueue_scripts', 'blogsquare_admin_init' );