How do you add a filter to wp-block-page-list?

I had a look at the wp-block-page-list block rendering callback and it doesn’t seem to provide any nice filters for this. The callback uses get_pages() for getting the list of pages, which means you can use get_pages_query_args and get_pages filter hooks to modify the pages query and the pages list. The difficult part here is to determine, when and where this filtering should happen – i.e. is the block in a sidebar or not.

One option to conditionally set the filter is to wrap the the default rendering callback in a helper function and handle the filtering logic in the helper. I haven’t tested this, but something along these lines should do the trick.

add_filter( 'block_type_metadata_settings', 'wpse_427144_filter_render_block_core_page_list', 10, 2 );
function wpse_427144_filter_render_block_core_page_list( array $settings, array $metadata ): array {
    if ( 'core/page-list' === $metadata['name'] ) {
        $settings['render_callback'] = 'wpse_427144_filtered_core_block_page_list_renderer';
    }

    return $settings;
}

function wpse_427144_filtered_core_block_page_list_renderer( array $attributes, string $content, WP_Block $block ): string {
    // use another helper function to determine, if the filtering should happen or not
    $should_filter_args = wpse_427144_should_filter_pages_query_args( $attributes, $content, $block );

    // add filtering for this case
    if ( $should_filter_args ) {
        add_filter( 'get_pages_query_args', 'wpse_427144_filtered_pages_query_args', 10, 2 );
    }

    // let the default rendering callback do its thing
    $block_html = render_block_core_page_list( $attributes, $content, $block );

    // remove filtering to prevent modifying later get_pages() calls, if any
    if ( $should_filter_args ) {
        remove_filter( 'get_pages_query_args', 'wpse_427144_filtered_pages_query_args', 10, 2 );
    }

    return $block_html;
}

function wpse_427144_should_filter_pages_query_args( array $attributes, string $content, WP_Block $block ): bool {

    $conditions_met = false;

    // if ( some logic here... ) {
    //     $conditions_met = true;
    // }

    return $conditions_met;
}

function wpse_427144_filtered_pages_query_args( array $query_args, array $parsed_args ): array {

    // modify $query_args as needed

    return $query_args;
}

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)