| Conditions | 8 |
| Paths | 96 |
| Total Lines | 119 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 102 | function wp_set_auth_cookie( $user_id, $remember = false, $secure = '', $token = '' ) { |
||
| 103 | if ( $remember ) { |
||
| 104 | /** This filter is documented in wp-includes/pluggable.php */ |
||
| 105 | $expiration = time() + apply_filters( 'auth_cookie_expiration', 14 * DAY_IN_SECONDS, $user_id, $remember ); |
||
| 106 | |||
| 107 | /* |
||
| 108 | * Ensure the browser will continue to send the cookie after the expiration time is reached. |
||
| 109 | * Needed for the login grace period in wp_validate_auth_cookie(). |
||
| 110 | */ |
||
| 111 | $expire = $expiration + ( 12 * HOUR_IN_SECONDS ); |
||
| 112 | } else { |
||
| 113 | /** This filter is documented in wp-includes/pluggable.php */ |
||
| 114 | $expiration = time() + apply_filters( 'auth_cookie_expiration', 2 * DAY_IN_SECONDS, $user_id, $remember ); |
||
| 115 | $expire = 0; |
||
| 116 | } |
||
| 117 | |||
| 118 | if ( '' === $secure ) { |
||
| 119 | $secure = is_ssl(); |
||
| 120 | } |
||
| 121 | |||
| 122 | // Front-end cookie is secure when the auth cookie is secure and the site's home URL is forced HTTPS. |
||
| 123 | $secure_logged_in_cookie = $secure && 'https' === wp_parse_url( get_option( 'home' ), PHP_URL_SCHEME ); |
||
| 124 | |||
| 125 | /** This filter is documented in wp-includes/pluggable.php */ |
||
| 126 | $secure = apply_filters( 'secure_auth_cookie', $secure, $user_id ); |
||
| 127 | |||
| 128 | /** This filter is documented in wp-includes/pluggable.php */ |
||
| 129 | $secure_logged_in_cookie = apply_filters( 'secure_logged_in_cookie', $secure_logged_in_cookie, $user_id, $secure ); |
||
| 130 | |||
| 131 | if ( $secure ) { |
||
| 132 | $auth_cookie_name = SECURE_AUTH_COOKIE; |
||
| 133 | $scheme = 'secure_auth'; |
||
| 134 | } else { |
||
| 135 | $auth_cookie_name = AUTH_COOKIE; |
||
| 136 | $scheme = 'auth'; |
||
| 137 | } |
||
| 138 | |||
| 139 | if ( '' === $token ) { |
||
| 140 | $manager = WP_Session_Tokens::get_instance( $user_id ); |
||
| 141 | $token = $manager->create( $expiration ); |
||
| 142 | } |
||
| 143 | |||
| 144 | $auth_cookie = wp_generate_auth_cookie( $user_id, $expiration, $scheme, $token ); |
||
| 145 | $logged_in_cookie = wp_generate_auth_cookie( $user_id, $expiration, 'logged_in', $token ); |
||
| 146 | |||
| 147 | /** This filter is documented in wp-includes/pluggable.php */ |
||
| 148 | do_action( 'set_auth_cookie', $auth_cookie, $expire, $expiration, $user_id, $scheme, $token ); |
||
| 149 | |||
| 150 | /** This filter is documented in wp-includes/pluggable.php */ |
||
| 151 | do_action( 'set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in', $token ); |
||
| 152 | |||
| 153 | /** This filter is documented in wp-includes/pluggable.php */ |
||
| 154 | if ( ! apply_filters( 'send_auth_cookies', true ) ) { |
||
| 155 | return; |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Filters the SameSite attribute to use in auth cookies. |
||
| 160 | * |
||
| 161 | * @param string $samesite SameSite attribute to use in auth cookies. |
||
| 162 | * |
||
| 163 | * @since 8.1.1 |
||
| 164 | */ |
||
| 165 | $samesite = apply_filters( 'jetpack_auth_cookie_samesite', 'Lax' ); |
||
| 166 | |||
| 167 | jetpack_shim_setcookie( |
||
| 168 | $auth_cookie_name, |
||
| 169 | $auth_cookie, |
||
| 170 | array( |
||
| 171 | 'expires' => $expire, |
||
| 172 | 'path' => PLUGINS_COOKIE_PATH, |
||
| 173 | 'domain' => COOKIE_DOMAIN, |
||
| 174 | 'secure' => $secure, |
||
| 175 | 'httponly' => true, |
||
| 176 | 'samesite' => $samesite, |
||
| 177 | ) |
||
| 178 | ); |
||
| 179 | |||
| 180 | jetpack_shim_setcookie( |
||
| 181 | $auth_cookie_name, |
||
| 182 | $auth_cookie, |
||
| 183 | array( |
||
| 184 | 'expires' => $expire, |
||
| 185 | 'path' => ADMIN_COOKIE_PATH, |
||
| 186 | 'domain' => COOKIE_DOMAIN, |
||
| 187 | 'secure' => $secure, |
||
| 188 | 'httponly' => true, |
||
| 189 | 'samesite' => $samesite, |
||
| 190 | ) |
||
| 191 | ); |
||
| 192 | |||
| 193 | jetpack_shim_setcookie( |
||
| 194 | LOGGED_IN_COOKIE, |
||
| 195 | $logged_in_cookie, |
||
| 196 | array( |
||
| 197 | 'expires' => $expire, |
||
| 198 | 'path' => COOKIEPATH, |
||
| 199 | 'domain' => COOKIE_DOMAIN, |
||
| 200 | 'secure' => $secure_logged_in_cookie, |
||
| 201 | 'httponly' => true, |
||
| 202 | 'samesite' => $samesite, |
||
| 203 | ) |
||
| 204 | ); |
||
| 205 | |||
| 206 | if ( COOKIEPATH !== SITECOOKIEPATH ) { |
||
| 207 | jetpack_shim_setcookie( |
||
| 208 | LOGGED_IN_COOKIE, |
||
| 209 | $logged_in_cookie, |
||
| 210 | array( |
||
| 211 | 'expires' => $expire, |
||
| 212 | 'path' => SITECOOKIEPATH, |
||
| 213 | 'domain' => COOKIE_DOMAIN, |
||
| 214 | 'secure' => $secure_logged_in_cookie, |
||
| 215 | 'httponly' => true, |
||
| 216 | 'samesite' => $samesite, |
||
| 217 | ) |
||
| 218 | ); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | endif; |
||
| 222 |