wpf_admin_functions.php
| 1 | <?php |
| 2 | /* |
| 3 | * This function is to handle the request and response to the main set global settings in wp_api. |
| 4 | * |
| 5 | * @input NULL |
| 6 | * @return Int |
| 7 | */ |
| 8 | if ( ! function_exists( 'wpf_global_settings' ) ) { |
| 9 | function wpf_global_settings() { |
| 10 | wpf_security_check(); |
| 11 | if ( $_POST['wpf_global_settings'] == 'yes' ) { |
| 12 | $url = WPF_CRM_API . 'update-global-settings'; |
| 13 | $wpf_license_key = get_option( 'wpf_license_key' ); |
| 14 | $wpf_license_key = wpf_crypt_key( $wpf_license_key, 'd' ); |
| 15 | $sendarr = array(); |
| 16 | $sendarr["wpf_site_id"] = get_option( 'wpf_site_id' ); |
| 17 | $sendarr["wpf_license_key"] = $wpf_license_key; |
| 18 | $sendtocloud = wp_json_encode( $sendarr ); |
| 19 | $response = wpf_send_remote_post( $url, $sendtocloud ); |
| 20 | echo ( isset( $response['status'] ) == 200 ) ? 1 : 3; |
| 21 | update_option( 'wpf_global_settings', 'yes' ); |
| 22 | get_notif_sitedata_filterdata(); |
| 23 | } else if ( $_POST['wpf_global_settings'] == 'no' ) { |
| 24 | $parms1 = []; |
| 25 | array_push( $parms1, ['name' => 'wpf_global_settings', 'value' => 'no'] ); |
| 26 | update_site_data( $parms1 ); |
| 27 | echo 2; |
| 28 | } else { |
| 29 | get_notif_sitedata_filterdata(); |
| 30 | echo 0; |
| 31 | } |
| 32 | exit; |
| 33 | } |
| 34 | } |
| 35 | add_action( 'wp_ajax_wpf_global_settings', 'wpf_global_settings' ); |
| 36 | |
| 37 | /* |
| 38 | * This function is to sync the global settings once a day. |
| 39 | * |
| 40 | * @input NULL |
| 41 | * @return Int |
| 42 | */ |
| 43 | if ( ! function_exists( 'sync_global_settings' ) ) { |
| 44 | function sync_global_settings() { |
| 45 | $wpf_active = wpf_check_if_enable(); |
| 46 | if ( $wpf_active == 1 ) { |
| 47 | $unix_time_now = time(); |
| 48 | $unix_time_last_sync = get_option( 'wpf_global_settings_resync_time' ); |
| 49 | if ( $unix_time_now > $unix_time_last_sync ) { |
| 50 | $global_settings = get_option( "wpf_global_settings" ); |
| 51 | if ( $global_settings == 'yes' ) { |
| 52 | $url = WPF_CRM_API . 'update-global-settings'; |
| 53 | $wpf_license_key = get_option( 'wpf_license_key' ); |
| 54 | $wpf_license_key = wpf_crypt_key( $wpf_license_key, 'd' ); |
| 55 | $sendarr = array(); |
| 56 | $sendarr["wpf_site_id"] = get_option( 'wpf_site_id' ); |
| 57 | $sendarr["wpf_license_key"] = $wpf_license_key; |
| 58 | $sendtocloud = wp_json_encode( $sendarr ); |
| 59 | $response = wpf_send_remote_post( $url, $sendtocloud ); |
| 60 | if ( isset( $response['status'] ) == 200 ) { |
| 61 | get_notif_sitedata_filterdata(); |
| 62 | } else { |
| 63 | get_notif_sitedata_filterdata(); |
| 64 | } |
| 65 | } elseif ( $global_settings == 'no' ) { |
| 66 | $parms1 = []; |
| 67 | array_push( $parms1, ['name' => 'wpf_global_settings', 'value' => 'no'] ); |
| 68 | update_site_data( $parms1 ); |
| 69 | } else { |
| 70 | get_notif_sitedata_filterdata(); |
| 71 | } |
| 72 | $unix_time = time(); |
| 73 | $unix_time += 86400; |
| 74 | update_option( "wpf_global_settings_resync_time", $unix_time, 'no' ); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | add_action( 'init', 'sync_global_settings' ); |