dismiss_pointer(); wp_send_json_success( $dismissed ); exit; } /** * Load correct pointers if any. * * @version 1.8.1.5 */ public function setup_pointers_for_screen() { if ( ! function_exists( 'get_current_screen' ) ) { return; } $screen = get_current_screen(); if ( ! $screen || ! is_object( $screen ) ) { return; } if ( ! in_array( $screen->id, charitable_get_charitable_screens() ) ) { return; } // Don't show this immediately for new users. $slug = 'donor-pointers'; // determine when to display this message. for now, there should be some sensible boundaries before showing the notification: a minimum of 14 days of use, created one donation form and received at least one donation. $activated_datetime = ( false !== get_option( 'wpcharitable_activated_datetime' ) ) ? get_option( 'wpcharitable_activated_datetime' ) : false; $activated_datetime = ( false === $activated_datetime ) ? get_option( 'charitable_activated', 0 ) : $activated_datetime; $days = 0; if ( $activated_datetime ) { $diff = current_time( 'timestamp' ) - $activated_datetime; $days = abs(ceil($diff / 86400)); } $count_campaigns = wp_count_posts( 'campaign' ); $total_campaigns = isset( $count_campaigns->publish ) ? $count_campaigns->publish : 0; // If days is at least 1 and the user isn't already on the 'charitable-donors' page, show the pointer. if ( $days >= apply_filters( 'charitable_days_since_activated', 1 ) && isset( $_GET['page'] ) && $_GET['page'] !== 'charitable-donors' ) { // phpcs:ignore // check transient. $help_pointers = get_transient( 'charitable_' . $slug . '_onboarding' ); // render five star rating banner/notice. if ( ! $help_pointers ) { wp_enqueue_style( 'wp-pointer' ); wp_enqueue_script( 'wp-pointer' ); $this->create_new_features_showoff(); } } } /** * Pointers for creating a feature show off! * * @version 1.8.1.5 * @version 1.8.5.1 * * @return void */ public function create_new_features_showoff() { if ( ! current_user_can( 'manage_options' ) ) { return; } if ( defined( 'CHARITABLE_DISABLE_ADMIN_POINTERS' ) && CHARITABLE_DISABLE_ADMIN_POINTERS ) { return; } // These pointers will chain - they will not be shown at once. $this->pointers = array( 'pointers' => array( 'tools' => array( 'target' => '#toplevel_page_charitable ul li.donors', 'next' => false, 'next_trigger' => array(), 'options' => array( 'content' => '

' . esc_html__( 'New Donor Management', 'charitable' ) . '

' . '

' . sprintf( /* translators: %s: URL to upgrade to Pro */ esc_html__( 'Maintain detailed donor profiles, monitor donation histories, and streamline your communication with supporters. Consider upgrading to %s.', 'charitable' ), 'Charitable Pro' ) . '

', 'position' => array( 'edge' => 'left', 'align' => 'left', ), 'visit_button' => array( 'url' => admin_url( 'admin.php?page=charitable-donors' ), 'label' => esc_html__( 'Go Here', 'charitable' ), ), ), ), ), ); // if CHARITABLE_FORCE_ADMIN_POINTERS isn't defined, we'll check if the user has dismissed the pointers before. if ( ! defined( 'CHARITABLE_FORCE_ADMIN_POINTERS' ) || ! CHARITABLE_FORCE_ADMIN_POINTERS ) { // Check user meta - if the user has seen these before, don't show them again. $dismissed = get_user_meta( get_current_user_id(), 'charitable-pointer-slug-dismissed', true ); if ( ! empty( $dismissed ) ) { foreach ( $dismissed as $pointer ) { if ( isset( $this->pointers['pointers'][ $pointer ] ) ) { unset( $this->pointers['pointers'][ $pointer ] ); } } // if any of the pointer keys are found in dismissed remove all the keys. if ( in_array( array_keys( $this->pointers['pointers'] ), $dismissed, true ) ) { foreach ( $this->pointers['pointers'] as $pointer => $pointer_info ) { unset( $this->pointers['pointers'][ $pointer ] ); } } } } } /** * Register pointers and added needed JavaScript. * * @version 1.8.1.5 * * @return void */ public function register_pointer() { if ( empty( $this->pointers ) ) { return; } $pointers = wp_json_encode( $this->pointers ); // phpcs:disable echo( "" ); // phpcs:enable } /** * Dismiss pointer. * * @version 1.8.1.5 * * @return bool */ public function dismiss_pointer() { if ( isset( $_POST['action'] ) && 'charitable_dismiss_pointer' == $_POST['action'] ) { // phpcs:ignore // get dismissed pointer slugs from the current user. $dismissed = (array) get_user_meta( get_current_user_id(), 'charitable-pointer-slug-dismissed', true ); if ( false === $dismissed ) { $dismissed = array(); } $dismissed[] = esc_attr( $_POST['pointer'] ); // phpcs:ignore $dismissed = array_unique( $dismissed ); $dismissed = array_filter( $dismissed ); return update_user_meta( get_current_user_id(), 'charitable-pointer-slug-dismissed', $dismissed ); } } } new Charitable_Admin_Pointers(); endif;