add_component( 'acf', new Types\Acf() ); } // Pods if ( function_exists( 'pods' ) ) { $this->add_component( 'pods', new Types\Pods() ); } // Toolset if ( function_exists( 'wpcf_admin_fields_get_groups' ) ) { $this->add_component( 'toolset', new Types\Toolset() ); } $this->add_component( 'posts', new Types\Posts() ); $this->add_component( 'terms', new Types\Terms() ); $this->add_component( 'authors', new Types\Authors() ); $this->add_component( 'users', new Types\Users() ); $this->add_component( 'templates', new Types\Templates() ); $this->add_actions(); } /** * Get Name * * Get the name of the module * * @since 2.0.0 * @return string */ public function get_name() { return 'query-control'; } /** * Add Actions * * Registeres actions to Elementor hooks * * @since 2.0.0 * @return void */ protected function add_actions() { add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] ); } /** * Calls function depending on ajax query data * * @since 2.0.0 * @return array */ public function ajax_call_filter_autocomplete( array $data ) { if ( empty( $data['query_type'] ) || empty( $data['q'] ) ) { throw new \Exception( 'Bad Request' ); } $results = $this->get_component( $data['query_type'] )->get_autocomplete_values( $data ); return [ 'results' => $results, ]; } /** * Calls function to get value titles depending on ajax query type * * @since 2.0.0 * @return array */ public function ajax_call_control_value_titles( array $request ) { $results = $this->get_component( $request['query_type'] )->get_value_titles( $request ); return $results; } /** * Register Elementor Ajax Actions * * @since 2.0.0 * @return array */ public function register_ajax_actions( $ajax_manager ) { $ajax_manager->register_ajax_action( 'ee_query_control_value_titles', [ $this, 'ajax_call_control_value_titles' ] ); $ajax_manager->register_ajax_action( 'ee_query_control_filter_autocomplete', [ $this, 'ajax_call_filter_autocomplete' ] ); } }