← All changes
|
modules/comments/subscription-modal-on-comment/class-jetpack-subscription-modal-on-comment.php
+21
-3
13.5.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. |
| @@ -173,8 +186,13 @@ | ||
| 173 | 186 | } |
| 174 | 187 | |
| 175 | 188 | // Don't show if post is for subscribers only or has paywall block |
| 176 | 189 | global $post; |
| 190 | + | |
| 191 | + if ( ! $post instanceof WP_Post ) { | |
| 192 | + return false; | |
| 193 | + } | |
| 194 | + | |
| 177 | 195 | if ( defined( 'Automattic\\Jetpack\\Extensions\\Subscriptions\\META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS' ) ) { |
| 178 | 196 | $access_level = get_post_meta( $post->ID, META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS, true ); |
| 179 | 197 | } else { |
| 180 | 198 | $access_level = get_post_meta( $post->ID, '_jetpack_newsletter_access', true ); |