class-import-plugin.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. * @var WPSEO_Import_Status
  15. */
  16. public $status;
  17. /**
  18. * @var WPSEO_Plugin_Importer
  19. */
  20. protected $importer;
  21. /**
  22. * Import class constructor.
  23. *
  24. * @param WPSEO_Plugin_Importer $importer The importer that needs to perform this action.
  25. * @param string $action The action to perform.
  26. */
  27. public function __construct( WPSEO_Plugin_Importer $importer, $action ) {
  28. $this->importer = $importer;
  29. switch ( $action ) {
  30. case 'cleanup':
  31. $this->status = $this->importer->run_cleanup();
  32. break;
  33. case 'import':
  34. $this->status = $this->importer->run_import();
  35. break;
  36. case 'detect':
  37. default:
  38. $this->status = $this->importer->run_detect();
  39. }
  40. $this->status->set_msg( $this->complete_msg( $this->status->get_msg() ) );
  41. }
  42. /**
  43. * Convenience function to replace %s with plugin name in import message.
  44. *
  45. * @param string $msg Message string.
  46. *
  47. * @return string Returns message with plugin name instead of replacement variables.
  48. */
  49. protected function complete_msg( $msg ) {
  50. return sprintf( $msg, $this->importer->get_plugin_name() );
  51. }
  52. }