首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >add_action在调用我的函数时出现错误

add_action在调用我的函数时出现错误
EN

Stack Overflow用户
提问于 2020-05-16 21:13:19
回答 1查看 261关注 0票数 0

我有以下代码,但wp告诉我:

警告: call_user_func_array()要求参数%1是有效的回调,在第287行的/home/deniztas/hekim.deniz-tasarim.site/wp-includes/class-wp-hook.php中找不到函数'widget_categories‘或函数名无效

那么,为什么我不能添加这个函数呢?我必须做什么?

代码语言:javascript
复制
<?php
/**
 * Plugin Name: Hekim - Elementor Extension
 * Description: For Hekim Theme
 * Plugin URI:  https://themeforest.net/user/helvatica
 * Version:     1.0.0
 * Author:      Helvatica Themes
 * Author URI:  https://themeforest.net/user/helvatica
 * Text Domain: hekim-plugin-elementor-extension
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
/**
 * Main Elementor Test Extension Class
 *
 * The main class that initiates and runs the plugin.
 *
 * @since 1.0.0
 */
   final class Hekim_Elementor {


        /**
         * widget_categories
         *
         * Register new category for widgets.
         *
         * @since 1.2.0
         * @access public
         */
        public function widget_categories( $elements_manager ) {

            $elements_manager->add_category(
                'hero-section',
                [
                    'title' => esc_html__( 'Hero Sections for elemntor', 'megaaddons' ),
                    'icon' => 'fa fa-plug',
                ]
            );

        }

    etc.etc.
    }
    add_action( 'elementor/elements/categories_registered', 'widget_categories' );
    ?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-16 22:25:55

我认为您希望在Elementor中添加小部件类别,以便将小部件分组(请更清楚地说明您下次在问题中要达到的目标)。所以如果这就是你想要实现的,你的插件代码应该是这样的:

代码语言:javascript
复制
<?php
/**
 * Plugin Name: Hekim - Elementor Extension
 * Description: For Hekim Theme
 * Plugin URI:  https://themeforest.net/user/helvatica
 * Version:     1.0.0
 * Author:      Helvatica Themes
 * Author URI:  https://themeforest.net/user/helvatica
 * Text Domain: hekim-plugin-elementor-extension
 */

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

function add_elementor_widget_categories( $elements_manager ) {

    $elements_manager->add_category(
        'hero-section',
        [
            'title' => esc_html__( 'Hero Sections for elemntor', 'megaaddons' ),
            'icon' => 'fa fa-plug',
        ]
    );

}
add_action( 'elementor/elements/categories_registered', 'add_elementor_widget_categories' );


?>

我在文档中找到了正确的结构:https://developers.elementor.com/widget-categories/

您不需要这个类和所有其他东西,只需连接add_action即可。

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61837336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档