PluginProbe
Counters Block – showcase your stats with animated numbers / trunk
Counters Block – showcase your stats with animated numbers vtrunk
2.0.8 2.0.7 trunk 1.0.0 1.0.1 1.0.2 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6
counters-block / includes / class-ctrbAdmin.php

class-ctrbAdmin.php in Counters Block – showcase your stats with animated numbers trunk, at includes/class-ctrbAdmin.php

125 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly.
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 if (!class_exists('CTRBAdmin')) {
8 class CTRBAdmin
9 {
10 public function __construct()
11 {
12
13 add_action('init', [$this, 'ctrbRegisterPostType']);
14 add_action('admin_enqueue_scripts', [$this, 'enqueueDashboardAssets']);
15 add_action('admin_menu', [$this, 'ctrbAdminSubmenu']);
16 add_filter('manage_counters-block_posts_columns', [$this, 'ctrb_setCustomColumn_edit']);
17 add_action('manage_counters-block_posts_custom_column', [$this, 'ctrb_manageCustomColumn'], 10, 2);
18 }
19
20 public function ctrbRegisterPostType()
21 {
22 $icon = "<svg xmlns='http://www.w3.org/2000/svg' className='bPlBlockIcon' viewBox='0 0 448 512' fill='currentColor' stroke='currentColor' stroke-width='0' color='#fff'>
23 <path d='M176 0c-17.7 0-32 14.3-32 32s14.3 32 32 32h16V98.4C92.3 113.8 16 200 16 304c0 114.9 93.1 208 208 208s208-93.1 208-208c0-41.8-12.3-80.7-33.5-113.2l24.1-24.1c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L355.7 143c-28.1-23-62.2-38.8-99.7-44.6V64h16c17.7 0 32-14.3 32-32s-14.3-32-32-32H176zM288 204c28.7 0 52 23.3 52 52v96c0 28.7-23.3 52-52 52s-52-23.3-52-52V256c0-28.7 23.3-52 52-52zm-12 52v96c0 6.6 5.4 12 12 12s12-5.4 12-12V256c0-6.6-5.4-12-12-12s-12 5.4-12 12zM159.5 244c-5.4 0-10.2 3.5-11.9 8.6l-.6 1.7c-3.5 10.5-14.8 16.1-25.3 12.6s-16.1-14.8-12.6-25.3l.6-1.7c7.2-21.5 27.2-35.9 49.8-35.9c29 0 52.5 23.5 52.5 52.5v2.2c0 13.4-4.9 26.4-13.8 36.4l-39 43.9c-6.2 7-10 15.7-10.9 24.9H192c11 0 20 9 20 20s-9 20-20 20H128c-11 0-20-9-20-20V368.3c0-20.6 7.5-40.4 21.2-55.8l39-43.9c2.4-2.7 3.7-6.2 3.7-9.8v-2.2c0-6.9-5.6-12.5-12.5-12.5z' />
24 </svg>";
25
26
27 register_post_type(
28 'counters-block',
29 [
30 'label' => 'Counters Block',
31 'labels' => [
32 'add_new' => 'Add New Shortcode',
33 'add_new_item' => 'Add New Shortcode',
34 'edit_item' => 'Edit Shortcode',
35 'not_found' => 'No Shortcode found',
36 ],
37 'supports' => ['title', 'editor', 'revisions'],
38 'show_in_rest' => true,
39 'public' => true,
40 'publicly_queryable' => false,
41 'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode($icon),
42 'item_published' => 'Counters Block Published',
43 'item_updated' => 'Counters Block Updated',
44 'template' => [['ctrb/counters']],
45 'template_lock' => 'all',
46
47 ]
48 );
49 }
50
51
52 public function ctrbAdminSubmenu()
53 {
54 $parent_slug = 'tools.php';
55
56 add_submenu_page(
57 'edit.php?post_type=counters-block',
58 'Demo and Help',
59 'Demo & Help',
60 'manage_options',
61 'demo_page',
62 [$this, 'ctrb_render_demo_page']
63 );
64 }
65
66 // pass dashboard data through inline script
67
68 public function enqueueDashboardAssets()
69 {
70 $data = [
71 'version' => CTRB_VERSION,
72 'isPremium' => ctrbIsPremium(),
73 'hasPro' => CTRB_HAS_PRO,
74 ];
75 wp_add_inline_script(
76 'ctrb-admin-dashboard',
77 'const dashboardData = ' . wp_json_encode($data) . ';',
78 'before'
79 );
80 }
81 // render dashboard and pass its data through data attributes
82
83 public function ctrb_render_demo_page()
84 {
85
86 ?>
87 <div id='ctrb-admin-dashboard'
88 data-info='<?php echo esc_attr(wp_json_encode([
89 'version' => CTRB_VERSION,
90 'isPremium' => ctrbIsPremium(),
91 'hasPro' => CTRB_HAS_PRO,
92 'licenseActiveNonce' => wp_create_nonce('ctrbLicenseActivation'),
93
94 ])); ?>'></div>
95 <?php
96 }
97 // set custom columns for edit page
98
99 public function ctrb_setCustomColumn_edit($column)
100 {
101 unset($column['date']);
102 $column['shortcode'] = 'ShortCode';
103 $column['date'] = 'Date';
104 $column['publisher'] = 'Publisher';
105 return $column;
106 }
107
108 public function ctrb_manageCustomColumn($column_name, $post_id)
109 {
110
111 if ($column_name == 'shortcode') {
112 echo '<div class="bPlAdminShortcode" id="bPlAdminShortcode-' . esc_attr($post_id) . '">
113 <input value="[counters-block id=' . esc_attr($post_id) . ']" onclick="copyBPlAdminShortcode(\'' . esc_attr($post_id) . '\')" readonly>
114 <span class="tooltip">Copy To Clipboard</span>
115 </div>';
116 }
117 if ($column_name == 'publisher') {
118 echo 'Counters Block';
119 }
120 }
121 }
122
123 new CTRBAdmin();
124 }
125