Advertisement
jegtheme

functions.php

Mar 2nd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.97 KB | None | 0 0
  1. <?php
  2.  
  3. function jeg_init_variable()
  4. {
  5.     /* Theme Name */
  6.     defined( 'JEG_THEMENAME' ) or define("JEG_THEMENAME", 'Minimy');
  7.     defined( 'JEG_SHORTNAME' ) or define("JEG_SHORTNAME", 'minimy');
  8.     defined( 'JEG_THEME' ) or define("JEG_THEME", 'jegtheme');
  9.  
  10.     /* url */
  11.     defined( 'JEG_SERVER_URL' ) or define( "JEG_SERVER_URL", "http://jegtheme.com");
  12.     defined( 'JEG_PURCHASE_URL') or define( "JEG_PURCHASE_URL", "http://jegtheme.com/ads/jkreativ.html" );
  13.     defined( 'JEG_VALIDATION_URL' ) or define( "JEG_VALIDATION_URL", "http://jegtheme.com/client/validate/license");
  14.     defined( 'JEG_SUPPORT_FORUM_URL' ) or define( "JEG_SUPPORT_FORUM_URL", "http://support.jegtheme.com");
  15.     defined( 'JEG_LICENSE_NAME' ) or define( "JEG_LICENSE_NAME", "jkreativ_license" );
  16.  
  17.     /* themes version */
  18.     $themeData          = wp_get_theme();
  19.     $themeVersion       = trim($themeData['Version']);
  20.     if (!$themeVersion)   $themeVersion = "1.0.0";
  21.     define("JEG_VERSION"    , $themeVersion);
  22.  
  23.     // Register Menu
  24.     register_nav_menus( array('primary' => 'Primary Menu',) );
  25.  
  26.     // Localization Support
  27.     load_theme_textdomain('jeg_textdomain', get_template_directory() . '/lang');
  28.  
  29.     // Support feed link
  30.     add_theme_support( 'automatic-feed-links' );
  31.  
  32.     // Featured image
  33.     add_theme_support( 'post-thumbnails' );
  34.  
  35.     // Support Post Types
  36.     add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link', 'quote', 'video', 'audio' ) );
  37.  
  38.     // Add Title Tag
  39.     add_theme_support( 'title-tag' );
  40.  
  41.     // Thumbnail Size
  42.     add_image_size( 'postnav-thumb', 120, 120, true ); // (cropped)
  43.     add_image_size( 'gallery-thumb', 200, 200, true ); // (cropped)
  44.  
  45.     // Unnecesary add
  46.     if ( ! isset( $content_width ) ) $content_width = 900;
  47. }
  48.  
  49. jeg_init_variable();
  50.  
  51. /* ------------------------------------------------------------------------- *
  52.  *  Register Widgets
  53.  * ------------------------------------------------------------------------- */
  54. function jeg_init_sidebar() {
  55.  
  56.     // Sidebar Widget
  57.     register_sidebar( array(
  58.         'name'          => __( 'Primary Sidebar', 'jeg_textdomain' ),
  59.         'id'            => 'sidebar',
  60.         'description'   => __( 'Main sidebar that appears on the right.', 'jeg_textdomain' ),
  61.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  62.         'before_title'  => '<h1 class="widget-title">',
  63.         'after_title'   => '</h1>',
  64.         'after_widget'  => '</aside>',
  65.     ) );
  66.  
  67.     // Footer Widget 1
  68.     register_sidebar( array(
  69.         'name'          => __( 'Footer Widget 1', 'jeg_textdomain' ),
  70.         'id'            => 'footer1',
  71.         'description'   => __( 'Footer widget that appear on first column.', 'jeg_textdomain' ),
  72.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  73.         'before_title'  => '<h1 class="widget-title">',
  74.         'after_title'   => '</h1>',
  75.         'after_widget'  => '</aside>',
  76.     ) );
  77.  
  78.     // Footer Widget 2
  79.     register_sidebar( array(
  80.         'name'          => __( 'Footer Widget 2', 'jeg_textdomain' ),
  81.         'id'            => 'footer2',
  82.         'description'   => __( 'Footer widget that appear on second column.', 'jeg_textdomain' ),
  83.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  84.         'before_title'  => '<h1 class="widget-title">',
  85.         'after_title'   => '</h1>',
  86.         'after_widget'  => '</aside>',
  87.     ) );
  88.  
  89.     // Footer Widget 3
  90.     register_sidebar( array(
  91.         'name'          => __( 'Footer Widget 3', 'jeg_textdomain' ),
  92.         'id'            => 'footer3',
  93.         'description'   => __( 'Footer widget that appear on third column.', 'jeg_textdomain' ),
  94.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  95.         'before_title'  => '<h1 class="widget-title">',
  96.         'after_title'   => '</h1>',
  97.         'after_widget'  => '</aside>',
  98.     ) );
  99. }
  100. add_action( 'widgets_init', 'jeg_init_sidebar' );
  101.  
  102. function jeg_add_author_socials( $socials ) {
  103.     $socials = array(
  104.         'twitter' => 'Twitter',
  105.         'facebook' => 'Facebook',
  106.     );
  107.     return $socials;
  108. }
  109. add_filter('user_contactmethods','jeg_add_author_socials',10,1);
  110.  
  111.  
  112.  
  113. // alter size of post gallery
  114. function jeg_gallery_shortcode($output, $attr){
  115.     $attr['size'] = 'gallery-thumb';
  116.     $post = get_post();
  117.  
  118.     static $instance = 0;
  119.     $instance++;
  120.  
  121.     if ( ! empty( $attr['ids'] ) ) {
  122.         // 'ids' is explicitly ordered, unless you specify otherwise.
  123.         if ( empty( $attr['orderby'] ) ) {
  124.             $attr['orderby'] = 'post__in';
  125.         }
  126.         $attr['include'] = $attr['ids'];
  127.     }
  128.  
  129.     // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
  130.     if ( isset( $attr['orderby'] ) ) {
  131.         $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
  132.         if ( ! $attr['orderby'] ) {
  133.             unset( $attr['orderby'] );
  134.         }
  135.     }
  136.  
  137.     $html5 = current_theme_supports( 'html5', 'gallery' );
  138.     $atts = shortcode_atts( array(
  139.         'order'      => 'ASC',
  140.         'orderby'    => 'menu_order ID',
  141.         'id'         => $post ? $post->ID : 0,
  142.         'itemtag'    => $html5 ? 'figure'     : 'dl',
  143.         'icontag'    => $html5 ? 'div'        : 'dt',
  144.         'captiontag' => $html5 ? 'figcaption' : 'dd',
  145.         'columns'    => 3,
  146.         'size'       => 'thumbnail',
  147.         'include'    => '',
  148.         'exclude'    => '',
  149.         'link'       => ''
  150.     ), $attr, 'gallery' );
  151.  
  152.     $id = intval( $atts['id'] );
  153.     if ( 'RAND' == $atts['order'] ) {
  154.         $atts['orderby'] = 'none';
  155.     }
  156.  
  157.     if ( ! empty( $atts['include'] ) ) {
  158.         $_attachments = get_posts( array( 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
  159.  
  160.         $attachments = array();
  161.         foreach ( $_attachments as $key => $val ) {
  162.             $attachments[$val->ID] = $_attachments[$key];
  163.         }
  164.     } elseif ( ! empty( $atts['exclude'] ) ) {
  165.         $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
  166.     } else {
  167.         $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
  168.     }
  169.  
  170.     if ( empty( $attachments ) ) {
  171.         return '';
  172.     }
  173.  
  174.     if ( is_feed() ) {
  175.         $output = "\n";
  176.         foreach ( $attachments as $att_id => $attachment ) {
  177.             $output .= wp_get_attachment_link( $att_id, $atts['size'], true ) . "\n";
  178.         }
  179.         return $output;
  180.     }
  181.  
  182.     $itemtag = tag_escape( $atts['itemtag'] );
  183.     $captiontag = tag_escape( $atts['captiontag'] );
  184.     $icontag = tag_escape( $atts['icontag'] );
  185.     $valid_tags = wp_kses_allowed_html( 'post' );
  186.     if ( ! isset( $valid_tags[ $itemtag ] ) ) {
  187.         $itemtag = 'dl';
  188.     }
  189.     if ( ! isset( $valid_tags[ $captiontag ] ) ) {
  190.         $captiontag = 'dd';
  191.     }
  192.     if ( ! isset( $valid_tags[ $icontag ] ) ) {
  193.         $icontag = 'dt';
  194.     }
  195.  
  196.     $columns = intval( $atts['columns'] );
  197.     $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
  198.     $float = is_rtl() ? 'right' : 'left';
  199.  
  200.     $selector = "gallery-{$instance}";
  201.  
  202.     $gallery_style = '';
  203.  
  204.     /**
  205.      * Filter whether to print default gallery styles.
  206.      *
  207.      * @since 3.1.0
  208.      *
  209.      * @param bool $print Whether to print default gallery styles.
  210.      *                    Defaults to false if the theme supports HTML5 galleries.
  211.      *                    Otherwise, defaults to true.
  212.      */
  213.     if ( apply_filters( 'use_default_gallery_style', ! $html5 ) ) {
  214.         $gallery_style = "
  215.         <style type='text/css'>
  216.             #{$selector} {
  217.                 margin: auto;
  218.             }
  219.             #{$selector} .gallery-item {
  220.                 float: {$float};
  221.                 margin-top: 10px;
  222.                 text-align: center;
  223.                 width: {$itemwidth}%;
  224.             }
  225.             #{$selector} img {
  226.                 border: 2px solid #cfcfcf;
  227.             }
  228.             #{$selector} .gallery-caption {
  229.                 margin-left: 0;
  230.             }
  231.             /* see gallery_shortcode() in wp-includes/media.php */
  232.         </style>\n\t\t";
  233.     }
  234.  
  235.     $size_class = sanitize_html_class( $atts['size'] );
  236.     $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
  237.  
  238.     /**
  239.      * Filter the default gallery shortcode CSS styles.
  240.      *
  241.      * @since 2.5.0
  242.      *
  243.      * @param string $gallery_style Default gallery shortcode CSS styles.
  244.      * @param string $gallery_div   Opening HTML div container for the gallery shortcode output.
  245.      */
  246.     $output = apply_filters( 'gallery_style', $gallery_style . $gallery_div );
  247.  
  248.     $i = 0;
  249.     foreach ( $attachments as $id => $attachment ) {
  250.         if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] ) {
  251.             $image_output = wp_get_attachment_link( $id, $atts['size'], false, false );
  252.         } elseif ( ! empty( $atts['link'] ) && 'none' === $atts['link'] ) {
  253.             $image_output = wp_get_attachment_image( $id, $atts['size'], false );
  254.         } else {
  255.             $image_output = wp_get_attachment_link( $id, $atts['size'], true, false );
  256.         }
  257.         $image_meta  = wp_get_attachment_metadata( $id );
  258.  
  259.         $orientation = '';
  260.         if ( isset( $image_meta['height'], $image_meta['width'] ) ) {
  261.             $orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape';
  262.         }
  263.         $output .= "<{$itemtag} class='gallery-item'>";
  264.         $output .= "
  265.             <{$icontag} class='gallery-icon {$orientation}'>
  266.                 $image_output
  267.             </{$icontag}>";
  268.         if ( $captiontag && trim($attachment->post_excerpt) ) {
  269.             $output .= "
  270.                 <{$captiontag} class='wp-caption-text gallery-caption'>
  271.                 " . wptexturize($attachment->post_excerpt) . "
  272.                 </{$captiontag}>";
  273.         }
  274.         $output .= "</{$itemtag}>";
  275.         if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) {
  276.             $output .= '<br style="clear: both" />';
  277.         }
  278.     }
  279.  
  280.     if ( ! $html5 && $columns > 0 && $i % $columns !== 0 ) {
  281.         $output .= "
  282.             <br style='clear: both' />";
  283.     }
  284.  
  285.     $output .= "
  286.         </div>\n";
  287.  
  288.     return $output;
  289.  
  290. }
  291. add_filter( 'post_gallery', 'jeg_gallery_shortcode', 10, 2 );
  292.  
  293.  
  294. function jeg_oembed_wrapper($html, $url, $attr, $post_id) {
  295.     return "<div class='video-container'>{$html}</div>";
  296. }
  297. add_filter('embed_oembed_html','jeg_oembed_wrapper',10,4);
  298.  
  299.  
  300. // Include Libraries
  301. locate_template(array('lib/scriptstyle.php'), true, true);
  302. locate_template(array('lib/jeg-functions.php'), true, true);
  303. locate_template(array('lib/jeg-customizer.php'), true, true);
  304. locate_template(array('tgm/plugin-list.php'), true, true);
  305. locate_template(array('lib/additional-widget.php'), true, true);
  306. locate_template(array('lib/jtemplate.php'), true, true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement