PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
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 5.2.1 All 155 releases
← All changes | modules/logs/connectors/class-connector-posts.php +170 -183 5.0 → 6.2.2 View file →
@@ -17,207 +17,194 @@
17 17 *
18 18 * @package MainWP\Dashboard
19 19 */
20 20 class Connector_Posts extends Log_Connector {
21 - /**
22 - * Connector slug
23 - *
24 - * @var string
25 - */
26 - public $name = 'posts';
21 + /**
22 + * Connector slug
23 + *
24 + * @var string
25 + */
26 + public $name = 'posts';
27 27
28 - /**
29 - * Actions registered for this connector
30 - *
31 - * @var array
32 - */
33 - public $actions = array(
34 - 'mainwp_post_created',
35 - 'mainwp_post_action',
36 - );
28 + /**
29 + * Actions registered for this connector
30 + *
31 + * @var array
32 + */
33 + public $actions = array(
34 + 'mainwp_post_created',
35 + 'mainwp_post_action',
36 + );
37 37
38 - /**
39 - * Return translated connector label
40 - *
41 - * @return string Translated connector label
42 - */
43 - public function get_label() {
44 - return esc_html__( 'Posts', 'mainwp' );
45 - }
38 + /**
39 + * Return translated connector label
40 + *
41 + * @return string Translated connector label
42 + */
43 + public function get_label() {
44 + return esc_html__( 'Posts', 'mainwp' );
45 + }
46 46
47 - /**
48 - * Return translated action labels
49 - *
50 - * @return array Action label translations
51 - */
52 - public function get_action_labels() {
53 - return array(
54 - 'published' => esc_html__( 'Published', 'mainwp' ),
55 - 'updated' => esc_html__( 'Updated', 'mainwp' ),
56 - 'created' => esc_html__( 'Created', 'mainwp' ),
57 - 'trashed' => esc_html__( 'Trashed', 'mainwp' ),
58 - 'untrashed' => esc_html__( 'Restored', 'mainwp' ),
59 - 'deleted' => esc_html__( 'Deleted', 'mainwp' ),
60 - );
61 - }
47 + /**
48 + * Return translated action labels
49 + *
50 + * @return array Action label translations
51 + */
52 + public function get_action_labels() {
53 + return array(
54 + 'published' => esc_html__( 'Published', 'mainwp' ),
55 + 'updated' => esc_html__( 'Updated', 'mainwp' ),
56 + 'created' => esc_html__( 'Created', 'mainwp' ),
57 + 'trashed' => esc_html__( 'Trashed', 'mainwp' ),
58 + 'untrashed' => esc_html__( 'Restored', 'mainwp' ),
59 + 'deleted' => esc_html__( 'Deleted', 'mainwp' ),
60 + );
61 + }
62 62
63 - /**
64 - * Register log data.
65 - */
66 - public function register() { //phpcs:ignore -- overrided.
67 - parent::register();
68 - }
63 + /**
64 + * Return translated context labels
65 + *
66 + * @return array Context label translations
67 + */
68 + public function get_context_labels() {
69 + global $wp_post_types;
70 + $post_types = wp_filter_object_list( $wp_post_types, array(), null, 'label' );
71 + add_action( 'registered_post_type', array( $this, 'registered_post_type' ), 10, 2 );
72 + return $post_types;
73 + }
69 74
70 - /**
71 - * Return translated context labels
72 - *
73 - * @return array Context label translations
74 - */
75 - public function get_context_labels() {
76 - global $wp_post_types;
77 - $post_types = wp_filter_object_list( $wp_post_types, array(), null, 'label' );
78 - add_action( 'registered_post_type', array( $this, 'registered_post_type' ), 10, 2 );
79 - return $post_types;
80 - }
75 + /**
76 + * Catch registration of post_types after initial loading, to cache its labels
77 + *
78 + * @action registered_post_type
79 + *
80 + * @param string $post_type Post type slug.
81 + * @param array $args Arguments used to register the post type.
82 + */
83 + public function registered_post_type( $post_type, $args ) {
84 + unset( $args );
81 85
82 - /**
83 - * Catch registration of post_types after initial loading, to cache its labels
84 - *
85 - * @action registered_post_type
86 - *
87 - * @param string $post_type Post type slug.
88 - * @param array $args Arguments used to register the post type.
89 - */
90 - public function registered_post_type( $post_type, $args ) {
91 - unset( $args );
86 + $post_type_obj = get_post_type_object( $post_type );
87 + $label = $post_type_obj->label;
92 88
93 - $post_type_obj = get_post_type_object( $post_type );
94 - $label = $post_type_obj->label;
89 + Log_Manager::instance()->connectors->term_labels['logs_context'][ $post_type ] = $label;
90 + }
95 91
96 - Log_Manager::instance()->connectors->term_labels['logs_context'][ $post_type ] = $label;
97 - }
92 + /**
93 + * Log create post.
94 + *
95 + * @action mainwp_post_created
96 + *
97 + * @param mixed $website website.
98 + * @param string $post_action post action.
99 + * @param array $data post data array.
100 + */
101 + public function callback_mainwp_post_created( $website, $post_action, $data ) {
102 + if ( empty( $website ) || ! is_array( $data ) || empty( $data['post_title'] ) ) {
103 + return;
104 + }
105 + $action = '';
106 + if ( 'newpost' === $post_action ) {
107 + $action = 'created';
108 + if ( ! empty( $data['is_editing'] ) ) {
109 + $action = 'updated';
110 + }
111 + }
98 112
99 - /**
100 - * Log create post.
101 - *
102 - * @action mainwp_post_created
103 - *
104 - * @param mixed $website website.
105 - * @param string $post_action post action.
106 - * @param array $data post data array.
107 - */
108 - public function callback_mainwp_post_created( $website, $post_action, $data ) {
109 - if ( empty( $website ) || ! is_array( $data ) || empty( $data['post_title'] ) ) {
110 - return;
111 - }
112 - $action = '';
113 - if ( 'newpost' === $post_action ) {
114 - $action = 'created';
115 - if ( ! empty( $data['is_editing'] ) ) {
116 - $action = 'updated';
117 - }
118 - }
113 + if ( empty( $action ) ) {
114 + return;
115 + }
119 116
120 - if ( empty( $action ) ) {
121 - return;
122 - }
117 + // translators: %1$s: Post title.
118 + $message = esc_html_x(
119 + 'Post: %1$s',
120 + '1: Post title',
121 + 'mainwp'
122 + );
123 123
124 - // translators: Placeholders refer to a post title.
125 - $message = esc_html_x(
126 - '%1$s',
127 - '1: Post title',
128 - 'mainwp'
129 - );
124 + $default = array(
125 + 'post_title' => '',
126 + 'singular_name' => '',
127 + );
128 + $args = MainWP_Utility::right_array_merge( $default, $data );
130 129
131 - $default = array(
132 - 'post_title' => '',
133 - 'singular_name' => '',
134 - );
135 - $args = MainWP_Utility::right_array_merge( $default, $data );
130 + $default_other = array(
131 + 'post_date' => '',
132 + 'post_date_gmt' => '',
133 + 'new_uptime_status' => '',
134 + 'old_status' => '',
135 + 'post_id' => '',
136 + );
137 + $other = MainWP_Utility::right_array_merge( $default_other, $data );
138 + $args['extra_info'] = wp_json_encode( $other );
139 + $state = 1;
140 + $this->log(
141 + $message,
142 + $args,
143 + $website->id,
144 + $data['post_type'],
145 + $action,
146 + $state
147 + );
148 + }
136 149
137 - $default_other = array(
138 - 'post_date' => '',
139 - 'post_date_gmt' => '',
140 - 'new_status' => '',
141 - 'old_status' => '',
142 - 'post_id' => '',
143 - );
144 - $other = MainWP_Utility::right_array_merge( $default_other, $data );
145 - $args['siteurl'] = $website->url;
146 - $args['site_name'] = $website->name;
147 - $args['extra_info'] = wp_json_encode( $other );
148 - $state = 1;
149 - $this->log(
150 - $message,
151 - $args,
152 - $website->id,
153 - $data['post_type'],
154 - $action,
155 - $state
156 - );
157 - }
150 + /**
151 + * Log all post status changes ( creating / updating / trashing )
152 + *
153 + * @action mainwp_post_action
154 + *
155 + * @param object $website website.
156 + * @param string $post_action post action.
157 + * @param array $data post data array.
158 + */
159 + public function callback_mainwp_post_action( $website, $post_action, $data ) {
158 160
159 - /**
160 - * Log all post status changes ( creating / updating / trashing )
161 - *
162 - * @action mainwp_post_action
163 - *
164 - * @param object $website website.
165 - * @param string $post_action post action.
166 - * @param array $data post data array.
167 - * @param int|false $post_id post id.
168 - * @param string $type post|page.
169 - */
170 - public function callback_mainwp_post_action( $website, $post_action, $data, $post_id, $type = '' ) {
161 + if ( empty( $website ) || ! is_array( $data ) || empty( $data['post_title'] ) ) {
162 + return;
163 + }
171 164
172 - if ( empty( $website ) || ! is_array( $data ) || empty( $data['post_title'] ) ) {
173 - return;
174 - }
165 + $action = '';
166 + // translators: %1$s: Post title, %2$s: Post type singular name (e.g. "Hello World", "Post").
167 + $message = esc_html_x(
168 + 'Post: %1$s (%2$s)',
169 + '1: Post title 2: singular name',
170 + 'mainwp'
171 + );
175 172
176 - $action = '';
177 - // translators: Placeholders refer to a post title, and a post type singular name (e.g. "Hello World", "Post").
178 - $message = esc_html_x(
179 - '%1$s',
180 - '1: Post title 2: singular name',
181 - 'mainwp'
182 - );
173 + if ( 'publish' === $post_action ) {
174 + $action = 'published';
175 + } elseif ( 'update' === $post_action ) {
176 + $action = 'updated';
177 + } elseif ( 'unpublish' === $post_action ) {
178 + $action = 'unpublished';
179 + } elseif ( 'trash' === $post_action ) {
180 + $action = 'trashed';
181 + } elseif ( 'delete' === $post_action ) {
182 + $action = 'deleted';
183 + } elseif ( 'restore' === $post_action ) {
184 + $action = 'restored';
185 + } else {
186 + return;
187 + }
183 188
184 - if ( 'publish' === $post_action ) {
185 - $action = 'published';
186 - } elseif ( 'update' === $post_action ) {
187 - $action = 'updated';
188 - } elseif ( 'unpublish' === $post_action ) {
189 - $action = 'unpublished';
190 - } elseif ( 'trash' === $post_action ) {
191 - $action = 'trashed';
192 - } elseif ( 'delete' === $post_action ) {
193 - $action = 'deleted';
194 - } elseif ( 'restore' === $post_action ) {
195 - $action = 'restored';
196 - } else {
197 - return;
198 - }
189 + $default = array(
190 + 'post_title' => '',
191 + 'singular_name' => '',
192 + 'post_date' => '',
193 + 'post_date_gmt' => '',
194 + 'new_uptime_status' => '',
195 + 'old_status' => '',
196 + );
199 197
200 - $default = array(
201 - 'post_title' => '',
202 - 'singular_name' => '',
203 - 'post_date' => '',
204 - 'post_date_gmt' => '',
205 - 'new_status' => '',
206 - 'old_status' => '',
207 - );
198 + $args = MainWP_Utility::right_array_merge( $default, $data );
208 199
209 - $args = MainWP_Utility::right_array_merge( $default, $data );
210 -
211 - $args['siteurl'] = $website->url;
212 - $args['site_name'] = $website->name;
213 - $state = 1;
214 - $this->log(
215 - $message,
216 - $args,
217 - $website->id,
218 - $data['post_type'],
219 - $action,
220 - $state
221 - );
222 - }
200 + $state = 1;
201 + $this->log(
202 + $message,
203 + $args,
204 + $website->id,
205 + $data['post_type'],
206 + $action,
207 + $state
208 + );
209 + }
223 210 }