| 1 |
<?php |
| 2 |
|
| 3 |
namespace AgeGate\Admin\Controller; |
| 4 |
|
| 5 |
use Asylum\Utility\Arr; |
| 6 |
use AgeGate\Common\Immutable\Constants as Immutable; |
| 7 |
use AgeGate\Admin\Settings\Restriction; |
| 8 |
use AgeGate\Common\Admin\AbstractController; |
| 9 |
|
| 10 |
class RestrictionController extends AbstractController |
| 11 |
{ |
| 12 |
use Restriction; |
| 13 |
|
| 14 |
public const PERMISSION = Immutable::RESTRICTIONS; |
| 15 |
protected const OPTION = Immutable::OPTION_RESTRICTION; |
| 16 |
|
| 17 |
protected const DATA_FILTERS = [ |
| 18 |
'redirect' => 'full_url', |
| 19 |
]; |
| 20 |
|
| 21 |
|
| 22 |
protected function required(): bool |
| 23 |
{ |
| 24 |
return current_user_can(self::PERMISSION); |
| 25 |
} |
| 26 |
|
| 27 |
public function register(): void |
| 28 |
{ |
| 29 |
add_action('admin_print_footer_scripts', function () { |
| 30 |
global $plugin_page; |
| 31 |
if ($plugin_page && strpos($plugin_page, 'age-gate') !== false) { |
| 32 |
if (! class_exists('_WP_Editors') && (! defined('DOING_AJAX') or ! DOING_AJAX)) { |
| 33 |
require_once ABSPATH.WPINC.'/class-wp-editor.php'; |
| 34 |
wp_print_styles('editor-buttons'); |
| 35 |
\_WP_Editors::wp_link_dialog(); |
| 36 |
} |
| 37 |
} |
| 38 |
}, 1); |
| 39 |
|
| 40 |
$this->menu(__('Restrictions', 'age-gate'), self::PERMISSION); |
| 41 |
} |
| 42 |
|
| 43 |
protected function data(): array |
| 44 |
{ |
| 45 |
return get_option(static::OPTION, []); |
| 46 |
} |
| 47 |
|
| 48 |
protected function fields(): array |
| 49 |
{ |
| 50 |
return $this->getRestrictionFields(); |
| 51 |
} |
| 52 |
|
| 53 |
public function enqueue(): void |
| 54 |
{ |
| 55 |
wp_enqueue_script('wplink'); |
| 56 |
} |
| 57 |
|
| 58 |
protected function rules() : array |
| 59 |
{ |
| 60 |
return [ |
| 61 |
'default_age' => 'numeric', |
| 62 |
'type' => 'alpha', |
| 63 |
'multi_age' => 'boolean', |
| 64 |
'input_type' => 'alpha', |
| 65 |
'date_format' => 'alpha_space', |
| 66 |
'button_order' => 'alpha_dash', |
| 67 |
'stepped' => 'boolean', |
| 68 |
'remember' => 'boolean', |
| 69 |
'remember_length.remember_length' => 'numeric', |
| 70 |
'remember_length.remember_time' => 'alpha', |
| 71 |
'remember_auto_check' => 'boolean', |
| 72 |
'ignore_logged' => 'boolean', |
| 73 |
'rechallenge' => 'boolean', |
| 74 |
'redirect' => 'valid_url', |
| 75 |
|
| 76 |
]; |
| 77 |
} |
| 78 |
} |
| 79 |
|