Skip to content

Commit f4d9fab

Browse files
chore: replace all themeisle_log_event
1 parent 574bade commit f4d9fab

File tree

5 files changed

+86
-42
lines changed

5 files changed

+86
-42
lines changed

feedzy-rss-feed.php

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ function feedzy_register_parrot( $plugins ) {
271271
* @param string $type Error type.
272272
* @param string $file File where the event occurred.
273273
* @param int $line Line number where the event occurred.
274+
*
275+
* @deprecated 5.1.0 Use Feedzy_Rss_Feeds_Log instead.
274276
*/
275277
function feedzy_themeisle_log_event( $name, $msg, $type, $file, $line ) {
276278
if ( FEEDZY_NAME === $name ) {
@@ -279,35 +281,6 @@ function feedzy_themeisle_log_event( $name, $msg, $type, $file, $line ) {
279281
}
280282
}
281283

282-
/**
283-
* Store import job errors in metadata.
284-
*
285-
* @param string $name Name.
286-
* @param string $msg Error message.
287-
* @param string $type Error type.
288-
*
289-
* @return void
290-
*/
291-
function feedzy_import_job_logs( $name, $msg, $type ) {
292-
if ( ! in_array( $type, apply_filters( 'feedzy_allowed_store_log_types', array( 'error' ) ), true ) ) {
293-
return;
294-
}
295-
if ( ! wp_doing_ajax() || wp_doing_cron() ) {
296-
return;
297-
}
298-
if ( apply_filters( 'feedzy_skip_store_error_logs', false ) ) {
299-
return;
300-
}
301-
global $themeisle_log_event;
302-
303-
if ( ! empty( $themeisle_log_event ) && count( $themeisle_log_event ) >= 200 ) {
304-
return;
305-
}
306-
307-
$themeisle_log_event[] = $msg;
308-
}
309-
add_action( 'themeisle_log_event', 'feedzy_import_job_logs', 20, 3 );
310-
311284
add_filter(
312285
'feedzy_rss_feeds_float_widget_metadata',
313286
function () {

includes/abstract/feedzy-rss-feeds-admin-abstract.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,14 @@ function ( $time ) use ( $cache_time ) {
863863
if ( ! $wp_filesystem->exists( $dir ) ) {
864864
$done = $wp_filesystem->mkdir( $dir );
865865
if ( false === $done ) {
866-
do_action( 'themeisle_log_event', FEEDZY_NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ );
866+
Feedzy_Rss_Feeds_Log::error(
867+
sprintf( 'Unable to create SimplePie cache directory: %s', $dir ),
868+
array(
869+
'feed_url' => $feed_url,
870+
'cache' => $cache,
871+
'sc' => $sc,
872+
)
873+
);
867874
}
868875
}
869876
$feed->set_cache_location( $dir );
@@ -904,8 +911,6 @@ function ( $time ) use ( $cache_time ) {
904911
}
905912

906913
if ( ! empty( $error ) ) {
907-
do_action( 'themeisle_log_event', FEEDZY_NAME, sprintf( 'Error while parsing feed: %s', $error ), 'error', __FILE__, __LINE__ );
908-
909914
Feedzy_Rss_Feeds_Log::error(
910915
sprintf( 'Error while parsing feed: %s', $error ),
911916
array(
@@ -927,7 +932,13 @@ function ( $time ) use ( $cache_time ) {
927932
);
928933
$feed = $this->init_feed( $feed_url, $cache, $sc, false );
929934
} elseif ( is_string( $feed_url ) || ( is_array( $feed_url ) && 1 === count( $feed_url ) ) ) {
930-
do_action( 'themeisle_log_event', FEEDZY_NAME, 'Trying to use raw data', 'debug', __FILE__, __LINE__ );
935+
Feedzy_Rss_Feeds_Log::debug(
936+
sprintf( 'Using raw data for feed: %s', $feed_url ),
937+
array(
938+
'cache' => $cache,
939+
'sc' => $sc,
940+
)
941+
);
931942

932943
$data = wp_remote_retrieve_body( wp_safe_remote_get( $feed_url, array( 'user-agent' => $default_agent ) ) );
933944
$cloned_feed->set_raw_data( $data );
@@ -939,7 +950,14 @@ function ( $time ) use ( $cache_time ) {
939950
$feed = $cloned_feed;
940951
}
941952
} else {
942-
do_action( 'themeisle_log_event', FEEDZY_NAME, 'Cannot use raw data as this is a multifeed URL', 'debug', __FILE__, __LINE__ );
953+
Feedzy_Rss_Feeds_Log::debug(
954+
'Cannot use raw data as this is a multifeed URL',
955+
array(
956+
'feed_url' => $feed_url,
957+
'cache' => $cache,
958+
'sc' => $sc,
959+
)
960+
);
943961
}
944962
}
945963
return $feed;
@@ -1953,7 +1971,15 @@ public function feedzy_image_encode( $img_url ) {
19531971
}
19541972

19551973
$filtered_url = apply_filters( 'feedzy_image_encode', esc_url( $img_url ), $img_url );
1956-
do_action( 'themeisle_log_event', FEEDZY_NAME, sprintf( 'Changing image URL from %s to %s', $img_url, $filtered_url ), 'debug', __FILE__, __LINE__ );
1974+
1975+
Feedzy_Rss_Feeds_Log::debug(
1976+
'Change featured image via feedzy_image_encode',
1977+
array(
1978+
'old_url' => $img_url,
1979+
'new_url' => $filtered_url,
1980+
)
1981+
);
1982+
19571983
return $filtered_url;
19581984
}
19591985

includes/admin/feedzy-rss-feeds-admin.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,13 @@ private function add_proxy( $url ) {
11701170
if ( $settings && isset( $settings['proxy'] ) && is_array( $settings['proxy'] ) && ! empty( $settings['proxy'] ) ) {
11711171
// if even one constant is defined, escape.
11721172
if ( defined( 'WP_PROXY_HOST' ) || defined( 'WP_PROXY_PORT' ) || defined( 'WP_PROXY_USERNAME' ) || defined( 'WP_PROXY_PASSWORD' ) ) {
1173-
do_action( 'themeisle_log_event', FEEDZY_NAME, 'Some proxy constants already defined; ignoring proxy settings', 'info', __FILE__, __LINE__ );
1173+
Feedzy_Rss_Feeds_Log::info(
1174+
'Some proxy constants already defined; ignoring proxy settings',
1175+
array(
1176+
'url' => $url,
1177+
'settings' => $settings['proxy'],
1178+
)
1179+
);
11741180

11751181
return;
11761182
}
@@ -1227,7 +1233,14 @@ public function http_request_args( $args ) {
12271233
public function add_user_agent( $ua ) {
12281234
$settings = apply_filters( 'feedzy_get_settings', null );
12291235
if ( $settings && isset( $settings['header']['user-agent'] ) && ! empty( $settings['header']['user-agent'] ) ) {
1230-
do_action( 'themeisle_log_event', FEEDZY_NAME, sprintf( 'Override user-agent from %s to %s', $ua, $settings['header']['user-agent'] ), 'info', __FILE__, __LINE__ );
1236+
Feedzy_Rss_Feeds_Log::info(
1237+
'Overriding user-agent',
1238+
array(
1239+
'old_user_agent' => $ua,
1240+
'new_user_agent' => $settings['header']['user-agent'],
1241+
)
1242+
);
1243+
12311244
$ua = $settings['header']['user-agent'];
12321245
}
12331246

@@ -1246,7 +1259,14 @@ public function add_user_agent( $ua ) {
12461259
public function send_through_proxy( $return_value, $uri, $check, $home ) {
12471260
$proxied = defined( 'FEEZY_URL_THRU_PROXY' ) ? FEEZY_URL_THRU_PROXY : null;
12481261
if ( $proxied && ( ( is_array( $proxied ) && in_array( $uri, $proxied, true ) ) || $uri === $proxied ) ) {
1249-
do_action( 'themeisle_log_event', FEEDZY_NAME, sprintf( 'sending %s through proxy', $uri ), 'info', __FILE__, __LINE__ );
1262+
Feedzy_Rss_Feeds_Log::info(
1263+
'Sending through proxy',
1264+
array(
1265+
'uri' => $uri,
1266+
'check' => $check,
1267+
'home' => $home,
1268+
)
1269+
);
12501270

12511271
return true;
12521272
}

includes/admin/feedzy-rss-feeds-import.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2888,7 +2888,16 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title
28882888
if ( $renamed ) {
28892889
$local_file = $new_local_file;
28902890
} else {
2891-
do_action( 'themeisle_log_event', FEEDZY_NAME, sprintf( 'Unable to rename file for postID %d', $post_id ), 'error', __FILE__, __LINE__ );
2891+
2892+
Feedzy_Rss_Feeds_Log::error(
2893+
// translators: %s the name of the post.
2894+
sprintf( __( 'Could not rename temporary file for %s', 'feedzy-rss-feeds' ), get_the_title( $post_id ) ),
2895+
array(
2896+
'post_id' => $post_id,
2897+
'local_file' => $local_file,
2898+
'new_local_file' => $new_local_file,
2899+
)
2900+
);
28922901

28932902
return false;
28942903
}

includes/admin/feedzy-rss-feeds-log.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,7 @@ public static function log( $level, $message, array $context = array() ) {
284284
private function write_log( $level, $message, array $context = array() ) {
285285
if ( self::ERROR === $level ) {
286286
$this->increment_log_stat( 'error_count' );
287-
if ( $this->retain_error_messages ) {
288-
$this->error_messages_accumulator[] = $message;
289-
}
287+
$this->try_accumulate_error_message( $message );
290288
}
291289

292290
if ( ! $this->filesystem ) {
@@ -836,4 +834,22 @@ public function disable_error_messages_retention() {
836834
public function get_error_messages_accumulator() {
837835
return $this->error_messages_accumulator;
838836
}
837+
838+
/**
839+
* Add an error message to the accumulator.
840+
*
841+
* @param string $message The error message to accumulate.
842+
* @return void
843+
*/
844+
public function try_accumulate_error_message( $message ) {
845+
if ( ! $this->retain_error_messages ) {
846+
return;
847+
}
848+
849+
if ( 200 >= count( $this->error_messages_accumulator ) ) {
850+
return;
851+
}
852+
853+
$this->error_messages_accumulator[] = $message;
854+
}
839855
}

0 commit comments

Comments
 (0)