PluginProbe
The GDPR Framework By Data443 / trunk
The GDPR Framework By Data443 vtrunk
2.5.0 2.4.0 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.3 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 All 41 releases
gdpr-framework / src / Components / PrivacyToolsPage / PrivacyToolsPageShortcode.php

PrivacyToolsPageShortcode.php in The GDPR Framework By Data443 trunk, at src/Components/PrivacyToolsPage/PrivacyToolsPageShortcode.php

91 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Codelight\GDPR\Components\PrivacyToolsPage;
4
5 use Codelight\GDPR\Components\Consent\ConsentManager;
6 class PrivacyToolsPageShortcode
7 {
8 protected $consentManager;
9 protected $controller;
10
11 public function __construct(PrivacyToolsPageController $controller, ConsentManager $consentManager )
12 {
13 $this->controller = $controller;
14 $this->consentManager = $consentManager;
15 add_shortcode('gdpr_privacy_tools', [$this, 'renderPage']);
16 add_shortcode('gdpr_privacy_tools_url', [$this, 'renderUrlShortcode']);
17 add_shortcode('gdpr_privacy_tools_link', [$this, 'renderLinkShortcode']);
18 add_shortcode('gdpr_do_not_sell_form', [$this, 'renderDoNotSellForm']);
19 }
20
21 public function renderPage()
22 {
23 global $gdpr;
24 if (!$gdpr->Options->get('enable')) {
25 return __('This page is currently disabled.', 'gdpr-framework');
26 }
27
28 if ((!$gdpr->Options->get('tools_page') || is_null(get_post($gdpr->Options->get('tools_page')))) && !$gdpr->Options->get('custom_tools_page')) {
29 return __('Please configure the Privacy Tools page in the admin interface.', 'gdpr-framework');
30 }
31
32 ob_start();
33 $this->controller->render();
34 return ob_get_clean();
35 }
36
37 public function renderUrlShortcode()
38 {
39 return gdpr('helpers')->getPrivacyToolsPageUrl();
40 }
41
42 public function renderLinkShortcode($attributes)
43 {
44 $attributes = shortcode_atts([
45 'title' => __('Privacy Tools', 'gdpr-framework'),
46 ], $attributes);
47
48 $url = gdpr('helpers')->getPrivacyToolsPageUrl();
49
50 return
51 "<a href='{$url}'>" .
52 esc_html($attributes['title']) .
53 "</a>";
54 }
55 public function renderDoNotSellForm()
56 {
57 global $gdpr;
58 if (!$gdpr->Options->get('enable')) {
59 return __('This page is currently disabled.', 'gdpr-framework');
60 }
61
62 if (!$gdpr->Options->get('tools_page') || is_null(get_post($gdpr->Options->get('tools_page')))) {
63 return __('Please configure the Privacy Tools page in the admin interface.', 'gdpr-framework');
64 }
65 // The consent type registered in ConsentManager is 'do-not-sell-info'
66 // (see registerDefaultConsentTypes()); 'do-not-sell-request' never
67 // matched, so getbySlugConsent() always returned null and the form
68 // silently fell back to its generic "receive communications" branch.
69 $slug = 'do-not-sell-info';
70 $defaultConsentTypes = $this->consentManager->getbySlugConsent($slug);
71 $first_name = '';
72 $last_name = '';
73 $user_email = '';
74 if (is_user_logged_in()) {
75 // your code for logged in user
76 $current_user = wp_get_current_user();
77 $first_name = get_user_meta($current_user->ID, 'first_name', true);
78 if ($first_name === '') {
79 $first_name = $current_user->user_nicename;
80 }
81 $last_name = get_user_meta($current_user->ID, 'last_name', true);
82 $user_email = $current_user->user_email;
83 }
84 ob_start();
85 //$this->controller->render();
86 //$this->controller->renderNoticesOnly();
87 echo gdpr('view')->render('privacy-tools/donotsell', compact('defaultConsentTypes', 'first_name', 'last_name', 'user_email'));
88 return ob_get_clean();
89 }
90 }
91