Skip to content

Commit

Permalink
Merge pull request #93 from mundschenk-at/misc-cleanups
Browse files Browse the repository at this point in the history
Various minor fixes
  • Loading branch information
mundschenk-at authored Apr 14, 2019
2 parents 91a4006 + 13c11ce commit 7506b18
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 29 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 2.1.0 (2019-04-14)
* _Feature_: Improved compatibility with multisite installations. Plugin data will
be properly deleted on uninstallation or when a site is removed. ("Large Networks"
will still have to take manual action to prevent timeouts.)
* _Feature_: Network settings for enabling/disabling global table use on multisite.
Existing global data will be migrated to the site-specific tables when global
table use is disabled (but not in the other direction).
* _Change_: `usermeta` keys are now prefixed (`avatar_privacy_use_gravatar`
instead of `use_gravatar`).
* _Change_: Generally improved code quality through unit tests.
* _Bugfix_: New multisite installations were incorrectly detected as "legacy",
making them use the global table (instead of per-site tables). Affected installations
can be switched via the new network settings page.

## 2.0.5 (2019-02-23)
* _Bugfix_: Fixed a previously undiscovered compatibility issue with recent versions of EWWW Image Optimizer.

Expand Down
4 changes: 2 additions & 2 deletions admin/partials/network/settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of Avatar Privacy.
*
* Copyright 2018 Peter Putzer.
* Copyright 2018-2019 Peter Putzer.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -27,7 +27,7 @@
use Avatar_Privacy\Data_Storage\Network_Options;

?><div class='wrap'>
<h1><?php \esc_html_e( 'Avatar Privacy Settings', 'avatar-privacy' ); ?></h1>
<h1><?php \esc_html_e( 'Avatar Privacy Network Settings', 'avatar-privacy' ); ?></h1>

