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

I have a custom class:

<?php

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()
    {
      register_sidebar([
        '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


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: