0

I want to make some changes to some Meta within an if statement on a parent function.php file and am doing so via child.

The following is a snippet of the parent code:

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'); }
?>

I have made all other necessary changes to files in other areas around the site with absolutely no errors. For instance, with this being a classified ads website, when customers submit an ad, they can select if the product is "new with tags" or "used with tags" during ad creation. Now i want to display that select in the meta of the ad instead of the original "new" and "used".

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'); }

Thank you for your time!

7
  • Are you sure that's the whole code of the adifier_custom_meta() function in the parent theme's functions.php file? Because I think $advert_details should be written as $meta_boxes[]. Or you could also use $meta_boxes[] = $advert_details;, but I'd use the the former.
    – Sally CJ
    Aug 19, 2018 at 13:24
  • @SallyCJ Well yes and know. There is quite a large array and I only want to change a single instance of that array. I will edit the question so you may see the FULL code including arrays for the adifier_custom_meta() function.
    – James
    Aug 19, 2018 at 14:10
  • I see. But if you override the (pluggable) adifier_custom_meta() function, you would need to copy the whole code there.. There is, however, a way to do what you wanted - i.e. to filter just part of the $advert_details array. I can show you the code.
    – Sally CJ
    Aug 19, 2018 at 14:26
  • So, if i am over riding the code of adifier_custom_meta() function, why is it not implementing. I know I'd lose other functionality but at least i'd know the over ride is working? However, the result of my implementation of this code does not provide any onsite changes. I'd love to see a way to filter just to that specific part leaving everything else unchanged as I do not need to change anything else and would like to keep it as is in parent.
    – James
    Aug 19, 2018 at 15:05
  • I'm not sure why it's not implementing the child function, but try to add echo 'Testing'; before the return statement in the adifier_custom_meta() function in the child theme. If you don't see the Testing, then maybe the parent theme is not aware of the existence of the child theme's adifier_custom_meta() function. So should I post the code now or would you like to further troubleshoot the "unimplemented function"?
    – Sally CJ
    Aug 19, 2018 at 15:12

1 Answer 1

0

you put a , instead of ; at end of $advert_details. you will better see this kind of error if you better indent the code.

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');

}

you can also try a editor with syntax analyse like Eclipse PHP :
https://www.eclipse.org/pdt/

2
  • Oh how silly. Finally, the site is not crashing and is functional. The change did not implement though. The Meta on an ad still states "new" instead of "new with tags". Any ideas?
    – James
    Aug 19, 2018 at 13:15
  • It seems like the site is still implementing the parent "if" instead of the child.
    – James
    Aug 19, 2018 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.