PluginProbe ʕ •ᴥ•ʔ
Export/Import Media – CSV Media Library Import & Export / 1.7.28
Export/Import Media – CSV Media Library Import & Export v1.7.28
1.7.28 1.7.27 1.7.20 1.7.26 1.7.10 1.7.9 1.7.1 1.7 trunk 1.0 1.0.3 1.2.1 1.2.2 1.2.3 1.6.15 1.6.4
calliope-media-import-export / includes / class-config.php
calliope-media-import-export / includes Last commit date
class-config.php 1 week ago class-eim-service-registry.php 1 week ago class-exporter.php 1 week ago class-importer.php 1 week ago
class-config.php
202 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class EIM_Config {
7
8 const OPTION_KEY = 'eim_settings';
9
10 public static function get_option_key() {
11 return (string) apply_filters( 'eim_settings_option_key', self::OPTION_KEY );
12 }
13
14 public static function get_defaults() {
15 $public_slug = defined( 'EIM_PUBLIC_SLUG' ) ? EIM_PUBLIC_SLUG : 'calliope-media-import-export';
16
17 $defaults = [
18 'required_capability' => 'manage_options',
19 'import' => [
20 'default_batch_size' => '25',
21 'preview_sample_limit' => 5,
22 'batch_size_options' => [
23 '10' => __( '10 (Safe)', 'calliope-media-import-export' ),
24 '25' => '25',
25 '50' => __( '50 (Local / advanced servers)', 'calliope-media-import-export' ),
26 ],
27 'options' => [
28 [
29 'id' => 'eim_local_import',
30 'label' => __( 'Local Import Mode', 'calliope-media-import-export' ),
31 'description' => __( 'Use the "Relative Path" column to locate files that already exist in this site\'s uploads folder. No remote download is attempted.', 'calliope-media-import-export' ),
32 'checked' => false,
33 'feature' => 'local_import',
34 ],
35 [
36 'id' => 'eim_honor_relative_path',
37 'label' => __( 'Honor Relative Path (Keep folders)', 'calliope-media-import-export' ),
38 'description' => __( 'Keep the folder structure from "Relative Path" when importing, and reuse files already present in uploads when the same path exists.', 'calliope-media-import-export' ),
39 'checked' => true,
40 'feature' => 'relative_path',
41 ],
42 [
43 'id' => 'eim_skip_thumbnails',
44 'label' => __( 'Skip Thumbnail Generation', 'calliope-media-import-export' ),
45 'description' => __( 'Speed up imports by skipping thumbnail generation. Turn this on if you plan to regenerate thumbnails later.', 'calliope-media-import-export' ),
46 'checked' => true,
47 'feature' => 'skip_thumbnails',
48 ],
49 ],
50 ],
51 'export' => [
52 'defaults' => [
53 'media_type' => 'all',
54 'attachment_filter' => 'all',
55 ],
56 'media_type_options' => [
57 'image' => __( 'Images', 'calliope-media-import-export' ),
58 'all' => __( 'All Media', 'calliope-media-import-export' ),
59 'video' => __( 'Videos', 'calliope-media-import-export' ),
60 'audio' => __( 'Audio', 'calliope-media-import-export' ),
61 'application' => __( 'Documents (PDF, ZIP, etc.)', 'calliope-media-import-export' ),
62 ],
63 'attachment_filter_options' => [
64 'all' => __( 'All Media', 'calliope-media-import-export' ),
65 'unattached' => __( 'Unattached (Not used in posts)', 'calliope-media-import-export' ),
66 'post' => __( 'Attached to Posts', 'calliope-media-import-export' ),
67 'page' => __( 'Attached to Pages', 'calliope-media-import-export' ),
68 'product' => [
69 'label' => __( 'Attached to Products (WooCommerce)', 'calliope-media-import-export' ),
70 'requires_class' => 'WooCommerce',
71 ],
72 ],
73 ],
74 'features' => [
75 'csv_preview' => true,
76 'batch_import' => true,
77 'local_import' => true,
78 'relative_path' => true,
79 'skip_thumbnails' => true,
80 'duplicate_detection' => true,
81 'advanced_column_mapping' => false,
82 'dry_run' => false,
83 'background_processing' => false,
84 'scheduled_imports' => false,
85 'external_sources' => false,
86 'advanced_export_filters' => false,
87 'advanced_duplicate_rules' => false,
88 'diagnostics' => false,
89 'cli' => false,
90 ],
91 'pro_features' => [
92 'advanced_column_mapping',
93 'dry_run',
94 'background_processing',
95 'scheduled_imports',
96 'external_sources',
97 'advanced_export_filters',
98 'advanced_duplicate_rules',
99 'diagnostics',
100 'cli',
101 ],
102 'urls' => [
103 'documentation' => 'https://pluginswordpress.calliope.com.ar/export-import-media/',
104 'support' => 'https://wordpress.org/support/plugin/' . $public_slug . '/',
105 'reviews' => 'https://wordpress.org/support/plugin/' . $public_slug . '/reviews/#new-post',
106 'pro' => 'https://pluginswordpress.calliope.com.ar/export-import-media/',
107 ],
108 ];
109
110 return apply_filters( 'eim_config_defaults', $defaults );
111 }
112
113 public static function get_settings() {
114 $stored = get_option( self::get_option_key(), [] );
115 if ( ! is_array( $stored ) ) {
116 $stored = [];
117 }
118
119 return self::merge_recursive( self::get_defaults(), $stored );
120 }
121
122 public static function get( $path, $default = null ) {
123 $settings = self::get_settings();
124 if ( '' === (string) $path ) {
125 return $settings;
126 }
127
128 $segments = explode( '.', (string) $path );
129 $value = $settings;
130
131 foreach ( $segments as $segment ) {
132 if ( ! is_array( $value ) || ! array_key_exists( $segment, $value ) ) {
133 return $default;
134 }
135
136 $value = $value[ $segment ];
137 }
138
139 return $value;
140 }
141
142 public static function get_feature_flags() {
143 $flags = self::get( 'features', [] );
144 if ( ! is_array( $flags ) ) {
145 $flags = [];
146 }
147
148 return apply_filters( 'eim_feature_flags', $flags, self::get_settings() );
149 }
150
151 public static function get_pro_features() {
152 $features = self::get( 'pro_features', [] );
153 return is_array( $features ) ? $features : [];
154 }
155
156 public static function is_pro_feature( $feature ) {
157 return in_array( (string) $feature, self::get_pro_features(), true );
158 }
159
160 public static function get_import_batch_size_options() {
161 $options = self::get( 'import.batch_size_options', [] );
162 $options = is_array( $options ) ? $options : [];
163 return apply_filters( 'eim_import_batch_size_options', $options );
164 }
165
166 public static function get_import_option_definitions() {
167 $options = self::get( 'import.options', [] );
168 $options = is_array( $options ) ? $options : [];
169 return apply_filters( 'eim_admin_import_options', $options );
170 }
171
172 public static function get_export_defaults() {
173 $defaults = self::get( 'export.defaults', [] );
174 $defaults = is_array( $defaults ) ? $defaults : [];
175 return apply_filters( 'eim_export_default_filters', $defaults );
176 }
177
178 public static function get_export_media_type_options() {
179 $options = self::get( 'export.media_type_options', [] );
180 $options = is_array( $options ) ? $options : [];
181 return apply_filters( 'eim_export_media_type_options', $options );
182 }
183
184 public static function get_export_attachment_filter_options() {
185 $options = self::get( 'export.attachment_filter_options', [] );
186 $options = is_array( $options ) ? $options : [];
187 return apply_filters( 'eim_export_attachment_filter_options', $options );
188 }
189
190 private static function merge_recursive( $defaults, $values ) {
191 foreach ( $values as $key => $value ) {
192 if ( isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) && is_array( $value ) ) {
193 $defaults[ $key ] = self::merge_recursive( $defaults[ $key ], $value );
194 } else {
195 $defaults[ $key ] = $value;
196 }
197 }
198
199 return $defaults;
200 }
201 }
202