Skip to content

Commit

Permalink
fix: displaying detailed errors for non-admin users
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoreMihai committed Apr 9, 2024
1 parent c9d6e6b commit 55879c3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion includes/abstract/feedzy-rss-feeds-admin-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function feedzy_default_error_notice( $errors, $feed, $feed_url ) {
// Show the error message only if the user who has created this post (which contains the feed) is logged in.
// Or if this is in the dry run window.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
$show_error = is_admin() || ( is_user_logged_in() && $post && get_current_user_id() == $post->post_author );
$show_error = is_admin() || ( is_user_logged_in() && $post && current_user_can( 'manage_options' ) && get_current_user_id() == $post->post_author );
$error_msg = '';

if ( is_array( $errors ) ) {
Expand Down Expand Up @@ -735,6 +735,7 @@ private function smart_convert( $url ) {
* @return SimplePie|string|void|WP_Error The feed resource.
*/
public function fetch_feed( $feed_url, $cache = '12_hours', $sc = '' ) {
error_log('fetch_feed');
// Load SimplePie if not already.
do_action( 'feedzy_pre_http_setup', $feed_url );
if ( function_exists( 'feedzy_amazon_get_locale_hosts' ) ) {
Expand All @@ -754,6 +755,7 @@ function( $url ) {
$is_amazon_source = ! empty( $amazon_hosts ) && in_array( $url_host, $amazon_hosts, true );
}
if ( $is_amazon_source ) {
error_log('is_amazon_source');
$feed = $this->init_amazon_api(
$feed_url,
isset( $sc['refresh'] ) ? $sc['refresh'] : '12_hours',
Expand All @@ -766,6 +768,10 @@ function( $url ) {
}
}
// Load SimplePie Instance.
error_log('init_feed');
error_log(print_r($feed_url,true));
error_log($cache);
error_log(print_r($sc,true));
$feed = $this->init_feed( $feed_url, $cache, $sc ); // Not used as log as #41304 is Opened.

// Report error when is an error loading the feed.
Expand Down Expand Up @@ -903,8 +909,10 @@ function() {
);
}

error_log('starting to init');
$feed->init();

error_log('init done');
if ( ! $feed->get_type() ) {
return $feed;
}
Expand All @@ -924,7 +932,9 @@ function() {
$feed = $this->init_feed( $feed_url, $cache, $sc, false );
} elseif ( is_string( $feed_url ) || ( is_array( $feed_url ) && 1 === count( $feed_url ) ) ) {
do_action( 'themeisle_log_event', FEEDZY_NAME, 'Trying to use raw data', 'debug', __FILE__, __LINE__ );
error_log('trying to use raw data');
$data = wp_remote_retrieve_body( wp_safe_remote_get( $feed_url, array( 'user-agent' => $default_agent ) ) );
error_log('got data');
$cloned_feed->set_raw_data( $data );
$cloned_feed->init();
$error_raw = $cloned_feed->error();
Expand Down

0 comments on commit 55879c3

Please sign in to comment.