PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.3 6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 All 156 releases
← All changes | widgets/widget-mainwp-site-actions.php +202 -209 5.0 → 6.2.1 View file →
@@ -8,230 +8,223 @@
8 8 */
9 9
10 10 namespace MainWP\Dashboard;
11 11
12 +use MainWP\Dashboard\MainWP_UI;
13 +use MainWP\Dashboard\Module\Log\Log_Manager;
14 +use MainWP\Dashboard\Module\Log\Log_Events_List_Table;
15 +use MainWP\Dashboard\Module\Log\Log_DB_Helper;
16 +
17 +// Exit if accessed directly.
18 +if ( ! defined( 'ABSPATH' ) ) {
19 + exit;
20 +}
21 +
12 22 /**
13 23 * Class MainWP_Site_Actions
14 24 *
15 25 * Displays the Site Actions.
16 26 */
17 -class MainWP_Site_Actions {
27 +class MainWP_Site_Actions { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
18 28
19 - /**
20 - * Method get_class_name()
21 - *
22 - * @return string __CLASS__ Class name.
23 - */
24 - public static function get_class_name() {
25 - return __CLASS__;
26 - }
29 + /**
30 + * Private static variable to hold the single instance of the class.
31 + *
32 + * @static
33 + *
34 + * @var mixed Default null
35 + */
36 + private static $instance = null;
27 37
28 - /**
29 - * Method render()
30 - *
31 - * @return mixed render_site_info()
32 - */
33 - public static function render() {
34 - $current_wpid = MainWP_System_Utility::get_current_wpid();
35 - $website = null;
36 - $actions_info = array();
37 - if ( $current_wpid ) {
38 - $params = array(
39 - 'wpid' => $current_wpid,
40 - 'where_extra' => ' AND dismiss = 0 ',
41 - );
42 - $website = MainWP_DB::instance()->get_website_by_id( $current_wpid );
43 - $actions_info = MainWP_DB_Site_Actions::instance()->get_wp_actions( $params );
44 - } elseif ( isset( $_GET['client_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
45 - $client_id = isset( $_GET['client_id'] ) ? intval( $_GET['client_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
46 - $websites = MainWP_DB_Client::instance()->get_websites_by_client_ids( $client_id );
47 - $site_ids = array();
38 + /**
39 + * Private static variable to hold the single instance of the events table.
40 + *
41 + * @static
42 + *
43 + * @var mixed Default null
44 + */
45 + private $list_events_table = null;
48 46
49 - foreach ( $websites as $website ) {
50 - $site_ids[] = $website->id;
51 - }
52 47
53 - if ( ! empty( $site_ids ) ) {
54 - $limit = apply_filters( 'mainwp_widget_site_actions_limit_number', 50 );
55 - $params = array(
56 - 'limit' => $limit,
57 - 'where_extra' => ' AND dismiss = 0 ',
58 - 'wpid' => $site_ids,
59 - );
60 - $actions_info = MainWP_DB_Site_Actions::instance()->get_wp_actions( $params );
61 - }
62 - } else {
63 - $limit = apply_filters( 'mainwp_widget_site_actions_limit_number', 50 );
64 - $params = array(
65 - 'limit' => $limit,
66 - 'where_extra' => ' AND dismiss = 0 ',
67 - );
68 - $actions_info = MainWP_DB_Site_Actions::instance()->get_wp_actions( $params );
69 - }
70 - self::render_info( $actions_info, $website );
71 - }
48 + /**
49 + * Private static variable to hold the table type value.
50 + *
51 + * @var mixed Default null
52 + */
53 + private $table_id_prefix = 'widget-overview';
72 54
73 - /**
74 - * Render Sites actions Info.
75 - *
76 - * @param object $actions_info Sites actions info.
77 - * @param object $website Sites info.
78 - */
79 - private static function render_info( $actions_info, $website ) {
55 + /**
56 + * Method instance()
57 + *
58 + * Create public static instance.
59 + *
60 + * @static
61 + * @return MainWP_Site_Actions
62 + */
63 + public static function instance() {
64 + if ( null === static::$instance ) {
65 + static::$instance = new self();
66 + }
67 + return static::$instance;
68 + }
80 69
81 - if ( ! is_array( $actions_info ) ) {
82 - $actions_info = array();
83 - }
84 - ?>
85 70
86 - <div class="mainwp-widget-header">
87 - <h3 class="ui header handle-drag">
88 - <?php
89 - /**
90 - * Filter: mainwp_non_mainwp_changes_widget_title
91 - *
92 - * Filters the Site info widget title text.
93 - *
94 - * @param object $website Object containing the child site info.
95 - *
96 - * @since 4.1
97 - */
98 - echo esc_html( apply_filters( 'mainwp_non_mainwp_changes_widget_title', esc_html__( 'Non-MainWP Changes', 'mainwp' ), $website ) );
99 - ?>
100 - <div class="sub header"><?php esc_html_e( 'The most recent changes made to your Child Sites that were not done through your MainWP Dashboard.', 'mainwp' ); ?></div>
101 - </h3>
102 - </div>
71 + /**
72 + * Method get_class_name()
73 + *
74 + * @return string __CLASS__ Class name.
75 + */
76 + public static function get_class_name() {
77 + return __CLASS__;
78 + }
103 79
104 - <div id="mainwp-widget-site-actions" class="mainwp-scrolly-overflow">
105 - <?php
106 - /**
107 - * Actoin: mainwp_non_mainwp_changes_widget_top
108 - *
109 - * Fires at the top of the Site Info widget on the Individual site overview page.
110 - *
111 - * @param object $website Object containing the child site info.
112 - *
113 - * @since 4.0
114 - */
115 - do_action( 'mainwp_non_mainwp_changes_widget_top', $website );
116 - ?>
117 - <?php if ( $actions_info ) : ?>
118 - <table class="ui table" id="mainwp-non-mainwp-changes-table">
119 - <thead>
120 - <tr>
121 - <th><?php esc_html_e( 'Change', 'mainwp' ); ?></th>
122 - <?php if ( empty( $website ) || isset( $_GET['client_id'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
123 - <th class="collapsing"><?php esc_html_e( 'Website', 'mainwp' ); ?></th>
124 - <?php endif; ?>
125 - <th class="collapsing"><?php esc_html_e( 'User', 'mainwp' ); ?></th>
126 - <th class="collapsing no-sort"></th>
127 - </tr>
128 - </thead>
129 - <tbody>
130 - <?php
131 - /**
132 - * Action: mainwp_non_mainwp_changes_table_top
133 - *
134 - * Fires at the top of the Site Info table in Site Info widget on the Individual site overview page.
135 - *
136 - * @param object $website Object containing the child site info.
137 - *
138 - * @since 4.0
139 - */
140 - do_action( 'mainwp_non_mainwp_changes_table_top', $website );
141 - ?>
142 - <?php foreach ( $actions_info as $idx => $data ) : ?>
143 - <?php
144 - if ( empty( $data->action_user ) || empty( $data->meta_data ) ) {
145 - continue;
146 - }
80 + /**
81 + * Method render()
82 + *
83 + * @return mixed render_site_info()
84 + */
85 + public static function render() {
86 + $current_wpid = MainWP_System_Utility::get_current_wpid();
87 + $website = null;
88 + $params = array();
89 + $params['limit'] = apply_filters( 'mainwp_widget_site_actions_limit_number', 50 );
90 + if ( $current_wpid ) {
91 + $params = array(
92 + 'wpid' => $current_wpid,
93 + );
94 + $website = MainWP_DB::instance()->get_website_by_id( $current_wpid );
95 + } elseif ( isset( $_GET['client_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
96 + $client_id = isset( $_GET['client_id'] ) ? intval( $_GET['client_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
97 + $params = array(
98 + 'client_id' => $client_id,
99 + );
100 + }
101 + static::instance()->render_info( $params, $website );
102 + }
147 103
148 - $meta_data = json_decode( $data->meta_data );
104 + /**
105 + * Render Sites actions Info.
106 + *
107 + * @param array $params Events params.
108 + * @param object $website Sites info.
109 + */
110 + private function render_info( $params, $website ) { // phpcs:ignore -- NOSONAR - complex.
149 111
150 - $action_class = '';
151 - if ( 'activated' === $data->action ) {
152 - $action_class = 'green';
153 - } elseif ( 'deactivated' === $data->action ) {
154 - $action_class = 'red';
155 - } elseif ( 'installed' === $data->action ) {
156 - $action_class = 'blue';
157 - }
112 + if ( ! is_array( $params ) ) {
113 + $params = array();
114 + }
115 + $this->load_events_list_table();
116 + ?>
158 117
159 - ?>
160 - <tr>
161 - <td data-order="<?php echo esc_attr( $data->created ); ?>">
162 - <strong><?php echo isset( $meta_data->name ) && '' !== $meta_data->name ? esc_html( $meta_data->name ) : 'WP Core'; ?></strong> <?php echo 'wordpress' !== $data->context ? esc_html( ucfirst( rtrim( $data->context, 's' ) ) ) : 'WordPress'; //phpcs:ignore -- text. ?><br/>
163 - <div><strong><span class="ui medium <?php echo esc_attr( $action_class ); ?> text"><?php echo esc_html( ucfirst( $data->action ) ); ?></span></strong></div>
164 - <span class="ui small text"><?php echo esc_html( MainWP_Utility::format_timestamp( $data->created ) ); ?></span>
165 - </td>
166 - <?php if ( empty( $website ) || isset( $_GET['client_id'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
167 - <td class="collapsing"><a href="admin.php?page=managesites&dashboard=<?php echo esc_attr( $data->wpid ); ?>"><?php echo esc_html( $data->name ); ?></a></td>
168 - <?php endif; ?>
169 - <td class="collapsing"><?php echo esc_html( $data->action_user ); ?></td>
170 - <td class="collapsing">
171 - <a href="javascript:void(0)" class="mainwp-action-dismiss ui mini icon button" action-id="<?php echo intval( $data->action_id ); ?>" data-tooltip="<?php esc_attr_e( 'Dismiss the notice.', 'mainwp' ); ?>" data-position="left center" data-inverted=""><i class="times icon"></i></a>
172 - </td>
173 - </tr>
174 - <?php endforeach; ?>
175 - <?php
176 - /**
177 - * Action: mainwp_non_mainwp_changes_table_bottom
178 - *
179 - * Fires at the bottom of the Site Info table in Site Info widget on the Individual site overview page.
180 - *
181 - * @param object $website Object containing the child site info.
182 - *
183 - * @since 4.0
184 - */
185 - do_action( 'mainwp_non_mainwp_changes_table_bottom', $website );
186 - ?>
187 - </tbody>
188 - </table>
189 - <script type="text/javascript">
190 - jQuery( document ).ready( function() {
191 - jQuery.fn.DataTable.ext.pager.numbers_length = 4;
192 - jQuery( '#mainwp-non-mainwp-changes-table' ).DataTable( {
193 - "pageLength": 10,
194 - "lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ],
195 - "stateSave" : true,
196 - "stateDuration" : 0,
197 - "columnDefs": [ {
198 - "targets": 'no-sort',
199 - "orderable": false
200 - } ],
201 - } );
202 - } );
203 - </script>
204 - <?php else : ?>
205 - <?php MainWP_UI::render_empty_element_placeholder(); ?>
206 - <?php endif; ?>
207 - </div>
208 - <?php
209 - $params = array(
210 - 'total_count' => true,
211 - 'dismiss' => 0,
212 - );
213 - $totalRecords = MainWP_DB_Site_Actions::instance()->get_wp_actions( $params );
214 - ?>
215 - <div class="mainwp-widget-footer">
216 - <div class="ui two columns stackable grid">
217 - <div class="middle aligned column">
218 - <?php if ( $totalRecords ) : ?>
219 - <a href="admin.php?page=NonMainWPChanges" class="ui button mini fluid green"><?php printf( esc_html__( 'See all %d Non-MainWP Changes', 'mainwp' ), intval( $totalRecords ) ); ?></a>
220 - <?php endif; ?>
221 - </div>
222 - <div class="middle aligned column"></div>
223 - </div>
224 - </div>
225 - <?php
226 - /**
227 - * Action: mainwp_non_mainwp_changes_widget_bottom
228 - *
229 - * Fires at the bottom of the Site Info widget on the Individual site overview page.
230 - *
231 - * @param object $website Object containing the child site info.
232 - *
233 - * @since 4.0
234 - */
235 - do_action( 'mainwp_non_mainwp_changes_widget_bottom', $website );
236 - }
118 + <div class="mainwp-widget-header">
119 + <div class="ui grid">
120 + <div class="fourteen wide column">
121 + <h2 class="ui header handle-drag">
122 + <?php
123 + /**
124 + * Filter: mainwp_non_mainwp_changes_widget_title
125 + *
126 + * Filters the Site info widget title text.
127 + *
128 + * @param object $website Object containing the child site info.
129 + *
130 + * @since 4.1
131 + */
132 + echo esc_html( apply_filters( 'mainwp_non_mainwp_changes_widget_title', esc_html__( 'Network Activity', 'mainwp' ), $website ) );
133 + ?>
134 + <div class="sub header"><?php esc_html_e( 'The most recent changes made to your Child Sites.', 'mainwp' ); ?></div>
135 + </h2>
136 + </div>
137 + <div class="two wide column right aligned">
138 + <div id="widget-sites-changes-dropdown-selector" class="ui dropdown top right tiny pointing not-auto-init mainwp-dropdown-tab">
139 + <i class="vertical ellipsis icon"></i>
140 + <div class="menu">
141 + <a href="javascript:void(0)" class="item" data-value="wp-admin"><?php esc_html_e( 'Non-MainWP Changes', 'mainwp' ); ?></a>
142 + <a href="javascript:void(0)" class="item" data-value="dashboard"><?php esc_html_e( 'Dashboard Changes', 'mainwp' ); ?></a>
143 + <a href="javascript:void(0)" class="item" data-value=""><?php esc_html_e( 'Show All', 'mainwp' ); ?></a>
144 + </div>
145 + </div>
146 + </div>
147 + </div>
148 + </div>
149 + <input type="hidden" id="mainwp-widget-filter-current-site-id" value="<?php echo isset( $params['wpid'] ) ? intval( $params['wpid'] ) : 0; ?>" />
150 + <input type="hidden" id="mainwp-widget-filter-current-client-id" value="<?php echo isset( $params['client_id'] ) ? intval( $params['client_id'] ) : 0; ?>" />
151 + <input type="hidden" id="mainwp-widget-filter-events-limit" value="<?php echo isset( $params['limit'] ) ? intval( $params['limit'] ) : 50; ?>" />
152 +
153 + <div id="mainwp-widget-site-actions" class="mainwp-scrolly-overflow">
154 + <?php
155 + /**
156 + * Actoin: mainwp_non_mainwp_changes_widget_top
157 + *
158 + * Fires at the top of the Site Info widget on the Individual site overview page.
159 + *
160 + * @param object $website Object containing the child site info.
161 + *
162 + * @since 4.0
163 + */
164 + do_action( 'mainwp_non_mainwp_changes_widget_top', $website );
165 + ?>
166 + <?php
167 + /**
168 + * Action: mainwp_non_mainwp_changes_table_top
169 + *
170 + * Fires at the top of the Site Info table in Site Info widget on the Individual site overview page.
171 + *
172 + * @param object $website Object containing the child site info.
173 + *
174 + * @since 4.0
175 + */
176 + do_action( 'mainwp_non_mainwp_changes_table_top', $website );
177 + ?>
178 + <div id="mainwp-non-mainwp-changes-feed">
179 + <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
180 + <?php
181 + MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' );
182 + $this->list_events_table->display();
183 + ?>
184 + </div>
185 + <?php
186 + /**
187 + * Action: mainwp_non_mainwp_changes_table_bottom
188 + *
189 + * Fires at the bottom of the Site Info table in Site Info widget on the Individual site overview page.
190 + *
191 + * @param object $website Object containing the child site info.
192 + *
193 + * @since 4.0
194 + */
195 + do_action( 'mainwp_non_mainwp_changes_table_bottom', $website );
196 + ?>
197 + </div>
198 +
199 + <div class="mainwp-widget-footer">
200 + <div class="ui two columns stackable grid">
201 + <div class="left aligned middle aligned column">
202 + </div>
203 + <div class="right aligned middle aligned column">
204 + <a href="admin.php?page=InsightsManage" class="ui mini basic button"><?php esc_html_e( 'View All Changes', 'mainwp' ); ?></a>
205 + </div>
206 + </div>
207 + </div>
208 + <?php
209 + /**
210 + * Action: mainwp_non_mainwp_changes_widget_bottom
211 + *
212 + * Fires at the bottom of the Site Info widget on the Individual site overview page.
213 + *
214 + * @param object $website Object containing the child site info.
215 + *
216 + * @since 4.0
217 + */
218 + do_action( 'mainwp_non_mainwp_changes_widget_bottom', $website );
219 + }
220 +
221 + /**
222 + * Method load_sites_table()
223 + *
224 + * Load sites table.
225 + */
226 + public function load_events_list_table() {
227 + $manager = Log_Manager::instance();
228 + $this->list_events_table = new Log_Events_List_Table( $manager, $this->table_id_prefix );
229 + }
237 230 }