PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.6.0
GiveWP – Donation Plugin and Fundraising Platform v2.6.0
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 6 years ago donors 6 years ago emails 6 years ago forms 6 years ago payments 6 years ago reports 6 years ago settings 6 years ago shortcodes 6 years ago tools 6 years ago upgrades 6 years ago views 6 years ago abstract-admin-settings-page.php 6 years ago admin-actions.php 6 years ago admin-filters.php 7 years ago admin-footer.php 6 years ago admin-pages.php 6 years ago class-addon-activation-banner.php 6 years ago class-admin-settings.php 6 years ago class-api-keys-table.php 7 years ago class-blank-slate.php 6 years ago class-give-admin.php 6 years ago class-give-html-elements.php 7 years ago class-give-welcome.php 6 years ago class-i18n-module.php 6 years ago dashboard-widgets.php 6 years ago give-metabox-functions.php 6 years ago import-functions.php 7 years ago misc-functions.php 6 years ago plugins.php 6 years ago setting-page-functions.php 6 years ago welcome.php 6 years ago
class-blank-slate.php
315 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 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 class Give_Blank_Slate {
17 /**
18 * The current screen ID.
19 *
20 * @since 1.8.13
21 * @var string
22 * @access public
23 */
24 public $screen = '';
25
26 /**
27 * Whether at least one donation form exists.
28 *
29 * @since 1.8.13
30 * @var bool
31 * @access private
32 */
33 private $form = false;
34
35 /**
36 * Whether at least one donation exists.
37 *
38 * @since 1.8.13
39 * @var bool
40 * @access private
41 */
42 private $donation = false;
43
44 /**
45 * Whether at least one donor exists.
46 *
47 * @since 1.8.13
48 * @var bool
49 * @access private
50 */
51 private $donor = false;
52
53 /**
54 * The content of the blank slate panel.
55 *
56 * @since 1.8.13
57 * @var array
58 * @access private
59 */
60 private $content = array();
61
62 /**
63 * Constructs the Give_Blank_Slate class.
64 *
65 * @since 1.8.13
66 */
67 public function __construct() {
68 $this->screen = get_current_screen()->id;
69 }
70
71 /**
72 * Initializes the class and hooks into WordPress.
73 *
74 * @since 1.8.13
75 */
76 public function init() {
77 // Bail early if screen cannot be detected.
78 if ( empty( $this->screen ) ) {
79 return null;
80 }
81
82 $content = array();
83
84 // Define content and hook into the appropriate action.
85 switch ( $this->screen ) {
86 // Forms screen.
87 case 'edit-give_forms':
88 $this->form = $this->post_exists( 'give_forms' );
89
90 if ( $this->form ) {
91 // Form exists. Bail out.
92 return false;
93 } else {
94 // No forms exist.
95 $content = $this->get_content( 'no_forms' );
96 }
97
98 add_action( 'manage_posts_extra_tablenav', array( $this, 'render' ) );
99 break;
100 // Donations screen.
101 case 'give_forms_page_give-payment-history':
102 $this->form = $this->post_exists( 'give_forms' );
103 $this->donation = $this->post_exists( 'give_payment' );
104
105 if ( $this->donation ) {
106 // Donation exists. Bail out.
107 return false;
108 } elseif ( ! $this->form ) {
109 // No forms and no donations exist.
110 $content = $this->get_content( 'no_donations_or_forms' );
111 } else {
112 // No donations exist but a form does exist.
113 $content = $this->get_content( 'no_donations' );
114 }
115
116 add_action( 'give_payments_page_bottom', array( $this, 'render' ) );
117 break;
118 // Donors screen.
119 case 'give_forms_page_give-donors':
120 $this->form = $this->post_exists( 'give_forms' );
121 $this->donor = $this->donor_exists();
122
123 if ( $this->donor ) {
124 // Donor exists. Bail out.
125 return false;
126 } elseif ( ! $this->form ) {
127 // No forms and no donors exist.
128 $content = $this->get_content( 'no_donors_or_forms' );
129 } else {
130 // No donors exist but a form does exist.
131 $content = $this->get_content( 'no_donors' );
132 }
133
134 add_action( 'give_donors_table_bottom', array( $this, 'render' ) );
135 break;
136 default:
137 return null;
138 }
139
140 $this->content = $content;
141
142 // Hide non-essential UI elements.
143 add_action( 'admin_head', array( $this, 'hide_ui' ) );
144 }
145
146 /**
147 * Renders the blank slate message.
148 *
149 * @since 1.8.13
150 *
151 * @param string $which The location of the list table hook: 'top' or 'bottom'.
152 */
153 public function render( $which = 'bottom' ) {
154 // Bail out to prevent content from rendering twice.
155 if ( 'top' === $which ) {
156 return null;
157 }
158
159 $screen = $this->screen;
160
161 /**
162 * Filters the content of the blank slate.
163 *
164 * @since 1.8.13
165 *
166 * @param array $content {
167 * Array of blank slate content.
168 *
169 * @type string $image_url URL of the blank slate image.
170 * @type string $image_alt Image alt text.
171 * @type string $heading Heading text.
172 * @type string $message Body copy.
173 * @type string $cta_text Call to action text.
174 * @type string $cta_link Call to action URL.
175 * @type string $help Help text.
176 * }
177 *
178 * @param string $screen The current screen ID.
179 */
180 $content = apply_filters( 'give_blank_slate_content', $this->content, $screen );
181
182 $template_path = GIVE_PLUGIN_DIR . 'includes/admin/views/blank-slate.php';
183
184 include $template_path;
185 }
186
187 /**
188 * Hides non-essential UI elements when blank slate content is on screen.
189 *
190 * @since 1.8.13
191 */
192 function hide_ui() {
193 ?>
194 <style type="text/css">
195 .give-filters,
196 .search-box,
197 .subsubsub,
198 .wp-list-table,
199 .tablenav.top,
200 .give_forms_page_give-payment-history .tablenav.bottom,
201 .give_forms_page_give-donors .tablenav.bottom,
202 .tablenav-pages {
203 display: none;
204 }
205 </style>
206 <?php
207 }
208
209 /**
210 * Determines if at least one post of a given post type exists.
211 *
212 * @since 1.8.13
213 *
214 * @param string $post_type Post type used in the query.
215 * @return bool True if post exists, otherwise false.
216 */
217 private function post_exists( $post_type ) {
218 // Attempt to get a single post of the post type.
219 $query = new WP_Query( array(
220 'post_type' => $post_type,
221 'posts_per_page' => 1,
222 'no_found_rows' => false,
223 'update_post_meta_cache' => false,
224 'update_post_term_cache' => false,
225 'fields' => 'ids',
226 'post_status' => array( 'any', 'trash' ),
227 ) );
228
229 return $query->have_posts();
230 }
231
232 /**
233 * Determines if at least one donor exists.
234 *
235 * @since 1.8.13
236 *
237 * @return bool True if donor exists, otherwise false.
238 */
239 private function donor_exists() {
240 $donors = Give()->donors->get_donors( array( 'number' => 1 ) );
241
242 return ! empty( $donors );
243 }
244
245 /**
246 * Gets the content of a blank slate message based on provided context.
247 *
248 * @since 1.8.13
249 *
250 * @param string $context The key used to determine which content is returned.
251 * @return array Blank slate content.
252 */
253 private function get_content( $context ) {
254 // Define default content.
255 $defaults = array(
256 'image_url' => GIVE_PLUGIN_URL . 'assets/dist/images/give-icon-full-circle.svg',
257 'image_alt' => __( 'GiveWP Icon', 'give' ),
258 'heading' => __( 'No donation forms found.', 'give' ),
259 'message' => __( 'The first step towards accepting online donations is to create a form.', 'give' ),
260 'cta_text' => __( 'Create Donation Form', 'give' ),
261 'cta_link' => admin_url( 'post-new.php?post_type=give_forms' ),
262 'help' => sprintf(
263 /* translators: 1: Opening anchor tag. 2: Closing anchor tag. */
264 __( 'Need help? Get started with %1$sGive 101%2$s.', 'give' ),
265 '<a href="http://docs.givewp.com/give101/" target="_blank">',
266 '</a>'
267 ),
268 );
269
270 // Define contextual content.
271 $content = array(
272 'no_donations_or_forms' => array(
273 'heading' => __( 'No donations found.', 'give' ),
274 'message' => __( 'Your donation history will appear here, but first, you need a donation form!', 'give' ),
275 ),
276 'no_donations' => array(
277 'heading' => __( 'No donations found.', 'give' ),
278 'message' => __( 'When your first donation arrives, a record of the donation will appear here.', 'give' ),
279 'cta_text' => __( 'View All Forms', 'give' ),
280 'cta_link' => admin_url( 'edit.php?post_type=give_forms' ),
281 'help' => sprintf(
282 /* translators: 1: Opening anchor tag. 2: Closing anchor tag. */
283 __( 'Need help? Learn more about %1$sDonations%2$s.', 'give' ),
284 '<a href="http://docs.givewp.com/core-donations/">',
285 '</a>'
286 ),
287 ),
288 'no_donors_or_forms' => array(
289 'heading' => __( 'No donors found.', 'give' ),
290 'message' => __( 'Your donor history will appear here, but first, you need a donation form!', 'give' ),
291 ),
292 'no_donors' => array(
293 'heading' => __( 'No donors found.', 'give' ),
294 'message' => __( 'When your first donation arrives, the donor will appear here.', 'give' ),
295 'cta_text' => __( 'View All Forms', 'give' ),
296 'cta_link' => admin_url( 'edit.php?post_type=give_forms' ),
297 'help' => sprintf(
298 /* translators: 1: Opening anchor tag. 2: Closing anchor tag. */
299 __( 'Need help? Learn more about %1$sDonors%2$s.', 'give' ),
300 '<a href="http://docs.givewp.com/core-donors/">',
301 '</a>'
302 ),
303 ),
304 );
305
306 if ( isset( $content[ $context ] ) ) {
307 // Merge contextual content with defaults.
308 return wp_parse_args( $content[ $context ], $defaults );
309 } else {
310 // Return defaults if context is undefined.
311 return $defaults;
312 }
313 }
314 }
315