Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/wp-import-export-lite/deactivate-plugins.php
+++ b/wp-import-export-lite/deactivate-plugins.php
@@ -1,20 +1,79 @@
-<?php
-
-defined( 'ABSPATH' ) || exit;
-
-if ( ! function_exists( "wpie_auto_deactivate_pro_plugins" ) ) {
-
- function wpie_auto_deactivate_pro_plugins() {
-
- $plugins = [];
-
- if ( is_plugin_active( 'woo-import-export/woo-import-export.php' ) || is_plugin_active( 'vj-wp-import-export/vj-wp-import-export.php' ) ) {
-
- $plugins[] = 'wp-import-export-lite/wp-import-export-lite.php';
- }
- if ( ! empty( $plugins ) ) {
- deactivate_plugins( $plugins );
- }
- }
-
-}
+<?php
+/**
+ * Auto-deactivation of conflicting plugins.
+ *
+ * Automatically deactivates the Lite version if the Pro version of WP Import Export
+ * or Woo Import Export is detected as active.
+ *
+ * @package WP_Import_Export_Lite
+ * @subpackage WP_Import_Export_Lite/bootstrap
+ * @since 1.0.0
+ */
+
+defined( 'ABSPATH' ) || exit;
+
+if ( ! function_exists( 'wpie_auto_deactivate_pro_plugins' ) ) {
+ /**
+ * Automatically deactivates the Lite version if Pro version is active.
+ *
+ * Checks for the presence of the Pro plugin and cleanly deactivates Lite,
+ * ensuring no function or class redeclaration conflicts occur.
+ *
+ * @since 1.0.0
+ * @return void
+ */
+ function wpie_auto_deactivate_pro_plugins() {
+ if ( ! function_exists( 'is_plugin_active' ) ) {
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
+ }
+
+ if ( ! current_user_can( 'activate_plugins' ) ) {
+ return;
+ }
+
+ $pro_plugins = array(
+ 'woo-import-export/woo-import-export.php',
+ 'vj-wp-import-export/vj-wp-import-export.php',
+ );
+
+ $is_pro_active = false;
+ foreach ( $pro_plugins as $pro_plugin ) {
+ if ( is_plugin_active( $pro_plugin ) ) {
+ $is_pro_active = true;
+ break;
+ }
+ }
+
+ if ( $is_pro_active ) {
+ $lite_plugin = 'wp-import-export-lite/wp-import-export-lite.php';
+ if ( is_plugin_active( $lite_plugin ) ) {
+ deactivate_plugins( array( $lite_plugin ) );
+ set_transient( 'wpie_lite_deactivated_notice', 1, 60 );
+ }
+ }
+ }
+}
+
+if ( ! function_exists( 'wpie_deactivated_pro_admin_notice' ) ) {
+ /**
+ * Displays an admin notice informing the user that Lite was deactivated in favor of Pro.
+ *
+ * @since 1.0.0
+ * @return void
+ */
+ function wpie_deactivated_pro_admin_notice() {
+ if ( get_transient( 'wpie_lite_deactivated_notice' ) ) {
+ delete_transient( 'wpie_lite_deactivated_notice' );
+ ?>
+ <div class="notice notice-warning is-dismissible">
+ <p>
+ <?php
+ echo esc_html__( 'WP Import Export Lite has been automatically deactivated because WP Import Export Pro is active.', 'wp-import-export-lite' );
+ ?>
+ </p>
+ </div>
+ <?php
+ }
+ }
+ add_action( 'admin_notices', 'wpie_deactivated_pro_admin_notice' );
+}
--- a/wp-import-export-lite/includes/classes/class-updates.php
+++ b/wp-import-export-lite/includes/classes/class-updates.php
@@ -1,5 +1,4 @@
<?php
-
/**
* Functions and actions related to updates.
*
@@ -15,89 +14,97 @@
/**
* Updates class
- *
- * Functions and actions related to updates.
+ *
+ * Handles version checking and automatic database migrations.
*
* @since 1.5.0
- *
- * @class Updates auto update for plugin
*/
class Updates {
- /**
- * Updates that need to be run
- *
- * @since 1.5.0
- * @access private
- *
- * @var array
- */
- private static $updates = [
- '1.5.0' => 'update-1.5.0.php'
- ];
-
- /**
- * Class Constructor
- *
- * Register hooks.
- *
- * @since 1.5.0
- * @access public
- */
- public function __construct() {
-
- add_action( 'admin_init', [ $this, 'do_updates' ] );
- }
-
- /**
- * Check if any update is required.
- *
- * @since 1.5.0
- * @access public
- */
- public function do_updates() {
-
- $installed_version = get_option( 'wpie_plugin_version' );
-
- // Maybe it's the first install.
- if ( ! $installed_version ) {
- return;
- }
-
- if ( version_compare( $installed_version, WPIE_PLUGIN_VERSION, '<' ) ) {
- $this->perform_updates();
- }
- }
-
- /**
- * Perform plugin updates.
- *
- * Perform all database updates.
- *
- * @since 1.5.0
- * @access public
- */
- private function perform_updates() {
-
- $installed_version = get_option( 'wpie_plugin_version' );
-
- foreach ( self::$updates as $version => $path ) {
-
- $abs_path = WPIE_CLASSES_DIR . "/updates/" . $path;
-
- if ( version_compare( $installed_version, $version, '<' ) && file_exists( $abs_path ) ) {
- require_once $abs_path;
- }
- }
-
- // Save install date.
- if ( false === boolval( get_option( 'wpie_install_date' ) ) ) {
- update_option( 'wpie_install_date', current_time( 'timestamp' ) );
- }
-
- update_option( 'wpie_plugin_version', WPIE_PLUGIN_VERSION );
+ /**
+ * Updates that need to be run, mapped by version to filename.
+ *
+ * @since 1.5.0
+ * @access private
+ *
+ * @var array
+ */
+ private static $updates = array(
+ '1.5.0' => 'update-1.5.0.php',
+ );
+
+ /**
+ * Class Constructor
+ *
+ * Registers update hooks on admin_init.
+ *
+ * @since 1.5.0
+ * @access public
+ */
+ public function __construct() {
+ add_action( 'admin_init', array( $this, 'do_updates' ) );
+ }
+
+ /**
+ * Check if any update is required and current user is authorized.
+ *
+ * @since 1.5.0
+ * @access public
+ *
+ * @return void
+ */
+ public function do_updates() {
+ if ( ! current_user_can( 'manage_options' ) ) {
+ return;
+ }
+
+ $installed_version = get_option( 'wpie_plugin_version' );
+
+ // Maybe it's the first install.
+ if ( ! $installed_version ) {
+ return;
+ }
+
+ if ( version_compare( (string) $installed_version, WPIE_PLUGIN_VERSION, '<' ) ) {
+ $this->perform_updates();
+ }
+ }
+
+ /**
+ * Perform plugin updates.
+ *
+ * Iterates over update scripts and applies pending migrations.
+ *
+ * @since 1.5.0
+ * @access private
+ *
+ * @return void
+ */
+ private function perform_updates() {
+ if ( get_transient( 'wpie_performing_updates' ) ) {
+ return;
+ }
+
+ set_transient( 'wpie_performing_updates', 1, 5 * MINUTE_IN_SECONDS );
+
+ $installed_version = get_option( 'wpie_plugin_version' );
+
+ foreach ( self::$updates as $version => $path ) {
+ $abs_path = wp_normalize_path( WPIE_CLASSES_DIR . '/updates/' . $path );
+
+ if ( version_compare( (string) $installed_version, (string) $version, '<' ) && file_exists( $abs_path ) ) {
+ require_once $abs_path;
+ }
+ }
+
+ // Save install date if not set.
+ if ( ! get_option( 'wpie_install_date' ) ) {
+ update_option( 'wpie_install_date', time() );
+ }
- update_option( 'wpie_db_version', WPIE_DB_VERSION );
- }
+ update_option( 'wpie_plugin_version', WPIE_PLUGIN_VERSION );
+ update_option( 'wpie_db_version', WPIE_DB_VERSION );
+ delete_transient( 'wpie_performing_updates' );
+ }
}
--- a/wp-import-export-lite/includes/classes/class-wpie-action.php
+++ b/wp-import-export-lite/includes/classes/class-wpie-action.php
@@ -1,38 +1,65 @@
-<?php
-
-
-defined( 'ABSPATH' ) || exit;
-
-if ( substr( wpie_sanitize_field( $_REQUEST[ 'action' ] ), 0, 11 ) == 'wpie_export' ) {
-
- if ( file_exists( WPIE_EXPORT_CLASSES_DIR . '/class-wpie-export-actions.php' ) ) {
-
- require_once(WPIE_EXPORT_CLASSES_DIR . '/class-wpie-export-actions.php');
-
- $action = new wpieexportactionsWPIE_Export_Actions();
-
- unset( $action );
- }
-} elseif ( substr( wpie_sanitize_field( $_REQUEST[ 'action' ] ), 0, 11 ) == 'wpie_import' ) {
-
- if ( file_exists( WPIE_IMPORT_CLASSES_DIR . '/class-wpie-import-actions.php' ) ) {
- require_once(WPIE_IMPORT_CLASSES_DIR . '/class-wpie-import-actions.php');
- $action = new wpieimportWPIE_Import_Actions();
-
- unset( $action );
- }
-} elseif ( substr( wpie_sanitize_field( $_REQUEST[ 'action' ] ), 0, 8 ) == 'wpie_ext' ) {
-
- if ( file_exists( WPIE_CLASSES_DIR . '/class-wpie-extensions.php' ) ) {
- require_once(WPIE_CLASSES_DIR . '/class-wpie-extensions.php');
- $wpie_ext = new wpieaddonsWPIE_Extension();
- unset( $wpie_ext );
- }
-} else {
- if ( file_exists( WPIE_CLASSES_DIR . '/class-wpie-common-action.php' ) ) {
- require_once(WPIE_CLASSES_DIR . '/class-wpie-common-action.php');
- $action = new WPIE_Common_Actions();
- unset( $action );
- }
-}
-
+<?php
+/**
+ * AJAX Action Router.
+ *
+ * Routes incoming WPIE AJAX requests to the corresponding module controller:
+ * Export, Import, Extensions, or Common Actions.
+ *
+ * @since 1.0.0
+ * @package wpie
+ * @subpackage wpieCore
+ * @author VJinfotech <support@vjinfotech.com>
+ */
+
+defined( 'ABSPATH' ) || exit;
+
+use WpieAppCoreHelpersParam;
+
+// Ensure Param helper is loaded if invoked outside standard loader.
+if ( ! class_exists( 'WpieAppCoreHelpersParam' ) ) {
+ if ( defined( 'WPIE_HELPERS_DIR' ) && file_exists( WPIE_HELPERS_DIR . '/Param.php' ) ) {
+ require_once WPIE_HELPERS_DIR . '/Param.php';
+ } elseif ( file_exists( dirname( __FILE__ ) . '/helpers/Param.php' ) ) {
+ require_once dirname( __FILE__ ) . '/helpers/Param.php';
+ }
+}
+
+$wpie_action = class_exists( 'WpieAppCoreHelpersParam' )
+ ? Param::requestSanitized( 'action', 'key', '' )
+ : ( isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : '' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
+
+if ( '' !== $wpie_action && strpos( $wpie_action, 'wpie_export' ) === 0 ) {
+ if ( defined( 'WPIE_EXPORT_CLASSES_DIR' ) && file_exists( WPIE_EXPORT_CLASSES_DIR . '/class-wpie-export-actions.php' ) ) {
+ require_once WPIE_EXPORT_CLASSES_DIR . '/class-wpie-export-actions.php';
+ if ( class_exists( 'wpieexportactionsWPIE_Export_Actions' ) ) {
+ $wpie_action_instance = new wpieexportactionsWPIE_Export_Actions();
+ unset( $wpie_action_instance );
+ }
+ }
+} elseif ( '' !== $wpie_action && strpos( $wpie_action, 'wpie_import' ) === 0 ) {
+ if ( defined( 'WPIE_IMPORT_CLASSES_DIR' ) && file_exists( WPIE_IMPORT_CLASSES_DIR . '/class-wpie-import-actions.php' ) ) {
+ require_once WPIE_IMPORT_CLASSES_DIR . '/class-wpie-import-actions.php';
+ if ( class_exists( 'wpieimportWPIE_Import_Actions' ) ) {
+ $wpie_action_instance = new wpieimportWPIE_Import_Actions();
+ unset( $wpie_action_instance );
+ }
+ }
+} elseif ( '' !== $wpie_action && strpos( $wpie_action, 'wpie_ext' ) === 0 ) {
+ if ( defined( 'WPIE_CLASSES_DIR' ) && file_exists( WPIE_CLASSES_DIR . '/class-wpie-extensions.php' ) ) {
+ require_once WPIE_CLASSES_DIR . '/class-wpie-extensions.php';
+ if ( class_exists( 'wpieaddonsWPIE_Extension' ) ) {
+ $wpie_ext_instance = new wpieaddonsWPIE_Extension();
+ unset( $wpie_ext_instance );
+ }
+ }
+} else {
+ if ( defined( 'WPIE_CLASSES_DIR' ) && file_exists( WPIE_CLASSES_DIR . '/class-wpie-common-action.php' ) ) {
+ require_once WPIE_CLASSES_DIR . '/class-wpie-common-action.php';
+ if ( class_exists( 'WPIE_Common_Actions' ) ) {
+ $wpie_action_instance = new WPIE_Common_Actions();
+ unset( $wpie_action_instance );
+ }
+ }
+}
+
+unset( $wpie_action );
--- a/wp-import-export-lite/includes/classes/class-wpie-common-action.php
+++ b/wp-import-export-lite/includes/classes/class-wpie-common-action.php
@@ -1,591 +1,825 @@
-<?php
-
-defined( 'ABSPATH' ) || exit;
-
-if ( file_exists( WPIE_CLASSES_DIR . '/class-wpie-security.php' ) ) {
- require_once(WPIE_CLASSES_DIR . '/class-wpie-security.php');
-}
-
-class WPIE_Common_Actions {
-
- public function __construct() {
-
- add_action( 'wp_ajax_wpie_save_user_cap', array( $this, 'wpie_save_user_cap' ) );
-
- add_action( 'wp_ajax_wpie_get_user_cap', array( $this, 'wpie_get_user_cap' ) );
-
- add_action( 'wp_ajax_wpie_delete_tempaltes', array( $this, 'wpie_delete_tempaltes' ) );
-
- add_action( 'wp_ajax_wpie_tempalte_import', array( $this, 'wpie_tempalte_import' ) );
-
- add_action( 'wp_ajax_wpie_get_tempaltes', array( $this, 'wpie_get_tempalte_list' ) );
-
- add_action( 'wp_ajax_wpie_save_advance_option', array( $this, 'wpie_save_advance_option' ) );
-
- add_action( 'wp_ajax_wpie_update_process_status', array( $this, 'update_process_status' ) );
-
- add_action( 'wp_ajax_wpie_save_bg_cron_processing', array( $this, 'wpie_save_bg_cron_processing' ) );
-
- add_action( 'wp_ajax_wpie_change_license_status', array( $this, 'wpie_change_license_status' ) );
- }
-
- public function wpie_save_user_cap() {
-
- wpieSecurity::verify_request( 'wpie_settings' );
-
- $new_export = isset( $_POST[ 'wpie_cap_new_export' ] ) ? intval( wpie_sanitize_field( $_POST[ 'wpie_cap_new_export' ] ) ) : 0;
-
- $manage_export = isset( $_POST[ 'wpie_cap_manage_export' ] ) ? intval( wpie_sanitize_field( $_POST[ 'wpie_cap_manage_export' ] ) ) : 0;
-
- $new_import = isset( $_POST[ 'wpie_cap_new_import' ] ) ? intval( wpie_sanitize_field( $_POST[ 'wpie_cap_new_import' ] ) ) : 0;
-
- $manage_import = isset( $_POST[ 'wpie_cap_manage_import' ] ) ? intval( wpie_sanitize_field( $_POST[ 'wpie_cap_manage_import' ] ) ) : 0;
-
- $cap_settings = isset( $_POST[ 'wpie_cap_settings' ] ) ? intval( wpie_sanitize_field( $_POST[ 'wpie_cap_settings' ] ) ) : 0;
-
- $cap_ext = isset( $_POST[ 'wpie_cap_ext' ] ) ? intval( wpie_sanitize_field( $_POST[ 'wpie_cap_ext' ] ) ) : 0;
-
- $add_shortcode = isset( $_POST[ 'wpie_cap_add_shortcode' ] ) ? intval( wpie_sanitize_field( $_POST[ 'wpie_cap_add_shortcode' ] ) ) : 0;
-
- $wpie_user_role = isset( $_POST[ 'wpie_user_role' ] ) ? wpie_sanitize_field( $_POST[ 'wpie_user_role' ] ) : "";
-
- $role = get_role( $wpie_user_role );
-
- unset( $wpie_user_role );
-
- if ( $role ) {
-
- if ( $new_export == 1 ) {
- if ( !$role->has_cap( 'wpie_new_export' ) ) {
- $role->add_cap( 'wpie_new_export' );
- }
- } else {
- $role->remove_cap( 'wpie_new_export' );
- }
-
- if ( $manage_export == 1 ) {
- if ( !$role->has_cap( 'wpie_manage_export' ) ) {
- $role->add_cap( 'wpie_manage_export' );
- }
- } else {
- $role->remove_cap( 'wpie_manage_export' );
- }
-
- if ( $new_import == 1 ) {
- if ( !$role->has_cap( 'wpie_new_import' ) ) {
- $role->add_cap( 'wpie_new_import' );
- }
- } else {
- $role->remove_cap( 'wpie_new_import' );
- }
- if ( $manage_import == 1 ) {
- if ( !$role->has_cap( 'wpie_manage_import' ) ) {
- $role->add_cap( 'wpie_manage_import' );
- }
- } else {
- $role->remove_cap( 'wpie_manage_import' );
- }
- if ( $cap_settings == 1 ) {
- if ( !$role->has_cap( 'wpie_settings' ) ) {
- $role->add_cap( 'wpie_settings' );
- }
- } else {
- $role->remove_cap( 'wpie_settings' );
- }
- if ( $cap_ext == 1 ) {
- if ( !$role->has_cap( 'wpie_extensions' ) ) {
- $role->add_cap( 'wpie_extensions' );
- }
- } else {
- $role->remove_cap( 'wpie_extensions' );
- }
- if ( $add_shortcode == 1 ) {
- if ( !$role->has_cap( 'wpie_add_shortcode' ) ) {
- $role->add_cap( 'wpie_add_shortcode' );
- }
- } else {
- $role->remove_cap( 'wpie_add_shortcode' );
- }
- }
-
- unset( $new_export, $manage_export, $new_import, $manage_import, $cap_settings, $cap_ext, $role, $add_shortcode );
-
- $return_value = array();
-
- $return_value[ 'status' ] = 'success';
-
- $return_value[ 'message' ] = __( 'Role Successfully Saved', 'wp-import-export-lite' );
-
- echo json_encode( $return_value );
-
- unset( $return_value );
-
- die();
- }
-
- public function wpie_get_user_cap() {
-
- wpieSecurity::verify_request( 'wpie_settings' );
-
- $wpie_user_role = isset( $_GET[ 'user_role' ] ) ? wpie_sanitize_field( $_GET[ 'user_role' ] ) : "";
-
- $role = get_role( $wpie_user_role );
-
- $cap = array();
-
- if ( $role ) {
- if ( $role->has_cap( 'wpie_new_export' ) ) {
- $cap[] = 'wpie_new_export';
- }
- if ( $role->has_cap( 'wpie_manage_export' ) ) {
- $cap[] = 'wpie_manage_export';
- }
- if ( $role->has_cap( 'wpie_new_import' ) ) {
- $cap[] = 'wpie_new_import';
- }
- if ( $role->has_cap( 'wpie_manage_import' ) ) {
- $cap[] = 'wpie_manage_import';
- }
- if ( $role->has_cap( 'wpie_settings' ) ) {
- $cap[] = 'wpie_settings';
- }
- if ( $role->has_cap( 'wpie_extensions' ) ) {
- $cap[] = 'wpie_extensions';
- }
- if ( $role->has_cap( 'wpie_add_shortcode' ) ) {
- $cap[] = 'wpie_add_shortcode';
- }
- }
-
- $return_value = array();
-
- $return_value[ 'status' ] = 'success';
-
- $return_value[ 'cap' ] = $cap;
-
- unset( $role, $wpie_user_role, $cap );
-
- echo json_encode( $return_value );
-
- unset( $return_value );
-
- die();
- }
-
- public function wpie_get_tempalte_list() {
-
- wpieSecurity::verify_request( 'wpie_settings' );
-
- $templates = $this->wpie_get_templates();
-
- $template_html = "";
-
- if ( !empty( $templates ) ) {
-
- foreach ( $templates as $data ) {
-
- $id = isset( $data->id ) ? $data->id : 0;
-
- $options = isset( $data->options ) ? maybe_unserialize( $data->options ) : array();
-
- $name = isset( $options[ 'wpie_template_name' ] ) ? $options[ 'wpie_template_name' ] : "";
-
- if ( $id > 0 && !empty( $name ) ) {
-
- $template_html .= '<option value="' . esc_attr( $id ) . '">' . esc_html( $name ) . '</option>';
- }
-
- unset( $id, $options, $name );
- }
- }
- $return_value = array();
-
- $return_value[ 'status' ] = 'success';
-
- $return_value[ 'html' ] = $template_html;
-
- unset( $templates, $template_html );
-
- echo json_encode( $return_value );
-
- unset( $return_value );
-
- die();
- }
-
- public function get_export_list( $limit = 25 ) {
-
- global $wpdb;
-
- $limit = absint( $limit ) > 0 ? absint( $limit ) : 25;
-
- $results = $wpdb->get_results(
- $wpdb->prepare(
- "SELECT * FROM " . $wpdb->prefix . "wpie_template where `opration` IN ('export','schedule_export') ORDER BY `id` DESC limit 0,%d"
- , $limit )
- );
-
- return $results;
- }
-
- public function get_import_list( $limit = 25 ) {
-
- global $wpdb;
-
- $limit = absint( $limit ) > 0 ? absint( $limit ) : 25;
-
- $results = $wpdb->get_results(
- $wpdb->prepare(
- "SELECT * FROM " . $wpdb->prefix . "wpie_template where `opration` IN ('import','schedule_import') ORDER BY `id` DESC limit 0,%d"
- , $limit )
- );
-
- return $results;
- }
-
- public function wpie_get_templates() {
-
- global $wpdb;
-
- $results = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "wpie_template where `opration` IN ('import_template','export_template')" );
-
- return $results;
- }
-
- public function wpie_delete_tempaltes() {
-
- wpieSecurity::verify_request( 'wpie_settings' );
-
- $ids = isset( $_GET[ 'templates' ] ) ? wpie_sanitize_field( $_GET[ 'templates' ] ) : "";
-
- if ( !empty( $ids ) ) {
-
- if ( is_string( $ids ) ) {
- $ids = explode( ",", $ids );
- }
-
- if ( !is_array( $ids ) ) {
- $ids = [ $ids ];
- }
-
- $ids = array_map( 'absint', $ids );
-
- if ( !empty( $ids ) ) {
-
- global $wpdb;
-
- foreach ( $ids as $id ) {
-
- if ( $id < 1 ) {
- continue;
- }
- $template = $wpdb->get_row( $wpdb->prepare( "SELECT opration,options FROM " . $wpdb->prefix . "wpie_template where `id` = %d limit 0,1", $id ) );
-
- $opration = isset( $template->opration ) ? $template->opration : "import";
-
- $options = isset( $template->options ) ? maybe_unserialize( $template->options ) : [];
-
- if ( in_array( $opration, [ "import", "schedule_import", "schedule_import_template" ] ) ) {
-
- if ( $opration === "schedule_import_template" ) {
- wp_clear_scheduled_hook( 'wpie_cron_schedule_import', [ $id ] );
- }
-
- $importFile = isset( $options[ 'importFile' ] ) ? $options[ 'importFile' ] : [];
-
- if ( empty( $importFile ) ) {
- continue;
- }
-
- foreach ( $importFile as $fileData ) {
-
- $baseDir = isset( $fileData[ 'baseDir' ] ) ? wpie_sanitize_field( $fileData[ 'baseDir' ] ) : "";
-
- if ( empty( trim( $baseDir ) ) ) {
- continue;
- }
-
- $this->remove_dir( WPIE_UPLOAD_IMPORT_DIR . "/" . $baseDir );
- }
- } elseif ( in_array( $opration, [ "export", "schedule_export", "schedule_export_template" ] ) ) {
-
- if ( $opration === "schedule_export_template" ) {
- wp_clear_scheduled_hook( 'wpie_cron_schedule_export', [ $id ] );
- }
-
- $fileDir = isset( $options[ 'fileDir' ] ) ? $options[ 'fileDir' ] : "";
-
- if ( empty( trim( $fileDir ) ) ) {
- continue;
- }
-
- $this->remove_dir( WPIE_UPLOAD_EXPORT_DIR . "/" . $fileDir );
- }
- }
-
- $wpdb->query( "DELETE FROM " . $wpdb->prefix . "wpie_template WHERE id IN (" . implode( ',', $ids ) . ")" );
- }
- }
-
- $data = [ 'status' => 'success', "message" => __( 'Templates Successfully Deleted', 'wp-import-export-lite' ) ];
-
- echo json_encode( $data );
-
- unset( $return_value );
-
- die();
- }
-
- private function remove_dir( $targetDir = "" ) {
-
- if ( is_dir( $targetDir ) ) {
-
- $cdir = scandir( $targetDir );
-
- if ( is_array( $cdir ) && !empty( $cdir ) ) {
- foreach ( $cdir as $key => $value ) {
- if ( !in_array( $value, array( ".", ".." ) ) ) {
- if ( is_dir( $targetDir . '/' . $value ) ) {
- $this->remove_dir( $targetDir . '/' . $value );
- } else {
- unlink( $targetDir . '/' . $value );
- }
- }
- }
- }
-
- rmdir( $targetDir );
-
- unset( $cdir );
- }
- }
-
- public function wpie_save_advance_option() {
-
- wpieSecurity::verify_request( 'wpie_settings' );
-
- $is_delete_data = isset( $_GET[ 'is_delete_data' ] ) ? absint( wpie_sanitize_field( $_GET[ 'is_delete_data' ] ) ) : 0;
-
- update_option( "wpie_delete_on_uninstall", $is_delete_data );
-
- $return_value = array();
-
- $return_value[ 'status' ] = 'success';
-
- $return_value[ 'message' ] = __( 'Settings Successfully Saved', 'wp-import-export-lite' );
-
- echo json_encode( $return_value );
-
- unset( $return_value );
-
- die();
- }
-
- public function wpie_tempalte_import() {
-
- wpieSecurity::verify_request( 'wpie_settings' );
-
- $return_value = array( "status" => 'error' );
-
- $filename = isset( $_FILES[ 'wpie_template_file' ][ 'name' ] ) ? $_FILES[ 'wpie_template_file' ][ 'name' ] : '';
-
- $validate = wp_check_filetype( $filename );
-
- $mime_check = isset( $_FILES[ 'wpie_template_file' ][ 'type' ] ) ? $_FILES[ 'wpie_template_file' ][ 'type' ] : '';
-
- if ( $validate[ 'type' ] !== 'text/plain' || $mime_check !== 'text/plain' ) {
-
- echo json_encode( [ 'status' => 'error', 'message' => __( 'File type is not allowed', 'wp-import-export-lite' ) ] );
- die();
- }
-
- if ( $_FILES && file_exists( $_FILES[ 'wpie_template_file' ][ 'tmp_name' ] ) && is_uploaded_file( $_FILES[ 'wpie_template_file' ][ 'tmp_name' ] ) ) {
-
- if ( !function_exists( 'wp_handle_upload' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
- }
-
- $movefile = wp_handle_upload( $_FILES[ 'wpie_template_file' ], array( 'test_form' => false, 'test_type' => false ) );
-
- if ( $movefile && isset( $movefile[ 'file' ] ) && !isset( $movefile[ 'error' ] ) ) {
-
- $file_path = $movefile[ 'file' ];
-
- $template_data = file_get_contents( $file_path );
-
- if ( !empty( $template_data ) ) {
-
- $template_data = json_decode( $template_data );
-
- if ( !empty( $template_data ) ) {
-
- global $wpdb;
-
- $time = current_time( 'mysql' );
-
- $current_user = wp_get_current_user();
-
- $username = "";
-
- if ( $current_user && isset( $current_user->user_login ) ) {
- $username = $current_user->user_login;
- }
-
- foreach ( $template_data as $template ) {
-
-
- $data = [
- 'status' => "completed",
- 'opration' => isset( $template->opration ) ? $template->opration : "",
- 'username' => $username,
- 'unique_id' => uniqid(),
- 'opration_type' => isset( $template->opration_type ) ? $template->opration_type : "",
- 'options' => isset( $template->options ) ? maybe_serialize( json_decode( json_encode( $template->options ), true ) ) : "",
- 'process_log' => "",
- 'process_lock' => 0,
- 'create_date' => $time,
- 'last_update_date' => $time,
- ];
-
- $wpdb->insert( $wpdb->prefix . "wpie_template", $data );
- }
-
- $return_value[ 'status' ] = 'success';
- $return_value[ 'message' ] = __( 'Templates Successfully Imported', 'wp-import-export-lite' );
- } else {
- $return_value[ 'status' ] = 'error';
- $return_value[ 'message' ] = __( 'Empty Data', 'wp-import-export-lite' );
- }
- } else {
- $return_value[ 'status' ] = 'error';
- $return_value[ 'message' ] = __( 'Empty Data', 'wp-import-export-lite' );
- }
- unset( $template_data );
-
- unlink( $file_path );
- } else {
- $return_value[ 'status' ] = 'error';
- $return_value[ 'message' ] = isset( $movefile[ 'error' ] ) ? $movefile[ 'error' ] : __( 'Error When move uploaded file', 'wp-import-export-lite' );
- }
- }
-
- echo json_encode( $return_value );
-
- unset( $return_value, $is_success, $file_path );
-
- die();
- }
-
- public function update_process_status() {
-
- wpieSecurity::verify_request( 'wpie_settings' );
-
- global $wpdb;
-
- $return_value = array( "status" => "error" );
-
- $wpie_import_id = isset( $_GET[ 'wpie_process_id' ] ) ? absint( wpie_sanitize_field( $_GET[ 'wpie_process_id' ] ) ) : 0;
-
- if ( $wpie_import_id > 0 ) {
-
- $process_status = isset( $_GET[ 'process_status' ] ) ? wpie_sanitize_field( $_GET[ 'process_status' ] ) : "";
-
- $new_satus = "";
-
- if ( $process_status == "bg" ) {
-
- $new_satus = "background";
-
- $return_value[ 'message' ] = __( 'Background Process Successfully Set', 'wp-import-export-lite' );
- } elseif ( $process_status == "stop" ) {
-
- $new_satus = "stopped";
-
- $return_value[ 'message' ] = __( 'Process Stopped Successfully', 'wp-import-export-lite' );
- } elseif ( $process_status == "pause" ) {
-
- $new_satus = "paused";
-
- $return_value[ 'message' ] = __( 'Process Paused Successfully', 'wp-import-export-lite' );
- }
-
- unset( $process_status );
-
- if ( $new_satus != "" ) {
-
- $final_data = array(
- 'last_update_date' => current_time( 'mysql' ),
- 'status' => $new_satus,
- );
-
- $wpdb->update( $wpdb->prefix . "wpie_template", $final_data, array( 'id' => $wpie_import_id ) );
-
- unset( $final_data );
-
- $return_value[ 'status' ] = 'success';
- } else {
- $return_value[ 'message' ] = __( 'Empty Status', 'wp-import-export-lite' );
- }
-
- unset( $new_satus );
- } else {
- $return_value[ 'message' ] = __( 'Template id not found', 'wp-import-export-lite' );
- }
-
- unset( $wpie_import_id );
-
- echo json_encode( $return_value );
-
- die();
- }
-
- public function wpie_save_bg_cron_processing() {
-
- wpieSecurity::verify_request( 'wpie_settings' );
-
- $wpie_bg_and_cron_processing = get_option( "wpie_bg_and_cron_processing" );
-
- if ( $wpie_bg_and_cron_processing && !empty( $wpie_bg_and_cron_processing ) ) {
- $cron_data = maybe_unserialize( $wpie_bg_and_cron_processing );
-
- $cron_method = isset( $_GET[ 'method' ] ) && wpie_sanitize_field( $_GET[ 'method' ] ) === "external" ? "external" : "wp";
- } else {
- $cron_method = "wp";
-
- $cron_data = [ "token" => time() ];
- }
-
- $cron_data[ "method" ] = $cron_method;
-
- update_option( "wpie_bg_and_cron_processing", maybe_serialize( $cron_data ) );
-
- $return_value = array( "status" => 'success', "message" => __( 'Settings Successfully Saved', 'wp-import-export-lite' ) );
-
- echo json_encode( $return_value );
-
- die();
- }
-
- public function wpie_change_license_status() {
-
- wpieSecurity::verify_request( 'wpie_settings' );
-
- if ( file_exists( WPIE_CLASSES_DIR . '/class-wpie-license-manager.php' ) ) {
- require_once(WPIE_CLASSES_DIR . '/class-wpie-license-manager.php');
- }
-
- $license = new wpielicenseWPIE_License_Manager(
- WPIE_PLUGIN_API,
- WPIE_PLUGIN_FILE,
- array( 'version' => WPIE_PLUGIN_VERSION, 'license_db_key' => "wpie_license", 'author' => 'vjinfotech' )
- );
-
- $license->wpie_change_license_status();
- }
-
- public function __destruct() {
- foreach ( $this as $key => $value ) {
- unset( $this->$key );
- }
- }
-}
+<?php
+/**
+ * Common AJAX Actions Controller.
+ *
+ * Handles general AJAX endpoints: user capabilities, templates management,
+ * background cron settings, process status updates, and template import/export.
+ *
+ * @since 1.0.0
+ * @package wpie
+ * @subpackage wpieCore
+ * @author VJinfotech <support@vjinfotech.com>
+ */
+
+defined( 'ABSPATH' ) || exit;
+
+use WpieAppCoreHelpersParam;
+
+if ( file_exists( WPIE_CLASSES_DIR . '/class-wpie-security.php' ) ) {
+ require_once WPIE_CLASSES_DIR . '/class-wpie-security.php';
+}
+
+/**
+ * WPIE_Common_Actions Class
+ *
+ * Registers and executes common administrative AJAX actions.
+ *
+ * @since 1.0.0
+ */
+class WPIE_Common_Actions {
+
+ /**
+ * Class Constructor.
+ *
+ * Registers AJAX action hooks for admin users.
+ *
+ * @since 1.0.0
+ */
+ public function __construct() {
+ add_action( 'wp_ajax_wpie_save_user_cap', array( $this, 'wpie_save_user_cap' ) );
+ add_action( 'wp_ajax_wpie_get_user_cap', array( $this, 'wpie_get_user_cap' ) );
+ add_action( 'wp_ajax_wpie_delete_tempaltes', array( $this, 'wpie_delete_tempaltes' ) );
+ add_action( 'wp_ajax_wpie_tempalte_import', array( $this, 'wpie_tempalte_import' ) );
+ add_action( 'wp_ajax_wpie_get_tempaltes', array( $this, 'wpie_get_tempalte_list' ) );
+ add_action( 'wp_ajax_wpie_save_advance_option', array( $this, 'wpie_save_advance_option' ) );
+ add_action( 'wp_ajax_wpie_update_process_status', array( $this, 'update_process_status' ) );
+ add_action( 'wp_ajax_wpie_save_bg_cron_processing', array( $this, 'wpie_save_bg_cron_processing' ) );
+ add_action( 'wp_ajax_wpie_change_license_status', array( $this, 'wpie_change_license_status' ) );
+ }
+
+ /**
+ * AJAX Handler: Saves customized capabilities for a specific user role.
+ *
+ * @since 1.0.0
+ * @access public
+ *
+ * @return void
+ */
+ public function wpie_save_user_cap() {
+ wpieSecurity::verify_request( 'wpie_settings' );
+
+ $new_export = Param::postSanitized( 'wpie_cap_new_export', 'int', 0 );
+ $manage_export = Param::postSanitized( 'wpie_cap_manage_export', 'int', 0 );
+ $new_import = Param::postSanitized( 'wpie_cap_new_import', 'int', 0 );
+ $manage_import = Param::postSanitized( 'wpie_cap_manage_import', 'int', 0 );
+ $cap_settings = Param::postSanitized( 'wpie_cap_settings', 'int', 0 );
+ $cap_ext = Param::postSanitized( 'wpie_cap_ext', 'int', 0 );
+ $add_shortcode = Param::postSanitized( 'wpie_cap_add_shortcode', 'int', 0 );
+ $update_superior_users = Param::postSanitized( 'wpie_cap_update_superior_users', 'int', 0 );
+ $wpie_user_role = Param::postSanitized( 'wpie_user_role', 'text', '' );
+
+ $role = get_role( $wpie_user_role );
+
+ if ( $role ) {
+ if ( 1 === $new_export ) {
+ if ( ! $role->has_cap( 'wpie_new_export' ) ) {
+ $role->add_cap( 'wpie_new_export' );
+ }
+ } else {
+ $role->remove_cap( 'wpie_new_export' );
+ }
+
+ if ( 1 === $manage_export ) {
+ if ( ! $role->has_cap( 'wpie_manage_export' ) ) {
+ $role->add_cap( 'wpie_manage_export' );
+ }
+ } else {
+ $role->remove_cap( 'wpie_manage_export' );
+ }
+
+ if ( 1 === $new_import ) {
+ if ( ! $role->has_cap( 'wpie_new_import' ) ) {
+ $role->add_cap( 'wpie_new_import' );
+ }
+ } else {
+ $role->remove_cap( 'wpie_new_import' );
+ }
+
+ if ( 1 === $manage_import ) {
+ if ( ! $role->has_cap( 'wpie_manage_import' ) ) {
+ $role->add_cap( 'wpie_manage_import' );
+ }
+ } else {
+ $role->remove_cap( 'wpie_manage_import' );
+ }
+
+ if ( 1 === $cap_settings ) {
+ if ( ! $role->has_cap( 'wpie_settings' ) ) {
+ $role->add_cap( 'wpie_settings' );
+ }
+ } else {
+ $role->remove_cap( 'wpie_settings' );
+ }
+
+ if ( 1 === $cap_ext ) {
+ if ( ! $role->has_cap( 'wpie_extensions' ) ) {
+ $role->add_cap( 'wpie_extensions' );
+ }
+ } else {
+ $role->remove_cap( 'wpie_extensions' );
+ }
+
+ if ( 1 === $add_shortcode ) {
+ if ( ! $role->has_cap( 'wpie_add_shortcode' ) ) {
+ $role->add_cap( 'wpie_add_shortcode' );
+ }
+ } else {
+ $role->remove_cap( 'wpie_add_shortcode' );
+ }
+
+ if ( 1 === $update_superior_users ) {
+ if ( ! $role->has_cap( 'wpie_update_superior_users' ) ) {
+ $role->add_cap( 'wpie_update_superior_users' );
+ }
+ } else {
+ $role->remove_cap( 'wpie_update_superior_users' );
+ }
+ }
+
+ $return_value = array(
+ 'status' => 'success',
+ 'message' => __( 'Role Successfully Saved', 'wp-import-export-lite' ),
+ );
+
+ wp_send_json( $return_value );
+ }
+
+ /**
+ * AJAX Handler: Retrieves the active capabilities for a specific user role.
+ *
+ * @since 1.0.0
+ * @access public
+ *
+ * @return void
+ */
+ public function wpie_get_user_cap() {
+ wpieSecurity::verify_request( 'wpie_settings' );
+
+ $wpie_user_role = Param::requestSanitized( 'user_role', 'text', '' );
+ $role = get_role( $wpie_user_role );
+ $cap = array();
+
+ if ( $role ) {
+ if ( $role->has_cap( 'wpie_new_export' ) ) {
+ $cap[] = 'wpie_new_export';
+ }
+ if ( $role->has_cap( 'wpie_manage_export' ) ) {
+ $cap[] = 'wpie_manage_export';
+ }
+ if ( $role->has_cap( 'wpie_new_import' ) ) {
+ $cap[] = 'wpie_new_import';
+ }
+ if ( $role->has_cap( 'wpie_manage_import' ) ) {
+ $cap[] = 'wpie_manage_import';
+ }
+ if ( $role->has_cap( 'wpie_settings' ) ) {
+ $cap[] = 'wpie_settings';
+ }
+ if ( $role->has_cap( 'wpie_extensions' ) ) {
+ $cap[] = 'wpie_extensions';
+ }
+ if ( $role->has_cap( 'wpie_add_shortcode' ) ) {
+ $cap[] = 'wpie_add_shortcode';
+ }
+ if ( $role->has_cap( 'wpie_update_superior_users' ) ) {
+ $cap[] = 'wpie_update_superior_users';
+ }
+ }
+
+ $return_value = array(
+ 'status' => 'success',
+ 'cap' => $cap,
+ );
+
+ wp_send_json( $return_value );
+ }
+
+ /**
+ * AJAX Handler: Retrieves the template list as HTML option elements.
+ *
+ * @since 1.0.0
+ * @access public
+ *
+ * @return void
+ */
+ public function wpie_get_tempalte_list() {
+ wpieSecurity::verify_request( 'wpie_settings' );
+
+ $templates = $this->wpie_get_templates();
+ $template_html = '';
+
+ if ( ! empty( $templates ) && is_array( $templates ) ) {
+ foreach ( $templates as $data ) {
+ $id = isset( $data->id ) ? absint( $data->id ) : 0;
+ $options = isset( $data->options ) ? maybe_unserialize( $data->options ) : array();
+ $name = isset( $options['wpie_template_name'] ) ? $options['wpie_template_name'] : '';
+
+ if ( $id > 0 && '' !== trim( strval( $name ) ) ) {
+ $template_html .= '<option value="' . esc_attr( $id ) . '">' . esc_html( $name ) . '</option>';
+ }
+ }
+ }
+
+ $return_value = array(
+ 'status' => 'success',
+ 'html' => $template_html,
+ );
+
+ wp_send_json( $return_value );
+ }
+
+ /**
+ * Retrieve list of export jobs.
+ *
+ * @since 1.0.0
+ * @access public
+ *
+ * @param int $limit Maximum records to return. Default 25.
+ *
+ * @return array Array of template database rows.
+ */
+ public function get_export_list( $limit = 25 ) {
+ global $wpdb;
+
+ $limit = absint( $limit ) > 0 ? absint( $limit ) : 25;
+
+ return $wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT * FROM {$wpdb->prefix}wpie_template WHERE `opration` IN ('export','schedule_export') ORDER BY `id` DESC LIMIT 0, %d",
+ $limit
+ )
+ );
+ }
+
+ /**
+ * Retrieve list of import jobs.
+ *
+ * @since 1.0.0
+ * @access public
+ *
+ * @param int $limit Maximum records to return. Default 25.
+ *
+ * @return array Array of template database rows.
+ */
+ public function get_import_list( $limit = 25 ) {
+ global $wpdb;
+
+ $limit = absint( $limit ) > 0 ? absint( $limit ) : 25;
+
+ return $wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT * FROM {$wpdb->prefix}wpie_template WHERE `opration` IN ('import','schedule_import') ORDER BY `id` DESC LIMIT 0, %d",
+ $limit
+ )
+ );
+ }
+
+ /**
+ * Retrieve saved export and import templates.
+ *
+ * @since 1.0.0
+ * @access public
+ *
+ * @return array Array of saved template records.
+ */
+ public function wpie_get_templates() {
+ global $wpdb;
+
+ return $wpdb->get_results(
+ "SELECT * FROM {$wpdb->prefix}wpie_template WHERE `opration` IN ('import_template','export_template')"
+ );
+ }
+
+ /**
+ * AJAX Handler: Deletes specified templates and their associated storage directories.
+ *
+ * @since 1.0.0
+ * @access public
+ *
+ * @return void
+ */
+ public function wpie_delete_tempaltes() {
+ wpieSecurity::verify_request( 'wpie_settings' );
+
+ $ids = Param::requestSanitized( 'templates', 'text', '' );
+
+ if ( ! empty( $ids ) ) {
+ if ( is_string( $ids ) ) {
+ $ids = explode( ',', $ids );
+ }
+
+ if ( ! is_array( $ids ) ) {
+ $ids = array( $ids );
+ }
+
+ $ids = array_values( array_filter( array_map( 'absint', $ids ) ) );
+
+ if ( ! empty( $ids ) ) {
+ global $wpdb;
+
+ foreach ( $ids as $id ) {
+ if ( $id < 1 ) {
+ continue;
+ }
+
+ $template = $wpdb->get_row(
+ $wpdb->prepare(
+ "SELECT opration, options FROM {$wpdb->prefix}wpie_template WHERE `id` = %d LIMIT 0, 1",
+ $id
+ )
+ );
+
+ if ( ! $template ) {
+ continue;
+ }
+
+ $opration = isset( $template->opration ) ? $template->opration : 'import';
+ $options = isset( $template->options ) ? maybe_unserialize( $template->options ) : array();
+ if ( ! is_array( $options ) ) {
+ $options = array();
+ }
+
+ if ( in_array( $opration, array( 'import', 'schedule_import', 'schedule_import_template' ), true ) ) {
+ if ( 'schedule_import_template' === $opration ) {
+ wp_clear_scheduled_hook( 'wpie_cron_schedule_import', array( $id ) );
+ }
+
+ $import_file = isset( $options['importFile'] ) && is_array( $options['importFile'] ) ? $options['importFile'] : array();
+
+ foreach ( $import_file as $file_data ) {
+ $base_dir = isset( $file_data['baseDir'] ) && is_string( $file_data['baseDir'] ) ? sanitize_file_name( $file_data['baseDir'] ) : '';
+
+ if ( '' === trim( $base_dir ) || strpos( $base_dir, '..' ) !== false || strpos( $base_dir, "