permalinks = $config->permalinks; $this->register(); } public function register(){ add_action('admin_footer', [$this, 'form']); add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']); add_filter("plugin_action_links_$this->base_name", [$this, 'addButtonInPlugin'] ); add_action("wp_ajax_{$this->prefix}_active_license_key", [$this, 'activeLicense']); add_action("wp_ajax_{$this->prefix}_sync_license_key", [$this, 'ajaxSyncLicense']); add_action('admin_footer', [$this, 'admin_footer']); } public function activeLicense(){ if(isset($_POST['nonce']) && !wp_verify_nonce( $_POST['nonce'], 'wp_ajax' )){ echo wp_json_encode(['success' => false, 'message' => 'invalid nonce']); wp_die(); return; } $data = isset($_POST['data']) ? stripslashes(sanitize_text_field( $_POST['data'])) : "{}"; if(!$data){ echo wp_json_encode(['success' => false, 'message' => 'invalid data']); wp_die(); return; } $result = \update_option($this->prefix."_pipe", $data); echo wp_json_encode(['success' => true]); wp_die(); } public function addButtonInPlugin($links){ if(get_option($this->prefix."_pipe", false) || !$this->config->isBlock){ $text = ($this->isPipe ? __('Deactivate License', 'bsdk') : __('Active License', 'bsdk')); }else { $text = __('Upgrade to pro', 'bsdk'); } $settings_link = ''. $text .''; array_unshift($links, $settings_link); return $links; } public function admin_enqueue_scripts($page){ if($page === 'plugins.php'){ wp_register_script( 'bsdk-license', plugin_dir_url( plugin_dir_path( __DIR__ ) ) . 'dist/license.js', array(), WP_B__VERSION , true ); wp_register_style( 'bsdk-license', plugin_dir_url( plugin_dir_path( __DIR__ ) ) . 'dist/license.css', array(), WP_B__VERSION , 'all' ); wp_localize_script('bsdk-license', 'BSDK', array( 'ajaxURL' => admin_url('admin-ajax.php'), 'website' => site_url(), 'email' => get_option('admin_email'), 'nonce' => wp_create_nonce( 'wp_ajax' ), )); } } public function form(){ $screen = \get_current_screen(); if($screen->base === 'plugins'){ ?>