ajax.php
3 weeks ago
install-notice.php
3 weeks ago
install-tracker.php
3 weeks ago
onboard-status.php
3 weeks ago
plugin-data-sender.php
1 year ago
plugin-installer.php
3 weeks ago
plugin-skin.php
1 year ago
plugin-status.php
4 years ago
utils.php
1 year ago
onboard-status.php
109 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ElementsKit_Lite\Libs\Framework\Classes; |
| 4 | |
| 5 | use ElementsKit_Lite\Traits\Singleton; |
| 6 | |
| 7 | defined( 'ABSPATH' ) || exit; |
| 8 | |
| 9 | class Onboard_Status { |
| 10 | |
| 11 | use Singleton; |
| 12 | protected $optionKey = 'elements_kit_onboard_status'; |
| 13 | protected $optionValue = 'onboarded'; |
| 14 | |
| 15 | public function onboard() { |
| 16 | |
| 17 | add_action( 'elementskit/admin/after_save', array( $this, 'ajax_action' ) ); |
| 18 | ( new Install_Notice() )->init(); |
| 19 | |
| 20 | if ( get_option( $this->optionKey ) ) { |
| 21 | return true; |
| 22 | } |
| 23 | |
| 24 | // Skip onboarding when ElementsKit was installed by another Wpmet onboarding flow. |
| 25 | if ( Install_Tracker::was_auto_installed( 'elementskit-lite/elementskit-lite.php' ) ) { |
| 26 | $this->finish_onboard(); |
| 27 | return true; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * We are checking if the user current page is elementskit and if the user is not completing onboarding, |
| 32 | * We are redirecting to the onboarding page. |
| 33 | */ |
| 34 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Checking current page type. The page only can access admin. So nonce verification is not required. |
| 35 | $param = isset( $_GET['ekit-onboard-steps'] ) ? sanitize_text_field( wp_unslash( $_GET['ekit-onboard-steps'] ) ) : null; |
| 36 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Checking current page post_type. The page only can access admin. So nonce verification is not required. |
| 37 | $requestUri = ( isset( $_GET['post_type'] ) ? sanitize_text_field( wp_unslash( $_GET['post_type'] ) ) : '' ) . ( isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '' ); |
| 38 | |
| 39 | if ( strpos( $requestUri, 'elementskit' ) !== false && is_admin() ) { |
| 40 | if ( $param !== 'loaded' && ! get_option( $this->optionKey ) ) { |
| 41 | wp_safe_redirect( $this->get_onboard_url() ); |
| 42 | exit; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | public function ajax_action() { |
| 50 | |
| 51 | if( empty( $_POST['nonce'] ) || !wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'ajax-nonce' ) ){ |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | // finish on-boarding |
| 56 | $this->finish_onboard(); |
| 57 | |
| 58 | if ( ! empty( $_POST['settings']['newsletter_email'] ) && is_email( $_POST['settings']['newsletter_email'] ) ) { |
| 59 | $email = sanitize_email( wp_unslash( $_POST['settings']['newsletter_email'] ) ); |
| 60 | $data = array( |
| 61 | 'email' => $email, |
| 62 | 'slug' => 'elementskit-lite', |
| 63 | ); |
| 64 | |
| 65 | $response = Plugin_Data_Sender::instance()->sendEmailSubscribeData( 'plugin-subscribe', $data ); |
| 66 | Install_Tracker::store_collected_email( $email ); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | private function get_onboard_url() { |
| 71 | return add_query_arg( |
| 72 | array( |
| 73 | 'page' => 'elementskit', |
| 74 | 'ekit-onboard-steps' => 'loaded', |
| 75 | ), |
| 76 | admin_url( 'admin.php' ) |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | public function redirect_onboard() { |
| 81 | if ( ! get_option( $this->optionKey ) ) { |
| 82 | wp_safe_redirect( $this->get_onboard_url() ); |
| 83 | exit; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | public function exit_from_onboard() { |
| 88 | if ( get_option( $this->optionKey ) ) { |
| 89 | wp_safe_redirect( $this->get_plugin_url() ); |
| 90 | exit; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | private static function get_plugin_url() { |
| 95 | return add_query_arg( |
| 96 | array( |
| 97 | 'page' => 'elementskit', |
| 98 | ), |
| 99 | admin_url( 'admin.php' ) |
| 100 | ); |
| 101 | } |
| 102 | |
| 103 | public function finish_onboard() { |
| 104 | if ( ! get_option( $this->optionKey ) ) { |
| 105 | add_option( $this->optionKey, $this->optionValue ); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 |