Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"php": "~7.4.0 || ~8.0.0",
"php": "~7.4.0 || ^8.0",
"composer-runtime-api": "^2.2"
},
"require-dev": {
Expand Down
20 changes: 19 additions & 1 deletion src/ModuleLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use RuntimeException;
use SzepeViktor\TestMode\Modules\Module;
use SzepeViktor\TestMode\ThirdPartyModules as ThirdParties;

use function apply_filters;

Expand Down Expand Up @@ -37,12 +38,29 @@ static function (string $fqcn): bool {
);
}

/**
* @return list<class-string>
*/
public static function getThirdParties(): array
{
$modules = [];

if (class_exists(\MakeCommerce::class)) {
$modules[] = ThirdParties\MakeCommerce::class;
}

return $modules;
}

/**
* @return list<class-string>
*/
public static function getAll(): array
{
$modules = apply_filters('szepeviktor/test-mode/modules', self::getBuiltins());
$modules = apply_filters(
'szepeviktor/test-mode/modules',
array_merge(self::getBuiltins(), self::getThirdParties())
);

return array_filter(
$modules,
Expand Down
8 changes: 4 additions & 4 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function loadTextDomain()
{
/** @var string */
$pluginBasename = Config::get('baseName');
load_plugin_textdomain('plugin-slug', false, sprintf('%s/%s', dirname($pluginBasename), 'languages'));
load_plugin_textdomain('szv-test-mode', false, sprintf('%s/%s', dirname($pluginBasename), 'languages'));
}

/**
Expand Down Expand Up @@ -77,10 +77,10 @@ public static function printRequirementsNotice()

printf(
'<div class="notice notice-error"><p>%1$s <a href="%2$s" target="_blank">%3$s</a> %4$s</p></div>',
esc_html__('Plugin Name activation failed! Please read', 'plugin-slug'),
esc_html__('Plugin Name activation failed! Please read', 'szv-test-mode'),
esc_url('https://github.com/szepeviktor/starter-plugin#installation'),
esc_html__('the Installation instructions', 'plugin-slug'),
esc_html__('for list of requirements.', 'plugin-slug')
esc_html__('the Installation instructions', 'szv-test-mode'),
esc_html__('for list of requirements.', 'szv-test-mode')
);
}

Expand Down
45 changes: 45 additions & 0 deletions src/ThirdPartyModules/MakeCommerce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace SzepeViktor\TestMode\ThirdPartyModules;

use SzepeViktor\TestMode\Modules\BaseModule;
use SzepeViktor\TestMode\Modules\Module;

use function add_filter;

class MakeCommerce extends BaseModule implements Module
{
public function getName(): string
{
return 'MakeCommerce payment gateway';
}

public function getLabel(): string
{
return 'Use sandbox, or do not start at all.';
}

public function testmode(): void
{
add_filter(
'pre_option_'.'mc_api_mode',
static function () {
return 'test';
},
PHP_INT_MAX,
0
);
}

public function disabled(): void
{
add_filter(
'pre_option_'.'mc_api_mode',
'__return_null',
PHP_INT_MAX,
0
);
}
}