-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update with more addon boilerplate
- Loading branch information
Jon Waldstein
committed
Oct 4, 2024
1 parent
fb220ea
commit 99fb51b
Showing
8 changed files
with
167 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace GiveCloudflareTurnstile\Addon; | ||
|
||
use Give_Addon_Activation_Banner; | ||
|
||
use GiveCloudflareTurnstile\Settings\Repositories\GlobalSettings; | ||
|
||
use const GIVE_CLOUDFLARE_TURNSTILE_VERSION; | ||
|
||
/** | ||
* Helper class responsible for showing add-on Activation Banner. | ||
* @since 1.0.0 | ||
*/ | ||
class ActivationBanner | ||
{ | ||
|
||
/** | ||
* Show activation banner | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public function show(): void | ||
{ | ||
// Check for Activation banner class. | ||
if (!class_exists('Give_Addon_Activation_Banner') && file_exists( | ||
GIVE_PLUGIN_DIR . 'includes/admin/class-addon-activation-banner.php' | ||
)) { | ||
include GIVE_PLUGIN_DIR . 'includes/admin/class-addon-activation-banner.php'; | ||
} | ||
|
||
// Only runs on admin. | ||
$args = [ | ||
'file' => GIVE_CLOUDFLARE_TURNSTILE_FILE, | ||
'name' => GIVE_CLOUDFLARE_TURNSTILE_NAME, | ||
'version' => GIVE_CLOUDFLARE_TURNSTILE_VERSION, | ||
'settings_url' => give(GlobalSettings::class)->getSettingsUrl(), | ||
'documentation_url' => 'https://givewp.com/documentation/add-ons/boilerplate/', | ||
'support_url' => 'https://givewp.com/support/', | ||
'testing' => false, // Never leave true. | ||
]; | ||
|
||
ray($args); | ||
|
||
new Give_Addon_Activation_Banner($args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace GiveCloudflareTurnstile\Addon; | ||
|
||
use InvalidArgumentException; | ||
|
||
use const GIVE_CLOUDFLARE_TURNSTILE_DIR; | ||
|
||
/** | ||
* Helper class responsible for loading add-on views. | ||
* @since 1.0.0 | ||
*/ | ||
class View | ||
{ | ||
/** | ||
* Default add-on domain | ||
*/ | ||
const DEFAULT_DOMAIN = 'Addon'; | ||
|
||
/** | ||
* @since 1.0.0 | ||
* | ||
* @param array $templateParams Arguments for template. | ||
* @param bool $echo | ||
* | ||
* @param string $view Template name | ||
* When using multiple domains within this add-on, the domain directory can be set by using "." in the template name. | ||
* String before the "." character is domain directory, and everything after is the template file path | ||
* Example usage: View::render( 'DomainName.templateName' ); | ||
* This will try to load src/DomainName/resources/view/templateName.php file | ||
* | ||
* @return string|void | ||
* @throws InvalidArgumentException if template file not exist | ||
* | ||
*/ | ||
public static function load(string $view, array $templateParams = [], bool $echo = false) | ||
{ | ||
// Get domain and file path | ||
list ($domain, $file) = static::getPaths($view); | ||
$template = GIVE_CLOUDFLARE_TURNSTILE_DIR . "src/{$domain}/resources/views/{$file}.php"; | ||
|
||
if ( ! file_exists($template)) { | ||
throw new InvalidArgumentException("View template file {$template} does not exist"); | ||
} | ||
|
||
ob_start(); | ||
extract($templateParams); | ||
include $template; | ||
$content = ob_get_clean(); | ||
|
||
if ( ! $echo) { | ||
return $content; | ||
} | ||
|
||
echo $content; | ||
} | ||
|
||
/** | ||
* @since 1.0.0 | ||
* | ||
* @param array $vars | ||
* | ||
* @param string $view | ||
*/ | ||
public static function render(string $view, array $vars = []): void | ||
{ | ||
static::load($view, $vars, true); | ||
} | ||
|
||
/** | ||
* Get domain and template file path | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @param string $path | ||
* | ||
* @return array | ||
*/ | ||
private static function getPaths(string $path): array | ||
{ | ||
// Check for . delimiter | ||
if (false === strpos($path, '.')) { | ||
return [ | ||
self::DEFAULT_DOMAIN, | ||
$path, | ||
]; | ||
} | ||
|
||
return explode('.', $path, 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php defined( 'ABSPATH' ) or exit; ?> | ||
|
||
<strong><?php _e( 'Activation Error:', 'givewp-cloudflare-turnstile' ); ?></strong> | ||
<?php _e( 'You must have', 'givewp-cloudflare-turnstile' ); ?> <a href="https://givewp.com" target="_blank">Give</a> | ||
<?php printf( __( 'plugin installed and activated for the %s add-on to activate', 'givewp-cloudflare-turnstile' ), GIVE_CLOUDFLARE_TURNSTILE_NAME ); ?> |
8 changes: 8 additions & 0 deletions
8
src/Addon/resources/views/admin/notices/give-version-error.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php defined( 'ABSPATH' ) or exit; ?> | ||
|
||
<strong><?php _e( 'Activation Error:', 'givewp-cloudflare-turnstile' ); ?></strong> | ||
<?php _e( 'You must have', 'givewp-cloudflare-turnstile' ); ?> <a href="https://givewp.com" target="_blank">Give</a> | ||
<?php _e( 'version', 'givewp-cloudflare-turnstile' ); ?> <?php echo GIVE_CLOUDFLARE_TURNSTILE_MIN_GIVE_VERSION; ?>+ | ||
<?php printf( esc_html__( 'for the %1$s add-on to activate', 'givewp-cloudflare-turnstile' ), GIVE_CLOUDFLARE_TURNSTILE_NAME ); ?> | ||
. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters