2016-12-16 17 views
0

私はsageテーマを初めて使用しています。私はlib/setup.phpファイルにカスタムウィジェットを追加しようとしていますが、クラス 'Roots \ Sage \ Setup \ WP_Widget'が{path}エラーに見つかりません。続きセージテーマにカスタムウィジェットを追加中にエラーが発生しました

は私のコードです:

class Banner_Widget extends WP_Widget { 
function __construct() { 
    $this->WP_Widget('Banner-Widget', __('Banner Widget', 'blogerist'), $widget_ops); 
    add_action('save_post', array(&$this, 'flush_widget_cache')); 
    add_action('deleted_post', array(&$this, 'flush_widget_cache')); 
    add_action('switch_theme', array(&$this, 'flush_widget_cache')); 
} 
public function form($instance) { 
    //form content 

} 
function widget($args, $instance) { 
    //widget content 
} 
function update($new_instance, $old_instance) { 
    $instance = array_map('strip_tags', $new_instance); 
    $this->flush_widget_cache(); 
    $alloptions = wp_cache_get('alloptions', 'options'); 
    if (isset($alloptions['Banner-Widget'])) { 
     delete_option('Banner-Widget'); 
    } 
    return $instance; 
} 
function flush_widget_cache() { 
    wp_cache_delete('Banner-Widget', 'widget'); 
} 
} 

答えて

0

あなたは、あなたがグローバルな名前空間を使用する必要がありますWP_Widgetを拡張することによって、あなたのクラスを作成する場合。

WP_Customize_Controlの前に\記号を追加します。

class Banner_Widget extends \WP_Widget { 
    //.... 
} 
+0

ありがとうございます –

関連する問題