Advertisement
liblogger

functions file for tri.be

Dec 4th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 18.14 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Twenty Twelve functions and definitions
  4.  *
  5.  * Sets up the theme and provides some helper functions, which are used
  6.  * in the theme as custom template tags. Others are attached to action and
  7.  * filter hooks in WordPress to change core functionality.
  8.  *
  9.  * When using a child theme (see http://codex.wordpress.org/Theme_Development and
  10.  * http://codex.wordpress.org/Child_Themes), you can override certain functions
  11.  * (those wrapped in a function_exists() call) by defining them first in your child theme's
  12.  * functions.php file. The child theme's functions.php file is included before the parent
  13.  * theme's file, so the child theme functions would be used.
  14.  *
  15.  * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
  16.  * to a filter or action hook.
  17.  *
  18.  * For more information on hooks, actions, and filters, @link http://codex.wordpress.org/Plugin_API
  19.  *
  20.  * @package WordPress
  21.  * @subpackage Twenty_Twelve
  22.  * @since Twenty Twelve 1.0
  23.  */
  24.  
  25. // Set up the content width value based on the theme's design and stylesheet.
  26. if ( ! isset( $content_width ) )
  27.     $content_width = 625;
  28.  
  29. //Fix of adding action at the same priority to prevents corruption of the $wp_filter array while it's looping.
  30. add_action('init','WPECfix', 8000000);
  31. function WPECfix(){
  32.         if ( $priority = has_action('pre_get_posts', 'wpsc_generate_product_query') )
  33.                 add_action( 'pre_get_posts', '__return_null', $priority );
  34. }
  35.  
  36. /**
  37.  * Twenty Twelve setup.
  38.  *
  39.  * Sets up theme defaults and registers the various WordPress features that
  40.  * Twenty Twelve supports.
  41.  *
  42.  * @uses load_theme_textdomain() For translation/localization support.
  43.  * @uses add_editor_style() To add a Visual Editor stylesheet.
  44.  * @uses add_theme_support() To add support for post thumbnails, automatic feed links,
  45.  *  custom background, and post formats.
  46.  * @uses register_nav_menu() To add support for navigation menus.
  47.  * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  48.  *
  49.  * @since Twenty Twelve 1.0
  50.  */
  51. function twentytwelve_setup() {
  52.     /*
  53.      * Makes Twenty Twelve available for translation.
  54.      *
  55.      * Translations can be added to the /languages/ directory.
  56.      * If you're building a theme based on Twenty Twelve, use a find and replace
  57.      * to change 'twentytwelve' to the name of your theme in all the template files.
  58.      */
  59.     load_theme_textdomain( 'twentytwelve', get_template_directory() . '/languages' );
  60.  
  61.     // This theme styles the visual editor with editor-style.css to match the theme style.
  62.     add_editor_style();
  63.  
  64.     // Adds RSS feed links to <head> for posts and comments.
  65.     add_theme_support( 'automatic-feed-links' );
  66.  
  67.     // This theme supports a variety of post formats.
  68.     add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) );
  69.  
  70.     // This theme uses wp_nav_menu() in one location.
  71.     register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) );
  72.  
  73.     /*
  74.      * This theme supports custom background color and image,
  75.      * and here we also set up the default background color.
  76.      */
  77.     add_theme_support( 'custom-background', array(
  78.         'default-color' => 'e6e6e6',
  79.     ) );
  80.  
  81.     // This theme uses a custom image size for featured images, displayed on "standard" posts.
  82.     add_theme_support( 'post-thumbnails' );
  83.     set_post_thumbnail_size( 624, 9999 ); // Unlimited height, soft crop
  84. }
  85. add_action( 'after_setup_theme', 'twentytwelve_setup' );
  86.  
  87. /**
  88.  * Add support for a custom header image.
  89.  */
  90. require( get_template_directory() . '/inc/custom-header.php' );
  91.  
  92. /**
  93.  * Return the Google font stylesheet URL if available.
  94.  *
  95.  * The use of Open Sans by default is localized. For languages that use
  96.  * characters not supported by the font, the font can be disabled.
  97.  *
  98.  * @since Twenty Twelve 1.2
  99.  *
  100.  * @return string Font stylesheet or empty string if disabled.
  101.  */
  102. function twentytwelve_get_font_url() {
  103.     $font_url = '';
  104.  
  105.     /* translators: If there are characters in your language that are not supported
  106.      * by Open Sans, translate this to 'off'. Do not translate into your own language.
  107.      */
  108.     if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) {
  109.         $subsets = 'latin,latin-ext';
  110.  
  111.         /* translators: To add an additional Open Sans character subset specific to your language,
  112.          * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
  113.          */
  114.         $subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
  115.  
  116.         if ( 'cyrillic' == $subset )
  117.             $subsets .= ',cyrillic,cyrillic-ext';
  118.         elseif ( 'greek' == $subset )
  119.             $subsets .= ',greek,greek-ext';
  120.         elseif ( 'vietnamese' == $subset )
  121.             $subsets .= ',vietnamese';
  122.  
  123.         $protocol = is_ssl() ? 'https' : 'http';
  124.         $query_args = array(
  125.             'family' => 'Open+Sans:400italic,700italic,400,700',
  126.             'subset' => $subsets,
  127.         );
  128.         $font_url = add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" );
  129.     }
  130.  
  131.     return $font_url;
  132. }
  133.  
  134. /**
  135.  * Enqueue scripts and styles for front-end.
  136.  *
  137.  * @since Twenty Twelve 1.0
  138.  *
  139.  * @return void
  140.  */
  141. function twentytwelve_scripts_styles() {
  142.     global $wp_styles;
  143.  
  144.     /*
  145.      * Adds JavaScript to pages with the comment form to support
  146.      * sites with threaded comments (when in use).
  147.      */
  148.     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
  149.         wp_enqueue_script( 'comment-reply' );
  150.  
  151.     // Adds JavaScript for handling the navigation menu hide-and-show behavior.
  152.     wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true );
  153.  
  154.     $font_url = twentytwelve_get_font_url();
  155.     if ( ! empty( $font_url ) )
  156.         wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
  157.  
  158.     // Loads our main stylesheet.
  159.     wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() );
  160.  
  161.     // Loads the Internet Explorer specific stylesheet.
  162.     wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' );
  163.     $wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );
  164. }
  165. add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
  166.  
  167. /**
  168.  * Filter TinyMCE CSS path to include Google Fonts.
  169.  *
  170.  * Adds additional stylesheets to the TinyMCE editor if needed.
  171.  *
  172.  * @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL.
  173.  *
  174.  * @since Twenty Twelve 1.2
  175.  *
  176.  * @param string $mce_css CSS path to load in TinyMCE.
  177.  * @return string Filtered CSS path.
  178.  */
  179. function twentytwelve_mce_css( $mce_css ) {
  180.     $font_url = twentytwelve_get_font_url();
  181.  
  182.     if ( empty( $font_url ) )
  183.         return $mce_css;
  184.  
  185.     if ( ! empty( $mce_css ) )
  186.         $mce_css .= ',';
  187.  
  188.     $mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) );
  189.  
  190.     return $mce_css;
  191. }
  192. add_filter( 'mce_css', 'twentytwelve_mce_css' );
  193.  
  194. /**
  195.  * Filter the page title.
  196.  *
  197.  * Creates a nicely formatted and more specific title element text
  198.  * for output in head of document, based on current view.
  199.  *
  200.  * @since Twenty Twelve 1.0
  201.  *
  202.  * @param string $title Default title text for current view.
  203.  * @param string $sep Optional separator.
  204.  * @return string Filtered title.
  205.  */
  206. function twentytwelve_wp_title( $title, $sep ) {
  207.     global $paged, $page;
  208.  
  209.     if ( is_feed() )
  210.         return $title;
  211.  
  212.     // Add the site name.
  213.     $title .= get_bloginfo( 'name' );
  214.  
  215.     // Add the site description for the home/front page.
  216.     $site_description = get_bloginfo( 'description', 'display' );
  217.     if ( $site_description && ( is_home() || is_front_page() ) )
  218.         $title = "$title $sep $site_description";
  219.  
  220.     // Add a page number if necessary.
  221.     if ( $paged >= 2 || $page >= 2 )
  222.         $title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );
  223.  
  224.     return $title;
  225. }
  226. add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );
  227.  
  228. /**
  229.  * Filter the page menu arguments.
  230.  *
  231.  * Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link.
  232.  *
  233.  * @since Twenty Twelve 1.0
  234.  */
  235. function twentytwelve_page_menu_args( $args ) {
  236.     if ( ! isset( $args['show_home'] ) )
  237.         $args['show_home'] = true;
  238.     return $args;
  239. }
  240. add_filter( 'wp_page_menu_args', 'twentytwelve_page_menu_args' );
  241.  
  242. /**
  243.  * Register sidebars.
  244.  *
  245.  * Registers our main widget area and the front page widget areas.
  246.  *
  247.  * @since Twenty Twelve 1.0
  248.  */
  249. function twentytwelve_widgets_init() {
  250.     register_sidebar( array(
  251.         'name' => __( 'Main Sidebar', 'twentytwelve' ),
  252.         'id' => 'sidebar-1',
  253.         'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
  254.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  255.         'after_widget' => '</aside>',
  256.         'before_title' => '<h3 class="widget-title">',
  257.         'after_title' => '</h3>',
  258.     ) );
  259.  
  260.     register_sidebar( array(
  261.         'name' => __( 'First Front Page Widget Area', 'twentytwelve' ),
  262.         'id' => 'sidebar-2',
  263.         'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
  264.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  265.         'after_widget' => '</aside>',
  266.         'before_title' => '<h3 class="widget-title">',
  267.         'after_title' => '</h3>',
  268.     ) );
  269.  
  270.     register_sidebar( array(
  271.         'name' => __( 'Second Front Page Widget Area', 'twentytwelve' ),
  272.         'id' => 'sidebar-3',
  273.         'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
  274.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  275.         'after_widget' => '</aside>',
  276.         'before_title' => '<h3 class="widget-title">',
  277.         'after_title' => '</h3>',
  278.     ) );
  279. }
  280. add_action( 'widgets_init', 'twentytwelve_widgets_init' );
  281.  
  282. if ( ! function_exists( 'twentytwelve_content_nav' ) ) :
  283. /**
  284.  * Displays navigation to next/previous pages when applicable.
  285.  *
  286.  * @since Twenty Twelve 1.0
  287.  */
  288. function twentytwelve_content_nav( $html_id ) {
  289.     global $wp_query;
  290.  
  291.     $html_id = esc_attr( $html_id );
  292.  
  293.     if ( $wp_query->max_num_pages > 1 ) : ?>
  294.         <nav id="<?php echo $html_id; ?>" class="navigation" role="navigation">
  295.             <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
  296.             <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
  297.             <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
  298.         </nav><!-- #<?php echo $html_id; ?> .navigation -->
  299.     <?php endif;
  300. }
  301. endif;
  302.  
  303. if ( ! function_exists( 'twentytwelve_comment' ) ) :
  304. /**
  305.  * Template for comments and pingbacks.
  306.  *
  307.  * To override this walker in a child theme without modifying the comments template
  308.  * simply create your own twentytwelve_comment(), and that function will be used instead.
  309.  *
  310.  * Used as a callback by wp_list_comments() for displaying the comments.
  311.  *
  312.  * @since Twenty Twelve 1.0
  313.  *
  314.  * @return void
  315.  */
  316. function twentytwelve_comment( $comment, $args, $depth ) {
  317.     $GLOBALS['comment'] = $comment;
  318.     switch ( $comment->comment_type ) :
  319.         case 'pingback' :
  320.         case 'trackback' :
  321.         // Display trackbacks differently than normal comments.
  322.     ?>
  323.     <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
  324.         <p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>
  325.     <?php
  326.             break;
  327.         default :
  328.         // Proceed with normal comments.
  329.         global $post;
  330.     ?>
  331.     <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  332.         <article id="comment-<?php comment_ID(); ?>" class="comment">
  333.             <header class="comment-meta comment-author vcard">
  334.                 <?php
  335.                     echo get_avatar( $comment, 44 );
  336.                     printf( '<cite><b class="fn">%1$s</b> %2$s</cite>',
  337.                         get_comment_author_link(),
  338.                         // If current post author is also comment author, make it known visually.
  339.                         ( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''
  340.                     );
  341.                     printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
  342.                         esc_url( get_comment_link( $comment->comment_ID ) ),
  343.                         get_comment_time( 'c' ),
  344.                         /* translators: 1: date, 2: time */
  345.                         sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
  346.                     );
  347.                 ?>
  348.             </header><!-- .comment-meta -->
  349.  
  350.             <?php if ( '0' == $comment->comment_approved ) : ?>
  351.                 <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwelve' ); ?></p>
  352.             <?php endif; ?>
  353.  
  354.             <section class="comment-content comment">
  355.                 <?php comment_text(); ?>
  356.                 <?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>
  357.             </section><!-- .comment-content -->
  358.  
  359.             <div class="reply">
  360.                 <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'twentytwelve' ), 'after' => ' <span>&darr;</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  361.             </div><!-- .reply -->
  362.         </article><!-- #comment-## -->
  363.     <?php
  364.         break;
  365.     endswitch; // end comment_type check
  366. }
  367. endif;
  368.  
  369. if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
  370. /**
  371.  * Set up post entry meta.
  372.  *
  373.  * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
  374.  *
  375.  * Create your own twentytwelve_entry_meta() to override in a child theme.
  376.  *
  377.  * @since Twenty Twelve 1.0
  378.  *
  379.  * @return void
  380.  */
  381. function twentytwelve_entry_meta() {
  382.     // Translators: used between list items, there is a space after the comma.
  383.     $categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
  384.  
  385.     // Translators: used between list items, there is a space after the comma.
  386.     $tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
  387.  
  388.     $date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
  389.         esc_url( get_permalink() ),
  390.         esc_attr( get_the_time() ),
  391.         esc_attr( get_the_date( 'c' ) ),
  392.         esc_html( get_the_date() )
  393.     );
  394.  
  395.     $author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
  396.         esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  397.         esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
  398.         get_the_author()
  399.     );
  400.  
  401.     // Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
  402.     if ( $tag_list ) {
  403.         $utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
  404.     } elseif ( $categories_list ) {
  405.         $utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
  406.     } else {
  407.         $utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
  408.     }
  409.  
  410.     printf(
  411.         $utility_text,
  412.         $categories_list,
  413.         $tag_list,
  414.         $date,
  415.         $author
  416.     );
  417. }
  418. endif;
  419.  
  420. /**
  421.  * Extend the default WordPress body classes.
  422.  *
  423.  * Extends the default WordPress body class to denote:
  424.  * 1. Using a full-width layout, when no active widgets in the sidebar
  425.  *    or full-width template.
  426.  * 2. Front Page template: thumbnail in use and number of sidebars for
  427.  *    widget areas.
  428.  * 3. White or empty background color to change the layout and spacing.
  429.  * 4. Custom fonts enabled.
  430.  * 5. Single or multiple authors.
  431.  *
  432.  * @since Twenty Twelve 1.0
  433.  *
  434.  * @param array $classes Existing class values.
  435.  * @return array Filtered class values.
  436.  */
  437. function twentytwelve_body_class( $classes ) {
  438.     $background_color = get_background_color();
  439.     $background_image = get_background_image();
  440.  
  441.     if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) )
  442.         $classes[] = 'full-width';
  443.  
  444.     if ( is_page_template( 'page-templates/front-page.php' ) ) {
  445.         $classes[] = 'template-front-page';
  446.         if ( has_post_thumbnail() )
  447.             $classes[] = 'has-post-thumbnail';
  448.         if ( is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) )
  449.             $classes[] = 'two-sidebars';
  450.     }
  451.  
  452.     if ( empty( $background_image ) ) {
  453.         if ( empty( $background_color ) )
  454.             $classes[] = 'custom-background-empty';
  455.         elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) )
  456.             $classes[] = 'custom-background-white';
  457.     }
  458.  
  459.     // Enable custom font class only if the font CSS is queued to load.
  460.     if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) )
  461.         $classes[] = 'custom-font-enabled';
  462.  
  463.     if ( ! is_multi_author() )
  464.         $classes[] = 'single-author';
  465.  
  466.     return $classes;
  467. }
  468. add_filter( 'body_class', 'twentytwelve_body_class' );
  469.  
  470. /**
  471.  * Adjust content width in certain contexts.
  472.  *
  473.  * Adjusts content_width value for full-width and single image attachment
  474.  * templates, and when there are no active widgets in the sidebar.
  475.  *
  476.  * @since Twenty Twelve 1.0
  477.  *
  478.  * @return void
  479.  */
  480. function twentytwelve_content_width() {
  481.     if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() || ! is_active_sidebar( 'sidebar-1' ) ) {
  482.         global $content_width;
  483.         $content_width = 960;
  484.     }
  485. }
  486. add_action( 'template_redirect', 'twentytwelve_content_width' );
  487.  
  488. /**
  489.  * Register postMessage support.
  490.  *
  491.  * Add postMessage support for site title and description for the Customizer.
  492.  *
  493.  * @since Twenty Twelve 1.0
  494.  *
  495.  * @param WP_Customize_Manager $wp_customize Customizer object.
  496.  * @return void
  497.  */
  498. function twentytwelve_customize_register( $wp_customize ) {
  499.     $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
  500.     $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
  501.     $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
  502. }
  503. add_action( 'customize_register', 'twentytwelve_customize_register' );
  504.  
  505. /**
  506.  * Enqueue Javascript postMessage handlers for the Customizer.
  507.  *
  508.  * Binds JS handlers to make the Customizer preview reload changes asynchronously.
  509.  *
  510.  * @since Twenty Twelve 1.0
  511.  *
  512.  * @return void
  513.  */
  514. function twentytwelve_customize_preview_js() {
  515.     wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20130301', true );
  516. }
  517. add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement