LICENSE, clean uninstall (opt-in data removal), privacy policy text, Update URI header
Test and Release / test (push) Successful in 1m28s
Test and Release / release (push) Successful in 4s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-15 14:00:04 -08:00
1 parent fb200594ce
commit 68bd917660
11 files changed
+669 -1

No files matched your search

+339
View File
@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
+9
View File
@@ -106,3 +106,12 @@ vendor/bin/phpunit
```
Architecture notes are in `docs/ARCHITECTURE.md`. Every push to `main` runs the tests and, if they pass,
publishes a versioned zip release via Gitea Actions.
## License
StreamGoals Donate is free software, released under the GNU General Public License, version 2 or (at your option)
any later version (GPL-2.0-or-later). See the `LICENSE` file for the full text.
## Uninstalling
Deleting the plugin from the Plugins screen always removes its scheduled task and cached data. Your donations, goals,
rules, rewards, alerts, tiers and settings are kept unless you first tick "Delete all data when the plugin is deleted"
in StreamGoals > Settings > Advanced (off by default; deleting cannot be undone).
+4 -1
View File
@@ -59,7 +59,9 @@ final class SettingsPage {
}
echo '</select><p class="description">Donation forms limit how fast one visitor can start payments (to stop abuse). Behind a proxy, every visitor can look like the same address, and a busy moment, like a raid, could block donations. <strong>Automatic</strong> recognises Cloudflare by its published addresses and counts each visitor separately; it ignores forged headers from anywhere else. For another kind of proxy, choose its option here, but only if <em>all</em> traffic to your site really goes through it.</p>';
self::ipDiagnostics( (string) $s['visitor_ip_header'] );
echo '</td></tr></table></div>';
echo '</td></tr>';
echo '<tr><th scope="row">Uninstall</th><td><label><input type="checkbox" name="delete_data_on_uninstall" value="1"' . checked( ! empty( $s['delete_data_on_uninstall'] ), true, false ) . '> Delete all data when the plugin is deleted</label>';
echo '<p class="description"><strong>When you delete the plugin from the Plugins screen, also delete ALL donations, goals, rules, rewards, alerts, tiers and settings. This cannot be undone. Leave off to keep your data if you reinstall later.</strong></p></td></tr></table></div>';
$rel = \StreamGoals\Update\Updater::latest();
echo '<div class="sg-card"><h2>Plugin updates</h2><table class="form-table" role="presentation">';
@@ -148,6 +150,7 @@ final class SettingsPage {
}
$upd['funding_card'] = ! empty( $post['funding_card'] );
$upd['funding_paylater'] = ! empty( $post['funding_paylater'] );
$upd['delete_data_on_uninstall'] = ! empty( $post['delete_data_on_uninstall'] );
$upd['donation_notice'] = Input::text( $post['donation_notice'] ?? '', 200 );
$upd['moderate_messages'] = ! empty( $post['moderate_messages'] );
$upd['profanity_filter'] = ! empty( $post['profanity_filter'] );
+1
View File
@@ -20,6 +20,7 @@ final class Plugin {
public static function boot(): void {
Installer::maybe_upgrade();
Maintenance::register();
Privacy::register();
foreach ( self::MODULES as $module ) {
if ( class_exists( $module ) && method_exists( $module, 'register' ) ) {
$module::register();
+47
View File
@@ -0,0 +1,47 @@
<?php
declare( strict_types=1 );
namespace StreamGoals\Core;
/** Suggested privacy-policy text (Settings > Privacy > Policy Guide). Describes only what the code actually does. */
final class Privacy {
public const DOMAIN = 'streamgoals-donate';
public static function register(): void {
add_action( 'admin_init', array( self::class, 'add_policy_content' ) );
}
public static function add_policy_content(): void {
if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
return;
}
wp_add_privacy_policy_content( 'StreamGoals Donate', self::content() );
}
/** @param callable|null $t Translator taking one string (defaults to WordPress' __ with this text domain). */
public static function content( ?callable $t = null ): string {
$t ??= static fn( string $s ): string => __( $s, self::DOMAIN ); // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
$html = '<div class="wp-suggested-text">';
$html .= '<p class="privacy-policy-tutorial">' . $t( 'Suggested text for your privacy policy. Review it and adjust it to how you use the plugin, and to the laws that apply to you.' ) . '</p>';
$html .= '<strong class="privacy-policy-tutorial">' . $t( 'Suggested text:' ) . '</strong> ';
$html .= '<h2>' . $t( 'Donations' ) . '</h2>';
$html .= '<p>' . $t( 'When you make a donation on this site, we store the amount, the currency, the date and time, the PayPal order and capture identifiers, and the display name you entered, unless you chose to donate anonymously. The name of an anonymous donor is never stored. If you write a message with your donation, we store that message too, so please do not put personal details in it.' ) . '</p>';
$html .= '<p>' . $t( 'We do not store your email address, postal address or payment card details. Payments are processed by PayPal, which collects and handles those details under its own privacy statement:' ) . ' <a href="https://www.paypal.com/webapps/mpp/ua/privacy-full" target="_blank" rel="noopener noreferrer">https://www.paypal.com/webapps/mpp/ua/privacy-full</a></p>';
$html .= '<p>' . $t( 'The donation form loads PayPal\'s payment script from paypal.com, so PayPal receives your IP address and browser information when the form is shown.' ) . '</p>';
$html .= '<h2>' . $t( 'How long we keep data' ) . '</h2>';
$html .= '<p>' . $t( 'Donation records are kept until the site owner deletes them. The site owner can export them as a CSV file. Checkouts that were started but never paid are removed automatically after a week.' ) . '</p>';
$html .= '<h2>' . $t( 'Abuse protection' ) . '</h2>';
$html .= '<p>' . $t( 'To stop abuse, the number of donation requests from one visitor is limited. For this, a one-way hash of the visitor\'s IP address is used as the name of a temporary cache entry (a WordPress transient) that expires after a few minutes. The IP address itself is not written to the donation records. Expired entries can remain in the database until WordPress cleans them up, and on sites with a persistent object cache they are kept in that cache instead.' ) . '</p>';
$html .= '<h2>' . $t( 'Stream overlays' ) . '</h2>';
$html .= '<p>' . $t( 'The overlay pages shown in broadcasting software load no third-party scripts, fonts or services. They show donor display names and messages (not the names of anonymous donors) and any images or sounds the site owner chose from the Media Library.' ) . '</p>';
$html .= '</div>';
return $html;
}
}
+1
View File
@@ -40,6 +40,7 @@ final class Settings {
'funding_paylater' => false, // show PayPal "Pay Later" button
'update_token' => '', // optional Gitea read token (only while the update repo is private)
'funding_card' => true, // show the Debit/Credit Card button
'delete_data_on_uninstall' => false, // when the plugin is deleted, also drop all tables/options (see Core\Uninstaller)
);
}
+110
View File
@@ -0,0 +1,110 @@
<?php
declare( strict_types=1 );
namespace StreamGoals\Core;
/**
* Removes what the plugin created. Dependency-free on purpose: uninstall.php loads this single file with
* require_once, without the plugin's autoloader or constants.
*
* Always removed on uninstall: the cron event and all transients (they are only caches/notices).
* Removed ONLY when the owner ticked "delete data on uninstall": every sg_ table and option.
*
* Keep the lists below in sync with Installer (tables) and every add/update_option call; UninstallerTest fails
* when something is missing.
*/
final class Uninstaller {
public const CRON_HOOK = 'sg_purge_abandoned';
/** @return string[] Table names without the WordPress prefix. */
public static function tables(): array {
return array(
'sg_goals',
'sg_donations',
'sg_rules',
'sg_rule_events',
'sg_state',
'sg_actions',
'sg_action_events',
'sg_alert_defs',
'sg_goal_tiers',
);
}
/** @return string[] Option names (per site). */
public static function options(): array {
return array(
'sg_settings',
'sg_db_version',
'sg_overlay_epoch',
'sg_overlay_rules_version',
'sg_currency',
'sg_paypal_verified',
'sg_donate_page_id',
'sg_wizard_goal_id',
);
}
/** @return string[] Fixed-name site transients. */
public static function site_transients(): array {
return array( 'sg_update_release' );
}
/** @return string[] Prefixes of transients whose names carry a suffix (rate limiter hashes, per-user notices). */
public static function transient_prefixes(): array {
return array( 'sg_rl_', 'sg_notice_' );
}
/** Whether this site's saved settings ask for all data to be deleted. */
public static function wants_data_deleted( mixed $settings ): bool {
return is_array( $settings ) && ! empty( $settings['delete_data_on_uninstall'] );
}
/** Drops every plugin table for the current site prefix. @param object $wpdb wpdb-like (prefix, query). */
public static function drop_tables( object $wpdb ): void {
foreach ( self::tables() as $t ) {
$wpdb->query( 'DROP TABLE IF EXISTS `' . $wpdb->prefix . $t . '`' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}
}
/** Deletes the dynamically named transients (and their timeouts) straight from the options table. @param object $wpdb wpdb-like (options, esc_like, prepare, query). */
public static function delete_dynamic_transients( object $wpdb ): void {
foreach ( self::transient_prefixes() as $prefix ) {
foreach ( array( '_transient_', '_transient_timeout_' ) as $kind ) {
$like = $wpdb->esc_like( $kind . $prefix ) . '%';
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $like ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
}
}
}
/** Uninstall for the current site (call inside switch_to_blog on multisite). */
public static function run_site( object $wpdb ): void {
$delete = self::wants_data_deleted( get_option( 'sg_settings', array() ) );
wp_clear_scheduled_hook( self::CRON_HOOK );
self::delete_dynamic_transients( $wpdb );
if ( $delete ) {
self::drop_tables( $wpdb );
foreach ( self::options() as $o ) {
delete_option( $o );
}
}
}
/** Entry point for uninstall.php. */
public static function run(): void {
global $wpdb;
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
foreach ( get_sites( array( 'fields' => 'ids', 'number' => 0 ) ) as $id ) {
switch_to_blog( (int) $id );
self::run_site( $wpdb );
restore_current_blog();
}
} else {
self::run_site( $wpdb );
}
foreach ( self::site_transients() as $t ) {
delete_site_transient( $t );
}
}
}
+3
View File
@@ -6,7 +6,10 @@
* Requires at least: 6.8
* Requires PHP: 8.1
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Update URI: https://repo.anhonesthost.net/wp-plugins/wp-donations
* Text Domain: streamgoals-donate
* Domain Path: /languages
*/
defined( 'ABSPATH' ) || exit;
+29
View File
@@ -0,0 +1,29 @@
<?php
declare( strict_types=1 );
namespace StreamGoals\Tests\Unit;
use PHPUnit\Framework\TestCase;
use StreamGoals\Core\Privacy;
final class PrivacyTest extends TestCase {
public function test_text_covers_the_required_disclosures(): void {
$t = Privacy::content( static fn( string $s ): string => $s );
$this->assertStringContainsString( 'Suggested text:', $t );
$this->assertStringContainsString( 'PayPal', $t );
$this->assertStringContainsString( 'paypal.com/webapps/mpp/ua/privacy-full', $t );
$this->assertStringContainsString( 'anonymous', $t );
$this->assertStringContainsString( 'never stored', $t );
$this->assertStringContainsString( 'IP address', $t );
$this->assertStringContainsString( 'CSV', $t );
$this->assertStringContainsString( 'overlay', $t );
$this->assertStringContainsString( 'do not store your email address', $t );
}
public function test_translator_is_applied_to_every_sentence(): void {
$t = Privacy::content( static fn( string $s ): string => '[' . $s . ']' );
$this->assertStringContainsString( '[Suggested text:]', $t );
$this->assertStringContainsString( '[Donations]', $t );
}
}
+113
View File
@@ -0,0 +1,113 @@
<?php
declare( strict_types=1 );
namespace StreamGoals\Tests\Unit;
use PHPUnit\Framework\TestCase;
use StreamGoals\Core\Maintenance;
use StreamGoals\Core\Settings;
use StreamGoals\Core\Uninstaller;
/** Guards the uninstall lists so a newly added table/option/transient/cron cannot be forgotten. */
final class UninstallerTest extends TestCase {
private const ROOT = __DIR__ . '/../../';
/** @return string[] contents of every PHP file under includes/ plus the main file, keyed by path */
private function sources(): array {
$out = array( 'streamgoals-donate.php' => (string) file_get_contents( self::ROOT . 'streamgoals-donate.php' ) );
$it = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( self::ROOT . 'includes', \FilesystemIterator::SKIP_DOTS ) );
foreach ( $it as $f ) {
if ( 'php' === $f->getExtension() && 'Uninstaller.php' !== $f->getFilename() ) {
$out[ $f->getPathname() ] = (string) file_get_contents( $f->getPathname() );
}
}
return $out;
}
public function test_every_installer_table_is_dropped(): void {
$src = (string) file_get_contents( self::ROOT . 'includes/Core/Installer.php' );
preg_match_all( '/CREATE TABLE \{\$p\}(\w+)/', $src, $m );
$this->assertNotEmpty( $m[1] );
$created = array_map( static fn( $t ) => 'sg_' . $t, $m[1] );
$this->assertSame( array(), array_diff( $created, Uninstaller::tables() ), 'table created by Installer but not dropped on uninstall' );
$this->assertSame( array(), array_diff( Uninstaller::tables(), $created ), 'uninstall drops a table Installer does not create' );
}
public function test_every_option_used_in_code_is_deleted(): void {
$found = array();
foreach ( $this->sources() as $src ) {
preg_match_all( "/(?:add|update|delete)_option\(\s*'(sg_\w+)'/", $src, $a );
preg_match_all( "/const\s+(?:OPTION|VERIFIED)\s*=\s*'(sg_\w+)'/", $src, $b );
$found = array_merge( $found, $a[1], $b[1] );
}
$found = array_unique( $found );
$this->assertContains( 'sg_settings', $found, 'scan sanity check' );
$this->assertContains( 'sg_overlay_epoch', $found );
$this->assertContains( 'sg_paypal_verified', $found );
$this->assertSame( array(), array_values( array_diff( $found, Uninstaller::options() ) ), 'option written by the plugin but not removed on uninstall' );
}
public function test_every_transient_and_cron_hook_is_cleaned(): void {
$fixed = array();
$dyn = array();
foreach ( $this->sources() as $src ) {
preg_match_all( "/(?:CACHE_KEY\s*=\s*|(?:set|get|delete)_site_transient\(\s*)'(sg_\w+)'/", $src, $a );
$fixed = array_merge( $fixed, $a[1] );
preg_match_all( "/(?:set|get|delete)_transient\(\s*'(sg_\w+?_)'\s*\./", $src, $b );
$dyn = array_merge( $dyn, $b[1] );
preg_match_all( "/'(sg_rl_)'\s*\./", $src, $c );
$dyn = array_merge( $dyn, $c[1] );
}
$this->assertContains( 'sg_update_release', $fixed, 'scan sanity check' );
$this->assertSame( array(), array_values( array_diff( array_unique( $fixed ), Uninstaller::site_transients() ) ) );
$this->assertSame( array(), array_values( array_diff( array_unique( $dyn ), Uninstaller::transient_prefixes() ) ) );
$this->assertContains( 'sg_rl_', Uninstaller::transient_prefixes() );
$this->assertContains( 'sg_notice_', Uninstaller::transient_prefixes() );
$this->assertSame( Maintenance::HOOK, Uninstaller::CRON_HOOK );
}
public function test_deactivation_unschedules_the_cron_event(): void {
$main = (string) file_get_contents( self::ROOT . 'streamgoals-donate.php' );
$this->assertMatchesRegularExpression( '/register_deactivation_hook\([^;]*Maintenance::class,\s*\'unschedule\'/', $main );
}
public function test_uninstall_is_opt_in_and_off_by_default(): void {
$this->assertFalse( Settings::defaults()['delete_data_on_uninstall'] );
$this->assertFalse( Uninstaller::wants_data_deleted( false ) );
$this->assertFalse( Uninstaller::wants_data_deleted( array() ) );
$this->assertFalse( Uninstaller::wants_data_deleted( array( 'delete_data_on_uninstall' => false ) ) );
$this->assertTrue( Uninstaller::wants_data_deleted( array( 'delete_data_on_uninstall' => true ) ) );
}
private function fakeDb(): object {
return new class() {
public string $prefix = 'wp7_';
public string $options = 'wp7_options';
public array $queries = array();
public function query( string $q ): int { $this->queries[] = $q; return 0; }
public function esc_like( string $s ): string { return addcslashes( $s, '_%\\' ); }
public function prepare( string $q, ...$a ): string { return str_replace( '%s', "'" . $a[0] . "'", $q ); }
};
}
public function test_drop_tables_issues_one_drop_per_table_with_prefix(): void {
$db = $this->fakeDb();
Uninstaller::drop_tables( $db );
$this->assertCount( count( Uninstaller::tables() ), $db->queries );
$this->assertContains( 'DROP TABLE IF EXISTS `wp7_sg_donations`', $db->queries );
foreach ( $db->queries as $q ) {
$this->assertMatchesRegularExpression( '/^DROP TABLE IF EXISTS `wp7_sg_\w+`$/', $q );
}
}
public function test_dynamic_transient_cleanup_only_targets_plugin_prefixes(): void {
$db = $this->fakeDb();
Uninstaller::delete_dynamic_transients( $db );
$this->assertCount( 4, $db->queries );
foreach ( $db->queries as $q ) {
$this->assertStringStartsWith( 'DELETE FROM wp7_options WHERE option_name LIKE', $q );
$this->assertMatchesRegularExpression( '/_transient_(timeout_)?sg_(rl|notice)_%/', str_replace( '\\', '', $q ) );
}
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
/**
* Runs when the plugin is deleted from the Plugins screen.
*
* Always removes the scheduled event and cached transients. Deletes donations, goals and settings only if the
* owner enabled "delete data on uninstall" in StreamGoals > Settings > Advanced.
*/
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
require_once __DIR__ . '/includes/Core/Uninstaller.php';
\StreamGoals\Core\Uninstaller::run();