Redirection::get_meta_fields()

Returns the available meta fields for the submodule.

Description

See also

Return

(array) Associative array of <code>$field_slug => $field_args</code> pairs.

Source

File: src/modules/actions/redirection.php

	public function get_meta_fields() {
		$meta_fields = $this->_get_meta_fields();

		unset( $meta_fields['enabled'] );

		$meta_fields['type'] = array(
			'type'         => 'select',
			'label'        => __( 'Redirect Type', 'torro-forms' ),
			'description'  => __( 'Select to which type of content to redirect the user.', 'torro-forms' ),
			'choices'      => array(
				'redirect_none' => __( 'No Redirection', 'torro-forms' ),
				'redirect_page' => __( 'Page Redirection', 'torro-forms' ),
				'redirect_url'  => __( 'URL Redirection', 'torro-forms' ),
			),
			'wrap_classes' => array( 'has-torro-tooltip-description' ),
		);

		$page_count = (int) wp_count_posts( 'page' )->publish;
		if ( $page_count > 15 ) {
			$meta_fields['page'] = array(
				'type'          => 'autocomplete',
				'label'         => __( 'Redirect Page', 'torro-forms' ),
				'description'   => __( 'Specify the page to redirect to.', 'torro-forms' ),
				'input_classes' => array( 'regular-text' ),
				'wrap_classes'  => array( 'has-torro-tooltip-description' ),
				'autocomplete'  => array(
					'rest_placeholder_search_route' => 'wp/v2/pages?search=%search%',
					'rest_placeholder_label_route'  => 'wp/v2/pages/%value%',
					'value_generator'               => '%id%',
					'label_generator'               => '%title.rendered%',
				),
			);
		} else {
			$pages = get_posts( array(
				'posts_per_page' => 15,
				'post_type'      => 'page',
				'post_status'    => 'publish',
			) );

			$page_choices = array();
			foreach ( $pages as $page ) {
				$page_choices[ $page->ID ] = get_the_title( $page->ID );
			}

			$meta_fields['page'] = array(
				'type'         => 'select',
				'label'        => __( 'Redirect Page', 'torro-forms' ),
				'description'  => __( 'Specify the page to redirect to.', 'torro-forms' ),
				'choices'      => $page_choices,
				'wrap_classes' => array( 'has-torro-tooltip-description' ),
			);
		}

		$meta_fields['page']['dependencies'] = array(
			array(
				'prop'     => 'display',
				'callback' => 'get_data_by_map',
				'fields'   => array( 'type' ),
				'args'     => array(
					'map' => array(
						'redirect_none' => false,
						'redirect_page' => true,
						'redirect_url'  => false,
					),
				),
			),
		);

		$meta_fields['url'] = array(
			'type'          => 'url',
			'label'         => __( 'Redirect URL', 'torro-forms' ),
			'description'   => __( 'Enter the URL to redirect to.', 'torro-forms' ),
			'placeholder'   => 'https://',
			'input_classes' => array( 'regular-text' ),
			'wrap_classes'  => array( 'has-torro-tooltip-description' ),
			'dependencies'  => array(
				array(
					'prop'     => 'display',
					'callback' => 'get_data_by_map',
					'fields'   => array( 'type' ),
					'args'     => array(
						'map' => array(
							'redirect_none' => false,
							'redirect_page' => false,
							'redirect_url'  => true,
						),
					),
				),
			),
		);

		return $meta_fields;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.