class-tracking-plugin-data.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Tracking
  6. */
  7. /**
  8. * Represents the plugin data.
  9. */
  10. class WPSEO_Tracking_Plugin_Data implements WPSEO_Collection {
  11. /**
  12. * Returns the collection data.
  13. *
  14. * @return array The collection data.
  15. */
  16. public function get() {
  17. return array(
  18. 'plugins' => $this->get_plugin_data(),
  19. );
  20. }
  21. /**
  22. * Returns all plugins.
  23. *
  24. * @return array The formatted plugins.
  25. */
  26. protected function get_plugin_data() {
  27. if ( ! function_exists( 'get_plugin_data' ) ) {
  28. require_once ABSPATH . 'wp-admin/includes/plugin.php';
  29. }
  30. $plugins = wp_get_active_and_valid_plugins();
  31. $plugins = array_map( 'get_plugin_data', $plugins );
  32. $plugins = array_map( array( $this, 'format_plugin' ), $plugins );
  33. return $plugins;
  34. }
  35. /**
  36. * Formats the plugin array.
  37. *
  38. * @param array $plugin The plugin details.
  39. *
  40. * @return array The formatted array.
  41. */
  42. protected function format_plugin( array $plugin ) {
  43. return array(
  44. 'name' => $plugin['Name'],
  45. 'url' => $plugin['PluginURI'],
  46. 'version' => $plugin['Version'],
  47. 'author' => array(
  48. 'name' => wp_strip_all_tags( $plugin['Author'], true ),
  49. 'url' => $plugin['AuthorURI'],
  50. ),
  51. );
  52. }
  53. }