Sindbad~EG File Manager

Current Path : /home/xiedrke/entrepot/wp-content/plugins/realpress/app/Controllers/
Upload File :
Current File : /home/xiedrke/entrepot/wp-content/plugins/realpress/app/Controllers/CompareController.php

<?php

namespace RealPress\Controllers;

use RealPress\Helpers\RestApi;
use RealPress\Helpers\Template;
use WP_REST_Server;

class CompareController {

	public function __construct() {
		add_action( 'rest_api_init', array( $this, 'register_rest_routes' ) );
	}

	public function register_rest_routes() {
		do_action('realpress/rest-api/before-register');

		register_rest_route(
			RestApi::generate_namespace(),
			'/compare',
			array(
				array(
					'methods'  => WP_REST_Server::READABLE,
					'callback' => array( $this, 'get_compare' ),
					'permission_callback' => '__return_true',
				),
			)
		);
	}

	/**
	 * @param \WP_REST_Request $request
	 *
	 * @return \WP_REST_Response
	 */
	public function get_compare( \WP_REST_Request $request ) {
		$params = $request->get_params();

		$args = array(
			'post_type'   => REALPRESS_PROPERTY_CPT,
			'post_status' => 'publish'
		);

		if ( ! isset( $params['post_in'] ) ) {
			$args['post__in'] = array(null);
		} else {
			$args['post__in'] = $params['post_in'];
		}

		$args = apply_filters( 'realpress/filter/compare/args', $args, $params );

		$query        = new \WP_Query( $args );
		$property_ids = array();

		ob_start();
		if ( $query->have_posts() ) {
			while ( $query->have_posts() ) {
				$query->the_post();
				$property_ids[] = get_the_ID();
			}
			wp_reset_postdata();
		}

		$data['property_ids'] = $property_ids;
		Template::instance()->get_frontend_template_type_classic(
			apply_filters( 'realpress/filter/compare/compare-list', 'compare-property/compare-list.php' ),
			compact( 'data' )
		);

		unset( $data['product_ids'] );
		$data['content'] = ob_get_clean();

		return RestApi::success( '', $data );
	}
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists