ajax.php
3 weeks ago
install-notice.php
3 weeks ago
install-tracker.php
3 weeks ago
onboard-status.php
3 weeks ago
plugin-data-sender.php
1 year ago
plugin-installer.php
3 weeks ago
plugin-skin.php
1 year ago
plugin-status.php
4 years ago
utils.php
1 year ago
ajax.php
152 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ElementsKit_Lite\Libs\Framework\Classes; |
| 4 | |
| 5 | use ElementsKit_Lite\Config\Module_List; |
| 6 | use ElementsKit_Lite\Config\Widget_List; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | class Ajax { |
| 11 | private $utils; |
| 12 | |
| 13 | public function __construct() { |
| 14 | add_action( 'wp_ajax_ekit_admin_action', array( $this, 'elementskit_admin_action' ) ); |
| 15 | add_action( 'wp_ajax_ekit_onboard_plugins', array( $this, 'elementskit_onboard_plugins' ) ); |
| 16 | $this->utils = Utils::instance(); |
| 17 | } |
| 18 | |
| 19 | public function elementskit_admin_action() { |
| 20 | // Check for nonce security |
| 21 | if (!isset($_POST['nonce']) || ! wp_verify_nonce( sanitize_key(wp_unslash($_POST['nonce'])), 'ajax-nonce' ) ) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | if ( ! current_user_can( 'manage_options' ) ) { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | if ( isset( $_POST['widget_list'] ) ) { |
| 30 | $widget_list = Widget_List::instance()->get_list(); |
| 31 | $widget_list_input = ! is_array( $_POST['widget_list'] ) ? array() : map_deep( wp_unslash( $_POST['widget_list'] ) , 'sanitize_text_field' ); |
| 32 | $widget_prepared_list = array(); |
| 33 | |
| 34 | foreach ( $widget_list as $widget_slug => $widget ) { |
| 35 | if ( isset( $widget['package'] ) && $widget['package'] == 'pro-disabled' ) { |
| 36 | continue; |
| 37 | } |
| 38 | |
| 39 | $widget['status'] = ( in_array( $widget_slug, $widget_list_input ) ? 'active' : 'inactive' ); |
| 40 | |
| 41 | $widget_prepared_list[ $widget_slug ] = $widget; |
| 42 | } |
| 43 | |
| 44 | // Allow to filter widget status |
| 45 | apply_filters( 'elementskit/widgets/status/update', $widget_prepared_list ); |
| 46 | |
| 47 | $this->utils->save_option( 'widget_list', $widget_prepared_list ); |
| 48 | } |
| 49 | |
| 50 | if ( isset( $_POST['module_list'] ) ) { |
| 51 | $module_list = Module_List::instance()->get_list( 'optional' ); |
| 52 | $module_list_input = ! is_array( $_POST['module_list'] ) ? array() : map_deep( wp_unslash( $_POST['module_list'] ) , 'sanitize_text_field' ); |
| 53 | $module_prepared_list = array(); |
| 54 | |
| 55 | foreach ( $module_list as $module_slug => $module ) { |
| 56 | if ( isset( $module['package'] ) && $module['package'] == 'pro-disabled' ) { |
| 57 | continue; |
| 58 | } |
| 59 | |
| 60 | $module['status'] = ( in_array( $module_slug, $module_list_input ) ? 'active' : 'inactive' ); |
| 61 | |
| 62 | $module_prepared_list[ $module_slug ] = $module; |
| 63 | } |
| 64 | |
| 65 | $this->utils->save_option( 'module_list', $module_prepared_list ); |
| 66 | } |
| 67 | |
| 68 | if ( isset( $_POST['user_data'] ) ) { |
| 69 | $this->utils->save_option( 'user_data', empty( $_POST['user_data'] ) ? array() : map_deep( wp_unslash( $_POST['user_data'] ) , 'wp_filter_nohtml_kses' ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- It will sanitize by wp_filter_nohtml_kses function |
| 70 | } |
| 71 | |
| 72 | if ( isset( $_POST['settings'] ) ) { |
| 73 | $this->utils->save_settings( empty( $_POST['settings'] ) ? array() : map_deep( wp_unslash( $_POST['settings'] ) , 'sanitize_text_field' ) ); |
| 74 | } |
| 75 | |
| 76 | do_action( 'elementskit/admin/after_save' ); |
| 77 | |
| 78 | $response = array( |
| 79 | 'message' => self::plugin_activate_message( 'setup_configurations' ) |
| 80 | ); |
| 81 | |
| 82 | $plugins = !empty($_POST['our_plugins']) && is_array($_POST['our_plugins']) ? $_POST['our_plugins'] : []; |
| 83 | if($plugins) { |
| 84 | $total_plugins = count($plugins); |
| 85 | $total_steps = 1 + $total_plugins; |
| 86 | $percentage = ($total_steps > 0) ? (1 / $total_steps) * 100 : 100; |
| 87 | $percentage = round($percentage); |
| 88 | |
| 89 | $response['progress'] = $percentage; |
| 90 | $response['plugins'] = $plugins; |
| 91 | } |
| 92 | |
| 93 | wp_send_json($response); |
| 94 | |
| 95 | wp_die(); // this is required to terminate immediately and return a proper response |
| 96 | } |
| 97 | |
| 98 | public function elementskit_onboard_plugins() { |
| 99 | // Check for nonce security |
| 100 | if (!isset($_POST['nonce']) || ! wp_verify_nonce( sanitize_key(wp_unslash($_POST['nonce'])), 'ajax-nonce' ) ) { |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | $plugin_slug = isset( $_POST['plugin_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_slug'] ) ) : ''; |
| 105 | if ( isset( $plugin_slug ) && current_user_can('install_plugins') ) { |
| 106 | $status = \ElementsKit_Lite\Libs\Framework\Classes\Plugin_Installer::single_install_and_activate( $plugin_slug ); |
| 107 | if ( is_wp_error( $status ) ) { |
| 108 | wp_send_json_error( array( 'status' => false ) ); |
| 109 | } else { |
| 110 | wp_send_json_success( |
| 111 | array( |
| 112 | 'message' => self::plugin_activate_message( $plugin_slug ) |
| 113 | ) |
| 114 | ); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | public static function plugin_activate_message($plugin_slug) { |
| 120 | $plugins_message = [ |
| 121 | 'setup_configurations' => esc_html__('Setup Configurations', 'elementskit-lite'), |
| 122 | 'elementskit-lite/elementskit-lite.php' => esc_html__('Page Builder Elements Activated', 'elementskit-lite'), |
| 123 | 'getgenie/getgenie.php' => esc_html__('AI Content & SEO Tool Activated', 'elementskit-lite'), |
| 124 | 'shopengine/shopengine.php' => esc_html__('WooCommerce Builder Activated', 'elementskit-lite'), |
| 125 | 'metform/metform.php' => esc_html__('Form Builder Activated', 'elementskit-lite'), |
| 126 | 'emailkit/EmailKit.php' => esc_html__('Email Customizer Activated', 'elementskit-lite'), |
| 127 | // 'wp-social/wp-social.php' => esc_html__('Social Integration Activated', 'elementskit-lite'), |
| 128 | // 'wp-ultimate-review/wp-ultimate-review.php' => esc_html__('Review Management Activated', 'elementskit-lite'), |
| 129 | // 'wp-fundraising-donation/wp-fundraising.php' => esc_html__('Fundraising & Donations', 'elementskit-lite'), |
| 130 | 'gutenkit-blocks-addon/gutenkit-blocks-addon.php' => esc_html__('Page Builder Blocks Activated', 'elementskit-lite'), |
| 131 | 'popup-builder-block/popup-builder-block.php' => esc_html__('Popup Builder Activated', 'elementskit-lite'), |
| 132 | // 'table-builder-block/table-builder-block.php' => esc_html__('Table Builder Activated', 'elementskit-lite'), |
| 133 | // 'rox-dynamic-cpt-fields-engine/rox-dynamic-cpt-fields-engine.php' => esc_html__('Dynamic CPT Fields Activated', 'elementskit-lite'), |
| 134 | // 'rox-appointment-booking/rox-appointment-booking.php' => esc_html__('Appointment Booking Activated', 'elementskit-lite'), |
| 135 | ]; |
| 136 | |
| 137 | if ( array_key_exists( $plugin_slug, $plugins_message ) ) { |
| 138 | return esc_html( $plugins_message[$plugin_slug] ); |
| 139 | } else { |
| 140 | return esc_html__( 'Plugin Activated', 'elementskit-lite' ); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | public function return_json( $data ) { |
| 145 | if ( is_array( $data ) || is_object( $data ) ) { |
| 146 | return wp_json_encode( $data ); |
| 147 | } else { |
| 148 | return $data; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 |