| 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 |
$slug = 'do-not-sell-request'; |
| 66 |
$defaultConsentTypes = $this->consentManager->getbySlugConsent($slug); |
| 67 |
$first_name = ''; |
| 68 |
$last_name = ''; |
| 69 |
$user_email = ''; |
| 70 |
if (is_user_logged_in()) { |
| 71 |
// your code for logged in user |
| 72 |
$current_user = wp_get_current_user(); |
| 73 |
$first_name = get_user_meta($current_user->ID, 'first_name', true); |
| 74 |
if ($first_name === '') { |
| 75 |
$first_name = $current_user->user_nicename; |
| 76 |
} |
| 77 |
$last_name = get_user_meta($current_user->ID, 'last_name', true); |
| 78 |
$user_email = $current_user->user_email; |
| 79 |
} |
| 80 |
ob_start(); |
| 81 |
//$this->controller->render(); |
| 82 |
//$this->controller->renderNoticesOnly(); |
| 83 |
echo gdpr('view')->render('privacy-tools/donotsell', compact('defaultConsentTypes', 'first_name', 'last_name', 'user_email')); |
| 84 |
return ob_get_clean(); |
| 85 |
} |
| 86 |
} |
| 87 |
|