PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.6.5
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.6.5
4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / src / settings / pages / PPG_Page.php
cookiebot / src / settings / pages Last commit date
Additional_Page.php 1 year ago Dashboard_Page.php 9 months ago Embeddings_Page.php 1 year ago Gcm_Page.php 1 year ago General_Page.php 11 months ago Gtm_Page.php 1 year ago Iab_Page.php 1 year ago Multiple_Page.php 1 year ago PPG_Page.php 4 months ago Settings_Page.php 1 year ago Settings_Page_Interface.php 1 year ago Support_Page.php 7 months ago
PPG_Page.php
163 lines
1 <?php
2
3 namespace cybot\cookiebot\settings\pages;
4
5 use cybot\cookiebot\lib\Cookiebot_WP;
6 use function cybot\cookiebot\lib\asset_url;
7 use function cybot\cookiebot\lib\include_view;
8
9 class PPG_Page implements Settings_Page_Interface {
10
11 const ADMIN_SLUG = 'cookiebot_ppg';
12
13 const PPG_PLUGIN_SLUG = 'privacy-policy-usercentrics/privacy-policy-usercentrics.php';
14
15 public function menu() {
16 add_submenu_page(
17 'cookiebot',
18 __( 'Policy Generator Plugin', 'cookiebot' ),
19 __( 'Policy Generator Plugin', 'cookiebot' ),
20 'manage_options',
21 self::ADMIN_SLUG,
22 array( $this, 'display' ),
23 30
24 );
25 }
26
27 public function register_ajax_hooks() {
28 add_action( 'wp_ajax_cookiebot_activate_ppg', array( $this, 'ajax_activate_plugin' ) );
29 add_action( 'wp_ajax_cookiebot_install_ppg', array( $this, 'ajax_install_plugin' ) );
30 }
31
32 public function ajax_activate_plugin() {
33 check_ajax_referer( 'cookiebot_ppg_nonce', 'nonce' );
34
35 if ( ! current_user_can( 'activate_plugins' ) ) {
36 wp_send_json_error( array( 'message' => __( 'You do not have permission to activate plugins.', 'cookiebot' ) ), 403 );
37 }
38
39 if ( self::is_plugin_active() ) {
40 wp_send_json_success();
41 }
42
43 if ( ! self::is_plugin_installed() ) {
44 wp_send_json_error( array( 'message' => __( 'Plugin is not installed.', 'cookiebot' ) ), 404 );
45 }
46
47 $result = activate_plugin( self::PPG_PLUGIN_SLUG );
48
49 if ( is_wp_error( $result ) ) {
50 wp_send_json_error( array( 'message' => $result->get_error_message() ), 500 );
51 }
52
53 wp_send_json_success();
54 }
55
56 public function ajax_install_plugin() {
57 check_ajax_referer( 'cookiebot_ppg_nonce', 'nonce' );
58
59 if ( ! current_user_can( 'install_plugins' ) ) {
60 wp_send_json_error( array( 'message' => __( 'You do not have permission to install plugins.', 'cookiebot' ) ), 403 );
61 }
62
63 if ( self::is_plugin_installed() ) {
64 wp_send_json_success();
65 }
66
67 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
68 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
69
70 $api = plugins_api(
71 'plugin_information',
72 array(
73 'slug' => 'privacy-policy-usercentrics',
74 'fields' => array( 'sections' => false ),
75 )
76 );
77
78 if ( is_wp_error( $api ) ) {
79 wp_send_json_error( array( 'message' => $api->get_error_message() ), 500 );
80 }
81
82 $upgrader = new \Plugin_Upgrader( new \WP_Ajax_Upgrader_Skin() );
83 $result = $upgrader->install( $api->download_link );
84
85 if ( is_wp_error( $result ) || ! $result ) {
86 wp_send_json_error( array( 'message' => __( 'Plugin installation failed.', 'cookiebot' ) ), 500 );
87 }
88
89 wp_send_json_success();
90 }
91
92 public function display() {
93 wp_enqueue_style(
94 'cookiebot-ppg-page-css',
95 asset_url( 'css/backend/ppg_page.css' ),
96 array(),
97 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
98 );
99
100 $is_installed = self::is_plugin_installed();
101 $is_active = self::is_plugin_active();
102
103 if ( ! $is_active ) {
104 wp_enqueue_script(
105 'cookiebot-ppg-page-js',
106 asset_url( 'js/backend/ppg-page.js' ),
107 array(),
108 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION,
109 true
110 );
111
112 $ppg_redirect_url = add_query_arg(
113 array(
114 'page' => 'privacy-policy-usercentrics',
115 'ppg_ref' => 'content-distribution',
116 ),
117 admin_url( 'admin.php' )
118 );
119
120 wp_localize_script(
121 'cookiebot-ppg-page-js',
122 'cookiebot_ppg',
123 array(
124 'ajax_url' => admin_url( 'admin-ajax.php' ),
125 'nonce' => wp_create_nonce( 'cookiebot_ppg_nonce' ),
126 'redirect_url' => $ppg_redirect_url,
127 'i18n' => array(
128 'installing' => __( 'Installing...', 'cookiebot' ),
129 'install' => __( 'Install Now', 'cookiebot' ),
130 'activating' => __( 'Activating...', 'cookiebot' ),
131 'activate' => __( 'Activate', 'cookiebot' ),
132 ),
133 )
134 );
135 }
136
137 $args = array(
138 'hero_image' => asset_url( 'img/ppg-hero.png' ),
139 'is_installed' => $is_installed,
140 'is_active' => $is_active,
141 );
142
143 include_view( 'admin/common/ppg-page.php', $args );
144 }
145
146 private static function is_plugin_installed() {
147 if ( ! function_exists( 'get_plugins' ) ) {
148 require_once ABSPATH . 'wp-admin/includes/plugin.php';
149 }
150
151 $plugins = get_plugins();
152 return isset( $plugins[ self::PPG_PLUGIN_SLUG ] );
153 }
154
155 private static function is_plugin_active() {
156 if ( ! function_exists( 'is_plugin_active' ) ) {
157 require_once ABSPATH . 'wp-admin/includes/plugin.php';
158 }
159
160 return is_plugin_active( self::PPG_PLUGIN_SLUG );
161 }
162 }
163