array(), 'em' => array(), 'code' => array(), ); public static function boot() { add_action( 'admin_menu', array( self::class, 'menu' ) ); add_action( 'admin_post_adibridge_create_token', array( self::class, 'handle_create' ) ); add_action( 'admin_post_adibridge_revoke_token', array( self::class, 'handle_revoke' ) ); add_filter( 'plugin_action_links_' . plugin_basename( ADIBRIDGE_FILE ), array( self::class, 'action_links' ) ); } public static function menu() { add_options_page( __( 'ADI Bridge', 'adi-site-bridge' ), __( 'ADI Bridge', 'adi-site-bridge' ), 'manage_options', self::PAGE, array( self::class, 'render' ) ); } public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'adi-site-bridge' ) . '' ); return $links; } private static function url( array $args = array() ) { return add_query_arg( array_merge( array( 'page' => self::PAGE ), $args ), admin_url( 'options-general.php' ) ); } const MAX_PICKER_USERS = 200; /** Users a token may be bound to: members of this site who can edit content and may_bind() accepts. */ private static function eligible_users() { $users = get_users( array( 'blog_id' => get_current_blog_id(), 'capability' => 'edit_posts', 'orderby' => 'display_name', 'number' => self::MAX_PICKER_USERS + 1, 'fields' => 'all', ) ); return array_values( array_filter( $users, array( self::class, 'may_bind' ) ) ); } /** * May the current admin bind a token to $user? A member of this site who can edit content; * on multisite, only a super admin may bind a super admin (else a site admin could hand ADI * network-wide powers such as unfiltered_html). */ public static function may_bind( $user ) { if ( ! $user || ! user_can( $user, 'edit_posts' ) ) { return false; } // Only for users this admin could act for anyway (on multisite edit_user is super-admin only, // so site admins can bind themselves; ADI's changes are credited to the bound user). if ( get_current_user_id() !== (int) $user->ID && ! current_user_can( 'edit_user', $user->ID ) ) { return false; } if ( is_multisite() ) { if ( ! is_user_member_of_blog( $user->ID, get_current_blog_id() ) ) { return false; } if ( is_super_admin( $user->ID ) && ! is_super_admin() ) { return false; } } return true; } /** * Administrator-level users (site settings or plugins): binding a token to one is allowed but * not recommended, since whoever holds the token gets that account's reach through ADI. */ public static function is_admin_like( $user ) { return $user && ( user_can( $user, 'manage_options' ) || user_can( $user, 'install_plugins' ) ); } /** The one-time display: encrypted at rest with a key from this site's salts (not in the DB). */ private static function park_token( $token ) { $key = sodium_crypto_generichash( wp_salt( 'auth' ) . '|adibridge-once', '', SODIUM_CRYPTO_SECRETBOX_KEYBYTES ); $nonce = random_bytes( SODIUM_CRYPTO_SECRETBOX_NONCEBYTES ); set_transient( 'adibridge_new_token_' . get_current_user_id(), base64_encode( $nonce . sodium_crypto_secretbox( $token, $nonce, $key ) ), 2 * MINUTE_IN_SECONDS ); } private static function take_parked_token() { $name = 'adibridge_new_token_' . get_current_user_id(); $parked = get_transient( $name ); if ( ! $parked ) { return ''; } delete_transient( $name ); $raw = base64_decode( $parked, true ); if ( false === $raw || strlen( $raw ) <= SODIUM_CRYPTO_SECRETBOX_NONCEBYTES ) { return ''; } $key = sodium_crypto_generichash( wp_salt( 'auth' ) . '|adibridge-once', '', SODIUM_CRYPTO_SECRETBOX_KEYBYTES ); $token = sodium_crypto_secretbox_open( substr( $raw, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES ), substr( $raw, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES ), $key ); return is_string( $token ) ? $token : ''; } private static function deny() { wp_die( esc_html__( 'Sorry, you are not allowed to manage ADI Bridge tokens.', 'adi-site-bridge' ), 403 ); } public static function handle_create() { if ( ! current_user_can( 'manage_options' ) ) { self::deny(); } check_admin_referer( 'adibridge_create_token' ); if ( ! Auth::site_is_secure() ) { wp_safe_redirect( self::url( array( 'adibridge_error' => 'insecure' ) ) ); exit; } $label = isset( $_POST['label'] ) ? sanitize_text_field( wp_unslash( $_POST['label'] ) ) : ''; $user_id = isset( $_POST['user_id'] ) ? absint( $_POST['user_id'] ) : 0; $user = $user_id ? get_userdata( $user_id ) : false; if ( '' === $label || ! self::may_bind( $user ) ) { wp_safe_redirect( self::url( array( 'adibridge_error' => 'invalid' ) ) ); exit; } $token = Auth::create( $label, $user->ID, get_current_user_id() ); // Shown once: parked (encrypted) for this admin only, for two minutes, deleted on first display. self::park_token( $token ); $args = array( 'adibridge_created' => 1 ); if ( self::is_admin_like( $user ) ) { $args['adibridge_admin'] = 1; } wp_safe_redirect( self::url( $args ) ); exit; } public static function handle_revoke() { if ( ! current_user_can( 'manage_options' ) ) { self::deny(); } $id = isset( $_POST['token_id'] ) ? sanitize_key( wp_unslash( $_POST['token_id'] ) ) : ''; check_admin_referer( 'adibridge_revoke_token_' . $id ); Auth::revoke( $id ); wp_safe_redirect( self::url( array( 'adibridge_revoked' => 1 ) ) ); exit; } public static function render() { if ( ! current_user_can( 'manage_options' ) ) { self::deny(); } $new_token = self::take_parked_token(); $endpoint = rest_url( Rest::NAMESPACE_V1 . '/mcp' ); $tokens = Auth::all(); $users = self::eligible_users(); ?>

Connections → WordPress Site and paste the site address below and this token.', 'adi-site-bridge' ), self::INLINE ); ?>

This connection acts as an administrator — not recommended. ADI can only read, edit, publish or trash content through it, but whoever holds this token can change, publish, unpublish or trash anything that administrator can edit.', 'adi-site-bridge' ), self::INLINE ); ?>

display_name . ' (' . $u->user_login . ')' ) : '' . esc_html__( 'deleted user', 'adi-site-bridge' ) . ''; ?>

%s

', wp_kses( sprintf( /* translators: %s: the address of Adiuvo's website. */ __( 'This edition edits content. Page and site styling, Customizer settings and widget editing are in ADI Site Bridge Pro, a free edition from adiuvo.ca.', 'adi-site-bridge' ), 'https://adiuvo.ca' ), array( 'a' => array( 'href' => true ) ) ) ); ?>

Last used stays at "never", your host may be stripping the Authorization header. Update ADI to the latest version first (1.1.28 or later): it also sends the token in a header hosts leave alone. On an older ADI, on Apache, add this line near the top of .htaccess:', 'adi-site-bridge' ), self::INLINE ); ?>

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1