I am trying to develop my first Wordpress plugin using OOP by following a guide. I have followed word for word so far yet I am struggling with an issue that I am unable to rewrite what I imagine will be the URL.
This is the code I am using...
class BookItNow
{
function __construct()
{
add_action('init', $this->custom_post_type());
}
function activate()
{
$this->custom_post_type();
flush_rewrite_rules();
}
function register()
{
add_action('admin_enqueue_scripts', array($this, 'enqueue'));
}
function deactivate()
{
flush_rewrite_rules();
}
function custom_post_type()
{
register_post_type('bookings', ['public' => true, 'label' => 'Bookings']);
}
function enqueue()
{
wp_enqueue_style('style', plugins_url('/assets/style.css', __FILE__));
}
}
if (class_exists('BookItNow')) {
$book = new BookItNow();
$book->register();
}
register_activation_hook(__FILE__, array($book, 'activate'));
register_deactivation_hook(__FILE__, array($book, 'deactivate'));
register_uninstall_hook(__FILE__, array($book, 'uninstall'));
And this is the error I am getting Uncaught Error: Call to a member function add_rewrite_tag() on null
. Removing the $this->custom_post_type()
removes this issue, so I have no idea. Any help would be appreciated.