handle_subscribe_block_post_end_placement(); } /** * Returns true if current user can view the post. * * @return bool */ protected function user_can_view_post() { if ( ! class_exists( 'Jetpack_Memberships' ) ) { return true; } return Jetpack_Memberships::user_can_view_post(); } /** * Returns post end placement hooked block attributes. * * @param array $default_attrs Deafult attributes. * @param array $anchor_block The anchor block, in parsed block array format. * * @return array */ protected function get_post_end_placement_block_attributes( $default_attrs, $anchor_block ) { if ( ! empty( $anchor_block['attrs']['layout']['type'] ) ) { return array_merge( $default_attrs, array( 'layout' => array( 'type' => $anchor_block['attrs']['layout']['type'], ), ) ); } if ( ! empty( $anchor_block['attrs']['layout']['inherit'] ) ) { return array_merge( $default_attrs, array( 'layout' => array( 'inherit' => $anchor_block['attrs']['layout']['inherit'], ), ) ); } return $default_attrs; } /** * Handles Subscribe block placement at the end of each post. * * @return void */ protected function handle_subscribe_block_post_end_placement() { global $wp_version; $subscribe_post_end_enabled = get_option( 'jetpack_subscriptions_subscribe_post_end_enabled', false ); if ( ! $subscribe_post_end_enabled ) { return; } if ( ! wp_is_block_theme() || version_compare( $wp_version, '6.5-beta2', '<' ) ) { // Fallback for classic themes and wp core < 6.5-beta2. add_filter( 'the_content', function ( $content ) { // Check if we're inside the main loop in a single Post. if ( is_singular() && in_the_loop() && is_main_query() && $this->user_can_view_post() ) { // translators: %s is the name of the site. $discover_more_from_text = sprintf( __( 'Discover more from %s', 'jetpack' ), get_bloginfo( 'name' ) ); $subscribe_text = __( 'Subscribe to get the latest posts to your email.', 'jetpack' ); return $content . do_blocks( <<
$subscribe_text
$subscribe_text