Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/disable authentication #93

Merged
merged 7 commits into from
Mar 13, 2019
22 changes: 22 additions & 0 deletions src/Provider/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Cedaro\WP\Plugin\AbstractHookProvider;
use Pimple\ServiceIterator;
use SatisPress\Authentication\Server;
use SatisPress\Capabilities as Caps;

/**
* Authentication provider class.
Expand Down Expand Up @@ -44,6 +45,7 @@ public function __construct( ServiceIterator $servers ) {
*/
public function register_hooks() {
add_action( 'plugins_loaded', [ $this, 'register_authentication_servers' ], 8 );
add_filter( 'user_has_cap', [ $this, 'maybe_allow_public_access' ] );
}

/**
Expand Down Expand Up @@ -119,4 +121,24 @@ protected function get_request_path(): string {

return '/' . ltrim( $request_path, '/' );
}

bradyvercher marked this conversation as resolved.
Show resolved Hide resolved
/**
* Sets and returns all the capabilities the current user has and should have.
*
* Appends `allcaps` with satispress_download_packages
* as well as satispress_view_packages if there are no servers,
* meaning that authentication should be skipped.
*
* @param array $allcaps All capabilities the current user has.
*
* @return array
*/
public function maybe_allow_public_access( array $allcaps ): array {
if ( 0 >= \iterator_count( $this->servers ) ) {
$allcaps[ Caps::DOWNLOAD_PACKAGES ] = true;
$allcaps[ Caps::VIEW_PACKAGES ] = true;
}

return $allcaps;
}
}