class-import-plugin.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Import\Plugins
  6. */
  7. /**
  8. * Class WPSEO_Import_Plugin.
  9. *
  10. * Class with functionality to import Yoast SEO settings from other plugins.
  11. */
  12. class WPSEO_Import_Plugin {
  13. /**
  14. * Holds the status of and message about imports.
  15. *
  16. * @var WPSEO_Import_Status
  17. */
  18. public $status;
  19. /**
  20. * Class with functionality to import meta data from other plugins.
  21. *
  22. * @var WPSEO_Plugin_Importer
  23. */
  24. protected $importer;
  25. /**
  26. * Import class constructor.
  27. *
  28. * @param WPSEO_Plugin_Importer $importer The importer that needs to perform this action.
  29. * @param string $action The action to perform.
  30. */
  31. public function __construct( WPSEO_Plugin_Importer $importer, $action ) {
  32. $this->importer = $importer;
  33. switch ( $action ) {
  34. case 'cleanup':
  35. $this->status = $this->importer->run_cleanup();
  36. break;
  37. case 'import':
  38. $this->status = $this->importer->run_import();
  39. break;
  40. case 'detect':
  41. default:
  42. $this->status = $this->importer->run_detect();
  43. }
  44. $this->status->set_msg( $this->complete_msg( $this->status->get_msg() ) );
  45. }
  46. /**
  47. * Convenience function to replace %s with plugin name in import message.
  48. *
  49. * @param string $msg Message string.
  50. *
  51. * @return string Returns message with plugin name instead of replacement variables.
  52. */
  53. protected function complete_msg( $msg ) {
  54. return sprintf( $msg, $this->importer->get_plugin_name() );
  55. }
  56. }