<p>I tried modifying site_URL and wp_redirect using the following code: </p>
<pre class="brush:php;toolbar:false;"><?php
add_filter( 'site_url', 'my_prefix_site_url', 10, 2 );
add_filter( 'wp_redirect', 'my_prefix_wp_redirect' );
function my_prefix_site_url( $url, $scheme ) {
return my_prefix_modify_url( $url, $scheme );
}
function my_prefix_wp_redirect( $url ) {
return my_prefix_modify_url( $url, null );
}
function my_prefix_modify_url( $url, $scheme = null ) {
$current_url = isset( $_SERVER['PHP_SELF'] ) ? sanitize_text_field( wp_unslush( $_SERVER['PHP_SELF'] ) ) : '';
if ( ! strpos( $current_url, 'wp-admin' ) && ! is_user_logged_in() ) {
return '/';
}
return $url;
}
</pre>
<p>But I encountered the following error.
I don't really understand what the actual purpose of this code is, if I understand it correctly I think it breaks a few things, but to your literal question: just write your own function i.e. Can.
The is_user_logged_in function is not complex in the default version:
And
wp_get_current_user
is also pluggable but simple:So you'd just write this:
function custom_is_user_logged_in() { return _wp_get_current_user()->exists(); }