Advertisement
darrenbachan

Untitled

Jun 6th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.35 KB | None | 0 0
  1. <?php
  2.     // Register Nav Walker class_alias
  3.     require_once('wp_bootstrap_navwalker.php');
  4.  
  5.     // Theme Support
  6.     function syau_theme_setup () {
  7.         // Add Featured Image Support
  8.         add_theme_support('post-thumbnails');
  9.  
  10.         // Nav Menus
  11.         register_nav_menus(array (
  12.             'primary' => __('Main Menu'),
  13.             'hamburger' => __('Mobile Menu'),
  14.             'footer' => __('Footer Menu')
  15.         ));
  16.  
  17.         // Switch default core markup for search form, comment form, and comments to output valid HTML5
  18.         add_theme_support( 'html5', array(
  19.             'search-form',
  20.             'comment-form',
  21.             'comment-list',
  22.             'gallery',
  23.             'caption',
  24.         ) );
  25.  
  26.         //Enable support for Post Formats
  27.         add_theme_support( 'post-formats', array(
  28.             'aside',
  29.             'image',
  30.             'video',
  31.             'quote',
  32.             'link',
  33.         ) );
  34.  
  35.         // Set up the WordPress core custom background feature.
  36.         add_theme_support( 'custom-background', apply_filters( 'darren_bachan_custom_background_args', array(
  37.             'default-color' => 'ffffff',
  38.             'default-image' => '',
  39.         ) ) );
  40.     }
  41.  
  42.     add_action('after_setup_theme', 'syau_theme_setup');
  43.  
  44.     //Add Our Widget Locations
  45.     function ourWidgetsInit () {
  46.  
  47.         register_sidebar( array(
  48.             'name'          => esc_html__( 'Sidebar', 'darren-bachan' ),
  49.             'id'            => 'sidebar-1',
  50.             'description'   => esc_html__( 'Add widgets here.', 'darren-bachan' ),
  51.             'before_widget' => '<section id="%1$s" class="widget %2$s">',
  52.             'after_widget'  => '</section>',
  53.             'before_title'  => '<h3 class="widget-title">',
  54.             'after_title'   => '</h3>',
  55.         ) );
  56.  
  57.         register_sidebar( array(
  58.             'name' => 'Footer Area 1',
  59.             'id' => 'footer1'
  60.         ));
  61.  
  62.     }
  63.  
  64.     add_action('widgets_init', 'ourWidgetsInit');
  65.  
  66.     // Enqueue Scripts & Styles
  67.     function syau_theme_scripts() {
  68.  
  69.         // Deregister the included library
  70.         wp_deregister_script( 'jquery' );
  71.          
  72.         // Register the library again
  73.         wp_register_script( 'jquery', get_template_directory_uri() . "/js/jquery-2.2.2.min.js", array(), '' , true );
  74.         wp_enqueue_script('jquery');
  75.  
  76.         wp_enqueue_script( 'typed', get_template_directory_uri() . "/js/typed.min.js", array(), '' , true );
  77.         wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . "/js/owl.carousel.min.js", array(), '' , true );
  78.         wp_enqueue_script( 'bootstrap', get_template_directory_uri() . "/js/bootstrap.min.js", array(), '' , true );
  79.         wp_enqueue_script( 'animation-scroll', get_template_directory_uri() . "/js/animatescroll.js", array(), '' , true );
  80.         wp_enqueue_script( 'animation-slide', get_template_directory_uri() . "/js/animation-slide.js", array(), '' , true );
  81.         wp_enqueue_script( 'main-js', get_template_directory_uri() . "/js/main.js", array(), '' , true );
  82.  
  83.         wp_enqueue_style( 'bootstrap', get_template_directory_uri()."/css/bootstrap.css", '', '' );
  84.         wp_enqueue_style( 'fonts', get_template_directory_uri()."/css/fonts.css", '', '' );
  85.         wp_enqueue_style( 'font-awesome', get_template_directory_uri()."/css/font-awesome.css", '', '' );
  86.         wp_enqueue_style( 'flag-icon', get_template_directory_uri()."/css/flag-icon.css", '', '' );
  87.         wp_enqueue_style( 'hamburger', get_template_directory_uri()."/css/hamburger.css", '', '' );
  88.         wp_enqueue_style( 'owl-carousel', get_template_directory_uri()."/css/owl.carousel.css", '', '' );
  89.         wp_enqueue_style( 'owl-theme', get_template_directory_uri()."/css/owl.theme.default.min.css", '', '' );
  90.         wp_enqueue_style( 'main-css', get_template_directory_uri()."/style.css", '', '' );
  91.  
  92.         if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  93.             wp_enqueue_script( 'comment-reply' );
  94.         }
  95.     }
  96.  
  97.     add_action( 'wp_enqueue_scripts', 'syau_theme_scripts' );
  98.  
  99.     // Customizer File
  100.     require get_template_directory(). '/inc/customizer.php';
  101.  
  102.     // Grab First Paragraph Of Text And Ignore Images For Excerpt
  103.     function awesome_excerpt($text, $raw_excerpt) {
  104.         if( ! $raw_excerpt ) {
  105.             $content = apply_filters( 'the_content', get_the_content() );
  106.             $text = substr( $content, 0, strpos( $content, '</p>' ) + 4 );
  107.         }
  108.         $text = preg_replace("/<img[^>]+\>/i", "", $text);
  109.         return $text;
  110.     }
  111.     add_filter( 'wp_trim_excerpt', 'awesome_excerpt', 10, 2 );
  112.  
  113.     // Customize Excerpt Word Count Length
  114.     function excerpt($limit) {
  115.         $excerpt = explode(' ', get_the_excerpt(), $limit);
  116.         if (count($excerpt)>=$limit) {
  117.             array_pop($excerpt);
  118.             $excerpt = implode(" ",$excerpt).'...';
  119.           } else {
  120.             $excerpt = implode(" ",$excerpt);
  121.           }
  122.         $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
  123.         return $excerpt;
  124.     }
  125.  
  126.     // Empty <p> Fix On Images
  127.     function filter_ptags_on_images($content){
  128.        return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
  129.     }
  130.  
  131.     add_filter('the_content', 'filter_ptags_on_images');
  132.  
  133.     // Change Author Permalinks
  134.     function change_author_permalinks() {
  135.         global $wp_rewrite;
  136.         $wp_rewrite->author_base = 'member';
  137.         $wp_rewrite->author_structure = '/' . $wp_rewrite->author_base. '/%author%';
  138.     }
  139.     add_action('init','change_author_permalinks');
  140.  
  141.     // Custom Comments Styling
  142.     function mytheme_comment($comment, $args, $depth) {
  143.         if ( 'div' === $args['style'] ) {
  144.             $tag       = 'div';
  145.             $add_below = 'comment';
  146.         } else {
  147.             $tag       = 'li';
  148.             $add_below = 'div-comment';
  149.         }
  150.         ?>
  151.         <<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
  152.         <?php if ( 'div' != $args['style'] ) : ?>
  153.             <div id="div-comment-<?php comment_ID() ?>" class="comment-meta-body">
  154.         <?php endif; ?>
  155.         <div class="comment-author vcard comment-meta-avatar">
  156.             <?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment ); ?>
  157.         </div>
  158.        
  159.         <div class="comment-meta-text">
  160.             <div class="comment-meta-author">
  161.                 <?php printf( __( '<cite class="fn">%s</cite>' ), get_comment_author_link() ); ?>
  162.             </div>
  163.             <div class="comment-meta-time commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
  164.                 <?php
  165.                 /* translators: 1: date, 2: time */
  166.                 printf( __('%1$s &#64; %2$s'), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), '  ', '' );
  167.                 ?>
  168.             </div>
  169.             <div class="comment-meta-mod">
  170.                 <?php if ( $comment->comment_approved == '0' ) : ?>
  171.                      <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
  172.                       <br />
  173.                 <?php endif; ?>
  174.             </div>
  175.             <div class="comment-content">
  176.                 <?php comment_text(); ?>
  177.                 <div class="reply">
  178.                     <?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  179.                 </div>
  180.             </div>
  181.         </div>
  182.         <?php if ( 'div' != $args['style'] ) : ?>
  183.         </div>
  184.         <?php endif; ?>
  185.         <?php
  186.         }
  187.  
  188.         // Personalize Reply Link
  189.         function add_comment_author_to_reply_link($link, $args, $comment){
  190.  
  191.             $comment = get_comment( $comment );
  192.  
  193.             // If no comment author is blank, use 'Anonymous'
  194.             if ( empty($comment->comment_author) ) {
  195.                 if (!empty($comment->user_id)){
  196.                     $user=get_userdata($comment->user_id);
  197.                     $author=$user->user_login;
  198.                 } else {
  199.                     $author = __('Anonymous');
  200.                 }
  201.             } else {
  202.                 $author = $comment->comment_author;
  203.             }
  204.  
  205.             // If the user provided more than a first name, use only first name
  206.             if(strpos($author, ' ')){
  207.                 $author = substr($author, 0, strpos($author, ' '));
  208.             }
  209.  
  210.             // Replace Reply Link with "Reply to &lt;Author First Name>"
  211.             $reply_link_text = $args['reply_text'];
  212.             //print_r($args);
  213.             $link = str_replace($reply_link_text, 'Reply to ' . $author . ' <i class="fa fa-long-arrow-right"></i>', $link);
  214.  
  215.             return $link;
  216.         }
  217.         add_filter('comment_reply_link', 'add_comment_author_to_reply_link', 10, 3);
  218.  
  219.         //Personalize Cancel Reply Link
  220.         function add_comment_author_to_cancel_reply_link($formatted_link, $link, $text){
  221.  
  222.             $comment = get_comment( $comment );
  223.  
  224.             // If no comment author is blank, use 'Anonymous'
  225.             if ( empty($comment->comment_author) ) {
  226.                 if (!empty($comment->user_id)){
  227.                     $user=get_userdata($comment->user_id);
  228.                     $author=$user->user_login;
  229.                 } else {
  230.                     $author = __('Anonymous');
  231.                 }
  232.             } else {
  233.                 $author = $comment->comment_author;
  234.             }
  235.  
  236.             // If the user provided more than a first name, use only first name
  237.             if(strpos($author, ' ')){
  238.                 $author = substr($author, 0, strpos($author, ' '));
  239.             }
  240.  
  241.             // Replace "Cancel Reply" with "Cancel Reply to <author First Name>"
  242.             $formatted_link = str_ireplace($text, 'Cancel reply to ' . $author . ' <i class="fa fa-long-arrow-right"></i>', $formatted_link);
  243.  
  244.             return $formatted_link;
  245.         }
  246.         add_filter('cancel_comment_reply_link', 'add_comment_author_to_cancel_reply_link', 10, 3);
  247.  
  248.         // Move comment field to bottom of comment form
  249.         function wpb_move_comment_field_to_bottom( $fields ) {
  250.             $comment_field = $fields['comment'];
  251.             unset( $fields['comment'] );
  252.             $fields['comment'] = $comment_field;
  253.             return $fields;
  254.         }
  255.  
  256.         // Remove website url field in comment form
  257.         function remove_comment_fields($fields) {
  258.             unset($fields['url']);
  259.             return $fields;
  260.         }
  261.         add_filter('comment_form_default_fields','remove_comment_fields');
  262.  
  263.         add_filter( 'comment_form_fields', 'wpb_move_comment_field_to_bottom' );
  264.  
  265.         // Custom Page Pagination
  266.         function wp_custom_pagination($args = [], $class = 'pagination') {
  267.  
  268.             if ($GLOBALS['wp_query']->max_num_pages <= 1) return;
  269.  
  270.             $args = wp_parse_args( $args, [
  271.                 'mid_size'           => 2,
  272.                 'prev_next'          => false,
  273.                 'prev_text'          => __('Older posts', 'textdomain'),
  274.                 'next_text'          => __('Newer posts', 'textdomain'),
  275.                 'screen_reader_text' => __('Posts navigation', 'textdomain'),
  276.             ]);
  277.  
  278.             $links     = paginate_links($args);
  279.             $next_link = get_previous_posts_link($args['next_text']);
  280.             $prev_link = get_next_posts_link($args['prev_text']);
  281.             $template  = apply_filters( 'navigation_markup_template', '
  282.             <nav class="navigation %1$s" role="navigation">
  283.                 <div class="nav-links">%3$s<div class="page-numbers-container">%4$s</div>%5$s</div>
  284.             </nav>', $args, $class);
  285.  
  286.             echo sprintf($template, $class, $args['screen_reader_text'], $prev_link, $links, $next_link);
  287.  
  288.         }
  289.         add_filter('previous_posts_link_attributes', function()
  290.         {
  291.         return 'class="next"';
  292.         });
  293.  
  294.         add_filter('next_posts_link_attributes', function()
  295.         {
  296.         return 'class="prev"';
  297.         });
  298.  
  299.         // [Title] Shortcode
  300.         function shortcode_title($atts, $content = null) {
  301.            
  302.             $output = '';
  303.            
  304.             $output .= '<div class="page-header">';
  305.             $output .= $content;
  306.             $output .= '</div>';
  307.  
  308.             return $output;
  309.  
  310.         }
  311.         add_shortcode('title','shortcode_title');
  312.  
  313.         function shortcode_container($atts, $content = null) {
  314.    
  315.             $type = isset($atts['type']) ? $atts['type'] : '';
  316.             $margintop = isset($atts['margintop']) ? $atts['margintop'] : '';
  317.             $marginbottom = isset($atts['marginbottom']) ? $atts['marginbottom'] : '';
  318.            
  319.             $output = '';
  320.            
  321.             $output .= '<div class="container '.$type.'" style="margin-top:'.$margintop.'; margin-bottom:'.$marginbottom.'">';
  322.             $output .= '<section>';
  323.             $output .= '<div class="row">';
  324.             $output .= apply_filters('the_content', $content);
  325.             $output .= '</div>';
  326.             $output .= '</section>';
  327.             $output .= '</div>';
  328.  
  329.             return $output;
  330.  
  331.         }
  332.         add_shortcode('container','shortcode_container');
  333.  
  334.         function so_shortcode_row($atts, $content = null) {
  335.    
  336.             $type = isset($atts['type']) ? $atts['type'] : '';
  337.             $margintop = isset($atts['margintop']) ? $atts['margintop'] : '';
  338.             $marginbottom = isset($atts['marginbottom']) ? $atts['marginbottom'] : '';
  339.            
  340.             $output = '';
  341.            
  342.             $output .= '<div class="row '.$type.'" style="margin-top:'.$margintop.'; margin-bottom:'.$marginbottom.'">';
  343.             $output .= '<div class="inner">';
  344.             $output .= apply_filters('the_content', $content);
  345.             $output .= '</div>';
  346.             $output .= '</div>';
  347.  
  348.             return $output;
  349.  
  350.         }
  351.         add_shortcode('row','so_shortcode_row');
  352.  
  353. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement