Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/custom-t.../inc/SmashTwi...
File: ErrorReport.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Class ErrorReport
[2] Fix | Delete
*
[3] Fix | Delete
* Tracks errors and creates messages.
[4] Fix | Delete
*
[5] Fix | Delete
* @since 2.2.2
[6] Fix | Delete
*/
[7] Fix | Delete
namespace TwitterFeed\SmashTwitter;
[8] Fix | Delete
[9] Fix | Delete
class ErrorReport {
[10] Fix | Delete
private $critical_error;
[11] Fix | Delete
[12] Fix | Delete
private $errors;
[13] Fix | Delete
[14] Fix | Delete
private $log;
[15] Fix | Delete
[16] Fix | Delete
public function __construct() {
[17] Fix | Delete
$this->critical_error = array();
[18] Fix | Delete
$this->errors = array();
[19] Fix | Delete
[20] Fix | Delete
$ctf_statuses_option = get_option( 'ctf_statuses', array() );
[21] Fix | Delete
$this->log = array();
[22] Fix | Delete
if ( ! empty( $ctf_statuses_option['smash_twitter']['error_log'] ) ) {
[23] Fix | Delete
$this->log = $ctf_statuses_option['smash_twitter']['error_log'];
[24] Fix | Delete
}
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
public function log( $message ) {
[28] Fix | Delete
if ( ! is_array( $this->log ) ) {
[29] Fix | Delete
$this->log = array();
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
if ( count( $this->log ) > 10 ) {
[33] Fix | Delete
reset( $this->log );
[34] Fix | Delete
unset( $this->log[ key( $this->log ) ] );
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
$this->log[] = date( 'Y-m-d H:i:s' ) . ' - ' . $message;
[38] Fix | Delete
[39] Fix | Delete
$this->save_log();
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
public function save_log() {
[43] Fix | Delete
$ctf_statuses_option = get_option( 'ctf_statuses', array() );
[44] Fix | Delete
[45] Fix | Delete
$ctf_statuses_option['smash_twitter']['error_log'] = $this->log;
[46] Fix | Delete
[47] Fix | Delete
update_option( 'ctf_statuses', $ctf_statuses_option, false );
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
public function get_log() {
[51] Fix | Delete
return $this->log;
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
public function maybe_add_critical_error( $error ) {
[55] Fix | Delete
if ( empty( $this->critical_error ) ) {
[56] Fix | Delete
$this->critical_error = $error;
[57] Fix | Delete
return true;
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
return false;
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
public function add_error( $error ) {
[64] Fix | Delete
$this->errors[] = $error;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
public function get_errors() {
[68] Fix | Delete
return $this->errors;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
public function get_critical_error() {
[72] Fix | Delete
return $this->critical_error;
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
public function process_error( $error, $add_to_log = false ) {
[76] Fix | Delete
$settings_page_url = admin_url( 'admin.php?page=ctf-settings' );
[77] Fix | Delete
$feed_edit_url = admin_url( 'admin.php?page=ctf-feed-builder' );
[78] Fix | Delete
$added = false;
[79] Fix | Delete
if ( is_wp_error( $error ) ) {
[80] Fix | Delete
[81] Fix | Delete
if ( isset( $error->errors ) ) {
[82] Fix | Delete
$error_message = '';
[83] Fix | Delete
foreach ( $error->errors as $key => $item ) {
[84] Fix | Delete
$error_message .= $key . ': ' . $item[0] . ' ';
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
$error_array = array(
[88] Fix | Delete
'message' => 'HTTP request error - ' . $error_message,
[89] Fix | Delete
'directions' => sprintf( __( 'Troubleshoot using %sthis doc%s on our website.', 'custom-twitter-feeds' ), '<a href="https://smashballoon.com/doc/twitter-api-error-message-reference/?twitter&utm_source=twitter-free&utm_medium=error-notice&utm_campaign=smash-twitter&utm_content=ThisDoc" target="_blank" rel="noopener">','</a>' )
[90] Fix | Delete
);
[91] Fix | Delete
$added = $this->maybe_add_critical_error( $error_array );
[92] Fix | Delete
[93] Fix | Delete
if ( $added && $add_to_log ) {
[94] Fix | Delete
$this->log( $error_array['message'] );
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
return;
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
if ( is_array( $error ) && isset( $error['code'] ) ) {
[101] Fix | Delete
[102] Fix | Delete
if ( $error['code'] === 429 ) {
[103] Fix | Delete
$error_array = array(
[104] Fix | Delete
'message' => sprintf( __( 'It looks like you\'ve exceeded your daily feed update limit for this site as of %s. You will not see new tweets in your feed until the limit resets.', 'custom-twitter-feeds' ), date( 'Y-m-d H:i:s' ) ),
[105] Fix | Delete
'directions' => __( 'This limit will automatically reset within the next week. No action required.', 'custom-twitter-feeds' ) . ' ' . sprintf( __( 'For more information on limitations due to the Twitter API changes effective April 2023, %svisit this page%s.', 'custom-twitter-feeds' ), '<a href="https://smashballoon.com/doc/smash-balloon-twitter-changes/?twitter&utm_source=twitter-free&utm_medium=error-notice&utm_campaign=smash-twitter&utm_content=ThisPage" target="_blank" rel="noopener">','</a>' )
[106] Fix | Delete
);
[107] Fix | Delete
$added = $this->maybe_add_critical_error( $error_array );
[108] Fix | Delete
} elseif ( $error['code'] === 401 ) {
[109] Fix | Delete
$error_array = array(
[110] Fix | Delete
'message' => __( 'Unable to complete update of your feeds. It seems your site key is not authorized to make requests to the Twitter API', 'custom-twitter-feeds' ),
[111] Fix | Delete
'directions' => sprintf( __( 'Try going to the %ssettings page%s to refresh your site key.', 'custom-twitter-feeds' ), '<a href="'.esc_url( $settings_page_url ).'" target="_blank" rel="noopener">','</a>' )
[112] Fix | Delete
);
[113] Fix | Delete
$added = $this->maybe_add_critical_error( $error_array );
[114] Fix | Delete
} elseif ( $error['code'] === 400 ) {
[115] Fix | Delete
$error_array = array(
[116] Fix | Delete
'message' => __( 'There may be an issue with your credentials for using the Smash Twitter API', 'custom-twitter-feeds' ),
[117] Fix | Delete
'directions' => sprintf( __( 'Try going to the %ssettings page%s to refresh your site key.', 'custom-twitter-feeds' ), '<a href="'.esc_url( $settings_page_url ).'" target="_blank" rel="noopener">','</a>' )
[118] Fix | Delete
);
[119] Fix | Delete
$added = $this->maybe_add_critical_error( $error_array );
[120] Fix | Delete
} else {
[121] Fix | Delete
$error_data = json_decode( $error['message'], true );
[122] Fix | Delete
$message = '';
[123] Fix | Delete
if ( $error_data ) {
[124] Fix | Delete
$message = $error_data['message'];
[125] Fix | Delete
}
[126] Fix | Delete
$error_array = array(
[127] Fix | Delete
'message' => sprintf( __( 'Error %s: %s.', 'custom-twitter-feeds' ), $error['code'], $message ),
[128] Fix | Delete
'directions' => sprintf( __( 'Troubleshoot using %sthis doc%s on our website.', 'custom-twitter-feeds' ), '<a href="https://smashballoon.com/doc/twitter-api-error-message-reference/?twitter&utm_source=twitter-free&utm_medium=error-notice&utm_campaign=smash-twitter&utm_content=ThisDoc" target="_blank" rel="noopener">','</a>' )
[129] Fix | Delete
);
[130] Fix | Delete
$added = $this->maybe_add_critical_error( $error_array );
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
if ( $add_to_log && ! empty( $error_array ) ) {
[134] Fix | Delete
$added = $this->log( $error_array['message'] );
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
} elseif ( is_string( $error ) ) {
[138] Fix | Delete
if ( $error === 'could_not_authenticate' ) {
[139] Fix | Delete
$error_array = array(
[140] Fix | Delete
'message' => __( 'Your site is unable to connect to smashballoon.com and start updating feeds.', 'custom-twitter-feeds' ),
[141] Fix | Delete
'directions' => sprintf( __( 'Try going to the %ssettings page%s to refresh your site key.', 'custom-twitter-feeds' ), '<a href="'.esc_url( $settings_page_url ).'" target="_blank" rel="noopener">','</a>' )
[142] Fix | Delete
);
[143] Fix | Delete
$added = $this->maybe_add_critical_error( $error_array );
[144] Fix | Delete
} elseif ( $error === 'no_tweets_found' ) {
[145] Fix | Delete
$error_array = array(
[146] Fix | Delete
'message' => __( 'No tweets found for your selected feed sources.', 'custom-twitter-feeds' ),
[147] Fix | Delete
'directions' => __( 'Make sure there are tweets available that fit your settings.', 'custom-twitter-feeds' )
[148] Fix | Delete
);
[149] Fix | Delete
$added = $this->maybe_add_critical_error( $error_array );
[150] Fix | Delete
} elseif ( $error === 'no_tweets_found_cache' ) {
[151] Fix | Delete
$error_array = array(
[152] Fix | Delete
'message' => __( 'No tweets found for your selected feed sources.', 'custom-twitter-feeds' ),
[153] Fix | Delete
'directions' => __( 'Make sure there are tweets available on Twitter that fit your settings and then clear your cache using the button found on the Settings page. It\'s also possible that you\'re encountering a limitation of our new system for updating feeds.', 'custom-twitter-feeds' ). ' ' . sprintf( __( 'For more information on limitations due to the Twitter API changes effective April 2023, %svisit this page%s.', 'custom-twitter-feeds' ), '<a href="https://smashballoon.com/doc/smash-balloon-twitter-changes-free-version/?twitter&utm_source=twitter-free&utm_medium=error-notice&utm_campaign=smash-twitter&utm_content=ThisPage" target="_blank" rel="noopener">','</a>' )
[154] Fix | Delete
);
[155] Fix | Delete
$added = $this->maybe_add_critical_error( $error_array );
[156] Fix | Delete
} elseif ( $error === 'too_many_requests' ) {
[157] Fix | Delete
$error_array = array(
[158] Fix | Delete
'message' => __( 'Too many requests', 'custom-twitter-feeds' ),
[159] Fix | Delete
'directions' => __( 'There were too many requests coming for the API within the certain periodof time.', 'custom-twitter-feeds' )
[160] Fix | Delete
);
[161] Fix | Delete
$added = $this->maybe_add_critical_error( $error_array );
[162] Fix | Delete
} elseif ( $error === 'too_much_filtering' ) {
[163] Fix | Delete
$error_array = array(
[164] Fix | Delete
'message' => __( 'It looks there were no tweets found that fit your feed moderation settings.', 'custom-twitter-feeds' ),
[165] Fix | Delete
'directions' => sprintf( __( 'Try %sediting your feed settings%s to include more tweets or wait until new tweets that fit your filters are retrieved.', 'custom-twitter-feeds' ), '<a href="'.esc_url( $feed_edit_url ).'" target="_blank" rel="noopener">','</a>' )
[166] Fix | Delete
);
[167] Fix | Delete
$added = $this->maybe_add_critical_error( $error_array );
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
if ( $added && $add_to_log && ! empty( $error_array ) ) {
[171] Fix | Delete
$this->log( $error_array['message'] );
[172] Fix | Delete
}
[173] Fix | Delete
}
[174] Fix | Delete
}
[175] Fix | Delete
}
[176] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function