PluginProbe
FeedWordPress / 2025.1211
FeedWordPress v2025.1211
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / feedwordpressdiagnostic.class.php

feedwordpressdiagnostic.class.php in FeedWordPress 2025.1211, at feedwordpressdiagnostic.class.php

131 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * class FeedWordPressDiagnostic: help to organize some diagnostics output functions.
4 *
5 * @uses FeedWordPress::diagnostic()
6 */
7 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 ) {
16 $wpError = $error['object'];
17 $url = $link->uri();
18
19 // check for effects of an effective-url filter
20 $effectiveUrl = $link->uri( array( 'fetch' => true ) );
21 if ( $url != $effectiveUrl ) : $url .= ' | ' . $effectiveUrl; endif;
22
23 $mesgs = $wpError->get_error_messages();
24 foreach ( $mesgs as $mesg ) :
25 $mesg = esc_html( $mesg );
26 FeedWordPress::diagnostic(
27 'updated_feeds:errors',
28 "Feed Error: [{$url}] update returned error: $mesg"
29 );
30
31 $hours = get_option( 'feedwordpress_diagnostics_persistent_errors_hours', 2 );
32 $span = ( $error['ts'] - $error['since'] );
33
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)
38 FeedWordPress::diagnostic(
39 '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']
45 );
46 endif;
47 endforeach;
48 } /* FeedWordPressDiagnostic::feed_error() */
49
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 );
81 $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 ) :
87 $recipients[] = $dude->user_email;
88 endif;
89 endif;
90 endforeach;
91 return $recipients;
92 } /* FeedWordPressDiagnostic::admin_emails() */
93
94 public static function noncritical_bug ($varname, $var, $line, $file = NULL) {
95 if ( FEEDWORDPRESS_DEBUG ) : // halt only when we are doing debugging
96 self::critical_bug($varname, $var, $line, $file);
97 endif;
98 } /* FeedWordPressDiagnostic::noncritical_bug () */
99
100 public static function critical_bug ($varname, $var, $line, $file = NULL) {
101 global $wp_version;
102
103 if ( !is_null($file)) :
104 $location = "line # {$line} of ".basename($file);
105 else :
106 $location = "line # {$line}";
107 endif;
108
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";
115 print "Error data: ";
116 print esc_html($varname) . ": " . esc_html( MyPHP::val( $var ) ) . "\n";
117 print "\n</pre>";
118 die;
119 } /* FeedWordPressDiagnostic::critical_bug () */
120
121 public static function is_on ($level) {
122 $show = get_option('feedwordpress_diagnostics_show', array());
123 if ( ! is_array( $show ) ) {
124 $show = array( $show );
125 }
126
127 return ( in_array( $level, $show ) );
128 } /* FeedWordPressDiagnostic::is_on () */
129
130 } /* class FeedWordPressDiagnostic */
131