Issues registering a widget area with custom widget class

I am wondering if I am doing something wrong, or if this is a timing issue of some kind.

I have a custom class:


namespace RiotWidgets;

class ContactForm {

    public function __construct()
        add_action('init', $this->register());
        // add_action('init', [$this, 'register']);

        add_filter( 'gform_submit_button', [$this, 'custom_submit_button'], 10, 2 );

    public function register()
        'name'          => 'Contact Page Form',
        'id'            => 'contact_page_form',
        'before_widget' => '<div class="contact-form-wrapper">',
        'after_widget'  => '</div>',

    public function custom_submit_button($button, $form)
      return "<button class='btn btn-lg btn-primary float-right'><span>Submit</span></button>";

Within my plugin file, I am instantiating the class within an init() method in a Bootstrap class. More or less, it’s doing this:

new WidgetsContactForm();

If you notice in my constructor, I have the call to the register() method commented out where I was using WP’s array syntax. This was breaking (shows nothing on front end). Above it I am calling that method directly, and this works fine.

What’s the WP way to do this?

Read more here: Issues registering a widget area with custom widget class

Leave a Reply

Your email address will not be published. Required fields are marked *