使用foreach创建OOP

时间:2013-10-08 19:30:05

标签: wordpress oop widget

我想使用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'];
    }

}

0 个答案:

没有答案