Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('CALCIO_NAME', wp_get_theme()->get( 'Name' ));
- define('CALCIO_CSS', get_template_directory_uri().'/css/');
- define('CALCIO_JS', get_template_directory_uri().'/js/');
- # TGM Plugin
- require_once( get_template_directory() . '/lib/class-tgm-plugin-activation.php');
- /*-------------------------------------------*
- * Register Navigation
- *------------------------------------------*/
- register_nav_menus( array(
- 'mainmenu' => esc_html__( 'Main Menu', 'calcio' ),
- 'secondary_menu' => esc_html__( 'Secondary Menu', 'calcio' ),
- ) );
- /*-------------------------------------------*
- * navwalker
- *------------------------------------------*/
- //Main Navigation
- require_once( get_template_directory() . '/lib/menu/admin-megamenu-walker.php');
- require_once( get_template_directory() . '/lib/menu/meagmenu-walker.php');
- require_once( get_template_directory() . '/lib/menu/mobile-navwalker.php');
- //Admin mega menu
- add_filter( 'wp_edit_nav_menu_walker', function( $class, $menu_id ){
- return 'Calcio_Themeum_Megamenu_Walker';
- }, 10, 2 );
- /*-------------------------------------------*
- * Startup Register
- *------------------------------------------*/
- require_once( get_template_directory() . '/lib/main-function/themeum-register.php');
- /*-------------------------------------------------------
- * Themeum Core
- *-------------------------------------------------------*/
- require_once( get_template_directory() . '/lib/main-function/themeum-core.php');
- /*-----------------------------------------------------
- * Custom Excerpt Length
- *----------------------------------------------------*/
- if(!function_exists('calcio_excerpt_max_charlength')):
- function calcio_excerpt_max_charlength($charlength) {
- $excerpt = get_the_excerpt();
- $charlength++;
- if ( mb_strlen( $excerpt ) > $charlength ) {
- $subex = mb_substr( $excerpt, 0, $charlength - 5 );
- $exwords = explode( ' ', $subex );
- $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
- if ( $excut < 0 ) {
- return mb_substr( $subex, 0, $excut );
- } else {
- return $subex;
- }
- } else {
- return $excerpt;
- }
- }
- endif;
- /*-----------------------------------------------------
- * Custom Title Length
- *----------------------------------------------------*/
- if(!function_exists('calcio_max_charlength')):
- function calcio_max_charlength($charlen, $char) {
- $exrcp= $char;
- $charlen++;
- if ( mb_strlen( $exrcp ) > $charlen ) {
- $subex = mb_substr( $exrcp, 0, $charlen - 5 );
- $exwords = explode( ' ', $subex );
- $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
- if ( $excut < 0 ) {
- return mb_substr( $subex, 0, $excut );
- } else {
- return $subex;
- }
- } else {
- return $exrcp;
- }
- }
- endif;
- /*-------------------------------------------*
- * woocommerce support
- *------------------------------------------*/
- add_action( 'after_setup_theme', 'calcio_woocommerce_support' );
- function calcio_woocommerce_support() {
- add_theme_support( 'woocommerce' );
- }
- /*-----------------------------------------------------
- * Custom body class
- *----------------------------------------------------*/
- add_filter( 'body_class', 'calcio_body_class' );
- function calcio_body_class( $classes ) {
- $layout = get_theme_mod( 'boxfull_en', 'fullwidth' );
- $classes[] = esc_attr($layout).'-bg';
- $sub_header_cls = '';
- if (!get_theme_mod( 'enable_sub_header' )) {
- $sub_header_cls = 'thm-sub-header-disabled';
- }
- if (is_page() && !is_front_page()) {
- $sub_header_cls = '';
- }
- $classes[] = esc_attr($sub_header_cls);
- return $classes;
- }
- function calcio_customize_control_js() {
- 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 );
- }
- add_action( 'customize_controls_enqueue_scripts', 'calcio_customize_control_js' );
- /* BG Image */
- if( ! class_exists( 'Tournament_Taxonomy_Images' ) ) {
- class Tournament_Taxonomy_Images {
- public function __construct() {
- //
- }
- /**
- * Initialize the class and start calling our hooks and filters
- */
- public function init() {
- # Image actions
- add_action( 'tournament_add_form_fields', array( $this, 'add_category_image' ), 10, 2 );
- add_action( 'created_tournament', array( $this, 'save_category_image' ), 10, 2 );
- add_action( 'tournament_edit_form_fields', array( $this, 'update_category_image' ), 10, 2 );
- add_action( 'edited_tournament', array( $this, 'updated_category_image' ), 10, 2 );
- add_action( 'admin_enqueue_scripts', array( $this, 'load_media' ) );
- add_action( 'admin_footer', array( $this, 'add_script' ) );
- }
- # Load Media
- public function load_media() {
- if( ! isset( $_GET['taxonomy'] ) || $_GET['taxonomy'] != 'tournament' ) {
- return;
- }
- wp_enqueue_media();
- }
- /**
- * Add a form field in the new category page
- * @since 1.0.0
- */
- public function add_category_image( $taxonomy ) { ?>
- <!-- <div class="form-field term-group">
- <label for="tour_check"><?php// _e( 'Tournament Checkbox:' ); ?></label>
- <input type="checkbox" value="" name="tour_check" />
- </div>
- -->
- <!-- Using selected() instead -->
- <select name="options_tour">
- <option value="1" <?php selected( $options_tour, 1 ); ?>>Popular Tournament</option>
- <option value="2" <?php selected( $options_tour, 2 ); ?>>More Tournament</option>
- </select>
- <div class="form-field term-group">
- <label for="tournament_year"><?php _e('Year','themeum-core');?></label>
- <input name="tournament_year" id="tournament_year" type="text" value="" size="40" aria-required="true" />
- </div>
- <!-- Logo Image -->
- <div class="form-field term-group">
- <label for="taxonomy-logo-image-id"><?php _e( 'Add Logo Image', 'calcio' ); ?></label>
- <input type="hidden" id="taxonomy-logo-image-id" name="taxonomy-logo-image-id" class="custom_media_url" value="">
- <div id="category-image-wrapper"></div>
- <p>
- <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' ); ?>" />
- <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' ); ?>" />
- </p>
- </div>
- <!-- Background Image -->
- <div class="form-field term-group">
- <label for="taxonomy-bg-image-id"><?php _e( 'Add Logo Image', 'calcio' ); ?></label>
- <input type="hidden" id="taxonomy-bg-image-id" name="taxonomy-bg-image-id" class="custom_media_url" value="">
- <div id="category-bg-image-wrapper"></div>
- <p>
- <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' ); ?>" />
- <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' ); ?>" />
- </p>
- </div>
- <?php }
- /**
- * Save the form field.
- */
- public function save_category_image( $term_id, $tt_id ) {
- // if( isset( $_POST['tour_check'] ) ){
- // $my_data = isset($_POST['tour_check']) ? 1 : 0;
- // add_term_meta( $term_id, 'tour_check', $my_data, true );
- // }
- # Save Tournament Year
- if( isset( $_POST['options_tour'] ) && '' !== $_POST['options_tour'] ){
- add_term_meta( $term_id, 'options_tour', absint( $_POST['options_tour'] ), true );
- }
- # Save Tournament Year
- if( isset( $_POST['tournament_year'] ) && '' !== $_POST['tournament_year'] ){
- add_term_meta( $term_id, 'tournament_year', absint( $_POST['tournament_year'] ), true );
- }
- # Save Logo
- if( isset( $_POST['taxonomy-logo-image-id'] ) && '' !== $_POST['taxonomy-logo-image-id'] ){
- add_term_meta( $term_id, 'taxonomy-logo-image-id', absint( $_POST['taxonomy-logo-image-id'] ), true );
- }
- # Save Background Image
- if( isset( $_POST['taxonomy-bg-image-id'] ) && '' !== $_POST['taxonomy-bg-image-id'] ){
- add_term_meta( $term_id, 'taxonomy-bg-image-id', absint( $_POST['taxonomy-bg-image-id'] ), true );
- }
- }
- # Save category image.
- /**
- * Edit the form field
- */
- public function update_category_image( $term, $taxonomy ) {
- $tour_year = get_term_meta( $term->term_id, 'tournament_year', true );
- $options_tour = get_term_meta( $term->term_id, 'options_tour', true ); ?>
- <!-- Using selected() instead -->
- <tr class="form-field">
- <th scope="row" valign="top">
- <label for="tournament_year"><?php _e('Tournament Options','themeum-core');?></label>
- </th>
- <td>
- <select name="options_tour">
- <option value="1" <?php selected( $options_tour, 1 ); ?>>Popular Tournament</option>
- <option value="2" <?php selected( $options_tour, 2 ); ?>>More Tournament</option>
- </select>
- </td>
- </tr>
- <tr class="form-field">
- <th scope="row" valign="top">
- <label for="tournament_year"><?php _e('Tournament Year','themeum-core');?></label>
- </th>
- <td>
- <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" />
- </td>
- </tr>
- <!-- Logo Update -->
- <tr class="form-field term-group-wrap">
- <th scope="row">
- <label for="taxonomy-logo-image-id"><?php _e( 'Logo Image', 'calcio' ); ?></label>
- </th>
- <td>
- <?php $image_id = get_term_meta( $term->term_id, 'taxonomy-logo-image-id', true ); ?>
- <input type="hidden" id="taxonomy-logo-image-id" name="taxonomy-logo-image-id" value="<?php echo esc_attr( $image_id ); ?>">
- <div id="category-image-wrapper">
- <?php if( $image_id ) { ?>
- <?php echo wp_get_attachment_image( $image_id, 'thumbnail' ); ?>
- <?php } ?>
- </div>
- <p>
- <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' ); ?>" />
- <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' ); ?>" />
- </p>
- </td>
- </tr>
- <!-- Background Image Update -->
- <tr class="form-field term-group-wrap">
- <th scope="row">
- <label for="taxonomy-bg-image-id"><?php _e( 'Background Image', 'calcio' ); ?></label>
- </th>
- <td>
- <?php $image_id = get_term_meta( $term->term_id, 'taxonomy-bg-image-id', true ); ?>
- <input type="hidden" id="taxonomy-bg-image-id" name="taxonomy-bg-image-id" value="<?php echo esc_attr( $image_id ); ?>">
- <div id="category-bg-image-wrapper">
- <?php if( $image_id ) { ?>
- <?php echo wp_get_attachment_image( $image_id, 'thumbnail' ); ?>
- <?php } ?>
- </div>
- <p>
- <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' ); ?>" />
- <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' ); ?>" />
- </p>
- </td>
- </tr>
- <?php }
- # Update Function End
- /**
- * Update the form field value
- * @since 1.0.0
- */
- public function updated_category_image( $term_id, $tt_id ) {
- // if( isset( $_POST['tour_check'] ) ){
- // $data = $_POST['tour_check'] ? 'true' : 'false';
- // update_term_meta( $term_id, 'tour_check', $_POST['tour_check'] );
- // }
- if( isset( $_POST['options_tour'] ) ){
- update_term_meta( $term_id, 'options_tour', absint( $_POST['options_tour'] ) );
- }
- if( isset( $_POST['tournament_year'] ) && '' !== $_POST['tournament_year'] ){
- update_term_meta( $term_id, 'tournament_year', absint( $_POST['tournament_year'] ) );
- }
- # Logo Image Update
- if( isset( $_POST['taxonomy-logo-image-id'] ) && '' !== $_POST['taxonomy-logo-image-id'] ){
- update_term_meta( $term_id, 'taxonomy-logo-image-id', absint( $_POST['taxonomy-logo-image-id'] ) );
- } else {
- update_term_meta( $term_id, 'taxonomy-logo-image-id', '' );
- }
- # Backround Image update
- if( isset( $_POST['taxonomy-bg-image-id'] ) && '' !== $_POST['taxonomy-bg-image-id'] ){
- update_term_meta( $term_id, 'taxonomy-bg-image-id', absint( $_POST['taxonomy-bg-image-id'] ) );
- } else {
- update_term_meta( $term_id, 'taxonomy-bg-image-id', '' );
- }
- }
- /**
- * Enqueue styles and scripts
- * @since 1.0.0
- */
- public function add_script() {
- if( ! isset( $_GET['taxonomy'] ) || $_GET['taxonomy'] != 'tournament' ) {
- return;
- } ?>
- <script>
- jQuery(document).ready( function($) {
- _wpMediaViewsL10n.insertIntoPost = '<?php _e( "Insert", "calcio" ); ?>';
- /* ==========================
- * Logo Image
- =============================*/
- function tournament_logo_media_uploader(button_class) {
- var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment;
- $('body').on('click', button_class, function(e) {
- var button_id = '#'+$(this).attr('id');
- var send_attachment_bkp_bg = wp.media.editor.send.attachment;
- var button = $(button_id);
- _custom_media = true;
- wp.media.editor.send.attachment = function(props, attachment){
- if( _custom_media ) {
- $('#taxonomy-logo-image-id').val(attachment.id);
- $('#category-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
- $( '#category-image-wrapper .custom_media_image' ).attr( 'src',attachment.url ).css( 'display','block' );
- } else {
- return _orig_send_attachment.apply( button_id, [props, attachment] );
- }
- }
- wp.media.editor.open(button); return false;
- });
- }
- /* End Logo Image Script */
- /* ==========================
- * Background Image
- =============================*/
- function tournament_bg_image_media_uploader(button_class) {
- var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment;
- $('body').on('click', button_class, function(e) {
- var bg_button_id = '#'+$(this).attr('id');
- var send_attachment_bkp_bg = wp.media.editor.send.attachment;
- var bg_button = $(bg_button_id);
- _custom_media = true;
- wp.media.editor.send.attachment = function(props, attachment){
- if( _custom_media ) {
- $('#taxonomy-bg-image-id').val(attachment.id);
- $('#category-bg-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
- $( '#category-bg-image-wrapper .custom_media_image' ).attr( 'src',attachment.url ).css( 'display','block' );
- } else {
- return _orig_send_attachment.apply( bg_button_id, [props, attachment] );
- }
- }
- wp.media.editor.open(bg_button); return false;
- });
- }
- /* End Background Image Script */
- /* Call Back function - logo */
- tournament_logo_media_uploader('.logo_tax_media_button.button');
- $('body').on('click','.logo_tax_media_remove',function(){
- $('#taxonomy-logo-image-id').val('');
- $('#category-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
- });
- /* Call Back function - BG Image */
- tournament_bg_image_media_uploader('.bg_img_tax_media_button.button');
- $('body').on('click','.bg_img_tax_media_remove',function(){
- $('#taxonomy-bg-image-id').val('');
- $('#category-bg-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
- });
- /* Clear The Thumb Tmage */
- $(document).ajaxComplete(function(event, xhr, settings) {
- var queryStringArr = settings.data.split('&');
- if( $.inArray('action=add-tag', queryStringArr) !== -1 ){
- var xml = xhr.responseXML;
- $response = $(xml).find('term_id').text();
- if($response!=""){
- /* Logo Image */
- $('#category-image-wrapper').html('');
- /* Bg image */
- $('#category-bg-image-wrapper').html('');
- }
- }
- });
- /* End Process */
- });
- </script>
- <?php }
- }
- $Tournament_Taxonomy_Images = new Tournament_Taxonomy_Images();
- $Tournament_Taxonomy_Images->init(); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement