Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Dealing with PressThis inside an administrative thickbox
<?php
/**
Auxiliary menu and page with a button to open the thickbox
*/
add_action('admin_menu', 'add_auxiliary_menu');
function add_auxiliary_menu()
{
add_menu_page(
'TB',
'<span style="color:#e57300;">Thickbox</span>',
'edit_pages',
'thickbox-press-this',
'menu_page_content',
'', // icon default for empty
1 // create before Dashboard menu item
);
}
function menu_page_content()
{
wp_enqueue_style('thickbox');
wp_enqueue_script('thickbox');
?>
<div id="icon-post" class="icon32"></div>
<h2>Press-This in a Thickbox</h2>
<div style="width:50%; padding: 5px;" class="updated" >
<p><a class="button-secondary" href="#" id="open-tb"><?php _e( 'Press not this' ); ?></a></p>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#open-tb").click(function() {
tb_show("", "press-this.php?TB_iframe=true&width=720&height=570");
return false;
});
});
</script>
<?php
}
/**
* Style and script for press-this.php
*/
add_action( 'admin_head', 'hide_press_this_notice' );
add_action( 'admin_footer', 'manipulate_press_this_notice' );
/**
* Avoid visual glitches while manipulating with jQuery
*/
function hide_press_this_notice()
{
?>
<style>#message{opacity:0.01}</style>
<?php
}
/**
* The original Press This opens in a normal popup
* ours, inside an iframe
*/
function manipulate_press_this_notice()
{
// The actions of the file don't have a '-$hook'
global $pagenow;
if( 'press-this.php' != $pagenow )
return;
?>
<script type="text/javascript">
jQuery(document).ready(function($)
{
// HAPPENING IN AN IFRAME
if(top!=self)
{
$('#message a').last().remove();
$('#message a').each( function()
{
$(this).removeAttr('onclick');
$(this).attr('target','_parent');
});
}
// UNDO THE CSS RULE FOR BOTH
$('#message').fadeTo(1500,1);
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment