Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.50 KB | None | 0 0
  1. <?php
  2. /**
  3.  * BrickYard functions and definitions.
  4.  * @package BrickYard
  5.  * @since BrickYard 1.0.0
  6. */
  7.  
  8. /**
  9.  * BrickYard theme variables.
  10.  *  
  11. */    
  12. $brickyard_themename = "BrickYard";         //Theme Name
  13. $brickyard_themever = "1.2.3";                                  //Theme version
  14. $brickyard_shortname = "brickyard";                         //Shortname
  15. $brickyard_manualurl = get_template_directory_uri() . '/docs/documentation.html';   //Manual Url
  16. // Set path to BrickYard Framework and theme specific functions
  17. $brickyard_be_path = get_template_directory() . '/functions/be/';                                   //BackEnd Path
  18. $brickyard_fe_path = get_template_directory() . '/functions/fe/';                                   //FrontEnd Path
  19. $brickyard_be_pathimages = get_template_directory_uri() . '/functions/be/images';       //BackEnd Path
  20. $brickyard_fe_pathimages = get_template_directory_uri() . '';   //FrontEnd Path
  21. //Include Framework [BE]
  22. require_once ($brickyard_be_path . 'fw-options.php');        // Framework Init  
  23. // Include Theme specific functionality [FE]
  24. require_once ($brickyard_fe_path . 'headerdata.php');        // Include css and js
  25. require_once ($brickyard_fe_path . 'library.php');         // Include library, functions
  26. require_once ($brickyard_fe_path . 'widget-posts-default.php');// Posts-Default Widget
  27.  
  28. /**
  29.  * BrickYard theme basic setup.
  30.  *  
  31. */
  32. function brickyard_setup() {
  33.     // Makes BrickYard available for translation.
  34.     load_theme_textdomain( 'brickyard', get_template_directory() . '/languages' );
  35.   // This theme styles the visual editor to resemble the theme style.
  36.   $brickyard_font_url = add_query_arg( 'family', 'Oswald', "//fonts.googleapis.com/css" );
  37.   add_editor_style( array( 'editor-style.css', $brickyard_font_url ) );
  38.     // Adds RSS feed links to <head> for posts and comments.  
  39.     add_theme_support( 'automatic-feed-links' );
  40.     // This theme supports custom background color and image.
  41.     $defaults = array(
  42.     'default-color' => '',
  43.   'default-image' => '',
  44.     'wp-head-callback' => '_custom_background_cb',
  45.     'admin-head-callback' => '',
  46.     'admin-preview-callback' => '' );  
  47.   add_theme_support( 'custom-background', $defaults );
  48.     // This theme uses a custom image size for featured images, displayed on "standard" posts.
  49.     add_theme_support( 'post-thumbnails' );
  50.     set_post_thumbnail_size( 972, 9999 );
  51.   // This theme uses a custom header background image.
  52.   $args = array(
  53.     'width' => 1012,
  54.   'flex-width' => true,
  55.   'flex-height' => true,
  56.   'header-text' => false,
  57.   'random-default' => true,);
  58.   add_theme_support( 'custom-header', $args );
  59.   add_theme_support( 'title-tag' );
  60.   add_theme_support( 'woocommerce' );
  61.   global $content_width;
  62.   if ( ! isset( $content_width ) ) { $content_width = 616; }
  63. }
  64. add_action( 'after_setup_theme', 'brickyard_setup' );
  65.  
  66. /**
  67.  * Enqueues scripts and styles for front-end.
  68.  *
  69. */
  70. function brickyard_scripts_styles() {
  71.     global $wp_styles, $wp_scripts;
  72.     // Adds JavaScript
  73.     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
  74.         wp_enqueue_script( 'comment-reply' );
  75.     wp_enqueue_script( 'brickyard-placeholders', get_template_directory_uri() . '/js/placeholders.js', array(), '3.0.2', true );
  76.     wp_enqueue_script( 'brickyard-scroll-to-top', get_template_directory_uri() . '/js/scroll-to-top.js', array( 'jquery' ), '1.0', true );
  77.     if ( !is_page_template('template-landing-page.php') ) {
  78.     wp_enqueue_script( 'brickyard-menubox', get_template_directory_uri() . '/js/menubox.js', array( 'jquery' ), '1.0', true ); }
  79.     wp_enqueue_script( 'brickyard-selectnav', get_template_directory_uri() . '/js/selectnav.js', array(), '0.1', true );
  80.     wp_enqueue_script( 'brickyard-responsive', get_template_directory_uri() . '/js/responsive.js', array(), '1.0', true );
  81.     wp_enqueue_script( 'brickyard-html5-ie', get_template_directory_uri() . '/js/html5.js', array(), '3.6', false );
  82.     $wp_scripts->add_data( 'brickyard-html5-ie', 'conditional', 'lt IE 9' );  
  83.     // Loads the main stylesheet.
  84.       wp_enqueue_style( 'brickyard-style', get_stylesheet_uri() );
  85.     wp_enqueue_style( 'brickyard-google-font-default', '//fonts.googleapis.com/css?family=Oswald&amp;subset=latin,latin-ext' );
  86.     if ( class_exists( 'woocommerce' ) ) { wp_enqueue_style( 'brickyard-woocommerce-custom', get_template_directory_uri() . '/css/woocommerce-custom.css' ); }
  87. }
  88. add_action( 'wp_enqueue_scripts', 'brickyard_scripts_styles' );
  89.  
  90. /**
  91.  * Backwards compatibility for older WordPress versions which do not support the Title Tag feature.
  92.  *  
  93. */
  94. if ( ! function_exists( '_wp_render_title_tag' ) ) {
  95. function brickyard_wp_title( $title, $sep ) {
  96.     if ( is_feed() )
  97.         return $title;
  98.     $title .= get_bloginfo( 'name' );
  99.     $site_description = get_bloginfo( 'description', 'display' );
  100.     if ( $site_description && ( is_home() || is_front_page() ) )
  101.         $title = "$title $sep $site_description";
  102.     return $title;
  103. }
  104. add_filter( 'wp_title', 'brickyard_wp_title', 10, 2 );
  105. }
  106.  
  107. /**
  108.  * Register our menus.
  109.  *
  110.  */
  111. function brickyard_register_my_menus() {
  112.   register_nav_menus(
  113.     array(
  114.       'main-navigation' => __( 'Main Header Menu', 'brickyard' ),
  115.       'top-navigation' => __( 'Top Header Menu', 'brickyard' )
  116.     )
  117.   );
  118. }
  119. add_action( 'after_setup_theme', 'brickyard_register_my_menus' );
  120.  
  121. /**
  122.  * Register our sidebars and widgetized areas.
  123.  *
  124. */
  125. function brickyard_widgets_init() {
  126.   register_sidebar( array(
  127.         'name' => __( 'Right Sidebar', 'brickyard' ),
  128.         'id' => 'sidebar-1',
  129.         'description' => __( 'Right sidebar which appears on all posts and pages.', 'brickyard' ),
  130.         'before_widget' => '<div id="%1$s" class="sidebar-widget %2$s"><div class="sidebar-widget-inner">',
  131.         'after_widget' => '</div></div>',
  132.         'before_title' => ' <p class="sidebar-headline"><span class="sidebar-headline-text">',
  133.         'after_title' => '</span></p>',
  134.     ) );
  135.   register_sidebar( array(
  136.         'name' => __( 'Footer left widget area', 'brickyard' ),
  137.         'id' => 'sidebar-2',
  138.         'description' => __( 'Left column with widgets in footer.', 'brickyard' ),
  139.         'before_widget' => '<div id="%1$s" class="footer-widget %2$s">',
  140.         'after_widget' => '</div>',
  141.         'before_title' => '<p class="footer-headline"><span class="footer-headline-text">',
  142.         'after_title' => '</span></p>',
  143.     ) );
  144.   register_sidebar( array(
  145.         'name' => __( 'Footer middle widget area', 'brickyard' ),
  146.         'id' => 'sidebar-3',
  147.         'description' => __( 'Middle column with widgets in footer.', 'brickyard' ),
  148.         'before_widget' => '<div id="%1$s" class="footer-widget %2$s">',
  149.         'after_widget' => '</div>',
  150.         'before_title' => '<p class="footer-headline"><span class="footer-headline-text">',
  151.         'after_title' => '</span></p>',
  152.     ) );
  153.   register_sidebar( array(
  154.         'name' => __( 'Footer right widget area', 'brickyard' ),
  155.         'id' => 'sidebar-4',
  156.         'description' => __( 'Right column with widgets in footer.', 'brickyard' ),
  157.         'before_widget' => '<div id="%1$s" class="footer-widget %2$s">',
  158.         'after_widget' => '</div>',
  159.         'before_title' => '<p class="footer-headline"><span class="footer-headline-text">',
  160.         'after_title' => '</span></p>',
  161.     ) );
  162.   register_sidebar( array(
  163.         'name' => __( 'Footer notices', 'brickyard' ),
  164.         'id' => 'sidebar-5',
  165.         'description' => __( 'The line for copyright and other notices below the footer widget areas. Insert here one Text widget. The "Title" field at this widget should stay empty.', 'brickyard' ),
  166.         'before_widget' => '<div class="footer-signature"><div class="footer-signature-content">',
  167.         'after_widget' => '</div></div>',
  168.         'before_title' => '',
  169.         'after_title' => '',
  170.     ) );
  171.   register_sidebar( array(
  172.         'name' => __( 'Latest Posts Homepage widget area', 'brickyard' ),
  173.         'id' => 'sidebar-6',
  174.         'description' => __( 'The area for any BrickYard Posts Widgets, which displays latest posts from a specific category below the default Latest Posts area.', 'brickyard' ),
  175.         'before_widget' => '<div class="entry-content"><div class="entry-content-inner">',
  176.         'after_widget' => '</div></div>',
  177.         'before_title' => '',
  178.         'after_title' => '',
  179.     ) );
  180. }
  181. add_action( 'widgets_init', 'brickyard_widgets_init' );
  182.  
  183. /**
  184.  * Post excerpt settings.
  185.  *
  186. */
  187.  
  188. function brickyard_custom_excerpt_length( $length ) {
  189. return 50;
  190. }
  191. add_filter( 'excerpt_length', 'brickyard_custom_excerpt_length', 20 );
  192. function brickyard_new_excerpt_more( $more ) {
  193. global $post;
  194. return '...<br /><a class="read-more-button" href="'. esc_url( get_permalink($post->ID) ) . '">' . __( 'Mais', 'brickyard' ) . '</a>';}
  195. add_filter( 'excerpt_more', 'brickyard_new_excerpt_more' );
  196.  
  197. if ( ! function_exists( 'brickyard_content_nav' ) ) :
  198. /**
  199.  * Displays navigation to next/previous pages when applicable.
  200.  *
  201. */
  202. function brickyard_content_nav( $html_id ) {
  203.     global $wp_query;
  204.     $html_id = esc_attr( $html_id );
  205.     if ( $wp_query->max_num_pages > 1 ) : ?>
  206.         <div id="<?php echo $html_id; ?>" class="navigation" role="navigation">
  207.     <div class="navigation-inner">
  208.             <h2 class="navigation-headline section-heading"><?php _e( 'Navegação', 'brickyard' ); ?></h2>
  209.       <div class="nav-wrapper">
  210.              <p class="navigation-links">
  211. <?php $big = 999999999;
  212. echo paginate_links( array(
  213.     'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  214.     'format' => '?paged=%#%',
  215.     'current' => max( 1, get_query_var('paged') ),
  216.   'prev_text' => __( '&larr; Anterior', 'brickyard' ),
  217.     'next_text' => __( 'Próximo &rarr;', 'brickyard' ),
  218.     'total' => $wp_query->max_num_pages,
  219.     'add_args' => false
  220. ) );
  221. ?>
  222.         </p>
  223.       </div>
  224.         </div>
  225.     </div>
  226.     <?php endif;
  227. }
  228. endif;
  229.  
  230. /**
  231.  * Displays navigation to next/previous posts on single posts pages.
  232.  *
  233. */
  234. function brickyard_prev_next($nav_id) { ?>
  235. <?php $brickyard_previous_post = get_adjacent_post( false, "", true );
  236. $brickyard_next_post = get_adjacent_post( false, "", false ); ?>
  237. <div id="<?php echo $nav_id; ?>" class="navigation" role="navigation">
  238.     <div class="nav-wrapper">
  239. <?php if ( !empty($brickyard_previous_post) ) { ?>
  240.   <p class="nav-previous"><a href="<?php echo esc_url(get_permalink($brickyard_previous_post->ID)); ?>" title="<?php echo esc_attr($brickyard_previous_post->post_title); ?>"><?php _e( '&larr; Post anterior', 'brickyard' ); ?></a></p>
  241. <?php } if ( !empty($brickyard_next_post) ) { ?>
  242.     <p class="nav-next"><a href="<?php echo esc_url(get_permalink($brickyard_next_post->ID)); ?>" title="<?php echo esc_attr($brickyard_next_post->post_title); ?>"><?php _e( 'Próximo post &rarr;', 'brickyard' ); ?></a></p>
  243. <?php } ?>
  244.    </div>
  245. </div>
  246. <?php }
  247.  
  248. if ( ! function_exists( 'brickyard_comment' ) ) :
  249. /**
  250.  * Template for comments and pingbacks.
  251.  *
  252. */
  253. function brickyard_comment( $comment, $args, $depth ) {
  254.     $GLOBALS['comment'] = $comment;
  255.     switch ( $comment->comment_type ) :
  256.         case 'pingback' :
  257.         case 'trackback' :
  258.     ?>
  259.     <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
  260.         <p><?php _e( 'Pingback:', 'brickyard' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'brickyard' ), '<span class="edit-link">', '</span>' ); ?></p>
  261.     <?php
  262.             break;
  263.         default :
  264.         global $post;
  265.     ?>
  266.     <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  267.         <div id="comment-<?php comment_ID(); ?>" class="comment">
  268.             <div class="comment-meta comment-author vcard">
  269.                 <?php
  270.                     echo get_avatar( $comment, 44 );
  271.                     printf( '<span><b class="fn">%1$s</b> %2$s</span>',
  272.                         get_comment_author_link(),
  273.                         ( $comment->user_id === $post->post_author ) ? '<span>' . __( '(Post author)', 'brickyard' ) . '</span>' : ''
  274.                     );
  275.                     printf( '<time datetime="%2$s">%3$s</time>',
  276.                         esc_url( get_comment_link( $comment->comment_ID ) ),
  277.                         get_comment_time( 'c' ),
  278.                         // translators: 1: date, 2: time
  279.                         sprintf( __( '%1$s at %2$s', 'brickyard' ), get_comment_date(''), get_comment_time() )
  280.                     );
  281.                 ?>
  282.             </div><!-- .comment-meta -->
  283.  
  284.             <?php if ( '0' == $comment->comment_approved ) : ?>
  285.                 <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'brickyard' ); ?></p>
  286.             <?php endif; ?>
  287.  
  288.             <div class="comment-content comment">
  289.                 <?php comment_text(); ?>
  290.              <div class="reply">
  291.                <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'brickyard' ), 'after' => ' <span>&darr;</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  292.             </div><!-- .reply -->
  293.                <?php edit_comment_link( __( 'Edit', 'brickyard' ), '<p class="edit-link">', '</p>' ); ?>
  294.             </div><!-- .comment-content -->
  295.         </div><!-- #comment-## -->
  296.     <?php
  297.         break;
  298.     endswitch;
  299. }
  300. endif;
  301.  
  302. /**
  303.  * Function for adding custom classes to the menu objects.
  304.  *
  305. */
  306. add_filter( 'wp_nav_menu_objects', 'brickyard_filter_menu_class', 10, 2 );
  307. function brickyard_filter_menu_class( $objects, $args ) {
  308.  
  309.     $ids        = array();
  310.     $parent_ids = array();
  311.     $top_ids    = array();
  312.     foreach ( $objects as $i => $object ) {
  313.  
  314.         if ( 0 == $object->menu_item_parent ) {
  315.             $top_ids[$i] = $object;
  316.             continue;
  317.         }
  318.  
  319.         if ( ! in_array( $object->menu_item_parent, $ids ) ) {
  320.             $objects[$i]->classes[] = 'first-menu-item';
  321.             $ids[]          = $object->menu_item_parent;
  322.         }
  323.  
  324.         if ( in_array( 'first-menu-item', $object->classes ) )
  325.             continue;
  326.  
  327.         $parent_ids[$i] = $object->menu_item_parent;
  328.     }
  329.  
  330.     $sanitized_parent_ids = array_unique( array_reverse( $parent_ids, true ) );
  331.  
  332.     foreach ( $sanitized_parent_ids as $i => $id )
  333.         $objects[$i]->classes[] = 'last-menu-item';
  334.  
  335.     return $objects;
  336. }
  337.  
  338. /**
  339.  * Function for rendering CSS3 features in IE.
  340.  *
  341. */
  342. add_filter( 'wp_head' , 'brickyard_pie' );
  343. function brickyard_pie() { ?>
  344. <!--[if IE]>
  345. <style type="text/css" media="screen">
  346. #header, #wrapper-footer, .entry-content, .sidebar-widget {
  347.         behavior: url("<?php echo get_template_directory_uri() . '/css/pie/PIE.php'; ?>");
  348.         zoom: 1;
  349. }
  350. </style>
  351. <![endif]-->
  352. <?php }
  353.  
  354. /**
  355.  * Include the TGM_Plugin_Activation class.
  356.  *  
  357. */
  358. if ( current_user_can ( 'install_plugins' ) ) {
  359. require_once get_template_directory() . '/class-tgm-plugin-activation.php';
  360. add_action( 'tgmpa_register', 'brickyard_my_theme_register_required_plugins' );
  361.  
  362. function brickyard_my_theme_register_required_plugins() {
  363.  
  364. $plugins = array(
  365.         array(
  366.             'name'     => 'Breadcrumb NavXT',
  367.             'slug'     => 'breadcrumb-navxt',
  368.             'required' => false,
  369.         ),
  370. );
  371.  
  372. $config = array(
  373.         'domain'       => 'brickyard',
  374.     'menu'         => 'install-my-theme-plugins',
  375.         'strings'        => array(
  376.         'page_title'             => __( 'Install Recommended Plugins', 'brickyard' ),
  377.         'menu_title'             => __( 'Install Plugins', 'brickyard' ),
  378.         'instructions_install'   => __( 'The %1$s plugin is required for this theme. Click on the big blue button below to install and activate %1$s.', 'brickyard' ),
  379.         'instructions_activate'  => __( 'The %1$s is installed but currently inactive. Please go to the <a href="%2$s">plugin administration page</a> page to activate it.', 'brickyard' ),
  380.         'button'                 => __( 'Install %s Now', 'brickyard' ),
  381.         'installing'             => __( 'Installing Plugin: %s', 'brickyard' ),
  382.         'oops'                   => __( 'Something went wrong with the plugin API.', 'brickyard' ), // */
  383.         'notice_can_install'     => __( 'This theme requires the %1$s plugin. <a href="%2$s"><strong>Click here to begin the installation process</strong></a>. You may be asked for FTP credentials based on your server setup.', 'brickyard' ),
  384.         'notice_cannot_install'  => __( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'brickyard' ),
  385.         'notice_can_activate'    => __( 'This theme requires the %1$s plugin. That plugin is currently inactive, so please go to the <a href="%2$s">plugin administration page</a> to activate it.', 'brickyard' ),
  386.         'notice_cannot_activate' => __( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'brickyard' ),
  387.         'return'                 => __( 'Return to Recommended Plugins Installer', 'brickyard' ),
  388. ),
  389. );
  390. brickyard_tgmpa( $plugins, $config );
  391. }}
  392.  
  393. /**
  394.  * WooCommerce custom template modifications.
  395.  *  
  396. */
  397. if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
  398. function brickyard_woocommerce_modifications() {
  399.   remove_action ( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
  400. }  
  401. add_action ( 'init', 'brickyard_woocommerce_modifications' );
  402. add_filter ( 'woocommerce_show_page_title', '__return_false' );
  403. } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement