() ); } /** * get_term_name_with_parents * @param \WP_Term $term * @param int $max * * @return string */ private function get_term_name_with_parents( \WP_Term $term, $max = 3 ) { if ( 0 === $term->parent ) { return $term->name; } $separator = is_rtl() ? ' < ' : ' > '; $test_term = $term; $names = []; while ( $test_term->parent > 0 ) { $test_term = get_term( $test_term->parent ); if ( ! $test_term ) { break; } $names[] = $test_term->name; } $names = array_reverse( $names ); if ( count( $names ) < ( $max ) ) { return implode( $separator, $names ) . $separator . $term->name; } $name_string = ''; for ( $i = 0; $i < ( $max - 1 ); $i++ ) { $name_string .= $names[ $i ] . $separator; } return $name_string . '...' . $separator . $term->name; } /** * get post name with parents * @param \WP_Post $post * @param int $max * * @return string */ private function get_post_name_with_parents( $post, $max = 3 ) { if ( 0 === $post->post_parent ) { return $post->post_title; } $separator = is_rtl() ? ' < ' : ' > '; $test_post = $post; $names = []; while ( $test_post->post_parent > 0 ) { $test_post = get_post( $test_post->post_parent ); if ( ! $test_post ) { break; } $names[] = $test_post->post_title; } $names = array_reverse( $names ); if ( count( $names ) < ( $max ) ) { return implode( $separator, $names ) . $separator . $post->post_title; } $name_string = ''; for ( $i = 0; $i < ( $max - 1 ); $i++ ) { $name_string .= $names[ $i ] . $separator; } return $name_string . '...' . $separator . $post->post_title; } /** * @deprecated use Elementor_Post_Query capabilities * * @param string $control_id * @param array $settings * * @return array */ public function get_query_args( $control_id, $settings ) { Plugin::elementor()->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.5.0', 'class Elementor_Post_Query' ); $controls_manager = Plugin::elementor()->controls_manager; /** @var Group_Control_Posts $posts_query */ $posts_query = $controls_manager->get_control_groups( Group_Control_Posts::get_type() ); return $posts_query->get_query_args( $control_id, $settings ); } /** * @param \ElementorPro\Base\Base_Widget $widget * @param string $name * @param array $query_args * @param array $fallback_args * * @return \WP_Query */ public function get_query( $widget, $name, $query_args = [], $fallback_args = [] ) { $prefix = $name . '_'; $post_type = $widget->get_settings( $prefix . 'post_type' ); if ( 'related' === $post_type ) { $elementor_query = new Elementor_Related_Query( $widget, $name, $query_args, $fallback_args ); } else { $elementor_query = new Elementor_Post_Query( $widget, $name, $query_args ); } return $elementor_query->get_query(); } /** * @param Ajax $ajax_manager */ public function register_ajax_actions( $ajax_manager ) { $ajax_manager->register_ajax_action( 'query_control_value_titles', [ $this, 'ajax_posts_control_value_titles' ] ); $ajax_manager->register_ajax_action( 'pro_panel_posts_control_filter_autocomplete', [ $this, 'ajax_posts_filter_autocomplete' ] ); /** * @deprecated 2.6.0 use new `autocomplete` format */ $ajax_manager->register_ajax_action( 'query_control_value_titles_deprecated', [ $this, 'ajax_posts_control_value_titles_deprecated' ] ); $ajax_manager->register_ajax_action( 'pro_panel_posts_control_filter_autocomplete_deprecated', [ $this, 'ajax_posts_filter_autocomplete_deprecated' ] ); } /** * @deprecated 3.1.0 */ public function localize_settings() { Plugin::elementor()->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0' ); return []; } protected function add_actions() { add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] ); add_action( 'elementor/controls/register', [ $this, 'register_controls' ] ); } /** * In WordPress 5.9 the 'who' query param was deprecated, this method * adding the new `capability` query param to the query and still support old versions of WordPress. * * @param $query * * @return mixed */ private function add_edit_capability_to_user_query( $query ) { // Capability queries were only introduced in WP 5.9. if ( version_compare( $GLOBALS['wp_version'], '5.9-alpha', '>=' ) ) { $query['capability'] = [ 'edit_posts' ]; } else { $query['who'] = 'authors'; } return $query; } }