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' ),
),
My Answer:
To create a child plugin for the main plugin and add the additional social profile fields, you can follow these steps:
1. Create a new folder for your child plugin in the plugins directory of your WordPress installation.
2. Create a new PHP file for your child plugin and add the necessary plugin headers at the top of the file.
3. In the PHP file, use the `add_filter` function to hook into the `dokan_profile_social_fields` filter and add the additional social profile fields.
Here's an example code snippet for your child plugin PHP file:
php
/*
Plugin Name: Child Plugin for Dokan
Description: Add additional social profile fields to Dokan plugin
Version: 1.0
Author: Your Name
*/
add_filter( 'dokan_profile_social_fields', 'add_additional_social_fields' );
function add_additional_social_fields( $fields ) {
$fields['telgram'] = array(
'icon' => 'telgram',
'title' => __( 'Telgram', 'dokan-lite' ),
);
$fields['discord'] = array(
'icon' => 'discord',
'title' => __( 'Discord', 'dokan-lite' ),
);
return $fields;
}
4. Save the PHP file and activate the child plugin in the WordPress admin dashboard.
By following these steps, your child plugin will hook into the `dokan_profile_social_fields` filter and add the additional social profile fields to the main plugin's function. This way, you can customize the functionality of the main plugin without modifying its core files.
Rate this post
5 of 5 based on 8965 votesComments