tice viewed. * * Whether the notice was viewed by the user. * * @since 1.0.0 * @access public * @static * * @param int $notice_id The notice ID. * * @return bool Whether the notice was viewed by the user. */ public static function is_user_notice_viewed( $notice_id ) { $notices = self::get_user_notices(); if ( empty( $notices ) || empty( $notices[ $notice_id ] ) ) { return false; } return true; } /** * Set admin notice as viewed. * * Flag the user admin notice as viewed using an authenticated ajax request. * * Fired by `wp_ajax_elementor_set_admin_notice_viewed` action. * * @since 1.0.0 * @access public * @static */ public static function ajax_set_admin_notice_viewed() { if ( empty( $_REQUEST['notice_id'] ) ) { wp_die(); } $notices = self::get_user_notices(); if ( empty( $notices ) ) { $notices = []; } $notices[ $_REQUEST['notice_id'] ] = 'true'; update_user_meta( get_current_user_id(), self::ADMIN_NOTICES_KEY, $notices ); if ( ! wp_doing_ajax() ) { wp_safe_redirect( admin_url() ); die; } wp_die(); } /** * @since 2.1.0 * @access public * @static */ public static function set_introduction_viewed( array $data ) { $user_introduction_meta = self::get_introduction_meta(); $user_introduction_meta[ $data['introductionKey'] ] = true; update_user_meta( get_current_user_id(), self::INTRODUCTION_KEY, $user_introduction_meta ); } public static function register_as_beta_tester( array $data ) { update_user_meta( get_current_user_id(), self::BETA_TESTER_META_KEY, true ); $response = wp_safe_remote_post( self::BETA_TESTER_API_URL, [ 'timeout' => 25, 'body' => [ 'api_version' => ELEMENTOR_VERSION, 'site_lang' => get_bloginfo( 'language' ), 'beta_tester_email' => $data['betaTesterEmail'], ], ] ); $response_code = (int) wp_remote_retrieve_response_code( $response ); if ( 200 === $response_code ) { self::set_introduction_viewed( [ 'introductionKey' => Beta_Testers::BETA_TESTER_SIGNUP, ] ); } } /** * @param string $key * * @return array|mixed|string * @since 2.1.0 * @access public * @static */ public static function get_introduction_meta( $key = '' ) { $user_introduction_meta = get_user_meta( get_current_user_id(), self::INTRODUCTION_KEY, true ); if ( ! $user_introduction_meta ) { $user_introduction_meta = []; } if ( $key ) { return empty( $user_introduction_meta[ $key ] ) ? '' : $user_introduction_meta[ $key ]; } return $user_introduction_meta; } /** * Get a user option with default value as fallback. * * @param string $option - Option key. * @param int $user_id - User ID * @param mixed $default - Default fallback value. * * @return mixed */ public static function get_user_option_with_default( $option, $user_id, $default ) { $value = get_user_option( $option, $user_id ); return ( false === $value ) ? $default : $value; } }