You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Dokan插件创建子插件并扩展社交资料字段?

How to Add Telegram & Discord Social Profile Fields to Dokan with a Child Plugin

Hey there, great question! The good news is Dokan already provides a perfect filter hook to extend its social profile fields without touching the main plugin code (which is critical to avoid breaking things when Dokan updates). Here's a step-by-step solution:

Step 1: Create a Custom Child Plugin

First, you'll need a tiny custom plugin (this is better than using your theme's functions.php because it stays active even if you switch themes).

Create a new folder in wp-content/plugins/ called dokan-custom-social-fields, then create a file inside it named dokan-custom-social-fields.php with the following code:

<?php
/**
 * Plugin Name: Dokan Custom Social Fields
 * Plugin URI:  #
 * Description: Adds Telegram and Discord social profile fields to Dokan vendor profiles
 * Version:     1.0.0
 * Author:      Your Name
 * Author URI:  #
 * License:     GPL2
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * Add Telegram and Discord to Dokan social profile fields
 *
 * @param array $fields Existing social fields
 * @return array Modified fields with new social links
 */
function dokan_add_custom_social_fields( $fields ) {
    // Add Telegram field
    $fields['telegram'] = array(
        'icon'  => 'telegram',
        'title' => __( 'Telegram', 'dokan-lite' ),
    );

    // Add Discord field
    $fields['discord'] = array(
        'icon'  => 'discord',
        'title' => __( 'Discord', 'dokan-lite' ),
    );

    return $fields;
}
add_filter( 'dokan_profile_social_fields', 'dokan_add_custom_social_fields' );

Step 2: Activate the Plugin

Go to your WordPress admin → Plugins, find "Dokan Custom Social Fields", and activate it.

How This Works

  • We're using the dokan_profile_social_fields filter that's already included in the original dokan_get_social_profile_fields() function. This filter lets us modify the fields array before it's returned.
  • We simply append our new Telegram and Discord entries to the existing fields array.
  • The icon values use Font Awesome class names (Dokan already loads Font Awesome, so these should display correctly out of the box).
  • We use __( 'Telegram', 'dokan-lite' ) to keep the text translatable, matching Dokan's existing localization setup.

Quick Notes

  • If the Telegram/Discord icons don't show up, double-check that your version of Dokan includes those Font Awesome icons. If not, you can enqueue the latest Font Awesome version in your plugin, but most recent Dokan versions support them.
  • This method is 100% update-safe—your custom fields won't be overwritten when Dokan updates.

内容的提问来源于stack exchange,提问作者cdk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:11:04