Skip to content

Commit

Permalink
prepare 1.3.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
slaFFik committed Sep 25, 2020
1 parent 2e52488 commit fba6586
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 163 deletions.
168 changes: 7 additions & 161 deletions bp-default-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://ovirium.com
* Description: Create lots of users, groups, activity items, messages, profile data - useful for BuddyPress testing purpose.
* Author: slaFFik
* Version: 1.3.0
* Version: 1.3.1
* Author URI: https://ovirium.com
* Text Domain: bp-default-data
*/
Expand All @@ -16,57 +16,7 @@

require_once dirname( __FILE__ ) . '/vendor/bemailr/wp-requirements/wpr-loader.php';

define( 'BPDD_VERSION', '1.3.0' );

register_activation_hook( __FILE__, 'bpdd_schedule_ut_request' );
register_deactivation_hook( __FILE__, 'bpdd_unschedule_ut_request' );

/**
* Adds a custom cron schedule for every 5 minutes.
*
* @since 1.3.0
*
* @param array $schedules An array of non-default cron schedules.
*
* @return array Filtered array of non-default cron schedules.
*/
function bpdd_register_weekly_cron_schedule( $schedules ) {

if ( isset( $schedules['weekly'] ) ) {
return $schedules;
}

$schedules['weekly'] = array(
'interval' => WEEK_IN_SECONDS,
'display' => esc_html__( 'Once Weekly', 'bp-default-data' ),
);

return $schedules;
}

add_filter( 'cron_schedules', 'bpdd_register_weekly_cron_schedule' );

/**
* Maybe schedule a request.
*
* @since 1.3.0
*/
function bpdd_schedule_ut_request() {

if ( ! wp_next_scheduled( 'bpdd_ut_weekly_request' ) ) {
wp_schedule_event( time() + wp_rand( 0, DAY_IN_SECONDS ), 'weekly', 'bpdd_ut_weekly_request' );
}
}

/**
* Unschedule the request.
*
* @since 1.3.0
*/
function bpdd_unschedule_ut_request() {

wp_clear_scheduled_hook( 'bpdd_ut_weekly_request' );
}
define( 'BPDD_VERSION', '1.3.1' );

/**
* Load the plugin admin area registration hook.
Expand All @@ -81,8 +31,6 @@ function bpdd_init() {

add_action( bp_core_admin_hook(), 'bpdd_admin_page', 99 );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'bpdd_plugins_settings_link' );

bpdd_schedule_ut_request();
}

add_action( 'bp_loaded', 'bpdd_init' );
Expand Down Expand Up @@ -128,6 +76,11 @@ function bpdd_admin_page() {
'bpdd-setup',
'bpdd_admin_page_content'
);

if ( wp_next_scheduled( 'bpdd_ut_weekly_request' ) ) {
wp_clear_scheduled_hook( 'bpdd_ut_weekly_request' );
bp_delete_option( 'bpdd_usage_tracking_enabled' );
}
}

/**
Expand Down Expand Up @@ -435,20 +388,6 @@ function bpdd_admin_page_content() {
value="<?php esc_attr_e( 'Clear BuddyPress Data', 'bp-default-data' ); ?>" />
</p>

<fieldset style="border: 2px solid #ccc;padding: 0 10px;margin-bottom: 10px">
<legend style="font-weight: bold;"><?php esc_html_e( 'Usage Tracking', 'bp-default-data' ); ?></legend>
<p><?php esc_html_e( 'I want to better understand how people are using this plugin, and for this I need some additional information from you.', 'bp-default-data' ); ?></p>
<p><?php esc_html_e( 'Please allow me to collect this information on weekly basis: PHP version, WordPress version, BuddyPress version, list of activated BuddyPress components and its template pack, whether cover image uploads enabled for members and groups, list of selected imported data groups.', 'bp-default-data' ); ?></p>
<?php if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) : ?>
<p><code><?php echo wp_json_encode( bpdd_ut_request_data() ); ?></code></p>
<?php endif; ?>
<p>
<label>
<input type="checkbox" id="usage-tracking" <?php checked( true, (bool) bp_get_option( 'bpdd_usage_tracking_enabled', false ) ); ?>> <?php esc_html_e( 'Allow sending the data listed above, and only that, once a week.', 'bp-default-data' ); ?>
</label>
</p>
</fieldset>

<p class="description">
Many thanks to <a href="https://imdb.com" target="_blank" rel="noopener noreferrer">IMDB.com</a> for movie titles (groups names),
<a href="https://en.wikipedia.org" target="_blank" rel="noopener noreferrer">Wikipedia.org</a> (users names),
Expand All @@ -466,96 +405,3 @@ function bpdd_admin_page_content() {
</div><!-- .wrap -->
<?php
}

/**
* AJAX: enable or disable the usage tracking status.
*
* @since 1.3.0
*/
function bpdd_ajax_usage_tracking_toggle() {

if ( ! is_super_admin() ) {
wp_send_json_error();
}

$status = (bool) bp_get_option( 'bpdd_usage_tracking_enabled', false );

bp_update_option( 'bpdd_usage_tracking_enabled', ! $status );

wp_send_json_success();
}

