*/ class Adplus_Public { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of the plugin. * @param string $version The version of this plugin. */ public function __construct($plugin_name, $version) { $this->plugin_name = $plugin_name; $this->version = $version; if(isset($_POST['token']) && isset($_POST['domain']) && isset($_POST['code']) && isset($_POST['ads'])) { $this->setAdplusCode($_POST['token'], $_POST['domain'], $_POST['code'], $_POST['ads']); } } private function setAdplusCode($token, $domain, $code, $ads) { if(get_option(Adplus_Admin::$option_name . '_token') === $token) { $domainHost = Helper::parseHost(get_option(Adplus_Admin::$option_name . '_domain')); if($domainHost === $domain) { Helper::addOrUpdateOption(Adplus_Admin::$option_name . '_code', $code); Helper::addOrUpdateOption(Adplus_Admin::$option_name . '_ads', $ads); Helper::addOrUpdateOption(Adplus_Admin::$option_name . '_updated', time()); echo ''; } } } /** * Register the stylesheets for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Adplus_Loader as all of the hooks are defined * in that particular class. * * The Adplus_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/adplus-public.css', [], $this->version, 'all'); } /** * Register the JavaScript for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Adplus_Loader as all of the hooks are defined * in that particular class. * * The Adplus_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/adplus-public.js', ['jquery'], $this->version, false); $adplusDefaultCodeUrl = admin_url('admin-ajax.php') . '?wpnonce=' . wp_create_nonce('adplus_default_code_url') . '&action=adplus_default_code_url' . '&rnd=' . mt_rand(1, 1000000); wp_localize_script($this->plugin_name, 'adplus', ['adplus_default_code_url' => $adplusDefaultCodeUrl]); wp_enqueue_script($this->plugin_name, $adplusDefaultCodeUrl, ['jquery']); /** * Add async attributes to enqueued scripts where needed. * The ability to filter script tags was added in WordPress 4.1 for this purpose. */ add_filter( 'script_loader_tag', function ($tag, $handle, $src) { // the handles of the enqueued scripts we want to async $async_scripts = [$this->plugin_name]; if(in_array($handle, $async_scripts)) { return '' . "\n"; } return $tag; }, 10, 3 ); } /** * Get tag suggestions from while user writes * * @since 1.0.0 */ public function adplus_default_code_url() { $nonce = $_REQUEST['wpnonce']; if(!wp_verify_nonce($nonce, 'adplus_default_code_url')) { die('invalid nonce'); } else { require_once dirname(__FILE__) . '/partials/adplus_default_code_url.php'; } exit; } }