Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_Debug_Data | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
156 | |
0.00% |
0 / 1 |
| what_jetpack_plan | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| seconds_to_time | n/a |
0 / 0 |
n/a |
0 / 0 |
5 | |||||
| add_plugin_fields | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
2 | |||
| core_debug_data | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
| debug_data | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
| 1 | <?php |
| 2 | /** |
| 3 | * Jetpack Debug Data for the Site Health sections. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | use Automattic\Jetpack\Connection\Debug_Data; |
| 9 | use Automattic\Jetpack\Current_Plan as Jetpack_Plan; |
| 10 | |
| 11 | /** |
| 12 | * Class Jetpack_Debug_Data |
| 13 | * |
| 14 | * Adds the Jetpack plugin's fields to the Jetpack Connection section of Site Health › Info. |
| 15 | * |
| 16 | * @since 7.3.0 |
| 17 | */ |
| 18 | class Jetpack_Debug_Data { |
| 19 | /** |
| 20 | * Determine the active plan and normalize it for the debugger results. |
| 21 | * |
| 22 | * @since 7.3.0 |
| 23 | * |
| 24 | * @return string The plan slug. |
| 25 | */ |
| 26 | public static function what_jetpack_plan() { |
| 27 | $plan = Jetpack_Plan::get(); |
| 28 | return ! empty( $plan['class'] ) ? $plan['class'] : 'undefined'; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Convert seconds to human readable time. |
| 33 | * |
| 34 | * A dedication function instead of using Core functionality to allow for output in seconds. |
| 35 | * |
| 36 | * @since 7.3.0 |
| 37 | * @deprecated $$next-version$$ Nothing in Jetpack uses it any more. |
| 38 | * |
| 39 | * @param int $seconds Number of seconds to convert to human time. |
| 40 | * |
| 41 | * @return string Human readable time. |
| 42 | */ |
| 43 | public static function seconds_to_time( $seconds ) { |
| 44 | _deprecated_function( __METHOD__, 'jetpack-$$next-version$$' ); |
| 45 | |
| 46 | $seconds = (int) $seconds; |
| 47 | $units = array( |
| 48 | 'week' => WEEK_IN_SECONDS, |
| 49 | 'day' => DAY_IN_SECONDS, |
| 50 | 'hour' => HOUR_IN_SECONDS, |
| 51 | 'minute' => MINUTE_IN_SECONDS, |
| 52 | 'second' => 1, |
| 53 | ); |
| 54 | // specifically handle zero. |
| 55 | if ( 0 === $seconds ) { |
| 56 | return '0 seconds'; |
| 57 | } |
| 58 | $human_readable = ''; |
| 59 | foreach ( $units as $name => $divisor ) { |
| 60 | $quot = (int) ( $seconds / $divisor ); |
| 61 | if ( $quot ) { |
| 62 | $human_readable .= "$quot $name"; |
| 63 | $human_readable .= ( abs( $quot ) > 1 ? 's' : '' ) . ', '; |
| 64 | $seconds -= $quot * $divisor; |
| 65 | } |
| 66 | } |
| 67 | return substr( $human_readable, 0, -2 ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Add the Jetpack plugin's own fields to the section the Connection package builds. |
| 72 | * |
| 73 | * @since $$next-version$$ |
| 74 | * |
| 75 | * @param array $fields Fields keyed by ID, each with a `label`, a `value` and a `private` flag. |
| 76 | * |
| 77 | * @return array The fields with the plugin's added. |
| 78 | */ |
| 79 | public static function add_plugin_fields( $fields ) { |
| 80 | $fields['version_option'] = array( |
| 81 | 'label' => 'Current Jetpack Version Option', |
| 82 | 'value' => Jetpack_Options::get_option( 'version' ), |
| 83 | 'private' => false, |
| 84 | ); |
| 85 | $fields['old_version'] = array( |
| 86 | 'label' => 'Previous Jetpack Version', |
| 87 | 'value' => Jetpack_Options::get_option( 'old_version' ), |
| 88 | 'private' => false, |
| 89 | ); |
| 90 | $fields['version'] = array( |
| 91 | 'label' => 'Jetpack Version', |
| 92 | 'value' => JETPACK__VERSION, |
| 93 | 'private' => false, |
| 94 | ); |
| 95 | $fields['jp_plugin_dir'] = array( |
| 96 | 'label' => 'Jetpack Directory', |
| 97 | 'value' => JETPACK__PLUGIN_DIR, |
| 98 | 'private' => true, |
| 99 | ); |
| 100 | $fields['plan'] = array( |
| 101 | 'label' => 'Plan Type', |
| 102 | 'value' => self::what_jetpack_plan(), |
| 103 | 'private' => false, |
| 104 | ); |
| 105 | |
| 106 | return $fields; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Return debug data in the format expected by Core's Site Health Info tab. |
| 111 | * |
| 112 | * @since 7.3.0 |
| 113 | * @deprecated $$next-version$$ The Connection package adds the section. |
| 114 | * |
| 115 | * @param array $debug The debug information already compiled by Core. |
| 116 | * |
| 117 | * @return array Debug information in the same format as the initial argument. |
| 118 | */ |
| 119 | public static function core_debug_data( $debug ) { |
| 120 | _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Connection\\Debug_Data::get_section' ); |
| 121 | |
| 122 | if ( ! class_exists( Debug_Data::class ) ) { |
| 123 | return $debug; |
| 124 | } |
| 125 | |
| 126 | $debug['jetpack'] = Debug_Data::get_section(); |
| 127 | |
| 128 | return $debug; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Compile and return array of debug information. |
| 133 | * |
| 134 | * @since 7.3.0 |
| 135 | * @deprecated $$next-version$$ The Connection package compiles the fields. |
| 136 | * |
| 137 | * @return array Fields keyed by ID, each with a `label`, a `value` and a `private` flag. |
| 138 | */ |
| 139 | public static function debug_data() { |
| 140 | _deprecated_function( __METHOD__, 'jetpack-$$next-version$$', 'Automattic\\Jetpack\\Connection\\Debug_Data::get_fields' ); |
| 141 | |
| 142 | return class_exists( Debug_Data::class ) ? Debug_Data::get_fields() : array(); |
| 143 | } |
| 144 | } |