add-ons
6 years ago
donors
6 years ago
emails
6 years ago
forms
5 years ago
payments
6 years ago
reports
6 years ago
settings
5 years ago
shortcodes
6 years ago
tools
6 years ago
upgrades
5 years ago
views
6 years ago
abstract-admin-settings-page.php
6 years ago
admin-actions.php
6 years ago
admin-filters.php
6 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
5 years ago
class-api-keys-table.php
6 years ago
class-blank-slate.php
6 years ago
class-give-admin.php
6 years ago
class-give-html-elements.php
6 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
5 years ago
import-functions.php
6 years ago
misc-functions.php
6 years ago
plugins.php
6 years ago
setting-page-functions.php
6 years ago
class-blank-slate.php
317 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( |
| 220 | array( |
| 221 | 'post_type' => $post_type, |
| 222 | 'posts_per_page' => 1, |
| 223 | 'no_found_rows' => false, |
| 224 | 'update_post_meta_cache' => false, |
| 225 | 'update_post_term_cache' => false, |
| 226 | 'fields' => 'ids', |
| 227 | 'post_status' => array( 'any', 'trash' ), |
| 228 | ) |
| 229 | ); |
| 230 | |
| 231 | return $query->have_posts(); |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Determines if at least one donor exists. |
| 236 | * |
| 237 | * @since 1.8.13 |
| 238 | * |
| 239 | * @return bool True if donor exists, otherwise false. |
| 240 | */ |
| 241 | private function donor_exists() { |
| 242 | $donors = Give()->donors->get_donors( array( 'number' => 1 ) ); |
| 243 | |
| 244 | return ! empty( $donors ); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Gets the content of a blank slate message based on provided context. |
| 249 | * |
| 250 | * @since 1.8.13 |
| 251 | * |
| 252 | * @param string $context The key used to determine which content is returned. |
| 253 | * @return array Blank slate content. |
| 254 | */ |
| 255 | private function get_content( $context ) { |
| 256 | // Define default content. |
| 257 | $defaults = array( |
| 258 | 'image_url' => GIVE_PLUGIN_URL . 'assets/dist/images/give-icon-full-circle.svg', |
| 259 | 'image_alt' => __( 'GiveWP Icon', 'give' ), |
| 260 | 'heading' => __( 'No donation forms found.', 'give' ), |
| 261 | 'message' => __( 'The first step towards accepting online donations is to create a form.', 'give' ), |
| 262 | 'cta_text' => __( 'Create Donation Form', 'give' ), |
| 263 | 'cta_link' => admin_url( 'post-new.php?post_type=give_forms' ), |
| 264 | 'help' => sprintf( |
| 265 | /* translators: 1: Opening anchor tag. 2: Closing anchor tag. */ |
| 266 | __( 'Need help? Get started with %1$sGive 101%2$s.', 'give' ), |
| 267 | '<a href="http://docs.givewp.com/give101/" target="_blank">', |
| 268 | '</a>' |
| 269 | ), |
| 270 | ); |
| 271 | |
| 272 | // Define contextual content. |
| 273 | $content = array( |
| 274 | 'no_donations_or_forms' => array( |
| 275 | 'heading' => __( 'No donations found.', 'give' ), |
| 276 | 'message' => __( 'Your donation history will appear here, but first, you need a donation form!', 'give' ), |
| 277 | ), |
| 278 | 'no_donations' => array( |
| 279 | 'heading' => __( 'No donations found.', 'give' ), |
| 280 | 'message' => __( 'When your first donation arrives, a record of the donation will appear here.', 'give' ), |
| 281 | 'cta_text' => __( 'View All Forms', 'give' ), |
| 282 | 'cta_link' => admin_url( 'edit.php?post_type=give_forms' ), |
| 283 | 'help' => sprintf( |
| 284 | /* translators: 1: Opening anchor tag. 2: Closing anchor tag. */ |
| 285 | __( 'Need help? Learn more about %1$sDonations%2$s.', 'give' ), |
| 286 | '<a href="http://docs.givewp.com/core-donations/">', |
| 287 | '</a>' |
| 288 | ), |
| 289 | ), |
| 290 | 'no_donors_or_forms' => array( |
| 291 | 'heading' => __( 'No donors found.', 'give' ), |
| 292 | 'message' => __( 'Your donor history will appear here, but first, you need a donation form!', 'give' ), |
| 293 | ), |
| 294 | 'no_donors' => array( |
| 295 | 'heading' => __( 'No donors found.', 'give' ), |
| 296 | 'message' => __( 'When your first donation arrives, the donor will appear here.', 'give' ), |
| 297 | 'cta_text' => __( 'View All Forms', 'give' ), |
| 298 | 'cta_link' => admin_url( 'edit.php?post_type=give_forms' ), |
| 299 | 'help' => sprintf( |
| 300 | /* translators: 1: Opening anchor tag. 2: Closing anchor tag. */ |
| 301 | __( 'Need help? Learn more about %1$sDonors%2$s.', 'give' ), |
| 302 | '<a href="http://docs.givewp.com/core-donors/">', |
| 303 | '</a>' |
| 304 | ), |
| 305 | ), |
| 306 | ); |
| 307 | |
| 308 | if ( isset( $content[ $context ] ) ) { |
| 309 | // Merge contextual content with defaults. |
| 310 | return wp_parse_args( $content[ $context ], $defaults ); |
| 311 | } else { |
| 312 | // Return defaults if context is undefined. |
| 313 | return $defaults; |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 |