Redirect non-logged-in users to the login page when they visit the search or feed page

If you have restricted the site to logged-in users only and have activated all of the restriction settings for your page, but the search results query pages are still showing up as visible to logged-out users, there may be a plugin or theme conflict. You may learn how to do a plugin or theme conflict test by reading this article.

If you discover that the issue is due to a theme conflict, you may add the code snippet below to your Theme's functions.php file or run the code using the Code Snippet plugin. Before adding the code, make sure you have access to FTP/SFTP so you can revert the changes if it hits a white page due to a fatal error.

	add_action( 'wp', 'um_code_snippet_071423_init', 1 );
	 function um_code_snippet_071423_init() {
		global $wp;
		if ( class_exists( 'UM' ) ) {
			if ( is_feed() || is_search()  ) {
				if ( ! is_user_logged_in() ) {
					$referer = add_query_arg( $wp->query_vars, home_url( $wp->request ) );
					$login_url = um_get_core_page( 'login' );
					$login_url = add_query_arg( 'redirect_to', urldecode_deep( $referer ), $login_url );
					wp_safe_redirect( $login_url );
					exit;
				}
			}
		}
        }