| @@ -1,99 +1,58 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * class FeedWordPressDiagnostic: help to organize some diagnostics output functions. |
| 4 | - * | |
| 5 | - * @uses FeedWordPress::diagnostic() | |
| 6 | 4 | */ |
| 7 | 5 | class FeedWordPressDiagnostic { |
| 8 | - /** | |
| 9 | - * Log error on a feed. | |
| 10 | - * | |
| 11 | - * @param array $error A structured array of error fields. | |
| 12 | - * @param mixex $old Unused. | |
| 13 | - * @param object $link A link object, containing an URI. * | |
| 14 | - */ | |
| 15 | - public static function feed_error( $error, $old, $link ) { | |
| 6 | + public static function feed_error ($error, $old, $link) { | |
| 16 | 7 | $wpError = $error['object']; |
| 17 | 8 | $url = $link->uri(); |
| 18 | - | |
| 9 | + | |
| 19 | 10 | // check for effects of an effective-url filter |
| 20 | - $effectiveUrl = $link->uri( array( 'fetch' => true ) ); | |
| 21 | - if ( $url != $effectiveUrl ) : $url .= ' | ' . $effectiveUrl; endif; | |
| 11 | + $effectiveUrl = $link->uri(array('fetch' => true)); | |
| 12 | + if ($url != $effectiveUrl) : $url .= ' | ' . $effectiveUrl; endif; | |
| 22 | 13 | |
| 23 | 14 | $mesgs = $wpError->get_error_messages(); |
| 24 | - foreach ( $mesgs as $mesg ) : | |
| 25 | - $mesg = esc_html( $mesg ); | |
| 15 | + foreach ($mesgs as $mesg) : | |
| 16 | + $mesg = esc_html($mesg); | |
| 26 | 17 | FeedWordPress::diagnostic( |
| 27 | 18 | 'updated_feeds:errors', |
| 28 | - "Feed Error: [{$url}] update returned error: $mesg" | |
| 19 | + "Feed Error: [${url}] update returned error: $mesg" | |
| 29 | 20 | ); |
| 30 | 21 | |
| 31 | - $hours = get_option( 'feedwordpress_diagnostics_persistent_errors_hours', 2 ); | |
| 32 | - $span = ( $error['ts'] - $error['since'] ); | |
| 22 | + $hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2); | |
| 23 | + $span = ($error['ts'] - $error['since']); | |
| 33 | 24 | |
| 34 | - if ( $span >= ( $hours * 60 * 60 ) ) : | |
| 35 | - $since = date( 'r', $error['since'] ); | |
| 36 | - /** @var string Never used. */ | |
| 37 | - $mostRecent = date( 'r', $error['ts'] ); // never used?... (gwyneth 20230919) | |
| 25 | + if ($span >= ($hours * 60 * 60)) : | |
| 26 | + $since = date('r', $error['since']); | |
| 27 | + $mostRecent = date('r', $error['ts']); | |
| 38 | 28 | FeedWordPress::diagnostic( |
| 39 | 29 | 'updated_feeds:errors:persistent', |
| 40 | - "Feed Update Error: [{$url}] returning errors" | |
| 41 | - ." since {$since}:<br/><code>$mesg</code>", | |
| 42 | - $url, | |
| 43 | - $error['since'], | |
| 44 | - $error['ts'] | |
| 30 | + "Feed Update Error: [${url}] returning errors" | |
| 31 | + ." since ${since}:<br/><code>$mesg</code>", | |
| 32 | + $url, $error['since'], $error['ts'] | |
| 45 | 33 | ); |
| 46 | 34 | endif; |
| 47 | 35 | endforeach; |
| 48 | - } /* FeedWordPressDiagnostic::feed_error() */ | |
| 36 | + } | |
| 49 | 37 | |
| 50 | - /** | |
| 51 | - * Returns an array with the list of administrator emails for this site. | |
| 52 | - * | |
| 53 | - * @param int|string $id Current blog ID (for multisite installations). | |
| 54 | - * | |
| 55 | - * @return array Array with all email addresses for this blog. | |
| 56 | - * | |
| 57 | - * @uses get_users_of_blog() | |
| 58 | - * | |
| 59 | - * @note This uses the deprecated WP function `get_users_of_blog()`, which | |
| 60 | - * should be replaced with `get_users()`, which, however, has quite more | |
| 61 | - * intricate syntax (and customisation!). | |
| 62 | - * | |
| 63 | - * It might be even possible to retrieve everything in a single call: | |
| 64 | - * ``` | |
| 65 | - * return get_users( | |
| 66 | - * array( | |
| 67 | - * 'role__in' => 'administrator', | |
| 68 | - * 'capability__in' => 'administrator', | |
| 69 | - * 'fields' => 'user_email', | |
| 70 | - * 'count_total' => false // no need to count them; improves performance. | |
| 71 | - * ) | |
| 72 | - * ); | |
| 73 | - * ``` | |
| 74 | - * | |
| 75 | - * Alternatively, the function `admin_emails()` may simply be marked as deprecated and | |
| 76 | - * `get_users()` used instead. This requires debugging! (gwyneth 20230919) | |
| 77 | - */ | |
| 78 | - public static function admin_emails( $id = '' ) { | |
| 79 | - // deprecated, see comment on the function description! (gwyneth 20230919) | |
| 80 | - $users = get_users_of_blog( $id ); | |
| 38 | + public static function admin_emails ($id = '') { | |
| 39 | + $users = get_users_of_blog($id); | |
| 81 | 40 | $recipients = array(); |
| 82 | - foreach ( $users as $user ) : | |
| 83 | - $user_id = ( isset( $user->user_id ) ? $user->user_id : $user->ID ); | |
| 84 | - $dude = new WP_User( $user_id ); | |
| 85 | - if ( $dude->has_cap('administrator') ) : | |
| 86 | - if ( $dude->user_email ) : | |
| 41 | + foreach ($users as $user) : | |
| 42 | + $user_id = (isset($user->user_id) ? $user->user_id : $user->ID); | |
| 43 | + $dude = new WP_User($user_id); | |
| 44 | + if ($dude->has_cap('administrator')) : | |
| 45 | + if ($dude->user_email) : | |
| 87 | 46 | $recipients[] = $dude->user_email; |
| 88 | 47 | endif; |
| 89 | 48 | endif; |
| 90 | 49 | endforeach; |
| 91 | 50 | return $recipients; |
| 92 | - } /* FeedWordPressDiagnostic::admin_emails() */ | |
| 51 | + } | |
| 93 | 52 | |
| 94 | 53 | public static function noncritical_bug ($varname, $var, $line, $file = NULL) { |
| 95 | - if ( FEEDWORDPRESS_DEBUG ) : // halt only when we are doing debugging | |
| 54 | + if (FEEDWORDPRESS_DEBUG) : // halt only when we are doing debugging | |
| 96 | 55 | self::critical_bug($varname, $var, $line, $file); |
| 97 | 56 | endif; |
| 98 | 57 | } /* FeedWordPressDiagnostic::noncritical_bug () */ |
| 99 | 58 | |
| @@ -99,32 +58,27 @@ | ||
| 99 | 58 | |
| 100 | 59 | public static function critical_bug ($varname, $var, $line, $file = NULL) { |
| 101 | 60 | global $wp_version; |
| 102 | 61 | |
| 103 | - if ( !is_null($file)) : | |
| 104 | - $location = "line # {$line} of ".basename($file); | |
| 62 | + if (!is_null($file)) : | |
| 63 | + $location = "line # ${line} of ".basename($file); | |
| 105 | 64 | else : |
| 106 | - $location = "line # {$line}"; | |
| 65 | + $location = "line # ${line}"; | |
| 107 | 66 | endif; |
| 108 | 67 | |
| 109 | - print '<p><strong>Critical error:</strong> There may be a bug in FeedWordPress. Please <a href="'.esc_url( FEEDWORDPRESS_AUTHOR_CONTACT ) .'">contact the author</a> and paste the following information into your e-mail:</p>'; | |
| 110 | - print "\n<pre>"; | |
| 111 | - print "Triggered at " . esc_html($location) . "\n"; | |
| 112 | - print "FeedWordPress: " . esc_html( FEEDWORDPRESS_VERSION ) . "\n"; | |
| 113 | - print "WordPress: " . esc_html( $wp_version ) . "\n"; | |
| 114 | - print "PHP: " . esc_html( phpversion() ) . "\n"; | |
| 68 | + print '<p><strong>Critical error:</strong> There may be a bug in FeedWordPress. Please <a href="'.FEEDWORDPRESS_AUTHOR_CONTACT.'">contact the author</a> and paste the following information into your e-mail:</p>'; | |
| 69 | + print "\n<plaintext>"; | |
| 70 | + print "Triggered at ${location}\n"; | |
| 71 | + print "FeedWordPress: ".FEEDWORDPRESS_VERSION."\n"; | |
| 72 | + print "WordPress: {$wp_version}\n"; | |
| 73 | + print "PHP: ".phpversion()."\n"; | |
| 115 | 74 | print "Error data: "; |
| 116 | - print esc_html($varname) . ": " . esc_html( MyPHP::val( $var ) ) . "\n"; | |
| 117 | - print "\n</pre>"; | |
| 75 | + print $varname.": "; var_dump($var); echo "\n"; | |
| 118 | 76 | die; |
| 119 | 77 | } /* FeedWordPressDiagnostic::critical_bug () */ |
| 120 | 78 | |
| 121 | 79 | public static function is_on ($level) { |
| 122 | 80 | $show = get_option('feedwordpress_diagnostics_show', array()); |
| 123 | - if ( ! is_array( $show ) ) { | |
| 124 | - $show = array( $show ); | |
| 125 | - } | |
| 126 | - | |
| 127 | - return ( in_array( $level, $show ) ); | |
| 81 | + return (in_array($level, $show)); | |
| 128 | 82 | } /* FeedWordPressDiagnostic::is_on () */ |
| 129 | 83 | |
| 130 | 84 | } /* class FeedWordPressDiagnostic */ |