Skip to content

Commit

Permalink
Merge pull request #2593 from Automattic/add/usage-tracking-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
gikaragia authored Oct 4, 2023
2 parents 4b858ce + ca6bc66 commit 7749db6
Show file tree
Hide file tree
Showing 21 changed files with 132 additions and 106 deletions.
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# .git-blame-ignore-revs
# Re-format PHP files with PHPCBF
2dc64b85a9a640f4fa1878f4c2e2a1b34c85f432

3 changes: 3 additions & 0 deletions includes/admin/class-wp-job-manager-cpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ public function sortable_columns( $columns ) {
* @return array
*/
public function sort_columns( $vars ) {
// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Query used in admin only.
if ( isset( $vars['orderby'] ) ) {
if ( 'job_expires' === $vars['orderby'] ) {
$vars = array_merge(
Expand All @@ -719,6 +720,8 @@ public function sort_columns( $vars ) {
);
}
}
// phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_key

return $vars;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/admin/class-wp-job-manager-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function setup_page() {
}

// Handle step 2 -> step 3 (setting up pages).
if ( 3 === $step && ! empty( $_POST ) ) {
if ( 3 === $step && ! empty( $_POST ) && empty( $_POST['skip-setup'] ) ) {
if (
! isset( $_REQUEST['setup_wizard'] )
|| false === wp_verify_nonce( wp_unslash( $_REQUEST['setup_wizard'] ), 'step_3' ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce should not be modified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<input
type="checkbox"
name="job_manager_usage_tracking_enabled"
value="1" />
value="1"
checked="checked" />
<?php
echo wp_kses(
$this->opt_in_text(),
Expand Down
10 changes: 6 additions & 4 deletions includes/admin/views/html-admin-setup-step-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
<p>
<?php
// translators: Placeholder %s is the path to WPJM documentation site.
echo wp_kses_post( sprintf( __( 'If you\'d prefer to skip this and set up your pages manually, our <a href="%s">documentation</a> will walk you through each step.', 'wp-job-manager' ), 'https://wpjobmanager.com/documentation/' ) );
echo wp_kses_post( sprintf( __( 'If you\'d prefer to skip this and set up your pages manually, our <a target="_blank" href="%s">documentation</a> will walk you through each step.', 'wp-job-manager' ), 'https://wpjobmanager.com/documentation/' ) );
?>
</p>

<form method="post" action="<?php echo esc_url( add_query_arg( 'step', 2 ) ); ?>">
<form method="post">
<input type="hidden" name="nonce" value="<?php echo esc_attr( wp_create_nonce( 'enable-usage-tracking' ) ); ?>" />

<?php $this->maybe_output_opt_in_checkbox(); ?>

<p class="submit">
<input type="submit" value="<?php esc_html_e( 'Start setup', 'wp-job-manager' ); ?>" class="button button-primary" />
<a href="<?php echo esc_url( add_query_arg( 'skip-job-manager-setup', 1, admin_url( 'index.php?page=job-manager-setup&step=3' ) ) ); ?>" class="button"><?php esc_html_e( 'Skip setup. I will set up the plugin manually.', 'wp-job-manager' ); ?></a>
<input type="submit" name="start-setup" value="<?php esc_html_e( 'Start setup', 'wp-job-manager' ); ?>" class="button button-primary" formaction="<?php echo esc_url( add_query_arg( 'step', 2 ) ); ?>" />

<input type="submit" name="skip-setup" value="<?php esc_html_e( 'Save and skip setup', 'wp-job-manager' ); ?>" class="button" formaction="<?php echo esc_url( add_query_arg( 'step', 3 ) ); ?>">

</p>
</form>
5 changes: 3 additions & 2 deletions includes/class-wp-job-manager-data-cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class WP_Job_Manager_Data_Cleaner {
'job_manager_promoted_jobs_status_update_last_check',
'job_manager_promoted_jobs_webhook_interval',
'job_manager_promoted_jobs_cron_interval',
'job_manager_display_usage_tracking_once',
];

/**
Expand Down Expand Up @@ -380,9 +381,9 @@ private static function cleanup_user_meta() {
global $wpdb;

foreach ( self::$user_meta_keys as $meta_key ) {
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery -- Delete data across all users.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Delete data across all users.
$wpdb->delete( $wpdb->usermeta, [ 'meta_key' => $meta_key ] );
// phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery
// phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.SlowDBQuery.slow_db_query_meta_key
}
}

Expand Down
12 changes: 6 additions & 6 deletions includes/class-wp-job-manager-dependency-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class WP_Job_Manager_Dependency_Checker {
*/
public static function check_dependencies() {
if ( ! self::check_php() ) {
add_action( 'admin_notices', array( 'WP_Job_Manager_Dependency_Checker', 'add_php_notice' ) );
add_action( 'admin_init', array( __CLASS__, 'deactivate_self' ) );
add_action( 'admin_notices', [ 'WP_Job_Manager_Dependency_Checker', 'add_php_notice' ] );
add_action( 'admin_init', [ __CLASS__, 'deactivate_self' ] );

return false;
}

if ( ! self::check_wp() ) {
add_action( 'admin_notices', array( 'WP_Job_Manager_Dependency_Checker', 'add_wp_notice' ) );
add_filter( 'plugin_action_links_' . JOB_MANAGER_PLUGIN_BASENAME, array( 'WP_Job_Manager_Dependency_Checker', 'wp_version_plugin_action_notice' ) );
add_action( 'admin_notices', [ 'WP_Job_Manager_Dependency_Checker', 'add_wp_notice' ] );
add_filter( 'plugin_action_links_' . JOB_MANAGER_PLUGIN_BASENAME, [ 'WP_Job_Manager_Dependency_Checker', 'wp_version_plugin_action_notice' ] );
}

return true;
Expand Down Expand Up @@ -66,7 +66,7 @@ public static function add_php_notice() {
$message = sprintf( __( '<strong>WP Job Manager</strong> requires a minimum PHP version of %1$s, but you are running %2$s.', 'wp-job-manager' ), self::MINIMUM_PHP_VERSION, phpversion() );

echo '<div class="error"><p>';
echo wp_kses( $message, array( 'strong' => array() ) );
echo wp_kses( $message, [ 'strong' => [] ] );
$php_update_url = 'https://wordpress.org/support/update-php/';
if ( function_exists( 'wp_get_update_php_url' ) ) {
$php_update_url = wp_get_update_php_url();
Expand Down Expand Up @@ -146,6 +146,6 @@ public static function wp_version_plugin_action_notice( $actions ) {
* @return array
*/
private static function get_critical_screen_ids() {
return array( 'dashboard', 'plugins', 'plugins-network', 'edit-job_listing', 'job_listing_page_job-manager-settings' );
return [ 'dashboard', 'plugins', 'plugins-network', 'edit-job_listing', 'job_listing_page_job-manager-settings' ];
}
}
2 changes: 1 addition & 1 deletion includes/class-wp-job-manager-email-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ private static function send_expiring_notice( $email_notification_key, $days_not
'post_status' => 'publish',
'fields' => 'ids',
'posts_per_page' => -1,
'meta_query' => [
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Used in production with no issues.
[
'key' => '_job_expires',
'value' => $notice_before_datetime->format( 'Y-m-d' ),
Expand Down
8 changes: 8 additions & 0 deletions includes/class-wp-job-manager-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public static function install() {
$is_new_install = true;
}

require_once __DIR__ . '/../lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php';

// On new installs display the usage tracking notice with one week delay and for existing installs display it right away.
if ( false === get_option( WP_Job_Manager_Usage_Tracking_Base::DISPLAY_ONCE_OPTION ) ) {
$time_to_show_notice = $is_new_install ? time() + WEEK_IN_SECONDS : time() - 10;
update_option( WP_Job_Manager_Usage_Tracking_Base::DISPLAY_ONCE_OPTION, $time_to_show_notice );
}

// Update featured posts ordering.
if ( version_compare( get_option( 'wp_job_manager_version', JOB_MANAGER_VERSION ), '1.22.0', '<' ) ) {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- One time data update.
Expand Down
8 changes: 4 additions & 4 deletions includes/class-wp-job-manager-post-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ public function job_feed() {
'ignore_sticky_posts' => 1,
'posts_per_page' => $input_posts_per_page,
'paged' => absint( get_query_var( 'paged', 1 ) ),
'tax_query' => [],
'meta_query' => [],
'tax_query' => [], // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Empty.
'meta_query' => [], // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Empty.
];

if ( ! empty( $input_search_location ) ) {
Expand Down Expand Up @@ -739,7 +739,7 @@ public function check_for_expired_jobs() {
'post_status' => 'publish',
'fields' => 'ids',
'posts_per_page' => -1,
'meta_query' => [
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Used in production with no issues.
'relation' => 'AND',
[
'key' => '_job_expires',
Expand Down Expand Up @@ -1370,7 +1370,7 @@ public function sitemaps_maybe_hide_filled( $query_args, $post_type ) {
}

if ( ! isset( $query_args['meta_query'] ) ) {
$query_args['meta_query'] = [];
$query_args['meta_query'] = []; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Empty.
}

$query_args['meta_query'][] = [
Expand Down
1 change: 1 addition & 0 deletions includes/class-wp-job-manager-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ public function output_job_summary( $atts ) {
$args['posts_per_page'] = $atts['limit'];
$args['orderby'] = 'rand';
if ( ! is_null( $atts['featured'] ) ) {
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Query results are limited.
$args['meta_query'] = [
[
'key' => '_featured',
Expand Down
10 changes: 5 additions & 5 deletions includes/class-wp-job-manager-usage-tracking-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private static function get_jobs_by_type_count( $job_type ) {
'post_type' => 'job_listing',
'post_status' => [ 'expired', 'publish' ],
'fields' => 'ids',
'tax_query' => [
'tax_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Used in production with no issues.
[
'field' => 'slug',
'taxonomy' => 'job_listing_type',
Expand All @@ -217,7 +217,7 @@ private static function get_company_logo_count() {
'post_type' => 'job_listing',
'post_status' => [ 'expired', 'publish' ],
'fields' => 'ids',
'meta_query' => [
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Used in production with no issues.
[
'key' => '_thumbnail_id',
'compare' => 'EXISTS',
Expand All @@ -242,7 +242,7 @@ private static function get_job_type_count() {
'post_type' => 'job_listing',
'post_status' => [ 'expired', 'publish' ],
'fields' => 'ids',
'tax_query' => [
'tax_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Used in production with no issues.
[
'taxonomy' => 'job_listing_type',
'operator' => 'EXISTS',
Expand All @@ -267,7 +267,7 @@ private static function get_jobs_count_with_meta( $meta_key ) {
'post_type' => 'job_listing',
'post_status' => [ 'publish', 'expired' ],
'fields' => 'ids',
'meta_query' => [
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Used in production with no issues.
[
'key' => $meta_key,
'value' => '[^[:space:]]',
Expand All @@ -294,7 +294,7 @@ private static function get_jobs_count_with_checked_meta( $meta_key ) {
'post_type' => 'job_listing',
'post_status' => [ 'publish', 'expired' ],
'fields' => 'ids',
'meta_query' => [
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Used in production with no issues.
[
'key' => $meta_key,
'value' => '1',
Expand Down
10 changes: 6 additions & 4 deletions includes/class-wp-job-manager-usage-tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
exit;
}

require dirname( __FILE__ ) . '/../lib/usage-tracking/class-usage-tracking-base.php';
require_once __DIR__ . '/../lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php';

/**
* WPJM Usage Tracking subclass.
Expand Down Expand Up @@ -182,7 +182,9 @@ protected function get_event_prefix() {
}

/**
* Get the text domain used in the plugin.
* Get the text domain used in the plugin. Deprecated - use 'wp-job-manager' directly.
*
* @deprecated $$next-version$$
*
* @return string
*/
Expand Down Expand Up @@ -227,7 +229,7 @@ protected function opt_in_dialog_text() {
// translators: Placeholder %s is a URL to the document on wpjobmanager.com with info on usage tracking.
__(
'We\'d love if you helped us make WP Job Manager better by allowing us to collect
<a href="%s">usage tracking data</a>. No sensitive information is
<a target="_blank" href="%s">usage tracking data</a>. No sensitive information is
collected, and you can opt out at any time.',
'wp-job-manager'
),
Expand Down Expand Up @@ -266,7 +268,7 @@ public function opt_in_checkbox_text() {
// translators: the href tag contains the URL for the page telling users what data WPJM tracks.
__(
'Help us make WP Job Manager better by allowing us to collect
<a href="%s">usage tracking data</a>.
<a target="_blank" href="%s">usage tracking data</a>.
No sensitive information is collected.',
'wp-job-manager'
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function get_items() {
'no_found_rows' => true,
'ignore_sticky_posts' => true,
'posts_per_page' => -1,
'meta_query' => [
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Returns promoted jobs only which should be a small number.
[
'key' => WP_Job_Manager_Promoted_Jobs::PROMOTED_META_KEY,
'compare' => 'EXISTS',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public static function query_promoted_jobs_count( $args = [] ) {
'post_status' => 'any',
'posts_per_page' => 1,
'fields' => 'ids',
'meta_query' => [
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Returns promoted jobs only which should be a small number.
[
'key' => self::PROMOTED_META_KEY,
'value' => '1',
Expand Down
Loading

0 comments on commit 7749db6

Please sign in to comment.