| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class that sets up editer blocks for Charitable. |
| 4 |
* |
| 5 |
* @package Charitable/Classes/Charitable_Admin |
| 6 |
* @author David Bisset |
| 7 |
* @copyright Copyright (c) 2023, WP Charitable LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.8.0 |
| 10 |
* @version 1.8.3 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
if ( ! class_exists( 'Charitable_Admin_Blocks' ) ) : |
| 19 |
|
| 20 |
/** |
| 21 |
* Charitable_Admin_Blocks |
| 22 |
* |
| 23 |
* @final |
| 24 |
* @since 1.8.0 |
| 25 |
*/ |
| 26 |
final class Charitable_Admin_Blocks { |
| 27 |
|
| 28 |
/** |
| 29 |
* The single instance of this class. |
| 30 |
* |
| 31 |
* @var Charitable_Admin|null |
| 32 |
*/ |
| 33 |
private static $instance = null; |
| 34 |
|
| 35 |
/** |
| 36 |
* Set up the class. |
| 37 |
* |
| 38 |
* @since 1.8.0 |
| 39 |
*/ |
| 40 |
public function __construct() { |
| 41 |
|
| 42 |
if ( $this->allow_load() ) { |
| 43 |
|
| 44 |
add_action( 'init', array( $this, 'register_blocks' ) ); |
| 45 |
|
| 46 |
do_action( 'charitable_admin_blocks_loaded' ); |
| 47 |
|
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Indicate if current integration is allowed to load. |
| 53 |
* |
| 54 |
* @since 1.8.0 |
| 55 |
* |
| 56 |
* @return bool |
| 57 |
*/ |
| 58 |
public function allow_load() { |
| 59 |
|
| 60 |
return function_exists( 'register_block_type' ); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Registers the block using the metadata loaded from the `block.json` file. |
| 65 |
* Behind the scenes, it registers also all assets so they can be enqueued |
| 66 |
* through the block editor in the corresponding context. |
| 67 |
* |
| 68 |
* @see https://developer.wordpress.org/reference/functions/register_block_type/ |
| 69 |
* |
| 70 |
* @since 1.8.0 |
| 71 |
* @version 1.8.3 - Added additional blocks. |
| 72 |
*/ |
| 73 |
public function register_blocks() { |
| 74 |
if ( ! $this->is_block_registered( 'create-block/campaignblock' ) ) { |
| 75 |
register_block_type( |
| 76 |
charitable()->get_path( 'directory', true ) . 'assets/js/blocks/campaign/build/block.json', |
| 77 |
array( |
| 78 |
'render_callback' => array( $this, 'charitable_block_render_campaign_widget' ), |
| 79 |
) |
| 80 |
); |
| 81 |
} |
| 82 |
if ( ! $this->is_block_registered( 'charitable/campaigns-block' ) ) { |
| 83 |
register_block_type( |
| 84 |
charitable()->get_path( 'directory', true ) . 'assets/js/blocks/campaigns/build/block.json', |
| 85 |
array( |
| 86 |
'render_callback' => array( $this, 'charitable_block_render_campaigns_widget' ), |
| 87 |
) |
| 88 |
); |
| 89 |
} |
| 90 |
if ( ! $this->is_block_registered( 'charitable/donations-block' ) ) { |
| 91 |
register_block_type( |
| 92 |
charitable()->get_path( 'directory', true ) . 'assets/js/blocks/donations/build/block.json', |
| 93 |
array( |
| 94 |
'render_callback' => array( $this, 'charitable_block_render_donations_widget' ), |
| 95 |
) |
| 96 |
); |
| 97 |
} |
| 98 |
if ( ! $this->is_block_registered( 'charitable/donors-block' ) ) { |
| 99 |
register_block_type( |
| 100 |
charitable()->get_path( 'directory', true ) . 'assets/js/blocks/donors/build/block.json', |
| 101 |
array( |
| 102 |
'render_callback' => array( $this, 'charitable_block_render_donors_widget' ), |
| 103 |
) |
| 104 |
); |
| 105 |
} |
| 106 |
if ( ! $this->is_block_registered( 'charitable/donation-button' ) ) { |
| 107 |
register_block_type( |
| 108 |
charitable()->get_path( 'directory', true ) . 'assets/js/blocks/donation-button/build/block.json', |
| 109 |
array( |
| 110 |
'render_callback' => array( $this, 'charitable_block_render_donation_button_widget' ), |
| 111 |
) |
| 112 |
); |
| 113 |
} |
| 114 |
if ( ! $this->is_block_registered( 'charitable/campaign-progress-bar' ) ) { |
| 115 |
register_block_type( |
| 116 |
charitable()->get_path( 'directory', true ) . 'assets/js/blocks/campaign-progress-bar/build/block.json', |
| 117 |
array( |
| 118 |
'render_callback' => array( $this, 'charitable_block_render_campaign_progress_bar_widget' ), |
| 119 |
) |
| 120 |
); |
| 121 |
} |
| 122 |
if ( ! $this->is_block_registered( 'charitable/campaign-stats' ) ) { |
| 123 |
register_block_type( |
| 124 |
charitable()->get_path( 'directory', true ) . 'assets/js/blocks/campaign-stats/build/block.json', |
| 125 |
array( |
| 126 |
'render_callback' => array( $this, 'charitable_block_render_campaign_stats_widget' ), |
| 127 |
) |
| 128 |
); |
| 129 |
} |
| 130 |
if ( ! $this->is_block_registered( 'charitable/my-donations' ) ) { |
| 131 |
register_block_type( |
| 132 |
charitable()->get_path( 'directory', true ) . 'assets/js/blocks/my-donations/build/block.json', |
| 133 |
array( |
| 134 |
'render_callback' => array( $this, 'charitable_block_render_my_donations_widget' ), |
| 135 |
) |
| 136 |
); |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Checks if a block is registered. |
| 142 |
* |
| 143 |
* @since 1.8.0 |
| 144 |
* |
| 145 |
* @param string $block_name The block name. |
| 146 |
* @return bool |
| 147 |
*/ |
| 148 |
private function is_block_registered( $block_name ) { |
| 149 |
|
| 150 |
if ( class_exists( 'WP_Block_Type_Registry' ) ) { |
| 151 |
return WP_Block_Type_Registry::get_instance()->is_registered( $block_name ); |
| 152 |
} |
| 153 |
|
| 154 |
return false; |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Renders the campaign widget block. |
| 159 |
* |
| 160 |
* @since 1.8.0 |
| 161 |
* |
| 162 |
* @param array $attributes The attributes for the block. |
| 163 |
*/ |
| 164 |
public function charitable_block_render_campaign_widget( $attributes ) { |
| 165 |
$campaign_id = $attributes['campaignID']; |
| 166 |
|
| 167 |
ob_start(); |
| 168 |
|
| 169 |
echo do_shortcode( '[campaign id="' . intval( $campaign_id ) . '"]' ); |
| 170 |
|
| 171 |
return ob_get_clean(); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Renders the campaigns widget block. |
| 176 |
* |
| 177 |
* @since 1.8.3 |
| 178 |
* |
| 179 |
* @param array $attributes The attributes for the block. |
| 180 |
*/ |
| 181 |
public function charitable_block_render_campaigns_widget( $attributes ) { |
| 182 |
|
| 183 |
$number = ! empty( $attributes['numberCampaigns'] ) ? $attributes['numberCampaigns'] : 10; |
| 184 |
$columns = ! empty( $attributes['columns'] ) ? $attributes['columns'] : 2; |
| 185 |
$order = ! empty( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
| 186 |
$orderby = ! empty( $attributes['orderby'] ) ? $attributes['orderby'] : 'post_date'; |
| 187 |
$creator = ! empty( $attributes['creatorId'] ) ? $attributes['creatorId'] : ''; |
| 188 |
$exclude = ! empty( $attributes['excludeCampaignIds'] ) ? $attributes['excludeCampaignIds'] : ''; |
| 189 |
$show = ! empty( $attributes['showChampaignIds'] ) ? $attributes['showChampaignIds'] : ''; |
| 190 |
$responsive = ! empty( $attributes['responsiveLayout'] ) ? 1 : ''; |
| 191 |
$masonry = ! empty( $attributes['masonryLayout'] ) ? 1 : ''; |
| 192 |
$description_limit = ! empty( $attributes['descriptionLimit'] ) ? $attributes['descriptionLimit'] : ''; |
| 193 |
$show_donate_button = ! empty( $attributes['showDonateButton'] ) ? $attributes['showDonateButton'] : ''; |
| 194 |
$include_inactive = ! empty( $attributes['includeInactive'] ) ? 1 : ''; |
| 195 |
|
| 196 |
// create a shortcode with the attributes, but only include the attributes that are not empty with ''. |
| 197 |
$shortcode_attribute_string = ''; |
| 198 |
$shortcode_attribute_string .= ! empty( $number ) ? ' number="' . intval( $number ) . '"' : ''; |
| 199 |
$shortcode_attribute_string .= ! empty( $columns ) ? ' columns="' . intval( $columns ) . '"' : ''; |
| 200 |
$shortcode_attribute_string .= ! empty( $order ) ? ' order="' . esc_attr( $order ) . '"' : ''; |
| 201 |
$shortcode_attribute_string .= ! empty( $orderby ) ? ' orderby="' . esc_attr( $orderby ) . '"' : ''; |
| 202 |
$shortcode_attribute_string .= ! empty( $creator ) ? ' creator="' . esc_html( $creator ) . '"' : ''; |
| 203 |
$shortcode_attribute_string .= ! empty( $exclude ) ? ' exclude="' . esc_html( $exclude ) . '"' : ''; |
| 204 |
$shortcode_attribute_string .= ! empty( $show ) ? ' id="' . esc_html( $show ) . '"' : ''; |
| 205 |
$shortcode_attribute_string .= ! empty( $responsive ) ? ' responsive="' . intval( $responsive ) . '"' : ''; |
| 206 |
$shortcode_attribute_string .= ! empty( $masonry ) ? ' masonry="' . intval( $masonry ) . '"' : ''; |
| 207 |
$shortcode_attribute_string .= ! empty( $description_limit ) ? ' description_limit="' . intval( $description_limit ) . '"' : ''; |
| 208 |
$shortcode_attribute_string .= ! empty( $show_donate_button ) ? ' button="' . esc_attr( $show_donate_button ) . '"' : ''; |
| 209 |
$shortcode_attribute_string .= ! empty( $include_inactive ) ? ' include_inactive="' . esc_attr( $include_inactive ) . '"' : ''; |
| 210 |
|
| 211 |
ob_start(); |
| 212 |
|
| 213 |
echo do_shortcode( '[campaigns ' . $shortcode_attribute_string . ']' ); |
| 214 |
|
| 215 |
return ob_get_clean(); |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* Renders the donations widget block. |
| 220 |
* |
| 221 |
* @since 1.8.3 |
| 222 |
* |
| 223 |
* @param array $attributes The attributes for the block. |
| 224 |
*/ |
| 225 |
public function charitable_block_render_donations_widget( $attributes ) { |
| 226 |
|
| 227 |
$args = array(); |
| 228 |
$args['title'] = ! empty( $attributes['title'] ) ? $attributes['title'] : ''; |
| 229 |
$args['campaign_id'] = ! empty( $attributes['campaignID'] ) ? $attributes['campaignID'] : false; |
| 230 |
|
| 231 |
ob_start(); |
| 232 |
|
| 233 |
charitable_template( 'widgets/donate.php', array_merge( $args ) ); |
| 234 |
|
| 235 |
return ob_get_clean(); |
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* Renders the donations widget block. |
| 240 |
* |
| 241 |
* @since 1.8.3 |
| 242 |
* |
| 243 |
* @param array $attributes The attributes for the block. |
| 244 |
*/ |
| 245 |
public function charitable_block_render_donors_widget( $attributes ) { |
| 246 |
|
| 247 |
$args = array(); |
| 248 |
$args['number'] = ! empty( $attributes['donorsNumber'] ) ? $attributes['donorsNumber'] : 10; |
| 249 |
$args['orderby'] = ! empty( $attributes['orderby'] ) ? $attributes['orderby'] : 'date'; |
| 250 |
$args['order'] = ! empty( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
| 251 |
$args['campaign'] = ! empty( $attributes['campaignID'] ) ? $attributes['campaignID'] : ''; |
| 252 |
$args['distinct'] = ! empty( $attributes['distinctDonors'] ) ? $attributes['distinctDonors'] : ''; |
| 253 |
$args['orientation'] = ! empty( $attributes['orientation'] ) ? $attributes['orientation'] : 'horizontal'; |
| 254 |
$args['show_name'] = ! empty( $attributes['showName'] ) ? $attributes['showName'] : '0'; |
| 255 |
$args['show_location'] = ! empty( $attributes['showLocation'] ) ? $attributes['showLocation'] : '0'; |
| 256 |
$args['show_amount'] = ! empty( $attributes['showAmount'] ) ? $attributes['showAmount'] : '0'; |
| 257 |
$args['show_avatar'] = ! empty( $attributes['showAvatar'] ) ? $attributes['showAvatar'] : '0'; |
| 258 |
$args['hide_if_no_donors'] = ! empty( $attributes['hideIfNoDonors'] ) ? $attributes['hideIfNoDonors'] : ''; |
| 259 |
|
| 260 |
// create a shortcode with the attributes, but only include the attributes that are not empty with ''. |
| 261 |
$shortcode_attribute_string = ''; |
| 262 |
$shortcode_attribute_string .= ! empty( $args['number'] ) ? ' number="' . intval( $args['number'] ) . '"' : ''; |
| 263 |
$shortcode_attribute_string .= ! empty( $args['orderby'] ) ? ' orderby="' . esc_attr( $args['orderby'] ) . '"' : ''; |
| 264 |
$shortcode_attribute_string .= ! empty( $args['order'] ) ? ' order="' . esc_attr( $args['order'] ) . '"' : ''; |
| 265 |
$shortcode_attribute_string .= ! empty( $args['campaign'] ) ? ' campaign="' . esc_html( $args['campaign'] ) . '"' : ''; |
| 266 |
$shortcode_attribute_string .= ! empty( $args['distinct'] ) ? ' distinct="' . esc_html( $args['distinct'] ) . '"' : ''; |
| 267 |
$shortcode_attribute_string .= ! empty( $args['orientation'] ) ? ' orientation="' . esc_attr( $args['orientation'] ) . '"' : ''; |
| 268 |
$shortcode_attribute_string .= ! empty( $args['show_name'] || '0' === $args['show_name'] ) ? ' show_name="' . esc_attr( $args['show_name'] ) . '"' : ''; |
| 269 |
$shortcode_attribute_string .= ! empty( $args['show_location'] || '0' === $args['show_location'] ) ? ' show_location="' . esc_attr( $args['show_location'] ) . '"' : ''; |
| 270 |
$shortcode_attribute_string .= ! empty( $args['show_amount'] || '0' === $args['show_amount'] ) ? ' show_amount="' . esc_attr( $args['show_amount'] ) . '"' : ''; |
| 271 |
$shortcode_attribute_string .= ! empty( $args['show_avatar'] || '0' === $args['show_avatar'] ) ? ' show_avatar="' . esc_attr( $args['show_avatar'] ) . '"' : ''; |
| 272 |
$shortcode_attribute_string .= ! empty( $args['hide_if_no_donors'] ) ? ' hide_if_no_donors="' . esc_attr( $args['hide_if_no_donors'] ) . '"' : ''; |
| 273 |
|
| 274 |
ob_start(); |
| 275 |
|
| 276 |
echo do_shortcode( '[charitable_donors ' . $shortcode_attribute_string . ']' ); |
| 277 |
|
| 278 |
return ob_get_clean(); |
| 279 |
} |
| 280 |
|
| 281 |
/** |
| 282 |
* Renders the donations widget block. |
| 283 |
* |
| 284 |
* @since 1.8.3 |
| 285 |
* |
| 286 |
* @param array $attributes The attributes for the block. |
| 287 |
*/ |
| 288 |
public function charitable_block_render_campaign_progress_bar_widget( $attributes ) { |
| 289 |
|
| 290 |
$args = array(); |
| 291 |
$args['campaign_id'] = ! empty( $attributes['campaignID'] ) ? $attributes['campaignID'] : ''; |
| 292 |
|
| 293 |
if ( empty( $args['campaign_id'] ) || ! function_exists( 'charitable_template_campaign_progress_bar' ) ) { |
| 294 |
return; |
| 295 |
} |
| 296 |
|
| 297 |
ob_start(); |
| 298 |
|
| 299 |
echo charitable_template_campaign_progress_bar( charitable_get_campaign( (int) $args['campaign_id'] ) ); // phpcs:ignore |
| 300 |
|
| 301 |
return ob_get_clean(); |
| 302 |
} |
| 303 |
|
| 304 |
/** |
| 305 |
* Renders the donations widget block. |
| 306 |
* |
| 307 |
* @since 1.8.3 |
| 308 |
* |
| 309 |
* @param array $attributes The attributes for the block. |
| 310 |
*/ |
| 311 |
public function charitable_block_render_campaign_stats_widget( $attributes ) { |
| 312 |
|
| 313 |
$args = array(); |
| 314 |
$args['campaign_ids'] = ! empty( $attributes['campaignIDs'] ) ? $attributes['campaignIDs'] : ''; |
| 315 |
$args['display'] = ! empty( $attributes['display'] ) ? $attributes['display'] : 'total'; |
| 316 |
$args['goal'] = ! empty( $attributes['goal'] ) ? $attributes['goal'] : ''; |
| 317 |
|
| 318 |
// create a shortcode with the attributes, but only include the attributes that are not empty with ''. |
| 319 |
$shortcode_attribute_string = ''; |
| 320 |
$shortcode_attribute_string .= ! empty( $args['campaign_ids'] ) ? ' campaigns="' . esc_html( $args['campaign_ids'] ) . '"' : ''; |
| 321 |
$shortcode_attribute_string .= ! empty( $args['display'] ) ? ' display="' . esc_html( $args['display'] ) . '"' : ''; |
| 322 |
$shortcode_attribute_string .= ! empty( $args['goal'] ) ? ' goal="' . esc_attr( $args['goal'] ) . '"' : ''; |
| 323 |
|
| 324 |
ob_start(); |
| 325 |
|
| 326 |
echo do_shortcode( '[charitable_stat ' . $shortcode_attribute_string . ']' ); |
| 327 |
|
| 328 |
return ob_get_clean(); |
| 329 |
} |
| 330 |
|
| 331 |
/** |
| 332 |
* Renders the progress bar block. |
| 333 |
* |
| 334 |
* @since 1.8.3 |
| 335 |
* |
| 336 |
* @param array $attributes The attributes for the block. |
| 337 |
*/ |
| 338 |
public function charitable_block_render_donation_button_widget( $attributes ) { |
| 339 |
|
| 340 |
$args = array(); |
| 341 |
$args['campaign'] = ! empty( $attributes['campaignID'] ) ? $attributes['campaignID'] : ''; |
| 342 |
$args['itemLabel'] = ! empty( $attributes['itemLabel'] ) ? $attributes['itemLabel'] : ''; |
| 343 |
$args['customCSS'] = ! empty( $attributes['customCSS'] ) ? $attributes['customCSS'] : ''; |
| 344 |
$args['newTab'] = ! empty( $attributes['newTab'] ) ? $attributes['newTab'] : '0'; |
| 345 |
$args['buttonType'] = ! empty( $attributes['buttonType'] ) ? $attributes['buttonType'] : 'button'; |
| 346 |
|
| 347 |
// the button must have a campaign ID, otherwise bail. |
| 348 |
if ( empty( $args['campaign'] ) ) { |
| 349 |
return; |
| 350 |
} |
| 351 |
|
| 352 |
// create a shortcode with the attributes, but only include the attributes that are not empty with ''. |
| 353 |
$shortcode_attribute_string = ''; |
| 354 |
$shortcode_attribute_string .= ! empty( $args['campaign'] ) ? ' campaign="' . esc_html( $args['campaign'] ) . '"' : ''; |
| 355 |
$shortcode_attribute_string .= ! empty( $args['itemLabel'] ) ? ' label="' . esc_html( $args['itemLabel'] ) . '"' : ''; |
| 356 |
$shortcode_attribute_string .= ! empty( $args['customCSS'] ) ? ' css="' . esc_html( $args['itemcustomCSSLabel'] ) . '"' : ''; |
| 357 |
$shortcode_attribute_string .= ! empty( $args['buttonType'] ) ? ' type="' . esc_html( $args['buttonType'] ) . '"' : ''; |
| 358 |
$shortcode_attribute_string .= ! empty( $args['newTab'] ) ? ' new_tab="' . esc_html( $args['newTab'] ) . '"' : ''; |
| 359 |
|
| 360 |
ob_start(); |
| 361 |
|
| 362 |
echo do_shortcode( '[charitable_donate_button ' . $shortcode_attribute_string . ']' ); |
| 363 |
|
| 364 |
return ob_get_clean(); |
| 365 |
} |
| 366 |
|
| 367 |
/** |
| 368 |
* Renders the donations widget block. |
| 369 |
* |
| 370 |
* @since 1.8.3 |
| 371 |
* |
| 372 |
* @param array $attributes The attributes for the block. |
| 373 |
*/ |
| 374 |
public function charitable_block_render_my_donations_widget( $attributes ) { |
| 375 |
|
| 376 |
$args = array(); |
| 377 |
$args['include_recurring'] = ! empty( $attributes['includeRecurring'] ) ? $attributes['includeRecurring'] : ''; |
| 378 |
|
| 379 |
// create a shortcode with the attributes, but only include the attributes that are not empty with ''. |
| 380 |
$shortcode_attribute_string = ''; |
| 381 |
$shortcode_attribute_string .= empty( $args['include_recurring'] ) ? ' hide_recurring="1"' : ''; |
| 382 |
|
| 383 |
ob_start(); |
| 384 |
|
| 385 |
echo do_shortcode( '[charitable_my_donations ' . $shortcode_attribute_string . ']' ); |
| 386 |
|
| 387 |
return ob_get_clean(); |
| 388 |
} |
| 389 |
|
| 390 |
/** |
| 391 |
* Loads admin-only scripts and stylesheets. |
| 392 |
* |
| 393 |
* @since 1.8.0 |
| 394 |
* |
| 395 |
* @return void |
| 396 |
*/ |
| 397 |
public function admin_enqueue_scripts() { |
| 398 |
|
| 399 |
$min = charitable_get_min_suffix(); |
| 400 |
$version = charitable()->get_version(); |
| 401 |
|
| 402 |
$assets_dir = charitable()->get_path( 'assets', false ); |
| 403 |
|
| 404 |
/* The following styles are only loaded on Charitable screens. */ |
| 405 |
$screen = get_current_screen(); |
| 406 |
|
| 407 |
// add data only for block editor pages, where the campaign block (among others) would be used. |
| 408 |
if ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) { |
| 409 |
|
| 410 |
wp_localize_script( |
| 411 |
'create-block-campaignblock-editor-script', |
| 412 |
'charitable_block_data', |
| 413 |
$this->get_localized_strings_block_data() |
| 414 |
); |
| 415 |
} |
| 416 |
|
| 417 |
do_action( 'after_charitable_admin_block_enqueue_scripts', $min, $version, $assets_dir ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Hook name may be used by other code. Changing it would break existing functionality. |
| 418 |
} |
| 419 |
|
| 420 |
/** |
| 421 |
* Retrieves localized strings for the Charitable Blocks editor. |
| 422 |
* |
| 423 |
* @since 1.8.0 |
| 424 |
* @version 1.8.3 |
| 425 |
* |
| 426 |
* @param array $args Optional. Arguments to customize the localized strings. |
| 427 |
* @return array An array of localized strings. |
| 428 |
*/ |
| 429 |
private function get_localized_strings_block_data( $args = array() ) { |
| 430 |
|
| 431 |
$defaults = array( |
| 432 |
'post_type' => array( Charitable::CAMPAIGN_POST_TYPE ), |
| 433 |
'posts_per_page' => -1, |
| 434 |
'post_status' => array( 'publish' ), |
| 435 |
); |
| 436 |
|
| 437 |
$args = wp_parse_args( $args, $defaults ); |
| 438 |
|
| 439 |
$query = new WP_Query( $args ); |
| 440 |
|
| 441 |
$campaigns_for_dropdown = array(); |
| 442 |
|
| 443 |
if ( ! empty( $query->posts ) ) : |
| 444 |
foreach ( $query->posts as $post_id => $campaign_post ) : |
| 445 |
$campaigns_for_dropdown[] = array( |
| 446 |
'label' => $campaign_post->post_title, |
| 447 |
'value' => $campaign_post->ID, |
| 448 |
); |
| 449 |
endforeach; |
| 450 |
// sory multidimensional array alphabetically by label. |
| 451 |
usort( |
| 452 |
$campaigns_for_dropdown, |
| 453 |
function ( $a, $b ) { |
| 454 |
return strcmp( $a['label'], $b['label'] ); |
| 455 |
} |
| 456 |
); |
| 457 |
endif; |
| 458 |
|
| 459 |
// add blank element. |
| 460 |
array_unshift( |
| 461 |
$campaigns_for_dropdown, |
| 462 |
array( |
| 463 |
'label' => '', |
| 464 |
'value' => '', |
| 465 |
) |
| 466 |
); |
| 467 |
|
| 468 |
$strings = array( |
| 469 |
'campaigns' => $campaigns_for_dropdown, |
| 470 |
'charitable_addons_page' => esc_url( admin_url( 'admin.php?page=charitable-addons' ) ), |
| 471 |
'version' => '1.8.3', |
| 472 |
'logo' => esc_url( home_url( 'wp-content/plugins/charitable/assets/images/charitable-header-logo.png' ) ), |
| 473 |
'charitable_assets_dir' => apply_filters( |
| 474 |
'charitable_campaign_builder_charitable_assets_dir', |
| 475 |
charitable()->get_path( 'directory', false ) . 'assets/' |
| 476 |
), |
| 477 |
'panel_notice_head' => esc_html__( 'Need Some Help?', 'charitable' ), |
| 478 |
'panel_notice_text' => esc_html__( 'Check out our docs for information about this block.', 'charitable' ), |
| 479 |
'panel_notice_link' => esc_url( charitable_utm_link( 'https://www.wpcharitable.com/documentation/', 'charitable' ) ), |
| 480 |
'panel_notice_link_text' => esc_html__( 'Check out our docs.', 'charitable' ), |
| 481 |
|
| 482 |
'panel_campaigns_notice_head' => esc_html__( 'Need Some Help?', 'charitable' ), |
| 483 |
'panel_campaigns_notice_text' => esc_html__( 'You can read more about the campaigns shortcode and block on our site.', 'charitable' ), |
| 484 |
'panel_campaigns_notice_link' => esc_url( charitable_utm_link( 'https://www.wpcharitable.com/documentation/the-campaigns-shortcode/', 'charitable' ) ), |
| 485 |
'panel_campaigns_notice_link_text' => esc_html__( 'Check out our docs.', 'charitable' ), |
| 486 |
|
| 487 |
'panel_donations_notice_head' => esc_html__( 'Need Some Help?', 'charitable' ), |
| 488 |
'panel_donations_notice_text' => esc_html__( 'You can read more about the donations shortcode and block on our site.', 'charitable' ), |
| 489 |
'panel_donations_notice_link' => esc_url( charitable_utm_link( 'https://www.wpcharitable.com/documentation/donations-shortcode/', 'charitable' ) ), |
| 490 |
'panel_donations_notice_link_text' => esc_html__( 'Check out our docs.', 'charitable' ), |
| 491 |
|
| 492 |
'panel_donation_button_notice_head' => esc_html__( 'Need Some Help?', 'charitable' ), |
| 493 |
'panel_donation_button_notice_text' => esc_html__( 'You can read more about the shortcode and block for the donation button on our site.', 'charitable' ), |
| 494 |
'panel_donation_button_notice_link' => esc_url( charitable_utm_link( 'https://www.wpcharitable.com/documentation/donation-button-shortcode/', 'charitable' ) ), |
| 495 |
'panel_donation_button_notice_link_text' => esc_html__( 'Check out our docs.', 'charitable' ), |
| 496 |
|
| 497 |
'panel_progress_bar_notice_head' => esc_html__( 'Need Some Help?', 'charitable' ), |
| 498 |
'panel_progress_bar_notice_text' => esc_html__( 'You can read more about the shortcode and block for the progress bar on our site.', 'charitable' ), |
| 499 |
'panel_progress_bar_notice_link' => esc_url( charitable_utm_link( 'https://www.wpcharitable.com/documentation/progress-bar-shortcode/', 'charitable' ) ), |
| 500 |
'panel_progress_bar_notice_link_text' => esc_html__( 'Check out our docs.', 'charitable' ), |
| 501 |
|
| 502 |
'panel_stats_notice_head' => esc_html__( 'Need Some Help?', 'charitable' ), |
| 503 |
'panel_stats_notice_text' => esc_html__( 'You can read more about the stats shortcode and the block on our site.', 'charitable' ), |
| 504 |
'panel_stats_notice_link' => esc_url( charitable_utm_link( 'https://www.wpcharitable.com/documentation/stats-shortcode/', 'charitable' ) ), |
| 505 |
'panel_stats_notice_link_text' => esc_html__( 'Check out our docs.', 'charitable' ), |
| 506 |
|
| 507 |
'panel_my_donations_notice_head' => esc_html__( 'Need Some Help?', 'charitable' ), |
| 508 |
'panel_my_donations_notice_text' => esc_html__( 'You can read more about this block along with other related blocks and shortcodes on our site.', 'charitable' ), |
| 509 |
'panel_my_donations_notice_link' => esc_url( charitable_utm_link( 'https://www.wpcharitable.com/documentation/account-shortcodes/', 'charitable' ) ), |
| 510 |
'panel_my_donations_notice_link_text' => esc_html__( 'Check out our docs.', 'charitable' ), |
| 511 |
|
| 512 |
'panel_my_donors_notice_head' => esc_html__( 'Need Some Help?', 'charitable' ), |
| 513 |
'panel_my_donors_notice_text' => esc_html__( 'You can read more about the donors block and donors shortcode on our site.', 'charitable' ), |
| 514 |
'panel_my_donors_notice_link' => esc_url( charitable_utm_link( 'https://www.wpcharitable.com/documentation/donors-shortcode/', 'charitable' ) ), |
| 515 |
'panel_my_donors_notice_link_text' => esc_html__( 'Check out our docs.', 'charitable' ), |
| 516 |
); |
| 517 |
|
| 518 |
return $strings; |
| 519 |
} |
| 520 |
|
| 521 |
/** |
| 522 |
* Returns and/or create the single instance of this class. |
| 523 |
* |
| 524 |
* @since 1.8.0 |
| 525 |
* |
| 526 |
* @return Charitable_Admin |
| 527 |
*/ |
| 528 |
public static function get_instance() { |
| 529 |
if ( is_null( self::$instance ) ) { |
| 530 |
self::$instance = new self(); |
| 531 |
} |
| 532 |
|
| 533 |
return self::$instance; |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
new Charitable_Admin_Blocks(); |
| 538 |
|
| 539 |
endif; |
| 540 |
|