-
-
Save eduardozulian/4739075 to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* Customize Image Reloaded Class | |
* | |
* Extend WP_Customize_Image_Control allowing access to uploads made within | |
* the same context | |
*/ | |
class My_Customize_Image_Reloaded_Control extends WP_Customize_Image_Control { | |
/** | |
* Constructor. | |
* | |
* @since 3.4.0 | |
* @uses WP_Customize_Image_Control::__construct() | |
* | |
* @param WP_Customize_Manager $manager | |
*/ | |
public function __construct( $manager, $id, $args = array() ) { | |
parent::__construct( $manager, $id, $args ); | |
} | |
/** | |
* Search for images within the defined context | |
*/ | |
public function tab_uploaded() { | |
$my_context_uploads = get_posts( array( | |
'post_type' => 'attachment', | |
'meta_key' => '_wp_attachment_context', | |
'meta_value' => $this->context, | |
'orderby' => 'post_date', | |
'nopaging' => true, | |
) ); | |
?> | |
<div class="uploaded-target"></div> | |
<?php | |
if ( empty( $my_context_uploads ) ) | |
return; | |
foreach ( (array) $my_context_uploads as $my_context_upload ) { | |
$this->print_tab_image( esc_url_raw( $my_context_upload->guid ) ); | |
} | |
} | |
} | |
/** | |
* Example of inserting a section called "Branding" with a | |
* context-based image uploader | |
*/ | |
$wp_customize->add_section( 'my_branding', array( | |
'title' => __( 'Branding', '' ), | |
'priority' => 30, | |
) ); | |
$wp_customize->add_setting( 'my_logo', array( | |
'capability' => 'edit_theme_options' | |
) ); | |
$wp_customize->add_control( new My_Customize_Image_Reloaded_Control( $wp_customize, 'my_logo', array( | |
'label' => __( 'Logo', '' ), | |
'section' => 'my_branding', | |
'settings' => 'my_logo', | |
'context' => 'my-custom-logo' | |
) ) ); | |
?> |
@nativeimaging @eduardozulian seems since 3.9 was released a few things changed, mainly a bug arose, the "remove" option is now gone. Looking into a fix.
hello,
i trying out your class and it act strange.
Right after i
require 'My_Customize_Image_Control.php';
and i save the new image options i get an error
Fatal error: Class 'WP_Customize_Image_Control' not found
And the Website is not loaded.
So after outcommenting
//require 'My_Customize_Image_Control.php';
the website loads correctly again.
What do i need to do to fix this?
Regards
AHHHH!!! THIS IS AMAZING!
@wesweat You need to go into your functions.php and add it from there. Look at https://gist.github.com/eduardozulian/4739075/#comment-823136
Anyway, I'm writing to ask how to actually use this? I'm not sure what to put inside the context. Anything I put in doesn't seem to work. The Uploaded tab is still hidden.
cool and time saved
@eduardozulian thanks for this! Wicked to extend this capability. Any resources that might point out how to implement or grab the new CustomLogo in the header.php
?
Oops, discard that last comment. It reappeared. :) Love this snippet!!!