tool-import-export.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. if ( ! defined( 'WPSEO_VERSION' ) ) {
  8. header( 'Status: 403 Forbidden' );
  9. header( 'HTTP/1.1 403 Forbidden' );
  10. exit();
  11. }
  12. $yform = Yoast_Form::get_instance();
  13. $import = false;
  14. /**
  15. * The import method is used to determine if there should be something imported.
  16. *
  17. * In case of POST the user is on the Yoast SEO import page and in case of the GET the user sees a notice from
  18. * Yoast SEO that we can import stuff for that plugin.
  19. */
  20. if ( filter_input( INPUT_POST, 'import' ) || filter_input( INPUT_GET, 'import' ) ) {
  21. check_admin_referer( 'wpseo-import' );
  22. $post_wpseo = filter_input( INPUT_POST, 'wpseo', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
  23. $action = 'import';
  24. }
  25. elseif ( filter_input( INPUT_POST, 'import_external' ) ) {
  26. check_admin_referer( 'wpseo-import-plugins' );
  27. $class = filter_input( INPUT_POST, 'import_external_plugin' );
  28. if ( class_exists( $class ) ) {
  29. $import = new WPSEO_Import_Plugin( new $class(), 'import' );
  30. }
  31. }
  32. elseif ( filter_input( INPUT_POST, 'clean_external' ) ) {
  33. check_admin_referer( 'wpseo-clean-plugins' );
  34. $class = filter_input( INPUT_POST, 'clean_external_plugin' );
  35. if ( class_exists( $class ) ) {
  36. $import = new WPSEO_Import_Plugin( new $class(), 'cleanup' );
  37. }
  38. }
  39. elseif ( filter_input( INPUT_POST, 'settings_import' ) ) {
  40. $import = new WPSEO_Import_Settings();
  41. $import->import();
  42. }
  43. /**
  44. * Allow custom import actions.
  45. *
  46. * @api WPSEO_Import_Status $import Contains info about the handled import.
  47. */
  48. $import = apply_filters( 'wpseo_handle_import', $import );
  49. if ( $import ) {
  50. $message = '';
  51. if ( $import->status instanceof WPSEO_Import_Status ) {
  52. $message = $import->status->get_msg();
  53. }
  54. /**
  55. * Allow customization of import/export message.
  56. *
  57. * @api string $msg The message.
  58. */
  59. $msg = apply_filters( 'wpseo_import_message', $message );
  60. if ( ! empty( $msg ) ) {
  61. $status = 'error';
  62. if ( $import->status->status ) {
  63. $status = 'updated';
  64. }
  65. $class = 'message ' . $status;
  66. echo '<div id="message" class="', esc_attr( $status ), '"><p>', esc_html( $msg ), '</p></div>';
  67. }
  68. }
  69. $tabs = [
  70. 'wpseo-import' => [
  71. 'label' => __( 'Import settings', 'wordpress-seo' ),
  72. ],
  73. 'wpseo-export' => [
  74. 'label' => __( 'Export settings', 'wordpress-seo' ),
  75. ],
  76. 'import-seo' => [
  77. 'label' => __( 'Import from other SEO plugins', 'wordpress-seo' ),
  78. ],
  79. ];
  80. ?>
  81. <br/><br/>
  82. <h2 class="nav-tab-wrapper" id="wpseo-tabs">
  83. <?php foreach ( $tabs as $identifier => $tab ) : ?>
  84. <a class="nav-tab" id="<?php echo esc_attr( $identifier . '-tab' ); ?>" href="<?php echo esc_url( '#top#' . $identifier ); ?>"><?php echo esc_html( $tab['label'] ); ?></a>
  85. <?php endforeach; ?>
  86. <?php
  87. /**
  88. * Allow adding a custom import tab header.
  89. */
  90. do_action( 'wpseo_import_tab_header' );
  91. ?>
  92. </h2>
  93. <?php
  94. foreach ( $tabs as $identifier => $tab ) {
  95. printf( '<div id="%s" class="wpseotab">', esc_attr( $identifier ) );
  96. require_once WPSEO_PATH . 'admin/views/tabs/tool/' . $identifier . '.php';
  97. echo '</div>';
  98. }
  99. /**
  100. * Allow adding a custom import tab.
  101. */
  102. do_action( 'wpseo_import_tab_content' );