PluginProbe ʕ •ᴥ•ʔ
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets / trunk
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets vtrunk
3.9.5 3.9.6 4.0.0 4.0.1 4.1.0 trunk 2.12 2.13 2.14 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.3-beta-1.0 3.7.4 3.7.4-beta-1.0 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4
wp-all-import / addon-api / classes / admin.php
wp-all-import / addon-api / classes Last commit date
admin.php 3 weeks ago base.php 3 weeks ago data-importer.php 3 weeks ago helpers.php 3 weeks ago importer.php 3 weeks ago manager.php 3 weeks ago parser.php 3 weeks ago post-data-importer.php 3 weeks ago rest.php 3 weeks ago updater.php 3 weeks ago view.php 3 weeks ago
admin.php
118 lines
1 <?php
2 namespace Wpai\AddonAPI;
3
4 if ( ! defined( 'ABSPATH' ) ) exit;
5
6 class PMXI_Addon_Admin {
7 use Singleton;
8
9 public string $url = WP_ALL_IMPORT_ROOT_URL . '/addon-api';
10
11 public function __construct() {
12 add_action( 'pmxi_extend_options_custom_fields', [ $this, 'render' ], 10, 2 );
13 add_action( 'pmxi_reimport', [ $this, 'renderUpdateScreen' ], 10, 2 );
14 add_action( 'pmxi_confirm_data_to_import', [ $this, 'renderConfirmDataToImport' ], 10, 2 );
15
16 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] );
17 add_filter( 'script_loader_tag', [ $this, 'add_type_attribute' ], 10, 3 );
18 }
19
20 public function enqueue() {
21 // Loaded as an ES module; a stray module on unrelated admin pages
22 // invalidates WordPress core's import map in Firefox (strict ordering),
23 // breaking screens such as the WP 7.0 Connectors page. Only load it on
24 // WP All Import's own pages, where it is used.
25 if ( ! $this->is_wp_all_import_page() ) {
26 return;
27 }
28
29 wp_enqueue_script( 'pmxi-datepicker', $this->url . '/static/vendor/air-datepicker/air-datepicker.min.js', array(), PMXI_VERSION, true );
30 wp_enqueue_style( 'pmxi-datepicker', $this->url . '/static/vendor/air-datepicker/air-datepicker.min.css', array(), PMXI_VERSION );
31
32 wp_enqueue_style( 'pmxi-addon-admin-style', $this->url . '/static/css/admin.css', array(), PMXI_VERSION );
33 wp_enqueue_script( 'pmxi-addon-admin-script', $this->url . '/static/js/admin.js', array(), PMXI_VERSION, true );
34 wp_localize_script( 'pmxi-addon-admin-script', 'pmxiAddon', [
35 'ajaxUrl' => get_rest_url( null, 'wp-all-import/v1/addon/fields' ),
36 ] );
37 }
38
39 private function is_wp_all_import_page(): bool {
40 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
41 if ( empty( $_GET['page'] ) || ! is_string( $_GET['page'] ) ) {
42 return false;
43 }
44
45 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
46 return strpos( sanitize_key( wp_unslash( $_GET['page'] ) ), 'pmxi-' ) === 0;
47 }
48
49 public function add_type_attribute( $tag, $handle, $src ) {
50 if ( 'pmxi-addon-admin-script' !== $handle ) {
51 return $tag;
52 }
53 $tag = str_replace( ' src', ' type="module" src', $tag );
54
55 return $tag;
56 }
57
58 /**
59 * Render something on the import page
60 *
61 * @param string $type
62 * @param array $importOptions
63 *
64 * @return void
65 */
66 public function render( string $type, array $importOptions ) {
67 $subtype = $importOptions['taxonomy_type'];
68 $addons = PMXI_Addon_Manager::get_addons();
69
70 if ( empty( $addons ) ) {
71 return;
72 }
73
74 foreach ( $addons as $addon ) {
75 $view = PMXI_Addon_View::create( $addon->slug, $type, $subtype );
76 $view->renderTabs( $importOptions );
77 }
78 }
79
80 /**
81 * Render the update screen
82 *
83 * @param string $type
84 * @param array $importOptions
85 *
86 * @return void
87 */
88
89 public function renderUpdateScreen( string $type, array $importOptions ) {
90 $subtype = $importOptions['taxonomy_type'];
91 $addons = PMXI_Addon_Manager::get_addons();
92
93 if ( empty( $addons ) ) {
94 return;
95 }
96
97 foreach ( $addons as $addon ) {
98 $view = PMXI_Addon_View::create( $addon->slug, $type, $subtype );
99 $view->renderUpdate( $importOptions );
100 }
101 }
102
103 public function renderConfirmDataToImport( bool $isWizard, array $importOptions ) {
104 $type = $importOptions['custom_type'];
105 $subtype = $importOptions['taxonomy_type'];
106 $addons = PMXI_Addon_Manager::get_addons();
107
108 if ( empty( $addons ) ) {
109 return;
110 }
111
112 foreach ( $addons as $addon ) {
113 $view = PMXI_Addon_View::create( $addon->slug, $type, $subtype );
114 $view->renderConfirmDataToImport( $importOptions );
115 }
116 }
117 }
118