File: /home/kashmira/www/razitahir.com/wp-content/themes/upress/functions.php
<?php
/**
* UrduPress functions and definitions
*
* @package UrduPress
*/
if ( ! function_exists( 'upress_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 upress_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Urdu News, use a find and replace
* to change 'urdupress' to the name of your theme in all the template files
*/
load_theme_textdomain( 'urdupress', 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 http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
add_image_size( 'postblock-grid', 360, 280, array( 'center', 'center' ) );
add_image_size( 'post-head', 1200, 630);
add_image_size( 'video-grid', 400, 300);
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => esc_html__( 'Primary Menu', 'urdupress' ),
) );
/*
* 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',
) );
/*
* Enable support for Post Formats.
* See http://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
) );
// Set up the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'upress_custom_background_args', array(
'default-color' => 'ffffff',
'default-image' => '',
) ) );
//HTML5 Search Form
add_theme_support( 'html5', array( 'search-form' ) );
}
endif; // upress_setup
add_action( 'after_setup_theme', 'upress_setup' );
/**
* Ping the product with the server.
*/
function stylothemes_product_ping () {
global $stylo_sdk_license;
if(isset($stylo_sdk_license) && $stylo_sdk_license != '') {
$license_data = get_option('stylocore_license_data');
$host = $_SERVER['HTTP_HOST'];
if(! empty($license_data) && ! empty($host)) {
$stylo_sdk_license->ping($license_data['license_key'], "UrduPress", $host);
}
}
}
add_action('after_switch_theme', 'stylothemes_product_ping');
/**
* 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 upress_content_width() {
$GLOBALS['content_width'] = apply_filters( 'upress_content_width', 640 );
}
add_action( 'after_setup_theme', 'upress_content_width', 0 );
/**
* Register widget area.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
function upress_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Default Sidebar', 'urdupress' ),
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => esc_html__( 'Sidebar - Single Video', 'urdupress' ),
'id' => 'single-video',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => esc_html__( 'Mini Sidebar (Single Post)', 'urdupress' ),
'id' => 'sidebar-mini-single',
'description' => 'Small right side sidebar for single post view',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widget 1', 'urdupress' ),
'id' => 'footer-1',
'description' => '',
'before_widget' => '<div id="%1$s" class="footer-widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widget 2', 'urdupress' ),
'id' => 'footer-2',
'description' => '',
'before_widget' => '<div id="%1$s" class="footer-widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widget 3', 'urdupress' ),
'id' => 'footer-3',
'description' => '',
'before_widget' => '<div id="%1$s" class="footer-widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widget 4', 'urdupress' ),
'id' => 'footer-4',
'description' => '',
'before_widget' => '<div id="%1$s" class="footer-widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'AD - Header', 'urdupress' ),
'id' => 'header-ad',
'description' => '',
'before_widget' => '<div id="%1$s" class="advert-widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'AD - Above Post Content', 'urdupress' ),
'id' => 'above-post-ad',
'description' => '',
'before_widget' => '<div id="%1$s" class="advert-widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'AD - Below Post Content', 'urdupress' ),
'id' => 'below-post-ad',
'description' => '',
'before_widget' => '<div id="%1$s" class="advert-widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
}
add_action( 'widgets_init', 'upress_widgets_init' );
/**
* Load Translations file.
*/
require get_template_directory() . '/inc/translations.php';
function wpdocs_custom_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );
function new_excerpt_more( $more ) {
$translation = upress_translation();
return ' <a class="read-more" href="' . get_permalink( get_the_ID() ) . '">' . __( $translation['forms']['button_readmore'], 'urdupress' ) . '</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );
/**
* Add autoplay functionality in featured youtube video
*/
if ( true == get_theme_mod( 'videos_page_featured_autoplay', 'on' ) ) :
function modify_youtube_embed_url($html) {
if(strpos($html, 'youtu.be') !== false || strpos($html, 'youtube.com') !== false){
return str_replace("?feature=oembed", "?feature=oembed&autoplay=1&mute=1", $html);
}
}
add_filter('oembed_result', 'modify_youtube_embed_url');
endif;
/***************************************
* Elementor Theme Builder Integration
****************************************/
function urdupress_register_elementor_locations( $elementor_theme_manager ) {
$elementor_theme_manager->register_location( 'header' );
}
add_action( 'elementor/theme/register_locations', 'urdupress_register_elementor_locations' );
/***************************************
* Search Results Modification
****************************************/
function custom_search_filter($query) {
if ($query->is_search) {
$query->set('post_type', array('post', 'video'));
}
return $query;
}
add_filter('pre_get_posts','custom_search_filter');
/************************************************************************
* Import Demo Data
*************************************************************************/
if( function_exists('stylothemes_is_valid_license')) {
if(stylothemes_is_valid_license() == true) {
function ocdi_import_files() {
return [
[
'import_file_name' => 'Urdu - News & Magazine',
'categories' => [ 'News' ],
'local_import_file' => trailingslashit( get_template_directory() ) . 'layouts/demo/default/content.xml',
'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'layouts/demo/default/widgets.json',
'local_import_customizer_file' => trailingslashit( get_template_directory() ) . 'layouts/demo/default/customizer.dat',
'import_preview_image_url' => get_template_directory_uri() . '/layouts/demo/default/preview.jpg',
'preview_url' => 'https://stylothemes.com/demo/urdupress/',
],
[
'import_file_name' => 'Sindhi - News & Magazine',
'categories' => [ 'News' ],
'local_import_file' => trailingslashit( get_template_directory() ) . 'layouts/demo/sindhi/content.xml',
'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'layouts/demo/sindhi/widgets.json',
'local_import_customizer_file' => trailingslashit( get_template_directory() ) . 'layouts/demo/sindhi/customizer.dat',
'import_preview_image_url' => get_template_directory_uri() . '/layouts/demo/sindhi/preview.jpg',
'preview_url' => 'https://stylothemes.com/demo/urdupress-sindhi',
],
[
'import_file_name' => 'VidPress - Video & Media',
'categories' => [ 'Videos' ],
'local_import_file' => trailingslashit( get_template_directory() ) . 'layouts/demo/videos/content.xml',
'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'layouts/demo/videos/widgets.json',
'local_import_customizer_file' => trailingslashit( get_template_directory() ) . 'layouts/demo/videos/customizer.dat',
'import_preview_image_url' => get_template_directory_uri() . '/layouts/demo/videos/preview.jpg',
'preview_url' => 'https://stylothemes.com/demo/urdupress-video',
],
];
}
add_filter( 'ocdi/import_files', 'ocdi_import_files' );
}
}
/************************************************************************
* Extended Example:
* Way to set menu and set home page.
*************************************************************************/
function ocdi_after_import_setup() {
// Assign menus to their locations.
$main_menu = get_term_by( 'name', 'Top Nav', 'nav_menu' );
set_theme_mod( 'nav_menu_locations', array(
'primary' => $main_menu->term_id,
)
);
// Assign front page and posts page (blog page).
$front_page_id = get_page_by_title( 'Homepage v1' );
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $front_page_id->ID );
}
add_action( 'pt-ocdi/after_import', 'ocdi_after_import_setup' );
function ocdi_plugin_page_setup( $default_settings ) {
$default_settings['parent_slug'] = 'themes.php';
$default_settings['page_title'] = esc_html__( 'One Click Demo Import' , 'one-click-demo-import' );
$default_settings['menu_title'] = esc_html__( 'Demo Importer' , 'one-click-demo-import' );
$default_settings['capability'] = 'import';
$default_settings['menu_slug'] = 'one-click-demo-import';
return $default_settings;
}
add_filter( 'ocdi/plugin_page_setup', 'ocdi_plugin_page_setup' );
/**
* Remove empty paragraphs created by wpautop()
* @author Ryan Hamilton
* @link https://gist.github.com/Fantikerz/5557617
*/
function remove_empty_p( $content ) {
$content = force_balance_tags( $content );
$content = preg_replace( '#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content );
$content = preg_replace( '~\s?<p>(\s| )+</p>\s?~', '', $content );
return $content;
}
add_filter('the_content', 'remove_empty_p', 20, 1);
function stylo_admin_notice__error() {
?>
<div class="notice notice-error">
<p>License Key is not active, some theme features may not work. <a href="admin.php?page=stylo-settings">Activate License Now</a></p>
</div>
<?php
}
/**
* Register Scripts & Styles.
*/
require get_template_directory() . '/inc/register-scripts.php';
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
/** Include the TGM_Plugin_Activation class. */
require_once dirname( __FILE__ ) . '/inc/class-tgm-plugin-activation.php';
/* Install Required Plugins*/
include_once('inc/install-plugins.php');
/**
* Load Theme Admin Panel.
*/
if( function_exists('stylothemes_is_valid_license')) {
if(stylothemes_is_valid_license() == true) {
if(class_exists('Kirki\Panel')) {
require get_template_directory() . '/inc/customizer-control.php';
}
} else {
add_action( 'admin_notices', 'stylo_admin_notice__error' );
}
}
/* Check for updates */
require get_template_directory() . '/inc/update-checker.php';
$update_checker = new ThemeUpdateChecker(
'upress',
'https://update.stylothemes.com/themes/upress/info.json'
);
$update_checker->checkForUpdates();