ajax.php
3 years ago
plugin-data-sender.php
3 years ago
plugin-status.php
4 years ago
utils.php
3 years ago
ajax.php
49 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 | |
| 13 | $this->utils = Utils::instance(); |
| 14 | add_action( 'wp_ajax_wp_social_admin_action', [ $this, 'metform_admin_action' ] ); |
| 15 | } |
| 16 | |
| 17 | public function metform_admin_action() { |
| 18 | |
| 19 | // Check for nonce security |
| 20 | if ( ! wp_verify_nonce( $_POST['nonce'], 'ajax-nonce' ) ) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | if ( ! current_user_can( 'manage_options' ) ) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | if ( isset( $_POST['user_data'] ) ) { |
| 29 | $this->utils->save_option( 'user_data', empty( $_POST['user_data'] ) ? [] : map_deep( wp_unslash( $_POST['user_data'] ) , 'sanitize_text_field' ) ); |
| 30 | } |
| 31 | |
| 32 | if ( isset( $_POST['settings'] ) ) { |
| 33 | $this->utils->save_settings( empty( $_POST['settings'] ) ? [] : map_deep( wp_unslash( $_POST['settings'] ) , 'sanitize_text_field' ) ); |
| 34 | } |
| 35 | |
| 36 | do_action( 'wpsocial/admin/after_save' ); |
| 37 | |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | public function return_json( $data ) { |
| 42 | if ( is_array( $data ) || is_object( $data ) ) { |
| 43 | return json_encode( $data ); |
| 44 | } else { |
| 45 | return $data; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | } |