File: /home/retoti4c1e1s/public_html/thameenah.com/wp-content/themes/covernews-pro/functions.php
<?php
/**
* CoverNews functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package CoverNews
*/
// Exit if accessed directly.
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* Define Theme Constants.
*/
defined( 'ESHF_COMPATIBILITY_TMPL' ) or define( 'ESHF_COMPATIBILITY_TMPL', 'covernews' );
if ( !function_exists( 'covernews_setup' ) ) {
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
/**
*
*/
/**
*
*/
function covernews_setup()
{
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on CoverNews, use a find and replace
* to change 'covernews' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'covernews', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
add_image_size(
'covernews-slider-full',
1115,
715,
true
);
// width, height, crop
add_image_size(
'covernews-slider-center',
800,
500,
true
);
// width, height, crop
add_image_size(
'covernews-featured',
1024,
0,
false
);
// width, height, crop
add_image_size(
'covernews-medium',
540,
340,
true
);
// width, height, crop
add_image_size(
'covernews-medium-square',
400,
250,
true
);
// width, height, crop
/*
* Enable support for Post Formats on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/post-formats/
*/
add_theme_support( 'post-formats', array( 'image', 'video', 'gallery' ) );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'aft-primary-nav' => esc_html__( 'Primary Menu', 'covernews' ),
'aft-top-nav' => esc_html__( 'Top Menu', 'covernews' ),
'aft-social-nav' => esc_html__( 'Social Menu', 'covernews' ),
'aft-footer-nav' => esc_html__( 'Footer Menu', 'covernews' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption'
) );
// Set up the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'covernews_custom_background_args', array(
'default-color' => 'f7f7f7',
'default-image' => '',
) ) );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support( 'custom-logo', array(
'flex-width' => true,
'flex-height' => true,
) );
/*theme updater*/
if ( is_admin() ) {
//require (get_template_directory().'/inc/updater/theme-updater.php');
}
/*
* Add theme support for gutenberg block
*/
add_theme_support( 'align-wide' );
add_theme_support( 'responsive-embeds' );
add_theme_support( 'wp-block-styles' );
add_theme_support( 'appearance-tools' );
add_theme_support( 'custom-spacing' );
add_theme_support( 'custom-units' );
add_theme_support( 'custom-line-height' );
add_theme_support( 'border' );
add_theme_support( 'link-color' );
}
}
add_action( 'after_setup_theme', 'covernews_setup' );
/**
* function for google fonts
*/
if ( !function_exists( 'covernews_fonts_url' ) ) {
/**
* Return fonts URL.
*
* @since 1.0.0
* @return string Fonts URL.
*/
function covernews_fonts_url()
{
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
$covernews_primary_font = covernews_get_option( 'primary_font' );
$covernews_secondary_font = covernews_get_option( 'secondary_font' );
$covernews_fonts = array();
$covernews_fonts[] = $covernews_primary_font;
$covernews_fonts[] = $covernews_secondary_font;
$i = 0;
for ( $i = 0 ; $i < count( $covernews_fonts ) ; $i++ ) {
if ( 'off' !== sprintf( _x( 'on', '%s font: on or off', 'covernews' ), $covernews_fonts[$i] ) ) {
$fonts[] = $covernews_fonts[$i];
}
}
if ( $fonts ) {
$fonts_url = add_query_arg( array(
'family' => urldecode( implode( '|', $fonts ) ),
'subset' => urldecode( $subsets ),
), 'https://fonts.googleapis.com/css' );
}
return $fonts_url;
}
}
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function covernews_content_width()
{
$GLOBALS['content_width'] = apply_filters( 'covernews_content_width', 640 );
}
add_action( 'after_setup_theme', 'covernews_content_width', 0 );
/**
* Load Init for Hook files.
*/
require get_template_directory() . '/inc/custom-style.php';
/**
* Enqueue scripts and styles.
*/
function covernews_scripts()
{
$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' );
$fonts_url = covernews_fonts_url();
$covernews_version = wp_get_theme()->get( 'Version' );
// wp_enqueue_style('font-awesome-v6', get_template_directory_uri().'/assets/font-awesome-v6/css/all'.$min.'.css');
wp_enqueue_style( 'covernews-icons', get_template_directory_uri() . '/assets/covernews-icons/style.css' );
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/bootstrap/css/bootstrap' . $min . '.css' );
// wp_enqueue_style('sidr', get_template_directory_uri().'/assets/sidr/css/jquery.sidr.dark.css');
wp_enqueue_style( 'magnific-popup', get_template_directory_uri() . '/assets/magnific-popup/magnific-popup.css' );
if ( !empty($fonts_url) ) {
wp_enqueue_style(
'covernews-google-fonts',
$fonts_url,
array(),
null
);
}
if ( class_exists( 'WooCommerce' ) ) {
wp_enqueue_style( 'covernews-woocommerce-style', get_template_directory_uri() . '/assets/woocommerce.css' );
}
wp_enqueue_style( 'covernews-style', get_stylesheet_uri() );
wp_add_inline_style( 'covernews-style', covernews_custom_style() );
wp_enqueue_script(
'covernews-navigation',
get_template_directory_uri() . '/js/navigation.js',
array(),
$covernews_version,
true
);
wp_enqueue_script(
'covernews-skip-link-focus-fix',
get_template_directory_uri() . '/js/skip-link-focus-fix.js',
array(),
$covernews_version,
true
);
// wp_enqueue_script('sidr', get_template_directory_uri().'/assets/sidr/js/jquery.sidr'.$min.'.js', array('jquery'), '', true);
wp_enqueue_script(
'magnific-popup',
get_template_directory_uri() . '/assets/magnific-popup/jquery.magnific-popup' . $min . '.js',
array( 'jquery' ),
$covernews_version,
true
);
wp_enqueue_script(
'matchheight',
get_template_directory_uri() . '/assets/jquery-match-height/jquery.matchHeight' . $min . '.js',
array( 'jquery' ),
$covernews_version,
true
);
if ( is_page_template( 'tmpl-front-page.php' ) || is_front_page() || is_home() ) {
$show_main_news_section = covernews_get_option( 'show_main_news_section' );
$show_flash_news_section = covernews_get_option( 'show_flash_news_section' );
if ( $show_main_news_section ) {
wp_enqueue_style(
'slick',
get_template_directory_uri() . '/assets/slick/css/slick.css',
array(),
$covernews_version
);
wp_enqueue_script(
'slick',
get_template_directory_uri() . '/assets/slick/js/slick' . $min . '.js',
array( 'jquery' ),
$covernews_version,
true
);
wp_enqueue_script(
'bootstrap',
get_template_directory_uri() . '/assets/bootstrap/js/bootstrap' . $min . '.js',
array( 'jquery' ),
$covernews_version,
true
);
}
if ( $show_flash_news_section ) {
wp_enqueue_script(
'marquee',
get_template_directory_uri() . '/assets/marquee/jquery.marquee.js',
array( 'jquery' ),
$covernews_version,
true
);
}
}
// wp_enqueue_script('sticky-sidebar', get_template_directory_uri() . '/assets/theiaStickySidebar/theia-sticky-sidebar.min.js', array('jquery'), '', true);
$disable_sticky_header_option = covernews_get_option( 'disable_sticky_header_option' );
if ( $disable_sticky_header_option == false ) {
wp_enqueue_script(
'covernews-fixed-header-script',
get_template_directory_uri() . '/assets/fixed-header-script.js',
array( 'jquery' ),
'',
1
);
}
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
wp_enqueue_script(
'covernews-script',
get_template_directory_uri() . '/assets/script.js',
array( 'jquery' ),
'',
true
);
}
add_action( 'wp_enqueue_scripts', 'covernews_scripts', 99999 );
/**
* Enqueue admin scripts and styles.
*
* @since CoverNews 1.0.0
*/
function covernews__admin_scripts( $hook )
{
if ( 'widgets.php' === $hook ) {
wp_enqueue_media();
wp_enqueue_script(
'covernews-widgets',
get_template_directory_uri() . '/assets/widgets.js',
array( 'jquery' ),
'1.0.0',
true
);
}
wp_enqueue_style( 'covernews-notice', get_template_directory_uri() . '/assets/notice.css' );
}
add_action( 'admin_enqueue_scripts', 'covernews__admin_scripts' );
/**
* Functions which adds instagram posts in footer.
*/
//require get_template_directory().'/inc/template-instagram.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom Multi Author tags for this theme.
*/
require get_template_directory() . '/inc/multi-author.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-images.php';
/**
* Functions which enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer/customizer.php';
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/init.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/ocdi.php';
/**
* Load Jetpack compatibility file.
*/
if ( defined( 'JETPACK__VERSION' ) ) {
require get_template_directory() . '/inc/jetpack.php';
}
/**
* Load WooCommerce compatibility file.
*/
if ( class_exists( 'WooCommerce' ) ) {
require get_template_directory() . '/inc/woocommerce.php';
}
/**
* Descriptions on Header Menu
* @author AF themes
* @param string $item_output, HTML outputp for the menu item
* @param object $item, menu item object
* @param int $depth, depth in menu structure
* @param object $args, arguments passed to wp_nav_menu()
* @return string $item_output
*/
function covernews_header_menu_desc(
$item_output,
$item,
$depth,
$args
)
{
if ( 'aft-primary-nav' == $args->theme_location && $item->description ) {
$item_output = str_replace( '</a>', '<span class="menu-description">' . $item->description . '</span></a>', $item_output );
}
return $item_output;
}
add_filter(
'walker_nav_menu_start_el',
'covernews_header_menu_desc',
10,
4
);
/**
* Freemius integration
* Since 2.1.1
*/
if ( !function_exists( 'covernews_fs' ) ) {
// Create a helper function for easy SDK access.
function covernews_fs()
{
global $covernews_fs ;
if ( !isset( $covernews_fs ) ) {
// Include Freemius SDK.
require_once dirname( __FILE__ ) . '/freemius/start.php';
$covernews_fs = fs_dynamic_init( array(
'id' => '5688',
'slug' => 'covernews-pro',
'premium_slug' => 'covernews-pro',
'type' => 'theme',
'public_key' => 'pk_7f522ddbc6d10ae5b377234ea4c9b',
'is_premium' => true,
'is_premium_only' => true,
'has_addons' => false,
'has_paid_plans' => true,
'has_affiliation' => 'selected',
'menu' => array(
'slug' => 'covernews-pro-details',
'support' => false,
'parent' => array(
'slug' => 'themes.php',
),
),
'is_live' => true,
) );
}
return $covernews_fs;
}
// Init Freemius.
covernews_fs();
// Signal that SDK was initiated.
do_action( 'covernews_fs_loaded' );
}
/**
* Get old license key from EDD
* Since 2.1.1
*/
function covernews_get_edd_key()
{
return get_option( 'covernews-pro_license_key' );
}
/**
* Freemius EDD License Match integration
* Since 2.1.1
*/
if ( !function_exists( 'covernews_fs_license_key_migration' ) ) {
/**
* Freemius EDD License Match integration
* Since 2.1.1
*/
function covernews_fs_license_key_migration()
{
if ( !covernews_fs()->has_api_connectivity() || covernews_fs()->is_registered() ) {
// No connectivity OR the user already opted-in to Freemius.
return;
}
if ( 'pending' != get_option( 'covernews_fs_migrated_edd', 'pending' ) ) {
return;
}
// Get the license key from the previous eCommerce platform's storage.
$license_key = covernews_get_edd_key();
if ( empty($license_key) ) {
// No key to migrate.
return;
}
// Get the first 32 characters.
$license_key = substr( $license_key, 0, 32 );
try {
$next_page = covernews_fs()->activate_migrated_license( $license_key );
} catch ( Exception $e ) {
update_option( 'covernews_fs_migrated_edd', 'unexpected_error' );
return;
}
if ( covernews_fs()->can_use_premium_code() ) {
update_option( 'covernews_fs_migrated_edd', 'done' );
if ( is_string( $next_page ) ) {
fs_redirect( $next_page );
}
} else {
update_option( 'covernews_fs_migrated_edd', 'failed' );
}
}
add_action( 'admin_init', 'covernews_fs_license_key_migration' );
}