0 ) { self::ensure_page_has_tasks_block( $page_id ); } update_option( self::SEED_OPTION, 1, false ); } /** * Insert the tasks 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_tasks_block( int $page_id ): bool { $page_id = absint( $page_id ); if ( $page_id <= 0 ) { return false; } $post = get_post( $page_id ); if ( ! $post instanceof \WP_Post || 'page' !== $post->post_type ) { return false; } if ( self::page_has_tasks_block( $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_tasks_block( $post ): bool { if ( ! $post instanceof \WP_Post ) { return false; } return has_block( self::BLOCK_NAME, $post ); } }