Skip to content

Commit

Permalink
All The Fixes (#787)
Browse files Browse the repository at this point in the history
* [#684] WIP Support Request Form

* [#684] Added form dependencies and populate data

* [#684] Wiring up HTMX

* [#684] HTMX Fix

* [#684] Now just need it to submit

* [#684] Styling the support form

* [#684] adjusting loading icon

* [#684] updating textarea

* [#684] Form Submission finally done.

* [#684] Submit Request from Bid Order page

* [#684] Support Request from Reward Order page

* [#684] Request Class (lost this code somehow)

* [#684] Admin Views

* [#684] Request Details

* [#684] WP Screen updates, unbolded "read" messages

* [#684] Support Request Email and Success Message

* [#684] Remove unused stuff

* [#684] Send Support Email to Super Admins

* [#684] Fixed removal of WC Settings tabs for nonprofits

* [#684] Create Support Page

* [#684] Actually trigger creation of support page

* [#684] Minor Adjustments

* [#684] Remove use of wp_die()

* [#684] Prevent Changes to Support Page

* [#684] Format bid amount

* [#684] Dynamic page URL

* [#684] Unnecessary comment

* [#781] Fix Free Bids Issue

* [#781] Fix filter count

* [#779] Auction End Bug fixes

* [#779] Update invalid check for Nonprofit

* [N/A] Fix Merge Bug

* [#779] puts the submit button on top

* [#784] Rename Support Requests Menu to "Support"

* [#784] PR Feedback

* [N/A] Adjust Bid Extension Formatted Text

* [N/A] Removes unused class reference

* [N/A] Init WC Emails class when it's not already loaded

* [N/A] Remove Debugging Plugins

* [#787] Move array_filter to ALL the returned pages.

* [#684] PR Feedback

* [#781] PR Feedback

* [NA] Updated to use existing constant

* [#779] PR Feedback

* [N/A] I18n Some Text

* [N/A] Fix bug with Reward arg vs Bid arg

---------

Co-authored-by: Nathan Schmidt <[email protected]>
  • Loading branch information
bd-viget and nathan-schmidt-viget authored Mar 18, 2024
1 parent bf40029 commit 2436956
Show file tree
Hide file tree
Showing 69 changed files with 4,027 additions and 1,094 deletions.
2 changes: 1 addition & 1 deletion client-mu-plugins/goodbids/blocks/bid-now/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function show_free_bid_button(): bool {
}

// Make sure the user has free bids.
if ( ! goodbids()->users->get_available_free_bid_count() ) {
if ( ! goodbids()->free_bids->get_available_count() ) {
return false;
}

Expand Down
15 changes: 15 additions & 0 deletions client-mu-plugins/goodbids/blocks/support-request-form/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "support-request-form",
"title": "Support Request Form",
"description": "Displays a support request form.",
"icon": "sos",
"category": "goodbids",
"textdomain": "goodbids",
"keywords": ["form", "support", "report", "help", "problem", "issue" ],
"acf": {
"mode": "preview"
},
"supports": {
"jsx": true
}
}
130 changes: 130 additions & 0 deletions client-mu-plugins/goodbids/blocks/support-request-form/block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
/**
* Support Request Form Block
*
* @since 1.0.0
* @package GoodBids
*/

namespace GoodBids\Blocks;

use GoodBids\Frontend\Notices;
use GoodBids\Frontend\SupportRequest;
use GoodBids\Network\Nonprofit;
use GoodBids\Plugins\ACF\ACFBlock;

/**
* Class for Support Request Form Block
*
* @since 1.0.0
*/
class SupportRequestForm extends ACFBlock {

/**
* Render the form
*
* @since 1.0.0
*
* @return void
*/
public function render(): void {
$form_data = [];

if ( goodbids()->support->submission_processed() ) {
goodbids()->notices->display_notice( Notices::REQUEST_SUBMITTED );
} else {
$form_data = goodbids()->support->get_form_data();
}

$button_class = 'btn-fill-secondary text-md';

if ( is_admin() ) {
$button_class .= ' pointer-events-none';
}
?>
<form method="post" action="" class="px-8 pt-4 pb-12 rounded-sm bg-contrast relative group opacity-100 group-[.htmx-request]:opacity-50 transition-opacity" data-form-spinner>
<?php if ( ! is_admin() ) : ?>
<div class="absolute inset-x-0 flex justify-center w-full -translate-y-full -bottom-2.5 text-base-2">
<svg xmlns="http://www.w3.org/2000/svg" class="relative inset-0 htmx-indicator w-14 h-14 animate-spin" viewBox="0 0 24 24" fill="currentColor"><path d="M12 3C16.9706 3 21 7.02944 21 12H19C19 8.13401 15.866 5 12 5V3Z"></path></svg>
</div>
<?php endif; ?>

<?php
if ( ! is_admin() ) :
wp_nonce_field( SupportRequest::FORM_NONCE_ACTION, SupportRequest::FORM_NONCE_ACTION . '_nonce' );
endif;
?>

<?php $this->inner_blocks(); ?>

<div id="gb-support-form-target" class="relative z-10">
<?php
$this->render_error();

foreach ( goodbids()->support->get_fields() as $key => $field ) :
goodbids()->forms->render_field( $key, $field, '', $form_data );
endforeach;
?>
<button
type="submit"
class="<?php echo esc_attr( $button_class ); ?>"
>
<?php esc_attr_e( 'Submit Request', 'goodbids' ); ?>
</button>
</div>
</form>
<?php
}

/**
* Render the error message if exists.
*
* @since 1.0.0
*
* @return void
*/
private function render_error(): void {
if ( ! goodbids()->support->get_error() ) {
return;
}
?>
<div class="p-4 mb-4 rounded bg-error-bg">
<p class="text-error-text">
<?php echo esc_html( goodbids()->support->get_error() ); ?>
</p>
</div>
<?php
}

/**
* Render the Inner Blocks tag
*
* @since 1.0.0
*
* @return void
*/
public function inner_blocks(): void {
$nonprofit = new Nonprofit( get_current_blog_id() );
$template = [
[
'core/heading',
[
'textColor' => 'base-2',
'content' => __( 'Request Support from', 'goodbids' ) . ' ' . $nonprofit->get_name(),
],
],
[
'core/paragraph',
[
'content' => __( 'Use the form below to submit a support request to this Nonprofit. Your submission will be visible to administrators for this Nonprofit site as well as the GOODBIDS support team. We will respond as soon as we can.', 'goodbids' ),
'textColor' => 'base-2',
],
],
];

printf(
'<InnerBlocks template="%s" />',
esc_attr( wp_json_encode( $template ) )
);
}
}
17 changes: 17 additions & 0 deletions client-mu-plugins/goodbids/blocks/support-request-form/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Block: Support Request Form
*
* @var array $block
*
* @since 1.0.0
* @package GoodBids
*/

use GoodBids\Blocks\SupportRequestForm;

$support_form = new SupportRequestForm( $block );
?>
<section <?php block_attr( $block, 'max-w-xl m-auto' ); ?>>
<?php $support_form->render(); ?>
</section>
2 changes: 0 additions & 2 deletions client-mu-plugins/goodbids/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@
"vlucas/phpdotenv": "^5.5",
"wpackagist-plugin/accessibility-checker": "^1.9.3",
"wpackagist-plugin/svg-support": "^2.5",
"wpackagist-plugin/user-role-editor": "^4.64",
"wpackagist-plugin/user-switching": "^1.7",
"wpackagist-plugin/woocommerce": "^8.6",
"wpackagist-plugin/woocommerce-gateway-stripe": "^8.0",
"wpackagist-plugin/woocommerce-services": "^2.5",
"wpackagist-plugin/wp-mail-log": "^1.1",
"wpackagist-plugin/zapier": "^1.0",
"wpengine/advanced-custom-fields-pro": "^6.2"
},
Expand Down
38 changes: 1 addition & 37 deletions client-mu-plugins/goodbids/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 66 additions & 1 deletion client-mu-plugins/goodbids/src/classes/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace GoodBids\Admin;

use GoodBids\Network\Sites;
use GoodBids\Users\Permissions;

/**
Expand All @@ -31,6 +32,9 @@ public function __construct() {

// Remove Nav Items for Jr Admins
$this->jr_admin_nav_cleanup();

// Limit access to pages
$this->limit_access_to_pages();
}

/**
Expand Down Expand Up @@ -81,7 +85,7 @@ public function add_menu_separator( mixed $position ): void {
* @return void
*/
public function render_field( string $key, array $field, string $prefix = '', array $data = [], bool $wrap = true ) : void {
$required = ! empty( $field['required'] ) && true === $field['required'];
$required = ! empty( $field['required'] );
$placeholder = $field['placeholder'] ?? '';
$field_id = $prefix ? $prefix . '-' . $key : $key;
$value = $data[ $key ] ?? '';
Expand Down Expand Up @@ -211,4 +215,65 @@ function ( array $features ): array {
}
);
}

/**
* Limit access to specific pages for non-Super Admins.
*
* @since 1.0.0
*
* @return void
*/
private function limit_access_to_pages(): void {
add_action(
'admin_init',
function () {
$pages = array_filter(
apply_filters(
'goodbids_restrict_pages',
[
intval( get_option( Sites::SUPPORT_OPTION ) ),
]
)
);

// Block access to Specific Pages
add_filter(
'user_has_cap',
function ( array $all_caps, array $caps, array $args ) use ( $pages ) {
if ( is_super_admin() ) {
return $all_caps;
}

$post_id = get_the_ID();

if ( ! $post_id && isset( $args[2] ) ) {
$post_id = $args[2];
}

if ( ! $post_id || 'page' !== get_post_type( $post_id ) ) {
return $all_caps;
}

if ( ! in_array( $post_id, $pages, true ) ) {
return $all_caps;
}

$all_caps['publish_pages'] = false;
$all_caps['edit_pages'] = false;
$all_caps['edit_others_pages'] = false;
$all_caps['edit_published_pages'] = false;
$all_caps['edit_private_pages'] = false;
$all_caps['delete_pages'] = false;
$all_caps['delete_private_pages'] = false;
$all_caps['delete_others_pages'] = false;
$all_caps['delete_published_pages'] = false;

return $all_caps;
},
10,
3
);
}
);
}
}
9 changes: 4 additions & 5 deletions client-mu-plugins/goodbids/src/classes/Auctions/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use WC_Product_Variation;
use WP_Post;
use WP_Screen;

/**
* Auction Admin Class
Expand Down Expand Up @@ -57,9 +58,7 @@ public function __construct() {
private function add_info_meta_box(): void {
add_action(
'current_screen',
function (): void {
$screen = get_current_screen();

function ( WP_Screen $screen ): void {
if ( goodbids()->auctions->get_post_type() !== $screen->id ) {
return;
}
Expand Down Expand Up @@ -236,8 +235,8 @@ function () {
private function live_auction_restrictions(): void {
add_action(
'current_screen',
function () {
if ( ! $this->is_restricted() ) {
function ( WP_Screen $screen ): void {
if ( $screen->id !== goodbids()->auctions->get_post_type() || ! $this->is_restricted() ) {
return;
}
?>
Expand Down
Loading

0 comments on commit 2436956

Please sign in to comment.