Advertisement
rejuancse

checkbox

Jan 22nd, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.80 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.         <div class="form-field term-group">
  195.             <label for="tournament_year"><?php _e('Year','themeum-core');?></label>
  196.             <input name="tournament_year" id="tournament_year" type="text" value="" size="40" aria-required="true" />
  197.         </div>
  198.        
  199.         <!-- Logo Image -->
  200.         <div class="form-field term-group">
  201.             <label for="taxonomy-logo-image-id"><?php _e( 'Add Logo Image', 'calcio' ); ?></label>
  202.             <input type="hidden" id="taxonomy-logo-image-id" name="taxonomy-logo-image-id" class="custom_media_url" value="">
  203.             <div id="category-image-wrapper"></div>
  204.             <p>
  205.                 <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' ); ?>" />
  206.                 <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' ); ?>" />
  207.             </p>
  208.         </div>
  209.  
  210.         <!-- Background Image -->
  211.         <div class="form-field term-group">
  212.             <label for="taxonomy-bg-image-id"><?php _e( 'Add Logo Image', 'calcio' ); ?></label>
  213.             <input type="hidden" id="taxonomy-bg-image-id" name="taxonomy-bg-image-id" class="custom_media_url" value="">
  214.             <div id="category-bg-image-wrapper"></div>
  215.             <p>
  216.                 <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' ); ?>" />
  217.                 <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' ); ?>" />
  218.             </p>
  219.         </div>
  220.     <?php }
  221.  
  222.     /**
  223.     * Save the form field.
  224.     */
  225.     public function save_category_image( $term_id, $tt_id ) {
  226.  
  227.         if( isset( $_POST['tour_check'] ) ){
  228.             $my_data = isset($_POST['tour_check']) ? 1 : 0;
  229.             add_term_meta( $term_id, 'tour_check', $my_data, true );
  230.         }
  231.  
  232.         # Save Tournament Year
  233.         if( isset( $_POST['tournament_year'] ) && '' !== $_POST['tournament_year'] ){
  234.             add_term_meta( $term_id, 'tournament_year', absint( $_POST['tournament_year'] ), true );
  235.         }
  236.  
  237.         # Save Logo
  238.         if( isset( $_POST['taxonomy-logo-image-id'] ) && '' !== $_POST['taxonomy-logo-image-id'] ){
  239.             add_term_meta( $term_id, 'taxonomy-logo-image-id', absint( $_POST['taxonomy-logo-image-id'] ), true );
  240.         }
  241.  
  242.         # Save Background Image
  243.         if( isset( $_POST['taxonomy-bg-image-id'] ) && '' !== $_POST['taxonomy-bg-image-id'] ){
  244.             add_term_meta( $term_id, 'taxonomy-bg-image-id', absint( $_POST['taxonomy-bg-image-id'] ), true );
  245.         }
  246.     }
  247.     # Save category image.
  248.  
  249.     /**
  250.     * Edit the form field
  251.     */
  252.     public function update_category_image( $term, $taxonomy ) {
  253.  
  254.         $tour_year = get_term_meta( $term->term_id, 'tournament_year', true );
  255.         $tour_check = get_term_meta( $term->term_id, 'tour_check', true );
  256.         print_r($tour_check);
  257.  
  258.         // echo $tour_check;
  259.         // $tour_region = get_term_meta( $term->term_id, 'tournament_region', true ); ?>
  260.  
  261.         <tr class="form-field">
  262.             <th scope="row" valign="top"><label for="tour_check"><?php _e( 'Tournament Check:' ); ?></label></th>
  263.             <td>
  264.                 <input type="checkbox" <?php checked( $tour_check, 'on' ); ?> value="" name="tour_check" />
  265.             </td>
  266.         </tr>
  267.  
  268.  
  269.  
  270.  
  271.         <tr class="form-field">
  272.             <th scope="row" valign="top">
  273.                 <label for="tournament_year"><?php _e('Tournament Year','themeum-core');?></label>
  274.             </th>
  275.             <td>
  276.                 <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" />
  277.             </td>
  278.         </tr>
  279.  
  280.         <!-- Logo Update -->
  281.         <tr class="form-field term-group-wrap">
  282.             <th scope="row">
  283.               <label for="taxonomy-logo-image-id"><?php _e( 'Logo Image', 'calcio' ); ?></label>
  284.             </th>
  285.             <td>
  286.                 <?php $image_id = get_term_meta( $term->term_id, 'taxonomy-logo-image-id', true ); ?>
  287.                 <input type="hidden" id="taxonomy-logo-image-id" name="taxonomy-logo-image-id" value="<?php echo esc_attr( $image_id ); ?>">
  288.                 <div id="category-image-wrapper">
  289.                     <?php if( $image_id ) { ?>
  290.                       <?php echo wp_get_attachment_image( $image_id, 'thumbnail' ); ?>
  291.                     <?php } ?>
  292.                 </div>
  293.                 <p>
  294.                     <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' ); ?>" />
  295.                     <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' ); ?>" />
  296.                 </p>
  297.             </td>
  298.         </tr>
  299.  
  300.         <!-- Background Image Update -->
  301.         <tr class="form-field term-group-wrap">
  302.             <th scope="row">
  303.               <label for="taxonomy-bg-image-id"><?php _e( 'Background Image', 'calcio' ); ?></label>
  304.             </th>
  305.             <td>
  306.                 <?php $image_id = get_term_meta( $term->term_id, 'taxonomy-bg-image-id', true ); ?>
  307.                 <input type="hidden" id="taxonomy-bg-image-id" name="taxonomy-bg-image-id" value="<?php echo esc_attr( $image_id ); ?>">
  308.                 <div id="category-bg-image-wrapper">
  309.                     <?php if( $image_id ) { ?>
  310.                       <?php echo wp_get_attachment_image( $image_id, 'thumbnail' ); ?>
  311.                     <?php } ?>
  312.                 </div>
  313.                 <p>
  314.                     <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' ); ?>" />
  315.                     <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' ); ?>" />
  316.                 </p>
  317.             </td>
  318.         </tr>
  319.     <?php }
  320.     # Update Function End
  321.  
  322.     /**
  323.     * Update the form field value
  324.     * @since 1.0.0
  325.     */
  326.     public function updated_category_image( $term_id, $tt_id ) {
  327.  
  328.         if( isset( $_POST['tour_check'] ) ){
  329.             $data = $_POST['tour_check'] ? 'true' : 'false';
  330.             update_term_meta( $term_id, 'tour_check', $_POST['tour_check'] );
  331.         }
  332.  
  333.         if( isset( $_POST['tournament_year'] ) && '' !== $_POST['tournament_year'] ){
  334.             update_term_meta( $term_id, 'tournament_year', absint( $_POST['tournament_year'] ) );
  335.         }
  336.         # Logo Image Update
  337.         if( isset( $_POST['taxonomy-logo-image-id'] ) && '' !== $_POST['taxonomy-logo-image-id'] ){
  338.             update_term_meta( $term_id, 'taxonomy-logo-image-id', absint( $_POST['taxonomy-logo-image-id'] ) );
  339.         } else {
  340.             update_term_meta( $term_id, 'taxonomy-logo-image-id', '' );
  341.         }
  342.         # Backround Image update
  343.         if( isset( $_POST['taxonomy-bg-image-id'] ) && '' !== $_POST['taxonomy-bg-image-id'] ){
  344.             update_term_meta( $term_id, 'taxonomy-bg-image-id', absint( $_POST['taxonomy-bg-image-id'] ) );
  345.         } else {
  346.             update_term_meta( $term_id, 'taxonomy-bg-image-id', '' );
  347.         }
  348.     }
  349.  
  350.     /**
  351.     * Enqueue styles and scripts
  352.     * @since 1.0.0
  353.     */
  354.     public function add_script() {
  355.         if( ! isset( $_GET['taxonomy'] ) || $_GET['taxonomy'] != 'tournament' ) {
  356.             return;
  357.         } ?>
  358.  
  359.         <script>
  360.         jQuery(document).ready( function($) {
  361.            _wpMediaViewsL10n.insertIntoPost = '<?php _e( "Insert", "calcio" ); ?>';
  362.  
  363.            /* ==========================
  364.             *    Logo Image
  365.             =============================*/
  366.             function tournament_logo_media_uploader(button_class) {
  367.                 var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment;
  368.                 $('body').on('click', button_class, function(e) {
  369.                     var button_id = '#'+$(this).attr('id');
  370.                     var send_attachment_bkp_bg = wp.media.editor.send.attachment;
  371.                     var button = $(button_id);
  372.                     _custom_media = true;
  373.                     wp.media.editor.send.attachment = function(props, attachment){
  374.                         if( _custom_media ) {
  375.                            $('#taxonomy-logo-image-id').val(attachment.id);
  376.                            $('#category-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
  377.                            $( '#category-image-wrapper .custom_media_image' ).attr( 'src',attachment.url ).css( 'display','block' );
  378.                         } else {
  379.                            return _orig_send_attachment.apply( button_id, [props, attachment] );
  380.                         }
  381.                     }
  382.                    wp.media.editor.open(button); return false;
  383.                 });
  384.             }
  385.             /* End Logo Image Script */
  386.  
  387.             /* ==========================
  388.             *    Background Image
  389.             =============================*/
  390.             function tournament_bg_image_media_uploader(button_class) {
  391.                 var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment;
  392.                 $('body').on('click', button_class, function(e) {
  393.                     var bg_button_id = '#'+$(this).attr('id');
  394.                     var send_attachment_bkp_bg = wp.media.editor.send.attachment;
  395.                     var bg_button = $(bg_button_id);
  396.                     _custom_media = true;
  397.                     wp.media.editor.send.attachment = function(props, attachment){
  398.                         if( _custom_media ) {
  399.                            $('#taxonomy-bg-image-id').val(attachment.id);
  400.                            $('#category-bg-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
  401.                            $( '#category-bg-image-wrapper .custom_media_image' ).attr( 'src',attachment.url ).css( 'display','block' );
  402.                         } else {
  403.                            return _orig_send_attachment.apply( bg_button_id, [props, attachment] );
  404.                         }
  405.                     }
  406.                     wp.media.editor.open(bg_button); return false;
  407.                 });
  408.             }
  409.             /* End Background Image Script */
  410.  
  411.  
  412.             /* Call Back function - logo */
  413.             tournament_logo_media_uploader('.logo_tax_media_button.button');
  414.             $('body').on('click','.logo_tax_media_remove',function(){
  415.                 $('#taxonomy-logo-image-id').val('');
  416.                 $('#category-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');    
  417.             });
  418.  
  419.             /* Call Back function - BG Image */
  420.             tournament_bg_image_media_uploader('.bg_img_tax_media_button.button');
  421.             $('body').on('click','.bg_img_tax_media_remove',function(){
  422.                 $('#taxonomy-bg-image-id').val('');
  423.                 $('#category-bg-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
  424.             });
  425.            
  426.             /* Clear The Thumb Tmage */
  427.             $(document).ajaxComplete(function(event, xhr, settings) {
  428.                 var queryStringArr = settings.data.split('&');
  429.                 if( $.inArray('action=add-tag', queryStringArr) !== -1 ){
  430.                 var xml = xhr.responseXML;
  431.                 $response = $(xml).find('term_id').text();
  432.                     if($response!=""){
  433.                         /* Logo Image */
  434.                         $('#category-image-wrapper').html('');
  435.                         /* Bg image */
  436.                         $('#category-bg-image-wrapper').html('');
  437.                     }
  438.                 }
  439.             });
  440.             /* End Process */
  441.         });
  442.         </script>
  443.    <?php }
  444. }
  445.  
  446. $Tournament_Taxonomy_Images = new Tournament_Taxonomy_Images();
  447. $Tournament_Taxonomy_Images->init(); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement