addon_name = $addon_name; $this->addon_code = $addon_code; $this->version = $version; $this->plugin_file = $plugin_file; $this->plugin_basename = plugin_basename( $plugin_file ); $this->author = $author; $this->hooks(); } /** * setup hooks. * * @access private * * @since 5.0 */ private function hooks() { add_action( 'admin_init', array( $this, 'check_license' ), 0 ); add_action( 'admin_notices', array( $this, 'show_admin_notices' ) ); add_action( 'after_plugin_row_' . $this->plugin_basename, array( $this, 'plugin_row' ), 11, 3 ); add_action( 'bd_license_form' , array( $this, 'display_license_form' ) ); add_action( 'bd_license_field', array( $this, 'add_license_field' ) ); add_filter( 'bd_license_input', array( $this, 'parse_license_input' ), 1 ); } /** * Check whether the license is valid for the addon. * * If the license is not valid then add a notice about it. * If it is valid then hook the plugin updater. * * @since 5.5 */ public function check_license() { if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return; } $campaign_args = array( 'utm_source' => 'wpadmin', 'utm_campaign' => 'BulkDelete', 'utm_medium' => 'header-notice', 'utm_content' => strtolower( $this->addon_code ), ); $addon_url = bd_get_addon_url( $this->addon_name, $campaign_args ); $license_code = BD_License::get_license_code( $this->addon_code ); if ( false == $license_code ) { $this->notice_msg = sprintf( __( '"%1$s" addon is installed but not activated. To activate the addon, please enter your license key. If you don\'t have a license key, then you can purchase one.', 'bulk-delete' ), $this->addon_name, esc_url( get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=' . Bulk_Delete::ADDON_PAGE_SLUG ), esc_url( $addon_url ) ); } else { if ( ! BD_License::has_valid_license( $this->addon_name, $this->addon_code ) ) { $this->notice_msg = sprintf( __( 'The license for "%1$s" addon is either invalid or has expired. Please renew the license or enter a new license key to receive updates and support.', 'bulk-delete' ), $this->addon_name, esc_url( $addon_url ), esc_url( get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=' . Bulk_Delete::ADDON_PAGE_SLUG ) ); } } $this->hook_updater( $license_code ); } /** * Start the updater. * * @since 5.0 * @access private * * @param string $license_code License Code */ private function hook_updater( $license_code ) { if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { require_once Bulk_Delete::$PLUGIN_DIR . '/include/libraries/EDD_SL_Plugin_Updater.php'; } $this->updater = new EDD_SL_Plugin_Updater( BD_EDD_API_Wrapper::STORE_URL, $this->plugin_file, array( 'version' => $this->version, 'license' => $license_code, 'item_name' => $this->addon_name, 'addon_code' => $this->addon_code, 'author' => $this->author, 'url' => home_url(), ) ); } /** * Display notification at the top of all admin pages. * * @since 5.5 */ public function show_admin_notices() { /** * Check if user have admin rights. * * @since 6.0 */ if ( current_user_can( 'manage_options' ) ) { if ( '' != $this->notice_msg ) { printf( '

%s

', $this->notice_msg ); } } } /** * Display license information about addon in plugin list table. * * @since 5.5 * * @param string $plugin_file Path to the plugin file, relative to the plugins directory. * @param array $plugin_data An array of plugin data. * @param string $status Status of the plugin. */ public function plugin_row( $plugin_file, $plugin_data, $status ) { if ( $plugin_file != $this->plugin_basename ) { return; } $campaign_args = array( 'utm_source' => 'wpadmin', 'utm_campaign' => 'BulkDelete', 'utm_medium' => 'plugin-page', 'utm_content' => strtolower( $this->addon_code ), ); $addon_url = bd_get_addon_url( $this->addon_name, $campaign_args ); $license_code = BD_License::get_license_code( $this->addon_code ); if ( false == $license_code ) { $plugin_row_msg = sprintf( __( 'Addon is not activated. To activate the addon, please enter your license key. If you don\'t have a license key, then you can purchase one.', 'bulk-delete' ), esc_url( get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=' . Bulk_Delete::ADDON_PAGE_SLUG ), esc_url( $addon_url ) ); ?>
addon_name, $this->addon_code ) ) { $plugin_row_msg = sprintf( __( 'The license for this addon is either invalid or has expired. Please renew the license or enter a new license key to receive updates and support.', 'bulk-delete' ), esc_url( $addon_url ), esc_url( get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=' . Bulk_Delete::ADDON_PAGE_SLUG ) ); ?>
addon_name, $this->addon_code ) ) { $bd = BULK_DELETE(); $bd->display_activate_license_form = true; } } /** * Add the license field to license form. * * @since 5.0 */ public function add_license_field() { if ( ! BD_License::has_valid_license( $this->addon_name, $this->addon_code ) ) { add_settings_field( $this->addon_code, // ID '"' . $this->addon_name . '" ' . __( 'Addon License Key', 'bulk-delete' ), // Title array( $this, 'print_license_key_field' ), // Callback Bulk_Delete::ADDON_PAGE_SLUG, // Page Bulk_Delete::SETTING_SECTION_ID // Section ); } } /** * Print the license field. * * @since 5.0 */ public function print_license_key_field() { if ( ! BD_License::has_valid_license( $this->addon_name, $this->addon_code ) ) { printf( '', $this->addon_code, Bulk_Delete::SETTING_OPTION_NAME, $this->addon_code, __( 'Enter license key', 'bulk-delete' ) ); } } /** * Parse the license key and activate it if needed. * If the key is invalid, then don't save it in the setting option. * * @since 5.0 * * @param array $input * * @return array */ public function parse_license_input( $input ) { if ( is_array( $input ) && key_exists( $this->addon_code, $input ) ) { $license_code = trim( $input[ $this->addon_code ] ); if ( ! empty( $license_code ) ) { if ( ! BD_License::has_valid_license( $this->addon_name, $this->addon_code ) ) { $activated = BD_License::activate_license( $this->addon_name, $this->addon_code, $license_code ); if ( ! $activated ) { unset( $input[ $this->addon_code ] ); } } } else { unset( $input[ $this->addon_code ] ); } } else { if ( BD_License::has_valid_license( $this->addon_name, $this->addon_code ) ) { $license_code = BD_License::get_license_code( $this->addon_code ); $input[ $this->addon_code ] = $license_code; } } return $input; } } ?>