Skip to content

Commit

Permalink
[#819] Fix Admin Grant Free Bids from Network Admin (#821)
Browse files Browse the repository at this point in the history
* [#819] Fix Network Admin Grant Free Bids

* [#819] Allow AJAX call inside Network Admin

* [#819] Remove debug logging
  • Loading branch information
bd-viget authored Mar 21, 2024
1 parent 83667a4 commit 6faf804
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions client-mu-plugins/goodbids/src/assets/js/admin-free-bids.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const $ = jQuery;

$(() => {
const grantFreeBidButton = $('#goodbids-grant-free-bid-button');
if (!grantFreeBidButton.length) {
return;
}

grantFreeBidButton.attr('disabled', true); // disable by default
const freeBidReason = $('#' + goodbidsFreeBids.reasonFieldId);
freeBidReason.on('keyup', function () {
Expand Down
13 changes: 7 additions & 6 deletions client-mu-plugins/goodbids/src/classes/Users/FreeBids.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ class FreeBids {
* @since 1.0.0
*/
public function __construct() {

// Handle Free Bid via AJAX.
$this->grant_free_bid_ajax();

// Disable Free Bids on Main Site.
if ( is_main_site() ) {
if ( is_main_site() && ! is_network_admin() ) {
return;
}

// Add UI for Super Admins to grant free bids to users.
$this->free_bid_user_fields();

// Handle Free Bid via AJAX.
$this->grant_free_bid_ajax();

// Set up JS Vars.
$this->free_bid_js_vars();
}
Expand Down Expand Up @@ -130,7 +131,7 @@ function ( $handle ) {
'title' => __( 'Success!', 'goodbids' ),
'text' => __( 'The free bid was successfully granted.', 'goodbids' ),
],
'grantAction' => 'goodbids_admin_grant_free_bid',
'grantAction' => 'goodbids_' . self::NONCE_ACTION,
'nonceGrant' => wp_create_nonce( self::NONCE_ACTION ),
]
);
Expand All @@ -147,7 +148,7 @@ function ( $handle ) {
*/
private function grant_free_bid_ajax(): void {
add_action(
'wp_ajax_goodbids_admin_grant_free_bid',
'wp_ajax_goodbids_' . self::NONCE_ACTION,
function () {
list( $user_id, $reason ) = $this->ajax_request_validation();

Expand Down

0 comments on commit 6faf804

Please sign in to comment.