Skip to content

Commit b515f4d

Browse files
committed
Switch to gmdate and use WP wrapper functions
1 parent 08c92e2 commit b515f4d

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

ai-seo-wp.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ private static function log(
237237
if ( get_option( 'wpseoai_log', get_option( 'wpseoai_debug', 'false' ) ) === 'false' ) {
238238
return null;
239239
}
240-
$log_directory = getcwd() . '/log/' . date( 'Y-m-d' );
240+
$log_directory = getcwd() . '/log/' . gmdate( 'Y-m-d' );
241241
if ( ! is_dir( $log_directory ) && ! mkdir( $log_directory ) ) {
242242
return false;
243243
}
244244
$timestamp = time();
245-
$data = json_encode( $data, JSON_PRETTY_PRINT );
245+
$data = wp_json_encode( $data, JSON_PRETTY_PRINT );
246246
if ( ! file_put_contents(
247247
"{$log_directory}/wpseoai-{$name}.json",
248248
"{$timestamp}: {$data}\n",
@@ -956,7 +956,7 @@ public function manage_responses_callback() {
956956
wp_die( esc_html( __( 'Invalid state information for this WPSEO.AI submission.', 'ai-seo-wp' ) ) );
957957
}
958958

959-
$response = addslashes( json_encode( $state ) );
959+
$response = addslashes( wp_json_encode( $state ) );
960960

961961
// Used with `wp_kses()` calls to `self::_key_value_array_to_html()`
962962
$allowed_html = [
@@ -1055,7 +1055,7 @@ class="toggle"
10551055
$total = count( $state[ 'received' ] );
10561056
foreach ( $state[ 'received' ] as $i => $received ) :
10571057
$index = $i + 1;
1058-
$date = date( 'jS F, h:i:s a', strtotime( $received[ 'date' ] ) );
1058+
$date = gmdate( 'jS F, h:i:s a', strtotime( $received[ 'date' ] ) );
10591059

10601060
$location = '';
10611061
if ( $total > 1 ) {
@@ -1472,13 +1472,13 @@ public static function submit_post(
14721472
];
14731473
$field_values = get_fields( $post_id );
14741474

1475-
self::log( 'service-input-acf', json_encode( $field_values, JSON_PRETTY_PRINT ) );
1475+
self::log( 'service-input-acf', wp_json_encode( $field_values, JSON_PRETTY_PRINT ) );
14761476

14771477
if ( $field_values ) {
14781478
$custom_fields = [];
14791479
$fields = get_field_objects( $post_id );
14801480

1481-
self::log( 'service-input-acf-obj', json_encode( $fields, JSON_PRETTY_PRINT ) );
1481+
self::log( 'service-input-acf-obj', wp_json_encode( $fields, JSON_PRETTY_PRINT ) );
14821482

14831483
// Process all ACF fields
14841484
foreach ( $fields as $key => $field ) {
@@ -1725,19 +1725,19 @@ private static function _request(
17251725
$host = "https://{$subdomain}.wpseo.ai";
17261726

17271727
// Prepare path
1728-
$path = parse_url( $uri, PHP_URL_PATH );
1728+
$path = wp_parse_url( $uri, PHP_URL_PATH );
17291729

17301730
// Prepare query string
1731-
$query = parse_url( $uri, PHP_URL_QUERY );
1731+
$query = wp_parse_url( $uri, PHP_URL_QUERY );
17321732

17331733
// Prepare GET request
17341734
$payload = $data;
17351735
$method = strtoupper( $method );
17361736

17371737
// Update for POST request
17381738
if ( $method === 'POST' ) {
1739-
$encoded_data = base64_encode( json_encode( $data ) );
1740-
$payload = json_encode( [ 'data' => $encoded_data ] );
1739+
$encoded_data = base64_encode( wp_json_encode( $data ) );
1740+
$payload = wp_json_encode( [ 'data' => $encoded_data ] );
17411741
}
17421742

17431743
// Calculate the HMAC signature
@@ -1795,7 +1795,7 @@ private static function _request(
17951795
// Determine if we need to return an array or JSON string
17961796
$return_json = '';
17971797
if ( $json ) {
1798-
$return_json = json_encode( $return, JSON_PRETTY_PRINT );
1798+
$return_json = wp_json_encode( $return, JSON_PRETTY_PRINT );
17991799
if ( $return_json === false ) {
18001800
throw new Exception( 'JSON encode failed' );
18011801
}
@@ -1829,7 +1829,7 @@ private static function _save_audit(
18291829
}
18301830

18311831
// Add date for this audit entry
1832-
$data[ 'date' ] = date( 'c' );
1832+
$data[ 'date' ] = gmdate( 'c' );
18331833

18341834
// Get existing post ID
18351835
$post_id = isset( $data[ 'post' ][ 'ID' ] ) ? intval( $data[ 'post' ][ 'ID' ] ) : 0;

includes/class-wpseoai-wp-list-table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function column_default(
209209
return esc_html( sanitize_text_field( $pto->labels->singular_name ?? $pto->label ) );
210210
// echo $pt->labels->name;
211211
case 'post_date':
212-
return esc_html( date( 'jS F, h:i:s a', strtotime( esc_attr( sanitize_text_field( $item[ $column_name ] ) ) ) ) );
212+
return esc_html( gmdate( 'jS F, h:i:s a', strtotime( esc_attr( sanitize_text_field( $item[ $column_name ] ) ) ) ) );
213213
default:
214214
return esc_html( sanitize_text_field( serialize( $item ) ) );
215215
// return print_r( $item, true ); //Show the whole array for troubleshooting purposes

0 commit comments

Comments
 (0)