Filter uncanny-learndash-toolkit

uncanny_toolkit_flp_get_pages

Filters the list of pages available for selection in the Floating Plugin feature.

add_filter( 'uncanny_toolkit_flp_get_pages', $callback, 10, 1 );

Description

Filters the list of published pages retrieved by the Frontend Login Plus module. Developers can use this to modify the returned page array, perhaps to exclude specific pages or add custom data before the pages are displayed. The hook fires after the initial database query but before the pages are returned.


Usage

add_filter( 'uncanny_toolkit_flp_get_pages', 'your_function_name', 10, 1 );

Parameters

$pages (mixed)
This parameter contains an array of WordPress page objects retrieved from the database, which are then filtered to allow modification before being returned.

Return Value

The filtered value.


Examples

/**
 * Example of using the uncanny_toolkit_flp_get_pages filter to modify the list of pages.
 *
 * This example demonstrates how to:
 * - Filter the pages returned by the default get_pages() function.
 * - Exclude specific pages based on their ID.
 * - Add a custom attribute to the remaining pages.
 */
add_filter( 'uncanny_toolkit_flp_get_pages', 'my_custom_flp_pages', 10, 1 );

function my_custom_flp_pages( $pages ) {

    // Ensure we are working with an array of WP_Post objects.
    if ( ! is_array( $pages ) || empty( $pages ) ) {
        return $pages;
    }

    // Define an array of page IDs to exclude from the login redirect options.
    $excluded_page_ids = array( 123, 456 ); // Replace with actual page IDs

    // Iterate through the pages and filter them.
    $filtered_pages = array_filter( $pages, function( $page ) use ( $excluded_page_ids ) {
        // Return true to keep the page, false to remove it.
        return ! in_array( $page->ID, $excluded_page_ids );
    } );

    // Optionally, add a custom attribute to the remaining pages.
    // This could be used for additional logic in the frontend.
    foreach ( $filtered_pages as $page ) {
        $page->custom_login_redirect_attribute = 'allows_login_redirect';
    }

    // Re-index the array to ensure sequential keys after filtering.
    return array_values( $filtered_pages );
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/frontend-login-plus.php:744

public static function get_pages() {

		global $wpdb;

		$pages = $wpdb->get_results(
			$wpdb->prepare(
				"SELECT * FROM $wpdb->posts
					WHERE post_type = %s AND post_status = %s
					ORDER BY post_title ASC",
				'page',
				'publish'
			)
		);

		return apply_filters( 'uncanny_toolkit_flp_get_pages', $pages );

	}

Scroll to Top