self::STATUS, 'warning' => $warning, 'preview' => $preview, 'confirm_token' => $token, 'next_step' => __( 'Nothing has changed yet. Show the warning to the user and ask "Are you really sure?". Only if they say yes, call this ability again with exactly the same input plus this confirm_token. The code works once and expires in 10 minutes.', 'members' ), ); } /** * Whether a result is a confirmation request. * * @param mixed $result Ability result. * @return bool */ public static function is_request( $result ) { return is_array( $result ) && isset( $result['status'] ) && self::STATUS === $result['status']; } /** * Transient key for one user's exact change. * * @param string $ability Full ability name. * @param array $input Ability input. * @return string */ private static function key( $ability, array $input ) { unset( $input['confirm_token'] ); self::ksort_deep( $input ); return 'members_mcp_confirm_' . md5( get_current_user_id() . '|' . $ability . '|' . wp_json_encode( $input ) ); } /** * Sort keys recursively so the same change always gives the same key. * * @param array $value Value to sort in place. * @return void */ private static function ksort_deep( array &$value ) { ksort( $value ); foreach ( $value as &$item ) { if ( is_array( $item ) ) { self::ksort_deep( $item ); } } } }