Skip to content

Instantly share code, notes, and snippets.

@franz-josef-kaiser
Last active December 21, 2015 06:08
Show Gist options
  • Save franz-josef-kaiser/6261781 to your computer and use it in GitHub Desktop.
Save franz-josef-kaiser/6261781 to your computer and use it in GitHub Desktop.
Plugin to reproduce a bug that seems to toggle Admin Menu items, The whole post/post-new screen contents and user preferences for Screen Options (showing Meta Boxes). Everything needs confirmation. The plugin logs the responsible JavaScript Events to the console.
<?php
namespace WCMTest;
defined( 'ABSPATH' ) OR exit;
/** Plugin Name: Toggle MetaBox: Bug Inspect */
\add_action( 'admin_menu', array( __NAMESPACE__.'\AddMetaBox', 'getInstance' ) );
class AddMetaBox
{
public static $instance = null;
public static function getInstance()
{
null === self::$instance AND self::$instance = new self;
return self::$instance;
}
public function __construct()
{
\add_action( 'add_meta_boxes', array( $this, 'addMetaBox' ) );
\add_action( 'admin_footer-post-new.php', array( $this, 'addDebugScript' ) );
}
public function addMetaBox()
{
\add_meta_box(
\get_current_screen()->id,
'MetaBox Test',
array( $this, 'metaBoxContent' )
);
}
public function metaBoxContent()
{
printf(
'<pre>%s</pre>',
htmlspecialchars( var_export( \get_current_screen(), true ) )
);
}
public function addDebugScript()
{
$el = \get_current_screen()->id."-hide";
?>
<script type="text/javascript">
"use strict";
( function( $ ) {
$( '#<?php echo $el; ?>' ).on( 'click', function( ev ) {
$.each(
$( '#<?php echo $el; ?>' ).data( 'events' ),
function( i, e ) {
console.log( i, e );
}
);
} );
} )( jQuery );
</script>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment