0

我想使用 foreach 注册小部件

$widgets['Gallery'] = array(
        'title' => __('Gallery', 'redux-framework'),
        'desc' => __('Creates a custom gallery', 'redux-framework'),
        'fields' => array(
            array(
                'id' => 'ids',
                'type' => 'gallery',
                'title' => __('Add/Edit Gallery', 'redux-framework'),
                'subtitle' => __('Create a new Gallery by selecting existing or uploading new images', 'redux-framework'),
            ),
        )
    );
$widgets['textblock'] = array(
    'title' => __('Text Block', 'redux-framework'),
    'desc' => __('Create a simple block text.', 'redux-framework'),
    'fields' => array(
        array(
            'id' => 'content',
            'type' => 'editor',
            'title' => __('Content', 'redux-framework'),
            'subtitle' => __('Enter some content for this textblock', 'redux-framework'),
        ),
    )
);
    foreach ($widgets as $class => $field) {
                $class = str_replace('-', '_', $class);
                class $class extends Cadr_Widget {
                    //the rest of methods here
                }
                if (class_exists($class))
                    register_widget($class);    
            }

有可能做这样的事情吗?我收到错误解析错误:语法错误,意外的 T_VARIABLE,在第 424 行的 C:\Dropbox\xampp\htdocs\theme\wp-content\themes\cadr-master\framework\builder\inc\core.php 中期待 T_STRING

没有在 foreach 中定义类,我必须编写每个类并且我有很多小部件

class Gallery extends cadr_Widget {

    /**
     * Render the widget in frontend
     *
     * @param array $args
     * @param array $instance
     * @return bool|void
     */
    function widget($args, $instance) {
        //echo $instance['content'];
    }

}
4

0 回答 0