calliope-media-import-export
Last commit date
admin
1 week ago
assets
1 week ago
includes
1 week ago
languages
1 week ago
export-import-media.php
1 week ago
readme.txt
1 week ago
export-import-media.php
247 lines
| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: Export/Import Media |
| 4 | Description: CSV export/import for your media library with preview, batch processing, duplicate prevention, and core metadata columns. |
| 5 | Version: 1.7.28 |
| 6 | Requires at least: 5.6 |
| 7 | Requires PHP: 7.4 |
| 8 | Author: CalliopeWP |
| 9 | Author URI: https://pluginswordpress.calliope.com.ar/ |
| 10 | License: GPLv2 or later |
| 11 | Text Domain: calliope-media-import-export |
| 12 | Domain Path: /languages |
| 13 | */ |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit; |
| 17 | } |
| 18 | |
| 19 | // Prevent fatal errors when two copies of the plugin are loaded at the same time. |
| 20 | if ( defined( 'EIM_BOOTSTRAPPED_FILE' ) ) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | define( 'EIM_BOOTSTRAPPED_FILE', __FILE__ ); |
| 25 | |
| 26 | if ( ! defined( 'EIM_FILE' ) ) { |
| 27 | define( 'EIM_FILE', __FILE__ ); |
| 28 | } |
| 29 | |
| 30 | if ( ! defined( 'EIM_VERSION' ) ) { |
| 31 | define( 'EIM_VERSION', '1.7.28' ); |
| 32 | } |
| 33 | |
| 34 | if ( ! defined( 'EIM_PUBLIC_SLUG' ) ) { |
| 35 | define( 'EIM_PUBLIC_SLUG', 'calliope-media-import-export' ); |
| 36 | } |
| 37 | |
| 38 | if ( ! defined( 'EIM_TEXT_DOMAIN' ) ) { |
| 39 | define( 'EIM_TEXT_DOMAIN', 'calliope-media-import-export' ); |
| 40 | } |
| 41 | |
| 42 | if ( ! defined( 'EIM_ADMIN_PAGE_SLUG' ) ) { |
| 43 | define( 'EIM_ADMIN_PAGE_SLUG', 'export-import-media' ); |
| 44 | } |
| 45 | |
| 46 | if ( ! defined( 'EIM_PATH' ) ) { |
| 47 | define( 'EIM_PATH', plugin_dir_path( EIM_FILE ) ); |
| 48 | } |
| 49 | |
| 50 | if ( ! defined( 'EIM_URL' ) ) { |
| 51 | define( 'EIM_URL', plugin_dir_url( EIM_FILE ) ); |
| 52 | } |
| 53 | |
| 54 | if ( ! defined( 'EIM_BASENAME' ) ) { |
| 55 | define( 'EIM_BASENAME', plugin_basename( EIM_FILE ) ); |
| 56 | } |
| 57 | |
| 58 | if ( ! defined( 'EIM_INSTALLED_AT_OPTION' ) ) { |
| 59 | define( 'EIM_INSTALLED_AT_OPTION', 'eim_installed_at' ); |
| 60 | } |
| 61 | |
| 62 | if ( ! defined( 'EIM_REVIEW_POPUP_DISMISSED_OPTION' ) ) { |
| 63 | define( 'EIM_REVIEW_POPUP_DISMISSED_OPTION', 'eim_review_popup_dismissed' ); |
| 64 | } |
| 65 | |
| 66 | if ( ! function_exists( 'eim_load_textdomain' ) ) { |
| 67 | /** |
| 68 | * Load bundled translations for the free plugin. |
| 69 | * |
| 70 | * @return void |
| 71 | */ |
| 72 | function eim_load_textdomain() { |
| 73 | load_plugin_textdomain( EIM_TEXT_DOMAIN, false, dirname( EIM_BASENAME ) . '/languages' ); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | add_action( 'plugins_loaded', 'eim_load_textdomain' ); |
| 78 | |
| 79 | require_once EIM_PATH . 'includes/class-config.php'; |
| 80 | require_once EIM_PATH . 'includes/class-eim-service-registry.php'; |
| 81 | |
| 82 | if ( ! function_exists( 'eim_get_setting' ) ) { |
| 83 | /** |
| 84 | * Get a plugin setting using dot notation. |
| 85 | * |
| 86 | * @param string $path Dot notation path. |
| 87 | * @param mixed $default Default value when setting does not exist. |
| 88 | * @return mixed |
| 89 | */ |
| 90 | function eim_get_setting( $path, $default = null ) { |
| 91 | return EIM_Config::get( $path, $default ); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if ( ! function_exists( 'eim_get_public_slug' ) ) { |
| 96 | /** |
| 97 | * Get the canonical public plugin slug. |
| 98 | * |
| 99 | * @return string |
| 100 | */ |
| 101 | function eim_get_public_slug() { |
| 102 | return (string) apply_filters( 'eim_public_slug', EIM_PUBLIC_SLUG ); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | if ( ! function_exists( 'eim_get_required_capability' ) ) { |
| 107 | /** |
| 108 | * Capability required to access plugin features. |
| 109 | * |
| 110 | * Filterable so future extensions can align permissions without forking core. |
| 111 | * |
| 112 | * @return string |
| 113 | */ |
| 114 | function eim_get_required_capability() { |
| 115 | $default = eim_get_setting( 'required_capability', 'manage_options' ); |
| 116 | $capability = apply_filters( 'eim_required_capability', $default ); |
| 117 | |
| 118 | if ( ! is_string( $capability ) || '' === trim( $capability ) ) { |
| 119 | return 'manage_options'; |
| 120 | } |
| 121 | |
| 122 | return trim( $capability ); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | if ( ! function_exists( 'eim_current_user_can_manage' ) ) { |
| 127 | /** |
| 128 | * Check whether the current user can access the plugin. |
| 129 | * |
| 130 | * @return bool |
| 131 | */ |
| 132 | function eim_current_user_can_manage() { |
| 133 | return current_user_can( eim_get_required_capability() ); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if ( ! function_exists( 'eim_is_pro_active' ) ) { |
| 138 | /** |
| 139 | * Whether a Pro add-on is active. |
| 140 | * |
| 141 | * The add-on can define a constant or use the filter to report itself. |
| 142 | * |
| 143 | * @return bool |
| 144 | */ |
| 145 | function eim_is_pro_active() { |
| 146 | $is_active = ( |
| 147 | defined( 'EIM_PRO_VERSION' ) || |
| 148 | defined( 'EXPORT_IMPORT_MEDIA_PRO_VERSION' ) || |
| 149 | class_exists( 'EIM_Pro_Plugin', false ) || |
| 150 | class_exists( 'EIM_Pro_Bootstrap', false ) |
| 151 | ); |
| 152 | |
| 153 | return (bool) apply_filters( 'eim_is_pro_active', $is_active ); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | if ( ! function_exists( 'eim_is_feature_enabled' ) ) { |
| 158 | /** |
| 159 | * Check whether a feature flag is enabled. |
| 160 | * |
| 161 | * @param string $feature Feature slug. |
| 162 | * @return bool |
| 163 | */ |
| 164 | function eim_is_feature_enabled( $feature ) { |
| 165 | $feature = sanitize_key( (string) $feature ); |
| 166 | if ( '' === $feature ) { |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | $flags = EIM_Config::get_feature_flags(); |
| 171 | $enabled = ! empty( $flags[ $feature ] ); |
| 172 | |
| 173 | return (bool) apply_filters( 'eim_is_feature_enabled', $enabled, $feature, $flags ); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | if ( ! function_exists( 'eim_get_service' ) ) { |
| 178 | /** |
| 179 | * Fetch a bootstrapped plugin service. |
| 180 | * |
| 181 | * @param string|null $service Service key. Pass null to retrieve the full map. |
| 182 | * @return mixed|null |
| 183 | */ |
| 184 | function eim_get_service( $service = null ) { |
| 185 | $services = EIM_Service_Registry::all(); |
| 186 | |
| 187 | if ( null === $service || '' === $service ) { |
| 188 | return $services; |
| 189 | } |
| 190 | |
| 191 | return EIM_Service_Registry::get( $service ); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | if ( ! class_exists( 'EIM_Importer', false ) ) { |
| 196 | require_once EIM_PATH . 'includes/class-importer.php'; |
| 197 | } |
| 198 | |
| 199 | if ( ! class_exists( 'EIM_Admin', false ) ) { |
| 200 | require_once EIM_PATH . 'admin/class-admin.php'; |
| 201 | } |
| 202 | |
| 203 | if ( ! class_exists( 'EIM_Exporter', false ) ) { |
| 204 | require_once EIM_PATH . 'includes/class-exporter.php'; |
| 205 | } |
| 206 | |
| 207 | |
| 208 | if ( ! function_exists( 'eim_init_plugin' ) ) { |
| 209 | /** |
| 210 | * Bootstrap plugin services. |
| 211 | */ |
| 212 | function eim_init_plugin() { |
| 213 | static $booted = false; |
| 214 | |
| 215 | if ( $booted ) { |
| 216 | return; |
| 217 | } |
| 218 | |
| 219 | $booted = true; |
| 220 | |
| 221 | $services = []; |
| 222 | |
| 223 | if ( class_exists( 'EIM_Admin' ) ) { |
| 224 | $services['admin'] = new EIM_Admin(); |
| 225 | } |
| 226 | |
| 227 | if ( class_exists( 'EIM_Importer' ) ) { |
| 228 | $services['importer'] = new EIM_Importer(); |
| 229 | } |
| 230 | |
| 231 | if ( class_exists( 'EIM_Exporter' ) ) { |
| 232 | $services['exporter'] = new EIM_Exporter(); |
| 233 | } |
| 234 | |
| 235 | EIM_Service_Registry::set_services( $services ); |
| 236 | |
| 237 | do_action( 'eim_plugin_ready', $services ); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | add_action( 'plugins_loaded', 'eim_init_plugin' ); |
| 242 | |
| 243 | if ( class_exists( 'EIM_Importer' ) ) { |
| 244 | register_activation_hook( EIM_FILE, [ 'EIM_Importer', 'activate_plugin' ] ); |
| 245 | register_deactivation_hook( EIM_FILE, [ 'EIM_Importer', 'deactivate_plugin' ] ); |
| 246 | } |
| 247 |