<form method="post" action="<?php echo \esc_url( 'edit.php?action=' . self::ACTION ); ?>">
<?php \settings_fields( self::OPTION_GROUP ); ?>
Expand Down
2 changes: 1 addition & 1 deletion avatar-privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Description: Adds options to enhance the privacy when using avatars.
* Author: Peter Putzer
* Author URI: https://code.mundschenk.at
* Version: 2.1.0-alpha.3
* Version: 2.1.0
* License: GNU General Public License v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: avatar-privacy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function run() {
*/
public function register_network_settings() {
// Create our options page.
$page = \add_submenu_page( 'settings.php', \__( 'My Network Options', 'avatar-privacy' ), \__( 'Avatar Privacy', 'avatar-privacy' ), 'manage_network_options', self::OPTION_GROUP, [ $this, 'print_settings_page' ] );
$page = \add_submenu_page( 'settings.php', \__( 'Avatar Privacy Network Settings', 'avatar-privacy' ), \__( 'Avatar Privacy', 'avatar-privacy' ), 'manage_network_options', self::OPTION_GROUP, [ $this, 'print_settings_page' ] );

// Add the section(s).
\add_settings_section( self::SECTION, '', [ $this, 'print_settings_section' ], self::OPTION_GROUP );
Expand Down Expand Up @@ -190,7 +190,7 @@ public function print_settings_page() {
public function save_network_settings() {
// Check if the user has the correct permissions.
if ( ! \current_user_can( 'manage_network_options' ) ) {
\wp_die( \esc_html( \__( 'Sorry, you are not allowed to edit network options.', 'avatar-privacy' ) ), 403 );
\wp_die( \esc_html( \__( 'Sorry, you are not allowed to access this page.', 'avatar-privacy' ) ), 403 );
}

// Make sure we are posting from our options page.
Expand Down Expand Up @@ -218,7 +218,7 @@ public function save_network_settings() {

$settings_errors = \get_settings_errors();
if ( empty( $settings_errors ) ) {
\add_settings_error( self::OPTION_GROUP, 'settings_updated', \__( 'Settings updated.', 'avatar-privacy' ), 'updated' );
\add_settings_error( self::OPTION_GROUP, 'settings_updated', \__( 'Settings saved.', 'avatar-privacy' ), 'updated' );
}

// Save the settings errors until after the redirect.
Expand Down Expand Up @@ -327,7 +327,7 @@ public function start_migration_from_global_table( $option, $value, $old_value )
$this->network_options->set( Network_Options::START_GLOBAL_TABLE_MIGRATION, $queue );

// Notify admins.
$this->trigger_admin_notice( Network_Options::USE_GLOBAL_TABLE, 'settings_updated', \__( 'Settings updated. Consent data will be migrated to site-specific tables.', 'avatar-privacy' ), 'updated' );
$this->trigger_admin_notice( Network_Options::USE_GLOBAL_TABLE, 'settings_updated', \__( 'Settings saved. Consent data will be migrated to site-specific tables.', 'avatar-privacy' ), 'updated' );
} elseif ( ! empty( $value ) && empty( $old_value ) ) {
// Clean up any running migrations on the next page load.
$this->network_options->set( Network_Options::START_GLOBAL_TABLE_MIGRATION, [] );
Expand Down
5 changes: 0 additions & 5 deletions includes/avatar-privacy/components/class-privacy-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ public function admin_init() {
* @since 2.1.0 Visibility changed to protected.
*/
protected function add_privacy_notice_content() {
// Don't crash on older versions of WordPress.
if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
return;
}

$suggested_text = '<strong class="privacy-policy-tutorial">' . __( 'Suggested text:' ) . ' </strong>'; // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Missing text domain is intentional to use Core translation.

$content = '<h3>' . __( 'Comments', 'avatar-privacy' ) . '</h3>';
Expand Down
2 changes: 1 addition & 1 deletion includes/avatar-privacy/components/class-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public function prefix_usermeta_keys() {

if ( \count( $affected_users ) > 0 ) {
// Update the database table.
$rows = $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->usermeta} SET meta_key = %s WHERE meta_key = %s", Core::GRAVATAR_USE_META_KEY, 'use_gravatar' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
$rows = $wpdb->update( $wpdb->usermeta, [ 'meta_key' => Core::GRAVATAR_USE_META_KEY ], [ 'meta_key' => 'use_gravatar' ] ); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching

// If there were any keys to update, we also have to clear the user_meta cache group.
if ( false !== $rows && $rows > 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- Set a description for this ruleset. -->
<description>A custom set of code standard rules to check for WordPress plugins.</description>

<config name="minimum_supported_wp_version" value="4.9"/>
<config name="minimum_supported_wp_version" value="5.1"/>
<config name="testVersion" value="5.6-"/>

<!-- Include the WordPress ruleset, with exclusions. -->
Expand Down
13 changes: 10 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Plugin Name: Avatar Privacy
Plugin URI: https://code.mundschenk.at/avatar-privacy/
Author URI: https://code.mundschenk.at/
Tags: gravatar, avatar, privacy, caching, bbpress
Requires at least: 4.9
Requires at least: 5.1
Requires PHP: 5.6
Tested up to: 5.1
Stable tag: 2.0.5
Tested up to: 5.2
Stable tag: 2.1.0
License: GPLv2 or later

Enhances the privacy of your users and visitors with gravatar opt-in and local avatars.
Expand Down Expand Up @@ -134,6 +134,13 @@ The default avatar image is set to the mystery man if you selected one of the ne

== Changelog ==

= 2.1.0 (2019-04-14) =
* _Feature_: Improved compatibility with multisite installations. Plugin data will be properly deleted on uninstallation or when a site is removed. ("Large Networks" will still have to take manual action to prevent timeouts.)
* _Feature_: Network settings for enabling/disabling global table use on multisite. Existing global data will be migrated to the site-specific tables when global table use is disabled (but not in the other direction).
* _Change_: `usermeta` keys are now prefixed (`avatar_privacy_use_gravatar` instead of `use_gravatar`).
* _Change_: Generally improved code quality through unit tests.
* _Bugfix_: New multisite installations were incorrectly detected as "legacy", making them use the global table (instead of per-site tables). Affected installations can be switched via the new network settings page.

= 2.0.5 (2019-02-23) =
* _Bugfix_: Fixed a previously undiscovered compatibility issue with recent versions of EWWW Image Optimizer.

Expand Down
10 changes: 0 additions & 10 deletions tests/avatar-privacy/components/class-privacy-tools-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,6 @@ public function test_admin_init() {
$this->assertNull( $this->sut->admin_init() );
}

/**
* Tests ::add_privacy_notice_content.
*
* @covers ::add_privacy_notice_content
*/
public function test_add_privacy_notice_content_old_wordpress() {
// No expectation so that the function does not exist.
$this->assertNull( $this->sut->add_privacy_notice_content() );
}

/**
* Tests ::add_privacy_notice_content.
*
Expand Down
3 changes: 1 addition & 2 deletions tests/avatar-privacy/components/class-setup-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,7 @@ public function test_prefix_usermeta_keys() {
// Update meta keys.
$wpdb->shouldReceive( 'prepare' )->once()->with( "SELECT DISTINCT user_id FROM {$wpdb->usermeta} WHERE meta_key = %s", 'use_gravatar' )->andReturn( 'select_query' );
$wpdb->shouldReceive( 'get_col' )->once()->with( 'select_query' )->andReturn( $user_ids );
$wpdb->shouldReceive( 'prepare' )->once()->with( "UPDATE {$wpdb->usermeta} SET meta_key = %s WHERE meta_key = %s", Core::GRAVATAR_USE_META_KEY, 'use_gravatar' )->andReturn( 'update_query' );
$wpdb->shouldReceive( 'query' )->once()->with( 'update_query' )->andReturn( $rows );
$wpdb->shouldReceive( 'update' )->once()->with( $wpdb->usermeta, [ 'meta_key' => Core::GRAVATAR_USE_META_KEY ], [ 'meta_key' => 'use_gravatar' ] )->andReturn( $rows ); // phpcs:ignore WordPress.DB.SlowDBQuery

// Clear cache.
Functions\expect( 'wp_cache_delete' )->times( $rows )->with( m::type( 'int' ), 'user_meta' );
Expand Down

0 comments on commit 7506b18

Please sign in to comment.