← All changes
|
modules/comments/subscription-modal-on-comment/class-jetpack-subscription-modal-on-comment.php
+32
-38
13.0.2
→
16.3-beta
View file →
| @@ -10,8 +10,12 @@ | ||
| 10 | 10 | use Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service\Abstract_Token_Subscription_Service; |
| 11 | 11 | use Automattic\Jetpack\Status\Host; |
| 12 | 12 | use const Automattic\Jetpack\Extensions\Subscriptions\META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS; |
| 13 | 13 | |
| 14 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 15 | + exit( 0 ); | |
| 16 | +} | |
| 17 | + | |
| 14 | 18 | /** |
| 15 | 19 | * Jetpack_Subscription_Modal_On_Comment class. |
| 16 | 20 | */ |
| 17 | 21 | class Jetpack_Subscription_Modal_On_Comment { |
| @@ -61,12 +65,21 @@ | ||
| 61 | 65 | * |
| 62 | 66 | * @return void |
| 63 | 67 | */ |
| 64 | 68 | public function enqueue_assets() { |
| 65 | - if ( $this->should_user_see_modal() ) { | |
| 66 | - wp_enqueue_style( 'subscription-modal-css', plugins_url( 'subscription-modal.css', __FILE__ ), array(), JETPACK__VERSION ); | |
| 67 | - wp_enqueue_script( 'subscription-modal-js', plugins_url( 'subscription-modal.js', __FILE__ ), array( 'wp-dom-ready' ), JETPACK__VERSION, true ); | |
| 69 | + if ( ! $this->should_user_see_modal() ) { | |
| 70 | + return; | |
| 68 | 71 | } |
| 72 | + | |
| 73 | + wp_enqueue_style( 'subscription-modal-css', plugins_url( 'subscription-modal.css', __FILE__ ), array(), JETPACK__VERSION ); | |
| 74 | + wp_enqueue_script( 'subscription-modal-js', plugins_url( 'subscription-modal.js', __FILE__ ), array( 'wp-dom-ready' ), JETPACK__VERSION, true ); | |
| 75 | + wp_localize_script( | |
| 76 | + 'subscription-modal-js', | |
| 77 | + 'subscriptionData', | |
| 78 | + array( | |
| 79 | + 'homeUrl' => wp_parse_url( home_url(), PHP_URL_HOST ), | |
| 80 | + ) | |
| 81 | + ); | |
| 69 | 82 | } |
| 70 | 83 | |
| 71 | 84 | /** |
| 72 | 85 | * Adds modal with Subscribe Modal content. |
| @@ -120,9 +133,9 @@ | ||
| 120 | 133 | $template->title = __( 'Jetpack Subscription modal', 'jetpack' ); |
| 121 | 134 | $template->status = 'publish'; |
| 122 | 135 | $template->has_theme_file = false; |
| 123 | 136 | $template->is_custom = true; |
| 124 | - $template->description = __( 'A subscribe form that submit a comment', 'jetpack' ); | |
| 137 | + $template->description = __( 'A subscribe form that submit a comment.', 'jetpack' ); | |
| 125 | 138 | |
| 126 | 139 | return $template; |
| 127 | 140 | } |
| 128 | 141 | |
| @@ -132,31 +145,17 @@ | ||
| 132 | 145 | * |
| 133 | 146 | * @return string |
| 134 | 147 | */ |
| 135 | 148 | public function get_subscribe_template_content() { |
| 136 | - $discover_more_from = __( 'Never miss a beat!', 'default' ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch | |
| 137 | - $subscribe_text = __( 'Interested in getting blog post updates? Simply click the button below to stay in the loop!', 'default' ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch | |
| 138 | - $subscribe_button = __( 'Subscribe', 'default' ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch | |
| 149 | + // translators: %s is the name of the site. | |
| 150 | + $discover_more_from = sprintf( __( 'Discover more from %s', 'jetpack' ), get_bloginfo( 'name' ) ); | |
| 151 | + $subscribe_text = __( 'Subscribe now to keep reading and get access to the full archive.', 'jetpack' ); | |
| 152 | + $continue_reading = __( 'Continue reading', 'jetpack' ); | |
| 139 | 153 | |
| 140 | 154 | return <<<HTML |
| 141 | - <!-- wp:group --> | |
| 142 | - <div class="jetpack-subscription-modal__iframe-container"> | |
| 143 | - <iframe | |
| 144 | - class="jetpack-subscription-modal__iframe" | |
| 145 | - frameBorder="0" | |
| 146 | - allowTransparency="1" | |
| 147 | - src="about:blank" | |
| 148 | - id="jetpack-subscription-modal__iframe" | |
| 149 | - ></iframe> | |
| 150 | - </div> | |
| 151 | - <!-- /wp:group --> | |
| 152 | 155 | <!-- wp:group {"style":{"spacing":{"top":"32px","bottom":"32px","left":"32px","right":"32px"},"margin":{"top":"0","bottom":"0"}},"border":{"color":"#dddddd","width":"1px"}},"layout":{"type":"constrained","contentSize":"450px"}} --> |
| 153 | - <div class="wp-block-group has-border-color jetpack-subscription-modal__modal-content-form" style="border-color:#dddddd;border-width:1px;margin-top:0;margin-bottom:0;padding-top:0;padding-right:32px;padding-bottom:32px;padding-left:32px"> | |
| 156 | + <div class="wp-block-group has-border-color jetpack-subscription-modal__modal-content-form" style="border-color:#dddddd;border-width:1px;margin-top:0;margin-bottom:0;padding:32px"> | |
| 154 | 157 | |
| 155 | - <!-- wp:paragraph {"align":"right","style":{"spacing":{"margin":{"top":"0"}},"typography":{"fontSize":"14px"}},"className":"jetpack-subscription-modal__close"} --> | |
| 156 | - <p class="has-text-align-center jetpack-subscription-modal__close" style="margin-top:20px;font-size:14px;text-align:right"><a href="#"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" width="24" height="24" focusable="false"><path d="M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"></path></svg></a></p> | |
| 157 | - <!-- /wp:paragraph --> | |
| 158 | - | |
| 159 | 158 | <!-- wp:heading {"textAlign":"center","style":{"typography":{"fontStyle":"normal","fontWeight":"600","fontSize":"26px"},"layout":{"selfStretch":"fit","flexSize":null},"spacing":{"margin":{"top":"4px","bottom":"10px"}}}} --> |
| 160 | 159 | <h2 class="wp-block-heading has-text-align-center" style="margin-top:4px;margin-bottom:10px;font-size:26px;font-style:normal;font-weight:600">$discover_more_from</h2> |
| 161 | 160 | <!-- /wp:heading --> |
| 162 | 161 | |
| @@ -163,23 +162,13 @@ | ||
| 163 | 162 | <!-- wp:paragraph {"align":"center","style":{"typography":{"fontSize":"15px"},"spacing":{"margin":{"top":"4px","bottom":"0px"}}}} --> |
| 164 | 163 | <p class='has-text-align-center' style='margin-top:4px;margin-bottom:0px;font-size:15px'>$subscribe_text</p> |
| 165 | 164 | <!-- /wp:paragraph --> |
| 166 | 165 | |
| 167 | - <!-- wp:group {"style":{"spacing":{"top":"32px","bottom":"32px","left":"32px","right":"32px"},"margin":{"top":"0","bottom":"0"}},"border":{"color":"#dddddd","width":"1px"}},"layout":{"type":"constrained","contentSize":"450px"}} --> | |
| 168 | - <form class="jetpack-subscription-modal__form"> | |
| 169 | - <input | |
| 170 | - class="jetpack-subscription-modal__form-email" | |
| 171 | - required="required" | |
| 172 | - type="email" | |
| 173 | - name="email" | |
| 174 | - style="border-width: 1px !important;" | |
| 175 | - /> | |
| 176 | - <button | |
| 177 | - class="jetpack-subscription-modal__form-submit" | |
| 178 | - type="submit" | |
| 179 | - name="jetpack_subscriptions_widget" >$subscribe_button</button> | |
| 180 | - </form> | |
| 181 | - <!-- /wp:group --> | |
| 166 | + <!-- wp:jetpack/subscriptions {"borderRadius":50,"className":"is-style-compact","appSource":"atomic-subscription-modal-lo"} /--> | |
| 167 | + | |
| 168 | + <!-- wp:paragraph {"align":"center","style":{"spacing":{"margin":{"top":"20px"}},"typography":{"fontSize":"14px"}},"className":"jetpack-subscription-modal__close"} --> | |
| 169 | + <p class="has-text-align-center jetpack-subscription-modal__close" style="margin-top:20px;font-size:14px"><a href="#">$continue_reading</a></p> | |
| 170 | + <!-- /wp:paragraph --> | |
| 182 | 171 | </div> |
| 183 | 172 | <!-- /wp:group --> |
| 184 | 173 | HTML; |
| 185 | 174 | } |
| @@ -197,8 +186,13 @@ | ||
| 197 | 186 | } |
| 198 | 187 | |
| 199 | 188 | // Don't show if post is for subscribers only or has paywall block |
| 200 | 189 | global $post; |
| 190 | + | |
| 191 | + if ( ! $post instanceof WP_Post ) { | |
| 192 | + return false; | |
| 193 | + } | |
| 194 | + | |
| 201 | 195 | if ( defined( 'Automattic\\Jetpack\\Extensions\\Subscriptions\\META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS' ) ) { |
| 202 | 196 | $access_level = get_post_meta( $post->ID, META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS, true ); |
| 203 | 197 | } else { |
| 204 | 198 | $access_level = get_post_meta( $post->ID, '_jetpack_newsletter_access', true ); |