[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-settings/actions/ -> data.php (source)

   1  <?php
   2  /**
   3   * Settings: Data management action handler.
   4   *
   5   * @package BuddyPress
   6   * @subpackage SettingsActions
   7   * @since 4.0.0
   8   */
   9  
  10  /**
  11   * Data export request handler.
  12   *
  13   * @since 4.0.0
  14   */
  15  function bp_settings_action_data() {
  16      if ( ! bp_is_post_request() || ! bp_displayed_user_id() || empty( $_POST['bp-data-export-nonce'] ) ) {
  17          return;
  18      }
  19  
  20      // Nonce check.
  21      check_admin_referer( 'bp-data-export', 'bp-data-export-nonce' );
  22  
  23      // Delete existing request if available.
  24      if ( ! empty( $_POST['bp-data-export-delete-request-nonce'] ) && wp_verify_nonce( $_POST['bp-data-export-delete-request-nonce'], 'bp-data-export-delete-request' ) ) {
  25          $existing = bp_settings_get_personal_data_request();
  26          if ( ! empty( $existing->ID ) ) {
  27              wp_delete_post( $existing->ID, true );
  28          }
  29      }
  30  
  31      // Create the user request.
  32      $request_id = wp_create_user_request( buddypress()->displayed_user->userdata->user_email, 'export_personal_data' );
  33  
  34      $success = true;
  35      if ( is_wp_error( $request_id ) ) {
  36          $success = false;
  37          $message = $request_id->get_error_message();
  38      } elseif ( ! $request_id ) {
  39          $success = false;
  40          $message = __( 'We were unable to generate the data export request.', 'buddypress' );
  41      }
  42  
  43      /*
  44       * Auto-confirm the user request since the user already consented by
  45       * submitting our form.
  46       */
  47      if ( $success ) {
  48          /** This hook is documented in /wp-login.php */
  49          do_action( 'user_request_action_confirmed', $request_id );
  50  
  51          $message = __( 'Data export request successfully created', 'buddypress' );
  52      }
  53  
  54      /**
  55       * Fires after a user has created a data export request.
  56       *
  57       * This hook can be used to intervene in the data export request process.
  58       *
  59       * @since 4.0.0
  60       *
  61       * @param int  $request_id ID of the request.
  62       * @param bool $success    Whether the request was successfully created by WordPress.
  63       */
  64      do_action( 'bp_user_data_export_requested', $request_id, $success );
  65  
  66      bp_core_add_message( $message, $success ? 'success' : 'error' );
  67      bp_core_redirect( bp_get_requested_url() );
  68  }
  69  add_action( 'bp_actions', 'bp_settings_action_data' );


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1