Skip to content

Register Admin class

ecorica edited this page Jul 23, 2021 · 1 revision

If you need to load methods only in the back office (add columns in a list view). You can add a class (Main.php) that will be loaded only in the admin.

For a better readability you have to create an Admin folder and add your class inside.

  1. Create your Main class in the Admin folder
<?php

namespace BEA\PB\Admin;

use BEA\PB\Singleton;

/**
 * Basic class for Admin
 *
 * Class Main
 * @package BEA\PB\Admin
 */
class Main {
	/**
	 * Use the trait
	 */
	use Singleton;

	public function init(): void {
	}
}
  1. Instantiate your class in the plugins_loaded method of the root php file.
// Admin
if ( is_admin() ) {
   \BEA\PB\Admin\Main::get_instance();
}
Clone this wiki locally