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!
adifier_custom_meta()
function in the parent theme'sfunctions.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.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.echo 'Testing';
before thereturn
statement in theadifier_custom_meta()
function in the child theme. If you don't see theTesting
, then maybe the parent theme is not aware of the existence of the child theme'sadifier_custom_meta()
function. So should I post the code now or would you like to further troubleshoot the "unimplemented function"?