PluginProbe
Age Gate / 3.7.3
Age Gate v3.7.3
3.7.3 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 All 113 releases
age-gate / src / Admin / Admin.php

Admin.php in Age Gate 3.7.3, at src/Admin/Admin.php

132 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AgeGate\Admin;
4
5 use WP_REST_Request;
6 use Asylum\Utility\Notice;
7 use AgeGate\Common\Settings;
8 use Asylum\Utility\Language;
9 use AgeGate\Admin\User\Toolbar;
10 use AgeGate\Common\Immutable\Constants;
11 use AgeGate\Admin\Controller\PostController;
12 use AgeGate\Admin\Controller\ToolsController;
13 use AgeGate\Admin\Controller\AccessController;
14 use AgeGate\Admin\Controller\ContentController;
15 use AgeGate\Admin\Controller\MessageController;
16 use AgeGate\Admin\Controller\AdvancedController;
17 use AgeGate\Admin\Controller\AppearanceController;
18 use AgeGate\Admin\Controller\RestrictionController;
19 use AgeGate\Admin\Controller\TroubleShootingController;
20
21 class Admin
22 {
23 public function __construct()
24 {
25 // add_action('init', fn() => dd(Language::getInstance()->getLanguages()));
26 add_action('init', function () {
27 new RestrictionController();
28 new MessageController();
29 new AppearanceController();
30 new AdvancedController();
31 new AccessController();
32 new ContentController();
33 new ToolsController();
34 new PostController();
35 new Toolbar();
36 new TroubleShootingController();
37 });
38
39 add_action('admin_notices', [$this, 'notices']);
40
41 $basename = plugin_basename(AGE_GATE_PATH . 'age-gate.php');
42 add_filter("plugin_action_links_" . $basename, [$this, 'actionLinks']);
43 add_filter('plugin_row_meta', [$this, 'websiteLink'], 10, 2);
44 }
45
46
47 public function notices()
48 {
49 global $pagenow, $plugin_page;
50 // $req = wp_remote_get(rest_url('/age-gate/v3/check'), [
51 // 'sslverify' => false
52 // ]);
53
54 if (!is_php_version_compatible('7.4') && strpos(sanitize_text_field($plugin_page ?: ''), 'age-gate') !== false) {
55 echo '<div id="message" class="notice notice-error"><p>' . esc_html__('Age Gate requires a minimum PHP version of 7.4 which your system does not have. You may experience some issues.', 'age-gate') . '</p></div>';
56 }
57
58 // if (wp_remote_retrieve_response_code($req) !== 200 && current_user_can(Constants::RESTRICTIONS) && strpos(sanitize_text_field($plugin_page ?: ''), 'age-gate-advanced') !== false) {
59 // echo '<div id="ag-api-error" class="notice notice-error is-dismissible"><p>' . esc_html__('Age Gate is having trouble contacting the Wordpress REST API. Is something blocking it?', 'age-gate') . '</p></div>';
60 // }
61
62 // is it an age gate page?
63 // TODO: replace with notice class. Why is it like this?
64 if ($pagenow === 'admin.php' && isset($_GET['m']) && strpos((sanitize_text_field($plugin_page ?: '')), 'age-gate') === 0) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
65 switch ((int) $_GET['m']) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
66 case 1:
67 $status = 'success';
68 $message = esc_html__('Settings saved', 'age-gate');
69 break;
70 case 0:
71 $status = 'error';
72 $message = esc_html__('Something went wrong', 'age-gate');
73 break;
74 }
75 echo sprintf('<div class="notice notice-%s"><p>%s</p></div>', esc_attr($status), esc_html($message));
76 }
77
78 if (Settings::getInstance()->disableAgeGate && current_user_can(Constants::TOOLS)) {
79 echo '<div id="message" class="notice notice-warning"><p>' . esc_html__('Age Gate is currently disabled in the Tools section and will not show for any users', 'age-gate') . '</p></div>';
80 }
81
82 foreach (Notice::get() ?? [] as $notice) {
83 echo '<div id="message" class="notice notice-' . esc_attr($notice['type'] ?? 'notice') . '"><p>' . esc_html($notice['message']) . '</p></div>';
84 }
85
86 if (is_plugin_active('age-gate-user-registration/age-gate-user-registration.php')) {
87
88 $data = get_plugin_data(WP_PLUGIN_DIR . '/age-gate-user-registration/age-gate-user-registration.php');
89
90 if ($data['Version'] ?? false) {
91 if (version_compare($data['Version'], '1.0.0', '<')) {
92 /* translators: 1: Age Gate User Registration version. 2: Aga gate version */
93 echo '<div id="message" class="notice notice-error"><p>' . esc_html(sprintf(__('Your version of Age Gate User Registration (%1$s) is not compatible with Age Gate %2$s. Please download a supported version from our website', 'age-gate'), $data['Version'], AGE_GATE_VERSION)) . '</p></div>';
94 }
95 }
96 }
97
98 }
99
100 public function actionLinks($links)
101 {
102 $settings = sprintf('<a href="%s">%s</a>', admin_url('admin.php?page=age-gate'), esc_html__('Settings', 'age-gate'));
103 $donate = '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=donate%40wordpressagegate%2ecom&lc=GB&item_name=Age%20Gate&item_number=Age%20Gate%20Donation&no_note=0&currency_code=GBP&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest" target="_blank" rel="noopener noreferrer">' . esc_html__('Donate', 'age-gate') . '</a>';
104
105 array_unshift($links, $settings);
106 array_push($links, $donate);
107
108 return $links;
109 }
110
111 public function websiteLink($meta, $file)
112 {
113 $basename = plugin_basename(AGE_GATE_PATH) . '/age-gate.php';
114
115 if ($basename === $file) {
116 $meta[] = sprintf(
117 '<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
118 'https://agegate.io/docs',
119 esc_html__('Documentation', 'age-gate')
120 );
121
122 $meta[] = sprintf(
123 '<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
124 'https://agegate.io/release-notes',
125 esc_html__('What&rsquo;s new?', 'age-gate')
126 );
127 }
128
129 return $meta;
130 }
131 }
132