Filter uncanny-automator

automator_select_all_pages_limit

Filters the maximum number of pages that can be selected for the automator.

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

Description

Filters the maximum number of pages retrieved by Uncanny Automator for selection. Developers can use this to override the default limit of 999, allowing for retrieval of more or fewer pages. The second parameter specifies the post type, defaulting to 'page'.


Usage

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

Return Value

The filtered value.


Examples

<?php
/**
 * Example of filtering the 'automator_select_all_pages_limit' hook
 * to reduce the number of pages returned when selecting a page.
 *
 * In a real-world scenario, you might want to limit the number of
 * pages to improve performance on sites with a very large number of pages.
 *
 * @param int    $limit The current limit for posts per page.
 * @param string $post_type The post type being queried.
 * @return int The modified limit.
 */
function my_custom_automator_page_limit( $limit, $post_type ) {
	// Only apply this limit to the 'page' post type.
	if ( 'page' === $post_type ) {
		// Let's say we want to limit it to a maximum of 50 pages.
		// We'll also ensure it doesn't go below a reasonable minimum,
		// though in this case, the default is 999, so we are only ever reducing it.
		$new_limit = 50;
		return $new_limit;
	}

	// If it's not a 'page', return the original limit.
	return $limit;
}

// Add the filter to WordPress. The third parameter '2' indicates that our callback function
// accepts two arguments ($limit and $post_type).
add_filter( 'automator_select_all_pages_limit', 'my_custom_automator_page_limit', 10, 2 );
?>

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/integrations/wp/helpers/wp-helpers.php:219

public function all_pages( $label = null, $option_code = 'WPPAGE', $any_option = true ) {

		if ( ! $label ) {
			$label = esc_attr_x( 'Page', 'WordPress', 'uncanny-automator' );
		}

		$args = array(
			// phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page
			'posts_per_page' => apply_filters( 'automator_select_all_pages_limit', 999, 'page' ),
			'orderby'        => 'title',
			'order'          => 'ASC',
			'post_type'      => 'page',
			'post_status'    => 'publish',
		);

		$all_pages = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr_x( 'Any page', 'WordPress', 'uncanny-automator' ) );

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'options'         => $all_pages,
			'relevant_tokens' => array(
				$option_code                         => esc_attr_x( 'Page title', 'WordPress', 'uncanny-automator' ),
				$option_code . '_ID'                 => esc_attr_x( 'Page ID', 'WordPress', 'uncanny-automator' ),
				$option_code . '_URL'                => esc_attr_x( 'Page URL', 'WordPress', 'uncanny-automator' ),
				$option_code . '_POSTNAME'           => esc_attr_x( 'Page slug', 'WordPress', 'uncanny-automator' ),
				$option_code . '_EXCERPT'            => esc_attr_x( 'Page excerpt', 'WordPress', 'uncanny-automator' ),
				$option_code . '_CONTENT'            => esc_attr_x( 'Page content (raw)', 'WordPress', 'uncanny-automator' ),
				$option_code . '_CONTENT_BEAUTIFIED' => esc_attr_x( 'Page content (formatted)', 'WordPress', 'uncanny-automator' ),
				$option_code . '_THUMB_ID'           => esc_attr_x( 'Page featured image ID', 'WordPress', 'uncanny-automator' ),
				$option_code . '_THUMB_URL'          => esc_attr_x( 'Page featured image URL', 'WordPress', 'uncanny-automator' ),
				'POSTAUTHORFN'                       => esc_attr_x( 'Page author first name', 'WordPress', 'uncanny-automator' ),
				'POSTAUTHORLN'                       => esc_attr_x( 'Page author last name', 'WordPress', 'uncanny-automator' ),
				'POSTAUTHORDN'                       => esc_attr_x( 'Page author display name', 'WordPress', 'uncanny-automator' ),
				'POSTAUTHOREMAIL'                    => esc_attr_x( 'Page author email', 'WordPress', 'uncanny-automator' ),
				'POSTAUTHORURL'                      => esc_attr_x( 'Page author URL', 'WordPress', 'uncanny-automator' ),
			),
		);

		return apply_filters( 'uap_option_all_pages', $option );
	}


Scroll to Top