PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.6.1
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.6.1
1.6.1 1.6.0 1.5.1 1.5.0 1.4.0 1.3.0 trunk 0.0.1 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0
← All changes | inc/admin/admin-bar.php +59 -0 1.3.0 → 1.6.1 View file →
@@ -8,15 +8,20 @@
8 8 * links to the payment settings so admins can switch modes in one click, and
9 9 * makes it obvious — while browsing the live site — that no real payments are
10 10 * being accepted. Modeled on the toolbar indicators in GiveWP and Charitable.
11 11 *
12 + * Also owns SureDonation's other toolbar adjustments, such as pointing the
13 + * "+ New" campaign entry at the campaign creation drawer.
14 + *
12 15 * @package SureDonation
13 16 */
14 17
15 18 namespace SureDonation\Inc\Admin;
16 19
20 +use SureDonation\Inc\Campaigns\Campaign_Cpt;
17 21 use SureDonation\Inc\Payments\Payment_Helper;
18 22 use WP_Admin_Bar;
23 +use WP_Post_Type;
19 24
20 25 // Exit if accessed directly.
21 26 if ( ! defined( 'ABSPATH' ) ) {
22 27 exit;
@@ -52,8 +57,11 @@
52 57 */
53 58 private function __construct() {
54 59 // Priority 100 so the badge is added after the core toolbar items.
55 60 add_action( 'admin_bar_menu', [ $this, 'add_mode_indicator' ], 100 );
61 + // Core builds the "+ New" menu at priority 70, so run after it to
62 + // repoint the campaign entry.
63 + add_action( 'admin_bar_menu', [ $this, 'retarget_new_campaign_link' ], 100 );
56 64 // The toolbar shows on the front-end too, so register the styles on both
57 65 // contexts.
58 66 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_style' ] );
59 67 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_style' ] );
@@ -111,8 +119,59 @@
111 119 'parent' => 'top-secondary',
112 120 'title' => $title,
113 121 'href' => Payment_Helper::get_settings_url(),
114 122 'meta' => [ 'title' => $tooltip ],
123 + ]
124 + );
125 + }
126 +
127 + /**
128 + * Point the "+ New → SureDonation Campaign" item at the creation drawer.
129 + *
130 + * Core links the item to post-new.php, which opens an empty block editor and
131 + * skips the drawer where a campaign's goal, currency and default form are
132 + * set. Re-adding the node under the same id keeps core's placement and
133 + * label while swapping the destination.
134 + *
135 + * The item is dropped entirely for anyone who cannot manage options. Core
136 + * shows it to any role with `edit_posts` (Editor, Author, Contributor), but
137 + * every step of campaign creation — the admin app, the REST routes and the
138 + * campaign meta — requires `manage_options`, so for those roles the entry
139 + * only leads to a permission error.
140 + *
141 + * @param WP_Admin_Bar $wp_admin_bar The admin bar instance.
142 + * @return void
143 + * @since 1.5.0
144 + */
145 + public function retarget_new_campaign_link( $wp_admin_bar ) {
146 + $post_type = get_post_type_object( Campaign_Cpt::POST_TYPE );
147 +
148 + if ( ! $post_type instanceof WP_Post_Type ) {
149 + return;
150 + }
151 +
152 + $node_id = 'new-' . Campaign_Cpt::POST_TYPE;
153 +
154 + if ( ! current_user_can( 'manage_options' ) ) {
155 + $wp_admin_bar->remove_node( $node_id );
156 + return;
157 + }
158 +
159 + /*
160 + * add_node() creates the node when the id is absent, so mirror core's
161 + * own capability check too — otherwise this would resurrect the entry
162 + * for users core deliberately hid it from.
163 + */
164 + if ( ! current_user_can( $post_type->cap->create_posts ) ) {
165 + return;
166 + }
167 +
168 + $wp_admin_bar->add_node(
169 + [
170 + 'id' => $node_id,
171 + 'parent' => 'new-content',
172 + 'title' => $post_type->labels->name_admin_bar,
173 + 'href' => Campaign_Cpt::get_create_url(),
115 174 ]
116 175 );
117 176 }
118 177