get_logger()->notice( 'UIPageSettings parent constructor called with default position.', [
'plugin' => $domain,
] );
}
/**
* Render the license subpage content
*/
protected function theContent( $slug, $page, $settings ) {
$this->get_logger()->info( 'Rendering the main content for the "Settings" UI page.', [
'plugin' => $this->domain,
'page_slug' => $page,
] );
// Define the options for the time period dropdowns.
$deleteOptionItems = array( 0 => __( 'never', 'double-opt-in' ) );
for ( $i = 1; $i <= 30; $i ++ ) {
$deleteOptionItems[ $i ] = (string) $i;
}
$deleteOptionPeriod = array(
'months' => 'months',
'days' => 'days',
'years' => 'years'
);
echo Messages::getInstance()->getAll();
// The form tag is handled by the parent renderContent method
?>
get_logger()->info( 'Triggering "f12_cf7_doubleoptin_ui_settings_render" action.', [
'plugin' => $this->domain,
] );
do_action( 'f12_cf7_doubleoptin_ui_settings_render', $settings );
$this->get_logger()->notice( 'Settings page content rendered successfully.', [
'plugin' => $this->domain,
] );
}
/**
* Display the sidebar content for the specified page.
*
* @param string $slug The slug of the current page.
* @param string $page The current page.
*
* @return void
*/
protected function theSidebar( $slug, $page ) {
$this->get_logger()->info( 'Attempting to render the sidebar for the "settings" page.', [
'plugin' => $this->domain,
'page_slug' => $page,
] );
// Check if the current page is the 'settings' page, and return if it's not.
if ( $page != 'settings' ) {
$this->get_logger()->debug( 'Skipping sidebar rendering because the page is not "settings".', [
'plugin' => $this->domain,
'page_slug' => $page,
] );
return;
}
$this->get_logger()->notice( 'Rendering sidebar content for the "settings" page.', [
'plugin' => $this->domain,
] );
?>
get_logger()->notice( 'Sidebar for the "settings" page rendered successfully.', [
'plugin' => $this->domain,
] );
}
/**
* Retrieves the settings array.
*
* @param array $settings The existing settings array.
*
* @return array The updated settings array.
*/
public function getSettings( $settings ) {
$this->get_logger()->info( 'getSettings method called. Merging default settings with existing ones.', [
'plugin' => $this->domain,
'page_slug' => $this->slug,
] );
// Define the default settings for this page.
$default_settings = array(
'telemetry' => 1,
'delete' => 0,
'delete_unconfirmed' => 7,
'delete_period' => 'months',
'delete_unconfirmed_period' => 'months',
);
// Merge the default settings with the provided settings array.
// This ensures that default values exist if they are not already set.
$settings = array_merge( $settings, $default_settings );
$this->get_logger()->debug( 'Merged settings: ' . json_encode( $settings ), [
'plugin' => $this->domain,
] );
return $settings;
}
/**
* Update the settings based on the POST data.
*
* @param array $settings The current settings.
*
* @return array The updated settings.
*/
protected function onSave( $settings ) {
$this->get_logger()->info( 'Executing onSave method for the "Settings" UI page.', [
'plugin' => $this->domain,
] );
// Update the 'delete' setting if it exists in the POST data.
if ( isset( $_POST['delete'] ) ) {
$settings['delete'] = (int) $_POST['delete'];
$this->get_logger()->debug( 'Updated "delete" setting to: ' . $settings['delete'], [
'plugin' => $this->domain,
] );
}
// Update the 'delete_unconfirmed' setting if it exists in the POST data.
if ( isset( $_POST['delete_unconfirmed'] ) ) {
$settings['delete_unconfirmed'] = (int) $_POST['delete_unconfirmed'];
$this->get_logger()->debug( 'Updated "delete_unconfirmed" setting to: ' . $settings['delete_unconfirmed'], [
'plugin' => $this->domain,
] );
}
if ( isset( $_POST['telemetry'] ) ) {
$settings['telemetry'] = (int) $_POST['telemetry'];
$this->get_logger()->debug( 'Updated "telemetry" setting to: ' . $settings['telemetry'], [
'plugin' => $this->domain,
] );
} else {
// If the checkbox is not set, it means the user unchecked it, so set the value to 0.
$settings['telemetry'] = 0;
$this->get_logger()->debug( 'Updated "telemetry" setting to 0 (unchecked).', [
'plugin' => $this->domain,
] );
}
// Update the 'delete_period' setting, sanitizing the input as a string.
if ( isset( $_POST['delete_period'] ) ) {
$settings['delete_period'] = sanitize_text_field( $_POST['delete_period'] );
$this->get_logger()->debug( 'Updated "delete_period" setting to: ' . $settings['delete_period'], [
'plugin' => $this->domain,
] );
}
// Update the 'delete_unconfirmed_period' setting, sanitizing the input as a string.
if ( isset( $_POST['delete_unconfirmed_period'] ) ) {
$settings['delete_unconfirmed_period'] = sanitize_text_field( $_POST['delete_unconfirmed_period'] );
$this->get_logger()->debug( 'Updated "delete_unconfirmed_period" setting to: ' . $settings['delete_unconfirmed_period'], [
'plugin' => $this->domain,
] );
}
$this->get_logger()->notice( 'onSave method finished. Returning the updated settings array.', [
'plugin' => $this->domain,
'final_settings' => $settings,
] );
// Return the updated settings array to be saved.
return $settings;
}
}
}