how to Build a plugin child? - php

I need to create a child plugin for a popular plugin
There are a few functions in the main plugin that I need to edit (by the Child plugin) How do I do this?
Note: There is a function in the main plugin, I just need to add code to it with the plugin child
Desired function:
function dokan_get_social_profile_fields() {
$fields = array(
'fb' => array(
'icon' => 'facebook-square',
'title' => __( 'Facebook', 'dokan-lite' ),
),
'gplus' => array(
'icon' => 'google',
'title' => __( 'Google', 'dokan-lite' ),
),
'twitter' => array(
'icon' => 'twitter-square',
'title' => __( 'Twitter', 'dokan-lite' ),
),
'pinterest' => array(
'icon' => 'pinterest-square',
'title' => __( 'Pinterest', 'dokan-lite' ),
),
'linkedin' => array(
'icon' => 'linkedin-square',
'title' => __( 'LinkedIn', 'dokan-lite' ),
),
'youtube' => array(
'icon' => 'youtube-square',
'title' => __( 'Youtube', 'dokan-lite' ),
),
'instagram' => array(
'icon' => 'instagram',
'title' => __( 'Instagram', 'dokan-lite' ),
),
'flickr' => array(
'icon' => 'flickr',
'title' => __( 'Flickr', 'dokan-lite' ),
),
);
return apply_filters( 'dokan_profile_social_fields', $fields );
}
The amount I need to add to it with the Child Plugin:
,
'telgram' => array(
'icon' => 'telgram',
'title' => __( 'Telgram', 'dokan-lite' ),
),
'discord' => array(
'icon' => 'discord',
'title' => __( 'Discord', 'dokan-lite' ),
),

Related

Updating WooCommerce Admin Shipping Order Fields

In functions.php I am trying to use this, but it is not working:
function rt_woocommerce_admin_shipping_fields( $fields ) {
$fields['first_name']['value'] = $_GET['f'];
$fields['last_name']['value'] = $_GET['l'];
$fields['address_1']['value'] = $_GET['a'];
$fields['address_2']['value'] = $_GET['b'];
// etc
// etc
return $fields;
}
add_filter( 'woocommerce_admin_shipping_fields', 'rt_woocommerce_admin_shipping_fields' );
woocommerce_admin_billing_fields() works but the shipping function does not. Any advice? I need to update the fields with $_GET variables on page load. This works perfectly for the billing fields.
The array has label and show indexes for each item in shipping fields. There is no value index by default. See the woocommerce_admin_shipping_fields filter below.
self::$shipping_fields = apply_filters(
'woocommerce_admin_shipping_fields',
array(
'first_name' => array(
'label' => __( 'First name', 'woocommerce' ),
'show' => false,
),
'last_name' => array(
'label' => __( 'Last name', 'woocommerce' ),
'show' => false,
),
'company' => array(
'label' => __( 'Company', 'woocommerce' ),
'show' => false,
),
'address_1' => array(
'label' => __( 'Address line 1', 'woocommerce' ),
'show' => false,
),
'address_2' => array(
'label' => __( 'Address line 2', 'woocommerce' ),
'show' => false,
),
'city' => array(
'label' => __( 'City', 'woocommerce' ),
'show' => false,
),
'postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'show' => false,
),
'country' => array(
'label' => __( 'Country / Region', 'woocommerce' ),
'show' => false,
'type' => 'select',
'class' => 'js_field-country select short',
'options' => array( '' => __( 'Select a country / region…', 'woocommerce' ) ) + WC()->countries->get_shipping_countries(),
),
'state' => array(
'label' => __( 'State / County', 'woocommerce' ),
'class' => 'js_field-state select short',
'show' => false,
),
'phone' => array(
'label' => __( 'Phone', 'woocommerce' ),
),
)
);

wordpress redux framework - create a repeater field and show values later

