[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> pluggable.php (source)

   1  <?php
   2  /**
   3   * These functions can be replaced via plugins. If plugins do not redefine these
   4   * functions, then these will be used instead.
   5   *
   6   * @package WordPress
   7   */
   8  
   9  if ( ! function_exists( 'wp_set_current_user' ) ) :
  10      /**
  11       * Changes the current user by ID or name.
  12       *
  13       * Set $id to null and specify a name if you do not know a user's ID.
  14       *
  15       * Some WordPress functionality is based on the current user and not based on
  16       * the signed in user. Therefore, it opens the ability to edit and perform
  17       * actions on users who aren't signed in.
  18       *
  19       * @since 2.0.3
  20       *
  21       * @global WP_User $current_user The current user object which holds the user data.
  22       *
  23       * @param int|null $id   User ID.
  24       * @param string   $name User's username.
  25       * @return WP_User Current user User object.
  26       */
  27  	function wp_set_current_user( $id, $name = '' ) {
  28          global $current_user;
  29  
  30          // If `$id` matches the current user, there is nothing to do.
  31          if ( isset( $current_user )
  32          && ( $current_user instanceof WP_User )
  33          && ( $id == $current_user->ID )
  34          && ( null !== $id )
  35          ) {
  36              return $current_user;
  37          }
  38  
  39          $current_user = new WP_User( $id, $name );
  40  
  41          setup_userdata( $current_user->ID );
  42  
  43          /**
  44           * Fires after the current user is set.
  45           *
  46           * @since 2.0.1
  47           */
  48          do_action( 'set_current_user' );
  49  
  50          return $current_user;
  51      }
  52  endif;
  53  
  54  if ( ! function_exists( 'wp_get_current_user' ) ) :
  55      /**
  56       * Retrieve the current user object.
  57       *
  58       * Will set the current user, if the current user is not set. The current user
  59       * will be set to the logged-in person. If no user is logged-in, then it will
  60       * set the current user to 0, which is invalid and won't have any permissions.
  61       *
  62       * @since 2.0.3
  63       *
  64       * @see _wp_get_current_user()
  65       * @global WP_User $current_user Checks if the current user is set.
  66       *
  67       * @return WP_User Current WP_User instance.
  68       */
  69  	function wp_get_current_user() {
  70          return _wp_get_current_user();
  71      }
  72  endif;
  73  
  74  if ( ! function_exists( 'get_userdata' ) ) :
  75      /**
  76       * Retrieve user info by user ID.
  77       *
  78       * @since 0.71
  79       *
  80       * @param int $user_id User ID
  81       * @return WP_User|false WP_User object on success, false on failure.
  82       */
  83  	function get_userdata( $user_id ) {
  84          return get_user_by( 'id', $user_id );
  85      }
  86  endif;
  87  
  88  if ( ! function_exists( 'get_user_by' ) ) :
  89      /**
  90       * Retrieve user info by a given field
  91       *
  92       * @since 2.8.0
  93       * @since 4.4.0 Added 'ID' as an alias of 'id' for the `$field` parameter.
  94       * @since 5.8.0 Returns the global `$current_user` if it's the user being fetched.
  95       *
  96       * @global WP_User $current_user The current user object which holds the user data.
  97       *
  98       * @param string     $field The field to retrieve the user with. id | ID | slug | email | login.
  99       * @param int|string $value A value for $field. A user ID, slug, email address, or login name.
 100       * @return WP_User|false WP_User object on success, false on failure.
 101       */
 102  	function get_user_by( $field, $value ) {
 103          global $current_user;
 104  
 105          $userdata = WP_User::get_data_by( $field, $value );
 106  
 107          if ( ! $userdata ) {
 108              return false;
 109          }
 110  
 111          if ( $current_user instanceof WP_User && $current_user->ID === (int) $userdata->ID ) {
 112              return $current_user;
 113          }
 114  
 115          $user = new WP_User;
 116          $user->init( $userdata );
 117  
 118          return $user;
 119      }
 120  endif;
 121  
 122  if ( ! function_exists( 'cache_users' ) ) :
 123      /**
 124       * Retrieve info for user lists to prevent multiple queries by get_userdata()
 125       *
 126       * @since 3.0.0
 127       *
 128       * @global wpdb $wpdb WordPress database abstraction object.
 129       *
 130       * @param array $user_ids User ID numbers list
 131       */
 132  	function cache_users( $user_ids ) {
 133          global $wpdb;
 134  
 135          $clean = _get_non_cached_ids( $user_ids, 'users' );
 136  
 137          if ( empty( $clean ) ) {
 138              return;
 139          }
 140  
 141          $list = implode( ',', $clean );
 142  
 143          $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" );
 144  
 145          $ids = array();
 146          foreach ( $users as $user ) {
 147              update_user_caches( $user );
 148              $ids[] = $user->ID;
 149          }
 150          update_meta_cache( 'user', $ids );
 151      }
 152  endif;
 153  
 154  if ( ! function_exists( 'wp_mail' ) ) :
 155      /**
 156       * Sends an email, similar to PHP's mail function.
 157       *
 158       * A true return value does not automatically mean that the user received the
 159       * email successfully. It just only means that the method used was able to
 160       * process the request without any errors.
 161       *
 162       * The default content type is `text/plain` which does not allow using HTML.
 163       * However, you can set the content type of the email by using the
 164       * {@see 'wp_mail_content_type'} filter.
 165       *
 166       * The default charset is based on the charset used on the blog. The charset can
 167       * be set using the {@see 'wp_mail_charset'} filter.
 168       *
 169       * @since 1.2.1
 170       * @since 5.5.0 is_email() is used for email validation,
 171       *              instead of PHPMailer's default validator.
 172       *
 173       * @global PHPMailer\PHPMailer\PHPMailer $phpmailer
 174       *
 175       * @param string|string[] $to          Array or comma-separated list of email addresses to send message.
 176       * @param string          $subject     Email subject.
 177       * @param string          $message     Message contents.
 178       * @param string|string[] $headers     Optional. Additional headers.
 179       * @param string|string[] $attachments Optional. Paths to files to attach.
 180       * @return bool Whether the email was sent successfully.
 181       */
 182  	function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
 183          // Compact the input, apply the filters, and extract them back out.
 184  
 185          /**
 186           * Filters the wp_mail() arguments.
 187           *
 188           * @since 2.2.0
 189           *
 190           * @param array $args {
 191           *     Array of the `wp_mail()` arguments.
 192           *
 193           *     @type string|string[] $to          Array or comma-separated list of email addresses to send message.
 194           *     @type string          $subject     Email subject.
 195           *     @type string          $message     Message contents.
 196           *     @type string|string[] $headers     Additional headers.
 197           *     @type string|string[] $attachments Paths to files to attach.
 198           * }
 199           */
 200          $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );
 201  
 202          /**
 203           * Filters whether to preempt sending an email.
 204           *
 205           * Returning a non-null value will short-circuit {@see wp_mail()}, returning
 206           * that value instead. A boolean return value should be used to indicate whether
 207           * the email was successfully sent.
 208           *
 209           * @since 5.7.0
 210           *
 211           * @param null|bool $return Short-circuit return value.
 212           * @param array     $atts {
 213           *     Array of the `wp_mail()` arguments.
 214           *
 215           *     @type string|string[] $to          Array or comma-separated list of email addresses to send message.
 216           *     @type string          $subject     Email subject.
 217           *     @type string          $message     Message contents.
 218           *     @type string|string[] $headers     Additional headers.
 219           *     @type string|string[] $attachments Paths to files to attach.
 220           * }
 221           */
 222          $pre_wp_mail = apply_filters( 'pre_wp_mail', null, $atts );
 223  
 224          if ( null !== $pre_wp_mail ) {
 225              return $pre_wp_mail;
 226          }
 227  
 228          if ( isset( $atts['to'] ) ) {
 229              $to = $atts['to'];
 230          }
 231  
 232          if ( ! is_array( $to ) ) {
 233              $to = explode( ',', $to );
 234          }
 235  
 236          if ( isset( $atts['subject'] ) ) {
 237              $subject = $atts['subject'];
 238          }
 239  
 240          if ( isset( $atts['message'] ) ) {
 241              $message = $atts['message'];
 242          }
 243  
 244          if ( isset( $atts['headers'] ) ) {
 245              $headers = $atts['headers'];
 246          }
 247  
 248          if ( isset( $atts['attachments'] ) ) {
 249              $attachments = $atts['attachments'];
 250          }
 251  
 252          if ( ! is_array( $attachments ) ) {
 253              $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
 254          }
 255          global $phpmailer;
 256  
 257          // (Re)create it, if it's gone missing.
 258          if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) ) {
 259              require_once  ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
 260              require_once  ABSPATH . WPINC . '/PHPMailer/SMTP.php';
 261              require_once  ABSPATH . WPINC . '/PHPMailer/Exception.php';
 262              $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true );
 263  
 264              $phpmailer::$validator = static function ( $email ) {
 265                  return (bool) is_email( $email );
 266              };
 267          }
 268  
 269          // Headers.
 270          $cc       = array();
 271          $bcc      = array();
 272          $reply_to = array();
 273  
 274          if ( empty( $headers ) ) {
 275              $headers = array();
 276          } else {
 277              if ( ! is_array( $headers ) ) {
 278                  // Explode the headers out, so this function can take
 279                  // both string headers and an array of headers.
 280                  $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
 281              } else {
 282                  $tempheaders = $headers;
 283              }
 284              $headers = array();
 285  
 286              // If it's actually got contents.
 287              if ( ! empty( $tempheaders ) ) {
 288                  // Iterate through the raw headers.
 289                  foreach ( (array) $tempheaders as $header ) {
 290                      if ( strpos( $header, ':' ) === false ) {
 291                          if ( false !== stripos( $header, 'boundary=' ) ) {
 292                              $parts    = preg_split( '/boundary=/i', trim( $header ) );
 293                              $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
 294                          }
 295                          continue;
 296                      }
 297                      // Explode them out.
 298                      list( $name, $content ) = explode( ':', trim( $header ), 2 );
 299  
 300                      // Cleanup crew.
 301                      $name    = trim( $name );
 302                      $content = trim( $content );
 303  
 304                      switch ( strtolower( $name ) ) {
 305                          // Mainly for legacy -- process a "From:" header if it's there.
 306                          case 'from':
 307                              $bracket_pos = strpos( $content, '<' );
 308                              if ( false !== $bracket_pos ) {
 309                                  // Text before the bracketed email is the "From" name.
 310                                  if ( $bracket_pos > 0 ) {
 311                                      $from_name = substr( $content, 0, $bracket_pos - 1 );
 312                                      $from_name = str_replace( '"', '', $from_name );
 313                                      $from_name = trim( $from_name );
 314                                  }
 315  
 316                                  $from_email = substr( $content, $bracket_pos + 1 );
 317                                  $from_email = str_replace( '>', '', $from_email );
 318                                  $from_email = trim( $from_email );
 319  
 320                                  // Avoid setting an empty $from_email.
 321                              } elseif ( '' !== trim( $content ) ) {
 322                                  $from_email = trim( $content );
 323                              }
 324                              break;
 325                          case 'content-type':
 326                              if ( strpos( $content, ';' ) !== false ) {
 327                                  list( $type, $charset_content ) = explode( ';', $content );
 328                                  $content_type                   = trim( $type );
 329                                  if ( false !== stripos( $charset_content, 'charset=' ) ) {
 330                                      $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset_content ) );
 331                                  } elseif ( false !== stripos( $charset_content, 'boundary=' ) ) {
 332                                      $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) );
 333                                      $charset  = '';
 334                                  }
 335  
 336                                  // Avoid setting an empty $content_type.
 337                              } elseif ( '' !== trim( $content ) ) {
 338                                  $content_type = trim( $content );
 339                              }
 340                              break;
 341                          case 'cc':
 342                              $cc = array_merge( (array) $cc, explode( ',', $content ) );
 343                              break;
 344                          case 'bcc':
 345                              $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
 346                              break;
 347                          case 'reply-to':
 348                              $reply_to = array_merge( (array) $reply_to, explode( ',', $content ) );
 349                              break;
 350                          default:
 351                              // Add it to our grand headers array.
 352                              $headers[ trim( $name ) ] = trim( $content );
 353                              break;
 354                      }
 355                  }
 356              }
 357          }
 358  
 359          // Empty out the values that may be set.
 360          $phpmailer->clearAllRecipients();
 361          $phpmailer->clearAttachments();
 362          $phpmailer->clearCustomHeaders();
 363          $phpmailer->clearReplyTos();
 364  
 365          // Set "From" name and email.
 366  
 367          // If we don't have a name from the input headers.
 368          if ( ! isset( $from_name ) ) {
 369              $from_name = 'WordPress';
 370          }
 371  
 372          /*
 373           * If we don't have an email from the input headers, default to wordpress@$sitename
 374           * Some hosts will block outgoing mail from this address if it doesn't exist,
 375           * but there's no easy alternative. Defaulting to admin_email might appear to be
 376           * another option, but some hosts may refuse to relay mail from an unknown domain.
 377           * See https://core.trac.wordpress.org/ticket/5007.
 378           */
 379          if ( ! isset( $from_email ) ) {
 380              // Get the site domain and get rid of www.
 381              $sitename = wp_parse_url( network_home_url(), PHP_URL_HOST );
 382              if ( 'www.' === substr( $sitename, 0, 4 ) ) {
 383                  $sitename = substr( $sitename, 4 );
 384              }
 385  
 386              $from_email = 'wordpress@' . $sitename;
 387          }
 388  
 389          /**
 390           * Filters the email address to send from.
 391           *
 392           * @since 2.2.0
 393           *
 394           * @param string $from_email Email address to send from.
 395           */
 396          $from_email = apply_filters( 'wp_mail_from', $from_email );
 397  
 398          /**
 399           * Filters the name to associate with the "from" email address.
 400           *
 401           * @since 2.3.0
 402           *
 403           * @param string $from_name Name associated with the "from" email address.
 404           */
 405          $from_name = apply_filters( 'wp_mail_from_name', $from_name );
 406  
 407          try {
 408              $phpmailer->setFrom( $from_email, $from_name, false );
 409          } catch ( PHPMailer\PHPMailer\Exception $e ) {
 410              $mail_error_data                             = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
 411              $mail_error_data['phpmailer_exception_code'] = $e->getCode();
 412  
 413              /** This filter is documented in wp-includes/pluggable.php */
 414              do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
 415  
 416              return false;
 417          }
 418  
 419          // Set mail's subject and body.
 420          $phpmailer->Subject = $subject;
 421          $phpmailer->Body    = $message;
 422  
 423          // Set destination addresses, using appropriate methods for handling addresses.
 424          $address_headers = compact( 'to', 'cc', 'bcc', 'reply_to' );
 425  
 426          foreach ( $address_headers as $address_header => $addresses ) {
 427              if ( empty( $addresses ) ) {
 428                  continue;
 429              }
 430  
 431              foreach ( (array) $addresses as $address ) {
 432                  try {
 433                      // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>".
 434                      $recipient_name = '';
 435  
 436                      if ( preg_match( '/(.*)<(.+)>/', $address, $matches ) ) {
 437                          if ( count( $matches ) == 3 ) {
 438                              $recipient_name = $matches[1];
 439                              $address        = $matches[2];
 440                          }
 441                      }
 442  
 443                      switch ( $address_header ) {
 444                          case 'to':
 445                              $phpmailer->addAddress( $address, $recipient_name );
 446                              break;
 447                          case 'cc':
 448                              $phpmailer->addCc( $address, $recipient_name );
 449                              break;
 450                          case 'bcc':
 451                              $phpmailer->addBcc( $address, $recipient_name );
 452                              break;
 453                          case 'reply_to':
 454                              $phpmailer->addReplyTo( $address, $recipient_name );
 455                              break;
 456                      }
 457                  } catch ( PHPMailer\PHPMailer\Exception $e ) {
 458                      continue;
 459                  }
 460              }
 461          }
 462  
 463          // Set to use PHP's mail().
 464          $phpmailer->isMail();
 465  
 466          // Set Content-Type and charset.
 467  
 468          // If we don't have a content-type from the input headers.
 469          if ( ! isset( $content_type ) ) {
 470              $content_type = 'text/plain';
 471          }
 472  
 473          /**
 474           * Filters the wp_mail() content type.
 475           *
 476           * @since 2.3.0
 477           *
 478           * @param string $content_type Default wp_mail() content type.
 479           */
 480          $content_type = apply_filters( 'wp_mail_content_type', $content_type );
 481  
 482          $phpmailer->ContentType = $content_type;
 483  
 484          // Set whether it's plaintext, depending on $content_type.
 485          if ( 'text/html' === $content_type ) {
 486              $phpmailer->isHTML( true );
 487          }
 488  
 489          // If we don't have a charset from the input headers.
 490          if ( ! isset( $charset ) ) {
 491              $charset = get_bloginfo( 'charset' );
 492          }
 493  
 494          /**
 495           * Filters the default wp_mail() charset.
 496           *
 497           * @since 2.3.0
 498           *
 499           * @param string $charset Default email charset.
 500           */
 501          $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
 502  
 503          // Set custom headers.
 504          if ( ! empty( $headers ) ) {
 505              foreach ( (array) $headers as $name => $content ) {
 506                  // Only add custom headers not added automatically by PHPMailer.
 507                  if ( ! in_array( $name, array( 'MIME-Version', 'X-Mailer' ), true ) ) {
 508                      try {
 509                          $phpmailer->addCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
 510                      } catch ( PHPMailer\PHPMailer\Exception $e ) {
 511                          continue;
 512                      }
 513                  }
 514              }
 515  
 516              if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) {
 517                  $phpmailer->addCustomHeader( sprintf( 'Content-Type: %s; boundary="%s"', $content_type, $boundary ) );
 518              }
 519          }
 520  
 521          if ( ! empty( $attachments ) ) {
 522              foreach ( $attachments as $attachment ) {
 523                  try {
 524                      $phpmailer->addAttachment( $attachment );
 525                  } catch ( PHPMailer\PHPMailer\Exception $e ) {
 526                      continue;
 527                  }
 528              }
 529          }
 530  
 531          /**
 532           * Fires after PHPMailer is initialized.
 533           *
 534           * @since 2.2.0
 535           *
 536           * @param PHPMailer $phpmailer The PHPMailer instance (passed by reference).
 537           */
 538          do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
 539  
 540          $mail_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
 541  
 542          // Send!
 543          try {
 544              $send = $phpmailer->send();
 545  
 546              /**
 547               * Fires after PHPMailer has successfully sent a mail.
 548               *
 549               * The firing of this action does not necessarily mean that the recipient received the
 550               * email successfully. It only means that the `send` method above was able to
 551               * process the request without any errors.
 552               *
 553               * @since 5.9.0
 554               *
 555               * @param array $mail_data An array containing the mail recipient, subject, message, headers, and attachments.
 556               */
 557              do_action( 'wp_mail_succeeded', $mail_data );
 558  
 559              return $send;
 560          } catch ( PHPMailer\PHPMailer\Exception $e ) {
 561              $mail_data['phpmailer_exception_code'] = $e->getCode();
 562  
 563              /**
 564               * Fires after a PHPMailer\PHPMailer\Exception is caught.
 565               *
 566               * @since 4.4.0
 567               *
 568               * @param WP_Error $error A WP_Error object with the PHPMailer\PHPMailer\Exception message, and an array
 569               *                        containing the mail recipient, subject, message, headers, and attachments.
 570               */
 571              do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_data ) );
 572  
 573              return false;
 574          }
 575      }
 576  endif;
 577  
 578  if ( ! function_exists( 'wp_authenticate' ) ) :
 579      /**
 580       * Authenticate a user, confirming the login credentials are valid.
 581       *
 582       * @since 2.5.0
 583       * @since 4.5.0 `$username` now accepts an email address.
 584       *
 585       * @param string $username User's username or email address.
 586       * @param string $password User's password.
 587       * @return WP_User|WP_Error WP_User object if the credentials are valid,
 588       *                          otherwise WP_Error.
 589       */
 590  	function wp_authenticate( $username, $password ) {
 591          $username = sanitize_user( $username );
 592          $password = trim( $password );
 593  
 594          /**
 595           * Filters whether a set of user login credentials are valid.
 596           *
 597           * A WP_User object is returned if the credentials authenticate a user.
 598           * WP_Error or null otherwise.
 599           *
 600           * @since 2.8.0
 601           * @since 4.5.0 `$username` now accepts an email address.
 602           *
 603           * @param null|WP_User|WP_Error $user     WP_User if the user is authenticated.
 604           *                                        WP_Error or null otherwise.
 605           * @param string                $username Username or email address.
 606           * @param string                $password User password
 607           */
 608          $user = apply_filters( 'authenticate', null, $username, $password );
 609  
 610          if ( null == $user ) {
 611              // TODO: What should the error message be? (Or would these even happen?)
 612              // Only needed if all authentication handlers fail to return anything.
 613              $user = new WP_Error( 'authentication_failed', __( '<strong>Error</strong>: Invalid username, email address or incorrect password.' ) );
 614          }
 615  
 616          $ignore_codes = array( 'empty_username', 'empty_password' );
 617  
 618          if ( is_wp_error( $user ) && ! in_array( $user->get_error_code(), $ignore_codes, true ) ) {
 619              $error = $user;
 620  
 621              /**
 622               * Fires after a user login has failed.
 623               *
 624               * @since 2.5.0
 625               * @since 4.5.0 The value of `$username` can now be an email address.
 626               * @since 5.4.0 The `$error` parameter was added.
 627               *
 628               * @param string   $username Username or email address.
 629               * @param WP_Error $error    A WP_Error object with the authentication failure details.
 630               */
 631              do_action( 'wp_login_failed', $username, $error );
 632          }
 633  
 634          return $user;
 635      }
 636  endif;
 637  
 638  if ( ! function_exists( 'wp_logout' ) ) :
 639      /**
 640       * Log the current user out.
 641       *
 642       * @since 2.5.0
 643       */
 644  	function wp_logout() {
 645          $user_id = get_current_user_id();
 646  
 647          wp_destroy_current_session();
 648          wp_clear_auth_cookie();
 649          wp_set_current_user( 0 );
 650  
 651          /**
 652           * Fires after a user is logged out.
 653           *
 654           * @since 1.5.0
 655           * @since 5.5.0 Added the `$user_id` parameter.
 656           *
 657           * @param int $user_id ID of the user that was logged out.
 658           */
 659          do_action( 'wp_logout', $user_id );
 660      }
 661  endif;
 662  
 663  if ( ! function_exists( 'wp_validate_auth_cookie' ) ) :
 664      /**
 665       * Validates authentication cookie.
 666       *
 667       * The checks include making sure that the authentication cookie is set and
 668       * pulling in the contents (if $cookie is not used).
 669       *
 670       * Makes sure the cookie is not expired. Verifies the hash in cookie is what is
 671       * should be and compares the two.
 672       *
 673       * @since 2.5.0
 674       *
 675       * @global int $login_grace_period
 676       *
 677       * @param string $cookie Optional. If used, will validate contents instead of cookie's.
 678       * @param string $scheme Optional. The cookie scheme to use: 'auth', 'secure_auth', or 'logged_in'.
 679       * @return int|false User ID if valid cookie, false if invalid.
 680       */
 681  	function wp_validate_auth_cookie( $cookie = '', $scheme = '' ) {
 682          $cookie_elements = wp_parse_auth_cookie( $cookie, $scheme );
 683          if ( ! $cookie_elements ) {
 684              /**
 685               * Fires if an authentication cookie is malformed.
 686               *
 687               * @since 2.7.0
 688               *
 689               * @param string $cookie Malformed auth cookie.
 690               * @param string $scheme Authentication scheme. Values include 'auth', 'secure_auth',
 691               *                       or 'logged_in'.
 692               */
 693              do_action( 'auth_cookie_malformed', $cookie, $scheme );
 694              return false;
 695          }
 696  
 697          $scheme     = $cookie_elements['scheme'];
 698          $username   = $cookie_elements['username'];
 699          $hmac       = $cookie_elements['hmac'];
 700          $token      = $cookie_elements['token'];
 701          $expired    = $cookie_elements['expiration'];
 702          $expiration = $cookie_elements['expiration'];
 703  
 704          // Allow a grace period for POST and Ajax requests.
 705          if ( wp_doing_ajax() || 'POST' === $_SERVER['REQUEST_METHOD'] ) {
 706              $expired += HOUR_IN_SECONDS;
 707          }
 708  
 709          // Quick check to see if an honest cookie has expired.
 710          if ( $expired < time() ) {
 711              /**
 712               * Fires once an authentication cookie has expired.
 713               *
 714               * @since 2.7.0
 715               *
 716               * @param string[] $cookie_elements An array of data for the authentication cookie.
 717               */
 718              do_action( 'auth_cookie_expired', $cookie_elements );
 719              return false;
 720          }
 721  
 722          $user = get_user_by( 'login', $username );
 723          if ( ! $user ) {
 724              /**
 725               * Fires if a bad username is entered in the user authentication process.
 726               *
 727               * @since 2.7.0
 728               *
 729               * @param string[] $cookie_elements An array of data for the authentication cookie.
 730               */
 731              do_action( 'auth_cookie_bad_username', $cookie_elements );
 732              return false;
 733          }
 734  
 735          $pass_frag = substr( $user->user_pass, 8, 4 );
 736  
 737          $key = wp_hash( $username . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme );
 738  
 739          // If ext/hash is not present, compat.php's hash_hmac() does not support sha256.
 740          $algo = function_exists( 'hash' ) ? 'sha256' : 'sha1';
 741          $hash = hash_hmac( $algo, $username . '|' . $expiration . '|' . $token, $key );
 742  
 743          if ( ! hash_equals( $hash, $hmac ) ) {
 744              /**
 745               * Fires if a bad authentication cookie hash is encountered.
 746               *
 747               * @since 2.7.0
 748               *
 749               * @param string[] $cookie_elements An array of data for the authentication cookie.
 750               */
 751              do_action( 'auth_cookie_bad_hash', $cookie_elements );
 752              return false;
 753          }
 754  
 755          $manager = WP_Session_Tokens::get_instance( $user->ID );
 756          if ( ! $manager->verify( $token ) ) {
 757              /**
 758               * Fires if a bad session token is encountered.
 759               *
 760               * @since 4.0.0
 761               *
 762               * @param string[] $cookie_elements An array of data for the authentication cookie.
 763               */
 764              do_action( 'auth_cookie_bad_session_token', $cookie_elements );
 765              return false;
 766          }
 767  
 768          // Ajax/POST grace period set above.
 769          if ( $expiration < time() ) {
 770              $GLOBALS['login_grace_period'] = 1;
 771          }
 772  
 773          /**
 774           * Fires once an authentication cookie has been validated.
 775           *
 776           * @since 2.7.0
 777           *
 778           * @param string[] $cookie_elements An array of data for the authentication cookie.
 779           * @param WP_User  $user            User object.
 780           */
 781          do_action( 'auth_cookie_valid', $cookie_elements, $user );
 782  
 783          return $user->ID;
 784      }
 785  endif;
 786  
 787  if ( ! function_exists( 'wp_generate_auth_cookie' ) ) :
 788      /**
 789       * Generates authentication cookie contents.
 790       *
 791       * @since 2.5.0
 792       * @since 4.0.0 The `$token` parameter was added.
 793       *
 794       * @param int    $user_id    User ID.
 795       * @param int    $expiration The time the cookie expires as a UNIX timestamp.
 796       * @param string $scheme     Optional. The cookie scheme to use: 'auth', 'secure_auth', or 'logged_in'.
 797       *                           Default 'auth'.
 798       * @param string $token      User's session token to use for this cookie.
 799       * @return string Authentication cookie contents. Empty string if user does not exist.
 800       */
 801  	function wp_generate_auth_cookie( $user_id, $expiration, $scheme = 'auth', $token = '' ) {
 802          $user = get_userdata( $user_id );
 803          if ( ! $user ) {
 804              return '';
 805          }
 806  
 807          if ( ! $token ) {
 808              $manager = WP_Session_Tokens::get_instance( $user_id );
 809              $token   = $manager->create( $expiration );
 810          }
 811  
 812          $pass_frag = substr( $user->user_pass, 8, 4 );
 813  
 814          $key = wp_hash( $user->user_login . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme );
 815  
 816          // If ext/hash is not present, compat.php's hash_hmac() does not support sha256.
 817          $algo = function_exists( 'hash' ) ? 'sha256' : 'sha1';
 818          $hash = hash_hmac( $algo, $user->user_login . '|' . $expiration . '|' . $token, $key );
 819  
 820          $cookie = $user->user_login . '|' . $expiration . '|' . $token . '|' . $hash;
 821  
 822          /**
 823           * Filters the authentication cookie.
 824           *
 825           * @since 2.5.0
 826           * @since 4.0.0 The `$token` parameter was added.
 827           *
 828           * @param string $cookie     Authentication cookie.
 829           * @param int    $user_id    User ID.
 830           * @param int    $expiration The time the cookie expires as a UNIX timestamp.
 831           * @param string $scheme     Cookie scheme used. Accepts 'auth', 'secure_auth', or 'logged_in'.
 832           * @param string $token      User's session token used.
 833           */
 834          return apply_filters( 'auth_cookie', $cookie, $user_id, $expiration, $scheme, $token );
 835      }
 836  endif;
 837  
 838  if ( ! function_exists( 'wp_parse_auth_cookie' ) ) :
 839      /**
 840       * Parses a cookie into its components.
 841       *
 842       * @since 2.7.0
 843       *
 844       * @param string $cookie Authentication cookie.
 845       * @param string $scheme Optional. The cookie scheme to use: 'auth', 'secure_auth', or 'logged_in'.
 846       * @return string[]|false Authentication cookie components.
 847       */
 848  	function wp_parse_auth_cookie( $cookie = '', $scheme = '' ) {
 849          if ( empty( $cookie ) ) {
 850              switch ( $scheme ) {
 851                  case 'auth':
 852                      $cookie_name = AUTH_COOKIE;
 853                      break;
 854                  case 'secure_auth':
 855                      $cookie_name = SECURE_AUTH_COOKIE;
 856                      break;
 857                  case 'logged_in':
 858                      $cookie_name = LOGGED_IN_COOKIE;
 859                      break;
 860                  default:
 861                      if ( is_ssl() ) {
 862                          $cookie_name = SECURE_AUTH_COOKIE;
 863                          $scheme      = 'secure_auth';
 864                      } else {
 865                          $cookie_name = AUTH_COOKIE;
 866                          $scheme      = 'auth';
 867                      }
 868              }
 869  
 870              if ( empty( $_COOKIE[ $cookie_name ] ) ) {
 871                  return false;
 872              }
 873              $cookie = $_COOKIE[ $cookie_name ];
 874          }
 875  
 876          $cookie_elements = explode( '|', $cookie );
 877          if ( count( $cookie_elements ) !== 4 ) {
 878              return false;
 879          }
 880  
 881          list( $username, $expiration, $token, $hmac ) = $cookie_elements;
 882  
 883          return compact( 'username', 'expiration', 'token', 'hmac', 'scheme' );
 884      }
 885  endif;
 886  
 887  if ( ! function_exists( 'wp_set_auth_cookie' ) ) :
 888      /**
 889       * Sets the authentication cookies based on user ID.
 890       *
 891       * The $remember parameter increases the time that the cookie will be kept. The
 892       * default the cookie is kept without remembering is two days. When $remember is
 893       * set, the cookies will be kept for 14 days or two weeks.
 894       *
 895       * @since 2.5.0
 896       * @since 4.3.0 Added the `$token` parameter.
 897       *
 898       * @param int         $user_id  User ID.
 899       * @param bool        $remember Whether to remember the user.
 900       * @param bool|string $secure   Whether the auth cookie should only be sent over HTTPS. Default is an empty
 901       *                              string which means the value of `is_ssl()` will be used.
 902       * @param string      $token    Optional. User's session token to use for this cookie.
 903       */
 904  	function wp_set_auth_cookie( $user_id, $remember = false, $secure = '', $token = '' ) {
 905          if ( $remember ) {
 906              /**
 907               * Filters the duration of the authentication cookie expiration period.
 908               *
 909               * @since 2.8.0
 910               *
 911               * @param int  $length   Duration of the expiration period in seconds.
 912               * @param int  $user_id  User ID.
 913               * @param bool $remember Whether to remember the user login. Default false.
 914               */
 915              $expiration = time() + apply_filters( 'auth_cookie_expiration', 14 * DAY_IN_SECONDS, $user_id, $remember );
 916  
 917              /*
 918               * Ensure the browser will continue to send the cookie after the expiration time is reached.
 919               * Needed for the login grace period in wp_validate_auth_cookie().
 920               */
 921              $expire = $expiration + ( 12 * HOUR_IN_SECONDS );
 922          } else {
 923              /** This filter is documented in wp-includes/pluggable.php */
 924              $expiration = time() + apply_filters( 'auth_cookie_expiration', 2 * DAY_IN_SECONDS, $user_id, $remember );
 925              $expire     = 0;
 926          }
 927  
 928          if ( '' === $secure ) {
 929              $secure = is_ssl();
 930          }
 931  
 932          // Front-end cookie is secure when the auth cookie is secure and the site's home URL uses HTTPS.
 933          $secure_logged_in_cookie = $secure && 'https' === parse_url( get_option( 'home' ), PHP_URL_SCHEME );
 934  
 935          /**
 936           * Filters whether the auth cookie should only be sent over HTTPS.
 937           *
 938           * @since 3.1.0
 939           *
 940           * @param bool $secure  Whether the cookie should only be sent over HTTPS.
 941           * @param int  $user_id User ID.
 942           */
 943          $secure = apply_filters( 'secure_auth_cookie', $secure, $user_id );
 944  
 945          /**
 946           * Filters whether the logged in cookie should only be sent over HTTPS.
 947           *
 948           * @since 3.1.0
 949           *
 950           * @param bool $secure_logged_in_cookie Whether the logged in cookie should only be sent over HTTPS.
 951           * @param int  $user_id                 User ID.
 952           * @param bool $secure                  Whether the auth cookie should only be sent over HTTPS.
 953           */
 954          $secure_logged_in_cookie = apply_filters( 'secure_logged_in_cookie', $secure_logged_in_cookie, $user_id, $secure );
 955  
 956          if ( $secure ) {
 957              $auth_cookie_name = SECURE_AUTH_COOKIE;
 958              $scheme           = 'secure_auth';
 959          } else {
 960              $auth_cookie_name = AUTH_COOKIE;
 961              $scheme           = 'auth';
 962          }
 963  
 964          if ( '' === $token ) {
 965              $manager = WP_Session_Tokens::get_instance( $user_id );
 966              $token   = $manager->create( $expiration );
 967          }
 968  
 969          $auth_cookie      = wp_generate_auth_cookie( $user_id, $expiration, $scheme, $token );
 970          $logged_in_cookie = wp_generate_auth_cookie( $user_id, $expiration, 'logged_in', $token );
 971  
 972          /**
 973           * Fires immediately before the authentication cookie is set.
 974           *
 975           * @since 2.5.0
 976           * @since 4.9.0 The `$token` parameter was added.
 977           *
 978           * @param string $auth_cookie Authentication cookie value.
 979           * @param int    $expire      The time the login grace period expires as a UNIX timestamp.
 980           *                            Default is 12 hours past the cookie's expiration time.
 981           * @param int    $expiration  The time when the authentication cookie expires as a UNIX timestamp.
 982           *                            Default is 14 days from now.
 983           * @param int    $user_id     User ID.
 984           * @param string $scheme      Authentication scheme. Values include 'auth' or 'secure_auth'.
 985           * @param string $token       User's session token to use for this cookie.
 986           */
 987          do_action( 'set_auth_cookie', $auth_cookie, $expire, $expiration, $user_id, $scheme, $token );
 988  
 989          /**
 990           * Fires immediately before the logged-in authentication cookie is set.
 991           *
 992           * @since 2.6.0
 993           * @since 4.9.0 The `$token` parameter was added.
 994           *
 995           * @param string $logged_in_cookie The logged-in cookie value.
 996           * @param int    $expire           The time the login grace period expires as a UNIX timestamp.
 997           *                                 Default is 12 hours past the cookie's expiration time.
 998           * @param int    $expiration       The time when the logged-in authentication cookie expires as a UNIX timestamp.
 999           *                                 Default is 14 days from now.
1000           * @param int    $user_id          User ID.
1001           * @param string $scheme           Authentication scheme. Default 'logged_in'.
1002           * @param string $token            User's session token to use for this cookie.
1003           */
1004          do_action( 'set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in', $token );
1005  
1006          /**
1007           * Allows preventing auth cookies from actually being sent to the client.
1008           *
1009           * @since 4.7.4
1010           *
1011           * @param bool $send Whether to send auth cookies to the client.
1012           */
1013          if ( ! apply_filters( 'send_auth_cookies', true ) ) {
1014              return;
1015          }
1016  
1017          setcookie( $auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true );
1018          setcookie( $auth_cookie_name, $auth_cookie, $expire, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, $secure, true );
1019          setcookie( LOGGED_IN_COOKIE, $logged_in_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true );
1020          if ( COOKIEPATH != SITECOOKIEPATH ) {
1021              setcookie( LOGGED_IN_COOKIE, $logged_in_cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true );
1022          }
1023      }
1024  endif;
1025  
1026  if ( ! function_exists( 'wp_clear_auth_cookie' ) ) :
1027      /**
1028       * Removes all of the cookies associated with authentication.
1029       *
1030       * @since 2.5.0
1031       */
1032  	function wp_clear_auth_cookie() {
1033          /**
1034           * Fires just before the authentication cookies are cleared.
1035           *
1036           * @since 2.7.0
1037           */
1038          do_action( 'clear_auth_cookie' );
1039  
1040          /** This filter is documented in wp-includes/pluggable.php */
1041          if ( ! apply_filters( 'send_auth_cookies', true ) ) {
1042              return;
1043          }
1044  
1045          // Auth cookies.
1046          setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN );
1047          setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN );
1048          setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN );
1049          setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN );
1050          setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
1051          setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
1052  
1053          // Settings cookies.
1054          setcookie( 'wp-settings-' . get_current_user_id(), ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
1055          setcookie( 'wp-settings-time-' . get_current_user_id(), ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
1056  
1057          // Old cookies.
1058          setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
1059          setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
1060          setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
1061          setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
1062  
1063          // Even older cookies.
1064          setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
1065          setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
1066          setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
1067          setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
1068  
1069          // Post password cookie.
1070          setcookie( 'wp-postpass_' . COOKIEHASH, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
1071      }
1072  endif;
1073  
1074  if ( ! function_exists( 'is_user_logged_in' ) ) :
1075      /**
1076       * Determines whether the current visitor is a logged in user.
1077       *
1078       * For more information on this and similar theme functions, check out
1079       * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
1080       * Conditional Tags} article in the Theme Developer Handbook.
1081       *
1082       * @since 2.0.0
1083       *
1084       * @return bool True if user is logged in, false if not logged in.
1085       */
1086  	function is_user_logged_in() {
1087          $user = wp_get_current_user();
1088  
1089          return $user->exists();
1090      }
1091  endif;
1092  
1093  if ( ! function_exists( 'auth_redirect' ) ) :
1094      /**
1095       * Checks if a user is logged in, if not it redirects them to the login page.
1096       *
1097       * When this code is called from a page, it checks to see if the user viewing the page is logged in.
1098       * If the user is not logged in, they are redirected to the login page. The user is redirected
1099       * in such a way that, upon logging in, they will be sent directly to the page they were originally
1100       * trying to access.
1101       *
1102       * @since 1.5.0
1103       */
1104  	function auth_redirect() {
1105          $secure = ( is_ssl() || force_ssl_admin() );
1106  
1107          /**
1108           * Filters whether to use a secure authentication redirect.
1109           *
1110           * @since 3.1.0
1111           *
1112           * @param bool $secure Whether to use a secure authentication redirect. Default false.
1113           */
1114          $secure = apply_filters( 'secure_auth_redirect', $secure );
1115  
1116          // If https is required and request is http, redirect.
1117          if ( $secure && ! is_ssl() && false !== strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) ) {
1118              if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
1119                  wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
1120                  exit;
1121              } else {
1122                  wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1123                  exit;
1124              }
1125          }
1126  
1127          /**
1128           * Filters the authentication redirect scheme.
1129           *
1130           * @since 2.9.0
1131           *
1132           * @param string $scheme Authentication redirect scheme. Default empty.
1133           */
1134          $scheme = apply_filters( 'auth_redirect_scheme', '' );
1135  
1136          $user_id = wp_validate_auth_cookie( '', $scheme );
1137          if ( $user_id ) {
1138              /**
1139               * Fires before the authentication redirect.
1140               *
1141               * @since 2.8.0
1142               *
1143               * @param int $user_id User ID.
1144               */
1145              do_action( 'auth_redirect', $user_id );
1146  
1147              // If the user wants ssl but the session is not ssl, redirect.
1148              if ( ! $secure && get_user_option( 'use_ssl', $user_id ) && false !== strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) ) {
1149                  if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
1150                      wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
1151                      exit;
1152                  } else {
1153                      wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1154                      exit;
1155                  }
1156              }
1157  
1158              return; // The cookie is good, so we're done.
1159          }
1160  
1161          // The cookie is no good, so force login.
1162          nocache_headers();
1163  
1164          $redirect = ( strpos( $_SERVER['REQUEST_URI'], '/options.php' ) && wp_get_referer() ) ? wp_get_referer() : set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1165  
1166          $login_url = wp_login_url( $redirect, true );
1167  
1168          wp_redirect( $login_url );
1169          exit;
1170      }
1171  endif;
1172  
1173  if ( ! function_exists( 'check_admin_referer' ) ) :
1174      /**
1175       * Ensures intent by verifying that a user was referred from another admin page with the correct security nonce.
1176       *
1177       * This function ensures the user intends to perform a given action, which helps protect against clickjacking style
1178       * attacks. It verifies intent, not authorisation, therefore it does not verify the user's capabilities. This should
1179       * be performed with `current_user_can()` or similar.
1180       *
1181       * If the nonce value is invalid, the function will exit with an "Are You Sure?" style message.
1182       *
1183       * @since 1.2.0
1184       * @since 2.5.0 The `$query_arg` parameter was added.
1185       *
1186       * @param int|string $action    The nonce action.
1187       * @param string     $query_arg Optional. Key to check for nonce in `$_REQUEST`. Default '_wpnonce'.
1188       * @return int|false 1 if the nonce is valid and generated between 0-12 hours ago,
1189       *                   2 if the nonce is valid and generated between 12-24 hours ago.
1190       *                   False if the nonce is invalid.
1191       */
1192  	function check_admin_referer( $action = -1, $query_arg = '_wpnonce' ) {
1193          if ( -1 === $action ) {
1194              _doing_it_wrong( __FUNCTION__, __( 'You should specify an action to be verified by using the first parameter.' ), '3.2.0' );
1195          }
1196  
1197          $adminurl = strtolower( admin_url() );
1198          $referer  = strtolower( wp_get_referer() );
1199          $result   = isset( $_REQUEST[ $query_arg ] ) ? wp_verify_nonce( $_REQUEST[ $query_arg ], $action ) : false;
1200  
1201          /**
1202           * Fires once the admin request has been validated or not.
1203           *
1204           * @since 1.5.1
1205           *
1206           * @param string    $action The nonce action.
1207           * @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between
1208           *                          0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.
1209           */
1210          do_action( 'check_admin_referer', $action, $result );
1211  
1212          if ( ! $result && ! ( -1 === $action && strpos( $referer, $adminurl ) === 0 ) ) {
1213              wp_nonce_ays( $action );
1214              die();
1215          }
1216  
1217          return $result;
1218      }
1219  endif;
1220  
1221  if ( ! function_exists( 'check_ajax_referer' ) ) :
1222      /**
1223       * Verifies the Ajax request to prevent processing requests external of the blog.
1224       *
1225       * @since 2.0.3
1226       *
1227       * @param int|string   $action    Action nonce.
1228       * @param false|string $query_arg Optional. Key to check for the nonce in `$_REQUEST` (since 2.5). If false,
1229       *                                `$_REQUEST` values will be evaluated for '_ajax_nonce', and '_wpnonce'
1230       *                                (in that order). Default false.
1231       * @param bool         $die       Optional. Whether to die early when the nonce cannot be verified.
1232       *                                Default true.
1233       * @return int|false 1 if the nonce is valid and generated between 0-12 hours ago,
1234       *                   2 if the nonce is valid and generated between 12-24 hours ago.
1235       *                   False if the nonce is invalid.
1236       */
1237  	function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) {
1238          if ( -1 == $action ) {
1239              _doing_it_wrong( __FUNCTION__, __( 'You should specify an action to be verified by using the first parameter.' ), '4.7.0' );
1240          }
1241  
1242          $nonce = '';
1243  
1244          if ( $query_arg && isset( $_REQUEST[ $query_arg ] ) ) {
1245              $nonce = $_REQUEST[ $query_arg ];
1246          } elseif ( isset( $_REQUEST['_ajax_nonce'] ) ) {
1247              $nonce = $_REQUEST['_ajax_nonce'];
1248          } elseif ( isset( $_REQUEST['_wpnonce'] ) ) {
1249              $nonce = $_REQUEST['_wpnonce'];
1250          }
1251  
1252          $result = wp_verify_nonce( $nonce, $action );
1253  
1254          /**
1255           * Fires once the Ajax request has been validated or not.
1256           *
1257           * @since 2.1.0
1258           *
1259           * @param string    $action The Ajax nonce action.
1260           * @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between
1261           *                          0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.
1262           */
1263          do_action( 'check_ajax_referer', $action, $result );
1264  
1265          if ( $die && false === $result ) {
1266              if ( wp_doing_ajax() ) {
1267                  wp_die( -1, 403 );
1268              } else {
1269                  die( '-1' );
1270              }
1271          }
1272  
1273          return $result;
1274      }
1275  endif;
1276  
1277  if ( ! function_exists( 'wp_redirect' ) ) :
1278      /**
1279       * Redirects to another page.
1280       *
1281       * Note: wp_redirect() does not exit automatically, and should almost always be
1282       * followed by a call to `exit;`:
1283       *
1284       *     wp_redirect( $url );
1285       *     exit;
1286       *
1287       * Exiting can also be selectively manipulated by using wp_redirect() as a conditional
1288       * in conjunction with the {@see 'wp_redirect'} and {@see 'wp_redirect_location'} filters:
1289       *
1290       *     if ( wp_redirect( $url ) ) {
1291       *         exit;
1292       *     }
1293       *
1294       * @since 1.5.1
1295       * @since 5.1.0 The `$x_redirect_by` parameter was added.
1296       * @since 5.4.0 On invalid status codes, wp_die() is called.
1297       *
1298       * @global bool $is_IIS
1299       *
1300       * @param string $location      The path or URL to redirect to.
1301       * @param int    $status        Optional. HTTP response status code to use. Default '302' (Moved Temporarily).
1302       * @param string $x_redirect_by Optional. The application doing the redirect. Default 'WordPress'.
1303       * @return bool False if the redirect was cancelled, true otherwise.
1304       */
1305  	function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
1306          global $is_IIS;
1307  
1308          /**
1309           * Filters the redirect location.
1310           *
1311           * @since 2.1.0
1312           *
1313           * @param string $location The path or URL to redirect to.
1314           * @param int    $status   The HTTP response status code to use.
1315           */
1316          $location = apply_filters( 'wp_redirect', $location, $status );
1317  
1318          /**
1319           * Filters the redirect HTTP response status code to use.
1320           *
1321           * @since 2.3.0
1322           *
1323           * @param int    $status   The HTTP response status code to use.
1324           * @param string $location The path or URL to redirect to.
1325           */
1326          $status = apply_filters( 'wp_redirect_status', $status, $location );
1327  
1328          if ( ! $location ) {
1329              return false;
1330          }
1331  
1332          if ( $status < 300 || 399 < $status ) {
1333              wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
1334          }
1335  
1336          $location = wp_sanitize_redirect( $location );
1337  
1338          if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
1339              status_header( $status ); // This causes problems on IIS and some FastCGI setups.
1340          }
1341  
1342          /**
1343           * Filters the X-Redirect-By header.
1344           *
1345           * Allows applications to identify themselves when they're doing a redirect.
1346           *
1347           * @since 5.1.0
1348           *
1349           * @param string $x_redirect_by The application doing the redirect.
1350           * @param int    $status        Status code to use.
1351           * @param string $location      The path to redirect to.
1352           */
1353          $x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
1354          if ( is_string( $x_redirect_by ) ) {
1355              header( "X-Redirect-By: $x_redirect_by" );
1356          }
1357  
1358          header( "Location: $location", true, $status );
1359  
1360          return true;
1361      }
1362  endif;
1363  
1364  if ( ! function_exists( 'wp_sanitize_redirect' ) ) :
1365      /**
1366       * Sanitizes a URL for use in a redirect.
1367       *
1368       * @since 2.3.0
1369       *
1370       * @param string $location The path to redirect to.
1371       * @return string Redirect-sanitized URL.
1372       */
1373  	function wp_sanitize_redirect( $location ) {
1374          // Encode spaces.
1375          $location = str_replace( ' ', '%20', $location );
1376  
1377          $regex    = '/
1378          (
1379              (?: [\xC2-\xDF][\x80-\xBF]        # double-byte sequences   110xxxxx 10xxxxxx
1380              |   \xE0[\xA0-\xBF][\x80-\xBF]    # triple-byte sequences   1110xxxx 10xxxxxx * 2
1381              |   [\xE1-\xEC][\x80-\xBF]{2}
1382              |   \xED[\x80-\x9F][\x80-\xBF]
1383              |   [\xEE-\xEF][\x80-\xBF]{2}
1384              |   \xF0[\x90-\xBF][\x80-\xBF]{2} # four-byte sequences   11110xxx 10xxxxxx * 3
1385              |   [\xF1-\xF3][\x80-\xBF]{3}
1386              |   \xF4[\x80-\x8F][\x80-\xBF]{2}
1387          ){1,40}                              # ...one or more times
1388          )/x';
1389          $location = preg_replace_callback( $regex, '_wp_sanitize_utf8_in_redirect', $location );
1390          $location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!*\[\]()@]|i', '', $location );
1391          $location = wp_kses_no_null( $location );
1392  
1393          // Remove %0D and %0A from location.
1394          $strip = array( '%0d', '%0a', '%0D', '%0A' );
1395          return _deep_replace( $strip, $location );
1396      }
1397  
1398      /**
1399       * URL encode UTF-8 characters in a URL.
1400       *
1401       * @ignore
1402       * @since 4.2.0
1403       * @access private
1404       *
1405       * @see wp_sanitize_redirect()
1406       *
1407       * @param array $matches RegEx matches against the redirect location.
1408       * @return string URL-encoded version of the first RegEx match.
1409       */
1410  	function _wp_sanitize_utf8_in_redirect( $matches ) {
1411          return urlencode( $matches[0] );
1412      }
1413  endif;
1414  
1415  if ( ! function_exists( 'wp_safe_redirect' ) ) :
1416      /**
1417       * Performs a safe (local) redirect, using wp_redirect().
1418       *
1419       * Checks whether the $location is using an allowed host, if it has an absolute
1420       * path. A plugin can therefore set or remove allowed host(s) to or from the
1421       * list.
1422       *
1423       * If the host is not allowed, then the redirect defaults to wp-admin on the siteurl
1424       * instead. This prevents malicious redirects which redirect to another host,
1425       * but only used in a few places.
1426       *
1427       * Note: wp_safe_redirect() does not exit automatically, and should almost always be
1428       * followed by a call to `exit;`:
1429       *
1430       *     wp_safe_redirect( $url );
1431       *     exit;
1432       *
1433       * Exiting can also be selectively manipulated by using wp_safe_redirect() as a conditional
1434       * in conjunction with the {@see 'wp_redirect'} and {@see 'wp_redirect_location'} filters:
1435       *
1436       *     if ( wp_safe_redirect( $url ) ) {
1437       *         exit;
1438       *     }
1439       *
1440       * @since 2.3.0
1441       * @since 5.1.0 The return value from wp_redirect() is now passed on, and the `$x_redirect_by` parameter was added.
1442       *
1443       * @param string $location      The path or URL to redirect to.
1444       * @param int    $status        Optional. HTTP response status code to use. Default '302' (Moved Temporarily).
1445       * @param string $x_redirect_by Optional. The application doing the redirect. Default 'WordPress'.
1446       * @return bool False if the redirect was cancelled, true otherwise.
1447       */
1448  	function wp_safe_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
1449  
1450          // Need to look at the URL the way it will end up in wp_redirect().
1451          $location = wp_sanitize_redirect( $location );
1452  
1453          /**
1454           * Filters the redirect fallback URL for when the provided redirect is not safe (local).
1455           *
1456           * @since 4.3.0
1457           *
1458           * @param string $fallback_url The fallback URL to use by default.
1459           * @param int    $status       The HTTP response status code to use.
1460           */
1461          $location = wp_validate_redirect( $location, apply_filters( 'wp_safe_redirect_fallback', admin_url(), $status ) );
1462  
1463          return wp_redirect( $location, $status, $x_redirect_by );
1464      }
1465  endif;
1466  
1467  if ( ! function_exists( 'wp_validate_redirect' ) ) :
1468      /**
1469       * Validates a URL for use in a redirect.
1470       *
1471       * Checks whether the $location is using an allowed host, if it has an absolute
1472       * path. A plugin can therefore set or remove allowed host(s) to or from the
1473       * list.
1474       *
1475       * If the host is not allowed, then the redirect is to $default supplied
1476       *
1477       * @since 2.8.1
1478       *
1479       * @param string $location The redirect to validate
1480       * @param string $default  The value to return if $location is not allowed
1481       * @return string redirect-sanitized URL
1482       */
1483  	function wp_validate_redirect( $location, $default = '' ) {
1484          $location = wp_sanitize_redirect( trim( $location, " \t\n\r\0\x08\x0B" ) );
1485          // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
1486          if ( '//' === substr( $location, 0, 2 ) ) {
1487              $location = 'http:' . $location;
1488          }
1489  
1490          // In PHP 5 parse_url() may fail if the URL query part contains 'http://'.
1491          // See https://bugs.php.net/bug.php?id=38143
1492          $cut  = strpos( $location, '?' );
1493          $test = $cut ? substr( $location, 0, $cut ) : $location;
1494  
1495          $lp = parse_url( $test );
1496  
1497          // Give up if malformed URL.
1498          if ( false === $lp ) {
1499              return $default;
1500          }
1501  
1502          // Allow only 'http' and 'https' schemes. No 'data:', etc.
1503          if ( isset( $lp['scheme'] ) && ! ( 'http' === $lp['scheme'] || 'https' === $lp['scheme'] ) ) {
1504              return $default;
1505          }
1506  
1507          if ( ! isset( $lp['host'] ) && ! empty( $lp['path'] ) && '/' !== $lp['path'][0] ) {
1508              $path = '';
1509              if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
1510                  $path = dirname( parse_url( 'http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH ) . '?' );
1511                  $path = wp_normalize_path( $path );
1512              }
1513              $location = '/' . ltrim( $path . '/', '/' ) . $location;
1514          }
1515  
1516          // Reject if certain components are set but host is not.
1517          // This catches URLs like https:host.com for which parse_url() does not set the host field.
1518          if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) {
1519              return $default;
1520          }
1521  
1522          // Reject malformed components parse_url() can return on odd inputs.
1523          foreach ( array( 'user', 'pass', 'host' ) as $component ) {
1524              if ( isset( $lp[ $component ] ) && strpbrk( $lp[ $component ], ':/?#@' ) ) {
1525                  return $default;
1526              }
1527          }
1528  
1529          $wpp = parse_url( home_url() );
1530  
1531          /**
1532           * Filters the list of allowed hosts to redirect to.
1533           *
1534           * @since 2.3.0
1535           *
1536           * @param string[] $hosts An array of allowed host names.
1537           * @param string   $host  The host name of the redirect destination; empty string if not set.
1538           */
1539          $allowed_hosts = (array) apply_filters( 'allowed_redirect_hosts', array( $wpp['host'] ), isset( $lp['host'] ) ? $lp['host'] : '' );
1540  
1541          if ( isset( $lp['host'] ) && ( ! in_array( $lp['host'], $allowed_hosts, true ) && strtolower( $wpp['host'] ) !== $lp['host'] ) ) {
1542              $location = $default;
1543          }
1544  
1545          return $location;
1546      }
1547  endif;
1548  
1549  if ( ! function_exists( 'wp_notify_postauthor' ) ) :
1550      /**
1551       * Notify an author (and/or others) of a comment/trackback/pingback on a post.
1552       *
1553       * @since 1.0.0
1554       *
1555       * @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
1556       * @param string         $deprecated Not used
1557       * @return bool True on completion. False if no email addresses were specified.
1558       */
1559  	function wp_notify_postauthor( $comment_id, $deprecated = null ) {
1560          if ( null !== $deprecated ) {
1561              _deprecated_argument( __FUNCTION__, '3.8.0' );
1562          }
1563  
1564          $comment = get_comment( $comment_id );
1565          if ( empty( $comment ) || empty( $comment->comment_post_ID ) ) {
1566              return false;
1567          }
1568  
1569          $post   = get_post( $comment->comment_post_ID );
1570          $author = get_userdata( $post->post_author );
1571  
1572          // Who to notify? By default, just the post author, but others can be added.
1573          $emails = array();
1574          if ( $author ) {
1575              $emails[] = $author->user_email;
1576          }
1577  
1578          /**
1579           * Filters the list of email addresses to receive a comment notification.
1580           *
1581           * By default, only post authors are notified of comments. This filter allows
1582           * others to be added.
1583           *
1584           * @since 3.7.0
1585           *
1586           * @param string[] $emails     An array of email addresses to receive a comment notification.
1587           * @param string   $comment_id The comment ID as a numeric string.
1588           */
1589          $emails = apply_filters( 'comment_notification_recipients', $emails, $comment->comment_ID );
1590          $emails = array_filter( $emails );
1591  
1592          // If there are no addresses to send the comment to, bail.
1593          if ( ! count( $emails ) ) {
1594              return false;
1595          }
1596  
1597          // Facilitate unsetting below without knowing the keys.
1598          $emails = array_flip( $emails );
1599  
1600          /**
1601           * Filters whether to notify comment authors of their comments on their own posts.
1602           *
1603           * By default, comment authors aren't notified of their comments on their own
1604           * posts. This filter allows you to override that.
1605           *
1606           * @since 3.8.0
1607           *
1608           * @param bool   $notify     Whether to notify the post author of their own comment.
1609           *                           Default false.
1610           * @param string $comment_id The comment ID as a numeric string.
1611           */
1612          $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID );
1613  
1614          // The comment was left by the author.
1615          if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) {
1616              unset( $emails[ $author->user_email ] );
1617          }
1618  
1619          // The author moderated a comment on their own post.
1620          if ( $author && ! $notify_author && get_current_user_id() == $post->post_author ) {
1621              unset( $emails[ $author->user_email ] );
1622          }
1623  
1624          // The post author is no longer a member of the blog.
1625          if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) {
1626              unset( $emails[ $author->user_email ] );
1627          }
1628  
1629          // If there's no email to send the comment to, bail, otherwise flip array back around for use below.
1630          if ( ! count( $emails ) ) {
1631              return false;
1632          } else {
1633              $emails = array_flip( $emails );
1634          }
1635  
1636          $switched_locale = switch_to_locale( get_locale() );
1637  
1638          $comment_author_domain = '';
1639          if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) {
1640              $comment_author_domain = gethostbyaddr( $comment->comment_author_IP );
1641          }
1642  
1643          // The blogname option is escaped with esc_html() on the way into the database in sanitize_option().
1644          // We want to reverse this for the plain text arena of emails.
1645          $blogname        = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1646          $comment_content = wp_specialchars_decode( $comment->comment_content );
1647  
1648          switch ( $comment->comment_type ) {
1649              case 'trackback':
1650                  /* translators: %s: Post title. */
1651                  $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n";
1652                  /* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
1653                  $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1654                  /* translators: %s: Trackback/pingback/comment author URL. */
1655                  $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
1656                  /* translators: %s: Comment text. */
1657                  $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
1658                  $notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n";
1659                  /* translators: Trackback notification email subject. 1: Site title, 2: Post title. */
1660                  $subject = sprintf( __( '[%1$s] Trackback: "%2$s"' ), $blogname, $post->post_title );
1661                  break;
1662  
1663              case 'pingback':
1664                  /* translators: %s: Post title. */
1665                  $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n";
1666                  /* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
1667                  $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1668                  /* translators: %s: Trackback/pingback/comment author URL. */
1669                  $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
1670                  /* translators: %s: Comment text. */
1671                  $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
1672                  $notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n";
1673                  /* translators: Pingback notification email subject. 1: Site title, 2: Post title. */
1674                  $subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title );
1675                  break;
1676  
1677              default: // Comments.
1678                  /* translators: %s: Post title. */
1679                  $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
1680                  /* translators: 1: Comment author's name, 2: Comment author's IP address, 3: Comment author's hostname. */
1681                  $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1682                  /* translators: %s: Comment author email. */
1683                  $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
1684                  /* translators: %s: Trackback/pingback/comment author URL. */
1685                  $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
1686  
1687                  if ( $comment->comment_parent && user_can( $post->post_author, 'edit_comment', $comment->comment_parent ) ) {
1688                      /* translators: Comment moderation. %s: Parent comment edit URL. */
1689                      $notify_message .= sprintf( __( 'In reply to: %s' ), admin_url( "comment.php?action=editcomment&c={$comment->comment_parent}#wpbody-content" ) ) . "\r\n";
1690                  }
1691  
1692                  /* translators: %s: Comment text. */
1693                  $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
1694                  $notify_message .= __( 'You can see all comments on this post here:' ) . "\r\n";
1695                  /* translators: Comment notification email subject. 1: Site title, 2: Post title. */
1696                  $subject = sprintf( __( '[%1$s] Comment: "%2$s"' ), $blogname, $post->post_title );
1697                  break;
1698          }
1699  
1700          $notify_message .= get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n";
1701          /* translators: %s: Comment URL. */
1702          $notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n";
1703  
1704          if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) {
1705              if ( EMPTY_TRASH_DAYS ) {
1706                  /* translators: Comment moderation. %s: Comment action URL. */
1707                  $notify_message .= sprintf( __( 'Trash it: %s' ), admin_url( "comment.php?action=trash&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n";
1708              } else {
1709                  /* translators: Comment moderation. %s: Comment action URL. */
1710                  $notify_message .= sprintf( __( 'Delete it: %s' ), admin_url( "comment.php?action=delete&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n";
1711              }
1712              /* translators: Comment moderation. %s: Comment action URL. */
1713              $notify_message .= sprintf( __( 'Spam it: %s' ), admin_url( "comment.php?action=spam&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n";
1714          }
1715  
1716          $wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', wp_parse_url( network_home_url(), PHP_URL_HOST ) );
1717  
1718          if ( '' === $comment->comment_author ) {
1719              $from = "From: \"$blogname\" <$wp_email>";
1720              if ( '' !== $comment->comment_author_email ) {
1721                  $reply_to = "Reply-To: $comment->comment_author_email";
1722              }
1723          } else {
1724              $from = "From: \"$comment->comment_author\" <$wp_email>";
1725              if ( '' !== $comment->comment_author_email ) {
1726                  $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
1727              }
1728          }
1729  
1730          $message_headers = "$from\n"
1731          . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";
1732  
1733          if ( isset( $reply_to ) ) {
1734              $message_headers .= $reply_to . "\n";
1735          }
1736  
1737          /**
1738           * Filters the comment notification email text.
1739           *
1740           * @since 1.5.2
1741           *
1742           * @param string $notify_message The comment notification email text.
1743           * @param string $comment_id     Comment ID as a numeric string.
1744           */
1745          $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID );
1746  
1747          /**
1748           * Filters the comment notification email subject.
1749           *
1750           * @since 1.5.2
1751           *
1752           * @param string $subject    The comment notification email subject.
1753           * @param string $comment_id Comment ID as a numeric string.
1754           */
1755          $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID );
1756  
1757          /**
1758           * Filters the comment notification email headers.
1759           *
1760           * @since 1.5.2
1761           *
1762           * @param string $message_headers Headers for the comment notification email.
1763           * @param string $comment_id      Comment ID as a numeric string.
1764           */
1765          $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID );
1766  
1767          foreach ( $emails as $email ) {
1768              wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
1769          }
1770  
1771          if ( $switched_locale ) {
1772              restore_previous_locale();
1773          }
1774  
1775          return true;
1776      }
1777  endif;
1778  
1779  if ( ! function_exists( 'wp_notify_moderator' ) ) :
1780      /**
1781       * Notifies the moderator of the site about a new comment that is awaiting approval.
1782       *
1783       * @since 1.0.0
1784       *
1785       * @global wpdb $wpdb WordPress database abstraction object.
1786       *
1787       * Uses the {@see 'notify_moderator'} filter to determine whether the site moderator
1788       * should be notified, overriding the site setting.
1789       *
1790       * @param int $comment_id Comment ID.
1791       * @return true Always returns true.
1792       */
1793  	function wp_notify_moderator( $comment_id ) {
1794          global $wpdb;
1795  
1796          $maybe_notify = get_option( 'moderation_notify' );
1797  
1798          /**
1799           * Filters whether to send the site moderator email notifications, overriding the site setting.
1800           *
1801           * @since 4.4.0
1802           *
1803           * @param bool $maybe_notify Whether to notify blog moderator.
1804           * @param int  $comment_ID   The id of the comment for the notification.
1805           */
1806          $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id );
1807  
1808          if ( ! $maybe_notify ) {
1809              return true;
1810          }
1811  
1812          $comment = get_comment( $comment_id );
1813          $post    = get_post( $comment->comment_post_ID );
1814          $user    = get_userdata( $post->post_author );
1815          // Send to the administration and to the post author if the author can modify the comment.
1816          $emails = array( get_option( 'admin_email' ) );
1817          if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) {
1818              if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) {
1819                  $emails[] = $user->user_email;
1820              }
1821          }
1822  
1823          $switched_locale = switch_to_locale( get_locale() );
1824  
1825          $comment_author_domain = '';
1826          if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) {
1827              $comment_author_domain = gethostbyaddr( $comment->comment_author_IP );
1828          }
1829  
1830          $comments_waiting = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'" );
1831  
1832          // The blogname option is escaped with esc_html() on the way into the database in sanitize_option().
1833          // We want to reverse this for the plain text arena of emails.
1834          $blogname        = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1835          $comment_content = wp_specialchars_decode( $comment->comment_content );
1836  
1837          switch ( $comment->comment_type ) {
1838              case 'trackback':
1839                  /* translators: %s: Post title. */
1840                  $notify_message  = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
1841                  $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
1842                  /* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
1843                  $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1844                  /* translators: %s: Trackback/pingback/comment author URL. */
1845                  $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
1846                  $notify_message .= __( 'Trackback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n";
1847                  break;
1848  
1849              case 'pingback':
1850                  /* translators: %s: Post title. */
1851                  $notify_message  = sprintf( __( 'A new pingback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
1852                  $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
1853                  /* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
1854                  $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1855                  /* translators: %s: Trackback/pingback/comment author URL. */
1856                  $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
1857                  $notify_message .= __( 'Pingback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n";
1858                  break;
1859  
1860              default: // Comments.
1861                  /* translators: %s: Post title. */
1862                  $notify_message  = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
1863                  $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
1864                  /* translators: 1: Comment author's name, 2: Comment author's IP address, 3: Comment author's hostname. */
1865                  $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1866                  /* translators: %s: Comment author email. */
1867                  $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
1868                  /* translators: %s: Trackback/pingback/comment author URL. */
1869                  $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
1870  
1871                  if ( $comment->comment_parent ) {
1872                      /* translators: Comment moderation. %s: Parent comment edit URL. */
1873                      $notify_message .= sprintf( __( 'In reply to: %s' ), admin_url( "comment.php?action=editcomment&c={$comment->comment_parent}#wpbody-content" ) ) . "\r\n";
1874                  }
1875  
1876                  /* translators: %s: Comment text. */
1877                  $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
1878                  break;
1879          }
1880  
1881          /* translators: Comment moderation. %s: Comment action URL. */
1882          $notify_message .= sprintf( __( 'Approve it: %s' ), admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" ) ) . "\r\n";
1883  
1884          if ( EMPTY_TRASH_DAYS ) {
1885              /* translators: Comment moderation. %s: Comment action URL. */
1886              $notify_message .= sprintf( __( 'Trash it: %s' ), admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" ) ) . "\r\n";
1887          } else {
1888              /* translators: Comment moderation. %s: Comment action URL. */
1889              $notify_message .= sprintf( __( 'Delete it: %s' ), admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" ) ) . "\r\n";
1890          }
1891  
1892          /* translators: Comment moderation. %s: Comment action URL. */
1893          $notify_message .= sprintf( __( 'Spam it: %s' ), admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ) ) . "\r\n";
1894  
1895          $notify_message .= sprintf(
1896              /* translators: Comment moderation. %s: Number of comments awaiting approval. */
1897              _n(
1898                  'Currently %s comment is waiting for approval. Please visit the moderation panel:',
1899                  'Currently %s comments are waiting for approval. Please visit the moderation panel:',
1900                  $comments_waiting
1901              ),
1902              number_format_i18n( $comments_waiting )
1903          ) . "\r\n";
1904          $notify_message .= admin_url( 'edit-comments.php?comment_status=moderated#wpbody-content' ) . "\r\n";
1905  
1906          /* translators: Comment moderation notification email subject. 1: Site title, 2: Post title. */
1907          $subject         = sprintf( __( '[%1$s] Please moderate: "%2$s"' ), $blogname, $post->post_title );
1908          $message_headers = '';
1909  
1910          /**
1911           * Filters the list of recipients for comment moderation emails.
1912           *
1913           * @since 3.7.0
1914           *
1915           * @param string[] $emails     List of email addresses to notify for comment moderation.
1916           * @param int      $comment_id Comment ID.
1917           */
1918          $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id );
1919  
1920          /**
1921           * Filters the comment moderation email text.
1922           *
1923           * @since 1.5.2
1924           *
1925           * @param string $notify_message Text of the comment moderation email.
1926           * @param int    $comment_id     Comment ID.
1927           */
1928          $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id );
1929  
1930          /**
1931           * Filters the comment moderation email subject.
1932           *
1933           * @since 1.5.2
1934           *
1935           * @param string $subject    Subject of the comment moderation email.
1936           * @param int    $comment_id Comment ID.
1937           */
1938          $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id );
1939  
1940          /**
1941           * Filters the comment moderation email headers.
1942           *
1943           * @since 2.8.0
1944           *
1945           * @param string $message_headers Headers for the comment moderation email.
1946           * @param int    $comment_id      Comment ID.
1947           */
1948          $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id );
1949  
1950          foreach ( $emails as $email ) {
1951              wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
1952          }
1953  
1954          if ( $switched_locale ) {
1955              restore_previous_locale();
1956          }
1957  
1958          return true;
1959      }
1960  endif;
1961  
1962  if ( ! function_exists( 'wp_password_change_notification' ) ) :
1963      /**
1964       * Notify the blog admin of a user changing password, normally via email.
1965       *
1966       * @since 2.7.0
1967       *
1968       * @param WP_User $user User object.
1969       */
1970  	function wp_password_change_notification( $user ) {
1971          // Send a copy of password change notification to the admin,
1972          // but check to see if it's the admin whose password we're changing, and skip this.
1973          if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) {
1974              /* translators: %s: User name. */
1975              $message = sprintf( __( 'Password changed for user: %s' ), $user->user_login ) . "\r\n";
1976              // The blogname option is escaped with esc_html() on the way into the database in sanitize_option().
1977              // We want to reverse this for the plain text arena of emails.
1978              $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1979  
1980              $wp_password_change_notification_email = array(
1981                  'to'      => get_option( 'admin_email' ),
1982                  /* translators: Password change notification email subject. %s: Site title. */
1983                  'subject' => __( '[%s] Password Changed' ),
1984                  'message' => $message,
1985                  'headers' => '',
1986              );
1987  
1988              /**
1989               * Filters the contents of the password change notification email sent to the site admin.
1990               *
1991               * @since 4.9.0
1992               *
1993               * @param array   $wp_password_change_notification_email {
1994               *     Used to build wp_mail().
1995               *
1996               *     @type string $to      The intended recipient - site admin email address.
1997               *     @type string $subject The subject of the email.
1998               *     @type string $message The body of the email.
1999               *     @type string $headers The headers of the email.
2000               * }
2001               * @param WP_User $user     User object for user whose password was changed.
2002               * @param string  $blogname The site title.
2003               */
2004              $wp_password_change_notification_email = apply_filters( 'wp_password_change_notification_email', $wp_password_change_notification_email, $user, $blogname );
2005  
2006              wp_mail(
2007                  $wp_password_change_notification_email['to'],
2008                  wp_specialchars_decode( sprintf( $wp_password_change_notification_email['subject'], $blogname ) ),
2009                  $wp_password_change_notification_email['message'],
2010                  $wp_password_change_notification_email['headers']
2011              );
2012          }
2013      }
2014  endif;
2015  
2016  if ( ! function_exists( 'wp_new_user_notification' ) ) :
2017      /**
2018       * Email login credentials to a newly-registered user.
2019       *
2020       * A new user registration notification is also sent to admin email.
2021       *
2022       * @since 2.0.0
2023       * @since 4.3.0 The `$plaintext_pass` parameter was changed to `$notify`.
2024       * @since 4.3.1 The `$plaintext_pass` parameter was deprecated. `$notify` added as a third parameter.
2025       * @since 4.6.0 The `$notify` parameter accepts 'user' for sending notification only to the user created.
2026       *
2027       * @param int    $user_id    User ID.
2028       * @param null   $deprecated Not used (argument deprecated).
2029       * @param string $notify     Optional. Type of notification that should happen. Accepts 'admin' or an empty
2030       *                           string (admin only), 'user', or 'both' (admin and user). Default empty.
2031       */
2032  	function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) {
2033          if ( null !== $deprecated ) {
2034              _deprecated_argument( __FUNCTION__, '4.3.1' );
2035          }
2036  
2037          // Accepts only 'user', 'admin' , 'both' or default '' as $notify.
2038          if ( ! in_array( $notify, array( 'user', 'admin', 'both', '' ), true ) ) {
2039              return;
2040          }
2041  
2042          $user = get_userdata( $user_id );
2043  
2044          // The blogname option is escaped with esc_html() on the way into the database in sanitize_option().
2045          // We want to reverse this for the plain text arena of emails.
2046          $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
2047  
2048          if ( 'user' !== $notify ) {
2049              $switched_locale = switch_to_locale( get_locale() );
2050  
2051              /* translators: %s: Site title. */
2052              $message = sprintf( __( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n";
2053              /* translators: %s: User login. */
2054              $message .= sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";
2055              /* translators: %s: User email address. */
2056              $message .= sprintf( __( 'Email: %s' ), $user->user_email ) . "\r\n";
2057  
2058              $wp_new_user_notification_email_admin = array(
2059                  'to'      => get_option( 'admin_email' ),
2060                  /* translators: New user registration notification email subject. %s: Site title. */
2061                  'subject' => __( '[%s] New User Registration' ),
2062                  'message' => $message,
2063                  'headers' => '',
2064              );
2065  
2066              /**
2067               * Filters the contents of the new user notification email sent to the site admin.
2068               *
2069               * @since 4.9.0
2070               *
2071               * @param array   $wp_new_user_notification_email_admin {
2072               *     Used to build wp_mail().
2073               *
2074               *     @type string $to      The intended recipient - site admin email address.
2075               *     @type string $subject The subject of the email.
2076               *     @type string $message The body of the email.
2077               *     @type string $headers The headers of the email.
2078               * }
2079               * @param WP_User $user     User object for new user.
2080               * @param string  $blogname The site title.
2081               */
2082              $wp_new_user_notification_email_admin = apply_filters( 'wp_new_user_notification_email_admin', $wp_new_user_notification_email_admin, $user, $blogname );
2083  
2084              wp_mail(
2085                  $wp_new_user_notification_email_admin['to'],
2086                  wp_specialchars_decode( sprintf( $wp_new_user_notification_email_admin['subject'], $blogname ) ),
2087                  $wp_new_user_notification_email_admin['message'],
2088                  $wp_new_user_notification_email_admin['headers']
2089              );
2090  
2091              if ( $switched_locale ) {
2092                  restore_previous_locale();
2093              }
2094          }
2095  
2096          // `$deprecated` was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notification.
2097          if ( 'admin' === $notify || ( empty( $deprecated ) && empty( $notify ) ) ) {
2098              return;
2099          }
2100  
2101          $key = get_password_reset_key( $user );
2102          if ( is_wp_error( $key ) ) {
2103              return;
2104          }
2105  
2106          $switched_locale = switch_to_locale( get_user_locale( $user ) );
2107  
2108          /* translators: %s: User login. */
2109          $message  = sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";
2110          $message .= __( 'To set your password, visit the following address:' ) . "\r\n\r\n";
2111          $message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user->user_login ), 'login' ) . "\r\n\r\n";
2112  
2113          $message .= wp_login_url() . "\r\n";
2114  
2115          $wp_new_user_notification_email = array(
2116              'to'      => $user->user_email,
2117              /* translators: Login details notification email subject. %s: Site title. */
2118              'subject' => __( '[%s] Login Details' ),
2119              'message' => $message,
2120              'headers' => '',
2121          );
2122  
2123          /**
2124           * Filters the contents of the new user notification email sent to the new user.
2125           *
2126           * @since 4.9.0
2127           *
2128           * @param array   $wp_new_user_notification_email {
2129           *     Used to build wp_mail().
2130           *
2131           *     @type string $to      The intended recipient - New user email address.
2132           *     @type string $subject The subject of the email.
2133           *     @type string $message The body of the email.
2134           *     @type string $headers The headers of the email.
2135           * }
2136           * @param WP_User $user     User object for new user.
2137           * @param string  $blogname The site title.
2138           */
2139          $wp_new_user_notification_email = apply_filters( 'wp_new_user_notification_email', $wp_new_user_notification_email, $user, $blogname );
2140  
2141          wp_mail(
2142              $wp_new_user_notification_email['to'],
2143              wp_specialchars_decode( sprintf( $wp_new_user_notification_email['subject'], $blogname ) ),
2144              $wp_new_user_notification_email['message'],
2145              $wp_new_user_notification_email['headers']
2146          );
2147  
2148          if ( $switched_locale ) {
2149              restore_previous_locale();
2150          }
2151      }
2152  endif;
2153  
2154  if ( ! function_exists( 'wp_nonce_tick' ) ) :
2155      /**
2156       * Returns the time-dependent variable for nonce creation.
2157       *
2158       * A nonce has a lifespan of two ticks. Nonces in their second tick may be
2159       * updated, e.g. by autosave.
2160       *
2161       * @since 2.5.0
2162       *
2163       * @return float Float value rounded up to the next highest integer.
2164       */
2165  	function wp_nonce_tick() {
2166          /**
2167           * Filters the lifespan of nonces in seconds.
2168           *
2169           * @since 2.5.0
2170           *
2171           * @param int $lifespan Lifespan of nonces in seconds. Default 86,400 seconds, or one day.
2172           */
2173          $nonce_life = apply_filters( 'nonce_life', DAY_IN_SECONDS );
2174  
2175          return ceil( time() / ( $nonce_life / 2 ) );
2176      }
2177  endif;
2178  
2179  if ( ! function_exists( 'wp_verify_nonce' ) ) :
2180      /**
2181       * Verifies that a correct security nonce was used with time limit.
2182       *
2183       * A nonce is valid for 24 hours (by default).
2184       *
2185       * @since 2.0.3
2186       *
2187       * @param string     $nonce  Nonce value that was used for verification, usually via a form field.
2188       * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
2189       * @return int|false 1 if the nonce is valid and generated between 0-12 hours ago,
2190       *                   2 if the nonce is valid and generated between 12-24 hours ago.
2191       *                   False if the nonce is invalid.
2192       */
2193  	function wp_verify_nonce( $nonce, $action = -1 ) {
2194          $nonce = (string) $nonce;
2195          $user  = wp_get_current_user();
2196          $uid   = (int) $user->ID;
2197          if ( ! $uid ) {
2198              /**
2199               * Filters whether the user who generated the nonce is logged out.
2200               *
2201               * @since 3.5.0
2202               *
2203               * @param int    $uid    ID of the nonce-owning user.
2204               * @param string $action The nonce action.
2205               */
2206              $uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
2207          }
2208  
2209          if ( empty( $nonce ) ) {
2210              return false;
2211          }
2212  
2213          $token = wp_get_session_token();
2214          $i     = wp_nonce_tick();
2215  
2216          // Nonce generated 0-12 hours ago.
2217          $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
2218          if ( hash_equals( $expected, $nonce ) ) {
2219              return 1;
2220          }
2221  
2222          // Nonce generated 12-24 hours ago.
2223          $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
2224          if ( hash_equals( $expected, $nonce ) ) {
2225              return 2;
2226          }
2227  
2228          /**
2229           * Fires when nonce verification fails.
2230           *
2231           * @since 4.4.0
2232           *
2233           * @param string     $nonce  The invalid nonce.
2234           * @param string|int $action The nonce action.
2235           * @param WP_User    $user   The current user object.
2236           * @param string     $token  The user's session token.
2237           */
2238          do_action( 'wp_verify_nonce_failed', $nonce, $action, $user, $token );
2239  
2240          // Invalid nonce.
2241          return false;
2242      }
2243  endif;
2244  
2245  if ( ! function_exists( 'wp_create_nonce' ) ) :
2246      /**
2247       * Creates a cryptographic token tied to a specific action, user, user session,
2248       * and window of time.
2249       *
2250       * @since 2.0.3
2251       * @since 4.0.0 Session tokens were integrated with nonce creation
2252       *
2253       * @param string|int $action Scalar value to add context to the nonce.
2254       * @return string The token.
2255       */
2256  	function wp_create_nonce( $action = -1 ) {
2257          $user = wp_get_current_user();
2258          $uid  = (int) $user->ID;
2259          if ( ! $uid ) {
2260              /** This filter is documented in wp-includes/pluggable.php */
2261              $uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
2262          }
2263  
2264          $token = wp_get_session_token();
2265          $i     = wp_nonce_tick();
2266  
2267          return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
2268      }
2269  endif;
2270  
2271  if ( ! function_exists( 'wp_salt' ) ) :
2272      /**
2273       * Returns a salt to add to hashes.
2274       *
2275       * Salts are created using secret keys. Secret keys are located in two places:
2276       * in the database and in the wp-config.php file. The secret key in the database
2277       * is randomly generated and will be appended to the secret keys in wp-config.php.
2278       *
2279       * The secret keys in wp-config.php should be updated to strong, random keys to maximize
2280       * security. Below is an example of how the secret key constants are defined.
2281       * Do not paste this example directly into wp-config.php. Instead, have a
2282       * {@link https://api.wordpress.org/secret-key/1.1/salt/ secret key created} just
2283       * for you.
2284       *
2285       *     define('AUTH_KEY',         ' Xakm<o xQy rw4EMsLKM-?!T+,PFF})H4lzcW57AF0U@N@< >M%G4Yt>f`z]MON');
2286       *     define('SECURE_AUTH_KEY',  'LzJ}op]mr|6+![P}Ak:uNdJCJZd>(Hx.-Mh#Tz)pCIU#uGEnfFz|f ;;eU%/U^O~');
2287       *     define('LOGGED_IN_KEY',    '|i|Ux`9<p-h$aFf(qnT:sDO:D1P^wZ$$/Ra@miTJi9G;ddp_<q}6H1)o|a +&JCM');
2288       *     define('NONCE_KEY',        '%:R{[P|,s.KuMltH5}cI;/k<Gx~j!f0I)m_sIyu+&NJZ)-iO>z7X>QYR0Z_XnZ@|');
2289       *     define('AUTH_SALT',        'eZyT)-Naw]F8CwA*VaW#q*|.)g@o}||wf~@C-YSt}(dh_r6EbI#A,y|nU2{B#JBW');
2290       *     define('SECURE_AUTH_SALT', '!=oLUTXh,QW=H `}`L|9/^4-3 STz},T(w}W<I`.JjPi)<Bmf1v,HpGe}T1:Xt7n');
2291       *     define('LOGGED_IN_SALT',   '+XSqHc;@Q*K_b|Z?NC[3H!!EONbh.n<+=uKR:>*c(u`g~EJBf#8u#R{mUEZrozmm');
2292       *     define('NONCE_SALT',       'h`GXHhD>SLWVfg1(1(N{;.V!MoE(SfbA_ksP@&`+AycHcAV$+?@3q+rxV{%^VyKT');
2293       *
2294       * Salting passwords helps against tools which has stored hashed values of
2295       * common dictionary strings. The added values makes it harder to crack.
2296       *
2297       * @since 2.5.0
2298       *
2299       * @link https://api.wordpress.org/secret-key/1.1/salt/ Create secrets for wp-config.php
2300       *
2301       * @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce)
2302       * @return string Salt value
2303       */
2304  	function wp_salt( $scheme = 'auth' ) {
2305          static $cached_salts = array();
2306          if ( isset( $cached_salts[ $scheme ] ) ) {
2307              /**
2308               * Filters the WordPress salt.
2309               *
2310               * @since 2.5.0
2311               *
2312               * @param string $cached_salt Cached salt for the given scheme.
2313               * @param string $scheme      Authentication scheme. Values include 'auth',
2314               *                            'secure_auth', 'logged_in', and 'nonce'.
2315               */
2316              return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme );
2317          }
2318  
2319          static $duplicated_keys;
2320          if ( null === $duplicated_keys ) {
2321              $duplicated_keys = array( 'put your unique phrase here' => true );
2322              foreach ( array( 'AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET' ) as $first ) {
2323                  foreach ( array( 'KEY', 'SALT' ) as $second ) {
2324                      if ( ! defined( "{$first}_{$second}" ) ) {
2325                          continue;
2326                      }
2327                      $value                     = constant( "{$first}_{$second}" );
2328                      $duplicated_keys[ $value ] = isset( $duplicated_keys[ $value ] );
2329                  }
2330              }
2331          }
2332  
2333          $values = array(
2334              'key'  => '',
2335              'salt' => '',
2336          );
2337          if ( defined( 'SECRET_KEY' ) && SECRET_KEY && empty( $duplicated_keys[ SECRET_KEY ] ) ) {
2338              $values['key'] = SECRET_KEY;
2339          }
2340          if ( 'auth' === $scheme && defined( 'SECRET_SALT' ) && SECRET_SALT && empty( $duplicated_keys[ SECRET_SALT ] ) ) {
2341              $values['salt'] = SECRET_SALT;
2342          }
2343  
2344          if ( in_array( $scheme, array( 'auth', 'secure_auth', 'logged_in', 'nonce' ), true ) ) {
2345              foreach ( array( 'key', 'salt' ) as $type ) {
2346                  $const = strtoupper( "{$scheme}_{$type}" );
2347                  if ( defined( $const ) && constant( $const ) && empty( $duplicated_keys[ constant( $const ) ] ) ) {
2348                      $values[ $type ] = constant( $const );
2349                  } elseif ( ! $values[ $type ] ) {
2350                      $values[ $type ] = get_site_option( "{$scheme}_{$type}" );
2351                      if ( ! $values[ $type ] ) {
2352                          $values[ $type ] = wp_generate_password( 64, true, true );
2353                          update_site_option( "{$scheme}_{$type}", $values[ $type ] );
2354                      }
2355                  }
2356              }
2357          } else {
2358              if ( ! $values['key'] ) {
2359                  $values['key'] = get_site_option( 'secret_key' );
2360                  if ( ! $values['key'] ) {
2361                      $values['key'] = wp_generate_password( 64, true, true );
2362                      update_site_option( 'secret_key', $values['key'] );
2363                  }
2364              }
2365              $values['salt'] = hash_hmac( 'md5', $scheme, $values['key'] );
2366          }
2367  
2368          $cached_salts[ $scheme ] = $values['key'] . $values['salt'];
2369  
2370          /** This filter is documented in wp-includes/pluggable.php */
2371          return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme );
2372      }
2373  endif;
2374  
2375  if ( ! function_exists( 'wp_hash' ) ) :
2376      /**
2377       * Get hash of given string.
2378       *
2379       * @since 2.0.3
2380       *
2381       * @param string $data   Plain text to hash
2382       * @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce)
2383       * @return string Hash of $data
2384       */
2385  	function wp_hash( $data, $scheme = 'auth' ) {
2386          $salt = wp_salt( $scheme );
2387  
2388          return hash_hmac( 'md5', $data, $salt );
2389      }
2390  endif;
2391  
2392  if ( ! function_exists( 'wp_hash_password' ) ) :
2393      /**
2394       * Create a hash (encrypt) of a plain text password.
2395       *
2396       * For integration with other applications, this function can be overwritten to
2397       * instead use the other package password checking algorithm.
2398       *
2399       * @since 2.5.0
2400       *
2401       * @global PasswordHash $wp_hasher PHPass object
2402       *
2403       * @param string $password Plain text user password to hash
2404       * @return string The hash string of the password
2405       */
2406  	function wp_hash_password( $password ) {
2407          global $wp_hasher;
2408  
2409          if ( empty( $wp_hasher ) ) {
2410              require_once  ABSPATH . WPINC . '/class-phpass.php';
2411              // By default, use the portable hash from phpass.
2412              $wp_hasher = new PasswordHash( 8, true );
2413          }
2414  
2415          return $wp_hasher->HashPassword( trim( $password ) );
2416      }
2417  endif;
2418  
2419  if ( ! function_exists( 'wp_check_password' ) ) :
2420      /**
2421       * Checks the plaintext password against the encrypted Password.
2422       *
2423       * Maintains compatibility between old version and the new cookie authentication
2424       * protocol using PHPass library. The $hash parameter is the encrypted password
2425       * and the function compares the plain text password when encrypted similarly
2426       * against the already encrypted password to see if they match.
2427       *
2428       * For integration with other applications, this function can be overwritten to
2429       * instead use the other package password checking algorithm.
2430       *
2431       * @since 2.5.0
2432       *
2433       * @global PasswordHash $wp_hasher PHPass object used for checking the password
2434       *                                 against the $hash + $password
2435       * @uses PasswordHash::CheckPassword
2436       *
2437       * @param string     $password Plaintext user's password
2438       * @param string     $hash     Hash of the user's password to check against.
2439       * @param string|int $user_id  Optional. User ID.
2440       * @return bool False, if the $password does not match the hashed password
2441       */
2442  	function wp_check_password( $password, $hash, $user_id = '' ) {
2443          global $wp_hasher;
2444  
2445          // If the hash is still md5...
2446          if ( strlen( $hash ) <= 32 ) {
2447              $check = hash_equals( $hash, md5( $password ) );
2448              if ( $check && $user_id ) {
2449                  // Rehash using new hash.
2450                  wp_set_password( $password, $user_id );
2451                  $hash = wp_hash_password( $password );
2452              }
2453  
2454              /**
2455               * Filters whether the plaintext password matches the encrypted password.
2456               *
2457               * @since 2.5.0
2458               *
2459               * @param bool       $check    Whether the passwords match.
2460               * @param string     $password The plaintext password.
2461               * @param string     $hash     The hashed password.
2462               * @param string|int $user_id  User ID. Can be empty.
2463               */
2464              return apply_filters( 'check_password', $check, $password, $hash, $user_id );
2465          }
2466  
2467          // If the stored hash is longer than an MD5,
2468          // presume the new style phpass portable hash.
2469          if ( empty( $wp_hasher ) ) {
2470              require_once  ABSPATH . WPINC . '/class-phpass.php';
2471              // By default, use the portable hash from phpass.
2472              $wp_hasher = new PasswordHash( 8, true );
2473          }
2474  
2475          $check = $wp_hasher->CheckPassword( $password, $hash );
2476  
2477          /** This filter is documented in wp-includes/pluggable.php */
2478          return apply_filters( 'check_password', $check, $password, $hash, $user_id );
2479      }
2480  endif;
2481  
2482  if ( ! function_exists( 'wp_generate_password' ) ) :
2483      /**
2484       * Generates a random password drawn from the defined set of characters.
2485       *
2486       * Uses wp_rand() is used to create passwords with far less predictability
2487       * than similar native PHP functions like `rand()` or `mt_rand()`.
2488       *
2489       * @since 2.5.0
2490       *
2491       * @param int  $length              Optional. The length of password to generate. Default 12.
2492       * @param bool $special_chars       Optional. Whether to include standard special characters.
2493       *                                  Default true.
2494       * @param bool $extra_special_chars Optional. Whether to include other special characters.
2495       *                                  Used when generating secret keys and salts. Default false.
2496       * @return string The random password.
2497       */
2498  	function wp_generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) {
2499          $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
2500          if ( $special_chars ) {
2501              $chars .= '!@#$%^&*()';
2502          }
2503          if ( $extra_special_chars ) {
2504              $chars .= '-_ []{}<>~`+=,.;:/?|';
2505          }
2506  
2507          $password = '';
2508          for ( $i = 0; $i < $length; $i++ ) {
2509              $password .= substr( $chars, wp_rand( 0, strlen( $chars ) - 1 ), 1 );
2510          }
2511  
2512          /**
2513           * Filters the randomly-generated password.
2514           *
2515           * @since 3.0.0
2516           * @since 5.3.0 Added the `$length`, `$special_chars`, and `$extra_special_chars` parameters.
2517           *
2518           * @param string $password            The generated password.
2519           * @param int    $length              The length of password to generate.
2520           * @param bool   $special_chars       Whether to include standard special characters.
2521           * @param bool   $extra_special_chars Whether to include other special characters.
2522           */
2523          return apply_filters( 'random_password', $password, $length, $special_chars, $extra_special_chars );
2524      }
2525  endif;
2526  
2527  if ( ! function_exists( 'wp_rand' ) ) :
2528      /**
2529       * Generates a random number.
2530       *
2531       * @since 2.6.2
2532       * @since 4.4.0 Uses PHP7 random_int() or the random_compat library if available.
2533       *
2534       * @global string $rnd_value
2535       *
2536       * @param int $min Lower limit for the generated number
2537       * @param int $max Upper limit for the generated number
2538       * @return int A random number between min and max
2539       */
2540  	function wp_rand( $min = 0, $max = 0 ) {
2541          global $rnd_value;
2542  
2543          // Some misconfigured 32-bit environments (Entropy PHP, for example)
2544          // truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
2545          $max_random_number = 3000000000 === 2147483647 ? (float) '4294967295' : 4294967295; // 4294967295 = 0xffffffff
2546  
2547          // We only handle ints, floats are truncated to their integer value.
2548          $min = (int) $min;
2549          $max = (int) $max;
2550  
2551          // Use PHP's CSPRNG, or a compatible method.
2552          static $use_random_int_functionality = true;
2553          if ( $use_random_int_functionality ) {
2554              try {
2555                  $_max = ( 0 != $max ) ? $max : $max_random_number;
2556                  // wp_rand() can accept arguments in either order, PHP cannot.
2557                  $_max = max( $min, $_max );
2558                  $_min = min( $min, $_max );
2559                  $val  = random_int( $_min, $_max );
2560                  if ( false !== $val ) {
2561                      return absint( $val );
2562                  } else {
2563                      $use_random_int_functionality = false;
2564                  }
2565              } catch ( Error $e ) {
2566                  $use_random_int_functionality = false;
2567              } catch ( Exception $e ) {
2568                  $use_random_int_functionality = false;
2569              }
2570          }
2571  
2572          // Reset $rnd_value after 14 uses.
2573          // 32 (md5) + 40 (sha1) + 40 (sha1) / 8 = 14 random numbers from $rnd_value.
2574          if ( strlen( $rnd_value ) < 8 ) {
2575              if ( defined( 'WP_SETUP_CONFIG' ) ) {
2576                  static $seed = '';
2577              } else {
2578                  $seed = get_transient( 'random_seed' );
2579              }
2580              $rnd_value  = md5( uniqid( microtime() . mt_rand(), true ) . $seed );
2581              $rnd_value .= sha1( $rnd_value );
2582              $rnd_value .= sha1( $rnd_value . $seed );
2583              $seed       = md5( $seed . $rnd_value );
2584              if ( ! defined( 'WP_SETUP_CONFIG' ) && ! defined( 'WP_INSTALLING' ) ) {
2585                  set_transient( 'random_seed', $seed );
2586              }
2587          }
2588  
2589          // Take the first 8 digits for our value.
2590          $value = substr( $rnd_value, 0, 8 );
2591  
2592          // Strip the first eight, leaving the remainder for the next call to wp_rand().
2593          $rnd_value = substr( $rnd_value, 8 );
2594  
2595          $value = abs( hexdec( $value ) );
2596  
2597          // Reduce the value to be within the min - max range.
2598          if ( 0 != $max ) {
2599              $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 );
2600          }
2601  
2602          return abs( (int) $value );
2603      }
2604  endif;
2605  
2606  if ( ! function_exists( 'wp_set_password' ) ) :
2607      /**
2608       * Updates the user's password with a new encrypted one.
2609       *
2610       * For integration with other applications, this function can be overwritten to
2611       * instead use the other package password checking algorithm.
2612       *
2613       * Please note: This function should be used sparingly and is really only meant for single-time
2614       * application. Leveraging this improperly in a plugin or theme could result in an endless loop
2615       * of password resets if precautions are not taken to ensure it does not execute on every page load.
2616       *
2617       * @since 2.5.0
2618       *
2619       * @global wpdb $wpdb WordPress database abstraction object.
2620       *
2621       * @param string $password The plaintext new user password
2622       * @param int    $user_id  User ID
2623       */
2624  	function wp_set_password( $password, $user_id ) {
2625          global $wpdb;
2626  
2627          $hash = wp_hash_password( $password );
2628          $wpdb->update(
2629              $wpdb->users,
2630              array(
2631                  'user_pass'           => $hash,
2632                  'user_activation_key' => '',
2633              ),
2634              array( 'ID' => $user_id )
2635          );
2636  
2637          clean_user_cache( $user_id );
2638      }
2639  endif;
2640  
2641  if ( ! function_exists( 'get_avatar' ) ) :
2642      /**
2643       * Retrieve the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post.
2644       *
2645       * @since 2.5.0
2646       * @since 4.2.0 Optional `$args` parameter added.
2647       *
2648       * @param mixed  $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
2649       *                            user email, WP_User object, WP_Post object, or WP_Comment object.
2650       * @param int    $size        Optional. Height and width of the avatar image file in pixels. Default 96.
2651       * @param string $default     Optional. URL for the default image or a default type. Accepts '404'
2652       *                            (return a 404 instead of a default image), 'retro' (8bit), 'monsterid'
2653       *                            (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"),
2654       *                            'mystery', 'mm', or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF),
2655       *                            or 'gravatar_default' (the Gravatar logo). Default is the value of the
2656       *                            'avatar_default' option, with a fallback of 'mystery'.
2657       * @param string $alt         Optional. Alternative text to use in img tag. Default empty.
2658       * @param array  $args {
2659       *     Optional. Extra arguments to retrieve the avatar.
2660       *
2661       *     @type int          $height        Display height of the avatar in pixels. Defaults to $size.
2662       *     @type int          $width         Display width of the avatar in pixels. Defaults to $size.
2663       *     @type bool         $force_default Whether to always show the default image, never the Gravatar. Default false.
2664       *     @type string       $rating        What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
2665       *                                       judged in that order. Default is the value of the 'avatar_rating' option.
2666       *     @type string       $scheme        URL scheme to use. See set_url_scheme() for accepted values.
2667       *                                       Default null.
2668       *     @type array|string $class         Array or string of additional classes to add to the img element.
2669       *                                       Default null.
2670       *     @type bool         $force_display Whether to always show the avatar - ignores the show_avatars option.
2671       *                                       Default false.
2672       *     @type string       $loading       Value for the `loading` attribute.
2673       *                                       Default null.
2674       *     @type string       $extra_attr    HTML attributes to insert in the IMG element. Is not sanitized. Default empty.
2675       * }
2676       * @return string|false `<img>` tag for the user's avatar. False on failure.
2677       */
2678  	function get_avatar( $id_or_email, $size = 96, $default = '', $alt = '', $args = null ) {
2679          $defaults = array(
2680              // get_avatar_data() args.
2681              'size'          => 96,
2682              'height'        => null,
2683              'width'         => null,
2684              'default'       => get_option( 'avatar_default', 'mystery' ),
2685              'force_default' => false,
2686              'rating'        => get_option( 'avatar_rating' ),
2687              'scheme'        => null,
2688              'alt'           => '',
2689              'class'         => null,
2690              'force_display' => false,
2691              'loading'       => null,
2692              'extra_attr'    => '',
2693          );
2694  
2695          if ( wp_lazy_loading_enabled( 'img', 'get_avatar' ) ) {
2696              $defaults['loading'] = wp_get_loading_attr_default( 'get_avatar' );
2697          }
2698  
2699          if ( empty( $args ) ) {
2700              $args = array();
2701          }
2702  
2703          $args['size']    = (int) $size;
2704          $args['default'] = $default;
2705          $args['alt']     = $alt;
2706  
2707          $args = wp_parse_args( $args, $defaults );
2708  
2709          if ( empty( $args['height'] ) ) {
2710              $args['height'] = $args['size'];
2711          }
2712          if ( empty( $args['width'] ) ) {
2713              $args['width'] = $args['size'];
2714          }
2715  
2716          if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) {
2717              $id_or_email = get_comment( $id_or_email );
2718          }
2719  
2720          /**
2721           * Allows the HTML for a user's avatar to be returned early.
2722           *
2723           * Returning a non-null value will effectively short-circuit get_avatar(), passing
2724           * the value through the {@see 'get_avatar'} filter and returning early.
2725           *
2726           * @since 4.2.0
2727           *
2728           * @param string|null $avatar      HTML for the user's avatar. Default null.
2729           * @param mixed       $id_or_email The avatar to retrieve. Accepts a user_id, Gravatar MD5 hash,
2730           *                                 user email, WP_User object, WP_Post object, or WP_Comment object.
2731           * @param array       $args        Arguments passed to get_avatar_url(), after processing.
2732           */
2733          $avatar = apply_filters( 'pre_get_avatar', null, $id_or_email, $args );
2734  
2735          if ( ! is_null( $avatar ) ) {
2736              /** This filter is documented in wp-includes/pluggable.php */
2737              return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args );
2738          }
2739  
2740          if ( ! $args['force_display'] && ! get_option( 'show_avatars' ) ) {
2741              return false;
2742          }
2743  
2744          $url2x = get_avatar_url( $id_or_email, array_merge( $args, array( 'size' => $args['size'] * 2 ) ) );
2745  
2746          $args = get_avatar_data( $id_or_email, $args );
2747  
2748          $url = $args['url'];
2749  
2750          if ( ! $url || is_wp_error( $url ) ) {
2751              return false;
2752          }
2753  
2754          $class = array( 'avatar', 'avatar-' . (int) $args['size'], 'photo' );
2755  
2756          if ( ! $args['found_avatar'] || $args['force_default'] ) {
2757              $class[] = 'avatar-default';
2758          }
2759  
2760          if ( $args['class'] ) {
2761              if ( is_array( $args['class'] ) ) {
2762                  $class = array_merge( $class, $args['class'] );
2763              } else {
2764                  $class[] = $args['class'];
2765              }
2766          }
2767  
2768          // Add `loading` attribute.
2769          $extra_attr = $args['extra_attr'];
2770          $loading    = $args['loading'];
2771  
2772          if ( in_array( $loading, array( 'lazy', 'eager' ), true ) && ! preg_match( '/\bloading\s*=/', $extra_attr ) ) {
2773              if ( ! empty( $extra_attr ) ) {
2774                  $extra_attr .= ' ';
2775              }
2776  
2777              $extra_attr .= "loading='{$loading}'";
2778          }
2779  
2780          $avatar = sprintf(
2781              "<img alt='%s' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>",
2782              esc_attr( $args['alt'] ),
2783              esc_url( $url ),
2784              esc_url( $url2x ) . ' 2x',
2785              esc_attr( implode( ' ', $class ) ),
2786              (int) $args['height'],
2787              (int) $args['width'],
2788              $extra_attr
2789          );
2790  
2791          /**
2792           * Filters the HTML for a user's avatar.
2793           *
2794           * @since 2.5.0
2795           * @since 4.2.0 The `$args` parameter was added.
2796           *
2797           * @param string $avatar      HTML for the user's avatar.
2798           * @param mixed  $id_or_email The avatar to retrieve. Accepts a user_id, Gravatar MD5 hash,
2799           *                            user email, WP_User object, WP_Post object, or WP_Comment object.
2800           * @param int    $size        Square avatar width and height in pixels to retrieve.
2801           * @param string $default     URL for the default image or a default type. Accepts '404', 'retro', 'monsterid',
2802           *                            'wavatar', 'indenticon', 'mystery', 'mm', 'mysteryman', 'blank', or 'gravatar_default'.
2803           * @param string $alt         Alternative text to use in the avatar image tag.
2804           * @param array  $args        Arguments passed to get_avatar_data(), after processing.
2805           */
2806          return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args );
2807      }
2808  endif;
2809  
2810  if ( ! function_exists( 'wp_text_diff' ) ) :
2811      /**
2812       * Displays a human readable HTML representation of the difference between two strings.
2813       *
2814       * The Diff is available for getting the changes between versions. The output is
2815       * HTML, so the primary use is for displaying the changes. If the two strings
2816       * are equivalent, then an empty string will be returned.
2817       *
2818       * @since 2.6.0
2819       *
2820       * @see wp_parse_args() Used to change defaults to user defined settings.
2821       * @uses Text_Diff
2822       * @uses WP_Text_Diff_Renderer_Table
2823       *
2824       * @param string       $left_string  "old" (left) version of string
2825       * @param string       $right_string "new" (right) version of string
2826       * @param string|array $args {
2827       *     Associative array of options to pass to WP_Text_Diff_Renderer_Table().
2828       *
2829       *     @type string $title           Titles the diff in a manner compatible
2830       *                                   with the output. Default empty.
2831       *     @type string $title_left      Change the HTML to the left of the title.
2832       *                                   Default empty.
2833       *     @type string $title_right     Change the HTML to the right of the title.
2834       *                                   Default empty.
2835       *     @type bool   $show_split_view True for split view (two columns), false for
2836       *                                   un-split view (single column). Default true.
2837       * }
2838       * @return string Empty string if strings are equivalent or HTML with differences.
2839       */
2840  	function wp_text_diff( $left_string, $right_string, $args = null ) {
2841          $defaults = array(
2842              'title'           => '',
2843              'title_left'      => '',
2844              'title_right'     => '',
2845              'show_split_view' => true,
2846          );
2847          $args     = wp_parse_args( $args, $defaults );
2848  
2849          if ( ! class_exists( 'WP_Text_Diff_Renderer_Table', false ) ) {
2850              require  ABSPATH . WPINC . '/wp-diff.php';
2851          }
2852  
2853          $left_string  = normalize_whitespace( $left_string );
2854          $right_string = normalize_whitespace( $right_string );
2855  
2856          $left_lines  = explode( "\n", $left_string );
2857          $right_lines = explode( "\n", $right_string );
2858          $text_diff   = new Text_Diff( $left_lines, $right_lines );
2859          $renderer    = new WP_Text_Diff_Renderer_Table( $args );
2860          $diff        = $renderer->render( $text_diff );
2861  
2862          if ( ! $diff ) {
2863              return '';
2864          }
2865  
2866          $is_split_view       = ! empty( $args['show_split_view'] );
2867          $is_split_view_class = $is_split_view ? ' is-split-view' : '';
2868  
2869          $r = "<table class='diff$is_split_view_class'>\n";
2870  
2871          if ( $args['title'] ) {
2872              $r .= "<caption class='diff-title'>$args[title]</caption>\n";
2873          }
2874  
2875          if ( $args['title_left'] || $args['title_right'] ) {
2876              $r .= '<thead>';
2877          }
2878  
2879          if ( $args['title_left'] || $args['title_right'] ) {
2880              $th_or_td_left  = empty( $args['title_left'] ) ? 'td' : 'th';
2881              $th_or_td_right = empty( $args['title_right'] ) ? 'td' : 'th';
2882  
2883              $r .= "<tr class='diff-sub-title'>\n";
2884              $r .= "\t<$th_or_td_left>$args[title_left]</$th_or_td_left>\n";
2885              if ( $is_split_view ) {
2886                  $r .= "\t<$th_or_td_right>$args[title_right]</$th_or_td_right>\n";
2887              }
2888              $r .= "</tr>\n";
2889          }
2890  
2891          if ( $args['title_left'] || $args['title_right'] ) {
2892              $r .= "</thead>\n";
2893          }
2894  
2895          $r .= "<tbody>\n$diff\n</tbody>\n";
2896          $r .= '</table>';
2897  
2898          return $r;
2899      }
2900  endif;


Generated: Sun Jan 16 01:00:03 2022 Cross-referenced by PHPXref 0.7.1