slug = 'protected_content'; $this->title = esc_html__( 'Protected Content', 'elasticpress' ); $this->requires_install_reindex = true; parent::__construct(); } /** * Setup all feature filters * * @since 2.1 */ public function setup() { add_filter( 'ep_indexable_post_status', [ $this, 'get_statuses' ] ); add_filter( 'ep_indexable_post_types', [ $this, 'post_types' ], 10, 1 ); if ( is_admin() ) { add_filter( 'ep_admin_wp_query_integration', '__return_true' ); add_action( 'pre_get_posts', [ $this, 'integrate' ] ); } } /** * Index all post types * * @param array $post_types Existing post types. * @since 2.2 * @return array */ public function post_types( $post_types ) { // Let's get non public post types first $pc_post_types = get_post_types( array( 'public' => false ) ); // We don't want to deal with nav menus if ( $pc_post_types['nav_menu_item'] ) { unset( $pc_post_types['nav_menu_item'] ); } if ( ! empty( $pc_post_types['revision'] ) ) { unset( $pc_post_types['revision'] ); } if ( ! empty( $pc_post_types['custom_css'] ) ) { unset( $pc_post_types['custom_css'] ); } if ( ! empty( $pc_post_types['customize_changeset'] ) ) { unset( $pc_post_types['customize_changeset'] ); } if ( ! empty( $pc_post_types['oembed_cache'] ) ) { unset( $pc_post_types['oembed_cache'] ); } if ( ! empty( $pc_post_types['wp_block'] ) ) { unset( $pc_post_types['wp_block'] ); } if ( ! empty( $pc_post_types['user_request'] ) ) { unset( $pc_post_types['user_request'] ); } // By default, attachments are not indexed, we have to make sure they are included (Could already be included by documents feature). $post_types['attachment'] = 'attachment'; // Merge non public post types with any pre-filtered post_type return array_merge( $post_types, $pc_post_types ); } /** * Integrate EP into proper queries * * @param WP_Query $query WP Query * @since 2.1 */ public function integrate( $query ) { // Lets make sure this doesn't interfere with the CLI if ( defined( 'WP_CLI' ) && WP_CLI ) { return; } if ( ! $query->is_main_query() ) { return; } /** * We limit to these post types to not conflict with other features like WooCommerce * * @since 2.1 * @var array */ $post_types = array( 'post' => 'post', 'attachment' => 'attachment', ); /** * Filter protected content supported post types. For backwards compatibility. * * @hook ep_admin_supported_post_types * @param {array} $post_types Post types * @return {array} New post types */ $supported_post_types = apply_filters( 'ep_admin_supported_post_types', $post_types ); /** * Filter protected content supported post types. * * @hook ep_pc_supported_post_types * @param {array} $supported_post_types Supported post types * @return {array} New post types */ $supported_post_types = apply_filters( 'ep_pc_supported_post_types', $supported_post_types ); $post_type = $query->get( 'post_type' ); if ( empty( $post_type ) ) { $post_type = 'post'; } if ( is_array( $post_type ) ) { foreach ( $post_type as $pt ) { if ( empty( $supported_post_types[ $pt ] ) ) { return; } } $query->set( 'ep_integrate', true ); } else { if ( ! empty( $supported_post_types[ $post_type ] ) ) { $query->set( 'ep_integrate', true ); } } /** * Remove articles weighting by date in admin. * * @since 3.0 */ $search_feature = Features::factory()->get_registered_feature( 'search' ); remove_filter( 'ep_formatted_args', [ $search_feature, 'weight_recent' ], 10 ); } /** * Output feature box summary * * @since 2.1 */ public function output_feature_box_summary() { ?>

We recommend using a secured Elasticsearch setup, such as ElasticPress.io, to prevent potential exposure of content not intended for the public.', 'elasticpress' ) ); ?>

message = __( "You aren't using ElasticPress.io so we can't be sure your Elasticsearch instance is secure.", 'elasticpress' ); } return $status; } }