| 1 |
<?php |
| 2 |
/** |
| 3 |
* Dashboard Widgets |
| 4 |
* |
| 5 |
* @package Give |
| 6 |
* @subpackage Admin/Dashboard |
| 7 |
* @copyright Copyright (c) 2016, GiveWP |
| 8 |
* @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 |
* @since 1.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Add donation forms count to dashboard "At a glance" widget |
| 19 |
* |
| 20 |
* @since 1.0 |
| 21 |
* |
| 22 |
* @param $items |
| 23 |
* |
| 24 |
* @return array |
| 25 |
*/ |
| 26 |
function give_dashboard_at_a_glance_widget( $items ) { |
| 27 |
|
| 28 |
$num_posts = wp_count_posts( 'give_forms' ); |
| 29 |
|
| 30 |
if ( $num_posts && $num_posts->publish ) { |
| 31 |
|
| 32 |
$text = sprintf( |
| 33 |
/* translators: %s: number of posts published */ |
| 34 |
_n( '%s GiveWP Form', '%s GiveWP Forms', $num_posts->publish, 'give' ), |
| 35 |
$num_posts->publish |
| 36 |
); |
| 37 |
|
| 38 |
$text = sprintf( $text, number_format_i18n( $num_posts->publish ) ); |
| 39 |
|
| 40 |
if ( current_user_can( 'edit_give_forms', get_current_user_id() ) ) { |
| 41 |
$text = sprintf( |
| 42 |
'<a class="give-forms-count" href="%1$s">%2$s</a>', |
| 43 |
admin_url( 'edit.php?post_type=give_forms' ), |
| 44 |
$text |
| 45 |
); |
| 46 |
} else { |
| 47 |
$text = sprintf( |
| 48 |
'<span class="give-forms-count">%1$s</span>', |
| 49 |
$text |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
$items[] = $text; |
| 54 |
} |
| 55 |
|
| 56 |
return $items; |
| 57 |
} |
| 58 |
|
| 59 |
add_filter( 'dashboard_glance_items', 'give_dashboard_at_a_glance_widget', 1, 1 ); |
| 60 |
|