PATH:
home
/
beestk
/
autocaz
/
wp-includes
<?php /** * WP_Application_Passwords class * * @package WordPress * @since 5.6.0 */ /** * Class for displaying, modifying, and sanitizing application passwords. * * @package WordPress */ #[AllowDynamicProperties] class WP_Application_Passwords { /** * The application passwords user meta key. * * @since 5.6.0 * * @var string */ const USERMETA_KEY_APPLICATION_PASSWORDS = '_application_passwords'; /** * The option name used to store whether application passwords are in use. * * @since 5.6.0 * * @var string */ const OPTION_KEY_IN_USE = 'using_application_passwords'; /** * The generated application password length. * * @since 5.6.0 * * @var int */ const PW_LENGTH = 24; /** * Checks if application passwords are being used by the site. * * This returns true if at least one application password has ever been created. * * @since 5.6.0 * * @return bool */ public static function is_in_use() { $network_id = get_main_network_id(); return (bool) get_network_option( $network_id, self::OPTION_KEY_IN_USE ); } /** * Creates a new application password. * * @since 5.6.0 * @since 5.7.0 Returns WP_Error if application name already exists. * * @param int $user_id User ID. * @param array $args { * Arguments used to create the application password. * * @type string $name The name of the application password. * @type string $app_id A UUID provided by the application to uniquely identify it. * } * @return array|WP_Error { * Application password details, or a WP_Error instance if an error occurs. * * @type string $0 The unhashed generated application password. * @type array $1 { * The details about the created password. * * @type string $uuid The unique identifier for the application password. * @type string $app_id A UUID provided by the application to uniquely identify it. * @type string $name The name of the application password. * @type string $password A one-way hash of the password. * @type int $created Unix timestamp of when the password was created. * @type null $last_used Null. * @type null $last_ip Null. * } * } */ public static function create_new_application_password( $user_id, $args = array() ) { if ( ! empty( $args['name'] ) ) { $args['name'] = sanitize_text_field( $args['name'] ); } if ( empty( $args['name'] ) ) { return new WP_Error( 'application_password_empty_name', __( 'An application name is required to create an application password.' ), array( 'status' => 400 ) ); } if ( self::application_name_exists_for_user( $user_id, $args['name'] ) ) { return new WP_Error( 'application_password_duplicate_name', __( 'Each application name should be unique.' ), array( 'status' => 409 ) ); } $new_password = wp_generate_password( static::PW_LENGTH, false ); $hashed_password = wp_hash_password( $new_password ); $new_item = array( 'uuid' => wp_generate_uuid4(), 'app_id' => empty( $args['app_id'] ) ? '' : $args['app_id'], 'name' => $args['name'], 'password' => $hashed_password, 'created' => time(), 'last_used' => null, 'last_ip' => null, ); $passwords = static::get_user_application_passwords( $user_id ); $passwords[] = $new_item; $saved = static::set_user_application_passwords( $user_id, $passwords ); if ( ! $saved ) { return new WP_Error( 'db_error', __( 'Could not save application password.' ) ); } $network_id = get_main_network_id(); if ( ! get_network_option( $network_id, self::OPTION_KEY_IN_USE ) ) { update_network_option( $network_id, self::OPTION_KEY_IN_USE, true ); } /** * Fires when an application password is created. * * @since 5.6.0 * * @param int $user_id The user ID. * @param array $new_item { * The details about the created password. * * @type string $uuid The unique identifier for the application password. * @type string $app_id A UUID provided by the application to uniquely identify it. * @type string $name The name of the application password. * @type string $password A one-way hash of the password. * @type int $created Unix timestamp of when the password was created. * @type null $last_used Null. * @type null $last_ip Null. * } * @param string $new_password The unhashed generated application password. * @param array $args { * Arguments used to create the application password. * * @type string $name The name of the application password. * @type string $app_id A UUID provided by the application to uniquely identify it. * } */ do_action( 'wp_create_application_password', $user_id, $new_item, $new_password, $args ); return array( $new_password, $new_item ); } /** * Gets a user's application passwords. * * @since 5.6.0 * * @param int $user_id User ID. * @return array { * The list of app passwords. * * @type array ...$0 { * @type string $uuid The unique identifier for the application password. * @type string $app_id A UUID provided by the application to uniquely identify it. * @type string $name The name of the application password. * @type string $password A one-way hash of the password. * @type int $created Unix timestamp of when the password was created. * @type int|null $last_used The Unix timestamp of the GMT date the application password was last used. * @type string|null $last_ip The IP address the application password was last used by. * } * } */ public static function get_user_application_passwords( $user_id ) { $passwords = get_user_meta( $user_id, static::USERMETA_KEY_APPLICATION_PASSWORDS, true ); if ( ! is_array( $passwords ) ) { return array(); } $save = false; foreach ( $passwords as $i => $password ) { if ( ! isset( $password['uuid'] ) ) { $passwords[ $i ]['uuid'] = wp_generate_uuid4(); $save = true; } } if ( $save ) { static::set_user_application_passwords( $user_id, $passwords ); } return $passwords; } /** * Gets a user's application password with the given UUID. * * @since 5.6.0 * * @param int $user_id User ID. * @param string $uuid The password's UUID. * @return array|null The application password if found, null otherwise. */ public static function get_user_application_password( $user_id, $uuid ) { $passwords = static::get_user_application_passwords( $user_id ); foreach ( $passwords as $password ) { if ( $password['uuid'] === $uuid ) { return $password; } } return null; } /** * Checks if an application password with the given name exists for this user. * * @since 5.7.0 * * @param int $user_id User ID. * @param string $name Application name. * @return bool Whether the provided application name exists. */ public static function application_name_exists_for_user( $user_id, $name ) { $passwords = static::get_user_application_passwords( $user_id ); foreach ( $passwords as $password ) { if ( strtolower( $password['name'] ) === strtolower( $name ) ) { return true; } } return false; } /** * Updates an application password. * * @since 5.6.0 * * @param int $user_id User ID. * @param string $uuid The password's UUID. * @param array $update Information about the application password to update. * @return true|WP_Error True if successful, otherwise a WP_Error instance is returned on error. */ public static function update_application_password( $user_id, $uuid, $update = array() ) { $passwords = static::get_user_application_passwords( $user_id ); foreach ( $passwords as &$item ) { if ( $item['uuid'] !== $uuid ) { continue; } if ( ! empty( $update['name'] ) ) { $update['name'] = sanitize_text_field( $update['name'] ); } $save = false; if ( ! empty( $update['name'] ) && $item['name'] !== $update['name'] ) { $item['name'] = $update['name']; $save = true; } if ( $save ) { $saved = static::set_user_application_passwords( $user_id, $passwords ); if ( ! $saved ) { return new WP_Error( 'db_error', __( 'Could not save application password.' ) ); } } /** * Fires when an application password is updated. * * @since 5.6.0 * * @param int $user_id The user ID. * @param array $item The updated app password details. * @param array $update The information to update. */ do_action( 'wp_update_application_password', $user_id, $item, $update ); return true; } return new WP_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) ); } /** * Records that an application password has been used. * * @since 5.6.0 * * @param int $user_id User ID. * @param string $uuid The password's UUID. * @return true|WP_Error True if the usage was recorded, a WP_Error if an error occurs. */ public static function record_application_password_usage( $user_id, $uuid ) { $passwords = static::get_user_application_passwords( $user_id ); foreach ( $passwords as &$password ) { if ( $password['uuid'] !== $uuid ) { continue; } // Only record activity once a day. if ( $password['last_used'] + DAY_IN_SECONDS > time() ) { return true; } $password['last_used'] = time(); $password['last_ip'] = $_SERVER['REMOTE_ADDR']; $saved = static::set_user_application_passwords( $user_id, $passwords ); if ( ! $saved ) { return new WP_Error( 'db_error', __( 'Could not save application password.' ) ); } return true; } // Specified application password not found! return new WP_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) ); } /** * Deletes an application password. * * @since 5.6.0 * * @param int $user_id User ID. * @param string $uuid The password's UUID. * @return true|WP_Error Whether the password was successfully found and deleted, a WP_Error otherwise. */ public static function delete_application_password( $user_id, $uuid ) { $passwords = static::get_user_application_passwords( $user_id ); foreach ( $passwords as $key => $item ) { if ( $item['uuid'] === $uuid ) { unset( $passwords[ $key ] ); $saved = static::set_user_application_passwords( $user_id, $passwords ); if ( ! $saved ) { return new WP_Error( 'db_error', __( 'Could not delete application password.' ) ); } /** * Fires when an application password is deleted. * * @since 5.6.0 * * @param int $user_id The user ID. * @param array $item The data about the application password. */ do_action( 'wp_delete_application_password', $user_id, $item ); return true; } } return new WP_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) ); } /** * Deletes all application passwords for the given user. * * @since 5.6.0 * * @param int $user_id User ID. * @return int|WP_Error The number of passwords that were deleted or a WP_Error on failure. */ public static function delete_all_application_passwords( $user_id ) { $passwords = static::get_user_application_passwords( $user_id ); if ( $passwords ) { $saved = static::set_user_application_passwords( $user_id, array() ); if ( ! $saved ) { return new WP_Error( 'db_error', __( 'Could not delete application passwords.' ) ); } foreach ( $passwords as $item ) { /** This action is documented in wp-includes/class-wp-application-passwords.php */ do_action( 'wp_delete_application_password', $user_id, $item ); } return count( $passwords ); } return 0; } /** * Sets a user's application passwords. * * @since 5.6.0 * * @param int $user_id User ID. * @param array $passwords Application passwords. * * @return bool */ protected static function set_user_application_passwords( $user_id, $passwords ) { return update_user_meta( $user_id, static::USERMETA_KEY_APPLICATION_PASSWORDS, $passwords ); } /** * Sanitizes and then splits a password into smaller chunks. * * @since 5.6.0 * * @param string $raw_password The raw application password. * @return string The chunked password. */ public static function chunk_password( $raw_password ) { $raw_password = preg_replace( '/[^a-z\d]/i', '', $raw_password ); return trim( chunk_split( $raw_password, 4, ' ' ) ); } }
[+]
..
[-] class-wp-http-proxy.php
[open]
[-] template.php
[open]
[+]
fonts
[-] vars.php
[open]
[-] l10n.php
[open]
[-] load.php
[open]
[-] class-wp-block-pattern-categories-registry.php
[open]
[-] class-wp-network.php
[open]
[-] capabilities.php
[open]
[-] class-wp-image-editor-imagick.php
[open]
[+]
sodium_compat
[-] class-wp-post.php
[open]
[+]
theme-compat
[-] block-editor.php
[open]
[-] class-wp-image-editor-gd.php
[open]
[-] template-canvas.php
[open]
[-] class-smtp.php
[open]
[-] class-wp-block-styles-registry.php
[open]
[-] class-wp-http-requests-response.php
[open]
[-] class-wp-widget-factory.php
[open]
[-] class-wp-http.php
[open]
[-] class-wp-theme-json.php
[open]
[-] feed-rdf.php
[open]
[-] class-wp-tax-query.php
[open]
[-] class-wp-role.php
[open]
[-] block-template-utils.php
[open]
[-] global-styles-and-settings.php
[open]
[-] class-phpass.php
[open]
[-] class-wp-site-query.php
[open]
[+]
IXR
[-] class-walker-comment.php
[open]
[-] class-wp-http-encoding.php
[open]
[-] class-wp-session-tokens.php
[open]
[-] sitemaps.php
[open]
[-] admin-bar.php
[open]
[-] class-wp-xmlrpc-server.php
[open]
[-] class-wp.php
[open]
[-] theme.php
[open]
[-] class-wp-post-type.php
[open]
[-] atomlib.php
[open]
[-] class-wp-theme-json-schema.php
[open]
[+]
sitemaps
[-] class.wp-dependencies.php
[open]
[-] rss.php
[open]
[-] registration.php
[open]
[-] taxonomy.php
[open]
[+]
style-engine
[-] shortcodes.php
[open]
[-] class-wp-http-ixr-client.php
[open]
[-] wp-diff.php
[open]
[-] class-wp-list-util.php
[open]
[-] class-walker-page-dropdown.php
[open]
[-] query.php
[open]
[-] session.php
[open]
[-] error-protection.php
[open]
[-] widgets.php
[open]
[-] class-wp-block-patterns-registry.php
[open]
[-] class-wp-http-cookie.php
[open]
[-] class-wp-duotone.php
[open]
[-] class-pop3.php
[open]
[-] class-wp-block-parser-block.php
[open]
[-] class-wp-date-query.php
[open]
[-] ms-blogs.php
[open]
[-] theme.json
[open]
[-] class-wp-recovery-mode-cookie-service.php
[open]
[-] compat.php
[open]
[-] class-wp-term.php
[open]
[-] embed.php
[open]
[-] class-wp-feed-cache.php
[open]
[-] post.php
[open]
[-] class.wp-scripts.php
[open]
[-] class-wp-text-diff-renderer-inline.php
[open]
[-] deprecated.php
[open]
[-] class-wp-image-editor.php
[open]
[-] default-filters.php
[open]
[-] class-wp-oembed-controller.php
[open]
[-] feed-rss2-comments.php
[open]
[-] ms-default-constants.php
[open]
[-] class-json.php
[open]
[-] post-formats.php
[open]
[-] category.php
[open]
[-] general-template.php
[open]
[-] revision.php
[open]
[-] pluggable.php
[open]
[+]
assets
[-] class-wp-meta-query.php
[open]
[-] class-wp-network-query.php
[open]
[+]
blocks
[-] registration-functions.php
[open]
[-] class-wp-locale-switcher.php
[open]
[-] post-thumbnail-template.php
[open]
[-] post-template.php
[open]
[-] ms-network.php
[open]
[-] http.php
[open]
[-] fonts.php
[open]
[-] class-walker-nav-menu.php
[open]
[-] ms-load.php
[open]
[-] default-widgets.php
[open]
[-] class-wp-taxonomy.php
[open]
[-] class-wp-simplepie-sanitize-kses.php
[open]
[-] class-IXR.php
[open]
[-] class-wp-term-query.php
[open]
[-] class-wp-block-type-registry.php
[open]
[-] class-wp-oembed.php
[open]
[+]
js
[-] theme-templates.php
[open]
[-] bookmark.php
[open]
[-] class-wp-widget.php
[open]
[-] plugin.php
[open]
[+]
widgets
[+]
rest-api
[-] class-wp-customize-section.php
[open]
[-] block-i18n.json
[open]
[-] feed.php
[open]
[-] class-wp-http-response.php
[open]
[-] ms-site.php
[open]
[-] class-wp-http-requests-hooks.php
[open]
[+]
Requests
[-] ms-files.php
[open]
[-] version.php
[open]
[-] class-wp-theme-json-resolver.php
[open]
[-] class-wp-block-list.php
[open]
[+]
pomo
[-] class-wp-fatal-error-handler.php
[open]
[-] functions.php
[open]
[-] class-simplepie.php
[open]
[-] class-wp-site.php
[open]
[-] ms-default-filters.php
[open]
[-] class-wp-block.php
[open]
[-] class-wp-customize-nav-menus.php
[open]
[-] template-loader.php
[open]
[-] option.php
[open]
[-] cache.php
[open]
[-] class-wp-ajax-response.php
[open]
[-] cache-compat.php
[open]
[+]
SimplePie
[-] theme-previews.php
[open]
[-] class-wp-block-supports.php
[open]
[-] pluggable-deprecated.php
[open]
[-] class-walker-category-dropdown.php
[open]
[-] rewrite.php
[open]
[-] class.wp-styles.php
[open]
[-] category-template.php
[open]
[-] class-wp-dependencies.php
[open]
[-] class-wp-recovery-mode-key-service.php
[open]
[-] meta.php
[open]
[-] blocks.php
[open]
[-] nav-menu-template.php
[open]
[-] https-detection.php
[open]
[-] class-wp-block-editor-context.php
[open]
[+]
certificates
[-] cron.php
[open]
[-] feed-atom-comments.php
[open]
[-] block-patterns.php
[open]
[-] class-wp-block-type.php
[open]
[-] class-wp-application-passwords.php
[open]
[-] class-wp-textdomain-registry.php
[open]
[-] media.php
[open]
[-] class-wp-metadata-lazyloader.php
[open]
[-] class-wp-styles.php
[open]
[-] robots-template.php
[open]
[-] feed-atom.php
[open]
[-] comment.php
[open]
[-] class-wp-http-curl.php
[open]
[-] user.php
[open]
[-] kses.php
[open]
[-] spl-autoload-compat.php
[open]
[+]
html-api
[-] class-wp-text-diff-renderer-table.php
[open]
[-] class-wp-feed-cache-transient.php
[open]
[-] class-snoopy.php
[open]
[-] class-wp-error.php
[open]
[-] locale.php
[open]
[-] class-wp-block-parser-frame.php
[open]
[-] class-wp-embed.php
[open]
[-] class-wp-comment-query.php
[open]
[-] nav-menu.php
[open]
[-] wp-db.php
[open]
[-] class-wp-recovery-mode-email-service.php
[open]
[+]
images
[-] date.php
[open]
[-] ms-settings.php
[open]
[+]
block-patterns
[-] rest-api.php
[open]
[-] class-requests.php
[open]
[-] class-wp-object-cache.php
[open]
[-] class-wp-recovery-mode-link-service.php
[open]
[-] class-wp-customize-setting.php
[open]
[-] class-wp-matchesmapregex.php
[open]
[-] class-wp-hook.php
[open]
[-] class-wp-walker.php
[open]
[-] class-walker-category.php
[open]
[-] class-wp-editor.php
[open]
[-] class-wp-recovery-mode.php
[open]
[-] class-wpdb.php
[open]
[-] class-wp-admin-bar.php
[open]
[-] class-wp-user-request.php
[open]
[-] class-wp-dependency.php
[open]
[-] class-wp-http-streams.php
[open]
[-] class-wp-customize-manager.php
[open]
[-] feed-rss2.php
[open]
[-] class-wp-navigation-fallback.php
[open]
[+]
customize
[-] class-wp-user-meta-session-tokens.php
[open]
[-] class-wp-roles.php
[open]
[-] media-template.php
[open]
[+]
ID3
[-] class-wp-theme.php
[open]
[-] class-wp-classic-to-block-menu-converter.php
[open]
[-] class-wp-scripts.php
[open]
[-] class-oembed.php
[open]
[-] class-wp-customize-panel.php
[open]
[-] functions.wp-scripts.php
[open]
[-] rss-functions.php
[open]
[-] class-wp-paused-extensions-storage.php
[open]
[-] class-feed.php
[open]
[-] class-wp-comment.php
[open]
[-] class-wp-user-query.php
[open]
[-] class-wp-user.php
[open]
[-] class-wp-customize-control.php
[open]
[-] functions.wp-styles.php
[open]
[-] class-phpmailer.php
[open]
[-] script-loader.php
[open]
[-] class-wp-block-template.php
[open]
[-] author-template.php
[open]
[-] ms-deprecated.php
[open]
[+]
css
[-] canonical.php
[open]
[-] class-wp-rewrite.php
[open]
[-] class-wp-block-parser.php
[open]
[-] class-wp-query.php
[open]
[-] class-walker-page.php
[open]
[-] bookmark-template.php
[open]
[-] class-wp-customize-widgets.php
[open]
[-] class-wp-locale.php
[open]
[+]
PHPMailer
[-] block-template.php
[open]
[-] theme-i18n.json
[open]
[-] embed-template.php
[open]
[-] feed-rss.php
[open]
[-] formatting.php
[open]
[-] update.php
[open]
[-] class-wp-simplepie-file.php
[open]
[-] link-template.php
[open]
[-] https-migration.php
[open]
[+]
php-compat
[-] comment-template.php
[open]
[-] style-engine.php
[open]
[+]
Text
[+]
block-supports
[-] class-http.php
[open]
[-] class-wp-theme-json-data.php
[open]
[-] ms-functions.php
[open]
[-] default-constants.php
[open]