get_option(); foreach ( $notifications as $key => $notification ) { // The message should never be empty, if they are, ignore. if ( empty( $notification['content'] ) ) { continue; } // Ignore if notification has already been dismissed. if ( ! empty( $option['dismissed'] ) && in_array( $notification['id'], $option['dismissed'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict continue; } $data[ $key ] = $notification; } return $data; } /** * Verify saved notification data for active notifications. * * @since 2.18 * * @param array $notifications Array of notifications items to verify. * * @return array */ public function verify_active( $notifications ) { if ( ! is_array( $notifications ) || empty( $notifications ) ) { return array(); } $sby_statuses_option = get_option( 'sby_statuses', array() ); $current_time = sby_get_current_time(); // rating notice logic $sby_rating_notice_option = get_option( 'sby_rating_notice', false ); $sby_rating_notice_waiting = get_transient( 'feeds_for_youtube_rating_notice_waiting' ); $should_show_rating_notice = ($sby_rating_notice_waiting !== 'waiting' && $sby_rating_notice_option !== 'dismissed'); // new user discount logic $in_new_user_month_range = true; $should_show_new_user_discount = false; $has_been_one_month_since_rating_dismissal = isset( $sby_statuses_option['rating_notice_dismissed'] ) ? ((int)$sby_statuses_option['rating_notice_dismissed'] + ((int)$notifications['review']['wait'] * DAY_IN_SECONDS)) < $current_time + 1: true; if ( isset( $sby_statuses_option['first_install'] ) && $sby_statuses_option['first_install'] === 'from_update' ) { global $current_user; $user_id = $current_user->ID; $ignore_new_user_sale_notice_meta = get_user_meta( $user_id, 'sby_ignore_new_user_sale_notice' ); $ignore_new_user_sale_notice_meta = isset( $ignore_new_user_sale_notice_meta[0] ) ? $ignore_new_user_sale_notice_meta[0] : ''; if ( $ignore_new_user_sale_notice_meta !== 'always' ) { $should_show_new_user_discount = true; } } elseif ( $in_new_user_month_range && $has_been_one_month_since_rating_dismissal && $sby_rating_notice_waiting !== 'waiting' ) { global $current_user; $user_id = $current_user->ID; $ignore_new_user_sale_notice_meta = get_user_meta( $user_id, 'sby_ignore_new_user_sale_notice' ); $ignore_new_user_sale_notice_meta = isset( $ignore_new_user_sale_notice_meta[0] ) ? $ignore_new_user_sale_notice_meta[0] : ''; if ( $ignore_new_user_sale_notice_meta !== 'always' && isset( $sby_statuses_option['first_install'] ) && $current_time > (int)$sby_statuses_option['first_install'] + ((int)$notifications['discount']['wait'] * DAY_IN_SECONDS) ) { $should_show_new_user_discount = true; } } if ( sby_is_pro_version() ) { $should_show_new_user_discount = false; } if ( isset( $notifications['review'] ) && $should_show_rating_notice ) { return array( $notifications['review'] ); } elseif ( isset( $notifications['discount'] ) && $should_show_new_user_discount ) { return array( $notifications['discount'] ); } return array(); } /** * Get notification data. * * @since 2.18 * * @return array */ public function get() { if ( ! $this->has_access() ) { return array(); } $option = $this->get_option(); // Only update if does not exist. if ( empty( $option['update'] ) ) { $this->update(); } $events = ! empty( $option['events'] ) ? $this->verify_active( $option['events'] ) : array(); $feed = ! empty( $option['feed'] ) ? $this->verify_active( $option['feed'] ) : array(); return array_merge( $events, $feed ); } /** * Add a manual notification event. * * @since 2.18 * * @param array $notification Notification data. */ public function add( $notification ) { if ( empty( $notification['id'] ) ) { return; } $option = $this->get_option(); if ( in_array( $notification['id'], $option['dismissed'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict return; } foreach ( $option['events'] as $item ) { if ( $item['id'] === $notification['id'] ) { return; } } $notification = $this->verify( array( $notification ) ); update_option( $this->option_name(), array( 'update' => $option['update'], 'feed' => $option['feed'], 'events' => array_merge( $notification, $option['events'] ), 'dismissed' => $option['dismissed'], ) ); } /** * Update notification data from feed. * * @since 2.18 */ public function update() { $feed = $this->fetch_feed(); $option = $this->get_option(); update_option( $this->option_name(), array( 'update' => time(), 'feed' => $feed, 'events' => $option['events'], 'dismissed' => $option['dismissed'], ) ); } /** * Do not enqueue anything extra. * * @since 2.18 */ public function enqueues() { } public function review_notice_consent() { //Security Checks check_ajax_referer( 'sby-admin', 'sby_nonce' ); $cap = current_user_can( 'manage_youtube_feed_options' ) ? 'manage_youtube_feed_options' : 'manage_options'; $cap = apply_filters( 'sby_settings_pages_capability', $cap ); if ( ! current_user_can( $cap ) ) { wp_send_json_error(); // This auto-dies. } $consent = isset( $_POST[ 'consent' ] ) ? sanitize_text_field( $_POST[ 'consent' ] ) : ''; update_option( 'sby_review_consent', $consent ); if ( $consent == 'no' ) { $sby_statuses_option = get_option( 'sby_statuses', array() ); update_option( 'sby_rating_notice', 'dismissed', false ); $sby_statuses_option['rating_notice_dismissed'] = sby_get_current_time(); update_option( 'sby_statuses', $sby_statuses_option, false ); } wp_die(); } /** * Output notifications on Form Overview admin area. * * @since 2.18 */ public function output() { // If the Instagram Feed plugin is active, notices only shown on SBY Settings pages if ( function_exists( 'sb_instagram_activate' ) && ! function_exists( 'sb_instagram_feed_pro_init' ) ) { return; } if ( function_exists( 'cff_check_for_db_updates' ) ) { return; } if ( function_exists( 'ctf_check_for_db_updates' ) ) { return; } $notifications = $this->get(); if ( empty( $notifications ) ) { return; } // new user notices included in regular settings page notifications so this // checks to see if user is one of those pages if ( ! empty( $_GET['page'] ) && ( strpos( $_GET['page'], 'sby' ) !== false || strpos( $_GET['page'], 'youtube-feed' ) !== false ) ) { return; } $content_allowed_tags = array( 'em' => array(), 'strong' => array(), 'span' => array( 'style' => array(), ), 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array(), ), ); $image_overlay = ''; foreach ( $notifications as $notification ) { $img_src = SBY_PLUGIN_URL . 'img/' . sanitize_text_field( $notification['image'] ); $type = sanitize_text_field( $notification['id'] ); // check if this is a review notice if( $type == 'review' ) { $review_consent = get_option( 'sby_review_consent' ); $sby_open_feedback_url = 'https://smashballoon.com/feedback/?plugin=youtube-free'; // step #1 for the review notice if ( ! $review_consent ) { ?>
$button ) : $btn_classes = array('sby-btn'); $btn_classes[] = esc_attr( $button['class'] ); if ( $type == 'primary' ) { $btn_classes[] = 'sby-btn-blue'; } else { $btn_classes[] = 'sby-btn-grey'; } ?> >