Skip to content

Commit beb4619

Browse files
dev: trigger activity log on deactivation
1 parent 3beba08 commit beb4619

3 files changed

Lines changed: 79 additions & 54 deletions

File tree

includes/abstract/feedzy-rss-feeds-admin-abstract.php

Lines changed: 63 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,49 @@ public function get_usage_data( $data ) {
8686
$categories = count( $terms );
8787
}
8888
// imports.
89-
$imports = array();
9089
$license = 'free';
90+
91+
$imports = apply_filters(
92+
'feedzy_usage_data',
93+
array(
94+
// how many active imports are created.
95+
'publish' => count(
96+
get_posts(
97+
array(
98+
'post_type' => 'feedzy_imports',
99+
'post_status' => 'publish',
100+
'numberposts' => 99,
101+
'fields' => 'ids',
102+
)
103+
)
104+
),
105+
// how many draft imports are created.
106+
'draft' => count(
107+
get_posts(
108+
array(
109+
'post_type' => 'feedzy_imports',
110+
'post_status' => 'draft',
111+
'numberposts' => 99,
112+
'fields' => 'ids',
113+
)
114+
)
115+
),
116+
// how many posts were imported by the imports.
117+
'imported' => count(
118+
get_posts(
119+
array(
120+
'post_type' => 'post',
121+
'post_status' => array( 'publish', 'private', 'draft', 'trash' ),
122+
'numberposts' => 2999, //phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_numberposts
123+
'fields' => 'ids',
124+
'meta_key' => 'feedzy', //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
125+
'meta_value' => 1, //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
126+
)
127+
)
128+
),
129+
)
130+
);
131+
91132
if ( feedzy_is_pro() ) {
92133
$license = 'pro';
93134
if ( apply_filters( 'feedzy_is_license_of_type', false, 'agency' ) ) {
@@ -107,70 +148,40 @@ public function get_usage_data( $data ) {
107148
}
108149
}
109150

110-
$imports = apply_filters(
111-
'feedzy_usage_data',
112-
array(
113-
// how many active imports are created.
114-
'publish' => count(
115-
get_posts(
116-
array(
117-
'post_type' => 'feedzy_imports',
118-
'post_status' => 'publish',
119-
'numberposts' => 99,
120-
'fields' => 'ids',
121-
)
122-
)
123-
),
124-
// how many draft imports are created
125-
'draft' => count(
126-
get_posts(
127-
array(
128-
'post_type' => 'feedzy_imports',
129-
'post_status' => 'draft',
130-
'numberposts' => 99,
131-
'fields' => 'ids',
132-
)
133-
)
134-
),
135-
// how many posts were imported by the imports
136-
'imported' => count(
137-
get_posts(
138-
array(
139-
'post_type' => 'post',
140-
'post_status' => array( 'publish', 'private', 'draft', 'trash' ),
141-
'numberposts' => 2999, //phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_numberposts
142-
'fields' => 'ids',
143-
'meta_key' => 'feedzy', //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
144-
'meta_value' => 1, //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
145-
)
146-
)
147-
),
148-
// integrations
149-
'integrations' => $integrations,
150-
)
151-
);
152-
153-
$imports = wp_parse_args( Feedzy_Rss_Feeds_Usage::get_instance()->get_usage_data(), $imports );
151+
$imports['integrations'] = $integrations;
154152
}
155153

156-
$settings = apply_filters( 'feedzy_get_settings', null );
157-
$config = array();
154+
$imports = wp_parse_args( Feedzy_Rss_Feeds_Usage::get_instance()->get_usage_data(), $imports );
155+
156+
$settings = apply_filters( 'feedzy_get_settings', null );
157+
$general_settings = array();
158+
$config = array();
159+
158160
if ( $settings ) {
159161
$proxy = isset( $settings['proxy'] ) && is_array( $settings['proxy'] ) && ! empty( $settings['proxy'] ) ? array_filter( $settings['proxy'] ) : array();
160162
if ( ! empty( $proxy ) ) {
161163
$config[] = 'proxy';
162164
}
165+
166+
if ( isset( $settings['header'], $settings['header']['user-agent'] ) && ! empty( $settings['header']['user-agent'] ) ) {
167+
$config[] = 'custom-user-agent';
168+
}
169+
170+
if ( is_array( $settings['general'] ) && ! empty( $settings['general'] ) ) {
171+
$general_settings = $settings['general'];
172+
}
163173
}
164174

165175
// how many posts contain the shortcode
166176
global $wpdb;
167177
$shortcodes = $wpdb->get_var( "SELECT count(*) FROM {$wpdb->prefix}posts WHERE post_status IN ('publish', 'private') AND post_content LIKE '%[feedzy-rss %'" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
168178
$data = array(
169-
'categories' => $categories,
170-
'imports' => $imports,
171-
'shortcodes' => $shortcodes,
172-
'license' => $license,
173-
'config' => $config,
179+
'categories' => $categories,
180+
'imports' => $imports,
181+
'shortcodes' => $shortcodes,
182+
'license' => $license,
183+
'config' => $config,
184+
'general_settings' => $general_settings
174185
);
175186

176187
return $data;

includes/admin/feedzy-rss-feeds-usage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class Feedzy_Rss_Feeds_Usage {
3636
* @var array
3737
*/
3838
private $default_data = array(
39-
'first_import_run_datetime' => null,
39+
'first_import_run_datetime' => '',
4040
'imports_runs' => 0,
41-
'first_import_created_datetime' => null,
41+
'first_import_created_datetime' => '',
4242
);
4343

4444
/**

includes/feedzy-rss-feeds-deactivator.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ class Feedzy_Rss_Feeds_Deactivator {
3030
* @access public
3131
*/
3232
public static function deactivate() {
33+
self::try_send_logs();
3334
delete_option( 'feedzy-activated' );
3435
}
36+
37+
/**
38+
* Send the logs with the plugin usage if telemetry is active.
39+
*
40+
* @return void
41+
*/
42+
public static function try_send_logs() {
43+
if ( 'yes' !== get_option( 'feedzy_rss_feeds_logger_flag' ) ) {
44+
return;
45+
}
46+
47+
do_action( 'feedzy_rss_feeds_log_activity' );
48+
}
3549
}

0 commit comments

Comments
 (0)