class-wpmtst-challenge-modal.php
105 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Challenge main class |
| 4 | * |
| 5 | * @since 2.6.8 |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | |
| 14 | class WPMTST_Challenge_Modal { |
| 15 | |
| 16 | |
| 17 | public function __construct() { |
| 18 | |
| 19 | if ( is_admin() && $this->show_challenge() && 1 == get_option( 'wpmtst-challenge', 1 ) ) { |
| 20 | add_action( 'admin_footer', array( $this, 'challenge_render' ), 99 ); |
| 21 | add_action( 'admin_enqueue_scripts', array( $this, 'challenge_scripts' ) ); |
| 22 | add_action( 'wp_ajax_wpmtst_challenge_hide', array( $this, 'wpmtst_challenge_hide' ) ); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | public function challenge_render() { |
| 27 | |
| 28 | $new_gallery_url = add_query_arg( |
| 29 | array( |
| 30 | 'post_type' => 'wpm-testimonial', |
| 31 | ), |
| 32 | admin_url( 'post-new.php' ) |
| 33 | ); |
| 34 | |
| 35 | ?> |
| 36 | <div class="wpmtst-challenge-wrap"> |
| 37 | <div class="wpmtst-challenge-header"> |
| 38 | <span id="wpmtst-challenge-close" class="dashicons dashicons-no-alt"></span> |
| 39 | <p><?php echo wp_kses_post( __( 'Start enjoying <strong>Strong Testimonials</strong> by adding your first testimonial.', 'strong-testimonials' ) ); ?></p> |
| 40 | </div> |
| 41 | <div class="wpmtst-challenge-list"> |
| 42 | <p><span class="wpmtst-challenge-marker"></span> <?php esc_html_e( 'Primul lucru din lista', 'strong-testimonials' ); ?></p> |
| 43 | <p><span class="wpmtst-challenge-marker"></span> <?php esc_html_e( 'Al 2-lea lucru din lista', 'strong-testimonials' ); ?></p> |
| 44 | <p><span class="wpmtst-challenge-marker"></span> <?php esc_html_e( 'Al 3-lea lucru din lista', 'strong-testimonials' ); ?></p> |
| 45 | <p><span class="wpmtst-challenge-marker"></span> <?php esc_html_e( 'Al 4-lea lucru din lista', 'strong-testimonials' ); ?></p> |
| 46 | <p><span class="wpmtst-challenge-marker"></span> <?php esc_html_e( 'Al 5-lea lucru din lista', 'strong-testimonials' ); ?></p> |
| 47 | </div> |
| 48 | <div class="wpmtst-challenge-footer"> |
| 49 | <img src="<?php echo esc_url( WPMTST_URL . 'admin/img/mascot.png' ); ?>" class="wpmtst-challenge-logo"/> |
| 50 | <div> |
| 51 | <h3>Strong Testimonials</h3> |
| 52 | <p><span class="wpmtst-challenge-time">5:00</span> remaining.</p> |
| 53 | </div> |
| 54 | </div> |
| 55 | <div class="wpmtst-challenge-footer-button"> |
| 56 | <a id="wpmtst-challenge-button" href="<?php echo esc_url( $new_gallery_url ); ?>" class="wpmtst-btn wpmtst-challenge-btn"><?php esc_html_e( 'Create First Gallery', 'strong-testimonials' ); ?></a> |
| 57 | </div> |
| 58 | |
| 59 | </div> |
| 60 | <?php |
| 61 | } |
| 62 | |
| 63 | public function challenge_scripts( $hook ) { |
| 64 | |
| 65 | wp_enqueue_style( 'wpmtst-challenge-style', WPMTST_URL . 'assets/css/challenge.css', array(), true ); |
| 66 | wp_enqueue_script( 'wpmtst-challenge-script', WPMTST_URL . 'assets/js/challenge.js', array( 'jquery' ), '1.0.0', true ); |
| 67 | $args = array( |
| 68 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 69 | 'nonce' => wp_create_nonce( 'wpmtst-challenge' ), |
| 70 | ); |
| 71 | wp_localize_script( 'wpmtst-challenge-script', 'wpmtstChallenge', $args ); |
| 72 | } |
| 73 | |
| 74 | public function show_challenge() { |
| 75 | $args = array( |
| 76 | 'numberposts' => 1, |
| 77 | 'post_status' => 'any, trash', |
| 78 | 'post_type' => 'wpm-testimonial', |
| 79 | ); |
| 80 | |
| 81 | if ( ! isset( $_GET['post_type'] ) || 'wpm-testimonial' !== $_GET['post_type'] ) { |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | if ( empty( get_posts( $args ) ) ) { |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | return false; |
| 90 | } |
| 91 | public function wpmtst_challenge_hide() { |
| 92 | |
| 93 | if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'wpmtst-challenge' ) ) { |
| 94 | wp_send_json_error(); |
| 95 | die(); |
| 96 | } |
| 97 | |
| 98 | update_option( 'wpmtst-challenge', 0 ); |
| 99 | wp_send_json_success(); |
| 100 | wp_die(); |
| 101 | } |
| 102 | } |
| 103 | new WPMTST_Challenge_Modal(); |
| 104 | ?> |
| 105 |