Hello,
If someone can post working code I will pay full amount to them - Time is against me. Thanks
I am running this function so simply manipulate the old thickbox media box.
As you can see in function I am trying to echo post information (custom field data) inside this media uploader iframe.
Please see below what I have done - but it not working...
Can anyone help please?
Thanks
Josh
add_action('admin_head-media-upload-popup','wpse_59984_script_enqueuer');
function wpse_59984_script_enqueuer() {
?>
<style>
li#tab-type_url {
display: none !important;
}
li#tab-library {
display: none !important;
}
#mass-edit {
display: none !important;
}
</style>
<?php
$blog_details = get_blog_details($blog_id);
$uploadArea = str_replace('.my-site.com', null, $blog_details->domain );
$postID = $_GET['postID'];
$firstname = get_post_meta($postID, 'first_name', true);
$surname = get_post_meta($postID, 'surname', true);
?>
<script type="text/javascript">
jQuery(document).ready(function($){
var galleryLabel = $('li#tab-gallery a').text();
galleryLabel = galleryLabel.replace("Gallery", "<?php echo $firstname.' '.$surname.'\'s '.strtoupper($uploadArea).' Files'; ?>");
$('li#tab-gallery a').text(galleryLabel);
});
</script>
<?php
return;
}
As you can see I'm trying to echo current user information here.
galleryLabel = galleryLabel.replace("Gallery", "<?php echo $firstname.' '.$surname.'\'s '.strtoupper($uploadArea).' Files'; ?>");
But $firstname and $surname are not outputting
Christianto answers:
Where will you call this media uploader modal box?
if this on post/page editor, we can get the value of post id from iframe referer.
simply by change
$postID = $_GET['postID'];
to
$referer = parse_url($_SERVER['HTTP_REFERER']);
preg_match('/post=(\d+)&/', $referer['query'], $referedID);
$postID = $referedID[1];
you also need to set global $blog_id;
Josh Cranwell comments:
Perfect you are a legend. Thank you!
Arnav Joy answers:
i think you have to use "wp_localize_script" as you can not get value of $_GET['postID']; directly
http://codex.wordpress.org/Function_Reference/wp_localize_script
Josh Cranwell comments:
How do I roughly use this within my code?
I'm confused :/