WordPress : Erreur lors de l’ajout d’un widget personnalisé dans le thème sage
Je suis nouveau sur le thème de la sauge. J’essaie d’ajouter un widget personnalisé dans le fichier lib/setup.php, mais j’obtiens la classe ‘RootsSageSetupWP_Widget’ introuvable dans l’erreur {path}.
Voici mon code :
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');
}
}
Solution n°1 trouvée
Lorsque vous souhaitez créer votre classe en étendant le WP_Widget, vous devez utiliser l’espace de noms global.
Ajoutez un signe avant WP_Customize_Control.
class Banner_Widget extends WP_Widget {
  //....
 }
0 commentaire