PATH:
home
/
centosnipponia
/
public_html
/
lifannl
/
wp-content
/
themes
/
sydney-pro-ii
/
inc
/
modules
/
page-headers
<?php /** * Adds an image picker on the category edit page * * @package Sydney */ if ( !is_admin() ) { return; } class Sydney_Archive_Form_Fields { public function __construct() { } /* * Initialize the class and start calling our hooks and filters */ public function init() { add_action( 'admin_enqueue_scripts', array( $this, 'load_media' ) ); add_action( 'admin_footer', array ( $this, 'add_script' ) ); //Get all taxonomies $args = array( 'public' => true, ); $output = 'names'; $operator = 'and'; $taxonomies = get_taxonomies( $args, $output, $operator ); foreach ( $taxonomies as $taxonomy ) { add_action( $taxonomy . '_add_form_fields', array( $this, 'add_category_image' ), 10, 2 ); add_action( $taxonomy . '_edit_form_fields', array( $this, 'update_category_image' ), 10, 2 ); add_action( 'created_' . $taxonomy, array ( $this, 'save_category_image' ), 10, 2 ); add_action( 'edited_' . $taxonomy, array ( $this, 'updated_category_image' ), 10, 2 ); } } public function load_media() { wp_enqueue_media(); } /* * Add a form field in the new category page */ public function add_category_image ( $taxonomy ) { ?> <div class="form-field term-group"> <label for="sydney-cat-img-id"><?php _e('Cover Image', 'sydney'); ?></label> <input type="hidden" id="sydney-cat-img-id" name="sydney-cat-img-id" class="custom_media_url" value=""> <div id="category-image-wrapper"></div> <p> <input type="button" class="button button-secondary ct_tax_media_button" id="ct_tax_media_button" name="ct_tax_media_button" value="<?php _e( 'Add Image', 'sydney' ); ?>" /> <input type="button" class="button button-secondary ct_tax_media_remove" id="ct_tax_media_remove" name="ct_tax_media_remove" value="<?php _e( 'Remove Image', 'sydney' ); ?>" /> </p> </div> <?php } /* * Save the form field */ public function save_category_image ( $term_id, $tt_id ) { if( isset( $_POST['sydney-cat-img-id'] ) && '' !== $_POST['sydney-cat-img-id'] ){ $image = $_POST['sydney-cat-img-id']; add_term_meta( $term_id, 'sydney-cat-img-id', $image, true ); } } /* * Edit the form field */ public function update_category_image ( $term, $taxonomy ) { ?> <tr class="form-field term-group-wrap"> <th scope="row"> <label for="sydney-cat-img-id"><?php _e( 'Cover Image', 'sydney' ); ?></label> </th> <td> <?php $image_id = get_term_meta ( $term -> term_id, 'sydney-cat-img-id', true ); ?> <input type="hidden" id="sydney-cat-img-id" name="sydney-cat-img-id" value="<?php echo $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 ct_tax_media_button" id="ct_tax_media_button" name="ct_tax_media_button" value="<?php _e( 'Add Image', 'sydney' ); ?>" /> <input type="button" class="button button-secondary ct_tax_media_remove" id="ct_tax_media_remove" name="ct_tax_media_remove" value="<?php _e( 'Remove Image', 'sydney' ); ?>" /> </p> </td> </tr> <?php } /* * Update the form field value * @since 1.0.0 */ public function updated_category_image ( $term_id, $tt_id ) { if( isset( $_POST['sydney-cat-img-id'] ) && '' !== $_POST['sydney-cat-img-id'] ){ $image = absint( $_POST['sydney-cat-img-id'] ); update_term_meta ( $term_id, 'sydney-cat-img-id', $image ); } else { update_term_meta ( $term_id, 'sydney-cat-img-id', '' ); } } /* * Add script * @since 1.0.0 */ public function add_script() { ?> <script> jQuery(document).ready( function($) { function ct_media_upload(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 = wp.media.editor.send.attachment; var button = $(button_id); _custom_media = true; wp.media.editor.send.attachment = function(props, attachment){ if ( _custom_media ) { $('#sydney-cat-img-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; }); } ct_media_upload('.ct_tax_media_button.button'); $('body').on('click','.ct_tax_media_remove',function(){ $('#sydney-cat-img-id').val(''); $('#category-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />'); }); // Thanks: http://stackoverflow.com/questions/15281995/wordpress-create-category-ajax-response $(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!=""){ // Clear the thumb image $('#category-image-wrapper').html(''); } } }); }); </script> <?php } } function sydney_init_taxonomy_form_fields() { $Sydney_Archive_Form_Fields = new Sydney_Archive_Form_Fields(); $Sydney_Archive_Form_Fields -> init(); } add_action( 'init', 'sydney_init_taxonomy_form_fields', 11 );
[+]
..
[+]
settings
[-] class_sydney_archive_form_fields.php
[edit]
[-] page-headers.php
[edit]
[-] .htaccess.disabled
[edit]