Skip to content

Cache redundant function call for is_user_logged_in() function #70999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/block-library/src/form-input/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ function render_block_core_form_input( $attributes, $content ) {
$visibility_permissions = $attributes['visibilityPermissions'];
}

if ( 'logged-in' === $visibility_permissions && ! is_user_logged_in() ) {
$user_logged_in = is_user_logged_in();

if ( 'logged-in' === $visibility_permissions && ! $user_logged_in ) {
return '';
}
if ( 'logged-out' === $visibility_permissions && is_user_logged_in() ) {
if ( 'logged-out' === $visibility_permissions && $user_logged_in ) {
return '';
}
return $content;
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/loginout/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ function render_block_core_loginout( $attributes ) {
*/
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

$classes = is_user_logged_in() ? 'logged-in' : 'logged-out';
$user_logged_in = is_user_logged_in();

$classes = $user_logged_in ? 'logged-in' : 'logged-out';
$contents = wp_loginout(
isset( $attributes['redirectToCurrent'] ) && $attributes['redirectToCurrent'] ? $current_url : '',
false
);

// If logged-out and displayLoginAsForm is true, show the login form.
if ( ! is_user_logged_in() && ! empty( $attributes['displayLoginAsForm'] ) ) {
if ( ! $user_logged_in && ! empty( $attributes['displayLoginAsForm'] ) ) {
// Add a class.
$classes .= ' has-login-form';

Expand Down
Loading