这是我第一次接触WordPress,我的任务是把已经定制好的核心功能提取出来,放到一个非核心的文件中,这样升级的时候更便于维护。以下是其中一种方法的示例wp-admin/includes/template.php
:
原始代码:
function meta_form() {
global $wpdb;
$limit = (int) apply_filters( 'postmeta_form_limit', 30 );
$keys = $wpdb->get_col( "
SELECT meta_key
FROM $wpdb->postmeta
GROUP BY meta_key
HAVING meta_key NOT LIKE '\_%'
ORDER BY meta_key
LIMIT $limit" );
if ( $keys )
natcasesort($keys);
?>
定制版:
function meta_form() {
global $wpdb;
if ( isset($_GET['post']) )
$post_id = (int) $_GET['post'];
elseif ( isset($_POST['post_ID']) )
$post_id = (int) $_POST['post_ID'];
else
$post_id = 0;
if ( $post_id ) {
$post_ = get_post($post_id);
}
if ($post_->post_type == 'video_photo' ){
$limit = (int) apply_filters( 'postmeta_form_limit', 30 );
$keys = $wpdb->get_col( "
SELECT meta_key
FROM $wpdb->postmeta
where meta_key like 'tqmcf_%'
GROUP BY meta_key
HAVING meta_key NOT LIKE '\_%'
ORDER BY meta_key
LIMIT $limit" );
}else{
$limit = (int) apply_filters( 'postmeta_form_limit', 30 );
$keys = $wpdb->get_col( "
SELECT meta_key
FROM $wpdb->postmeta
GROUP BY meta_key
HAVING meta_key NOT LIKE '\_%'
ORDER BY meta_key
LIMIT $limit" );
}
if ( $keys )
natcasesort($keys);
?>
我将在哪里定义我的meta_form()
函数以确保它覆盖核心方法?