├── index.php ├── api ├── index.php ├── deprecated.php └── functions.php ├── lib └── index.php ├── view ├── index.php ├── meta_box_caps.php ├── account_login.php ├── meta_box_members.php ├── meta_box_member_triggers.php ├── top_bar.php └── meta_box_options.php ├── admin ├── index.php ├── screen_addons.php ├── screen_account.php ├── walker-nav-menu.php ├── admin.php └── nav-menu.php ├── assets ├── index.php ├── js │ ├── index.php │ ├── suggest-levels.min.js │ ├── suggest-levels.js │ └── edit.min.js ├── css │ ├── index.php │ └── style.css └── img │ ├── index.php │ └── icon.png ├── helpers ├── index.php └── collection.php ├── models ├── index.php ├── level.php └── user_level.php ├── interfaces ├── index.php ├── level.php ├── user_level.php └── user.php ├── .gitignore ├── src ├── helpers.php ├── Repository │ ├── RepositoryInterface.php │ ├── AbstractRepository.php │ ├── SettingRepository.php │ └── SettingRepositoryInterface.php ├── Shortcode │ ├── ShortcodeInterface.php │ ├── ShortcodeService.php │ ├── UserLevels.php │ └── Restrict.php ├── Level │ ├── Repository │ │ ├── LevelRepositoryInterface.php │ │ └── LevelRepository.php │ └── LevelProvider.php ├── Support │ ├── WPDBAwareTrait.php │ └── InstanceTrait.php ├── Hook │ ├── HookSubscriberInterface.php │ ├── HookProviderTrait.php │ └── HookService.php ├── Provider │ ├── ProviderInterface.php │ └── AbstractProvider.php ├── Membership │ ├── MembershipProvider.php │ ├── Automator │ │ ├── UserRoleTraitAutomator.php │ │ ├── RegistrationTriggerAutomator.php │ │ ├── LoginStateTraitAutomator.php │ │ ├── UserRoleTriggerAutomator.php │ │ ├── AutomatorService.php │ │ ├── BPMemberTypeTraitAutomator.php │ │ ├── WooProductTriggerAutomator.php │ │ ├── EDDProductTriggerAutomator.php │ │ ├── GiveWPDonationTriggerAutomator.php │ │ └── AbstractAutomator.php │ └── QueryFilters.php ├── Container │ ├── ContainerInterface.php │ └── Container.php ├── Application.php ├── Module │ ├── AdminBar.php │ ├── AdminAccess.php │ ├── ContentMode.php │ └── RestApiContentProtection.php ├── Autoloader.php └── CoreProvider.php ├── .gitmodules ├── wpml-config.xml ├── phpstan.neon ├── package.json ├── composer.json ├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── phpdoc.xml ├── .php-cs-fixer.php ├── automators └── base.php ├── gulpfile.js ├── restrict-user-access.php ├── freemius.php └── docs └── api ├── graphs └── classes.html ├── reports ├── errors.html └── markers.html ├── files ├── api-deprecated.html ├── helpers-collection.html ├── interfaces-user.html ├── interfaces-level.html └── interfaces-user-level.html ├── packages └── Default.html └── css └── template.css /index.php: -------------------------------------------------------------------------------- 1 | 5 | * @license GPLv3 6 | * @copyright 2024 by Joachim Jensen 7 | */ 8 | -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 | 5 | * @license GPLv3 6 | * @copyright 2024 by Joachim Jensen 7 | */ 8 | 9 | $list_caps = new RUA_Capabilities_List(); 10 | $list_caps->prepare_items(); 11 | $list_caps->display(); 12 | -------------------------------------------------------------------------------- /src/Repository/RepositoryInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | interface RepositoryInterface 12 | { 13 | } 14 | -------------------------------------------------------------------------------- /src/Repository/AbstractRepository.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | abstract class AbstractRepository implements RepositoryInterface 12 | { 13 | } 14 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/wp-content-aware-engine"] 2 | path = lib/wp-content-aware-engine 3 | url = git@github.com:intoxstudio/wp-content-aware-engine.git 4 | [submodule "lib/wp-db-updater"] 5 | path = lib/wp-db-updater 6 | url = git@github.com:intoxstudio/wp-db-updater.git 7 | [submodule "lib/freemius"] 8 | path = lib/freemius 9 | url = git@github.com:intoxstudio/wordpress-sdk.git 10 | -------------------------------------------------------------------------------- /src/Shortcode/ShortcodeInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | interface ShortcodeInterface 12 | { 13 | public function get_names(); 14 | 15 | public function get_callback($atts, $content = null); 16 | } 17 | -------------------------------------------------------------------------------- /wpml-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | _ca_post_type 4 | _ca_taxonomy 5 | 6 | 7 | restriction 8 | condition_group 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Level/Repository/LevelRepositoryInterface.php: -------------------------------------------------------------------------------- 1 | 11 | * @license https://www.gnu.org/licenses/gpl-3.0.html 12 | */ 13 | interface LevelRepositoryInterface extends RepositoryInterface 14 | { 15 | } 16 | -------------------------------------------------------------------------------- /src/Support/WPDBAwareTrait.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | trait WPDBAwareTrait 12 | { 13 | /** 14 | * @return \wpdb 15 | */ 16 | public function wpdb() 17 | { 18 | global $wpdb; 19 | return $wpdb; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Hook/HookSubscriberInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | interface HookSubscriberInterface 12 | { 13 | /** 14 | * @param HookService $service 15 | * @return void|array 16 | */ 17 | public function subscribe(HookService $service); 18 | } 19 | -------------------------------------------------------------------------------- /src/Provider/ProviderInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | interface ProviderInterface 12 | { 13 | /** 14 | * @return void 15 | */ 16 | public function register(); 17 | 18 | /** 19 | * @return void 20 | */ 21 | public function boot(); 22 | } 23 | -------------------------------------------------------------------------------- /src/Provider/AbstractProvider.php: -------------------------------------------------------------------------------- 1 | 11 | * @license https://www.gnu.org/licenses/gpl-3.0.html 12 | */ 13 | abstract class AbstractProvider implements ProviderInterface 14 | { 15 | protected $app; 16 | 17 | public function __construct(Application $app) 18 | { 19 | $this->app = $app; 20 | } 21 | 22 | public function boot() 23 | { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /phpstan.neon: -------------------------------------------------------------------------------- 1 | includes: 2 | - vendor/phpstan/phpstan-strict-rules/rules.neon 3 | - vendor/szepeviktor/phpstan-wordpress/extension.neon 4 | 5 | parameters: 6 | level: 1 7 | paths: 8 | - src 9 | scanDirectories: 10 | - lib/wp-db-updater 11 | - lib/wp-content-aware-engine 12 | - admin 13 | - models 14 | - helpers 15 | - interfaces 16 | - api 17 | scanFiles: 18 | - level.php 19 | - freemius.php 20 | - app.php 21 | strictRules: 22 | disallowedLooseComparison: false 23 | disallowedEmpty: false 24 | disallowedShortTernary: false 25 | strictFunctionCalls: false -------------------------------------------------------------------------------- /view/account_login.php: -------------------------------------------------------------------------------- 1 | 5 | * @license GPLv3 6 | * @copyright 2024 by Joachim Jensen 7 | */ 8 | ?> 9 | 10 |
11 |

