* @license GPL-2.0+ * @link https://wpadvancedads.com * @copyright since 2013 Thomas Maier, Advanced Ads GmbH * * Plugin class. This class should ideally be used to work with the * administrative side of the WordPress site. */ class Advanced_Ads_Admin { /** * Instance of this class. * * @var object */ protected static $instance = null; /** * Instance of admin notice class. * * @var object $notices */ protected $notices = null; /** * Slug of the settings page * * @var string $plugin_screen_hook_suffix */ public $plugin_screen_hook_suffix = null; /** * General plugin slug * * @var string */ protected $plugin_slug = ''; /** * Admin settings. * * @var array */ protected static $admin_settings = null; /** * Initialize the plugin by loading admin scripts & styles and adding a * settings page and menu. */ private function __construct() { if ( wp_doing_ajax() ) { new Advanced_Ads_Ad_Ajax_Callbacks(); add_action( 'plugins_loaded', [ $this, 'wp_plugins_loaded_ajax' ] ); } else { add_action( 'plugins_loaded', [ $this, 'wp_plugins_loaded' ] ); Advanced_Ads_Ad_List_Filters::get_instance(); } // add shortcode creator to TinyMCE. Advanced_Ads_Shortcode_Creator::get_instance(); Advanced_Ads_Admin_Licenses::get_instance(); } /** * License handling legacy code after moving license handling code to Advanced_Ads_Admin_Licenses * * @param string $addon slug of the add-on. * @param string $plugin_name name of the add-on. * @param string $options_slug slug of the options the plugin is saving in the options table. * * @return mixed 1 on success or string with error message. * @since version 1.7.16 (early January 2017) */ public function deactivate_license( $addon = '', $plugin_name = '', $options_slug = '' ) { return Advanced_Ads_Admin_Licenses::get_instance()->deactivate_license( $addon, $plugin_name, $options_slug ); } /** * Get license status. * * @param string $slug slug of the add-on. * * @return string license status */ public function get_license_status( $slug = '' ) { return Advanced_Ads_Admin_Licenses::get_instance()->get_license_status( $slug ); } /** * Actions and filter available after all plugins are initialized. */ public function wp_plugins_loaded() { // call $plugin_slug from public plugin class. $plugin = Advanced_Ads::get_instance(); $this->plugin_slug = $plugin->get_plugin_slug(); // update placements. add_action( 'admin_init', [ 'Advanced_Ads_Placements', 'update_placements' ] ); // add Advanced Ads admin notices // removes admin notices from other plugins // `in_admin_header` is the last hook to run before àdmin_notices` according to https://codex.wordpress.org/Plugin_API/Action_Reference. add_action( 'in_admin_header', [ $this, 'register_admin_notices' ] ); add_action( 'plugins_api_result', [ $this, 'recommend_suitable_add_ons' ], 11, 3 ); // register dynamic action to load a starter setup. add_action( 'admin_action_advanced_ads_starter_setup', [ $this, 'import_starter_setup' ] ); Advanced_Ads_Admin_Meta_Boxes::get_instance(); Advanced_Ads_Admin_Ad_Type::get_instance(); Advanced_Ads_Admin_Settings::get_instance(); Advanced_Ads_Ad_Authors::get_instance(); new Advanced_Ads_Admin_Upgrades(); new Advanced_Ads\Admin\Post_List(); } /** * Actions and filters that should also be available for ajax */ public function wp_plugins_loaded_ajax() { // needed here in order to work with Quick Edit option on ad list page. Advanced_Ads_Admin_Ad_Type::get_instance(); new Advanced_Ads\Admin\Post_List(); add_action( 'wp_ajax_advads_load_rss_widget_content', [ 'Advanced_Ads_Admin_Meta_Boxes', 'dashboard_widget_function_output' ] ); } /** * Return an instance of this class. * * @return object A single instance of this class. */ public static function get_instance() { // If the single instance hasn't been set, set it now. if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Check if the current screen belongs to Advanced Ads * * @deprecated 1.47.0 * * @return bool */ public static function screen_belongs_to_advanced_ads() { _deprecated_function( __METHOD__, '1.47.0', '\AdvancedAds\Utilities\Conditional::is_screen_advanced_ads()' ); return Conditional::is_screen_advanced_ads(); } /** * Get action from the params * * @deprecated 1.47.0 */ public function current_action() { _deprecated_function( __METHOD__, '1.47.0', 'AdvancedAds\Utilities\WordPress::current_action()' ); return WordPress::current_action(); } /** * Get DateTimeZone object for the WP installation * * @return DateTimeZone object set in WP settings. * @see Advanced_Ads_Utils::get_wp_timezone() * * @deprecated This is also used outside of admin as well as other plugins. */ public static function get_wp_timezone() { return Advanced_Ads_Utils::get_wp_timezone(); } /** * Get literal expression of timezone. * * @param DateTimeZone $date_time_zone the DateTimeZone object to get literal value from. * * @return string time zone. * @see Advanced_Ads_Utils::get_timezone_name() * * @deprecated This is also used outside of admin as well as other plugins. */ public static function timezone_get_name( DateTimeZone $date_time_zone ) { return Advanced_Ads_Utils::get_timezone_name(); } /** * Registers Advanced Ads admin notices * prevents other notices from showing up on our own pages */ public function register_admin_notices() { /** * Remove all registered admin_notices from AA screens * we need to use this or some users have half or more of their viewports cluttered with unrelated notices */ if ( Conditional::is_screen_advanced_ads() ) { remove_all_actions( 'admin_notices' ); } // register our own notices. add_action( 'admin_notices', [ $this, 'admin_notices' ] ); } /** * Initiate the admin notices class */ public function admin_notices() { // display ad block warning to everyone who can edit ads. if ( WordPress::user_can( 'advanced_ads_edit_ads' ) ) { if ( Conditional::is_screen_advanced_ads() ) { $ad_blocker_notice_id = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix() . 'abcheck-' . md5( microtime() ); wp_register_script( $ad_blocker_notice_id . '-adblocker-notice', false, [], ADVADS_VERSION, true ); wp_enqueue_script( $ad_blocker_notice_id . '-adblocker-notice' ); wp_add_inline_script( $ad_blocker_notice_id . '-adblocker-notice', " jQuery( document ).ready( function () { if ( typeof advanced_ads_adblocker_test === 'undefined' ) { jQuery( '#" . esc_attr( $ad_blocker_notice_id ) . ".message' ).show(); } } );" ); include ADVADS_ABSPATH . 'admin/views/notices/adblock.php'; } } // Show success notice after starter setup was imported. Registered here because it will be visible only once. if ( isset( $_GET['message'] ) && 'advanced-ads-starter-setup-success' === $_GET['message'] ) { add_action( 'advanced-ads-admin-notices', [ $this, 'starter_setup_success_message' ] ); } // register our own notices on Advanced Ads pages, except from the overview page where they should appear in the notices section. $screen = get_current_screen(); if ( class_exists( 'Advanced_Ads_Admin_Notices' ) && WordPress::user_can( 'advanced_ads_edit_ads' ) && ( ! isset( $screen->id ) || 'toplevel_page_advanced-ads' !== $screen->id ) ) { $this->notices = Advanced_Ads_Admin_Notices::get_instance()->notices; echo '