PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / trunk
Wp Social Login and Register Social Counter vtrunk
trunk 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.10 1.3.11 1.3.2 1.3.3 1.3.4 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.4 1.4.5 1.4.6 1.4.8 1.4.9 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.5 1.8.6 1.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.8 2.2.9 3.0.0 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0
wp-social / lib / onboard / classes / ajax.php
wp-social / lib / onboard / classes Last commit date
ajax.php 7 months ago plugin-data-sender.php 9 months ago plugin-installer.php 7 months ago plugin-skin.php 7 months ago plugin-status.php 4 years ago utils.php 3 years ago
ajax.php
118 lines
1 <?php
2
3 namespace WP_Social\Lib\Onboard\Classes;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class Ajax {
8
9 private $utils;
10
11 public function __construct() {
12 add_action( 'wp_ajax_wp_social_admin_action', [ $this, 'wp_social_admin_action' ] );
13 add_action( 'wp_ajax_wp_social_onboard_plugins', array( $this, 'wp_social_onboard_plugins' ) );
14 $this->utils = Utils::instance();
15 }
16
17 public function wp_social_admin_action() {
18 // Check for nonce security
19 if (!isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field(wp_unslash($_POST['nonce'])), 'ajax-nonce' ) ) {
20 return;
21 }
22
23 if ( ! current_user_can( 'manage_options' ) ) {
24 return;
25 }
26
27 if ( isset( $_POST['user_data'] ) ) {
28 $this->utils->save_option( 'user_data', empty( $_POST['user_data'] ) ? [] : sanitize_text_field(wp_unslash($_POST['user_data'])));
29 }
30
31 if ( isset( $_POST['settings'] ) ) {
32 //phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- Sanitized using map_deep
33 $this->utils->save_settings( map_deep($_POST['settings'],function($data){
34 return sanitize_text_field(wp_unslash($data));
35 }));
36 }
37
38
39 do_action( 'wpsocial/admin/after_save' );
40
41 $response = array(
42 'message' => self::plugin_activate_message( 'setup_configurations' )
43 );
44
45 $plugins = !empty($_POST['our_plugins']) && is_array($_POST['our_plugins']) ? $_POST['our_plugins'] : [];
46 if($plugins) {
47 $total_plugins = count($plugins);
48 $total_steps = 1 + $total_plugins;
49 $percentage = ($total_steps > 0) ? (1 / $total_steps) * 100 : 100;
50 $percentage = round($percentage);
51
52 $response['progress'] = $percentage;
53 $response['plugins'] = $plugins;
54 }
55
56 wp_send_json($response);
57
58 wp_die(); // this is required to terminate immediately and return a proper response
59 }
60
61 public function wp_social_onboard_plugins() {
62 // Check for nonce security
63 if (!isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field(wp_unslash($_POST['nonce'])), 'ajax-nonce' ) ) {
64 return;
65 }
66
67 if ( ! current_user_can( 'manage_options' ) ) {
68 return;
69 }
70
71 $plugin_slug = isset( $_POST['plugin_slug'] ) ? sanitize_text_field(wp_unslash($_POST['plugin_slug'])) : '';
72 if ( isset( $plugin_slug ) && current_user_can('install_plugins') ) {
73 $status = \WP_Social\Lib\Onboard\Classes\Plugin_Installer::single_install_and_activate( $plugin_slug );
74 if ( is_wp_error( $status ) ) {
75 wp_send_json_error( array( 'status' => false ) );
76 } else {
77 wp_send_json_success(
78 array(
79 'message' => self::plugin_activate_message( $plugin_slug )
80 )
81 );
82 }
83 }
84 }
85
86
87 public static function plugin_activate_message($plugin_slug) {
88 $plugins_message = [
89 'setup_configurations' => esc_html__('Setup Configurations', 'wp-social'),
90 'elementskit-lite/elementskit-lite.php' => esc_html__('Page Builder Elements Activated', 'wp-social'),
91 'getgenie/getgenie.php' => esc_html__('AI Content & SEO Tool Activated', 'wp-social'),
92 'shopengine/shopengine.php' => esc_html__('WooCommerce Builder Activated', 'wp-social'),
93 'metform/metform.php' => esc_html__('Form Builder Activated', 'wp-social'),
94 'emailkit/EmailKit.php' => esc_html__('Email Customizer Activated', 'wp-social'),
95 'wp-social/wp-social.php' => esc_html__('Social Integration Activated', 'wp-social'),
96 'wp-ultimate-review/wp-ultimate-review.php' => esc_html__('Review Management Activated', 'wp-social'),
97 'wp-fundraising-donation/wp-fundraising.php' => esc_html__('Fundraising & Donations', 'wp-social'),
98 'gutenkit-blocks-addon/gutenkit-blocks-addon.php' => esc_html__('Page Builder Blocks Activated', 'wp-social'),
99 'popup-builder-block/popup-builder-block.php' => esc_html__('Popup Builder Activated', 'wp-social'),
100 'table-builder-block/table-builder-block.php' => esc_html__('Table Builder Activated', 'wp-social'),
101 ];
102
103 if ( array_key_exists( $plugin_slug, $plugins_message ) ) {
104 return esc_html( $plugins_message[$plugin_slug] );
105 } else {
106 return esc_html__( 'Plugin Activated', 'wp-social' );
107 }
108 }
109
110 public function return_json( $data ) {
111 if ( is_array( $data ) || is_object( $data ) ) {
112 return json_encode( $data );
113 } else {
114 return $data;
115 }
116 }
117
118 }