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.

I want to replace the media uploader thickbox text only if it's used in the theme options page. If it is used in the Post then I don't want to make any changes.

I am trying the following code, but this will change media uploader text in the post as well.
How can I make it to change text only in the theme options page?

add_filter("attribute_escape", "myfunction", 10, 2);
function myfunction($safe_text, $text) {
    return str_replace("Insert into Post", "Use this image", $text);
}
share|improve this question
    
Hi, welcome to WPSE! Please, search before posting a Question. Possible duplicate of Rename the insert button in media upload window. Also, read this Stack FAQ to better understand its mechanics, thanks! –  brasofilo Jul 28 '12 at 16:36
    
@brasofilo the link you mention is not duplicate of my question. If you can read my question again, I know how to change the text, the only problem is how to change text only if the media window is used in the options page (not in any type of post). –  casper Jul 28 '12 at 16:57
    
Sorry, casper, too fast to read = misreading. Made few improvements to the Q and removed the down vote. –  brasofilo Jul 28 '12 at 17:04
add comment

1 Answer

This is a short version of what I do in one of my plugins.
I copied this behavior from the plugin Advanced Custom Fields (some versions ago, donnow how it proceeds now).

1) When calling the thickbox, add a custom query var (mtt_type in this case):

tb_show('{$mtt_title}', 'media-upload.php?type=image&mtt_type=image&TB_iframe=true');

2) Print scripts in media-upload.php to modify the text. Code not tested:

add_action('admin_head-media-upload-popup','wpse_59984_script_enqueuer');

function wpse_59984_script_enqueuer() {
    if( !isset($_GET['mtt_type'] )
        return;

    // HIDE MANY ELEMENTS   
    ?>
        <style>
        #media-upload-header #sidemenu li#tab-type_url, tr.post_excerpt, tr.post_content, tr.url, tr.align, tr.image_alt, tr.post_title.form-required {display: none !important}
        }
        </style>
    <?php

    // REFRESH UPLOAD SCREEN EVERY HALF SECOND TO CHANGE THE BUTTON NAMES
    // Only happens in the Upload Tab
    $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : "type";
    if ( 'type' == $tab ) 
        $refresh = 'var mtt_t = setInterval(function(){
            $("#media-items").each(setButtonNames); 
            $("p.savebutton").css("display", "none");
        }, 500);';
    else 
        $refresh = '';

    // BUTTON NAME
    $select = __("Select Image", 'mtt');

    //CHANGE BUTTON NAMES
   ?>
        <script type="text/javascript">
        function setButtonNames() {
            jQuery(this).find('.savesend .button').val('{$select}');
        }
        jQuery(document).ready(function($){
            $('#media-items').each(setButtonNames);
            <?php echo $refresh; ?>
        });
        </script>
    <?php
}
share|improve this answer
add comment

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.