Advertisement
Guest User

Functions.php

a guest
Oct 11th, 2018
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 44.43 KB | None | 0 0
  1. <?php
  2.  
  3. // Add Translation Option
  4. load_theme_textdomain( 'wpbootstrap', TEMPLATEPATH.'/languages' );
  5. $locale = get_locale();
  6. $locale_file = TEMPLATEPATH . "/languages/$locale.php";
  7. if ( is_readable( $locale_file ) ) require_once( $locale_file );
  8.  
  9. // Clean up the WordPress Head
  10. if( !function_exists( "wp_bootstrap_head_cleanup" ) ) {
  11.   function wp_bootstrap_head_cleanup() {
  12.     // remove header links
  13.     remove_action( 'wp_head', 'feed_links_extra', 3 );                    // Category Feeds
  14.     remove_action( 'wp_head', 'feed_links', 2 );                          // Post and Comment Feeds
  15.     remove_action( 'wp_head', 'rsd_link' );                               // EditURI link
  16.     remove_action( 'wp_head', 'wlwmanifest_link' );                       // Windows Live Writer
  17.     remove_action( 'wp_head', 'index_rel_link' );                         // index link
  18.     remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );            // previous link
  19.     remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );             // start link
  20.     remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Links for Adjacent Posts
  21.     remove_action( 'wp_head', 'wp_generator' );                           // WP version
  22.   }
  23. }
  24. // Launch operation cleanup
  25. add_action( 'init', 'wp_bootstrap_head_cleanup' );
  26.  
  27. // remove WP version from RSS
  28. if( !function_exists( "wp_bootstrap_rss_version" ) ) {
  29.   function wp_bootstrap_rss_version() { return ''; }
  30. }
  31. add_filter( 'the_generator', 'wp_bootstrap_rss_version' );
  32.  
  33. // Remove the […] in a Read More link
  34. if( !function_exists( "wp_bootstrap_excerpt_more" ) ) {
  35.   function wp_bootstrap_excerpt_more( $more ) {
  36.     global $post;
  37.     return '<span class="after-desc">›</span>';
  38.   }
  39. }
  40. add_filter('excerpt_more', 'wp_bootstrap_excerpt_more');
  41.  
  42. // Add WP 3+ Functions & Theme Support
  43. if( !function_exists( "wp_bootstrap_theme_support" ) ) {
  44.   function wp_bootstrap_theme_support() {
  45.     add_theme_support( 'post-thumbnails' );      // wp thumbnails (sizes handled in functions.php)
  46.     set_post_thumbnail_size( 125, 125, true );   // default thumb size
  47.     add_theme_support( 'custom-background' );  // wp custom background
  48.     add_theme_support( 'automatic-feed-links' ); // rss
  49.  
  50.     // Add post format support - if these are not needed, comment them out
  51.     add_theme_support( 'post-formats',      // post formats
  52.       array(
  53.         'aside',   // title less blurb
  54.         'gallery', // gallery of images
  55.         'link',    // quick link to other site
  56.         'image',   // an image
  57.         'quote',   // a quick quote
  58.         'status',  // a Facebook like status update
  59.         'video',   // video
  60.         'audio',   // audio
  61.         'chat'     // chat transcript
  62.       )
  63.     );
  64.  
  65.     add_theme_support( 'menus' );            // wp menus
  66.  
  67.     register_nav_menus(                      // wp3+ menus
  68.       array(
  69.         'main_nav' => 'The Main Menu',   // main nav in header
  70.         'footer_links' => 'Footer Links' // secondary nav in footer
  71.       )
  72.     );
  73.   }
  74. }
  75. // launching this stuff after theme setup
  76. add_action( 'after_setup_theme','wp_bootstrap_theme_support' );
  77.  
  78. function wp_bootstrap_main_nav() {
  79.   // Display the WordPress menu if available
  80.   wp_nav_menu(
  81.     array(
  82.       'menu' => 'main_nav', /* menu name */
  83.       'menu_class' => 'nav navbar-nav',
  84.       'theme_location' => 'main_nav', /* where in the theme it's assigned */
  85.       'container' => 'false', /* container class */
  86.       'fallback_cb' => 'wp_bootstrap_main_nav_fallback', /* menu fallback */
  87.       'walker' => new Bootstrap_walker()
  88.     )
  89.   );
  90. }
  91.  
  92. function wp_bootstrap_footer_links() {
  93.   // Display the WordPress menu if available
  94.   wp_nav_menu(
  95.     array(
  96.       'menu' => 'footer_links', /* menu name */
  97.       'theme_location' => 'footer_links', /* where in the theme it's assigned */
  98.       'container_class' => 'footer-links', /* container class */
  99.       'fallback_cb' => 'wp_bootstrap_footer_links_fallback' /* menu fallback */
  100.     )
  101.   );
  102. }
  103.  
  104. // this is the fallback for header menu
  105. function wp_bootstrap_main_nav_fallback() {
  106.   /* you can put a default here if you like */
  107. }
  108.  
  109. // this is the fallback for footer menu
  110. function wp_bootstrap_footer_links_fallback() {
  111.   /* you can put a default here if you like */
  112. }
  113.  
  114. // Shortcodes
  115. require_once('library/shortcodes.php');
  116.  
  117. // Admin Functions (commented out by default)
  118. // require_once('library/admin.php');         // custom admin functions
  119.  
  120. // Custom Backend Footer
  121. add_filter('admin_footer_text', 'wp_bootstrap_custom_admin_footer');
  122. function wp_bootstrap_custom_admin_footer() {
  123.     echo '<span id="footer-thankyou">Developed by <a href="http://320press.com" target="_blank">320press</a></span>. Built using <a href="http://themble.com/bones" target="_blank">Bones</a>.';
  124. }
  125.  
  126. // adding it to the admin area
  127. add_filter('admin_footer_text', 'wp_bootstrap_custom_admin_footer');
  128.  
  129. // Set content width
  130. if ( ! isset( $content_width ) ) $content_width = 580;
  131.  
  132. /************* THUMBNAIL SIZE OPTIONS *************/
  133.  
  134. // Thumbnail sizes
  135. add_image_size( 'wpbs-featured', 780, 300, true );
  136. add_image_size( 'wpbs-featured-home', 970, 311, true);
  137. add_image_size( 'wpbs-featured-carousel', 970, 400, true);
  138.  
  139. /*
  140. to add more sizes, simply copy a line from above
  141. and change the dimensions & name. As long as you
  142. upload a "featured image" as large as the biggest
  143. set width or height, all the other sizes will be
  144. auto-cropped.
  145.  
  146. To call a different size, simply change the text
  147. inside the thumbnail function.
  148.  
  149. For example, to call the 300 x 300 sized image,
  150. we would use the function:
  151. <?php the_post_thumbnail( 'bones-thumb-300' ); ?>
  152. for the 600 x 100 image:
  153. <?php the_post_thumbnail( 'bones-thumb-600' ); ?>
  154.  
  155. You can change the names and dimensions to whatever
  156. you like. Enjoy!
  157. */
  158.  
  159. /************* ACTIVE SIDEBARS ********************/
  160.  
  161. // Sidebars & Widgetizes Areas
  162. function wp_bootstrap_register_sidebars() {
  163.   register_sidebar(array(
  164.     'id' => 'sidebar1',
  165.     'name' => 'Main Sidebar',
  166.     'description' => 'Used on every page BUT the homepage page template.',
  167.     'before_widget' => '<div id="%1$s" class="widget %2$s">',
  168.     'after_widget' => '</div>',
  169.     'before_title' => '<h4 class="widgettitle">',
  170.     'after_title' => '</h4>',
  171.   ));
  172.  
  173.   register_sidebar(array(
  174.     'id' => 'sidebar2',
  175.     'name' => 'Homepage Sidebar',
  176.     'description' => 'Used only on the homepage page template.',
  177.     'before_widget' => '<div id="%1$s" class="widget %2$s">',
  178.     'after_widget' => '</div>',
  179.     'before_title' => '<h4 class="widgettitle">',
  180.     'after_title' => '</h4>',
  181.   ));
  182.  
  183.   register_sidebar(array(
  184.     'id' => 'footer1',
  185.     'name' => 'Footer 1',
  186.     'before_widget' => '<div id="%1$s" class="widget col-sm-3 %2$s">',
  187.     'after_widget' => '</div>',
  188.     'before_title' => '<h4 class="widgettitle">',
  189.     'after_title' => '</h4>',
  190.   ));
  191.  
  192.   register_sidebar(array(
  193.     'id' => 'footer2',
  194.     'name' => 'Footer 2',
  195.     'before_widget' => '<div id="%1$s" class="widget col-sm-3 %2$s">',
  196.     'after_widget' => '</div>',
  197.     'before_title' => '<h4 class="widgettitle">',
  198.     'after_title' => '</h4>',
  199.   ));
  200.  
  201.   register_sidebar(array(
  202.     'id' => 'footer3',
  203.     'name' => 'Footer 3',
  204.     'before_widget' => '<div id="%1$s" class="widget col-sm-4 %2$s">',
  205.     'after_widget' => '</div>',
  206.     'before_title' => '<h4 class="widgettitle">',
  207.     'after_title' => '</h4>',
  208.   ));
  209.  
  210.  
  211.   /*
  212.   to add more sidebars or widgetized areas, just copy
  213.   and edit the above sidebar code. In order to call
  214.   your new sidebar just use the following code:
  215.  
  216.   Just change the name to whatever your new
  217.   sidebar's id is, for example:
  218.  
  219.   To call the sidebar in your template, you can just copy
  220.   the sidebar.php file and rename it to your sidebar's name.
  221.   So using the above example, it would be:
  222.   sidebar-sidebar2.php
  223.  
  224.   */
  225. } // don't remove this bracket!
  226. add_action( 'widgets_init', 'wp_bootstrap_register_sidebars' );
  227.  
  228. /************* COMMENT LAYOUT *********************/
  229.  
  230. // Comment Layout
  231. function wp_bootstrap_comments($comment, $args, $depth) {
  232.    $GLOBALS['comment'] = $comment; ?>
  233.     <li <?php comment_class(); ?>
  234.         <article id="comment-<?php comment_ID(); ?>" class="clearfix">
  235.             <div class="comment-author vcard clearfix">
  236.                 <div class="avatar col-sm-3">
  237.                     <?php echo get_avatar( $comment, $size='75' ); ?>
  238.                 </div>
  239.                 <div class="col-sm-9 comment-text">
  240.                     <?php printf('<h4>%s</h4>', get_comment_author_link()) ?>
  241.                     <?php edit_comment_link(__('Edit','wpbootstrap'),'<span class="edit-comment btn btn-sm btn-info"><i class="glyphicon-white glyphicon-pencil"></i>','</span>') ?>
  242.  
  243.                     <?php if ($comment->comment_approved == '0') : ?>
  244.                         <div class="alert-message success">
  245.                         <p><?php _e('Your comment is awaiting moderation.','wpbootstrap') ?></p>
  246.                         </div>
  247.                     <?php endif; ?>
  248.  
  249.                     <?php comment_text() ?>
  250.  
  251.                     <time datetime="<?php echo comment_time('Y-m-j'); ?>"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php comment_time('F jS, Y'); ?> </a></time>
  252.  
  253.                     <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  254.                 </div>
  255.             </div>
  256.         </article>
  257.     <!-- </li> is added by wordpress automatically -->
  258. <?php
  259. } // don't remove this bracket!
  260.  
  261. // Display trackbacks/pings callback function
  262. function list_pings($comment, $args, $depth) {
  263.        $GLOBALS['comment'] = $comment;
  264. ?>
  265.         <li id="comment-<?php comment_ID(); ?>"><i class="icon icon-share-alt"></i>&nbsp;<?php comment_author_link(); ?>
  266. <?php
  267.  
  268. }
  269.  
  270. /************* SEARCH FORM LAYOUT *****************/
  271.  
  272. /****************** password protected post form *****/
  273.  
  274. add_filter( 'the_password_form', 'wp_bootstrap_custom_password_form' );
  275.  
  276. function wp_bootstrap_custom_password_form() {
  277.     global $post;
  278.     $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
  279.     $o = '<div class="clearfix"><form class="protected-post-form" action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post">
  280.     ' . '<p>' . __( "This post is password protected. To view it please enter your password below:" ,'wpbootstrap') . '</p>' . '
  281.     <label for="' . $label . '">' . __( "Password:" ,'wpbootstrap') . ' </label><div class="input-append"><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" class="btn btn-primary" value="' . esc_attr__( "Submit",'wpbootstrap' ) . '" /></div>
  282.     </form></div>
  283.     ';
  284.     return $o;
  285. }
  286.  
  287. /*********** update standard wp tag cloud widget so it looks better ************/
  288.  
  289. add_filter( 'widget_tag_cloud_args', 'wp_bootstrap_my_widget_tag_cloud_args' );
  290.  
  291. function wp_bootstrap_my_widget_tag_cloud_args( $args ) {
  292.     $args['number'] = 20; // show less tags
  293.     $args['largest'] = 9.75; // make largest and smallest the same - i don't like the varying font-size look
  294.     $args['smallest'] = 9.75;
  295.     $args['unit'] = 'px';
  296.     return $args;
  297. }
  298.  
  299. // filter tag clould output so that it can be styled by CSS
  300. function wp_bootstrap_add_tag_class( $taglinks ) {
  301.     $tags = explode('</a>', $taglinks);
  302.     $regex = "#(.*tag-link[-])(.*)(' title.*)#e";
  303.  
  304.     foreach( $tags as $tag ) {
  305.         $tagn[] = preg_replace($regex, "('$1$2 label tag-'.get_tag($2)->slug.'$3')", $tag );
  306.     }
  307.  
  308.     $taglinks = implode('</a>', $tagn);
  309.  
  310.     return $taglinks;
  311. }
  312.  
  313. add_action( 'wp_tag_cloud', 'wp_bootstrap_add_tag_class' );
  314.  
  315. add_filter( 'wp_tag_cloud','wp_bootstrap_wp_tag_cloud_filter', 10, 2) ;
  316.  
  317. function wp_bootstrap_wp_tag_cloud_filter( $return, $args )
  318. {
  319.   return '<div id="tag-cloud">' . $return . '</div>';
  320. }
  321.  
  322. // Enable shortcodes in widgets
  323. add_filter( 'widget_text', 'do_shortcode' );
  324.  
  325. // Disable jump in 'read more' link
  326. function wp_bootstrap_remove_more_jump_link( $link ) {
  327.     $offset = strpos($link, '#more-');
  328.     if ( $offset ) {
  329.         $end = strpos( $link, '"',$offset );
  330.     }
  331.     if ( $end ) {
  332.         $link = substr_replace( $link, '', $offset, $end-$offset );
  333.     }
  334.     return $link;
  335. }
  336. add_filter( 'the_content_more_link', 'wp_bootstrap_remove_more_jump_link' );
  337.  
  338. // Remove height/width attributes on images so they can be responsive
  339. add_filter( 'post_thumbnail_html', 'wp_bootstrap_remove_thumbnail_dimensions', 10 );
  340. add_filter( 'image_send_to_editor', 'wp_bootstrap_remove_thumbnail_dimensions', 10 );
  341.  
  342. function wp_bootstrap_remove_thumbnail_dimensions( $html ) {
  343.     $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
  344.     return $html;
  345. }
  346.  
  347. // Add the Meta Box to the homepage template
  348. function wp_bootstrap_add_homepage_meta_box() {
  349.     global $post;
  350.  
  351.     // Only add homepage meta box if template being used is the homepage template
  352.     // $post_id = isset($_GET['post']) ? $_GET['post'] : (isset($_POST['post_ID']) ? $_POST['post_ID'] : "");
  353.     $post_id = $post->ID;
  354.     $template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
  355.  
  356.     if ( $template_file == 'page-homepage.php' ){
  357.         add_meta_box(
  358.             'homepage_meta_box', // $id
  359.             'Optional Homepage Tagline', // $title
  360.             'wp_bootstrap_show_homepage_meta_box', // $callback
  361.             'page', // $page
  362.             'normal', // $context
  363.             'high'); // $priority
  364.     }
  365. }
  366.  
  367. add_action( 'add_meta_boxes', 'wp_bootstrap_add_homepage_meta_box' );
  368.  
  369. // Field Array
  370. $prefix = 'custom_';
  371. $custom_meta_fields = array(
  372.     array(
  373.         'label'=> 'Homepage tagline area',
  374.         'desc'  => 'Displayed underneath page title. Only used on homepage template. HTML can be used.',
  375.         'id'    => $prefix.'tagline',
  376.         'type'  => 'textarea'
  377.     )
  378. );
  379.  
  380. // The Homepage Meta Box Callback
  381. function wp_bootstrap_show_homepage_meta_box() {
  382.   global $custom_meta_fields, $post;
  383.  
  384.   // Use nonce for verification
  385.   wp_nonce_field( basename( __FILE__ ), 'wpbs_nonce' );
  386.  
  387.   // Begin the field table and loop
  388.   echo '<table class="form-table">';
  389.  
  390.   foreach ( $custom_meta_fields as $field ) {
  391.       // get value of this field if it exists for this post
  392.       $meta = get_post_meta($post->ID, $field['id'], true);
  393.       // begin a table row with
  394.       echo '<tr>
  395.              <th><label for="'.$field['id'].'">'.$field['label'].'</label></th>
  396.              <td>';
  397.               switch($field['type']) {
  398.                   // text
  399.                   case 'text':
  400.                       echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="60" />
  401.                          <br /><span class="description">'.$field['desc'].'</span>';
  402.                   break;
  403.  
  404.                   // textarea
  405.                   case 'textarea':
  406.                       echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="80" rows="4">'.$meta.'</textarea>
  407.                          <br /><span class="description">'.$field['desc'].'</span>';
  408.                   break;
  409.               } //end switch
  410.       echo '</td></tr>';
  411.   } // end foreach
  412.   echo '</table>'; // end table
  413. }
  414.  
  415. // Save the Data
  416. function wp_bootstrap_save_homepage_meta( $post_id ) {
  417.  
  418.     global $custom_meta_fields;
  419.  
  420.     // verify nonce
  421.     if ( !isset( $_POST['wpbs_nonce'] ) || !wp_verify_nonce($_POST['wpbs_nonce'], basename(__FILE__)) )
  422.         return $post_id;
  423.  
  424.     // check autosave
  425.     if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
  426.         return $post_id;
  427.  
  428.     // check permissions
  429.     if ( 'page' == $_POST['post_type'] ) {
  430.         if ( !current_user_can( 'edit_page', $post_id ) )
  431.             return $post_id;
  432.         } elseif ( !current_user_can( 'edit_post', $post_id ) ) {
  433.             return $post_id;
  434.     }
  435.  
  436.     // loop through fields and save the data
  437.     foreach ( $custom_meta_fields as $field ) {
  438.         $old = get_post_meta( $post_id, $field['id'], true );
  439.         $new = $_POST[$field['id']];
  440.  
  441.         if ($new && $new != $old) {
  442.             update_post_meta( $post_id, $field['id'], $new );
  443.         } elseif ( '' == $new && $old ) {
  444.             delete_post_meta( $post_id, $field['id'], $old );
  445.         }
  446.     } // end foreach
  447. }
  448. add_action( 'save_post', 'wp_bootstrap_save_homepage_meta' );
  449.  
  450. // Add thumbnail class to thumbnail links
  451. function wp_bootstrap_add_class_attachment_link( $html ) {
  452.     $postid = get_the_ID();
  453.     $html = str_replace( '<a','<a class="thumbnail"',$html );
  454.     return $html;
  455. }
  456. add_filter( 'wp_get_attachment_link', 'wp_bootstrap_add_class_attachment_link', 10, 1 );
  457.  
  458. // Add lead class to first paragraph
  459. function wp_bootstrap_first_paragraph( $content ){
  460.     global $post;
  461.  
  462.     // if we're on the homepage, don't add the lead class to the first paragraph of text
  463.     if( is_page_template( 'page-homepage.php' ) )
  464.         return $content;
  465.     else
  466.         return preg_replace('/<p([^>]+)?>/', '<p$1 class="lead">', $content, 1);
  467. }
  468. add_filter( 'the_content', 'wp_bootstrap_first_paragraph' );
  469.  
  470. // Menu output mods
  471. class Bootstrap_walker extends Walker_Nav_Menu{
  472.  
  473.   function start_el(&$output, $object, $depth = 0, $args = Array(), $current_object_id = 0){
  474.  
  475.      global $wp_query;
  476.      $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  477.  
  478.      $class_names = $value = '';
  479.  
  480.         // If the item has children, add the dropdown class for bootstrap
  481.         if ( $args->has_children ) {
  482.             $class_names = "dropdown ";
  483.         }
  484.  
  485.         $classes = empty( $object->classes ) ? array() : (array) $object->classes;
  486.  
  487.         $class_names .= join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $object ) );
  488.         $class_names = ' class="'. esc_attr( $class_names ) . '"';
  489.  
  490.     $output .= $indent . '<li id="menu-item-'. $object->ID . '"' . $value . $class_names .'>';
  491.  
  492.     $attributes  = ! empty( $object->attr_title ) ? ' title="'  . esc_attr( $object->attr_title ) .'"' : '';
  493.     $attributes .= ! empty( $object->target )     ? ' target="' . esc_attr( $object->target     ) .'"' : '';
  494.     $attributes .= ! empty( $object->xfn )        ? ' rel="'    . esc_attr( $object->xfn        ) .'"' : '';
  495.     $attributes .= ! empty( $object->url )        ? ' href="'   . esc_attr( $object->url        ) .'"' : '';
  496.  
  497.     // if the item has children add these two attributes to the anchor tag
  498.     if ( $args->has_children ) {
  499.           $attributes .= ' class="dropdown-toggle" data-toggle="dropdown"';
  500.     }
  501.  
  502.     $item_output = $args->before;
  503.     $item_output .= '<a'. $attributes .'>';
  504.     $item_output .= $args->link_before .apply_filters( 'the_title', $object->title, $object->ID );
  505.     $item_output .= $args->link_after;
  506.  
  507.     // if the item has children add the caret just before closing the anchor tag
  508.     if ( $args->has_children ) {
  509.         $item_output .= '<b class="caret"></b></a>';
  510.     }
  511.     else {
  512.         $item_output .= '</a>';
  513.     }
  514.  
  515.     $item_output .= $args->after;
  516.  
  517.     $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $object, $depth, $args );
  518.   } // end start_el function
  519.  
  520.   function start_lvl(&$output, $depth = 0, $args = Array()) {
  521.     $indent = str_repeat("\t", $depth);
  522.     $output .= "\n$indent<ul class=\"dropdown-menu\">\n";
  523.   }
  524.  
  525.     function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ){
  526.     $id_field = $this->db_fields['id'];
  527.     if ( is_object( $args[0] ) ) {
  528.         $args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
  529.     }
  530.     return parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
  531.   }
  532. }
  533.  
  534. add_editor_style('editor-style.css');
  535.  
  536. function wp_bootstrap_add_active_class($classes, $item) {
  537.     if( $item->menu_item_parent == 0 && in_array('current-menu-item', $classes) ) {
  538.     $classes[] = "active";
  539.     }
  540.  
  541.   return $classes;
  542. }
  543.  
  544. // Add Twitter Bootstrap's standard 'active' class name to the active nav link item
  545. add_filter('nav_menu_css_class', 'wp_bootstrap_add_active_class', 10, 2 );
  546.  
  547. // enqueue styles
  548. if( !function_exists("wp_bootstrap_theme_styles") ) {
  549.     function wp_bootstrap_theme_styles() {
  550.         // This is the compiled css file from LESS - this means you compile the LESS file locally and put it in the appropriate directory if you want to make any changes to the master bootstrap.css.
  551.         wp_register_style( 'wpbs', get_template_directory_uri() . '/library/css/styles.css', array(), '1.0', 'all' );
  552.         wp_enqueue_style( 'wpbs' );
  553.  
  554.         // For child themes
  555.         wp_register_style( 'wpbs-style', get_stylesheet_directory_uri() . '/style.css', array(), '1.0', 'all' );
  556.         wp_enqueue_style( 'wpbs-style' );
  557.     }
  558. }
  559. add_action( 'wp_enqueue_scripts', 'wp_bootstrap_theme_styles' );
  560.  
  561. // enqueue javascript
  562. if( !function_exists( "wp_bootstrap_theme_js" ) ) {
  563.   function wp_bootstrap_theme_js(){
  564.  
  565.     if ( !is_admin() ){
  566.       if ( is_singular() AND comments_open() AND ( get_option( 'thread_comments' ) == 1) )
  567.         wp_enqueue_script( 'comment-reply' );
  568.     }
  569.  
  570.     // This is the full Bootstrap js distribution file. If you only use a few components that require the js files consider loading them individually instead
  571.     wp_register_script( 'bootstrap',
  572.       get_template_directory_uri() . '/bower_components/bootstrap/dist/js/bootstrap.js',
  573.       array('jquery'),
  574.       '1.2' );
  575.  
  576.     wp_register_script( 'wpbs-js',
  577.       get_template_directory_uri() . '/library/dist/js/scripts.d1e3d952.min.js',
  578.       array('bootstrap'),
  579.       '1.2' );
  580.  
  581.     wp_register_script( 'modernizr',
  582.       get_template_directory_uri() . '/bower_components/modernizer/modernizr.js',
  583.       array('jquery'),
  584.       '1.2' );
  585.  
  586.     wp_enqueue_script( 'bootstrap' );
  587.     wp_enqueue_script( 'wpbs-js' );
  588.     wp_enqueue_script( 'modernizr' );
  589.  
  590.   }
  591. }
  592. add_action( 'wp_enqueue_scripts', 'wp_bootstrap_theme_js' );
  593.  
  594. // Get <head> <title> to behave like other themes
  595. function wp_bootstrap_wp_title( $title, $sep ) {
  596.   global $paged, $page;
  597.  
  598.   if ( is_feed() ) {
  599.     return $title;
  600.   }
  601.  
  602.   // Add the site name.
  603.   $title .= get_bloginfo( 'name' );
  604.  
  605.   // Add the site description for the home/front page.
  606.   $site_description = get_bloginfo( 'description', 'display' );
  607.   if ( $site_description && ( is_home() || is_front_page() ) ) {
  608.     $title = "$title $sep $site_description";
  609.   }
  610.  
  611.   // Add a page number if necessary.
  612.   if ( $paged >= 2 || $page >= 2 ) {
  613.     $title = "$title $sep " . sprintf( __( 'Page %s', 'wpbootstrap' ), max( $paged, $page ) );
  614.   }
  615.  
  616.   return $title;
  617. }
  618. add_filter( 'wp_title', 'wp_bootstrap_wp_title', 10, 2 );
  619.  
  620. // Related Posts Function (call using wp_bootstrap_related_posts(); )
  621. function wp_bootstrap_related_posts() {
  622.   echo '<ul id="bones-related-posts">';
  623.   global $post;
  624.   $tags = wp_get_post_tags($post->ID);
  625.   if($tags) {
  626.       $tag_arr = "";
  627.     foreach($tags as $tag) { $tag_arr .= $tag->slug . ','; }
  628.         $args = array(
  629.           'tag' => $tag_arr,
  630.           'numberposts' => 5, /* you can change this to show more */
  631.           'post__not_in' => array($post->ID)
  632.       );
  633.         $related_posts = get_posts($args);
  634.         if($related_posts) {
  635.           foreach ($related_posts as $post) : setup_postdata($post); ?>
  636.               <li class="related_post"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
  637.           <?php endforeach; }
  638.       else { ?>
  639.             <li class="no_related_post">No Related Posts Yet!</li>
  640.     <?php }
  641.   }
  642.   wp_reset_query();
  643.   echo '</ul>';
  644. }
  645.  
  646. // Numeric Page Navi (built into the theme by default)
  647. function wp_bootstrap_page_navi($before = '', $after = '') {
  648.   global $wpdb, $wp_query;
  649.   $request = $wp_query->request;
  650.   $posts_per_page = intval(get_query_var('posts_per_page'));
  651.   $paged = intval(get_query_var('paged'));
  652.   $numposts = $wp_query->found_posts;
  653.   $max_page = $wp_query->max_num_pages;
  654.   if ( $numposts <= $posts_per_page ) { return; }
  655.   if(empty($paged) || $paged == 0) {
  656.     $paged = 1;
  657.   }
  658.   $pages_to_show = 7;
  659.   $pages_to_show_minus_1 = $pages_to_show-1;
  660.   $half_page_start = floor($pages_to_show_minus_1/2);
  661.   $half_page_end = ceil($pages_to_show_minus_1/2);
  662.   $start_page = $paged - $half_page_start;
  663.   if($start_page <= 0) {
  664.     $start_page = 1;
  665.   }
  666.   $end_page = $paged + $half_page_end;
  667.   if(($end_page - $start_page) != $pages_to_show_minus_1) {
  668.     $end_page = $start_page + $pages_to_show_minus_1;
  669.   }
  670.   if($end_page > $max_page) {
  671.     $start_page = $max_page - $pages_to_show_minus_1;
  672.     $end_page = $max_page;
  673.   }
  674.   if($start_page <= 0) {
  675.     $start_page = 1;
  676.   }
  677.  
  678.   echo $before.'<ul class="pagination">'."";
  679.   if ($paged > 1) {
  680.     $first_page_text = "&laquo";
  681.     echo '<li class="prev"><a href="'.get_pagenum_link().'" title="' . __('First','wpbootstrap') . '">'.$first_page_text.'</a></li>';
  682.   }
  683.  
  684.   $prevposts = get_previous_posts_link( __('&larr; Previous','wpbootstrap') );
  685.   if($prevposts) { echo '<li>' . $prevposts  . '</li>'; }
  686.   else { echo '<li class="disabled"><a href="#">' . __('&larr; Previous','wpbootstrap') . '</a></li>'; }
  687.  
  688.   for($i = $start_page; $i  <= $end_page; $i++) {
  689.     if($i == $paged) {
  690.       echo '<li class="active"><a href="#">'.$i.'</a></li>';
  691.     } else {
  692.       echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
  693.     }
  694.   }
  695.   echo '<li class="">';
  696.   next_posts_link( __('Next &rarr;','wpbootstrap') );
  697.   echo '</li>';
  698.   if ($end_page < $max_page) {
  699.     $last_page_text = "&raquo;";
  700.     echo '<li class="next"><a href="'.get_pagenum_link($max_page).'" title="' . __('Last','wpbootstrap') . '">'.$last_page_text.'</a></li>';
  701.   }
  702.   echo '</ul>'.$after."";
  703. }
  704.  
  705. // Remove <p> tags from around images
  706. function wp_bootstrap_filter_ptags_on_images( $content ){
  707.   return preg_replace( '/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content );
  708. }
  709. add_filter( 'the_content', 'wp_bootstrap_filter_ptags_on_images' );
  710.  
  711. //Lab post type
  712. add_action( 'init', 'create_posttype' );
  713. function create_posttype() {
  714.   register_post_type( 'Lab',
  715.     array(
  716.       'labels' => array(
  717.         'name' => __( 'Lab pages' ),
  718.         'singular_name' => __( 'Lab page' )
  719.       ),
  720.       'public' => true,
  721.       'has_archive' => true,
  722.       'rewrite' => array('slug' => 'labs',
  723.       'with_front' => false
  724.     ),
  725.     )
  726.   );
  727. }
  728.  
  729. // //News post type
  730. // add_action( 'init', 'create_posttype_news' );
  731. // function create_posttype_news() {
  732. //   register_post_type( 'News',
  733. //     array(
  734. //       'labels' => array(
  735. //         'name' => __( 'News' ),
  736. //         'singular_name' => __( 'News' )
  737. //       ),
  738. //       'public' => true,
  739. //       'has_archive' => true,
  740. //       'rewrite' => array('slug' => 'news',
  741. //       'with_front' => false
  742. //     ),
  743. //
  744. //     )
  745. //   );
  746. // }
  747.  
  748. //events post type
  749. add_action( 'init', 'create_posttype_events' );
  750. function create_posttype_events() {
  751.   register_post_type( 'Events',
  752.     array(
  753.       'labels' => array(
  754.         'name' => __( 'Events' ),
  755.         'singular_name' => __( 'Event' )
  756.       ),
  757.       'public' => true,
  758.       'has_archive' => true,
  759.       'taxonomies'=> array( 'category' , 'trends' ),
  760.       'rewrite' => array('slug' => 'events',
  761.       'with_front' => false
  762.       ),
  763.       //'taxonomies' => array('trends'),
  764.     )
  765.   );
  766. }
  767.  
  768. // //partners post type
  769. // add_action( 'init', 'create_posttype_partners' );
  770. // function create_posttype_partners() {
  771. //   register_post_type( 'Partners',
  772. //     array(
  773. //       'labels' => array(
  774. //         'name' => __( 'Partners' ),
  775. //         'singular_name' => __( 'Partner' )
  776. //       ),
  777. //       'public' => true,
  778. //       'has_archive' => false,
  779. //       'rewrite' => array('slug' => 'partners',
  780. //       'with_front' => false
  781. //       ),
  782. //     )
  783. //   );
  784. // }
  785.  
  786. //stories post type
  787. add_action( 'init', 'create_posttype_stories' );
  788. function create_posttype_stories() {
  789.   register_post_type( 'Stories',
  790.     array(
  791.       'labels' => array(
  792.         'name' => __( 'Stories' ),
  793.         'singular_name' => __( 'Story' )
  794.       ),
  795.       'public' => true,
  796.       'has_archive' => true,
  797.       'rewrite' => array('slug' => 'stories',
  798.       'with_front' => false,
  799.       ),
  800.       'taxonomies' => array('trends')
  801.     )
  802.   );
  803. }
  804.  
  805. //stories post type
  806. add_action( 'init', 'create_posttype_other_posts' );
  807. function create_posttype_other_posts() {
  808.   register_post_type( 'Other Posts',
  809.     array(
  810.       'labels' => array(
  811.         'name' => __( 'Other Posts' ),
  812.         'singular_name' => __( 'Other Post' )
  813.       ),
  814.       'public' => true,
  815.       'has_archive' => false,
  816.       'rewrite' => array('slug' => 'other-posts',
  817.       'with_front' => false,
  818.       ),
  819.       //'taxonomies' => array('trends')
  820.     )
  821.   );
  822. }
  823.  
  824. // Microservices post type
  825. add_action( 'init', 'create_posttype_microservices' );
  826. function create_posttype_microservices() {
  827.   register_post_type( 'Microservices',
  828.     array(
  829.       'labels' => array(
  830.         'name' => __( 'Microservices' ),
  831.         'singular_name' => __( 'Microservice' )
  832.       ),
  833.       'public' => true,
  834.       'has_archive' => true,
  835.       'rewrite' => array('slug' => 'microservices',
  836.       'with_front' => false,
  837.       ),
  838.       'taxonomies' => array('trends')
  839.     )
  840.   );
  841. }
  842.  
  843. //custom taxonomy Trends
  844.  
  845. //hook into the init action and call create_book_taxonomies when it fires
  846. add_action( 'init', 'create_trends_hierarchical_taxonomy', 0 );
  847.  
  848. //create a custom taxonomy name it topics for your posts
  849.  
  850. function create_trends_hierarchical_taxonomy() {
  851.  
  852. // Add new taxonomy, make it hierarchical like categories
  853. //first do the translations part for GUI
  854.  
  855.   $labels = array(
  856.     'name' => _x( 'Trends', 'taxonomy general name' ),
  857.     'singular_name' => _x( 'Trend', 'taxonomy singular name' ),
  858.     'search_items' =>  __( 'Search Trends' ),
  859.     'all_items' => __( 'All Trends' ),
  860.     'parent_item' => __( 'Parent Trend' ),
  861.     'parent_item_colon' => __( 'Parent Trend:' ),
  862.     'edit_item' => __( 'Edit Trend' ),
  863.     'update_item' => __( 'Update Trend' ),
  864.     'add_new_item' => __( 'Add New Trend' ),
  865.     'new_item_name' => __( 'New Trend Name' ),
  866.     'menu_name' => __( 'Trends' ),
  867.   );
  868.  
  869. // Now register the taxonomy
  870.  
  871.   register_taxonomy('trends',array('post'), array(
  872.     'hierarchical' => true,
  873.     'labels' => $labels,
  874.     'show_ui' => true,
  875.     'show_admin_column' => true,
  876.     'query_var' => true,
  877.     'rewrite' => array( 'slug' => 'trend' ),
  878.   ));
  879.  
  880. }
  881.  
  882. //custom taxonomy Maturity
  883.  
  884. //hook into the init action and call create_book_taxonomies when it fires
  885. add_action( 'init', 'create_maturities_hierarchical_taxonomy', 0 );
  886.  
  887. //create a custom taxonomy name it topics for your posts
  888.  
  889. function create_maturities_hierarchical_taxonomy() {
  890.  
  891. // Add new taxonomy, make it hierarchical like categories
  892. //first do the translations part for GUI
  893.  
  894.   $labels = array(
  895.     'name' => _x( 'Maturities', 'taxonomy general name' ),
  896.     'singular_name' => _x( 'Maturity', 'taxonomy singular name' ),
  897.     'search_items' =>  __( 'Search Maturities' ),
  898.     'all_items' => __( 'All Maturities' ),
  899.     'parent_item' => __( 'Parent Maturity' ),
  900.     'parent_item_colon' => __( 'Parent Maturity:' ),
  901.     'edit_item' => __( 'Edit Maturity' ),
  902.     'update_item' => __( 'Update Maturity' ),
  903.     'add_new_item' => __( 'Add New Maturity' ),
  904.     'new_item_name' => __( 'New Maturity Name' ),
  905.     'menu_name' => __( 'Maturities' ),
  906.   );
  907.  
  908. // Now register the taxonomy
  909.   register_taxonomy('maturity',array('post'), array(
  910.     'hierarchical' => true,
  911.     'labels' => $labels,
  912.     'show_ui' => true,
  913.     'show_admin_column' => true,
  914.     'query_var' => true,
  915.     'rewrite' => array( 'slug' => 'maturity' ),
  916.   ));
  917.  
  918. }
  919.  
  920. // filtering stories, projects, events
  921. function misha_filter_function() {
  922.     $filter_args = array(
  923.     'posts_per_page' => 9,
  924.     'paged'                  => $_POST['paged'],
  925.     'post_type'          => array('stories', 'post', 'events'),
  926.     'post_status'    => 'publish',
  927.     'orderby'            => 'date',
  928.     'order'                  => 'DESC',
  929.     'tax_query'      => array()
  930.     );
  931.   if (isset($_POST['trend-filter'])) {
  932.     $selected_trend = $_POST['trend-filter'];
  933.   }
  934.   else {
  935.     if (!empty($_GET['trend-filter'])) {
  936.       $selected_trend = $_GET['trend-filter'];
  937.     }
  938.   }
  939.     if (!empty($selected_trend)) {
  940.     $filter_args['tax_query']['queries'][] = array(
  941.                 'taxonomy' => 'trends',
  942.                 'field' => 'slug',
  943.                 'terms' => $selected_trend
  944.     );
  945.     $current_url_trend = 'trend-filter=' . $selected_trend . '&';
  946.     }
  947.   if (isset($_POST['maturity-filter'])) {
  948.     $selected_maturity = $_POST['maturity-filter'];
  949.   }
  950.   else {
  951.     if (!empty($_GET['maturity-filter'])) {
  952.       $selected_maturity = $_GET['maturity-filter'];
  953.     }
  954.   }
  955.     if (!empty($selected_maturity)) {
  956.     $filter_args['tax_query']['queries'][] = array(
  957.                 'taxonomy' => 'maturity',
  958.                 'field' => 'slug',
  959.                 'terms' => $selected_maturity
  960.         );
  961.     $current_url_maturity = 'maturity-filter=' . $selected_maturity . '&';
  962.     }
  963.   $current_url = get_permalink(2308) . '?' . $current_url_trend . $current_url_maturity;
  964.     $filter_query = new WP_Query( $filter_args );
  965.     if($filter_query->have_posts()) {
  966.         while($filter_query->have_posts()) : $filter_query->the_post();
  967.       $post_type = get_post_type_object(get_post_type());
  968.       if ($post_type) {
  969.           $post_type_singular = esc_html($post_type->labels->singular_name);
  970.       }
  971. ?>
  972.       <div class="col-md-4 col-sm-6 featured post-container animate-reveal post-type-<?php echo get_post_type(); ?>">
  973.         <a href="<?php the_permalink(); ?>">
  974.           <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>
  975.             <div class="featured-heading-container">
  976.               <span class="featured-heading"><?php the_title(); ?></span>
  977.             </div>
  978.             <div class="featured-post-image">
  979.               <span class="post-type-tag"><?php echo $post_type_singular; ?></span>
  980.               <?php
  981.                 $image_id = get_field('post_header_image');
  982.                 $image_size = 'project-thumb';
  983.                 $image_array = wp_get_attachment_image_src($image_id, $image_size);
  984.                 $image_url = $image_array[0];
  985.               ?>
  986.               <img src="<?php echo $image_url; ?>" alt="">
  987.               <?php
  988.                 if ( get_field( 'header_video' ) ):
  989.                   echo '<img class="yt-icon" src="<?php echo get_template_directory_uri(); ?>/library/img/yt.svg">';
  990.                 else: // field_name returned false
  991.                 endif; // end of if field_name logic
  992.               ?>
  993.             </div>
  994.             <div class="featured-description-container">
  995.               <span class="featured-description"><?php // echo get_excerpt(); ?><?php the_field('post_excerpt'); ?></span>
  996.               <div class="trends-container">
  997.                   <?php
  998.                     if((get_post_type() == 'events') && (get_field('event_date_and_place'))) {
  999.                       echo '<span class="date-container trends">';
  1000.                       the_field('event_date_and_place');
  1001.                       echo '</span>';
  1002.                     }
  1003.                   ?>
  1004.                 <?php
  1005.                   $trends = wp_get_post_terms( get_the_ID(), 'trends', array( 'fields' => 'names' ));
  1006.                   if ($trends){
  1007.                     foreach ($trends as $trend) {
  1008.                       echo '<span class="trends">' . $trend . '</span>';
  1009.                     }
  1010.                   }
  1011.                 ?>
  1012.               </div>
  1013.  
  1014.               </div>
  1015.               <span class="after-desc">›</span>
  1016.             </div>
  1017.           </article>
  1018.         </a>
  1019.       </div>
  1020.   <?
  1021.         endwhile;
  1022.     if(($_POST['paged'] == 0) && ($filter_query->max_num_pages > 1)) {
  1023.       echo '<div class="malinky-load-more custom-load-more-wrapper"><a href="#" onclick="showMoreFilteredPosts(' . $filter_query->max_num_pages . ');return false;" id="malinky-ajax-pagination-button" class="custom-load-more malinky-load-more__button btn-4a icon-arrow-load-more btn btn-4-bg-none">Load more</a></div>';
  1024.     }
  1025.         wp_reset_postdata();
  1026.   }
  1027.   else {
  1028.     // no posts found
  1029.   }
  1030.   wp_die();
  1031. }
  1032. add_action('wp_ajax_myfilter', 'misha_filter_function');
  1033. add_action('wp_ajax_nopriv_myfilter', 'misha_filter_function');
  1034.  
  1035.  
  1036. //next post link class
  1037. add_filter('next_posts_link_attributes', 'posts_link_attributes');
  1038. function posts_link_attributes() {
  1039.     return 'class="next-posts"';
  1040. }
  1041.  
  1042. function wt_get_category_count($input = '') {
  1043.     global $wpdb;
  1044.     if($input == '')
  1045.     {
  1046.         $category = get_the_category();
  1047.         return $category[0]->category_count;
  1048.     }
  1049.     elseif(is_numeric($input))
  1050.     {
  1051.         $SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.term_id=$input";
  1052.         return $wpdb->get_var($SQL);
  1053.     }
  1054.     else
  1055.     {
  1056.         $SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->terms.slug='$input'";
  1057.         return $wpdb->get_var($SQL);
  1058.     }
  1059. }
  1060.  
  1061. function get_excerpt(){
  1062. $excerpt = get_the_content();
  1063. $excerpt = preg_replace(" ([.*?])",'',$excerpt);
  1064. $excerpt = strip_shortcodes($excerpt);
  1065. $excerpt = strip_tags($excerpt);
  1066. $excerpt = substr($excerpt, 0, 230);
  1067. $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
  1068. $excerpt = trim(preg_replace( '/s+/', ' ', $excerpt));
  1069. $excerpt = $excerpt.'<span class="after-desc">›</span>';
  1070. return $excerpt;
  1071. }
  1072.  
  1073. function load_custom_wp_admin_style() {
  1074.         wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/library/css/admin-style.css', false, '1.0.0' );
  1075.         wp_enqueue_style( 'custom_wp_admin_css' );
  1076. }
  1077. add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
  1078.  
  1079. function load_custom_wp_admin_script() {
  1080.         wp_register_script( 'custom_wp_admin_script', get_template_directory_uri() . '/library/js/admin-script.js', false, '1.0.0' );
  1081.         wp_enqueue_script( 'custom_wp_admin_script' );
  1082. }
  1083. add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_script' );
  1084.  
  1085. add_filter( 'jpeg_quality', create_function( '', 'return 80;' ) );
  1086.  
  1087. //buttons post box
  1088. /* Fire our meta box setup function on the post editor screen. */
  1089. add_action( 'load-post.php', 'smashing_post_meta_boxes_setup' );
  1090. add_action( 'load-post-new.php', 'smashing_post_meta_boxes_setup' );
  1091.  
  1092. /* Meta box setup function. */
  1093. function smashing_post_meta_boxes_setup() {
  1094.  
  1095.   /* Add meta boxes on the 'add_meta_boxes' hook. */
  1096.   add_action( 'add_meta_boxes', 'smashing_add_post_meta_boxes' );
  1097. }
  1098.  
  1099. /* Create one or more meta boxes to be displayed on the post editor screen. */
  1100. function smashing_add_post_meta_boxes() {
  1101.  
  1102.   $post_types = array ( 'post', 'Partners', 'News' , 'Events' , 'Lab' );
  1103.  
  1104.   add_meta_box(
  1105.     'smashing-post-class',      // Unique ID
  1106.     esc_html__( 'Post Class', 'example' ),    // Title
  1107.     'smashing_post_class_meta_box',   // Callback function
  1108.     $post_types,         // Admin page (or post type)
  1109.     'side',         // Context
  1110.     'default'         // Priority
  1111.   );
  1112. }
  1113.  
  1114. /* Display the post meta box. */
  1115. function smashing_post_class_meta_box( $object, $box ) {
  1116.     ?>
  1117.  
  1118.   <?php wp_nonce_field( basename( __FILE__ ), 'smashing_post_class_nonce' ); ?>
  1119.  
  1120.   <p>
  1121.     <a class="post-btn-blue">Button</a>
  1122.     <br />
  1123.     <span class="short-blue">[buttonblue]Link Text[/buttonblue]</span>
  1124.     <br />
  1125.   </p>
  1126. <?php
  1127. }
  1128.  
  1129. function buttonviolet_function( $atts, $content = null ) {
  1130.  return '<button class="post-btn-violet post-btn" type="button">'.do_shortcode($content).'</button>';
  1131. }
  1132. add_shortcode('buttonviolet', 'buttonviolet_function');
  1133.  
  1134. function buttonblue_function( $atts, $content = null ) {
  1135.  return '<button class="post-btn-blue post-btn" type="button">'.do_shortcode($content).'</button>';
  1136. }
  1137. add_shortcode('buttonblue', 'buttonblue_function');
  1138.  
  1139. //media frame scripts
  1140. /*function media_script_enqueue() {
  1141.    wp_enqueue_script( 'media-script', get_template_directory_uri() . '/library/js/media-script.js', array( 'jquery', 'media-editor' ), '', true );
  1142. }
  1143.  
  1144. add_action( 'admin_enqueue_scripts', 'media_script_enqueue' ); // Back-end*/
  1145.  
  1146. add_image_size( 'project-thumb', 360, 240, true );
  1147. add_image_size( 'project-header', 800, 534, true );
  1148. add_image_size( 'portrait', 263, 263, true );
  1149. add_image_size( 'featured-story', 679, 457, true );
  1150.  
  1151. //Posts register_nav_menus
  1152.  
  1153. function revcon_change_post_label() {
  1154.     global $menu;
  1155.     global $submenu;
  1156.     $menu[5][0] = 'Projects';
  1157.     $submenu['edit.php'][5][0] = 'Projects';
  1158.     $submenu['edit.php'][10][0] = 'Add Project';
  1159.     $submenu['edit.php'][16][0] = 'Project Tags';
  1160. }
  1161. function revcon_change_post_object() {
  1162.     global $wp_post_types;
  1163.     $labels = &$wp_post_types['post']->labels;
  1164.     $labels->name = 'Projects';
  1165.     $labels->singular_name = 'Project';
  1166.     $labels->add_new = 'Add Projects';
  1167.     $labels->add_new_item = 'Add Projects';
  1168.     $labels->edit_item = 'Edit Projects';
  1169.     $labels->new_item = 'Projects';
  1170.     $labels->view_item = 'View Projects';
  1171.     $labels->search_items = 'Search Projects';
  1172.     $labels->not_found = 'No Projects found';
  1173.     $labels->not_found_in_trash = 'No Projects found in Trash';
  1174.     $labels->all_items = 'All Projects';
  1175.     $labels->menu_name = 'Projects';
  1176.     $labels->name_admin_bar = 'Projects';
  1177. }
  1178.  
  1179. add_action( 'admin_menu', 'revcon_change_post_label' );
  1180. add_action( 'init', 'revcon_change_post_object' );
  1181.  
  1182.  
  1183. $role_object = get_role( 'editor' );
  1184. $role_object->add_cap( 'manage_options' );
  1185.  
  1186. /*
  1187.  * Let Editors manage users, and run this only once.
  1188.  */
  1189. function isa_editor_manage_users() {
  1190.  
  1191.     if ( get_option( 'isa_add_cap_editor_once' ) != 'done' ) {
  1192.  
  1193.         // let editor manage users
  1194.  
  1195.         $edit_editor = get_role('editor'); // Get the user role
  1196.         $edit_editor->add_cap('edit_users');
  1197.         $edit_editor->add_cap('list_users');
  1198.         $edit_editor->add_cap('promote_users');
  1199.         $edit_editor->add_cap('create_users');
  1200.         $edit_editor->add_cap('add_users');
  1201.         $edit_editor->add_cap('delete_users');
  1202.  
  1203.         update_option( 'isa_add_cap_editor_once', 'done' );
  1204.     }
  1205.  
  1206. }
  1207. add_action( 'init', 'isa_editor_manage_users' );
  1208.  
  1209. //prevent editor from deleting, editing, or creating an administrator
  1210. // only needed if the editor was given right to edit users
  1211.  
  1212. class ISA_User_Caps {
  1213.  
  1214.   // Add our filters
  1215.   function ISA_User_Caps(){
  1216.     add_filter( 'editable_roles', array(&$this, 'editable_roles'));
  1217.     add_filter( 'map_meta_cap', array(&$this, 'map_meta_cap'),10,4);
  1218.   }
  1219.   // Remove 'Administrator' from the list of roles if the current user is not an admin
  1220.   function editable_roles( $roles ){
  1221.     if( isset( $roles['administrator'] ) && !current_user_can('administrator') ){
  1222.       unset( $roles['administrator']);
  1223.     }
  1224.     return $roles;
  1225.   }
  1226.   // If someone is trying to edit or delete an
  1227.   // admin and that user isn't an admin, don't allow it
  1228.   function map_meta_cap( $caps, $cap, $user_id, $args ){
  1229.     switch( $cap ){
  1230.         case 'edit_user':
  1231.         case 'remove_user':
  1232.         case 'promote_user':
  1233.             if( isset($args[0]) && $args[0] == $user_id )
  1234.                 break;
  1235.             elseif( !isset($args[0]) )
  1236.                 $caps[] = 'do_not_allow';
  1237.             $other = new WP_User( absint($args[0]) );
  1238.             if( $other->has_cap( 'administrator' ) ){
  1239.                 if(!current_user_can('administrator')){
  1240.                     $caps[] = 'do_not_allow';
  1241.                 }
  1242.             }
  1243.             break;
  1244.         case 'delete_user':
  1245.         case 'delete_users':
  1246.             if( !isset($args[0]) )
  1247.                 break;
  1248.             $other = new WP_User( absint($args[0]) );
  1249.             if( $other->has_cap( 'administrator' ) ){
  1250.                 if(!current_user_can('administrator')){
  1251.                     $caps[] = 'do_not_allow';
  1252.                 }
  1253.             }
  1254.             break;
  1255.         default:
  1256.             break;
  1257.     }
  1258.     return $caps;
  1259.   }
  1260.  
  1261. }
  1262.  
  1263. $isa_user_caps = new ISA_User_Caps();
  1264.  
  1265. add_action('pre_user_query','isa_pre_user_query');
  1266. function isa_pre_user_query($user_search) {
  1267.   $user = wp_get_current_user();
  1268.   if ($user->ID!=1) { // Is not administrator, remove administrator
  1269.     global $wpdb;
  1270.     $user_search->query_where = str_replace('WHERE 1=1',
  1271.       "WHERE 1=1 AND {$wpdb->users}.ID<>1",$user_search->query_where);
  1272.   }
  1273. }
  1274.  
  1275.  
  1276. function dcg_password_form_fix() {
  1277.     global $post;
  1278.     $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
  1279.     $o = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
  1280.    ' . __( "To view the contents of this page, enter the password below:" ) . '
  1281.    <label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
  1282.    </form>
  1283.    ';
  1284.     return $o;
  1285. }
  1286. add_filter( 'the_password_form', 'dcg_password_form_fix' );
  1287.  
  1288. function my_default_image_size () {
  1289.     return 'full size';
  1290. }
  1291.  
  1292. add_filter( 'pre_option_image_default_size', 'my_default_image_size' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement