File: /var/www/zaklada/wp-content/plugins/coming-soon/app/settings.php
<?php
/**
* Save Settings
*/
function seedprod_lite_save_settings()
{
if (check_ajax_referer('seedprod_nonce')) {
if (!empty($_POST['settings'])) {
$settings = stripslashes_deep($_POST['settings']);
$s = json_decode($settings);
// Get old settings to check if there has been a change
$settings_old = get_option('seedprod_settings');
$s_old = json_decode($settings_old);
// Key is for $settings, Value is for get_option()
$settings_to_update = array(
'enable_coming_soon_mode' => 'seedprod_coming_soon_page_id',
'enable_maintenance_mode' => 'seedprod_maintenance_mode_page_id',
'enable_login_mode' => 'seedprod_login_page_id',
'enable_404_mode' => 'seedprod_404_page_id'
);
foreach ( $settings_to_update as $setting => $option ) {
$has_changed = ($s->$setting !== $s_old->$setting ? true : false);
if ( !$has_changed ) { continue; } // Do nothing if no change
$id = get_option($option);
$post_exists = !is_null( get_post($id) );
if ( !$post_exists ) {
update_option($option, null);
continue;
}
$update = array();
$update['ID'] = $id;
// Publish page when active
if ( $s->$setting === true ) {
$update['post_status'] = 'publish';
wp_update_post($update);
}
// Unpublish page when inactive
if ( $s->$setting === false ) {
$update['post_status'] = 'draft';
wp_update_post($update);
}
}
update_option('seedprod_settings', $settings);
$response = array(
'status'=> 'true',
'msg'=> __('Settings Updated', 'coming-soon')
);
} else {
$response = array(
'status'=> 'false',
'msg'=> __('Error Updating Settings', 'coming-soon')
);
}
// Send Response
wp_send_json($response);
exit;
}
}