LLMS_REST_Memberships_Controller::prepare_item_for_database( WP_REST_Request $request )

Prepares a single post for create or update.


Parameters Parameters

$request

(WP_REST_Request) (Required) Request object.


Top ↑

Return Return

(array|WP_Error) Array of llms post args or WP_Error.


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/server/class-llms-rest-memberships-controller.php

	 *
	 * @param object $taxonomy The taxonomy object.
	 * @return string The taxonomy rest base.
	 */
	protected function get_taxonomy_rest_base( $taxonomy ) {
		$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;

		$taxonomy_base_map = array(
			'membership_cat' => 'categories',
			'membership_tag' => 'tags',
		);

		return isset( $taxonomy_base_map[ $base ] ) ? $taxonomy_base_map[ $base ] : $base;
	}

	/**
	 * Prepares a single post for create or update.
	 *
	 * @since 1.0.0-beta.9
	 *
	 * @param WP_REST_Request $request Request object.
	 * @return array|WP_Error Array of llms post args or WP_Error.
	 */
	protected function prepare_item_for_database( $request ) {
		$prepared_item = parent::prepare_item_for_database( $request );
		$schema        = $this->get_item_schema();

		// Restriction action.
		if ( ! empty( $schema['properties']['restriction_action'] ) && isset( $request['restriction_action'] ) ) {
			$prepared_item['restriction_redirect_type'] = $request['restriction_action'];
		}

		// Restriction page id.
		if ( ! empty( $schema['properties']['restriction_page_id'] ) && isset( $request['restriction_page_id'] ) ) {
			$page = get_post( $request['restriction_page_id'] );
			if ( $page && is_a( $page, 'WP_Post' ) ) {
				$prepared_item['redirect_page_id'] = $request['restriction_page_id'];
			} else {
				$prepared_item['redirect_page_id'] = 0;
			}
		}

		// Restriction URL.
		if ( ! empty( $schema['properties']['restriction_url'] ) && isset( $request['restriction_url'] ) ) {
			$prepared_item['redirect_custom_url'] = $request['restriction_url'];
		}

		// Sales page id.
		if ( ! empty( $schema['properties']['sales_page_page_id'] ) && isset( $request['sales_page_page_id'] ) ) {
			$page = get_post( $request['sales_page_page_id'] );
			if ( $page && is_a( $page, 'WP_Post' ) ) {
				$prepared_item['sales_page_content_page_id'] = $request['sales_page_page_id'];
			} else {
				$prepared_item['sales_page_content_page_id'] = 0;
			}
		}



Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.9 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.