Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Plugins_Page_View_Details | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| add_plugin_modal_data | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
110 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * This is necessary to get the View Details modal to work. |
| 4 | * |
| 5 | * http://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request[slug]=woocommerce |
| 6 | * |
| 7 | * @see install_plugin_information() |
| 8 | * |
| 9 | * @package brianhenryie/bh-wp-plugin-updater |
| 10 | */ |
| 11 | |
| 12 | namespace BrianHenryIE\WP_Plugin_Updater\Admin; |
| 13 | |
| 14 | use BrianHenryIE\WP_Plugin_Updater\API_Interface; |
| 15 | use BrianHenryIE\WP_Plugin_Updater\Settings_Interface; |
| 16 | |
| 17 | class Plugins_Page_View_Details { |
| 18 | |
| 19 | /** |
| 20 | * Constructor. |
| 21 | * |
| 22 | * @param API_Interface $api |
| 23 | * @param Settings_Interface $settings |
| 24 | */ |
| 25 | public function __construct( |
| 26 | protected API_Interface $api, |
| 27 | protected Settings_Interface $settings, |
| 28 | ) { |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * The "View details" link on the plugins.php page is not present for plugins that are not in the WordPress.org repo. |
| 33 | * |
| 34 | * Add a slug to the plugin details array to add the link. |
| 35 | */ |
| 36 | |
| 37 | /** |
| 38 | * @hooked plugins_api |
| 39 | * @see plugins_api() |
| 40 | * |
| 41 | * @see https://github.com/WordPress/wordpress.org/blob/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php |
| 42 | * |
| 43 | * The `plugins_api` filter will always pass `false` as its value and any non-false return value short-circuits |
| 44 | * the normal API request process. The `plugins_api_result` is used for filtering the API response. |
| 45 | * |
| 46 | * $api->sections as $section_name => $content |
| 47 | * |
| 48 | * @param false|object|array $res The result object or array. Default false. |
| 49 | * @param string $action The type of information being requested from the Plugin Installation API. |
| 50 | * @param object $args Plugin API arguments. |
| 51 | */ |
| 52 | public function add_plugin_modal_data( $res, $action, $args ) { |
| 53 | |
| 54 | if ( $this->settings->get_plugin_slug() !== $args->slug ) { |
| 55 | return $res; |
| 56 | } |
| 57 | |
| 58 | if ( false === $res ) { |
| 59 | $res = new \stdClass(); |
| 60 | } |
| 61 | |
| 62 | $minimum = array( |
| 63 | 'slug' => $this->settings->get_plugin_slug(), |
| 64 | 'name' => $this->settings->get_plugin_name(), |
| 65 | 'sections' => array(), |
| 66 | ); |
| 67 | |
| 68 | foreach ( $minimum as $key => $value ) { |
| 69 | if ( ! isset( $res->$key ) ) { |
| 70 | $res->$key = $value; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if ( isset( $_GET['section'] ) && 'changelog' === $_GET['section'] && ! isset( $sections['changelog'] ) ) { |
| 75 | $res->sections['changelog'] = 'No changelog available.'; |
| 76 | } |
| 77 | |
| 78 | $update_information = $this->api->get_plugin_information( false ); |
| 79 | |
| 80 | if ( is_null( $update_information ) ) { |
| 81 | return $res; |
| 82 | } |
| 83 | |
| 84 | // Check sections have content before adding any. |
| 85 | $sections = $update_information->get_sections(); |
| 86 | |
| 87 | foreach ( $sections as $name => $section ) { |
| 88 | $res->sections[ $name ] = $section; |
| 89 | } |
| 90 | |
| 91 | // $res->banners // $update_information->get_banners() |
| 92 | // $res->ratings // $update_information->get_ratings() |
| 93 | |
| 94 | return $res; |
| 95 | } |
| 96 | } |