class-ads-editing.php
3 months ago
class-ads.php
3 months ago
class-dashboard.php
3 months ago
class-groups.php
3 months ago
class-onboarding.php
3 months ago
class-placements.php
3 months ago
class-settings.php
3 months ago
class-support.php
3 months ago
class-tools.php
3 months ago
class-onboarding.php
267 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Onboarding wizard screen. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.47.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds\Admin\Pages; |
| 11 | |
| 12 | use AdvancedAds\Constants; |
| 13 | use Advanced_Ads_AdSense_Data; |
| 14 | use Advanced_Ads_AdSense_MAPI; |
| 15 | use Advanced_Ads_AdSense_Admin; |
| 16 | use AdvancedAds\Abstracts\Screen; |
| 17 | use AdvancedAds\Utilities\Conditional; |
| 18 | |
| 19 | defined( 'ABSPATH' ) || exit; |
| 20 | |
| 21 | /** |
| 22 | * Onboarding Wizard. |
| 23 | */ |
| 24 | class Onboarding extends Screen { |
| 25 | |
| 26 | /** |
| 27 | * Screen unique id. |
| 28 | * |
| 29 | * @return string |
| 30 | */ |
| 31 | public function get_id(): string { |
| 32 | return 'onboarding'; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Register screen into WordPress admin area. |
| 37 | * |
| 38 | * @return void |
| 39 | */ |
| 40 | public function register_screen(): void { |
| 41 | $hook = add_submenu_page( |
| 42 | Constants::HIDDEN_PAGE_SLUG, |
| 43 | __( 'Onboarding Wizard', 'advanced-ads' ), |
| 44 | __( 'Onboarding Wizard', 'advanced-ads' ), |
| 45 | Conditional::user_cap( 'advanced_ads_manage_options' ), |
| 46 | ADVADS_SLUG . '-onboarding', |
| 47 | [ $this, 'display' ] |
| 48 | ); |
| 49 | |
| 50 | $this->set_hook( $hook ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Enqueue assets |
| 55 | * |
| 56 | * @return void |
| 57 | */ |
| 58 | public function enqueue_assets(): void { |
| 59 | $this->i18n(); |
| 60 | $this->adsense_data(); |
| 61 | wp_enqueue_media(); |
| 62 | |
| 63 | wp_advads()->registry->enqueue_style( 'screen-onboarding' ); |
| 64 | wp_advads()->registry->enqueue_script( 'screen-onboarding' ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Display screen content. |
| 69 | * |
| 70 | * @return void |
| 71 | */ |
| 72 | public function display(): void { |
| 73 | include ADVADS_ABSPATH . 'views/admin/screens/onboarding.php'; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Add Adsense data |
| 78 | * |
| 79 | * @return void |
| 80 | */ |
| 81 | private function adsense_data(): void { |
| 82 | if ( current_user_can( Conditional::user_cap( 'advanced_ads_manage_options' ) ) ) { |
| 83 | $nonce = wp_create_nonce( 'advanced_ads_wizard' ); |
| 84 | wp_advads_json_add( |
| 85 | 'wizard', |
| 86 | [ |
| 87 | 'nonce' => $nonce, |
| 88 | 'authUrl' => 'https://accounts.google.com/o/oauth2/v2/auth?scope=' . rawurlencode( 'https://www.googleapis.com/auth/adsense.readonly' ), |
| 89 | 'clientId' => Advanced_Ads_AdSense_MAPI::CID, |
| 90 | 'state' => base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
| 91 | wp_json_encode( |
| 92 | [ |
| 93 | 'api' => 'adsense', |
| 94 | 'nonce' => $nonce, |
| 95 | 'return_url' => admin_url( 'admin.php?page=advanced-ads-onboarding&route=adsense#wizard#adsense' ), |
| 96 | ] |
| 97 | ) |
| 98 | ), |
| 99 | 'redirectUri' => Advanced_Ads_AdSense_MAPI::REDIRECT_URI, |
| 100 | 'adsenseData' => array_merge( |
| 101 | Advanced_Ads_AdSense_Data::get_instance()->get_options(), |
| 102 | [ 'accounts' => Advanced_Ads_AdSense_MAPI::get_option()['accounts'] ] |
| 103 | ), |
| 104 | 'newAccountLink' => Advanced_Ads_AdSense_Admin::ADSENSE_NEW_ACCOUNT_LINK, |
| 105 | ] |
| 106 | ); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Add wizard internationalization |
| 112 | * |
| 113 | * @return void |
| 114 | */ |
| 115 | private function i18n(): void { |
| 116 | wp_advads_json_add( |
| 117 | 'i18n', |
| 118 | [ |
| 119 | 'wizard' => [ |
| 120 | 'loading' => __( 'Loading...', 'advanced-ads' ), |
| 121 | 'processing' => __( 'Processing authorization...', 'advanced-ads' ), |
| 122 | 'selectAccount' => [ |
| 123 | 'optionZero' => __( 'Select an account', 'advanced-ads' ), |
| 124 | 'title' => __( 'Please select an account to use', 'advanced-ads' ), |
| 125 | ], |
| 126 | 'exitLabel' => __( 'Exit the wizard without saving', 'advanced-ads' ), |
| 127 | 'btnGoBack' => __( 'Go back', 'advanced-ads' ), |
| 128 | 'newsletter' => [ |
| 129 | 'title' => __( 'Subscribe to our newsletter and get 2 add-ons for free', 'advanced-ads' ), |
| 130 | 'btnLabel' => __( 'Subscribe now', 'advanced-ads' ), |
| 131 | 'inputPlaceholder' => __( 'Enter your email address', 'advanced-ads' ), |
| 132 | ], |
| 133 | 'stepTitles' => [ |
| 134 | 'adImage' => __( 'Please select your image', 'advanced-ads' ), |
| 135 | 'adCode' => __( 'Please paste your ad code', 'advanced-ads' ), |
| 136 | 'congrats' => [ |
| 137 | 'default' => __( 'Congratulations, your ad is now published!', 'advanced-ads' ), |
| 138 | 'adsenseManual' => __( 'Your ad is almost ready!', 'advanced-ads' ), |
| 139 | 'adsenseAuto' => __( 'Congratulations, AdSense Auto Ads are now set up!', 'advanced-ads' ), |
| 140 | ], |
| 141 | ], |
| 142 | 'firstStep' => [ |
| 143 | 'taskAdSense' => __( 'I want to use mostly Google AdSense or Google Auto Ads', 'advanced-ads' ), |
| 144 | 'taskImage' => __( 'I want to add a banner ad with an image', 'advanced-ads' ), |
| 145 | 'taskCode' => __( 'I want to insert an ad code from an ad network', 'advanced-ads' ), |
| 146 | 'stepHeading' => __( 'Welcome! To kick things off, and to simplify your journey, answer a few questions and let Advanced Ads tailor the perfect ad for your site\'s needs.', 'advanced-ads' ), |
| 147 | 'agreementText' => __( 'I agree to share usage data to <strong>help the developers</strong> improve the plugin. Read more in our <a href="https://wpadvancedads.com/privacy-policy/" target="_blank">privacy policy</a>.', 'advanced-ads' ), |
| 148 | 'inputTitle' => __( 'What\'s your task?', 'advanced-ads' ), |
| 149 | ], |
| 150 | 'bannerAd' => [ |
| 151 | 'mediaFrameTitle' => __( 'Select an image to upload', 'advanced-ads' ), |
| 152 | 'mediaFrameButton' => __( 'Use this image', 'advanced-ads' ), |
| 153 | 'mediaBtnUpload' => __( 'Upload', 'advanced-ads' ), |
| 154 | 'mediaBtnReplace' => __( 'Replace', 'advanced-ads' ), |
| 155 | 'stepHeading' => __( 'Would you like to set a target URL for your image ad?', 'advanced-ads' ), |
| 156 | 'inputPlaceholder' => __( 'Enter an optional target URL for your image ad', 'advanced-ads' ), |
| 157 | 'footerEnableText' => __( 'Create placement and ad', 'advanced-ads' ), |
| 158 | 'footerDisableText' => __( 'Please select an image', 'advanced-ads' ), |
| 159 | ], |
| 160 | 'codeAd' => [ |
| 161 | 'inputPlaceholder' => __( 'Paste the ad code that your advertising network has provided to you', 'advanced-ads' ), |
| 162 | 'footerEnableText' => __( 'Insert the ad code into my site', 'advanced-ads' ), |
| 163 | 'footerDisableText' => __( 'Please paste your ad code', 'advanced-ads' ), |
| 164 | ], |
| 165 | 'googleAd' => [ |
| 166 | 'adsPlacement' => [ |
| 167 | [ |
| 168 | 'label' => __( 'I will place ad units manually', 'advanced-ads' ), |
| 169 | 'value' => 'manual', |
| 170 | ], |
| 171 | [ |
| 172 | 'label' => __( 'I will use Auto Ads and let Google place the ads automatically', 'advanced-ads' ), |
| 173 | 'value' => 'auto_ads', |
| 174 | ], |
| 175 | ], |
| 176 | 'autoAdsOptions' => [ |
| 177 | [ |
| 178 | 'label' => __( 'Enable Auto Ads on my site', 'advanced-ads' ), |
| 179 | 'value' => 'enable', |
| 180 | ], |
| 181 | [ |
| 182 | 'label' => __( 'Enable Accelerated Mobile Pages (AMP) Auto Ads', 'advanced-ads' ), |
| 183 | 'value' => 'enableAmp', |
| 184 | ], |
| 185 | ], |
| 186 | 'errors' => [ |
| 187 | 'notSaved' => __( 'Unknown error while saving account information.', 'advanced-ads' ), |
| 188 | 'notFetched' => __( 'Unknown error while fetching AdSense account information.', 'advanced-ads' ), |
| 189 | 'notAuthorized' => __( 'Unknown error while submitting the authorization code.', 'advanced-ads' ), |
| 190 | ], |
| 191 | 'stepHeading' => __( 'Do you have a Google AdSense account?', 'advanced-ads' ), |
| 192 | 'btnSignup' => __( 'No, I’d like to sign up for free now', 'advanced-ads' ), |
| 193 | 'btnConnect' => __( 'Yes, connect to AdSense now', 'advanced-ads' ), |
| 194 | 'labelAccount' => __( 'Account holder name:', 'advanced-ads' ), |
| 195 | 'labelConnected' => __( 'You are connected to Google AdSense. Publisher ID:', 'advanced-ads' ), |
| 196 | 'labelAdsPlacement' => __( 'Will you place ad units manually or use Google Auto Ads?', 'advanced-ads' ), |
| 197 | 'labelAutoAds' => __( 'Please confirm these Auto Ads options', 'advanced-ads' ), |
| 198 | 'footerProcessText' => __( 'Process', 'advanced-ads' ), |
| 199 | 'footerEnableText' => [ |
| 200 | 'manual' => __( 'Create placement and ad', 'advanced-ads' ), |
| 201 | 'autoAds' => __( 'Confirm Auto Ads options', 'advanced-ads' ), |
| 202 | ], |
| 203 | 'footerDisableText' => __( 'Please select an option', 'advanced-ads' ), |
| 204 | ], |
| 205 | 'congrats' => [ |
| 206 | 'adsenseManual' => [ |
| 207 | 'stepHeading' => __( "For the last step, import the desired ad unit from AdSense. Visit the ad's edit screen to make your selection.", 'advanced-ads' ), |
| 208 | 'btnEditItem' => __( 'Select ad unit', 'advanced-ads' ), |
| 209 | 'liveHeading' => sprintf( |
| 210 | /* translators: 1: opening strong tag, 2: closing strong tag, 3: opening italic tag, 4: closing italic tag. */ |
| 211 | esc_html__( 'We have created a placement for your ad that will display %1$safter the 3rd paragraph on every post%2$s. Go to %3$sAdvanced Ads > Placements%4$s and edit the placement to change this.', 'advanced-ads' ), |
| 212 | '<strong>', |
| 213 | '</strong>', |
| 214 | '<i>', |
| 215 | '</i>' |
| 216 | ), |
| 217 | ], |
| 218 | 'adsenseAuto' => [ |
| 219 | 'stepHeading' => __( "Everything's ready for AdSense to populate your site with Auto Ads. Make sure your site is verified, <strong>enable Auto Ads in your AdSense account</strong>, and, optionally, fine-tune their settings further.", 'advanced-ads' ), |
| 220 | 'btnAccount' => __( 'Go to AdSense account', 'advanced-ads' ), |
| 221 | ], |
| 222 | 'stepHeading' => __( 'We have created a placement for your ad that will display <strong>after the 3rd paragraph on every post</strong>. You may edit the placement to change this.', 'advanced-ads' ), |
| 223 | 'liveHeading' => __( 'See the live ad in your website\'s frontend.', 'advanced-ads' ), |
| 224 | 'btnEditItem' => __( 'Edit the placement', 'advanced-ads' ), |
| 225 | 'btnLiveAd' => __( 'See the live ad', 'advanced-ads' ), |
| 226 | 'upgradeHeading' => __( 'Upgrade to all features and full support today', 'advanced-ads' ), |
| 227 | 'upgradeText' => __( 'Our All Access deal offers every drop of ad expertise that we\'ve acquired in more than ten years, distilled into one jam-packed plugin bundle, supported by a dedicated team of real persons eager to help you.', 'advanced-ads' ), |
| 228 | 'btnUpgrade' => __( 'Upgrade now', 'advanced-ads' ), |
| 229 | 'btnDashboard' => __( 'Go to the Dashboard', 'advanced-ads' ), |
| 230 | 'upgradePoints' => [ |
| 231 | [ |
| 232 | 'title' => __( 'More placements', 'advanced-ads' ), |
| 233 | 'text' => __( 'to embed in high-converting spots', 'advanced-ads' ), |
| 234 | 'icon' => true, |
| 235 | ], |
| 236 | [ |
| 237 | 'title' => __( 'More conditions', 'advanced-ads' ), |
| 238 | 'text' => __( 'for advanced targeting', 'advanced-ads' ), |
| 239 | 'icon' => true, |
| 240 | ], |
| 241 | [ |
| 242 | 'title' => __( 'Ad Tracking', 'advanced-ads' ), |
| 243 | 'text' => __( 'to optimize performance', 'advanced-ads' ), |
| 244 | 'icon' => true, |
| 245 | ], |
| 246 | [ |
| 247 | 'title' => __( 'Click Fraud Protection', 'advanced-ads' ), |
| 248 | 'text' => __( 'to safeguard your accounts', 'advanced-ads' ), |
| 249 | 'icon' => true, |
| 250 | ], |
| 251 | [ |
| 252 | 'title' => __( 'Lazy Loading', 'advanced-ads' ), |
| 253 | 'text' => __( 'to speed up your website', 'advanced-ads' ), |
| 254 | 'icon' => true, |
| 255 | ], |
| 256 | [ |
| 257 | 'text' => '…' . __( 'and much more!', 'advanced-ads' ), |
| 258 | 'icon' => false, |
| 259 | ], |
| 260 | ], |
| 261 | ], |
| 262 | ], |
| 263 | ] |
| 264 | ); |
| 265 | } |
| 266 | } |
| 267 |