| @@ -6,8 +6,10 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace SureDonation\Inc\Admin; |
| 9 | 9 | |
| 10 | +use SureDonation\Inc\Campaigns\Campaign_Cpt; | |
| 11 | +use SureDonation\Inc\API\Onboarding_API; | |
| 10 | 12 | use SureDonation\Inc\Helper; |
| 11 | 13 | use SureDonation\Inc\Onboarding; |
| 12 | 14 | use SureDonation\Inc\Pdf\Pdf_Utils; |
| 13 | 15 | use SureDonation\Inc\Payments\Payment_Helper; |
| @@ -73,9 +75,9 @@ | ||
| 73 | 75 | [ |
| 74 | 76 | 'id' => 'sd-configure-gateway', |
| 75 | 77 | 'variant' => 'error', |
| 76 | 78 | // translators: the <a></a> tags wrap the inline link text and must be kept intact. |
| 77 | - 'message' => __( 'No payment gateway is connected, so your forms cannot accept donations yet. <a>Set up a payment gateway</a> to get started.', 'suredonation' ), | |
| 79 | + 'message' => __( 'Your forms cannot accept donations yet. <a>Connect Stripe or PayPal</a> and you can start accepting them today.', 'suredonation' ), | |
| 78 | 80 | 'link' => [ |
| 79 | 81 | // Deep-link to the gateway connect screen, matching the dashboard Quick Access entry. |
| 80 | 82 | 'url' => Payment_Helper::get_settings_url( 'stripe' ), |
| 81 | 83 | ], |
| @@ -109,9 +111,9 @@ | ||
| 109 | 111 | [ |
| 110 | 112 | 'id' => 'sd-test-mode-react', |
| 111 | 113 | 'variant' => 'error', |
| 112 | 114 | // translators: the <a></a> tags wrap the inline link text and must be kept intact. |
| 113 | - 'message' => __( 'SureDonation is in test mode, so no real donations are being processed. <a>Switch to live mode</a> to start accepting them.', 'suredonation' ), | |
| 115 | + 'message' => __( 'Supporters cannot donate while your site is in test mode. Anything they try now is a test and no money reaches you. <a>Switch to live mode</a> when you are ready to accept real donations.', 'suredonation' ), | |
| 114 | 116 | 'link' => [ |
| 115 | 117 | 'url' => $settings_url, |
| 116 | 118 | ], |
| 117 | 119 | 'event' => Analytics::TRACKED_EVENTS['test_mode'], |
| @@ -150,8 +152,13 @@ | ||
| 150 | 152 | * For the form listing, attempt to resolve the originating campaign |
| 151 | 153 | * from the referer (the "back" arrow on the form editor sends the |
| 152 | 154 | * user here) and redirect to that campaign's single view. |
| 153 | 155 | * |
| 156 | + * Campaign creation (post-new.php) is redirected too, so bookmarks and | |
| 157 | + * third-party links to the raw editor land in the creation drawer rather | |
| 158 | + * than producing a half-configured campaign. New forms keep using | |
| 159 | + * post-new.php — the campaign screen links there with a campaign_id. | |
| 160 | + * | |
| 154 | 161 | * @return void |
| 155 | 162 | * @since 1.0.0 |
| 156 | 163 | */ |
| 157 | 164 | public function redirect_cpt_listings() { |
| @@ -156,9 +163,9 @@ | ||
| 156 | 163 | */ |
| 157 | 164 | public function redirect_cpt_listings() { |
| 158 | 165 | global $pagenow; |
| 159 | 166 | |
| 160 | - if ( 'edit.php' !== $pagenow ) { | |
| 167 | + if ( 'edit.php' !== $pagenow && 'post-new.php' !== $pagenow ) { | |
| 161 | 168 | return; |
| 162 | 169 | } |
| 163 | 170 | |
| 164 | 171 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading post_type from query, no state mutation. |
| @@ -163,8 +170,22 @@ | ||
| 163 | 170 | |
| 164 | 171 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading post_type from query, no state mutation. |
| 165 | 172 | $post_type = isset( $_GET['post_type'] ) ? sanitize_key( wp_unslash( $_GET['post_type'] ) ) : ''; |
| 166 | 173 | |
| 174 | + if ( 'post-new.php' === $pagenow ) { | |
| 175 | + /* | |
| 176 | + * Only for users who can actually open the destination: the admin app | |
| 177 | + * requires manage_options, while the campaign post type is creatable | |
| 178 | + * by any role with edit_posts. Redirecting those roles would trade the | |
| 179 | + * editor for a permission error. | |
| 180 | + */ | |
| 181 | + if ( Campaign_Cpt::POST_TYPE === $post_type && current_user_can( 'manage_options' ) ) { | |
| 182 | + wp_safe_redirect( Campaign_Cpt::get_create_url() ); | |
| 183 | + exit; | |
| 184 | + } | |
| 185 | + return; | |
| 186 | + } | |
| 187 | + | |
| 167 | 188 | if ( 'suredonation_form' === $post_type ) { |
| 168 | 189 | $campaign_id = $this->resolve_campaign_id_from_referer(); |
| 169 | 190 | $target = $campaign_id |
| 170 | 191 | ? admin_url( 'admin.php?page=suredonation#/campaigns/' . $campaign_id ) |
| @@ -173,9 +194,9 @@ | ||
| 173 | 194 | wp_safe_redirect( $target ); |
| 174 | 195 | exit; |
| 175 | 196 | } |
| 176 | 197 | |
| 177 | - if ( 'suredonation_cmpgn' === $post_type ) { | |
| 198 | + if ( Campaign_Cpt::POST_TYPE === $post_type ) { | |
| 178 | 199 | wp_safe_redirect( admin_url( 'admin.php?page=suredonation#/campaigns' ) ); |
| 179 | 200 | exit; |
| 180 | 201 | } |
| 181 | 202 | } |
| @@ -281,8 +302,16 @@ | ||
| 281 | 302 | |
| 282 | 303 | // Load JS translations for the admin app. |
| 283 | 304 | wp_set_script_translations( 'suredonation-admin', 'suredonation' ); |
| 284 | 305 | |
| 306 | + // Campaign guided tour resume point (empty when there is none). | |
| 307 | + $campaign_tour_progress = get_user_meta( get_current_user_id(), Onboarding_API::TOUR_PROGRESS_META, true ); | |
| 308 | + $campaign_tour_progress = is_string( $campaign_tour_progress ) ? $campaign_tour_progress : ''; | |
| 309 | + | |
| 310 | + // Campaign whose first-run tour the onboarding wizard armed (empty = none). | |
| 311 | + $campaign_tour_pending = get_user_meta( get_current_user_id(), Onboarding_API::TOUR_PENDING_META, true ); | |
| 312 | + $campaign_tour_pending = is_scalar( $campaign_tour_pending ) ? (string) $campaign_tour_pending : ''; | |
| 313 | + | |
| 285 | 314 | // Localize script with plugin data. |
| 286 | 315 | /** |
| 287 | 316 | * Filters the bootstrap data localized to the SureDonation admin React app |
| 288 | 317 | * (exposed as window.suredonation_admin). Lets features inject additional |
| @@ -302,8 +331,11 @@ | ||
| 302 | 331 | 'site_url' => site_url(), |
| 303 | 332 | 'admin_url' => admin_url(), |
| 304 | 333 | 'is_first_campaign_created' => $this->has_campaigns(), |
| 305 | 334 | 'is_onboarding_completed' => Onboarding::get_instance()->is_completed(), |
| 335 | + 'campaign_tour_seen' => 'yes' === get_user_meta( get_current_user_id(), Onboarding_API::TOUR_SEEN_META, true ), | |
| 336 | + 'campaign_tour_progress' => $campaign_tour_progress, | |
| 337 | + 'campaign_tour_pending' => $campaign_tour_pending, | |
| 306 | 338 | 'rotating_plugin_banner' => $this->get_rotating_plugin_banner(), |
| 307 | 339 | 'smart_tags' => Helper::get_smart_tags(), |
| 308 | 340 | 'is_pro_active' => defined( 'SUREDONATION_PRO_VER' ), |
| 309 | 341 | 'pro_plugin_version' => defined( 'SUREDONATION_PRO_VER' ) ? SUREDONATION_PRO_VER : '', |
| @@ -583,28 +615,36 @@ | ||
| 583 | 615 | } catch ( \Throwable $e ) { |
| 584 | 616 | $has_givewp_data = false; |
| 585 | 617 | } |
| 586 | 618 | |
| 619 | + $has_charitable_data = false; | |
| 620 | + try { | |
| 621 | + $has_charitable_data = \SureDonation\Inc\Import\Charitable\Source::get_instance()->has_charitable_data(); | |
| 622 | + } catch ( \Throwable $e ) { | |
| 623 | + $has_charitable_data = false; | |
| 624 | + } | |
| 625 | + | |
| 587 | 626 | wp_localize_script( |
| 588 | 627 | 'suredonation-onboarding', |
| 589 | 628 | 'suredonation_onboarding', |
| 590 | 629 | [ |
| 591 | - 'apiUrl' => rest_url( 'suredonation/v1' ), | |
| 592 | - 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 593 | - 'pluginUrl' => SUREDONATION_URL, | |
| 594 | - 'adminUrl' => admin_url(), | |
| 595 | - 'dashboardUrl' => admin_url( 'admin.php?page=suredonation' ), | |
| 596 | - 'paymentsUrl' => Payment_Helper::get_settings_url( 'stripe' ), | |
| 597 | - 'campaignsUrl' => admin_url( 'admin.php?page=suredonation#/campaigns' ), | |
| 598 | - 'docsUrl' => 'https://suredonation.com/docs/', | |
| 599 | - 'isProActive' => $is_pro, | |
| 600 | - 'hasGiveWPData' => $has_givewp_data, | |
| 601 | - 'currentUser' => [ | |
| 630 | + 'apiUrl' => rest_url( 'suredonation/v1' ), | |
| 631 | + 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 632 | + 'pluginUrl' => SUREDONATION_URL, | |
| 633 | + 'adminUrl' => admin_url(), | |
| 634 | + 'dashboardUrl' => admin_url( 'admin.php?page=suredonation' ), | |
| 635 | + 'paymentsUrl' => Payment_Helper::get_settings_url( 'stripe' ), | |
| 636 | + 'campaignsUrl' => admin_url( 'admin.php?page=suredonation#/campaigns' ), | |
| 637 | + 'docsUrl' => 'https://suredonation.com/docs/', | |
| 638 | + 'isProActive' => $is_pro, | |
| 639 | + 'hasGiveWPData' => $has_givewp_data, | |
| 640 | + 'hasCharitableData' => $has_charitable_data, | |
| 641 | + 'currentUser' => [ | |
| 602 | 642 | 'firstName' => $current_user ? $current_user->first_name : '', |
| 603 | 643 | 'lastName' => $current_user ? $current_user->last_name : '', |
| 604 | 644 | 'email' => $current_user ? $current_user->user_email : '', |
| 605 | 645 | ], |
| 606 | - 'privacyUrl' => 'https://suredonation.com/privacy-policy/', | |
| 646 | + 'privacyUrl' => 'https://suredonation.com/privacy-policy/', | |
| 607 | 647 | ] |
| 608 | 648 | ); |
| 609 | 649 | |
| 610 | 650 | // Shim suredonation_admin on the onboarding page too — shared API |