0 ) { self::ensure_page_has_list_block( $page_id ); } update_option( self::SEED_OPTION, 1 ); } /** * Insert the notifications list block when the page has no list yet. * * @param int $page_id Page ID. * @return bool True when content was updated. */ public static function ensure_page_has_list_block( $page_id ) { $page_id = (int) $page_id; if ( $page_id <= 0 ) { return false; } $post = get_post( $page_id ); if ( ! $post || 'page' !== $post->post_type ) { return false; } if ( self::page_has_list( $post ) ) { return false; } $block = ''; $content = trim( (string) $post->post_content ); $new_content = '' !== $content ? $content . "\n\n" . $block : $block; wp_update_post( array( 'ID' => $page_id, 'post_content' => $new_content, ) ); return true; } /** * @param WP_Post|null $post Post object. * @return bool */ public static function page_has_list( $post ) { if ( ! $post instanceof WP_Post ) { return false; } if ( has_block( 'forwp/notifications', $post ) ) { return true; } $content = (string) $post->post_content; return has_shortcode( $content, 'forwp_notifications' ) || has_shortcode( $content, '4wp_notifications' ); } }