PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / trunk
GiveWP – Donation Plugin and Fundraising Platform vtrunk
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / class-blank-slate.php
give / includes / admin Last commit date
add-ons 4 years ago donors 7 months ago emails 4 days ago forms 2 days ago payments 1 year ago reports 1 year ago settings 1 month ago shortcodes 1 year ago tools 4 months ago upgrades 5 months ago views 1 year ago abstract-admin-settings-page.php 2 years ago admin-actions.php 1 month ago admin-filters.php 9 months ago admin-footer.php 2 years ago admin-pages.php 5 months ago class-addon-activation-banner.php 9 months ago class-admin-settings.php 1 year ago class-api-keys-table.php 4 years ago class-blank-slate.php 1 year ago class-give-admin.php 5 years ago class-give-html-elements.php 1 year ago class-i18n-module.php 4 years ago dashboard-widgets.php 3 years ago give-metabox-functions.php 3 years ago import-functions.php 11 months ago misc-functions.php 2 years ago plugins.php 9 months ago setting-page-functions.php 6 years ago
class-blank-slate.php
320 lines
1 <?php
2 /**
3 * Give Blank Slate Class
4 *
5 * @package Give
6 * @subpackage Admin
7 * @copyright Copyright (c) 2017, GiveWP
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.8.13
10 */
11
12 use Give\DonationForms\V2\DonationFormsAdminPage;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 class Give_Blank_Slate {
19 /**
20 * The current screen ID.
21 *
22 * @since 1.8.13
23 * @var string
24 * @access public
25 */
26 public $screen = '';
27
28 /**
29 * Whether at least one donation form exists.
30 *
31 * @since 1.8.13
32 * @var bool
33 * @access private
34 */
35 private $form = false;
36
37 /**
38 * Whether at least one donation exists.
39 *
40 * @since 1.8.13
41 * @var bool
42 * @access private
43 */
44 private $donation = false;
45
46 /**
47 * Whether at least one donor exists.
48 *
49 * @since 1.8.13
50 * @var bool
51 * @access private
52 */
53 private $donor = false;
54
55 /**
56 * The content of the blank slate panel.
57 *
58 * @since 1.8.13
59 * @var array
60 * @access private
61 */
62 private $content = array();
63
64 /**
65 * Constructs the Give_Blank_Slate class.
66 *
67 * @since 1.8.13
68 */
69 public function __construct() {
70 $this->screen = get_current_screen()->id;
71 }
72
73 /**
74 * Initializes the class and hooks into WordPress.
75 *
76 * @since 1.8.13
77 */
78 public function init() {
79 // Bail early if screen cannot be detected.
80 if ( empty( $this->screen ) ) {
81 return null;
82 }
83
84 $content = array();
85
86 // Define content and hook into the appropriate action.
87 switch ( $this->screen ) {
88 // Forms screen.
89 case 'edit-give_forms':
90 $this->form = $this->post_exists( 'give_forms' );
91
92 if ( $this->form ) {
93 // Form exists. Bail out.
94 return false;
95 } else {
96 // No forms exist.
97 $content = $this->get_content( 'no_forms' );
98 }
99
100 add_action( 'manage_posts_extra_tablenav', array( $this, 'render' ) );
101 break;
102 // Donations screen.
103 case 'give_forms_page_give-payment-history':
104 $this->form = $this->post_exists( 'give_forms' );
105 $this->donation = $this->post_exists( 'give_payment' );
106
107 if ( $this->donation ) {
108 // Donation exists. Bail out.
109 return false;
110 } elseif ( ! $this->form ) {
111 // No forms and no donations exist.
112 $content = $this->get_content( 'no_donations_or_forms' );
113 } else {
114 // No donations exist but a form does exist.
115 $content = $this->get_content( 'no_donations' );
116 }
117
118 add_action( 'give_payments_page_bottom', array( $this, 'render' ) );
119 break;
120 // Donors screen.
121 case 'give_forms_page_give-donors':
122 $this->form = $this->post_exists( 'give_forms' );
123 $this->donor = $this->donor_exists();
124
125 if ( $this->donor ) {
126 // Donor exists. Bail out.
127 return false;
128 } elseif ( ! $this->form ) {
129 // No forms and no donors exist.
130 $content = $this->get_content( 'no_donors_or_forms' );
131 } else {
132 // No donors exist but a form does exist.
133 $content = $this->get_content( 'no_donors' );
134 }
135
136 add_action( 'give_donors_table_bottom', array( $this, 'render' ) );
137 break;
138 default:
139 return null;
140 }
141
142 $this->content = $content;
143
144 // Hide non-essential UI elements.
145 add_action( 'admin_head', array( $this, 'hide_ui' ) );
146 }
147
148 /**
149 * Renders the blank slate message.
150 *
151 * @since 1.8.13
152 *
153 * @param string $which The location of the list table hook: 'top' or 'bottom'.
154 */
155 public function render( $which = 'bottom' ) {
156 // Bail out to prevent content from rendering twice.
157 if ( 'top' === $which ) {
158 return null;
159 }
160
161 $screen = $this->screen;
162
163 /**
164 * Filters the content of the blank slate.
165 *
166 * @since 1.8.13
167 *
168 * @param array $content {
169 * Array of blank slate content.
170 *
171 * @type string $image_url URL of the blank slate image.
172 * @type string $image_alt Image alt text.
173 * @type string $heading Heading text.
174 * @type string $message Body copy.
175 * @type string $cta_text Call to action text.
176 * @type string $cta_link Call to action URL.
177 * @type string $help Help text.
178 * }
179 *
180 * @param string $screen The current screen ID.
181 */
182 $content = apply_filters( 'give_blank_slate_content', $this->content, $screen );
183
184 $template_path = GIVE_PLUGIN_DIR . 'includes/admin/views/blank-slate.php';
185
186 include $template_path;
187 }
188
189 /**
190 * Hides non-essential UI elements when blank slate content is on screen.
191 *
192 * @since 1.8.13
193 */
194 function hide_ui() {
195 ?>
196 <style type="text/css">
197 .give-filters,
198 .search-box,
199 .subsubsub,
200 .wp-list-table,
201 .tablenav.top,
202 .give_forms_page_give-payment-history .tablenav.bottom,
203 .give_forms_page_give-donors .tablenav.bottom,
204 .tablenav-pages {
205 display: none;
206 }
207 </style>
208 <?php
209 }
210
211 /**
212 * Determines if at least one post of a given post type exists.
213 *
214 * @since 1.8.13
215 *
216 * @param string $post_type Post type used in the query.
217 * @return bool True if post exists, otherwise false.
218 */
219 private function post_exists( $post_type ) {
220 // Attempt to get a single post of the post type.
221 $query = new WP_Query(
222 array(
223 'post_type' => $post_type,
224 'posts_per_page' => 1,
225 'no_found_rows' => false,
226 'update_post_meta_cache' => false,
227 'update_post_term_cache' => false,
228 'fields' => 'ids',
229 'post_status' => array( 'any', 'trash' ),
230 )
231 );
232
233 return $query->have_posts();
234 }
235
236 /**
237 * Determines if at least one donor exists.
238 *
239 * @since 1.8.13
240 *
241 * @return bool True if donor exists, otherwise false.
242 */
243 private function donor_exists() {
244 $donors = Give()->donors->get_donors( array( 'number' => 1 ) );
245
246 return ! empty( $donors );
247 }
248
249 /**
250 * Gets the content of a blank slate message based on provided context.
251 *
252 * @since 1.8.13
253 *
254 * @param string $context The key used to determine which content is returned.
255 * @return array Blank slate content.
256 */
257 private function get_content( $context ) {
258 // Define default content.
259 $defaults = array(
260 'image_url' => GIVE_PLUGIN_URL . 'build/assets/dist/images/give-icon-full-circle.svg',
261 'image_alt' => __( 'GiveWP Icon', 'give'),
262 'heading' => __('No campaign forms found.', 'give'),
263 'message' => __('The first step towards accepting online donations is to create a campaign.',
264 'give'),
265 'cta_text' => __('Create Campaign Form', 'give'),
266 'cta_link' => admin_url('edit.php?post_type=give_forms&page=give-campaigns&new=campaign'),
267 'help' => sprintf(
268 /* translators: 1: Opening anchor tag. 2: Closing anchor tag. */
269 __( 'Need help? Get started with %1$sGive 101%2$s.', 'give' ),
270 '<a href="http://docs.givewp.com/give101/" target="_blank">',
271 '</a>'
272 ),
273 );
274
275 // Define contextual content.
276 $content = array(
277 'no_donations_or_forms' => array(
278 'heading' => __( 'No donations found.', 'give' ),
279 'message' => __( 'Your donation history will appear here, but first, you need a donation form!', 'give' ),
280 ),
281 'no_donations' => array(
282 'heading' => __( 'No donations found.', 'give' ),
283 'message' => __( 'When your first donation arrives, a record of the donation will appear here.', 'give' ),
284 'cta_text' => __( 'View All Forms', 'give' ),
285 'cta_link' => DonationFormsAdminPage::getUrl(),
286 'help' => sprintf(
287 /* translators: 1: Opening anchor tag. 2: Closing anchor tag. */
288 __( 'Need help? Learn more about %1$sDonations%2$s.', 'give' ),
289 '<a href="http://docs.givewp.com/core-donations/">',
290 '</a>'
291 ),
292 ),
293 'no_donors_or_forms' => array(
294 'heading' => __( 'No donors found.', 'give' ),
295 'message' => __( 'Your donor history will appear here, but first, you need a donation form!', 'give' ),
296 ),
297 'no_donors' => array(
298 'heading' => __( 'No donors found.', 'give' ),
299 'message' => __( 'When your first donation arrives, the donor will appear here.', 'give' ),
300 'cta_text' => __( 'View All Forms', 'give' ),
301 'cta_link' => DonationFormsAdminPage::getUrl(),
302 'help' => sprintf(
303 /* translators: 1: Opening anchor tag. 2: Closing anchor tag. */
304 __( 'Need help? Learn more about %1$sDonors%2$s.', 'give' ),
305 '<a href="http://docs.givewp.com/core-donors/">',
306 '</a>'
307 ),
308 ),
309 );
310
311 if ( isset( $content[ $context ] ) ) {
312 // Merge contextual content with defaults.
313 return wp_parse_args( $content[ $context ], $defaults );
314 } else {
315 // Return defaults if context is undefined.
316 return $defaults;
317 }
318 }
319 }
320