I am trying to use Redux inside the wordpress theme and not as a plugin. In functions.php I included both redux-framework.php and sample-config.php .
Now I need to create a repeater field.
From Redux doc, I got the following code to use in order to create a repeater field:
$this->sections[] = array(
'title' => __('Repeater Field', 'redux-framework-demo' ),
'icon' => 'el-icon-thumbs-up',
'fields' => array(
array(
'id' => 'repeater-field-id',
'type' => 'repeater',
'title' => __( 'Title', 'redux-framework-demo' ),
'subtitle' => __( '', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
//'group_values' => true, // Group all fields below within the repeater ID
//'item_name' => '', // Add a repeater block name to the Add and Delete buttons
//'bind_title' => '', // Bind the repeater block title to this field ID
//'static' => 2, // Set the number of repeater blocks to be output
//'limit' => 2, // Limit the number of repeater blocks a user can create
//'sortable' => false, // Allow the users to sort the repeater blocks or not
'fields' => array(
array(
'id' => 'title_field',
'type' => 'text',
'placeholder' => __( 'Title', 'redux-framework-demo' ),
),
array(
'id' => 'text_field',
'type' => 'text',
'placeholder' => __( 'Text Field', 'redux-framework-demo' ),
),
array(
'id' => 'select_field',
'type' => 'select',
'title' => __( 'Select Field', 'redux-framework-demo' ),
'options' => array(
'1' => __( 'Option 1', 'redux-framework-demo' ),
'2' => __( 'Option 2', 'redux-framework-demo' ),
'3' => __( 'Option 3', 'redux-framework-demo' ),
),
'placeholder' => __( 'Listing Field', 'redux-framework-demo' ),
),
)
)
)
);
but if I place the code inside functions.php, what will the $this variable refer to? It'll produce errors. So how to use the snippet so that I can retrieve the values from template files as well?
You have to tried an old version system to create a section. You can try the new version system, I'm not sure if this works or not, but you can try this way:
Redux::setSection($opt_name, array(
'title' => __('Ads Sections', 'cbnews'),
'id' => 'ads-sections',
'desc' => __('You can manage your ads', 'cbnews'),
'icon' => 'dashicons dashicons-dashboard',
'fields' => array(
array(
'id' => 'repeater-field-id',
'type' => 'repeater',
'title' => __( 'Title', 'redux-framework-demo' ),
'subtitle' => __( '', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
//'group_values' => true, // Group all fields below within the repeater ID
//'item_name' => '', // Add a repeater block name to the Add and Delete buttons
//'bind_title' => '', // Bind the repeater block title to this field ID
//'static' => 2, // Set the number of repeater blocks to be output
//'limit' => 2, // Limit the number of repeater blocks a user can create
//'sortable' => false, // Allow the users to sort the repeater blocks or not
'fields' => array(
array(
'id' => 'title_field',
'type' => 'text',
'placeholder' => __( 'Title', 'redux-framework-demo' ),
),
array(
'id' => 'text_field',
'type' => 'text',
'placeholder' => __( 'Text Field', 'redux-framework-demo' ),
),
array(
'id' => 'select_field',
'type' => 'select',
'title' => __( 'Select Field', 'redux-framework-demo' ),
'options' => array(
'1' => __( 'Option 1', 'redux-framework-demo' ),
'2' => __( 'Option 2', 'redux-framework-demo' ),
'3' => __( 'Option 3', 'redux-framework-demo' ),
),
'placeholder' => __( 'Listing Field', 'redux-framework-demo' ),
),
)
)
)
));

Adding meta box is only appearing in add new post not appearing in page

add_filter( 'rwmb_meta_boxes', 'your_prefix_meta_boxes' );
function your_prefix_meta_boxes( $meta_boxes ) {
$meta_boxes[] = array(
'title' => __( 'Test Meta Box', 'textdomain' ),
'post_types' => 'post',
'fields' => array(
array(
'id' => 'name',
'name' => __( 'Name', 'textdomain' ),
'type' => 'text',
),
array(
'id' => 'gender',
'name' => __( 'Gender', 'textdomain' ),
'type' => 'radio',
'options' => array(
'm' => __( 'Male', 'textdomain' ),
'f' => __( 'Female', 'textdomain' ),
),
),
array(
'id' => 'email',
'name' => __( 'Email', 'textdomain' ),
'type' => 'email',
),
),
);
return $meta_boxes;
}
i had pud this code in my function.php and i am getting meta box in add new post only. i need meta box also on my page. please help me out
You should select one of the hooks available on your pages and to add your function there. For example use page_template hook:
add_filter( 'page_template', 'your_prefix_meta_boxes' );

Wordpress plugin - get value of field from setting

I am working on a woocommerce plugin extension and i would like to ask how to get value of some field from setting. Like I have checkout page and i would like to make here a list choice and the choices have to be editable.
Here is code which creating fields in setting:
public static function get_settings() {
$settings = array(
'section_title' => array(
'name' => __( 'Nastavení událostí, kde převzít (zatím ještě není nefunguje).', 'woocommerce-settings-tab-demo' ),
'type' => 'title',
'desc' => '',
'id' => 'WC_checkout_extension_section_title'
),
'action1' => array(
'name' => __( 'Akce 1', 'woocommerce-settings-tab-demo' ),
'type' => 'text',
'desc' => __( 'Napiš datum a název akce, pro převzetí.', 'woocommerce-settings-tab-demo' ),
'id' => 'WC_checkout_extension_action1'
),
'action2' => array(
'name' => __( 'Akce 2', 'woocommerce-settings-tab-demo' ),
'type' => 'text',
'desc' => __( 'Napiš datum a název akce, pro převzetí.', 'woocommerce-settings-tab-demo' ),
'id' => 'WC_checkout_extension_action2'
),
'action3' => array(
'name' => __( 'Akce 3', 'woocommerce-settings-tab-demo' ),
'type' => 'text',
'desc' => __( 'Napiš datum a název akce, pro převzetí.', 'woocommerce-settings-tab-demo' ),
'id' => 'WC_checkout_extension_action3'
),
'action4' => array(
'name' => __( 'Akce 4', 'woocommerce-settings-tab-demo' ),
'type' => 'text',
'desc' => __( 'Napiš datum a název akce, pro převzetí.', 'woocommerce-settings-tab-demo' ),
'id' => 'WC_checkout_extension_action4'
),
'action5' => array(
'name' => __( 'Akce 5', 'woocommerce-settings-tab-demo' ),
'type' => 'text',
'desc' => __( 'Napiš datum a název akce, pro převzetí.', 'woocommerce-settings-tab-demo' ),
'id' => 'WC_checkout_extension_action5'
),
);
return apply_filters( 'WC_checkout_extension_settings', $settings );
}
}
WC_checkout_extension::init();
And i need to get values of this fields into this list:
function kia_filter_checkout_fields($fields){
$fields['extra_fields'] = array(
'another_field' => array(
'type' => 'select',
'options' => array( 'a' => __('Akce 1'), 'b' => __( 'Akce 2' ), 'c' => __( 'Akce 3' ) ),
'required' => false,
'label' => __( 'Vyber si akci, na které bys chtěl objednávku vyzvednout' )
)
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'kia_filter_checkout_fields');
Thanks for help

Wordpress metabox not showing up

I need a Webinar in my wordpress site. So I'm registering an meta box for my custom post type. I can see my custom post in the wordpress admin panel, but inside the custom post meta box is missing. What is wrong here!
// Meta boxes
add_filter( 'rwmb_meta_boxes', 'navbig_webinars_register_meta_boxes' );
//Register meta boxes
function navbig_webinars_register_meta_boxes( $meta_boxes )
{
$prefix = 'navbig_webinars_';
$meta_boxes[] = array(
'id' => 'standard',
'title' => __( 'Webinar Data', 'rwmb' ),
'pages' => array( 'webinar' ),
'context' => 'normal',
'priority' => 'high',
'autosave' => true,
'fields' => array(
array(
'name' => __( 'Date of Webinar', 'rwmb' ),
'id' => "webinar_date",
'type' => 'date',
// jQuery date picker options. See here http://api.jqueryui.com/datepicker
'js_options' => array(
'dateFormat' => __( 'dd-MM-yy', 'rwmb' ),
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
),
),
array(
'name' => __( 'Location', 'rwmb' ),
'id' => "webinar-location",
'type' => 'text',
'std' => __( 'Default text value', 'rwmb' ),
),
array(
'name' => __( 'Time Of Webinar', 'rwmb' ),
'id' => 'webinar_time',
'type' => 'time',
'js_options' => array(
'stepMinute' => 5,
'showSecond' => true,
'stepSecond' => 10,
),
),
array(
'name' => __( 'Select Time Zone', 'rwmb' ),
'id' => "select-timezone",
'type' => 'select_advanced',
'options' => array(
'value1' => __( 'PST', 'rwmb' ),
'value2' => __( 'EST', 'rwmb' ),
),
'multiple' => false,
'placeholder' => __( 'Select an Coures Type', 'rwmb' ),
),
// URL
array(
'name' => __( 'Webinar URL', 'rwmb' ),
'id' => "webinar_url",
'type' => 'url',
'std' => 'http://google.com',
),
array(
'name' => __( 'Webinar Banner', 'rwmb' ),
'id' => "webinar_banner",
'type' => 'thickbox_image',
),
),
);
return $meta_boxes;
}
You can find more detail about meta boxes here.
Here is sample add_meta_box code:-
add_meta_box(
'some_meta_box_name'
,__( 'Some Meta Box Headline', 'plugin_textdomain' )
,'render_meta_box_content' //this is callback function.
,'post_type'
,'advanced'
,'high'
);

Categories