Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermaxfield committed Nov 2, 2023
2 parents 52a7f13 + 2c32336 commit 51987a2
Show file tree
Hide file tree
Showing 16 changed files with 1,648 additions and 815 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM wordpress:6.1.0
ARG wordpress_version

FROM wordpress:$wordpress_version
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && chmod +x wp-cli.phar && mv wp-cli.phar /usr/local/bin/wp
RUN apt-get update
RUN apt-get -y install vim less
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ container:
compose file. Defaults to the host machine's platform. The image used for the
`db` service does not have `linux/arm64/v8` support. On such hosts (e.g. Apple
Silicon Macs), set this to `linux/amd64`.
* `WORDPRESS_VERSION`: The WordPress version to use when building the docker
container. Must be a valid tag per https://hub.docker.com/_/wordpress/tags.
Defaults to `latest`. Note that only one container at a time is currently
supported, so when switching versions you'll need to remove the existing
dev container before running `docker-compose up -d` again.

#### Wordpress CLI
The wordpress installation includes the `wp` command line tool. Note that all
Expand Down
157 changes: 84 additions & 73 deletions class-duouniversal-settings.php

Large diffs are not rendered by default.

57 changes: 39 additions & 18 deletions class-duouniversal-utilities.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
<?php
/**
* Utility functions
*
* Provides a number of commonly-used utility functions for used
* throughout the plugin.
*
* @link https://duo.com/docs/wordpress
*
* @package Duo Universal
* @since 1.0.0
*/

namespace Duo\DuoUniversalWordpress;

class DuoUniversal_Utilities {

public function __construct(
$wordpress_helper
) {
$this->wordpress_helper = $wordpress_helper;
}

function xmlrpc_enabled() {
return defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST;
}

function duo_get_roles() {
global $wp_roles;
// $wp_roles may not be initially set if WordPress < 3.3
$wp_roles = isset( $wp_roles ) ? $wp_roles : $this->wordpress_helper->WP_Roles();
return $wp_roles;
$roles = isset( $wp_roles ) ? $wp_roles : \WP_Roles();
return $roles;
}

function duo_auth_enabled() {
Expand All @@ -26,7 +32,7 @@ function duo_auth_enabled() {
return false; // allows the XML-RPC protocol for remote publishing
}

if ( $this->duo_get_option( 'duoup_client_id', '' ) === '' || $this->duo_get_option( 'duoup_client_secret', '' ) == ''
if ( $this->duo_get_option( 'duoup_client_id', '' ) === '' || $this->duo_get_option( 'duoup_client_secret', '' ) === ''
|| $this->duo_get_option( 'duoup_api_host', '' ) === ''
) {
return false;
Expand All @@ -49,7 +55,7 @@ function duo_role_require_mfa( $user ) {
* Don't use get_user_by()
*/
if ( ! isset( $user->roles ) ) {
$user = $this->wordpress_helper->WP_User( 0, $user->user_login );
$user = $this->new_WP_User( 0, $user->user_login );
}

/*
Expand Down Expand Up @@ -77,24 +83,31 @@ function duo_get_uri() {
// paths (for which protocols are not required/enforced), and REQUEST_URI
// always includes the leading slash in the URI path.
if ( ! isset( $_SERVER['REQUEST_URI'] )
|| ( ! empty( $_SERVER['QUERY_STRING'] ) && ! strpos( $this->wordpress_helper->sanitize_url( $_SERVER['REQUEST_URI'] ), '?', 0 ) )
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
|| ( ! empty( $_SERVER['QUERY_STRING'] ) && ! strpos( \sanitize_url( $_SERVER['REQUEST_URI'] ), '?', 0 ) )
) {
$current_uri = $this->wordpress_helper->sanitize_url( substr( $_SERVER['PHP_SELF'], 1 ) );
if ( ! isset( $_SERVER['PHP_SELF'] ) ) {
throw new Exception( 'Could not determine request URI' );
}
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$current_uri = isset( $_SERVER['PHP_SELF'] ) ? substr( \sanitize_url( $_SERVER['PHP_SELF'] ), 1 ) : null;
if ( isset( $_SERVER['QUERY_STRING'] ) ) {
$current_uri = $this->wordpress_helper->sanitize_url( $current_uri . '?' . $_SERVER['QUERY_STRING'] );
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$current_uri = \sanitize_url( $current_uri . '?' . $_SERVER['QUERY_STRING'] );
}

return $current_uri;
} else {
return $this->wordpress_helper->sanitize_url( $_SERVER['REQUEST_URI'] );
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
return \sanitize_url( $_SERVER['REQUEST_URI'] );
}
}

function duo_get_option( $key, $default = '' ) {
if ( $this->wordpress_helper->is_multisite() ) {
return $this->wordpress_helper->get_site_option( $key, $default );
function duo_get_option( $key, $default_value = '' ) {
if ( \is_multisite() ) {
return \get_site_option( $key, $default_value );
} else {
return $this->wordpress_helper->get_option( $key, $default );
return \get_option( $key, $default_value );
}
}

Expand All @@ -104,4 +117,12 @@ function duo_debug_log( $message ) {
error_log( 'Duo debug: ' . $message );
}
}

function new_WP_User( $id, $name = '', $site_id = '' ) {
return new \WP_User( $id, $name, $site_id );
}

function new_WP_Error( $code, $message = '', $data = '' ) {
return new \WP_Error( $code, $message, $data );
}
}
158 changes: 0 additions & 158 deletions class-duouniversal-wordpresshelper.php

This file was deleted.

Loading

0 comments on commit 51987a2

Please sign in to comment.