Call to widgets_init function from controller in a controller it does not work


i have a conrtoller (app\controllers) with this code becouse i want to disable widgets from the admin area,
however the widgets_init function does not execute therefore the unregister_widget call does not run.
what am I doing wrong?
Is it possible to make calls to wordpress functions from controllers?


namespace App\Controllers;

use Sober\Controller\Controller;

class CustomUserOptions extends Controller

public function __construct() {
     add_action('widgets_init', [ $this, 'wpdocs_remove_calendar_widget' ], 99);


function wpdocs_remove_calendar_widget() {      



Thank you so much


i have wrote this code in filters.php file

add_action('widgets_init', function () {  





this works fine, so i can make calls to unregister_widget and widgets_init from filters.php

why canĀ“t do the same inside controller file from controllers folders?


Controllers are for modifying and passing data to blade templates. They are not executed during an admin request, therefore admin-specific code in them will never be executed.

thank alwaysblank

i have added the code in filters.php and works fine

This topic was automatically closed after 42 days. New replies are no longer allowed.