. */ // Exit if accessed directly. if ( ! defined( 'ABSPATH' ) ) exit; final class About_Me_Widget_By_Src { /** * Hold the class instance. * * @var null|About_Me_Widget_By_Src */ private static $instance = null; /** * The constructor */ private function __construct() { // Init tracker $this->includes(); add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); add_action( 'widgets_init', [ $this, 'widgets_init' ] ); add_action( 'admin_footer', [ $this, 'admin_footer' ], 20 ); // Init tracker $this->plugin_tracker(); } /** * The object is created from within the class itself * only if the class has no instance. */ public static function init() { if ( self::$instance == null ) { self::$instance = new self(); } return self::$instance; } /** * After all plugins loaded */ public function plugins_loaded() { // Load plugin textdomain load_plugin_textdomain( 'aboutwidget', false, basename( dirname( __FILE__ ) ) . '/languages' ); } /** * Initialize the plugin tracker * * @return void */ public function plugin_tracker() { if ( ! class_exists( 'Appsero\Client' ) ) { require_once __DIR__ . '/lib/appsero/Client.php'; } $client = new Appsero\Client( 'b5631efe-1587-4365-a4e8-31a5ebab2b6d', 'About Me Widget by SRC', __FILE__ ); // Active insights $client->insights()->init(); } /** * Require necessary files */ private function includes() { require __DIR__ . '/includes/About_Me_Widget.php'; } /** * Admin enqueue scripts */ public function admin_enqueue_scripts() { global $pagenow; if ( 'widgets.php' == $pagenow ) { // WP default media upload files wp_enqueue_media(); } } /** * Active Widget */ public function widgets_init() { register_widget( 'Amws\About_Me_Widget' ); } /** * Admin footer * JS for add or remove widget image */ public function admin_footer() { global $pagenow; if ( 'widgets.php' == $pagenow ) { ?>