2012年7月10日-WordPress 3.4.1
之前的答案不起作用,正如拉斯特在评论中所说:
与主题相关的内部构件在3.4中经历了重大的重构和API更改,所以很多旧的东西都无法工作
快速脏的jQuery解决方案
add_action(\'admin_head\', \'wpse_13671_script_enqueuer\');
function wpse_13671_script_enqueuer() {
global $current_screen;
/**
* /wp-admin/edit.php?post_type=page
*/
if(\'edit-page\' == $current_screen->id)
{
?>
<script type="text/javascript">
jQuery(document).ready( function($) {
$("a.editinline").live("click", function () {
var ilc_qe_id = inlineEditPost.getId(this);
setTimeout(function() {
$(\'#edit-\'+ilc_qe_id+\' select[name="page_template"] option[value="showcase.php"]\').remove();
}, 100);
});
$(\'#doaction, #doaction2\').live("click", function () {
setTimeout(function() {
$(\'#bulk-edit select[name="page_template"] option[value="showcase.php"]\').remove();
}, 100);
});
});
</script>
<?php
}
/**
* /wp-admin/post.php?post=21&action=edit
*/
if( \'page\' == $current_screen->id )
{
?>
<script type="text/javascript">
jQuery(document).ready( function($) {
$(\'#page_template option[value="showcase.php"]\').remove();
});
</script>
<?php
}
}
没有钩子如果我遵循正确的路径,这就是“操作”发生的地方(
/wp-includes/class-wp-theme.php
), 看起来像
there\'s nothing here to hook on...
/**
* Returns the theme\'s page templates.
*
* @since 3.4.0
* @access public
*
* @return array Array of page templates, keyed by filename, with the value of the translated header name.
*/
public function get_page_templates() {
// If you screw up your current theme and we invalidate your parent, most things still work. Let it slide.
if ( $this->errors() && $this->errors()->get_error_codes() !== array( \'theme_parent_invalid\' ) )
return array();
$page_templates = $this->cache_get( \'page_templates\' );
if ( ! is_array( $page_templates ) ) {
$page_templates = array();
$files = (array) $this->get_files( \'php\', 1 );
foreach ( $files as $file => $full_path ) {
$headers = get_file_data( $full_path, array( \'Template Name\' => \'Template Name\' ) );
if ( empty( $headers[\'Template Name\'] ) )
continue;
$page_templates[ $file ] = $headers[\'Template Name\'];
}
$this->cache_add( \'page_templates\', $page_templates );
}
if ( $this->load_textdomain() ) {
foreach ( $page_templates as &$page_template ) {
$page_template = $this->translate_header( \'Template Name\', $page_template );
}
}
if ( $this->parent() )
$page_templates += $this->parent()->get_page_templates();
return $page_templates;
}