Skip to content

Commit 7023c51

Browse files
dhananjaykuberdhananjaykuberMamaduka
authored
Cache redundant function call for is_user_logged_in() function (#70999)
Co-authored-by: dhananjaykuber <[email protected]> Co-authored-by: Mamaduka <[email protected]>
1 parent e6ce7a3 commit 7023c51

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/block-library/src/form-input/index.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ function render_block_core_form_input( $attributes, $content ) {
1919
$visibility_permissions = $attributes['visibilityPermissions'];
2020
}
2121

22-
if ( 'logged-in' === $visibility_permissions && ! is_user_logged_in() ) {
22+
$user_logged_in = is_user_logged_in();
23+
24+
if ( 'logged-in' === $visibility_permissions && ! $user_logged_in ) {
2325
return '';
2426
}
25-
if ( 'logged-out' === $visibility_permissions && is_user_logged_in() ) {
27+
if ( 'logged-out' === $visibility_permissions && $user_logged_in ) {
2628
return '';
2729
}
2830
return $content;

packages/block-library/src/loginout/index.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ function render_block_core_loginout( $attributes ) {
2323
*/
2424
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
2525

26-
$classes = is_user_logged_in() ? 'logged-in' : 'logged-out';
26+
$user_logged_in = is_user_logged_in();
27+
28+
$classes = $user_logged_in ? 'logged-in' : 'logged-out';
2729
$contents = wp_loginout(
2830
isset( $attributes['redirectToCurrent'] ) && $attributes['redirectToCurrent'] ? $current_url : '',
2931
false
3032
);
3133

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

0 commit comments

Comments
 (0)