12 | 13 | 14 | 15 |

16 | 17 |
-------------------------------------------------------------------------------- /src/Support/InstanceTrait.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | trait InstanceTrait 12 | { 13 | protected static $instance; 14 | 15 | /** 16 | * @return static 17 | */ 18 | public static function instance() 19 | { 20 | if (!(static::$instance instanceof static)) { 21 | static::$instance = new static(); 22 | } 23 | return static::$instance; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /interfaces/level.php: -------------------------------------------------------------------------------- 1 | 5 | * @license GPLv3 6 | * @copyright 2024 by Joachim Jensen 7 | */ 8 | 9 | interface RUA_Level_Interface 10 | { 11 | /** 12 | * @since 2.1 13 | * @return int 0 if new 14 | */ 15 | public function get_id(); 16 | 17 | /** 18 | * @since 2.1 19 | * 20 | * @return string 21 | */ 22 | public function get_title(); 23 | 24 | /** 25 | * @since 2.1 26 | * 27 | * @return bool 28 | */ 29 | public function exists(); 30 | } 31 | -------------------------------------------------------------------------------- /src/Shortcode/ShortcodeService.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | class ShortcodeService 12 | { 13 | /** 14 | * @param ShortcodeInterface $shortcode 15 | * @return void 16 | */ 17 | public function register(ShortcodeInterface $shortcode) 18 | { 19 | foreach ($shortcode->get_names() as $name) { 20 | add_shortcode($name, [$shortcode, 'get_callback']); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "restrict-user-access", 3 | "version": "1.1.0", 4 | "description": "Restrict User Access for WordPress", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/intoxstudio/restrict-user-access.git" 8 | }, 9 | "author": "Joachim Jensen", 10 | "license": "GPL-3.0", 11 | "bugs": { 12 | "url": "https://github.com/intoxstudio/restrict-user-access/issues" 13 | }, 14 | "homepage": "https://dev.institute/wordpress-memberships/", 15 | "devDependencies": { 16 | "del": "^3.0.0", 17 | "gulp": "^4.0.0", 18 | "gulp-rename": "^1.2.2", 19 | "gulp-clean-css": "^4.0.0", 20 | "gulp-less": "^3.4.0", 21 | "gulp-purgecss": "^1.1.1", 22 | "gulp-uglify": "^3.0.2", 23 | "less-plugin-autoprefix": "^1.5.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Hook/HookProviderTrait.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | trait HookProviderTrait 12 | { 13 | /** 14 | * @param string[] $subscribers 15 | * @return void 16 | * @throws \Exception 17 | */ 18 | public function registerHooks($subscribers) 19 | { 20 | if (empty($subscribers)) { 21 | return; 22 | } 23 | 24 | $service = $this->app->get(HookService::class); 25 | foreach ($subscribers as $subscriberName) { 26 | /** @var HookSubscriberInterface $subscriber */ 27 | $subscriber = $this->app->get($subscriberName); 28 | $subscriber->subscribe($service); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "intoxstudio/restrict-user-access", 3 | "type": "project", 4 | "license": "GPL-3.0", 5 | "autoload": { 6 | "psr-4": { 7 | "RestrictUserAccess\\": "src/" 8 | }, 9 | "files": [ 10 | ] 11 | }, 12 | "authors": [ 13 | { 14 | "name": "Joachim Jensen", 15 | "email": "joachim@dev.institute" 16 | } 17 | ], 18 | "minimum-stability": "stable", 19 | "require-dev": { 20 | "php": "^7.2 || ^8.0", 21 | "friendsofphp/php-cs-fixer": "^3.89", 22 | "phpstan/phpstan": "^2.1", 23 | "szepeviktor/phpstan-wordpress": "^2.0", 24 | "phpstan/phpstan-strict-rules": "^2.0" 25 | }, 26 | "scripts": { 27 | "test:phpstan": "vendor/bin/phpstan analyse -c phpstan.neon --memory-limit=-1", 28 | "fix:cs-fixer": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Hook/HookService.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | class HookService 12 | { 13 | /** 14 | * @param string $name 15 | * @param callable $callback 16 | * @param int $priority 17 | * @param int $args 18 | * @return void 19 | */ 20 | public function add_action($name, $callback, $priority = 10, $args = 1) 21 | { 22 | add_action($name, $callback, $priority, $args); 23 | } 24 | 25 | /** 26 | * @param string $name 27 | * @param callable $callback 28 | * @param int $priority 29 | * @param int $args 30 | * @return void 31 | */ 32 | public function add_filter($name, $callback, $priority = 10, $args = 1) 33 | { 34 | add_filter($name, $callback, $priority, $args); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Level/Repository/LevelRepository.php: -------------------------------------------------------------------------------- 1 | 13 | * @license https://www.gnu.org/licenses/gpl-3.0.html 14 | */ 15 | class LevelRepository extends AbstractRepository implements LevelRepositoryInterface 16 | { 17 | public function find($id) 18 | { 19 | $wp_entity = \WP_Post::get_instance($id); 20 | if (!($wp_entity instanceof \WP_Post)) { 21 | return null; 22 | } 23 | return new RUA_Level($wp_entity); 24 | } 25 | 26 | /** 27 | * @param $args 28 | * @return \WP_Query 29 | */ 30 | protected function query($args) 31 | { 32 | $args['post_type'] = PostType::NAME; 33 | return new \WP_Query($args); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Membership/MembershipProvider.php: -------------------------------------------------------------------------------- 1 | 14 | * @license https://www.gnu.org/licenses/gpl-3.0.html 15 | */ 16 | class MembershipProvider extends AbstractProvider implements 17 | ProviderInterface 18 | { 19 | use HookProviderTrait; 20 | 21 | public function register() 22 | { 23 | $this->app->singleton(AutomatorService::class); 24 | $this->app->set(QueryFilters::class); 25 | } 26 | 27 | public function boot() 28 | { 29 | $this->registerHooks([ 30 | AutomatorService::class, 31 | QueryFilters::class, 32 | ]); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Level/LevelProvider.php: -------------------------------------------------------------------------------- 1 | 15 | * @license https://www.gnu.org/licenses/gpl-3.0.html 16 | */ 17 | class LevelProvider extends AbstractProvider implements 18 | ProviderInterface 19 | { 20 | use HookProviderTrait; 21 | 22 | public function register() 23 | { 24 | $this->app->set(LevelRepositoryInterface::class, LevelRepository::class); 25 | $this->app->set(PostType::class); 26 | } 27 | 28 | public function boot() 29 | { 30 | $this->registerHooks([ 31 | PostType::class, 32 | ]); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Shortcode/UserLevels.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | class UserLevels implements ShortcodeInterface 12 | { 13 | public function get_names() 14 | { 15 | return [ 16 | 'rua-user-levels' 17 | ]; 18 | } 19 | 20 | public function get_callback($atts, $content = null) 21 | { 22 | $a = shortcode_atts([ 23 | 'id' => null 24 | ], $atts, 'rua-user-level'); 25 | 26 | $user = rua_get_user($a['id']); 27 | 28 | $levels = \RUA_App::instance()->get_levels(); 29 | $level_names = []; 30 | foreach ($user->get_level_ids() as $id) { 31 | if (isset($levels[$id])) { 32 | $level_names[] = $levels[$id]->post_title; 33 | } 34 | } 35 | 36 | return implode(', ', $level_names); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /assets/js/suggest-levels.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * @package Restrict User Access 3 | * @author Joachim Jensen 4 | * @license GPLv3 5 | * @copyright 2024 by Joachim Jensen 6 | */ 7 | ($=>{var n={init:function(){this.suggestLevels(),this.lazyInitsuggestLevels()},suggestLevels:function(){$(".js-rua-levels").each(function(){n.createDropdown($(this))})},lazyInitsuggestLevels:function(){$("#menu-to-edit").on("click",".item-edit",function(e){var t=$(this).closest(".menu-item");t.hasClass("menu-item-edit-inactive")&&!(t=t.find(".js-rua-levels")).data("select2")&&n.createDropdown(t)})},createDropdown:function(t){t.select2({theme:"wpca",placeholder:RUA.search,minimumInputLength:0,closeOnSelect:!0,allowClear:!1,data:RUA.levels}).on("select2:selecting",function(e){t.data("forceOpen",!0)}).on("select2:close",function(e){t.data("forceOpen")&&(e.preventDefault(),t.select2("open"),t.data("forceOpen",!1))}),t.data("value")&&t.val(t.data("value").toString().split(",")).trigger("change.select2")}};$(document).ready(function(){n.init()})})(jQuery); -------------------------------------------------------------------------------- /src/Container/ContainerInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | interface ContainerInterface 12 | { 13 | /** 14 | * @param string $id 15 | * @return mixed 16 | */ 17 | public function get($id); 18 | 19 | /** 20 | * @param string $id 21 | * @return bool 22 | */ 23 | public function has($id); 24 | 25 | /** 26 | * @param string $id 27 | * @param string|callable|null $concrete 28 | * @param array $arguments 29 | * @param bool $shared 30 | * @return void 31 | */ 32 | public function set($id, $concrete = null, $arguments = [], $shared = false); 33 | 34 | /** 35 | * @param string $id 36 | * @param string|callable|null $concrete 37 | * @param array $arguments 38 | * @return void 39 | */ 40 | public function singleton($id, $concrete = null, $arguments = []); 41 | } 42 | -------------------------------------------------------------------------------- /models/level.php: -------------------------------------------------------------------------------- 1 | 5 | * @license GPLv3 6 | * @copyright 2024 by Joachim Jensen 7 | */ 8 | 9 | class RUA_Level implements RUA_Level_Interface 10 | { 11 | /** 12 | * @var WP_Post 13 | */ 14 | private $wp_post; 15 | 16 | /** 17 | * @since 2.1 18 | * @param WP_Post|null $post 19 | */ 20 | public function __construct(?WP_Post $post = null) 21 | { 22 | if (is_null($post)) { 23 | $post = new WP_Post((object)[]); 24 | } 25 | $this->wp_post = $post; 26 | } 27 | 28 | /** 29 | * @inheritDoc 30 | */ 31 | public function get_id() 32 | { 33 | return $this->wp_post->ID; 34 | } 35 | 36 | /** 37 | * @inheritDoc 38 | */ 39 | public function get_title() 40 | { 41 | return $this->wp_post->post_title; 42 | } 43 | 44 | /** 45 | * @inheritDoc 46 | */ 47 | public function exists() 48 | { 49 | return (bool) $this->wp_post->ID; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Repository/SettingRepository.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | class SettingRepository implements SettingRepositoryInterface 12 | { 13 | public function get_int($name, $default_value = 0) 14 | { 15 | return (int) $this->get_option($name, $default_value); 16 | } 17 | 18 | public function get_float($name, $default_value = 0.0) 19 | { 20 | return (float) $this->get_option($name, $default_value); 21 | } 22 | 23 | public function get_string($name, $default_value = '') 24 | { 25 | return (string) $this->get_option($name, $default_value); 26 | } 27 | 28 | public function get_bool($name, $default_value = false) 29 | { 30 | return (bool) $this->get_option($name, $default_value); 31 | } 32 | 33 | private function get_option($name, $default_value) 34 | { 35 | return \get_option($name, $default_value); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Repository/SettingRepositoryInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html 10 | */ 11 | interface SettingRepositoryInterface extends RepositoryInterface 12 | { 13 | /** 14 | * @param string $name 15 | * @param int $default_value 16 | * @return int 17 | */ 18 | public function get_int($name, $default_value = 0); 19 | 20 | /** 21 | * @param string $name 22 | * @param float $default_value 23 | * @return float 24 | */ 25 | public function get_float($name, $default_value = 0.0); 26 | 27 | /** 28 | * @param string $name 29 | * @param string $default_value 30 | * @return string 31 | */ 32 | public function get_string($name, $default_value = ''); 33 | 34 | /** 35 | * @param string $name 36 | * @param bool $default_value 37 | * @return bool 38 | */ 39 | public function get_bool($name, $default_value = false); 40 | } 41 | -------------------------------------------------------------------------------- /admin/screen_addons.php: -------------------------------------------------------------------------------- 1 | 5 | * @license GPLv3 6 | * @copyright 2024 by Joachim Jensen 7 | */ 8 | 9 | defined('ABSPATH') || exit; 10 | 11 | class RUA_Admin_Screen_Addons extends RUA_Admin 12 | { 13 | /** @var Freemius */ 14 | protected $freemius; 15 | 16 | public function __construct($freemius) 17 | { 18 | parent::__construct(); 19 | $this->freemius = $freemius; 20 | } 21 | 22 | /** 23 | * @inheritDoc 24 | */ 25 | public function get_screen() 26 | { 27 | return 'user-access_page_wprua-addons'; 28 | } 29 | 30 | /** 31 | * @inheritDoc 32 | */ 33 | public function authorize_user() 34 | { 35 | return true; 36 | } 37 | 38 | /** 39 | * @inheritDoc 40 | */ 41 | public function prepare_screen() 42 | { 43 | } 44 | 45 | /** 46 | * @inheritDoc 47 | */ 48 | public function admin_hooks() 49 | { 50 | } 51 | 52 | /** 53 | * @inheritDoc 54 | */ 55 | public function add_scripts_styles() 56 | { 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Membership/Automator/UserRoleTraitAutomator.php: -------------------------------------------------------------------------------- 1 | get_id()) { 25 | return $level_ids; 26 | } 27 | 28 | $current_user = wp_get_current_user(); 29 | if ($user->get_id() !== $current_user->ID) { 30 | return $level_ids; 31 | } 32 | 33 | foreach ($this->get_level_data() as $level_id => $level_roles) { 34 | if (array_intersect($current_user->roles, $level_roles)) { 35 | $level_ids[] = $level_id; 36 | } 37 | } 38 | return $level_ids; 39 | }, 10, 2); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Application.php: -------------------------------------------------------------------------------- 1 | 16 | * @license https://www.gnu.org/licenses/gpl-3.0.html 17 | */ 18 | class Application extends Container implements ContainerInterface 19 | { 20 | use InstanceTrait; 21 | 22 | protected $providers = [ 23 | CoreProvider::class, 24 | LevelProvider::class, 25 | MembershipProvider::class 26 | ]; 27 | 28 | public function init() 29 | { 30 | $this->registerProviders(); 31 | } 32 | 33 | protected function registerProviders() 34 | { 35 | $registered = []; 36 | foreach ($this->providers as $providerClass) { 37 | $provider = new $providerClass($this); 38 | if ($provider instanceof ProviderInterface) { 39 | $provider->register(); 40 | $registered[] = $provider; 41 | } 42 | } 43 | foreach ($registered as $provider) { 44 | $provider->boot(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Membership/Automator/RegistrationTriggerAutomator.php: -------------------------------------------------------------------------------- 1 | get_level_data() as $level_id => $values) { 33 | $user->add_level($level_id); 34 | } 35 | } 36 | ); 37 | } 38 | 39 | /** 40 | * @inheritDoc 41 | */ 42 | public function search_enabled() 43 | { 44 | return false; 45 | } 46 | 47 | /** 48 | * @inheritDoc 49 | */ 50 | public function search_content($term, $page, $limit) 51 | { 52 | return []; 53 | } 54 | 55 | /** 56 | * @inheritDoc 57 | */ 58 | public function get_content_title($selected_value) 59 | { 60 | return null; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /phpdoc.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | Restrict User Access 9 | 10 | docs/api 11 | 12 | 13 | latest 14 | 15 | 16 | interfaces 17 | api 18 | helpers 19 | 20 | api 21 | 24 | 25 | php 26 | 27 | 28 | author 29 | copyright 30 | license 31 | 32 | Restrict User Access 33 | false 34 | public 35 | 36 | 37 | 38 | docs 39 | 40 | guide 41 | 42 | 43 |