constants(); self::$instance->hooks(); } return self::$instance; } /** * Define plugin constants */ public function constants() { if ( ! defined( 'ADSENSE_INPOST_ADS_PLUGIN_DIR' ) ) { define( 'ADSENSE_INPOST_ADS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); } if ( ! defined( 'ADSENSE_INPOST_ADS_PLUGIN_URL' ) ) { define( 'ADSENSE_INPOST_ADS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); } if ( ! defined( 'ADSENSE_INPOST_ADS' ) ) { define( 'ADSENSE_INPOST_ADS', __FILE__ ); } if ( ! defined( 'ADSENSE_INPOST_ADS_PLUGIN_BASENAME' ) ) { define( 'ADSENSE_INPOST_ADS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); } if ( ! defined( 'ADSENSE_INPOST_ADS_VERSION' ) ) { define( 'ADSENSE_INPOST_ADS_VERSION', '1.1.1' ); } } /** * Kick everything off */ public function hooks() { add_action( 'admin_enqueue_scripts', array( $this, 'enqueues' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueues' ) ); add_action( 'admin_notices', array( $this, 'admin_notice' ) ); // Will run for users that are logged in (wp_ajax_nopriv_{action} will run for users that are not logged in) add_action( 'wp_ajax_adsense_inpost_ads_admin_notice', array( $this, 'dismiss_admin_notice' ) ); } /** * Enqueue the assets in the admin */ public function enqueues() { // Add the admin JS if the notice has not been dismissed if ( is_admin() && get_user_meta( get_current_user_id(), 'adsense_inpost_ads_admin_notice', true ) !== 'dismissed' ) { // Adds our JS file to the queue that WordPress will load wp_enqueue_script( 'adsense_inpost_ads_admin_script', ADSENSE_INPOST_ADS_PLUGIN_URL . '/includes/js/dismiss-notice.js', array( 'jquery' ), ADSENSE_INPOST_ADS_VERSION, true ); // Make some data available to our JS file wp_localize_script( 'adsense_inpost_ads_admin_script', 'adsense_inpost_ads_admin', array( 'adsense_inpost_ads_admin_nonce' => wp_create_nonce( 'adsense_inpost_ads_admin_nonce' ), )); } } /** * Add our admin notice if the user has not previously dismissed it. */ public function admin_notice() { ?>