Advertisement
rejuancse

functions

Jan 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.47 KB | None | 0 0
  1. <?php
  2.  
  3. define('CALCIO_NAME', wp_get_theme()->get( 'Name' ));
  4. define('CALCIO_CSS', get_template_directory_uri().'/css/');
  5. define('CALCIO_JS', get_template_directory_uri().'/js/');
  6.  
  7.  
  8. # TGM Plugin
  9. require_once( get_template_directory()  . '/lib/class-tgm-plugin-activation.php');
  10.  
  11.  
  12. /*-------------------------------------------*
  13.  *              Register Navigation
  14.  *------------------------------------------*/
  15. register_nav_menus( array(
  16.     'mainmenu' => esc_html__( 'Main Menu', 'calcio' ),
  17.     'secondary_menu' => esc_html__( 'Secondary Menu', 'calcio' ),
  18. ) );
  19.  
  20.  
  21. /*-------------------------------------------*
  22.  *              navwalker
  23.  *------------------------------------------*/
  24. //Main Navigation
  25. require_once( get_template_directory()  . '/lib/menu/admin-megamenu-walker.php');
  26. require_once( get_template_directory()  . '/lib/menu/meagmenu-walker.php');
  27. require_once( get_template_directory()  . '/lib/menu/mobile-navwalker.php');
  28. //Admin mega menu
  29. add_filter( 'wp_edit_nav_menu_walker', function( $class, $menu_id ){
  30.     return 'Calcio_Themeum_Megamenu_Walker';
  31. }, 10, 2 );
  32.  
  33.  
  34. /*-------------------------------------------*
  35.  *              Startup Register
  36.  *------------------------------------------*/
  37. require_once( get_template_directory()  . '/lib/main-function/themeum-register.php');
  38.  
  39.  
  40.  
  41. /*-------------------------------------------------------
  42.  *          Themeum Core
  43.  *-------------------------------------------------------*/
  44. require_once( get_template_directory()  . '/lib/main-function/themeum-core.php');
  45.  
  46.  
  47.  
  48. /*-----------------------------------------------------
  49. *               Custom Excerpt Length
  50. *----------------------------------------------------*/
  51.  
  52. if(!function_exists('calcio_excerpt_max_charlength')):
  53.     function calcio_excerpt_max_charlength($charlength) {
  54.         $excerpt = get_the_excerpt();
  55.         $charlength++;
  56.  
  57.         if ( mb_strlen( $excerpt ) > $charlength ) {
  58.             $subex = mb_substr( $excerpt, 0, $charlength - 5 );
  59.             $exwords = explode( ' ', $subex );
  60.             $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
  61.             if ( $excut < 0 ) {
  62.                 return mb_substr( $subex, 0, $excut );
  63.             } else {
  64.                 return $subex;
  65.             }
  66.  
  67.         } else {
  68.             return $excerpt;
  69.         }
  70.     }
  71. endif;
  72.  
  73.  
  74. /*-----------------------------------------------------
  75. *               Custom Title Length
  76. *----------------------------------------------------*/
  77.  
  78. if(!function_exists('calcio_max_charlength')):
  79.     function calcio_max_charlength($charlen, $char) {
  80.         $exrcp= $char;
  81.         $charlen++;
  82.  
  83.         if ( mb_strlen( $exrcp ) > $charlen ) {
  84.             $subex = mb_substr( $exrcp, 0, $charlen - 5 );
  85.             $exwords = explode( ' ', $subex );
  86.             $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
  87.             if ( $excut < 0 ) {
  88.                 return mb_substr( $subex, 0, $excut );
  89.             } else {
  90.                 return $subex;
  91.             }
  92.  
  93.         } else {
  94.             return $exrcp;
  95.         }
  96.     }
  97. endif;
  98.  
  99.  
  100.  
  101. /*-------------------------------------------*
  102.  *              woocommerce support
  103.  *------------------------------------------*/
  104.  
  105. add_action( 'after_setup_theme', 'calcio_woocommerce_support' );
  106. function calcio_woocommerce_support() {
  107.     add_theme_support( 'woocommerce' );
  108. }
  109.  
  110. /*-----------------------------------------------------
  111.  *              Custom body class
  112.  *----------------------------------------------------*/
  113. add_filter( 'body_class', 'calcio_body_class' );
  114. function calcio_body_class( $classes ) {
  115.     $layout = get_theme_mod( 'boxfull_en', 'fullwidth' );
  116.     $classes[] = esc_attr($layout).'-bg';
  117.  
  118.     $sub_header_cls = '';
  119.  
  120.     if (!get_theme_mod( 'enable_sub_header' )) {
  121.         $sub_header_cls = 'thm-sub-header-disabled';
  122.     }
  123.  
  124.     if (is_page() && !is_front_page()) {
  125.         $sub_header_cls = '';
  126.     }
  127.  
  128.     $classes[] = esc_attr($sub_header_cls);
  129.  
  130.     return $classes;
  131. }
  132.  
  133.  
  134. function calcio_customize_control_js() {
  135.     wp_enqueue_script( 'calcio-color-preset-control', get_template_directory_uri() . '/js/color-scheme-control.js', array( 'customize-controls', 'iris', 'underscore', 'wp-util' ), '20141216', true );
  136. }
  137. add_action( 'customize_controls_enqueue_scripts', 'calcio_customize_control_js' );
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147. /* BG Image */
  148.  
  149. if( ! class_exists( 'Tournament_Taxonomy_Images' ) ) {
  150. class Tournament_Taxonomy_Images {
  151.    
  152.     public function __construct() {
  153.      //
  154.     }
  155.  
  156.     /**
  157.     * Initialize the class and start calling our hooks and filters
  158.     */
  159.     public function init() {
  160.         # Image actions
  161.         add_action( 'tournament_add_form_fields', array( $this, 'add_category_image' ), 10, 2 );
  162.         add_action( 'created_tournament', array( $this, 'save_category_image' ), 10, 2 );
  163.         add_action( 'tournament_edit_form_fields', array( $this, 'update_category_image' ), 10, 2 );
  164.         add_action( 'edited_tournament', array( $this, 'updated_category_image' ), 10, 2 );
  165.         add_action( 'admin_enqueue_scripts', array( $this, 'load_media' ) );
  166.  
  167.  
  168.         add_action( 'admin_footer', array( $this, 'add_script' ) );
  169.     }
  170.  
  171.     # Load Media
  172.     public function load_media() {
  173.         if( ! isset( $_GET['taxonomy'] ) || $_GET['taxonomy'] != 'tournament' ) {
  174.            return;
  175.         }
  176.         wp_enqueue_media();
  177.     }
  178.  
  179.     /**
  180.     * Add a form field in the new category page
  181.     * @since 1.0.0
  182.     */
  183.     public function add_category_image( $taxonomy ) { ?>
  184.  
  185.  
  186.        
  187.  
  188.         <!-- <div class="form-field term-group">
  189.             <label for="tour_check"><?php// _e( 'Tournament Checkbox:' ); ?></label>
  190.             <input type="checkbox" value="" name="tour_check" />
  191.         </div>
  192.         -->
  193.  
  194.         <!-- Using selected() instead -->
  195.         <select name="options_tour">
  196.             <option value="1" <?php selected( $options_tour, 1 ); ?>>Popular Tournament</option>
  197.             <option value="2" <?php selected( $options_tour, 2 ); ?>>More Tournament</option>
  198.         </select>
  199.  
  200.         <div class="form-field term-group">
  201.             <label for="tournament_year"><?php _e('Year','themeum-core');?></label>
  202.             <input name="tournament_year" id="tournament_year" type="text" value="" size="40" aria-required="true" />
  203.         </div>
  204.        
  205.         <!-- Logo Image -->
  206.         <div class="form-field term-group">
  207.             <label for="taxonomy-logo-image-id"><?php _e( 'Add Logo Image', 'calcio' ); ?></label>
  208.             <input type="hidden" id="taxonomy-logo-image-id" name="taxonomy-logo-image-id" class="custom_media_url" value="">
  209.             <div id="category-image-wrapper"></div>
  210.             <p>
  211.                 <input type="button" class="button button-secondary logo_tax_media_button" id="logo_tax_media_button" name="logo_tax_media_button" value="<?php _e( 'Add Image', 'calcio' ); ?>" />
  212.                 <input type="button" class="button button-secondary logo_tax_media_remove" id="logo_tax_media_remove" name="logo_tax_media_remove" value="<?php _e( 'Remove Image', 'calcio' ); ?>" />
  213.             </p>
  214.         </div>
  215.  
  216.         <!-- Background Image -->
  217.         <div class="form-field term-group">
  218.             <label for="taxonomy-bg-image-id"><?php _e( 'Add Logo Image', 'calcio' ); ?></label>
  219.             <input type="hidden" id="taxonomy-bg-image-id" name="taxonomy-bg-image-id" class="custom_media_url" value="">
  220.             <div id="category-bg-image-wrapper"></div>
  221.             <p>
  222.                 <input type="button" class="button button-secondary bg_img_tax_media_button" id="bg_img_tax_media_button" name="bg_img_tax_media_button" value="<?php _e( 'Add Image', 'calcio' ); ?>" />
  223.                 <input type="button" class="button button-secondary bg_img_tax_media_remove" id="bg_img_tax_media_remove" name="bg_img_tax_media_remove" value="<?php _e( 'Remove Image', 'calcio' ); ?>" />
  224.             </p>
  225.         </div>
  226.     <?php }
  227.  
  228.     /**
  229.     * Save the form field.
  230.     */
  231.     public function save_category_image( $term_id, $tt_id ) {
  232.  
  233.         // if( isset( $_POST['tour_check'] ) ){
  234.         //  $my_data = isset($_POST['tour_check']) ? 1 : 0;
  235.      //        add_term_meta( $term_id, 'tour_check', $my_data, true );
  236.      //    }
  237.  
  238.         # Save Tournament Year
  239.         if( isset( $_POST['options_tour'] ) && '' !== $_POST['options_tour'] ){
  240.             add_term_meta( $term_id, 'options_tour', absint( $_POST['options_tour'] ), true );
  241.         }
  242.  
  243.  
  244.  
  245.         # Save Tournament Year
  246.         if( isset( $_POST['tournament_year'] ) && '' !== $_POST['tournament_year'] ){
  247.             add_term_meta( $term_id, 'tournament_year', absint( $_POST['tournament_year'] ), true );
  248.         }
  249.  
  250.         # Save Logo
  251.         if( isset( $_POST['taxonomy-logo-image-id'] ) && '' !== $_POST['taxonomy-logo-image-id'] ){
  252.             add_term_meta( $term_id, 'taxonomy-logo-image-id', absint( $_POST['taxonomy-logo-image-id'] ), true );
  253.         }
  254.  
  255.         # Save Background Image
  256.         if( isset( $_POST['taxonomy-bg-image-id'] ) && '' !== $_POST['taxonomy-bg-image-id'] ){
  257.             add_term_meta( $term_id, 'taxonomy-bg-image-id', absint( $_POST['taxonomy-bg-image-id'] ), true );
  258.         }
  259.     }
  260.     # Save category image.
  261.  
  262.     /**
  263.     * Edit the form field
  264.     */
  265.     public function update_category_image( $term, $taxonomy ) {
  266.  
  267.         $tour_year = get_term_meta( $term->term_id, 'tournament_year', true );
  268.         $options_tour = get_term_meta( $term->term_id, 'options_tour', true );  ?>
  269.  
  270.         <!-- Using selected() instead -->
  271.         <tr class="form-field">
  272.             <th scope="row" valign="top">
  273.                 <label for="tournament_year"><?php _e('Tournament Options','themeum-core');?></label>
  274.             </th>
  275.             <td>
  276.                 <select name="options_tour">
  277.                     <option value="1" <?php selected( $options_tour, 1 ); ?>>Popular Tournament</option>
  278.                     <option value="2" <?php selected( $options_tour, 2 ); ?>>More Tournament</option>
  279.                 </select>
  280.             </td>
  281.         </tr>
  282.  
  283.         <tr class="form-field">
  284.             <th scope="row" valign="top">
  285.                 <label for="tournament_year"><?php _e('Tournament Year','themeum-core');?></label>
  286.             </th>
  287.             <td>
  288.                 <input type="text" name="tournament_year" id="tournament_year" value="<?php echo esc_attr( $tour_year ) ? esc_attr( $tour_year ) : ''; ?>" size="40" aria-required="true" />
  289.             </td>
  290.         </tr>
  291.  
  292.         <!-- Logo Update -->
  293.         <tr class="form-field term-group-wrap">
  294.             <th scope="row">
  295.               <label for="taxonomy-logo-image-id"><?php _e( 'Logo Image', 'calcio' ); ?></label>
  296.             </th>
  297.             <td>
  298.                 <?php $image_id = get_term_meta( $term->term_id, 'taxonomy-logo-image-id', true ); ?>
  299.                 <input type="hidden" id="taxonomy-logo-image-id" name="taxonomy-logo-image-id" value="<?php echo esc_attr( $image_id ); ?>">
  300.                 <div id="category-image-wrapper">
  301.                     <?php if( $image_id ) { ?>
  302.                       <?php echo wp_get_attachment_image( $image_id, 'thumbnail' ); ?>
  303.                     <?php } ?>
  304.                 </div>
  305.                 <p>
  306.                     <input type="button" class="button button-secondary logo_tax_media_button" id="logo_tax_media_button" name="logo_tax_media_button" value="<?php _e( 'Add Image', 'calcio' ); ?>" />
  307.                     <input type="button" class="button button-secondary logo_tax_media_remove" id="logo_tax_media_remove" name="logo_tax_media_remove" value="<?php _e( 'Remove Image', 'calcio' ); ?>" />
  308.                 </p>
  309.             </td>
  310.         </tr>
  311.  
  312.         <!-- Background Image Update -->
  313.         <tr class="form-field term-group-wrap">
  314.             <th scope="row">
  315.               <label for="taxonomy-bg-image-id"><?php _e( 'Background Image', 'calcio' ); ?></label>
  316.             </th>
  317.             <td>
  318.                 <?php $image_id = get_term_meta( $term->term_id, 'taxonomy-bg-image-id', true ); ?>
  319.                 <input type="hidden" id="taxonomy-bg-image-id" name="taxonomy-bg-image-id" value="<?php echo esc_attr( $image_id ); ?>">
  320.                 <div id="category-bg-image-wrapper">
  321.                     <?php if( $image_id ) { ?>
  322.                       <?php echo wp_get_attachment_image( $image_id, 'thumbnail' ); ?>
  323.                     <?php } ?>
  324.                 </div>
  325.                 <p>
  326.                     <input type="button" class="button button-secondary bg_img_tax_media_button" id="bg_img_tax_media_button" name="bg_img_tax_media_button" value="<?php _e( 'Add Image', 'calcio' ); ?>" />
  327.                     <input type="button" class="button button-secondary bg_img_tax_media_remove" id="bg_img_tax_media_remove" name="bg_img_tax_media_remove" value="<?php _e( 'Remove Image', 'calcio' ); ?>" />
  328.                 </p>
  329.             </td>
  330.         </tr>
  331.     <?php }
  332.     # Update Function End
  333.  
  334.     /**
  335.     * Update the form field value
  336.     * @since 1.0.0
  337.     */
  338.     public function updated_category_image( $term_id, $tt_id ) {
  339.  
  340.      //    if( isset( $_POST['tour_check'] ) ){
  341.      //         $data = $_POST['tour_check'] ? 'true' : 'false';
  342.         //  update_term_meta( $term_id, 'tour_check', $_POST['tour_check'] );
  343.         // }
  344.  
  345.         if( isset( $_POST['options_tour'] ) ){
  346.             update_term_meta( $term_id, 'options_tour', absint( $_POST['options_tour'] ) );
  347.         }
  348.  
  349.  
  350.  
  351.  
  352.  
  353.         if( isset( $_POST['tournament_year'] ) && '' !== $_POST['tournament_year'] ){
  354.             update_term_meta( $term_id, 'tournament_year', absint( $_POST['tournament_year'] ) );
  355.         }
  356.         # Logo Image Update
  357.         if( isset( $_POST['taxonomy-logo-image-id'] ) && '' !== $_POST['taxonomy-logo-image-id'] ){
  358.             update_term_meta( $term_id, 'taxonomy-logo-image-id', absint( $_POST['taxonomy-logo-image-id'] ) );
  359.         } else {
  360.             update_term_meta( $term_id, 'taxonomy-logo-image-id', '' );
  361.         }
  362.         # Backround Image update
  363.         if( isset( $_POST['taxonomy-bg-image-id'] ) && '' !== $_POST['taxonomy-bg-image-id'] ){
  364.             update_term_meta( $term_id, 'taxonomy-bg-image-id', absint( $_POST['taxonomy-bg-image-id'] ) );
  365.         } else {
  366.             update_term_meta( $term_id, 'taxonomy-bg-image-id', '' );
  367.         }
  368.     }
  369.  
  370.     /**
  371.     * Enqueue styles and scripts
  372.     * @since 1.0.0
  373.     */
  374.     public function add_script() {
  375.         if( ! isset( $_GET['taxonomy'] ) || $_GET['taxonomy'] != 'tournament' ) {
  376.             return;
  377.         } ?>
  378.  
  379.         <script>
  380.         jQuery(document).ready( function($) {
  381.            _wpMediaViewsL10n.insertIntoPost = '<?php _e( "Insert", "calcio" ); ?>';
  382.  
  383.            /* ==========================
  384.             *    Logo Image
  385.             =============================*/
  386.             function tournament_logo_media_uploader(button_class) {
  387.                 var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment;
  388.                 $('body').on('click', button_class, function(e) {
  389.                     var button_id = '#'+$(this).attr('id');
  390.                     var send_attachment_bkp_bg = wp.media.editor.send.attachment;
  391.                     var button = $(button_id);
  392.                     _custom_media = true;
  393.                     wp.media.editor.send.attachment = function(props, attachment){
  394.                         if( _custom_media ) {
  395.                            $('#taxonomy-logo-image-id').val(attachment.id);
  396.                            $('#category-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
  397.                            $( '#category-image-wrapper .custom_media_image' ).attr( 'src',attachment.url ).css( 'display','block' );
  398.                         } else {
  399.                            return _orig_send_attachment.apply( button_id, [props, attachment] );
  400.                         }
  401.                     }
  402.                    wp.media.editor.open(button); return false;
  403.                 });
  404.             }
  405.             /* End Logo Image Script */
  406.  
  407.             /* ==========================
  408.             *    Background Image
  409.             =============================*/
  410.             function tournament_bg_image_media_uploader(button_class) {
  411.                 var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment;
  412.                 $('body').on('click', button_class, function(e) {
  413.                     var bg_button_id = '#'+$(this).attr('id');
  414.                     var send_attachment_bkp_bg = wp.media.editor.send.attachment;
  415.                     var bg_button = $(bg_button_id);
  416.                     _custom_media = true;
  417.                     wp.media.editor.send.attachment = function(props, attachment){
  418.                         if( _custom_media ) {
  419.                            $('#taxonomy-bg-image-id').val(attachment.id);
  420.                            $('#category-bg-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
  421.                            $( '#category-bg-image-wrapper .custom_media_image' ).attr( 'src',attachment.url ).css( 'display','block' );
  422.                         } else {
  423.                            return _orig_send_attachment.apply( bg_button_id, [props, attachment] );
  424.                         }
  425.                     }
  426.                     wp.media.editor.open(bg_button); return false;
  427.                 });
  428.             }
  429.             /* End Background Image Script */
  430.  
  431.  
  432.             /* Call Back function - logo */
  433.             tournament_logo_media_uploader('.logo_tax_media_button.button');
  434.             $('body').on('click','.logo_tax_media_remove',function(){
  435.                 $('#taxonomy-logo-image-id').val('');
  436.                 $('#category-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');    
  437.             });
  438.  
  439.             /* Call Back function - BG Image */
  440.             tournament_bg_image_media_uploader('.bg_img_tax_media_button.button');
  441.             $('body').on('click','.bg_img_tax_media_remove',function(){
  442.                 $('#taxonomy-bg-image-id').val('');
  443.                 $('#category-bg-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
  444.             });
  445.            
  446.             /* Clear The Thumb Tmage */
  447.             $(document).ajaxComplete(function(event, xhr, settings) {
  448.                 var queryStringArr = settings.data.split('&');
  449.                 if( $.inArray('action=add-tag', queryStringArr) !== -1 ){
  450.                 var xml = xhr.responseXML;
  451.                 $response = $(xml).find('term_id').text();
  452.                     if($response!=""){
  453.                         /* Logo Image */
  454.                         $('#category-image-wrapper').html('');
  455.                         /* Bg image */
  456.                         $('#category-bg-image-wrapper').html('');
  457.                     }
  458.                 }
  459.             });
  460.             /* End Process */
  461.         });
  462.         </script>
  463.    <?php }
  464. }
  465.  
  466. $Tournament_Taxonomy_Images = new Tournament_Taxonomy_Images();
  467. $Tournament_Taxonomy_Images->init(); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement