$app_name,
'app_id' => $app_id,
)
);
if ( is_wp_error( $created ) ) {
$error = $created;
} else {
list( $new_password ) = $created;
if ( $success_url ) {
$redirect = add_query_arg(
array(
'site_url' => urlencode( site_url() ),
'user_login' => urlencode( wp_get_current_user()->user_login ),
'password' => urlencode( $new_password ),
),
$success_url
);
}
}
}
if ( $redirect ) {
// Explicitly not using wp_safe_redirect b/c sends to arbitrary domain.
wp_redirect( $redirect );
exit;
}
}
// Used in the HTML title tag.
$title = __( 'Authorize Application' );
$app_name = ! empty( $_REQUEST['app_name'] ) ? $_REQUEST['app_name'] : '';
$app_id = ! empty( $_REQUEST['app_id'] ) ? $_REQUEST['app_id'] : '';
$success_url = ! empty( $_REQUEST['success_url'] ) ? $_REQUEST['success_url'] : null;
if ( ! empty( $_REQUEST['reject_url'] ) ) {
$reject_url = $_REQUEST['reject_url'];
} elseif ( $success_url ) {
$reject_url = add_query_arg( 'success', 'false', $success_url );
} else {
$reject_url = null;
}
$user = wp_get_current_user();
$request = compact( 'app_name', 'app_id', 'success_url', 'reject_url' );
$is_valid = wp_is_authorize_application_password_request_valid( $request, $user );
if ( is_wp_error( $is_valid ) ) {
wp_die(
__( 'The Authorize Application request is not allowed.' ) . ' ' . implode( ' ', $is_valid->get_error_messages() ),
__( 'Cannot Authorize Application' )
);
}
if ( wp_is_site_protected_by_basic_auth( 'front' ) ) {
wp_die(
__( 'Your website appears to use Basic Authentication, which is not currently compatible with application passwords.' ),
__( 'Cannot Authorize Application' ),
array(
'response' => 501,
'link_text' => __( 'Go Back' ),
'link_url' => $reject_url ? add_query_arg( 'error', 'disabled', $reject_url ) : admin_url(),
)
);
}
if ( ! wp_is_application_passwords_available_for_user( $user ) ) {
if ( wp_is_application_passwords_available() ) {
$message = __( 'Application passwords are not available for your account. Please contact the site administrator for assistance.' );
} else {
$message = __( 'Application passwords are not available.' );
}
wp_die(
$message,
__( 'Cannot Authorize Application' ),
array(
'response' => 501,
'link_text' => __( 'Go Back' ),
'link_url' => $reject_url ? add_query_arg( 'error', 'disabled', $reject_url ) : admin_url(),
)
);
}
wp_enqueue_script( 'auth-app' );
wp_localize_script(
'auth-app',
'authApp',
array(
'site_url' => site_url(),
'user_login' => $user->user_login,
'success' => $success_url,
'reject' => $reject_url ? $reject_url : admin_url(),
)
);
require_once ABSPATH . 'wp-admin/admin-header.php';
?>
get_error_message(),
array(
'type' => 'error',
)
);
}
?>
' . esc_html( $app_name ) . ''
);
?>
ID, true );
$blogs_count = count( $blogs );
if ( $blogs_count > 1 ) {
?>
the %2$s site in this installation that you have permissions on.',
'This will grant access to all %2$s sites in this installation that you have permissions on .',
$blogs_count
);
if ( is_super_admin() ) {
/* translators: 1: URL to my-sites.php, 2: Number of sites the user has. */
$message = _n(
'This will grant access to the %2$s site on the network as you have Super Admin rights .',
'This will grant access to all %2$s sites on the network as you have Super Admin rights .',
$blogs_count
);
}
printf(
$message,
admin_url( 'my-sites.php' ),
number_format_i18n( $blogs_count )
);
?>
' . sprintf(
/* translators: %s: Application name. */
esc_html__( 'Your new password for %s is:' ),
'' . esc_html( $app_name ) . ' '
) . '
' . __( 'Be sure to save this in a safe location. You will not be able to retrieve it.' ) . '
';
$args = array(
'type' => 'success',
'additional_classes' => array( 'notice-alt', 'below-h2' ),
'paragraph_wrap' => false,
);
wp_admin_notice( $message, $args );
/**
* Fires in the Authorize Application Password new password section in the no-JS version.
*
* In most cases, this should be used in combination with the {@see 'wp_application_passwords_approve_app_request_success'}
* action to ensure that both the JS and no-JS variants are handled.
*
* @since 5.6.0
* @since 5.6.1 Corrected action name and signature.
*
* @param string $new_password The newly generated application password.
* @param array $request The array of request data. All arguments are optional and may be empty.
* @param WP_User $user The user authorizing the application.
*/
do_action( 'wp_authorize_application_password_form_approved_no_js', $new_password, $request, $user );
else :
?>