Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

One of my filters is breaking a plugin that enables featured images for categories. Here's its code:

function html5_insert_image($html, $id, $caption, $title, $align, $url, $size, $alt) {
if (!$caption) {
    $src  = wp_get_attachment_image_src( $id, $size, false );

    $html5 = "<figure id='post-$id media-$id' class='photoswipe align$align'>";
    if ($url) { $html5 .= '<a href="'.$url.'">'; }
    $html5 .= '<img src="'.$src[0].'" class="image" width="'.$src[1].'" height="'.$src[2].'" ';
    if ($alt) { $html5 .= 'alt="'.$alt.'" '; }
    $html5 .= '/>';
    if ($url) { $html5 .= '</a>'; }
    $html5 .= "</figure>";
    return $html5;
} else {
    return $html;
}   
}
add_filter( 'image_send_to_editor', 'html5_insert_image', 10, 9 );

Is there an easy way to disable this filter entirely when the user is on the category management page in the admin panel?

share|improve this question

1 Answer 1

This should work, I guess:

function my_init() {
    global $pagenow;
    if ( is_admin() && $pagenow != 'edit-tags.php' ) {
        add_filter( 'image_send_to_editor', 'html5_insert_image', 10, 9 );
    }
}
add_action('init', 'my_init');

There is also get_current_screen function, which will be perfect here, but... You can use it after admin_init hook, and your image_send_to_editor is called earlier, I guess.

share|improve this answer
    
Unfortunately, this did not solve the problem. For more information, I'm using this PHP class for custom category images: github.com/bainternet/Tax-Meta-Class –  NoviQ Aug 5 '13 at 13:54
    
What do you mean? What exactly have you done? What is the problem now? Are you sure that this filter is added correctly and that it runs? –  Krzysiek Dróżdż Aug 5 '13 at 13:57
    
It's added correctly. The problem might be somewhere else, I guess. When I click the button to add a category image, the normal WP media modal window appears. I can select the image and it gets marked as selected as it should but the moment I save changes, it's gone. I think the problem might be with not-so-flexible functions in this PHP class as it works fine with the default WP image_send_to_editor. –  NoviQ Aug 5 '13 at 15:04
    
I see where the problem is: the html5_insert_image filter somehow prevents the function in the PHP Tax Meta Class to get the ID of the selected image. Not sure how to fix it yet. –  NoviQ Aug 5 '13 at 15:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.