Skip to content

Commit

Permalink
fix: minor corrections after WordPress plugin review
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquimds committed Nov 29, 2024
1 parent df90a15 commit 829bb47
Show file tree
Hide file tree
Showing 17 changed files with 963 additions and 242 deletions.
8 changes: 4 additions & 4 deletions packages/join-block/composer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"version": "1.0.6",
"require": {
"gocardless/gocardless-pro": "^4.5",
"vlucas/phpdotenv": "^5.2",
"giggsey/libphonenumber-for-php": "^8.12",
"htmlburger/carbon-fields": "^3.2",
"monolog/monolog": "^2.1",
"cmdisp/monolog-microsoft-teams": "^1.1",
"auth0/auth0-php": "^8.3.1",
"http-interop/http-factory-guzzle": "^1.2",
"chargebee/chargebee-php": "^3.23",
"stripe/stripe-php": "^16.1",
"mailchimp/marketing": "^3.0",
"guzzlehttp/guzzle": "^7.9"
"guzzlehttp/guzzle": "^7.9",
"gocardless/gocardless-pro": "^6.0",
"monolog/monolog": "3.8.0",
"cmdisp/monolog-microsoft-teams": "^2.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.5",
Expand Down
1,069 changes: 850 additions & 219 deletions packages/join-block/composer.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion packages/join-block/join.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* License: GPLv2 or later
*/

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

require_once plugin_dir_path(__FILE__) . 'vendor/autoload.php';

use ChargeBee\ChargeBee\Environment;
Expand Down Expand Up @@ -51,7 +53,7 @@
$joinBlockLog->pushHandler(
new \CMDISP\MonologMicrosoftTeams\TeamsLogHandler(
$teamsWebhook,
\Monolog\Logger::ERROR
\Monolog\Level::Error
)
);
}
Expand Down
52 changes: 51 additions & 1 deletion packages/join-block/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Donate link: https://commonknowledge.coop/
Tags: membership, subscription, join
Contributors: commonknowledgecoop
Requires at least: 5.4
Tested up to: 6.6
Tested up to: 6.7
Stable tag: 1.1.0
Requires PHP: 7.4
License: GPLv2 or later
Expand Down Expand Up @@ -46,6 +46,56 @@ To support an additional donation in ChargeBee, create two more products:
- a charge called "Additional Donation", with a price in the desired
currency called "additional_donation_single".

== External Services ==

The following is a list of all the external services used by the plugin.
Each service is marked as optional or required.

