PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 5.5.4
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v5.5.4
5.5.4 5.5.3 3.1.0 3.2.0 3.2.1 3.3.0 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.6.0 3.7.0 3.8.0 3.8.1 3.8.2 3.8.3 4.0.0 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 All 79 releases
copy-the-code / includes / global-injector / class-main-rule-list.php

class-main-rule-list.php in Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code 5.5.4, at includes/global-injector/class-main-rule-list.php

144 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main Rule List (Global Injector)
4 *
5 * @package CTC
6 * @since 5.1.0
7 */
8
9 namespace CTC\Global_Injector;
10
11 use CTC\Global_Injector;
12 use CTC\Helper;
13 use CTC\Analytics\Database as Analytics_Database;
14
15 /**
16 * Main Rule List class.
17 *
18 * Replaces the default post list table with a custom UI for Pro users.
19 *
20 * @since 5.1.0
21 */
22 class Main_Rule_List {
23
24 /**
25 * Instance
26 *
27 * @since 5.1.0
28 *
29 * @access private
30 * @var object Class object.
31 */
32 private static $instance;
33
34 /**
35 * Initiator
36 *
37 * @since 5.1.0
38 *
39 * @return object initialized object of class.
40 */
41 public static function get() {
42 if ( null === self::$instance ) {
43 self::$instance = new self();
44 }
45 return self::$instance;
46 }
47
48 /**
49 * Bootstrap the Main Rule List UI.
50 *
51 * @since 5.1.0
52 * @return void
53 */
54 public function bootstrap() {
55 if ( ! current_user_can( 'manage_options' ) ) {
56 return;
57 }
58
59 $this->enqueue_assets();
60 }
61
62 /**
63 * Enqueue assets and localize data.
64 *
65 * @since 5.1.0
66 * @return void
67 */
68 public function enqueue_assets() {
69 wp_enqueue_style(
70 'ctc-global-injector',
71 CTC_URI . 'assets/admin/css/global-injector.css',
72 [],
73 CTC_VER
74 );
75
76 wp_enqueue_style(
77 'ctc-main-rule-list',
78 CTC_URI . 'assets/admin/css/main-rule-list.css',
79 [],
80 CTC_VER
81 );
82
83 wp_enqueue_script(
84 'ctc-main-rule-list',
85 CTC_URI . 'assets/admin/js/main-rule-list.js',
86 [
87 'wp-element',
88 'wp-i18n',
89 'wp-api-fetch',
90 'lodash',
91 'jquery',
92 ],
93 CTC_VER,
94 true
95 );
96
97 $rules = Global_Injector::get()->get_admin_rules();
98
99 $rule_stats = [];
100 if ( ! empty( $rules ) && class_exists( 'CTC\Analytics\Database' ) ) {
101 $db = Analytics_Database::get();
102 $now = Helper::mysql_now();
103 $date_from = Helper::mysql_date_ago( '-30 days' );
104 foreach ( $rules as $rule ) {
105 $id = isset( $rule['id'] ) ? (int) $rule['id'] : 0;
106 if ( $id > 0 ) {
107 $rule_stats[ $id ] = $db->get_rule_stats( $id, $date_from, $now );
108 }
109 }
110 }
111
112 $localize_data = [
113 'isPro' => Helper::is_pro(),
114 'version' => CTC_VER,
115 'rules' => $rules,
116 'rule_stats' => $rule_stats,
117 'apiUrl' => rest_url( 'ctc/v1/' ),
118 'nonce' => wp_create_nonce( 'wp_rest' ),
119 'urls' => [
120 'addNew' => admin_url( 'options-general.php?page=ctc-global-injector' ),
121 'dashboard' => admin_url( 'options-general.php?page=ctc' ),
122 'editRuleBase' => admin_url( 'options-general.php?page=ctc-global-injector&rule=' ),
123 'analytics' => admin_url( 'options-general.php?page=ctc-analytics' ),
124 ],
125 ];
126
127 /**
128 * Filter Main Rule List localize data.
129 *
130 * Pro can use this to add urls.analytics and ruleActivity data.
131 *
132 * @since 5.3.0
133 * @param array $data Localized data array.
134 */
135 $localize_data = apply_filters( 'ctc/main_rule_list/localize_data', $localize_data );
136
137 wp_localize_script(
138 'ctc-main-rule-list',
139 'CTCMainRuleList',
140 $localize_data
141 );
142 }
143 }
144