| 1 |
<?php |
| 2 |
|
| 3 |
namespace Codelight\GDPR\Installer\Steps; |
| 4 |
|
| 5 |
use Codelight\GDPR\Installer\InstallerStep; |
| 6 |
use Codelight\GDPR\Installer\InstallerStepInterface; |
| 7 |
|
| 8 |
class ConfigurationPages extends InstallerStep implements InstallerStepInterface |
| 9 |
{ |
| 10 |
protected $slug = 'configuration-pages'; |
| 11 |
|
| 12 |
protected $type = 'wizard'; |
| 13 |
|
| 14 |
protected $template = 'installer/steps/configuration-pages'; |
| 15 |
|
| 16 |
protected $activeSteps = 1; |
| 17 |
|
| 18 |
protected function renderContent() |
| 19 |
{ |
| 20 |
global $gdpr; |
| 21 |
$policyPage = $gdpr->Options->get('policy_page'); |
| 22 |
$policyPageSelector = wp_dropdown_pages([ |
| 23 |
'name' => 'gdpr_policy_page', |
| 24 |
'show_option_none' => _x('— Create a new page —', '(Admin)', 'gdpr-framework'), |
| 25 |
'option_none_value' => 'new', |
| 26 |
'selected' => $policyPage ? $policyPage : 'new', |
| 27 |
'echo' => false, |
| 28 |
'class' => 'gdpr-select js-gdpr-select2', |
| 29 |
]); |
| 30 |
|
| 31 |
$privacyToolsPage = $gdpr->Options->get('tools_page'); |
| 32 |
$privacyToolsPageSelector = wp_dropdown_pages([ |
| 33 |
'name' => 'gdpr_tools_page', |
| 34 |
'show_option_none' => _x('— Create a new page —', '(Admin)', 'gdpr-framework'), |
| 35 |
'option_none_value' => 'new', |
| 36 |
'selected' => $privacyToolsPage ? $privacyToolsPage : 'new', |
| 37 |
'echo' => false, |
| 38 |
'class' => 'gdpr-select js-gdpr-select2', |
| 39 |
]); |
| 40 |
|
| 41 |
echo gdpr('view')->render( |
| 42 |
$this->template, |
| 43 |
compact( |
| 44 |
'policyPage', |
| 45 |
'policyPageSelector', |
| 46 |
'privacyToolsPage', |
| 47 |
'privacyToolsPageSelector' |
| 48 |
) |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
public function submit() |
| 53 |
{ |
| 54 |
global $gdpr; |
| 55 |
if (isset($_POST['gdpr_create_tools_page']) && 'yes' === $_POST['gdpr_create_tools_page']) { |
| 56 |
$id = $this->createPrivacyToolsPage(); |
| 57 |
$gdpr->Options->set('tools_page', $id); |
| 58 |
} else { |
| 59 |
$gdpr->Options->set('tools_page', $_POST['gdpr_tools_page']); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
protected function createPrivacyToolsPage() |
| 64 |
{ |
| 65 |
$id = wp_insert_post([ |
| 66 |
'post_content' => '<!-- wp:shortcode -->[gdpr_privacy_tools]<!-- /wp:shortcode -->', |
| 67 |
'post_title' => __('Privacy Tools', 'gdpr-framework'), |
| 68 |
'post_type' => 'page', |
| 69 |
]); |
| 70 |
|
| 71 |
return $id; |
| 72 |
} |
| 73 |
} |
| 74 |
|