如何在子函数文件中正确实现新的if语句?

时间:2018-08-19 作者:James

我想对父函数的if语句中的某个元进行一些更改。php文件,我通过child这样做。

以下是父代码片段:

if( !function_exists(\'adifier_custom_meta\') ){
function adifier_custom_meta(){

$meta_boxes = array();

$advert_details = array(

array(
        \'id\'                => \'advert_cond\',
        \'name\'              => esc_html__( \'Condition\', \'adifier\' ),
        \'type\'              => \'select\',
        \'options\'           => array(
            \'0\' => esc_html__( \'-Select-\', \'adifier\' ),
            \'1\' => esc_html__( \'New\', \'adifier\' ),
            \'2\' => esc_html__( \'Manufacturer Refurbished\', \'adifier\' ),
            \'3\' => esc_html__( \'Used\', \'adifier\' ),
            \'4\' => esc_html__( \'For Parts Or Not Working\', \'adifier\' ),
        ),
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',          
        ),
    ),

return $meta_boxes;}

add_filter(\'cmb_meta_boxes\', \'adifier_custom_meta\'); }

The following below is the simple change i have made (See meta "new" changed to "new with tags" as with "used".

if( !function_exists(\'adifier_custom_meta\') ){
function adifier_custom_meta(){

$meta_boxes = array();

$advert_details = array(

array(
        \'id\'                => \'advert_cond\',
        \'name\'              => esc_html__( \'Condition\', \'adifier\' ),
        \'type\'              => \'select\',
        \'options\'           => array(
            \'0\' => esc_html__( \'-Select-\', \'adifier\' ),
            \'1\' => esc_html__( \'New with tags\', \'adifier\' ),
            \'2\' => esc_html__( \'Manufacturer Refurbished\', \'adifier\' ),
            \'3\' => esc_html__( \'Used with tags\', \'adifier\' ),
            \'4\' => esc_html__( \'For Parts Or Not Working\', \'adifier\' ),
        ),
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',          
        ),
    ),

return $meta_boxes; }



add_filter(\'cmb_meta_boxes\', \'adifier_custom_meta\');
}

Completing this change is crashing my site. I am unsure as to why. Please see my full child functions.php code:

<?php
 add_action( \'wp_enqueue_scripts\', \'theme_enqueue_styles\', 12 );
 function theme_enqueue_styles() {
 wp_enqueue_style( \'parent-style\', get_template_directory_uri() . 
 \'/style.css\' ); }   

 if( !function_exists(\'adifier_custom_meta\') ){
 function adifier_custom_meta(){

$meta_boxes = array();

$advert_details = array(

array(
        \'id\'                => \'advert_cond\',
        \'name\'              => esc_html__( \'Condition\', \'adifier\' ),
        \'type\'              => \'select\',
        \'options\'           => array(
            \'0\' => esc_html__( \'-Select-\', \'adifier\' ),
            \'1\' => esc_html__( \'New with tags\', \'adifier\' ),
            \'2\' => esc_html__( \'Manufacturer Refurbished\', \'adifier\' ),
            \'3\' => esc_html__( \'Used with tags\', \'adifier\' ),
            \'4\' => esc_html__( \'For Parts Or Not Working\', \'adifier\' ),
        ),
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',          
        ),
    ),

return $meta_boxes; }


add_filter(\'cmb_meta_boxes\', \'adifier_custom_meta\'); }
?>
我已经对网站周围其他区域的文件进行了所有其他必要的更改,绝对没有错误。例如,这是一个分类广告网站,当客户提交广告时,他们可以在广告创建期间选择产品是“带标签的新产品”还是“带标签的使用产品”。现在我想在广告元中显示选择,而不是原来的“新建”和“已使用”。

The below is the full array & the adifier_custom_meta() function from parent:

if( !function_exists(\'adifier_custom_meta\') ){
function adifier_custom_meta(){

$meta_boxes = array();

$advert_details = array(
    array(
        \'id\'                => \'advert_gallery\',
        \'name\'              => esc_html__( \'Images\', \'adifier\' ),
        \'type\'              => \'image\',
        \'repeatable\'        => true,
        \'sortable\'          => true,
    ),
    array(
        \'id\'                => \'advert_videos\',
        \'name\'              => esc_html__( \'Video URLs\', \'adifier\' ),
        \'type\'              => \'text\',
        \'repeatable\'        => true,
        \'sortable\'          => true,
    ),
    array(
        \'id\'                => \'advert_type\',
        \'name\'              => esc_html__( \'Ad Type\', \'adifier\' ),
        \'type\'              => \'select\',
        \'options\'           => array(
            \'1\' => esc_html__( \'Sell\', \'adifier\' ),
            \'2\' => esc_html__( \'Auction\', \'adifier\' ),
            \'3\' => esc_html__( \'Buy\', \'adifier\' ),
            \'4\' => esc_html__( \'Exchange\', \'adifier\' ),
            \'5\' => esc_html__( \'Gift\', \'adifier\' )
        ),
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',          
    ),  
    array(
        \'id\'                => \'advert_start_price\',
        \'name\'              => esc_html__( \'Start Price\', \'adifier\' ),
        \'type\'              => \'text\',
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',
        \'desc\'              => esc_html__( \'Start price if ad is an auction\', \'adifier\' )
    ),
    array(
        \'id\'                => \'advert_price\',
        \'name\'              => esc_html__( \'Price\', \'adifier\' ),
        \'type\'              => \'text\',
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',
        \'desc\'              => esc_html__( \'Leave empty to display price "On Call"\', \'adifier\' )
    ),
    array(
        \'id\'                => \'advert_sale_price\',
        \'name\'              => esc_html__( \'Sale Price\', \'adifier\' ),
        \'type\'              => \'text\',
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',          
    ),
    array(
        \'id\'                => \'advert_expire\',
        \'name\'              => esc_html__( \'Expires\', \'adifier\' ),
        \'type\'              => \'datetime_unix\',
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',          
    ),
    array(
        \'id\'                => \'advert_views\',
        \'name\'              => esc_html__( \'Views\', \'adifier\' ),
        \'type\'              => \'number\',
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',          
    ),
    array(
        \'id\'                => \'advert_sold\',
        \'name\'              => esc_html__( \'Is Sold\', \'adifier\' ),
        \'type\'              => \'select\',
        \'options\'           => array(
            \'0\' => esc_html__( \'No\', \'adifier\' ) ,
            \'1\' => esc_html__( \'Yes\', \'adifier\' ) 
        ),
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',          
    ),
    array(
        \'id\'                => \'advert_negotiable\',
        \'name\'              => esc_html__( \'Is Negotiable\', \'adifier\' ),
        \'type\'              => \'select\',
        \'options\'           => array(
            \'0\' => esc_html__( \'No\', \'adifier\' ) ,
            \'1\' => esc_html__( \'Yes\', \'adifier\' ) 
        ),
    ),
    array(
        \'id\'                => \'advert_cond\',
        \'name\'              => esc_html__( \'Condition\', \'adifier\' ),
        \'type\'              => \'select\',
        \'options\'           => array(
            \'0\' => esc_html__( \'-Select-\', \'adifier\' ),
            \'1\' => esc_html__( \'New\', \'adifier\' ),
            \'2\' => esc_html__( \'Manufacturer Refurbished\', \'adifier\' ),
            \'3\' => esc_html__( \'Used\', \'adifier\' ),
            \'4\' => esc_html__( \'For Parts Or Not Working\', \'adifier\' ),
        ),
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',          
    ),
);

$meta_boxes[] = array(
    \'title\'         => esc_html__( \'Details\', \'adifier\' ),
    \'pages\'         => \'advert\',
    \'fields\'        => $advert_details,
);

$advert_promotions = array(
    array(
        \'id\'                => \'promo_bumpup\',
        \'name\'              => esc_html__( \'Is Bump Up\', \'adifier\' ),
        \'type\'              => \'select\',
        \'options\'           => array(
            \'no\'    => esc_html__( \'No\', \'adifier\' ),
            \'yes\'   => esc_html__( \'Yes\', \'adifier\' )
        ),
        \'values_callback\'   => \'adifier_get_promo_admin_status\',
        \'save_callback\'     => \'adifier_save_promo_admin_status\',
    ),
    array(
        \'id\'                => \'promo_highlight\',
        \'name\'              => esc_html__( \'Highlight Until\', \'adifier\' ),
        \'type\'              => \'datetime_unix\',
    ),
    array(
        \'id\'                => \'promo_topad\',
        \'name\'              => esc_html__( \'Is Top Ads Until\', \'adifier\' ),
        \'type\'              => \'datetime_unix\',
        \'values_callback\'   => \'adifier_get_promo_admin_status\',
        \'save_callback\'     => \'adifier_save_promo_admin_status\',
    ),
    array(
        \'id\'                => \'advert_urgent\',
        \'name\'              => esc_html__( \'Urgent Until\', \'adifier\' ),
        \'type\'              => \'datetime_unix\',
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',
    ),
    array(
        \'id\'                => \'promo_homemap\',
        \'name\'              => esc_html__( \'On Home Map\', \'adifier\' ),
        \'type\'              => \'datetime_unix\',
        \'values_callback\'   => \'adifier_get_promo_admin_status\',
        \'save_callback\'     => \'adifier_save_promo_admin_status\',
    ),
);

$meta_boxes[] = array(
    \'title\'         => esc_html__( \'Promotions\', \'adifier\' ),
    \'pages\'         => \'advert\',
    \'fields\'        => $advert_promotions,
    \'context\'       => \'side\',
);  

$advert_contact = array(
    array(
        \'id\'                => \'advert_location\',
        \'name\'              => esc_html__( \'Location\', \'adifier\' ),
        \'type\'              => \'gmap\',
        \'extract_location\'  => true,
        \'values_callback\'   => \'adifier_get_advert_meta\',
        \'save_callback\'     => \'adifier_save_advert_meta\',
        \'api_key\'           => adifier_get_option( \'google_api_key\' )
    ),
    array(
        \'id\'                => \'advert_phone\',
        \'name\'              => esc_html__( \'Phone\', \'adifier\' ),
        \'type\'              => \'text\',
    ),
);

$meta_boxes[] = array(
    \'title\'         => esc_html__( \'Contact information\', \'adifier\' ),
    \'pages\'         => \'advert\',
    \'fields\'        => $advert_contact,
);  

$advert_report = array(
    array(
        \'id\'                => \'advert_report\',
        \'name\'              => esc_html__( \'Reason\', \'adifier\' ),
        \'type\'              => \'textarea\',
    ),
);


$meta_boxes[] = array(
    \'title\'         => esc_html__( \'Ad Report\', \'adifier\' ),
    \'pages\'         => \'advert\',
    \'fields\'        => $advert_report,
);  

$order_meta = array(
    array(
        \'id\'            => \'order_payment_type\',
        \'name\'          => esc_html__( \'Payment Type\', \'adifier\' ),
        \'type\'          => \'select\',
        \'allow_none\'    => false,
        \'options\'       => apply_filters( \'adifier_payments_dropdown\', array() )
    ),
    array(
        \'id\'    => \'order_transaction_id\',
        \'name\'  => esc_html__( \'Transaction Id\', \'adifier\' ),
        \'type\'  => \'text\',
    ),
    array(
        \'id\'        => \'order_paid\',
        \'name\'      => esc_html__( \'Paid\', \'adifier\' ),
        \'type\'      => \'select\',
        \'options\'   => array(
            \'no\'        => esc_html__( \'No\', \'adifier\' ),
            \'yes\'       => esc_html__( \'Yes\', \'adifier\' )
        )
    ),
);

$meta_boxes[] = array(
    \'title\'     => esc_html__( \'Order Details\', \'adifier\' ),
    \'pages\'     => \'ad-order\',
    \'fields\'    => $order_meta,
);  

return $meta_boxes;}
add_filter(\'cmb_meta_boxes\', \'adifier_custom_meta\'); }
感谢您抽出时间!

1 个回复
SO网友:Kaperto

你把, 而不是; 结束时$advert_details. 如果您更好地缩进代码,您将更好地看到这种错误。

add_action(\'wp_enqueue_scripts\', \'theme_enqueue_styles\', 12);

function theme_enqueue_styles() {
    wp_enqueue_style(\'parent-style\', get_template_directory_uri() . \'/style.css\');
}

if (!function_exists(\'adifier_custom_meta\')) {

    function adifier_custom_meta() {

        $meta_boxes = array();

        $advert_details = array(
            array(
                \'id\'                => \'advert_cond\',
                \'name\'              => esc_html__( \'Condition\', \'adifier\' ),
                \'type\'              => \'select\',
                \'options\'           => array(
                    \'0\' => esc_html__( \'-Select-\', \'adifier\' ),
                    \'1\' => esc_html__( \'New with tags\', \'adifier\' ),
                    \'2\' => esc_html__( \'Manufacturer Refurbished\', \'adifier\' ),
                    \'3\' => esc_html__( \'Used with tags\', \'adifier\' ),
                    \'4\' => esc_html__( \'For Parts Or Not Working\', \'adifier\' ),
                ),
                \'values_callback\'   => \'adifier_get_advert_meta\',
                \'save_callback\'     => \'adifier_save_advert_meta\',          
            ),
        );

        return $meta_boxes;

    }

    add_filter(\'cmb_meta_boxes\', \'adifier_custom_meta\');

}
您还可以尝试使用具有语法分析功能的编辑器,如Eclipse PHP:
https://www.eclipse.org/pdt/

结束