Advertisement
sahilmultani

Untitled

Mar 31st, 2022
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.74 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * wp-magazine functions and definitions
  5.  *
  6.  * @package WP Magazine
  7.  */
  8.  
  9.  
  10. if ( !function_exists( 'wp_magazine_setup' ) ) {
  11.     /**
  12.      * Sets up theme defaults and registers support for various WordPress features.
  13.      *
  14.      * Note that this function is hooked into the after_setup_theme hook, which
  15.      * runs before the init hook. The init hook is too late for some features, such
  16.      * as indicating support for post thumbnails.
  17.      */
  18.     function wp_magazine_setup()
  19.     {
  20.         /*
  21.          * Make theme available for translation.
  22.          * Translations can be filed in the /languages/ directory.
  23.          * If you're building a theme based on wp-magazine, use a find and replace
  24.          * to change 'wp-magazine' to the name of your theme in all the template files
  25.          */
  26.         load_theme_textdomain( 'wp-magazine', get_template_directory() . '/languages' );
  27.         // Add default posts and comments RSS feed links to head.
  28.         add_theme_support( 'automatic-feed-links' );
  29.         /*
  30.          * Let WordPress manage the document title.
  31.          * By adding theme support, we declare that this theme does not use a
  32.          * hard-coded <title> tag in the document head, and expect WordPress to
  33.          * provide it for us.
  34.          */
  35.         add_theme_support( 'title-tag' );
  36.         /*
  37.          * Enable support for Post Thumbnails on posts and pages.
  38.          *
  39.          * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  40.          */
  41.         add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
  42.         add_theme_support( 'post-templates' );
  43.         // This theme uses wp_nav_menu() in one location.
  44.         register_nav_menus( array(
  45.             'primary' => esc_html__( 'Primary Menu', 'wp-magazine' ),
  46.             'top'     => esc_html__( 'Top Menu', 'wp-magazine' ),
  47.         ) );
  48.         /*
  49.          * Switch default core markup for search form, comment form, and comments
  50.          * to output valid HTML5.
  51.          */
  52.         add_theme_support( 'html5', array(
  53.             'search-form',
  54.             'comment-form',
  55.             'comment-list',
  56.             'gallery',
  57.             'caption'
  58.         ) );
  59.         /*
  60.          * Enable support for Post Formats.
  61.          * See http://codex.wordpress.org/Post_Formats
  62.          */
  63.         add_theme_support( 'custom-logo', array(
  64.             'height'     => 90,
  65.             'width'      => 400,
  66.             'flex-width' => true,
  67.         ) );
  68.         // Set up the WordPress core custom background feature.
  69.         add_theme_support( 'custom-background', apply_filters( 'wp_magazine_custom_background_args', array(
  70.             'default-color' => 'ffffff',
  71.             'default-image' => '',
  72.         ) ) );
  73.         add_theme_support( "custom-header", array(
  74.             'default-color' => 'ffffff',
  75.         ) );
  76.         remove_theme_support( 'header_textcolor' );
  77.         add_editor_style();
  78.         add_theme_support( "wp-block-styles" );
  79.         add_theme_support( "responsive-embeds" );
  80.         add_theme_support( "align-wide" );
  81.         add_image_size(
  82.             'wp-magazine-header-ad-image',
  83.             729,
  84.             90,
  85.             true
  86.         );
  87.     }
  88.    
  89.     // wp_magazine_setup
  90. }
  91.  
  92. add_action( 'after_setup_theme', 'wp_magazine_setup' );
  93.  
  94. /**
  95.  * Enqueue scripts and styles.
  96.  */
  97. function wp_magazine_scripts()
  98. {
  99.     $defaults = wp_magazine_default_fonts_attributes();
  100.     $font_family = get_theme_mod( 'font_family', 'Source Sans Pro' );
  101.     $detail_post_page_font_family = get_theme_mod( 'detail_post_page_font_family', 'Source Sans Pro' );
  102.     $site_identity_font_family = esc_attr( get_theme_mod( 'site_identity_font_family', 'Muli' ) );
  103.     $category_news_title_font_family = esc_attr( get_theme_mod( 'category_news_title_font_family', 'Playfair Display' ) );
  104.     $featured_news_title_font_family = esc_attr( get_theme_mod( 'featured_news_title_font_family', 'Playfair Display' ) );
  105.     $blog_news_title_font_family = esc_attr( get_theme_mod( 'blog_news_title_font_family', 'Playfair Display' ) );
  106.     $slider_news_title_font_family = esc_attr( get_theme_mod( 'slider_news_title_font_family', 'Playfair Display' ) );
  107.     $headline_news_title_font_family = esc_attr( get_theme_mod( 'headline_news_title_font_family', 'Playfair Display' ) );
  108.     $menu_font_family = esc_attr( get_theme_mod( 'menu_font_family', 'Source Sans Pro' ) );
  109.     for ( $i = 1 ;  $i <= 6 ;  $i++ ) {
  110.         $heading_font_family = esc_attr( get_theme_mod( 'wp_magazine_heading_' . $i . '_font_family', 'Montserrat' ) );
  111.     }
  112.     wp_enqueue_style(
  113.         'bootstrap',
  114.         get_template_directory_uri() . '/css/bootstrap.min.css',
  115.         array(),
  116.         '3.3.6'
  117.     );
  118.     wp_enqueue_style(
  119.         'font-awesome',
  120.         get_template_directory_uri() . '/css/font-awesome.min.css',
  121.         array(),
  122.         '4.6.1'
  123.     );
  124.     wp_enqueue_style(
  125.         'owl',
  126.         get_template_directory_uri() . '/css/owl.carousel.min.css',
  127.         array(),
  128.         '2.2.1'
  129.     );
  130.     $fonts = wp_magazine_google_fonts();
  131.     foreach ( $fonts as $font ) {
  132.         wp_enqueue_style( 'wp-magazine-googlefonts', 'https://fonts.googleapis.com/css?family=' . esc_attr( $font_family ) . ':200,300,400,500,600,700,800,900|' . esc_attr( $detail_post_page_font_family ) . ':200,300,400,500,600,700,800,900|' . $site_identity_font_family . ':200,300,400,500,600,700,800,900|' . $category_news_title_font_family . ':200,300,400,500,600,700,800,900|' . $heading_font_family . ':200,300,400,500,600,700,800,900|' . $featured_news_title_font_family . ':200,300,400,500,600,700,800,900|' . $blog_news_title_font_family . ':200,300,400,500,600,700,800,900|' . $slider_news_title_font_family . ':200,300,400,500,600,700,800,900|' . $headline_news_title_font_family . ':200,300,400,500,600,700,800,900|' . $menu_font_family . ':200,300,400,500,600,700,800,900|' );
  133.     }
  134.     wp_enqueue_style( 'wp-magazine-style', get_template_directory_uri() . '/style.css' );
  135.     wp_enqueue_style( 'wp-magazine-layout', get_template_directory_uri() . '/css/layout.min.css' );
  136.    
  137.     if ( is_rtl() ) {
  138.         wp_enqueue_style( 'bootstrap-rtl', get_template_directory_uri() . '/css/bootstrap-rtl.css', array( 'bootstrap' ) );
  139.         wp_enqueue_style( 'wp-magazine-rtl', get_template_directory_uri() . '/css/style-rtl.css', array( 'wp-magazine-style' ) );
  140.         wp_enqueue_style( 'wp-magazine-layout-rtl', get_template_directory_uri() . '/css/layout-rtl.css', array( 'wp-magazine-layout' ) );
  141.     }
  142.    
  143.     wp_enqueue_script(
  144.         'fontawesome',
  145.         get_template_directory_uri() . '/js/fontawesome.min.js',
  146.         array(),
  147.         '5.14.0',
  148.         true
  149.     );
  150.     wp_enqueue_script(
  151.         'owl',
  152.         get_template_directory_uri() . '/js/owl.carousel.min.js',
  153.         array( 'jquery' ),
  154.         '2.2.1',
  155.         true
  156.     );
  157.     wp_enqueue_script(
  158.         'wp-magazine-navigation',
  159.         get_template_directory_uri() . '/js/navigation.min.js',
  160.         array( 'jquery' ),
  161.         '1.0.0',
  162.         true
  163.     );
  164.     $ad_blocker_msg = get_theme_mod( 'header_ad_disable_adblocker_msg', '' );
  165.     wp_register_script(
  166.         'wp-magazine-scripts',
  167.         get_template_directory_uri() . '/js/script.js',
  168.         array( 'jquery' ),
  169.         '',
  170.         true
  171.     );
  172.     wp_localize_script( 'wp-magazine-scripts', 'wp_magazine_scripts_var', array(
  173.         'ad_blocker_msg' => esc_html( $ad_blocker_msg ),
  174.     ) );
  175.     wp_enqueue_script( 'wp-magazine-scripts' );
  176.     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  177.         wp_enqueue_script( 'comment-reply' );
  178.     }
  179. }
  180.  
  181. add_action( 'wp_enqueue_scripts', 'wp_magazine_scripts' );
  182. /**
  183.  * Set the content width in pixels, based on the theme's design and stylesheet.
  184.  *
  185.  * Priority 0 to make it available to lower priority callbacks.
  186.  *
  187.  * @global int $content_width
  188.  */
  189. if ( !isset( $content_width ) ) {
  190.     $content_width = 900;
  191. }
  192. function wp_magazine_content_width()
  193. {
  194.     $GLOBALS['content_width'] = apply_filters( 'wp_magazine_content_width', 640 );
  195. }
  196.  
  197. add_action( 'after_setup_theme', 'wp_magazine_content_width', 0 );
  198. require get_template_directory() . '/inc/google-fonts.php';
  199. /**
  200. * Call Widget page
  201. **/
  202. require get_template_directory() . '/inc/widgets/widgets.php';
  203. /**
  204.  * Custom template tags for this theme.
  205.  */
  206. require get_template_directory() . '/inc/template-tags.php';
  207. /**
  208.  * Custom functions that act independently of the theme templates.
  209.  */
  210. require get_template_directory() . '/inc/extras.php';
  211. require get_template_directory() . '/inc/custom-controls/custom-control.php';
  212. /**
  213.  * Customizer additions.
  214.  */
  215. require get_template_directory() . '/inc/customizer/customizer.php';
  216. // Register Custom Navigation Walker
  217. require get_template_directory() . '/inc/wp_bootstrap_navwalker.php';
  218. /**
  219.  * Recommended Plugins
  220.  */
  221. require get_template_directory() . '/inc/tgmpa/recommended-plugins.php';
  222. require get_template_directory() . '/inc/dynamic-css.php';
  223. if ( is_admin() ) {
  224.     require get_template_directory() . '/inc/getting-started/getting-started.php';
  225. }
  226. require get_template_directory() . '/inc/breadcrumbs.php';
  227. // Remove default "Category or Tags" from title
  228. add_filter( 'get_the_archive_title', 'wp_magazine_remove_defalut_tax_title' );
  229. function wp_magazine_remove_defalut_tax_title( $title )
  230. {
  231.    
  232.     if ( is_category() ) {
  233.         $title = single_cat_title( '', false );
  234.     } elseif ( is_tag() ) {
  235.         $title = single_tag_title( '', false );
  236.     }
  237.    
  238.     return $title;
  239. }
  240.  
  241. // add classes for post_class function
  242. add_filter(
  243.     'post_class',
  244.     'wp_magazine_sticky_classes',
  245.     10,
  246.     3
  247. );
  248. function wp_magazine_sticky_classes( $classes, $class, $post_id )
  249. {
  250.     $classes[] = 'eq-blocks';
  251.     return $classes;
  252. }
  253.  
  254. function wp_magazine_load_more_scripts()
  255. {
  256.     $archive_cat = get_query_var( 'cat' );
  257.     if ( is_front_page() && !is_home() ) {
  258.         $archive_cat = get_theme_mod( 'homepage_blog_section_category' );
  259.     }
  260.     $args = array(
  261.         'post_type' => 'post',
  262.         'cat'       => absint( $archive_cat ),
  263.         'paged'     => ( get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1 ),
  264.     );
  265.     $wp_query = new WP_Query( $args );
  266.     wp_register_script( 'wp_magazine_loadmore', get_template_directory_uri() . '/js/loadmore.min.js', array( 'jquery' ) );
  267.     wp_localize_script( 'wp_magazine_loadmore', 'wp_magazine_loadmore_params', array(
  268.         'ajaxurl'      => esc_url( site_url() . '/wp-admin/admin-ajax.php' ),
  269.         'current_page' => ( get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1 ),
  270.         'max_page'     => absint( $wp_query->max_num_pages ),
  271.         'cat'          => absint( $archive_cat ),
  272.     ) );
  273.     wp_enqueue_script( 'wp_magazine_loadmore' );
  274. }
  275.  
  276. add_action( 'wp_enqueue_scripts', 'wp_magazine_load_more_scripts' );
  277. function wp_magazine_load_more_ajax()
  278. {
  279.     if ( isset( $_POST['page'] ) ) {
  280.         $args['paged'] = absint( $_POST['page'] + 1 );
  281.     }
  282.     $args['post_status'] = esc_html( 'publish' );
  283.     $args['cat'] = absint( $_POST['cat'] );
  284.     $wp_query = new WP_Query( $args );
  285.     if ( $wp_query->have_posts() ) {
  286.         while ( $wp_query->have_posts() ) {
  287.             $wp_query->the_post();
  288.             get_template_part( 'template-parts/content' );
  289.         }
  290.     }
  291.     die;
  292.     // here we exit the script and even no wp_reset_query() required!
  293. }
  294.  
  295. add_action( 'wp_ajax_wp_magazine_loadmore', 'wp_magazine_load_more_ajax' );
  296. add_action( 'wp_ajax_nopriv_wp_magazine_loadmore', 'wp_magazine_load_more_ajax' );
  297. // Enable woocommerce if installed:
  298. if ( class_exists( 'WooCommerce' ) ) {
  299.     add_theme_support( 'woocommerce' );
  300. }
  301. function wp_magazine_excerpt( $limit )
  302. {
  303.     $excerpt = explode( ' ', get_the_excerpt(), $limit );
  304.     if ( count( $excerpt ) >= $limit ) {
  305.         array_pop( $excerpt );
  306.     }
  307.     $excerpt = implode( " ", $excerpt );
  308.     $excerpt = preg_replace( '`[[^]]*]`', '', $excerpt );
  309.     return $excerpt;
  310. }
  311.  
  312. function wp_magazine_get_headline()
  313. {
  314.     $category_id = get_theme_mod( 'theme_headline_category' );
  315.     $title = get_theme_mod( 'headline_title' );
  316.     $posts_per_page = get_theme_mod( 'number_of_headline_posts', 4 );
  317.     $layout = get_theme_mod( 'wp_magazine_headline_layouts', 'one' );
  318.     $args = array(
  319.         'cat'                 => absint( $category_id ),
  320.         'posts_per_page'      => $posts_per_page,
  321.         'ignore_sticky_posts' => 1,
  322.     );
  323.     $query = new WP_Query( $args );
  324.    
  325.     if ( $query->have_posts() && $posts_per_page ) {
  326.         set_query_var( 'query', $query );
  327.         set_query_var( 'title', $title );
  328.         if ( $layout == 'one' ) {
  329.             get_template_part( 'layouts/headline/headline-layout', 'one' );
  330.         }
  331.         if ( $layout == 'two' ) {
  332.             get_template_part( 'layouts/headline/headline-layout', 'two' );
  333.         }
  334.     }
  335.    
  336.     wp_reset_postdata();
  337. }
  338.  
  339. function wp_magazine_get_dropdown_categories()
  340. {
  341.     $terms = get_terms( array(
  342.         'taxonomy'   => 'category',
  343.         'hide_empty' => false,
  344.     ) );
  345.     $cats = array();
  346.     if ( !empty($terms) && !is_wp_error( $terms ) ) {
  347.         foreach ( $terms as $term ) {
  348.             $cats[$term->slug] = $term->name;
  349.         }
  350.     }
  351.     return $cats;
  352. }
  353.  
  354. function wp_magazine_default_fonts_attributes()
  355. {
  356.     $defaults = array();
  357.     $defaults[1]['font_size'] = 32;
  358.     $defaults[2]['font_size'] = 28;
  359.     $defaults[3]['font_size'] = 24;
  360.     $defaults[4]['font_size'] = 21;
  361.     $defaults[5]['font_size'] = 15;
  362.     $defaults[6]['font_size'] = 12;
  363.     $defaults[1]['font_weight'] = 500;
  364.     $defaults[2]['font_weight'] = 400;
  365.     $defaults[3]['font_weight'] = 300;
  366.     $defaults[4]['font_weight'] = 200;
  367.     $defaults[5]['font_weight'] = 150;
  368.     $defaults[6]['font_weight'] = 100;
  369.     $defaults[1]['font_family'] = 'Poppins';
  370.     $defaults[2]['font_family'] = 'Mirza';
  371.     $defaults[3]['font_family'] = 'Monda';
  372.     $defaults[4]['font_family'] = 'Moul';
  373.     $defaults[5]['font_family'] = 'Ovo';
  374.     $defaults[6]['font_family'] = 'Oxygen';
  375.     return $defaults;
  376. }
  377.  
  378. function wp_magazine_define_font_sizes()
  379. {
  380.     for ( $i = 12 ;  $i <= 32 ;  $i++ ) {
  381.         $font_size[$i . 'px'] = $i . 'px';
  382.     }
  383.     return $font_size;
  384. }
  385.  
  386. function wp_magazine_define_line_height()
  387. {
  388.     for ( $i = 12 ;  $i <= 40 ;  $i++ ) {
  389.         $line_height[$i . 'px'] = $i . 'px';
  390.     }
  391.     return $line_height;
  392. }
  393.  
  394. /**
  395.  * Social media links
  396.  */
  397. function wp_magazine_social_links()
  398. {
  399.     $social_media = get_theme_mod( 'wp_magazine_social_media', '' );
  400.     // To store only value which has links :
  401.    
  402.     if ( !empty($social_media) && is_array( $social_media ) ) {
  403.         $social_media_filtered = array();
  404.         foreach ( $social_media as $value ) {
  405.             if ( empty($value['social_media_link']) ) {
  406.                 continue;
  407.             }
  408.             $social_media_filtered[] = $value;
  409.         }
  410.     }
  411.    
  412.    
  413.     if ( !empty($social_media_filtered) && is_array( $social_media_filtered ) ) {
  414.         ?>
  415.  
  416.         <div class="social-icons">
  417.             <ul class="list-inline">
  418.                 <?php
  419.         foreach ( $social_media_filtered as $value ) {
  420.             ?>
  421.                     <?php
  422.             $class = strtolower( 'fa fa-' . $value['social_media_title'] );
  423.             ?>
  424.                     <li class="<?php
  425.             echo  esc_attr( strtolower( $value['social_media_title'] ) ) ;
  426.             ?>"><a href="<?php
  427.             echo  esc_url( $value['social_media_link'] ) ;
  428.             ?>" target="_blank"><i class="<?php
  429.             echo  esc_attr( $class ) ;
  430.             ?>"></i></a></li>
  431.                 <?php
  432.         }
  433.         ?>
  434.             </ul>
  435.         </div>
  436.     <?php
  437.     }
  438.  
  439. }
  440.  
  441. /**
  442.  * Social media share buttons
  443.  */
  444. function wp_magazine_share_buttons()
  445. {
  446.     $url = urlencode( get_the_permalink() );
  447.     $title = html_entity_decode( get_the_title(), ENT_COMPAT, 'UTF-8' );
  448.     $media = urlencode( get_the_post_thumbnail_url( get_the_ID(), 'full' ) );
  449.     $twitter_id = get_theme_mod( 'twitter_id' );
  450.     include locate_template( 'share-template.php', false, false );
  451. }
  452.  
  453. function wp_magazine_header_ad()
  454. {
  455.    
  456.     if ( get_theme_mod( 'header_image_ad_display_option', false ) || get_theme_mod( 'header_google_ad_display_option', false ) ) {
  457.         $ad_image_id = absint( get_theme_mod( 'header_ad_image' ) );
  458.         $ad_image = wp_get_attachment_image_src( $ad_image_id, 'wp-magazine-header-ad-image' );
  459.         $ad_script = get_theme_mod( 'header_ad_script', '' );
  460.         $ad_link = get_theme_mod( 'ad_link', '' );
  461.         ?>
  462.  
  463.         <div class="col-sm-8 advertisement text-right">
  464.  
  465.             <?php
  466.        
  467.         if ( get_theme_mod( 'header_image_ad_display_option', false ) && !empty($ad_image) ) {
  468.             ?>
  469.  
  470.                 <?php
  471.            
  472.             if ( !empty($ad_link) ) {
  473.                 ?>
  474.                     <a href="<?php
  475.                 echo  esc_url( $ad_link ) ;
  476.                 ?>" target="_blank">
  477.                 <?php
  478.             }
  479.            
  480.             ?>
  481.  
  482.                     <img src="<?php
  483.             echo  esc_url( $ad_image[0] ) ;
  484.             ?> ">
  485.  
  486.                 <?php
  487.             if ( !empty($ad_link) ) {
  488.                 ?>
  489.                     </a>
  490.                 <?php
  491.             }
  492.             ?>
  493.  
  494.             <?php
  495.         }
  496.        
  497.         ?>
  498.  
  499.             <?php
  500.         ?>
  501.  
  502.         </div>
  503.  
  504.     <?php
  505.     }
  506.  
  507. }
  508.  
  509. function wp_magazine_menu()
  510. {
  511.     add_theme_page(
  512.         esc_html__( 'Get Started', 'wp-magazine' ),
  513.         esc_html__( 'Get Started', 'wp-magazine' ),
  514.         'edit_theme_options',
  515.         'wp-magazine-get-started',
  516.         'wp_magazine_about_page'
  517.     );
  518. }
  519.  
  520. add_action( 'admin_menu', 'wp_magazine_menu' );
  521. function wp_magazine_about_page()
  522. {
  523.    
  524.     if ( has_filter( 'wpmagplus_about_page' ) ) {
  525.         $about_page = apply_filters( 'wpmagplus_about_page', false );
  526.     } else {
  527.         $about_page = "";
  528.     }
  529.    
  530.     return $about_page;
  531. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement