__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(); ?>