使用jQuery和全局$typenow ex非常简单:
add_action(\'admin_print_scripts-post.php\', \'my_publish_admin_hook\');
add_action(\'admin_print_scripts-post-new.php\', \'my_publish_admin_hook\');
function my_publish_admin_hook(){
global $typenow;
if (in_array($typenow, array(\'post\',\'page\',\'mm_photo \'))){
?>
<script language="javascript" type="text/javascript">
jQuery(document).ready(function() {
jQuery(\'#post\').submit(function() {
if (jQuery("#set-post-thumbnail").find(\'img\').size() > 0) {
jQuery(\'#ajax-loading\').hide();
jQuery(\'#publish\').removeClass(\'button-primary-disabled\');
return true;
}else{
alert("please set a featured image!!!");
jQuery(\'#ajax-loading\').hide();
jQuery(\'#publish\').removeClass(\'button-primary-disabled\');
return false;
}
return false;
});
});
</script>
<?php
}
}