is_woa_site() && get_option( 'jetpack_verbum_subscription_modal', true ) ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) );
add_action( 'wp_footer', array( $this, 'add_subscription_modal_to_frontend' ) );
add_filter( 'get_block_template', array( $this, 'get_block_template_filter' ), 10, 3 );
}
}
/**
* Enqueues JS to load modal.
*
* @return void
*/
public function enqueue_assets() {
if ( ! $this->should_user_see_modal() ) {
return;
}
wp_enqueue_style( 'subscription-modal-css', plugins_url( 'subscription-modal.css', __FILE__ ), array(), JETPACK__VERSION );
wp_enqueue_script( 'subscription-modal-js', plugins_url( 'subscription-modal.js', __FILE__ ), array( 'wp-dom-ready' ), JETPACK__VERSION, true );
wp_localize_script(
'subscription-modal-js',
'subscriptionData',
array(
'homeUrl' => wp_parse_url( home_url(), PHP_URL_HOST ),
)
);
}
/**
* Adds modal with Subscribe Modal content.
*
* @return void
*/
public function add_subscription_modal_to_frontend() {
if ( $this->should_user_see_modal() ) { ?>
get_template();
}
}
return $block_template;
}
/**
* Returns a custom template for the Subscribe Modal.
*
* @return WP_Block_Template
*/
public function get_template() {
$template = new WP_Block_Template();
$template->theme = get_stylesheet();
$template->slug = self::BLOCK_TEMPLATE_PART_SLUG;
$template->id = self::get_block_template_part_id();
$template->area = 'uncategorized';
$template->content = $this->get_subscribe_template_content();
$template->source = 'plugin';
$template->type = 'wp_template_part';
$template->title = __( 'Jetpack Subscription modal', 'jetpack' );
$template->status = 'publish';
$template->has_theme_file = false;
$template->is_custom = true;
$template->description = __( 'A subscribe form that submit a comment.', 'jetpack' );
return $template;
}
/**
* Returns the initial content of the Subscribe Modal template.
* This can then be edited by the user.
*
* @return string
*/
public function get_subscribe_template_content() {
// translators: %s is the name of the site.
$discover_more_from = sprintf( __( 'Discover more from %s', 'jetpack' ), get_bloginfo( 'name' ) );
$subscribe_text = __( 'Subscribe now to keep reading and get access to the full archive.', 'jetpack' );
$continue_reading = __( 'Continue reading', 'jetpack' );
return <<
HTML;
}
/**
* Returns true if a site visitor should see
* the Subscribe Modal.
*
* @return bool
*/
public function should_user_see_modal() {
// Only show when viewing frontend single post.
if ( is_admin() || ! is_singular( 'post' ) ) {
return false;
}
// Don't show if post is for subscribers only or has paywall block
global $post;
if ( defined( 'Automattic\\Jetpack\\Extensions\\Subscriptions\\META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS' ) ) {
$access_level = get_post_meta( $post->ID, META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS, true );
} else {
$access_level = get_post_meta( $post->ID, '_jetpack_newsletter_access', true );
}
require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/premium-content/_inc/subscription-service/include.php';
$is_accessible_by_everyone = Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_EVERYBODY === $access_level || empty( $access_level );
if ( ! $is_accessible_by_everyone ) {
return false;
}
return true;
}
}
Jetpack_Subscription_Modal_On_Comment::init();
add_action(
'rest_api_switched_to_blog',
function () {
Jetpack_Subscription_Modal_On_Comment::init();
}
);