- getAddress()
Domain: [getaddress.io](https://getaddress.io)
Used for: converting a UK postcode to a full address.
Data received: the postcode provided by the user.

- Ideal Postcodes
Domain: [ideal-postcodes.co.uk](https://ideal-postcodes.co.uk/)
Used for: converting a UK postcode to a full address.
Data received: the postcode provided by the user.

- postcodes.io
Domain: [postcodes.io](https://postcodes.io)
Used for: fetching useful data about a postcode that is then sent to your organisation's membership list.
Data received: the postcode provided by the user.

- ChargeBee
Domain: [chargebee.com](https://www.chargebee.com/)
Used for: managing user payments and subscriptions.
Data received: user payment information, i.e. credit/debit card details or bank account details.

- Stripe
Domain: [stripe.com](https://stripe.com/)
Used for: managing user payments and subscriptions.
Data received: user payment information, i.e. credit/debit card details or bank account details.

- GoCardless
Domain: [gocardless.com](https://gocardless.com/)
Used for: managing user direct debit subscriptions.
Data received: user bank account details.

- Action Network
Domain: [actionnetwork.org](https://actionnetwork.org/)
Used for: storing user membership details.
Data received: all data provided by the user.

- Mailchimp
Domain: [mailchimp.com](https://mailchimp.com/)
Used for: storing user membership details.
Data received: all data provided by the user.

- Auth0
Domain: [auth0.com](https://auth0.com/)
Used for: giving users the ability to modify their data.
Data received: the user's name, email, password and payment subscription ID.

== Contact Us ==

Need help? Contact us at [[email protected]](mailto:[email protected]).
Expand Down
43 changes: 29 additions & 14 deletions packages/join-block/src/Blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CommonKnowledge\JoinBlock;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

use Carbon_Fields\Block;
use Carbon_Fields\Field;
use Carbon_Fields\Container\Block_Container;
Expand All @@ -25,6 +27,10 @@ private static function registerScripts()
{
global $joinBlockLog;

if (is_admin()) {
return;
}

$directoryName = dirname(__FILE__, 2);

$joinFormJavascriptBundleLocation = 'build/join-flow/bundle.js';
Expand Down Expand Up @@ -109,7 +115,7 @@ private static function registerJoinHeaderBlock()
$title = str_replace($to_replace, $value, $title);
}
}
self::echoBlockCss();
self::enqueueBlockCss();
?>
<!-- wrap in .ck-join-flow so 'namespaced' styles apply -->
<div class="ck-join-flow">
Expand Down Expand Up @@ -166,7 +172,7 @@ private static function registerJoinFormBlock()

));
$join_form_block->set_render_callback(function ($fields, $attributes, $inner_blocks) {
self::echoBlockCss();
self::enqueueBlockCss();
self::echoEnvironment($fields, self::NORMAL_BLOCK_MODE);
if (Settings::get("USE_CHARGEBEE")) {
wp_enqueue_script("chargebee", "https://js.chargebee.com/v2/chargebee.js", [], "v2", ["in_footer" => false]);
Expand Down Expand Up @@ -218,7 +224,7 @@ private static function registerJoinLinkBlock()
));
$join_form_block->set_render_callback(function ($fields, $attributes, $inner_blocks) {
$link = get_page_link($fields['join_page'][0]['id']);
self::echoBlockCss();
self::enqueueBlockCss();
?>
<!-- wrap in .ck-join-flow so 'namespaced' styles apply -->
<?php if ($fields['include_email_input']) : ?>
Expand Down Expand Up @@ -397,18 +403,27 @@ private static function echoEnvironment($fields, $block_mode)
<?php
}

private static function echoBlockCss()
private static function enqueueBlockCss()
{
?>
<style>
:root {
--ck-join-form-primary-color: <?php echo esc_attr(Settings::get("THEME_PRIMARY_COLOR")) ?>;
--ck-join-form-gray-color: <?php echo esc_attr(Settings::get("THEME_GRAY_COLOR")) ?>;
--ck-join-form-background-color: <?php echo esc_attr(Settings::get("THEME_BACKGROUND_COLOR")) ?>;
}
// Dynamic inline CSS cannot have a fixed version
wp_register_style("common-knowledge-join-flow-block-css", false, [], time());
wp_enqueue_style("common-knowledge-join-flow-block-css");

$inline_style = ":root {\n";
$primary_color = Settings::get("THEME_PRIMARY_COLOR");
$gray_color = Settings::get("THEME_GRAY_COLOR");
$background_color = Settings::get("THEME_BACKGROUND_COLOR");
if ($primary_color) {
$inline_style .= " --ck-join-form-primary-color: $primary_color;\n";
}
if ($gray_color) {
$inline_style .= " --ck-join-form-gray-color: $gray_color;\n";
}
if ($background_color) {
$inline_style .= " --ck-join-form-background-color: $background_color;\n";
}
$inline_style .= "}\n " . Settings::get('custom_css');

<?php echo esc_attr(Settings::get('custom_css')) ?>
</style>
<?php
wp_add_inline_style("common-knowledge-join-flow-block-css", $inline_style);
}
}
2 changes: 2 additions & 0 deletions packages/join-block/src/CK_Theme_Options_Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CommonKnowledge\JoinBlock;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

use Carbon_Fields\Carbon_Fields;
use Carbon_Fields\Container\Theme_Options_Container;
use Carbon_Fields\Exception\Incorrect_Syntax_Exception;
Expand Down
2 changes: 2 additions & 0 deletions packages/join-block/src/Exceptions/JoinBlockException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CommonKnowledge\JoinBlock\Exceptions;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

class JoinBlockException extends \Exception
{
public $fields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CommonKnowledge\JoinBlock\Exceptions;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

class SubscriptionExistsException extends \Exception
{
}
5 changes: 4 additions & 1 deletion packages/join-block/src/Logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace CommonKnowledge\JoinBlock;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

use Monolog\Logger;
use Monolog\Processor\WebProcessor;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Level;

class Logging
{
Expand All @@ -26,7 +29,7 @@ public static function init()
$logFilenameHash = bin2hex(random_bytes(18));
}
$logFilename = "debug-$logFilenameHash.log";
$joinBlockLog->pushHandler(new RotatingFileHandler("$logLocation/$logFilename", 10, Logger::INFO));
$joinBlockLog->pushHandler(new RotatingFileHandler("$logLocation/$logFilename", 10, Level::Info));
$joinBlockLog->pushProcessor(new WebProcessor());
}
}
2 changes: 2 additions & 0 deletions packages/join-block/src/Services/ActionNetworkService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CommonKnowledge\JoinBlock\Services;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

use CommonKnowledge\JoinBlock\Settings;
use GuzzleHttp\Client;

Expand Down
2 changes: 2 additions & 0 deletions packages/join-block/src/Services/Auth0Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CommonKnowledge\JoinBlock\Services;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

use Auth0\SDK\API\Management;
use Auth0\SDK\Auth0;
use Auth0\SDK\Configuration\SdkConfiguration;
Expand Down
2 changes: 2 additions & 0 deletions packages/join-block/src/Services/GocardlessService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CommonKnowledge\JoinBlock\Services;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

use CommonKnowledge\JoinBlock\Exceptions\SubscriptionExistsException;
use CommonKnowledge\JoinBlock\Settings;

Expand Down
2 changes: 2 additions & 0 deletions packages/join-block/src/Services/JoinService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CommonKnowledge\JoinBlock\Services;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

use Carbon\Carbon;
use ChargeBee\ChargeBee\Exceptions\APIError;
use ChargeBee\ChargeBee\Exceptions\InvalidRequestException;
Expand Down
2 changes: 2 additions & 0 deletions packages/join-block/src/Services/MailchimpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CommonKnowledge\JoinBlock\Services;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

use MailchimpMarketing\ApiClient;
use CommonKnowledge\JoinBlock\Settings;

Expand Down
3 changes: 2 additions & 1 deletion packages/join-block/src/Services/StripeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace CommonKnowledge\JoinBlock\Services;

use CommonKnowledge\JoinBlock\Settings;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

use CommonKnowledge\JoinBlock\Settings;
use Stripe\Stripe;
use Stripe\Customer;
use Stripe\Subscription;
Expand Down
2 changes: 2 additions & 0 deletions packages/join-block/src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CommonKnowledge\JoinBlock;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

use Carbon_Fields\Container;
use Carbon_Fields\Datastore\Empty_Datastore;
use Carbon_Fields\Field;
Expand Down
3 changes: 2 additions & 1 deletion packages/join-block/tests/SessionLockTestProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use CommonKnowledge\JoinBlock\Services\JoinService;
use Monolog\Handler\StreamHandler;
use Monolog\Level;
use Monolog\Logger;

/**
Expand All @@ -25,7 +26,7 @@
$joinBlockLogLocation = __DIR__ . '/../logs/tests.log';
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
$joinBlockLogFile = fopen($joinBlockLogLocation, 'a');
$joinBlockLog->pushHandler(new StreamHandler($joinBlockLogFile, 10, Logger::INFO));
$joinBlockLog->pushHandler(new StreamHandler($joinBlockLogFile, Level::Info));

$sessionId = $argv[1];

Expand Down

0 comments on commit 829bb47

Please sign in to comment.