← All changes
|
modules/subscriptions/subscribe-modal/class-jetpack-subscribe-modal.php
+51
-6
13.1.5
→
16.3-a.7
View file →
| @@ -61,8 +61,49 @@ | ||
| 61 | 61 | public function enqueue_assets() { |
| 62 | 62 | if ( $this->should_user_see_modal() ) { |
| 63 | 63 | wp_enqueue_style( 'subscribe-modal-css', plugins_url( 'subscribe-modal.css', __FILE__ ), array(), JETPACK__VERSION ); |
| 64 | 64 | wp_enqueue_script( 'subscribe-modal-js', plugins_url( 'subscribe-modal.js', __FILE__ ), array( 'wp-dom-ready' ), JETPACK__VERSION, true ); |
| 65 | + | |
| 66 | + /** | |
| 67 | + * Filter how many milliseconds until the Subscribe Modal appears. | |
| 68 | + * | |
| 69 | + * @module subscriptions | |
| 70 | + * | |
| 71 | + * @since 13.4 | |
| 72 | + * | |
| 73 | + * @param int 60000 Time in milliseconds for the Subscribe Modal to appear. | |
| 74 | + */ | |
| 75 | + $load_time = absint( apply_filters( 'jetpack_subscribe_modal_load_time', 60000 ) ); | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Filter how many percentage of the page should be scrolled before the Subscribe Modal appears. | |
| 79 | + * | |
| 80 | + * @module subscriptions | |
| 81 | + * | |
| 82 | + * @since 13.6 | |
| 83 | + * | |
| 84 | + * @param int Percentage of the page scrolled before the Subscribe Modal appears. | |
| 85 | + */ | |
| 86 | + $scroll_threshold = absint( apply_filters( 'jetpack_subscribe_modal_scroll_threshold', 50 ) ); | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * Filter to control the interval at which the subscribe modal is shown to the same user. The default interval is 24 hours. | |
| 90 | + * | |
| 91 | + * @since 13.7 | |
| 92 | + * | |
| 93 | + * @param int 24 Hours before we show the same user the Subscribe Modal to again. | |
| 94 | + */ | |
| 95 | + $modal_interval = absint( apply_filters( 'jetpack_subscribe_modal_interval', 24 ) ); | |
| 96 | + | |
| 97 | + wp_localize_script( | |
| 98 | + 'subscribe-modal-js', | |
| 99 | + 'Jetpack_Subscriptions', | |
| 100 | + array( | |
| 101 | + 'modalLoadTime' => $load_time, | |
| 102 | + 'modalScrollThreshold' => $scroll_threshold, | |
| 103 | + 'modalInterval' => ( $modal_interval * HOUR_IN_SECONDS * 1000 ), | |
| 104 | + ) | |
| 105 | + ); | |
| 65 | 106 | } |
| 66 | 107 | } |
| 67 | 108 | |
| 68 | 109 | /** |
| @@ -117,9 +158,9 @@ | ||
| 117 | 158 | $template->title = __( 'Jetpack Subscribe modal', 'jetpack' ); |
| 118 | 159 | $template->status = 'publish'; |
| 119 | 160 | $template->has_theme_file = false; |
| 120 | 161 | $template->is_custom = true; |
| 121 | - $template->description = __( 'A subscribe form that pops up when someone visits your site', 'jetpack' ); | |
| 162 | + $template->description = __( 'A subscribe form that pops up when someone visits your site.', 'jetpack' ); | |
| 122 | 163 | |
| 123 | 164 | return $template; |
| 124 | 165 | } |
| 125 | 166 | |
| @@ -133,11 +174,12 @@ | ||
| 133 | 174 | // translators: %s is the name of the site. |
| 134 | 175 | $discover_more_from = sprintf( __( 'Discover more from %s', 'jetpack' ), get_bloginfo( 'name' ) ); |
| 135 | 176 | $continue_reading = __( 'Continue reading', 'jetpack' ); |
| 136 | 177 | $subscribe_text = __( 'Subscribe now to keep reading and get access to the full archive.', 'jetpack' ); |
| 178 | + $group_block_name = esc_attr__( 'Subscription pop-up container', 'jetpack' ); | |
| 137 | 179 | |
| 138 | 180 | return <<<HTML |
| 139 | - <!-- 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"}} --> | |
| 181 | + <!-- wp:group {"metadata":{"name":"$group_block_name"},"style":{"spacing":{"padding":{"top":"32px","bottom":"32px","left":"32px","right":"32px"},"margin":{"top":"0","bottom":"0"}},"border":{"color":"#dddddd","width":"1px"}},"layout":{"type":"constrained","contentSize":"450px"}} --> | |
| 140 | 182 | <div class="wp-block-group has-border-color" style="border-color:#dddddd;border-width:1px;margin-top:0;margin-bottom:0;padding-top:32px;padding-right:32px;padding-bottom:32px;padding-left:32px"> |
| 141 | 183 | |
| 142 | 184 | <!-- wp:heading {"textAlign":"center","style":{"typography":{"fontStyle":"normal","fontWeight":"600","fontSize":"26px"},"layout":{"selfStretch":"fit","flexSize":null},"spacing":{"margin":{"top":"4px","bottom":"10px"}}}} --> |
| 143 | 185 | <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> |
| @@ -143,15 +185,15 @@ | ||
| 143 | 185 | <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> |
| 144 | 186 | <!-- /wp:heading --> |
| 145 | 187 | |
| 146 | 188 | <!-- wp:paragraph {"align":"center","style":{"typography":{"fontSize":"15px"},"spacing":{"margin":{"top":"4px","bottom":"0px"}}}} --> |
| 147 | - <p class='has-text-align-center' style='margin-top:4px;margin-bottom:0px;font-size:15px'>$subscribe_text</p> | |
| 189 | + <p class='has-text-align-center' style='margin-top:4px;margin-bottom:1em;font-size:15px'>$subscribe_text</p> | |
| 148 | 190 | <!-- /wp:paragraph --> |
| 149 | 191 | |
| 150 | - <!-- wp:jetpack/subscriptions {"borderRadius":50,"className":"is-style-compact"} /--> | |
| 192 | + <!-- wp:jetpack/subscriptions {"borderRadius":50,"className":"is-style-compact","appSource":"subscribe-modal"} /--> | |
| 151 | 193 | |
| 152 | 194 | <!-- wp:paragraph {"align":"center","style":{"spacing":{"margin":{"top":"20px"}},"typography":{"fontSize":"14px"}},"className":"jetpack-subscribe-modal__close"} --> |
| 153 | - <p class="has-text-align-center jetpack-subscribe-modal__close" style="margin-top:20px;font-size:14px"><a href="#">$continue_reading</a></p> | |
| 195 | + <p class="has-text-align-center jetpack-subscribe-modal__close" style="margin-top:20px;margin-bottom:0;font-size:14px"><a href="#">$continue_reading</a></p> | |
| 154 | 196 | <!-- /wp:paragraph --> |
| 155 | 197 | </div> |
| 156 | 198 | <!-- /wp:group --> |
| 157 | 199 | HTML; |
| @@ -190,10 +232,13 @@ | ||
| 190 | 232 | if ( isset( $_GET['subscribe'] ) || isset( $_GET['blogsub'] ) ) { |
| 191 | 233 | return false; |
| 192 | 234 | } |
| 193 | 235 | |
| 194 | - // Don't show if post is for subscribers only or has paywall block | |
| 236 | + // Don't show if post is not a post, is for subscribers only, or has paywall block | |
| 195 | 237 | global $post; |
| 238 | + if ( ! $post instanceof WP_Post ) { | |
| 239 | + return false; | |
| 240 | + } | |
| 196 | 241 | if ( defined( 'Automattic\\Jetpack\\Extensions\\Subscriptions\\META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS' ) ) { |
| 197 | 242 | $access_level = get_post_meta( $post->ID, META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS, true ); |
| 198 | 243 | } else { |
| 199 | 244 | $access_level = get_post_meta( $post->ID, '_jetpack_newsletter_access', true ); |