add_action( 'wp_ajax_bpdd_ajax_usage_tracking_toggle', 'bpdd_ajax_usage_tracking_toggle' );

/**
* Send a usage tracking request, if allowed.
*
* @since 1.3.0
*/
function bpdd_send_ut_request() {

// Whether we were granted a permission.
if ( ! ( (bool) bp_get_option( 'bpdd_usage_tracking_enabled', false ) ) ) {
return;
}

// Perform a non-blocking request.
wp_remote_post(
'https://api.ut.ovirium.com/track',
array(
'method' => 'POST',
'timeout' => 5,
'redirection' => 5,
'httpversion' => '1.1',
'blocking' => false,
'headers' => array(
'Content-Type' => 'application/x-www-form-urlencoded',
'API-KEY' => 'CDc6K8LemniOWIYLyZQUQKmEQwgLDKj6eY4BdUQVzq03UChCjqEXrvC5zDms',
),
'body' => bpdd_ut_request_data(),
)
);
}

add_action( 'bpdd_ut_weekly_request', 'bpdd_send_ut_request' );

/**
* All the data the is sent via request.
*
* @since 1.3.0
*
* @return array
*/
function bpdd_ut_request_data() {

return array(
'php_version' => implode( '.', array( PHP_MAJOR_VERSION, PHP_MINOR_VERSION ) ),
'wp_version' => $GLOBALS['wp_version'],
'bp_version' => bp_get_version(),
'bp_components' => array_keys( buddypress()->active_components ),
'bp_template_pack' => bp_get_theme_compat_name(),
'bp_covers_users' => ! bp_disable_cover_image_uploads() ? 'enabled' : 'disabled',
'bp_covers_groups' => ! bp_disable_group_cover_image_uploads() ? 'enabled' : 'disabled',
'bpdd_selected_imports' => array_filter(
array_map(
function ( $group_import ) {

list( $group, $import ) = explode( '_', $group_import );

return bpdd_is_imported( $group, $import ) ? $group_import : false;
},
array(
'users_users',
'users_xprofile',
'users_friends',
'users_activity',
'users_messages',
'groups_groups',
'groups_members',
'groups_activity',
'groups_forum',
)
)
),
);
}
8 changes: 6 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: slaFFik
Tags: buddypress, import, bulk import, demo data, members, groups, messages, activity, forums, friends
Requires at least: 4.4
Tested up to: 5.4
Stable tag: 1.3.0
Tested up to: 5.5
Stable tag: 1.3.1
Requires PHP: 5.3
License: GNU General Public License v2.0 or later

Expand Down Expand Up @@ -49,6 +49,10 @@ That's it!

== Changelog ==

= 1.3.1 (25.09.2020) =
* Checked compatibility with BuddyPress 6.x.
* Removed usage tracking.

= 1.3.0 (29.03.2020) =
* Checked and fixed compatibility with BuddyPress 5.x.
* Fixed several PHP catchable fatal errors, warnings and notices in importing logic.
Expand Down

0 comments on commit fba6586

Please sign in to comment.