';
echo '
';
esc_html_e( 'Theme not activated: this theme requires at least WordPress Version 4.7 !', 'the-clean-blog' );
echo '
';
echo '';
}
add_action( 'admin_notices', 'thecleanblog_not_activated_admin_notice' );
// Switch back to previous theme
switch_theme( $old_theme->stylesheet );
return false;
endif;
}
add_action( 'after_switch_theme', 'thecleanblog_check_wp_version', 10, 2 );
/**
* Disable output of kirki styles if the plugin is disabled or removed.
*/
if( ! class_exists( 'Kirki' ) ) {
function thecleanblog_remove_kirki_styles() {
wp_dequeue_style( 'the-clean-blog_no-kirki' );
wp_deregister_style( 'the-clean-blog_no-kirki' );
}
add_action( 'wp_enqueue_scripts', 'thecleanblog_remove_kirki_styles', 20 );
}
/**
* Localize hero.js to asynchronously load the header image.
*/
function thecleanblog_header_script() {
// Adding custom javascript file to handle the header image.
if (is_404() || is_search()) {
wp_dequeue_script('thecleanblog-hero');
} else {
wp_enqueue_script('thecleanblog-hero', get_theme_file_uri('/assets/js/the-clean-blog-hero.js'), array('jquery'), '', true);
}
// Declare $post global if used outside of the loop.
$post = get_post();
// Check if post is object otherwise we're not in singular post.
if (!is_object($post)) {
return;
}
$heroImg = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), '');
$heroImgDefault = get_theme_mod('default_header_background_image');
if (empty($heroImgDefault)) {
$heroImgDefault = get_template_directory_uri() . '/components/header/images/default-hero.jpg';
}
$heroSettings = array (
'thecleanblog_hero_ajaxurl' => esc_url(admin_url('admin-ajax.php')),
'thecleanblog_has_post_thumbnail' => has_post_thumbnail(),
'thecleanblog_featured_image' => esc_url($heroImg[0]),
'thecleanblog_get_theme_mod' => $heroImgDefault,
);
wp_localize_script('thecleanblog-hero', 'thecleanblog_hero_set', $heroSettings);
}
add_action('wp_enqueue_scripts', 'thecleanblog_header_script');
/**
* Set background image for the header.
* PHP falback for the header image.
*
* Add inline style to the backgroung header image.
* @link https://developer.wordpress.org/reference/functions/wp_add_inline_style/
*/
function thecleanblog_header_style() {
// Declare $post global if used outside of the loop.
$post = get_post();
// Check if post is object otherwise we're not in singular post.
if (!is_object($post)) {
return;
}
// If Object
$backgroundImg = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), '');
// Add inline style to the backgroung header image.
if (has_post_thumbnail()) {
$custom_header_style = '
.intro-header {
background-image: url( ' . esc_url($backgroundImg[0]) . ' );
height: 100vh;
}
';
} else {
$custom_header_style = '
.intro-header {
background-image: url( ' . get_template_directory_uri() . '/components/header/images/default-hero.jpg' . ' );
height: 100vh;
}
';
}
wp_add_inline_style('thecleanblog-main-style', $custom_header_style);
}
add_action('wp_enqueue_scripts', 'thecleanblog_header_style');
add_action('wp_ajax_thecleanblog_header_style', 'thecleanblog_header_style');
add_action('wp_ajax_nopriv_thecleanblog_header_style', 'thecleanblog_header_style');
/**
* Provide a fallback menu featuring a 'Home' link, if no other menu has been provided.
* Add 'Create a new menu' link only if the current_user_can('edit_theme_options').
*/
function thecleanblog_fallback_menu() {
$html = '';
echo $html; /* WPCS: xss ok. */
}
/**
* Generate custom search form
*
* @param string $form Form HTML.
* @return string Modified form HTML.
*
* @link https://developer.wordpress.org/reference/functions/get_search_form/#comment-369
*
*/
function thecleanblog_search_form( $form ) {
$form =
'';
return $form;
}
add_filter( 'get_search_form', 'thecleanblog_search_form' );
function thecleanblog_header_search_form( $form ) {
$placeholder = get_theme_mod('dropdown_search_placeholder_text');
if (empty($placeholder)) {
$placeholder = esc_html_x('Search …', 'placeholder', 'the-clean-blog');
} else {
$placeholder = esc_attr($placeholder);
}
$form =
'';
return $form;
}
/**
* Customizimg the excerpt function.
*
* @link https://developer.wordpress.org/reference/functions/the_excerpt/
*/
function thecleanblog_custom_excerpt_length($length)
{
if ( is_admin() ) {
return $length;
} else {
return 15;
}
}
add_filter('excerpt_length', 'thecleanblog_custom_excerpt_length', 999);
function thecleanblog_excerpt_more($link) {
if ( is_admin() ) {
return $link;
}
$link = sprintf(' %2$s',
esc_url(get_permalink(get_the_ID())),
/* translators: %s: Name of current post */
sprintf( __( 'Read More "%s"', 'the-clean-blog' ), get_the_title( get_the_ID() ) )
);
return $link;
}
add_filter('excerpt_more', 'thecleanblog_excerpt_more');
/**
* Add social sharing icons to posts.
*
* Thanks to App Shah
* @link http://crunchify.com/how-to-create-social-sharing-button-without-any-plugin-and-script-loading-wordpress-speed-optimization-goal/
*/
function thecleanblog_social_sharing_buttons($content) {
global $post, $variable;
if(is_single()){
// Get current post URL.
$thecleanblogURL = urlencode(get_permalink());
// Get current post title.
$thecleanblogTitle = str_replace( ' ', '%20', the_title_attribute('echo=0'));
// Get Post Thumbnail for pinterest.
$thecleanblogThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
// Construct sharing URL without using any script
$emailURL = 'mailto:?subject=' . $thecleanblogTitle . '&body=Check out this post: '. $thecleanblogURL;
$twitterURL = 'https://twitter.com/intent/tweet?text='.$thecleanblogTitle.'&url='.$thecleanblogURL;
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$thecleanblogURL;
$googleURL = 'https://plus.google.com/share?url='.$thecleanblogURL;
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$thecleanblogURL.'&media='.$thecleanblogThumbnail[0].'&description='.$thecleanblogTitle;
$whatsappURL = 'whatsapp://send?text='.$thecleanblogTitle . ' ' . $thecleanblogURL;
// Add sharing button at the end of post's content.
$variable .= '';
return $content.$variable;
}else{
// if not a post/page then don't include sharing button
return $content;
}
}
add_filter( 'the_content', 'thecleanblog_social_sharing_buttons');
/**
* Use placeholders instead of labels in comment form.
*
* Thanks to Bill Erickson
* @link http://www.billerickson.net/code/use-placeholders-instead-of-labels-in-comment-form/
*
*/
/**
* Change comment form textarea to use placeholder.
*/
function thecleanblog_comment_textarea_placeholder($args)
{
$args['comment_field'] = str_replace('textarea', 'textarea placeholder="' . esc_attr__('Comment', 'the-clean-blog') .'" class="form-control"', $args['comment_field']);
return $args;
}
add_filter('comment_form_defaults', 'thecleanblog_comment_textarea_placeholder');
/**
* Comment Form Fields Placeholder.
*/
function thecleanblog_comment_form_fields($fields)
{
unset($fields['url']);
foreach ($fields as &$field) {
$field = str_replace('id="author"', 'id="author" class="form-control" placeholder="' . esc_attr__('Name *', 'the-clean-blog') . '"', $field);
$field = str_replace('id="email"', 'id="email" class="form-control" placeholder="' . esc_attr__('Email *', 'the-clean-blog') . '"', $field);
}
return $fields;
}
add_filter('comment_form_default_fields', 'thecleanblog_comment_form_fields');
/**
* Editing wp_list_comments() output.
*
* Thanks to Bruno Kos
* @link http://bbird.me/editing-wp_list_comments-output/
*/
function thecleanblog_comments($comment, $depth, $args)
{
$tag = ('div' === $args['style']) ? 'div' : 'li'; ?>
id="comment-" has_children ? 'parent' : '', $comment); ?>>
'div-comment',
'depth' => $depth,
'max_depth' => $args['max_depth'],
'before' => '',
'after' => '
'
))); ?>
'thecleanblog_email',
'twitter' => 'thecleanblog_twitter',
'facebook' => 'thecleanblog_facebook',
'github' => 'thecleanblog_github',
'instagram' => 'thecleanblog_instagram',
'youtube' => 'thecleanblog_youtube',
'google-plus' => 'thecleanblog_googleplus',
'flickr' => 'thecleanblog_flickr',
'pinterest' => 'thecleanblog_pinterest',
'tumblr' => 'thecleanblog_tumblr',
'dribbble' => 'thecleanblog_dribbble',
'linkedin' => 'thecleanblog_linkedin',
'rss' => 'thecleanblog_rss'
);
// Filtering the function, allowing user(s) to add more social sites in child theme.
return apply_filters( 'thecleanblog_social_media', $social_sites );
}
/**
* Add settings to create various social media text areas in the Customizer.
*/
function thecleanblog_social_sites($wp_customize)
{
// Section
$wp_customize->add_section('thecleanblog_social_settings', array(
'title' => __('Social Media Icons', 'the-clean-blog'),
'priority' => 30,
'active_callback' => 'is_front_page',
));
$social_sites = thecleanblog_social_media();
$priority = 5;
// Create a setting and control for each social site.
foreach ($social_sites as $social_site => $value) {
if ( $social_site == 'email' ) {
$label = esc_attr__('Email URL', 'the-clean-blog');
} elseif ( $social_site == 'twitter' ) {
$label = esc_attr__('Twitter URL', 'the-clean-blog');
} elseif ( $social_site == 'facebook' ) {
$label = esc_attr__('Facebook URL', 'the-clean-blog');
} elseif ( $social_site == 'github' ) {
$label = esc_attr__('GitHub URL', 'the-clean-blog');
} elseif ( $social_site == 'instagram' ) {
$label = esc_attr__('Instagram URL', 'the-clean-blog');
} elseif ( $social_site == 'youtube' ) {
$label = esc_attr__('YouTube URL', 'the-clean-blog');
} elseif ( $social_site == 'google-plus' ) {
$label = esc_attr__('Google Plus URL', 'the-clean-blog');
} elseif ( $social_site == 'flickr' ) {
$label = esc_attr__('Flickr URL', 'the-clean-blog');
} elseif ( $social_site == 'pinterest' ) {
$label = esc_attr__('Pinterest URL', 'the-clean-blog');
} elseif ( $social_site == 'tumblr' ) {
$label = esc_attr__('Tumblr URL', 'the-clean-blog');
} elseif ( $social_site == 'dribbble' ) {
$label = esc_attr__('Dribble URL', 'the-clean-blog');
} elseif ( $social_site == 'linkedin' ) {
$label = esc_attr__('LinkedIn URL', 'the-clean-blog');
} elseif ( $social_site == 'rss' ) {
$label = esc_attr__('RSS URL', 'the-clean-blog');
}
// Setting
$wp_customize->add_setting($social_site, array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'sanitize_callback' => 'esc_url_raw'
));
// Control
$wp_customize->add_control($social_site, array(
'type' => 'text',
'label' => $label,
'section' => 'thecleanblog_social_settings',
'priority' => $priority,
));
$priority = $priority + 5;
}
}
add_action('customize_register', 'thecleanblog_social_sites');
/**
* Get user input from the Customizer and output the linked social media icons.
*/
function thecleanblog_social_media_icons()
{
$social_sites = thecleanblog_social_media();
/* any inputs that aren't empty are stored in $active_sites array */
foreach ($social_sites as $social_site => $profile) {
if (strlen(get_theme_mod($social_site)) > 0) {
$active_sites[] = $social_site;
}
}
/* for each active social site, add it as a list item */
if (!empty($active_sites)) {
echo "";
foreach ($active_sites as $key => $active_site) {
/* setup the class */
$class = 'fa fa-' . $active_site . ' fa-stack-1x fa-inverse';
if ($active_site == 'email') {
?>
-
-
";
}
}
/**
* Add copyright date from first post date to last post date.
*
* @link http://www.wpbeginner.com/wp-tutorials/how-to-add-a-dynamic-copyright-date-in-wordpress-footer/
*/
function thecleanblog_copyright_date()
{
global $wpdb;
$copyright_dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
FROM
$wpdb->posts
WHERE
post_status = 'publish'
");
$output = '';
if ($copyright_dates) {
$copyright = "Copyright © " . get_bloginfo('name') . ' : ' . $copyright_dates[0]->firstdate;
if ($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
}
$output = $copyright;
}
return $output;
}
/**
* Hooking in JS code to affect the controls in the customizer.
*/
function thecleanblog_customizer_controls() {
wp_enqueue_script( 'thecleanblog-customizer-controls', get_template_directory_uri() . '/assets/js/the-clean-blog-customizer.js', array( 'jquery', 'customize-controls' ), false, true );
$customizerSettings = array (
'thecleanblog_control_placeholder' => esc_html__( 'Replace Default Text', 'the-clean-blog' ),
);
wp_localize_script('thecleanblog-customizer-controls', 'thecleanblog_customizer_set', $customizerSettings);
}
add_action( 'customize_controls_enqueue_scripts', 'thecleanblog_customizer_controls' );