__FILE__, // (required) Directory path to the main plugin file * 'name' => __( 'Authorize.net Gateway', 'give-authorize' ), // (required) Name of the Add-on * 'version' => GIVE_AUTHORIZE_VERSION, // (required)The most current version * 'documentation_url' => 'http://docs.givewp.com/addon-authorize',// (required) * 'support_url' => 'https://givewp.com/support/', // (required)Location of Add-on settings page, leave blank to hide * 'testing' => false, // (required) Never leave as "true" in production!!! * } */ function __construct( $_banner_details ) { global $give_addons, $pagenow; // Append add-on information to the global variable. $give_addons[] = $_banner_details; if ( 'plugins.php' === $pagenow ) { // Get the current user. $current_user = wp_get_current_user(); $this->user_id = $current_user->ID; // Set up hooks. $this->init(); // Store user id who activated plugin. $this->add_addon_activate_meta(); // Check if notice callback is already hooked. if ( ! $this->is_banner_notice_hooked() ) { // If multiple add-on are activated then show activation banner in tab view. add_action( 'admin_notices', array( $this, 'addon_activation_banner_notices' ), 10 ); } } } /** * Get the meta key name. * * @since 2.1 * @param string $addon_banner_key * * @return string */ public static function get_banner_user_meta_key( $addon_banner_key ) { $addon_slug = sanitize_text_field( $addon_banner_key ); return "give_addon_{$addon_slug}_active_by_user"; } /** * Set up WordPress filters to hook into WP's update process. * * @since 1.0 * @access public * * @return void */ public function init() { // Get the current page to add the notice to add_action( 'current_screen', array( $this, 'give_addon_notice_ignore' ) ); // Get the Give add-ons. $give_addons = $this->get_plugin_file_names(); if ( ! empty( $give_addons ) ) { // Go through each of the add-on and hook deactivate action. foreach ( $give_addons as $addon_name => $give_addon ) { // Testing? if ( true === $give_addon['testing'] ) { $nag_meta_key = 'give_addon_activation_ignore_' . $addon_name; delete_user_meta( $this->user_id, $nag_meta_key ); } // Add deactivate hook. add_action( 'deactivate_' . $give_addon['plugin_main_file'], array( $this, 'remove_addon_activate_meta' ) ); } } } /** * Get plugin file name. * * @since 1.8 * @access private * @return mixed */ private function get_plugin_file_names() { global $give_addons; // Get recently activated plugins. $active_plugins = get_option( 'active_plugins' ); $file_names = array(); if ( empty( $give_addons ) ) { return $file_names; } // Go through each addon and get the plugin file url. foreach ( $give_addons as $give_addon ) { $file_name = ''; $file_path = explode( '/plugins/', $give_addon['file'] ); if ( $file_path ) { $file_path = array_pop( $file_path ); $file_name = current( explode( '/', $file_path ) ); } if ( ! empty( $file_name ) ) { foreach ( $active_plugins as $plugin ) { if ( false !== strpos( $plugin, $file_name ) ) { $add_on_key = sanitize_title( $give_addon['name'] ); $give_addon['plugin_main_file'] = $plugin; // Include plugin file. $file_names[ $add_on_key ] = $give_addon; break; } } } } return $file_names; } /** * Setup user id to option * * @since 1.8 * @access private */ private function add_addon_activate_meta() { // Get all activated add-ons. $give_addons = $this->get_plugin_file_names(); if ( ! empty( $give_addons ) ) { // Go through rach add-ons and add meta data. foreach ( $give_addons as $banner_addon_name => $addon ) { // User meta key. $user_id = __give_get_active_by_user_meta( $banner_addon_name ); if ( ! $user_id ) { update_option( self::get_banner_user_meta_key( $banner_addon_name ), $this->user_id, false ); } } } } /** * Check if the addon_activation_banner_notices function has already been hooked to admin_notice. * * @since 2.1.0 * * @return bool */ public function is_banner_notice_hooked() { global $wp_filter; $notice_already_hooked = false; if ( isset( $wp_filter['admin_notices']->callbacks[10] ) ) { // Get all of the hooks. $admin_notice_callbacks = array_keys( $wp_filter['admin_notices']->callbacks[10] ); if ( ! empty( $admin_notice_callbacks ) ) { foreach ( $admin_notice_callbacks as $key ) { //If the key is found in your string, set $found to true if ( false !== strpos( $key, 'addon_activation_banner_notices' ) ) { $notice_already_hooked = true; } } } } return $notice_already_hooked; } /** * Get the add-on banner notices. * * @since 2.1.0 */ public function addon_activation_banner_notices() { global $pagenow, $give_addons; // Bailout. if ( 'plugins.php' !== $pagenow ) { return false; } // Store the add-ons of which activation banner should be shown. $addon_to_display = array(); // Get recently activated add-ons. $recent_activated = $this->get_recently_activated_addons(); $latest_addon = array(); // Get the plugin folder name, because many give-addon not sending proper plugin_file. if ( ! empty( $recent_activated ) ) { foreach ( $recent_activated as $recent_addon ) { // Get the add-on folder name. $latest_addon[] = substr( $recent_addon, 0, strpos( $recent_addon, '/' ) ); } } // Go through each of the give add-on. foreach ( $give_addons as $addon ) { $addon_sanitized_name = sanitize_title( $addon['name'] ); // Get the add-on dismiss status. $add_on_state = get_user_meta( $this->user_id, "give_addon_activation_ignore_{$addon_sanitized_name}", true ); // Get the option key. $activate_by_user = (int) __give_get_active_by_user_meta( $addon_sanitized_name ); // Remove plugin file and get the Add-on's folder name only. $file_path = $this->get_plugin_folder_name( $addon['file'] ); // If add-on were never dismissed. if ( 'true' !== $add_on_state && $this->user_id === $activate_by_user ) { if ( ! empty( $latest_addon ) && ( in_array( $file_path, $latest_addon, true ) || empty( $latest_addon ) ) ) { $addon_to_display[] = $addon; } } } if ( ! empty( $addon_to_display ) ) { ob_start(); // Output inline styles here because there's no reason // to enqueued them after the alert is dismissed. $this->print_css_js(); ?>
render_single_addon_banner( $banner, false ); $is_first = false; ?>
render_single_addon_banner( $addon_to_display[0], true ); } ?>
notices->register_notice( array( 'id' => 'give_add_on_activation_notice', 'type' => 'updated', 'description_html' => $notice_html, 'show' => true, ) ); } } /** * Render single banner activation * * @since 2.1.0 * * @param array $banner_arr Banner options. * @param bool $is_single Is single. */ private function render_single_addon_banner( $banner_arr, $is_single ) { // Get all give add-on. $give_addons = give_get_plugins(); // Plugin main file. $plugin_file = $banner_arr['file']; // Get the plugin main file. foreach ( $give_addons as $main_file => $addon ) { // Plugin should be activated. if ( ! is_plugin_active( $main_file ) ) { continue; } if ( isset( $banner_arr['name'] ) && 'add-on' === $addon['Type'] && $this->get_plugin_folder_name( $main_file ) === $this->get_plugin_folder_name( $plugin_file ) ) { $plugin_file = WP_PLUGIN_DIR . '/' . $main_file; break; } } // Create dismiss URL. $dismiss_url = $is_single ? admin_url( 'plugins.php?give_addon_activation_ignore=1&give_addon=' . sanitize_title( $banner_arr['name'] ) ) : admin_url( 'plugins.php?give_addon_activation_ignore=1&give_addon=all' ); // Get the add-on details. $plugin_data = get_plugin_data( $plugin_file ); ?>

%s', __( 'New Give Add-on Activated: ', 'give' ), esc_html( $banner_arr['name'] ) ); ?>


%s', esc_url( $banner_arr['settings_url'] ), esc_html__( 'Go to Settings', 'give' ) ); } // Show them how to configure the Addon. if ( isset( $banner_arr['documentation_url'] ) ) { printf( '%s', esc_url( $banner_arr['documentation_url'] ), sprintf( /* translators: %s: Add-on name */ esc_html__( 'Documentation: %s Add-on', 'give' ), esc_html( $banner_arr['name'] ) ) ); } //Let them signup for plugin updates if ( isset( $banner_arr['support_url'] ) ) { printf( '%s', esc_url( $banner_arr['support_url'] ), esc_html__( 'Get Support', 'give' ) ); } ?>
get_plugin_file_names(); if ( ! empty( $give_addons ) ) { $deactivated_addons = array_keys( $give_addons ); } } else { // Store the addon to deactivate. $deactivated_addons[] = $addon_query_arg; } if ( ! empty( $deactivated_addons ) ) { foreach ( $deactivated_addons as $addon ) { // Record it user meta. add_user_meta( $this->user_id, "give_addon_activation_ignore_{$addon}", 'true', true ); } } } } /** * Delete user id from option if plugin deactivated. * * @since 1.8 * @since 2.1.0 Added support for multiple addons. * @access public */ public function remove_addon_activate_meta() { // Get the hook name and then grab the plugin file from it. $plugin_file = str_replace( 'deactivate_', '', current_action() ); // Get all activated add-ons. $give_addons = $this->get_plugin_file_names(); if ( ! empty( $give_addons ) ) { foreach ( $give_addons as $banner_addon_name => $addon ) { if ( $plugin_file === $addon['plugin_main_file'] ) { // Get the user meta key. $user_id = (int) __give_get_active_by_user_meta( $banner_addon_name ); if ( $user_id ) { // Get user meta for this add-on. $nag_meta_key = "give_addon_activation_ignore_{$banner_addon_name}"; // Delete plugin activation option key. delete_option( self::get_banner_user_meta_key( $banner_addon_name ) ); // Delete user meta of plugin activation. delete_user_meta( $user_id, $nag_meta_key ); } } } } } /** * Get list of add-on last activated. * * @since 2.1.0 * * @return mixed|array */ public function get_recently_activated_addons() { return give_get_recently_activated_addons(); } /** * Get the addon's folder name. * * @since 2.1.0 * * @param string $main_file Plugin Main File. * * @return bool|mixed|string */ public function get_plugin_folder_name( $main_file ) { // Remove plugin file and get the Add-on's folder name only. $file_path = explode( '/plugins/', $main_file ); $addon_file_path = array_pop( $file_path ); $addon_file_path = substr( $addon_file_path, 0, strpos( $addon_file_path, '/' ) ); return $addon_file_path; } /** * Add activation banner css and js . * * @since 1.8.16 * @since 2.1.0 Added JS code for multiple add-on. * @access private */ private function print_css_js() { ?>