Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakiboy committed Jun 25, 2024
1 parent 632dac7 commit 273ca6d
Show file tree
Hide file tree
Showing 49 changed files with 976 additions and 963 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"jakiboy/vanilleplugin",
"version":"1.0.6",
"version":"1.0.7",
"type":"library",
"description":"WordPress Plugin Framework",
"keywords":[
Expand Down
24 changes: 3 additions & 21 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ The "traits" folder (tr) contains VanillePlugin "librairies" traits.

These classes **SHOULD NOT** include:
- Exceptions (exc)
- Core (VanillePluginValidator)

The "third-parties" folder (third) contains VanillePlugin third-party wrapper classes.

These classes **SHOULD NOT** include:
- Exceptions (exc)
- Interfaces (int)
- librairies (lib)
- Core (VanillePluginConfig, VanillePluginOption, VanillePluginValidator)

The "interfaces" folder (int) contains VanillePlugin "librairies" interfaces.
Expand All @@ -27,20 +19,13 @@ These classes **CAN ONLY** be used by:
The "includes" folder (inc) contains VanillePlugin wrapper classes,
Used to improve or change behavior of built-in PHP & WordPress functions.

These classes **SHOULD NOT** include:
- Exceptions (exc)
- Interfaces (int)
- librairies (lib)
- Third-parties (third)
- Traits (tr)
- Core (VanillePluginConfig, VanillePluginOption, VanillePluginValidator)
These classes **SHOULD NOT** include any of VanillePlugin parts

The "exceptions" folder (exc) contains VanillePlugin core exceptions.

These classes **SHOULD NOT** include:
- Interfaces (int)
These classes **SHOULD NOT** include any of VanillePlugin parts
and **CAN ONLY** be used by:
- librairies (lib)
- Third-parties (third)
- Traits (tr)
- Core (VanillePluginConfig, VanillePluginOption, VanillePluginValidator)

Expand All @@ -51,19 +36,16 @@ The VanillePluginConfig **SHOULD NOT** include:
- Includes (inc)
- Interfaces (int)
- librairies (lib)
- Third-parties (third)
- Core (VanillePluginOption)

The VanillePluginOption **SHOULD NOT** include:
- Exceptions (exc)
- Includes (inc)
- Interfaces (int)
- librairies (lib)
- Third-parties (third)
- Core (VanillePluginValidator)

The VanillePluginValidator **SHOULD NOT** include:
- Interfaces (int)
- librairies (lib)
- Third-parties (third)
- Core (VanillePluginConfig, VanillePluginOption)
95 changes: 68 additions & 27 deletions src/VanillePluginOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ protected function removePluginAction(string $hook, $callback, int $priority = 1
* @access protected
* @inheritdoc
*/
protected function doPluginAction(string $hook, $args = null)
protected function doPluginAction(string $hook, ...$args)
{
$hook = $this->applyNamespace($hook);
$this->doAction($hook, $args);
$this->doAction($hook, ...$args);
}

/**
Expand Down Expand Up @@ -114,10 +114,10 @@ protected function removePluginFilter(string $hook, $callback, int $priority = 1
* @access protected
* @inheritdoc
*/
protected function applyPluginFilter(string $hook, $value, $args = null)
protected function applyPluginFilter(string $hook, $value, ...$args)
{
$hook = $this->applyNamespace($hook);
return $this->applyFilter($hook, $value, $args);
return $this->applyFilter($hook, $value, ...$args);
}

/**
Expand Down Expand Up @@ -596,24 +596,24 @@ protected function createToken($action = null) : string
{
if ( $this->isType('string', $action) ) {
if ( empty($action) ) {
$action = 'check';
$action = 'verify';
}
$action = $this->applyNamespace($action);
}
return $this->createNonce($action);
}

/**
* Check token.
* Verify token.
*
* @access protected
* @inheritdoc
*/
protected function checkToken($action = null, bool $strict = false)
protected function verifyToken($action = null, bool $strict = false)
{
if ( $this->isType('string', $action) ) {
if ( empty($action) ) {
$action = 'check';
$action = 'verify';
}
$action = $this->applyNamespace($action);
}
Expand All @@ -635,16 +635,16 @@ protected function checkToken($action = null, bool $strict = false)
}

/**
* Check AJAX token.
* Verify AJAX token.
*
* @access protected
* @inheritdoc
*/
protected function checkAjaxToken($action = null, bool $strict = false)
protected function verifyAjaxToken($action = null, bool $strict = false)
{
if ( $this->isType('string', $action) ) {
if ( empty($action) ) {
$action = 'check';
$action = 'verify';
}
$action = $this->applyNamespace($action);
}
Expand All @@ -666,12 +666,12 @@ protected function checkAjaxToken($action = null, bool $strict = false)
}

/**
* Check role permission.
* Verify role permission.
*
* @access protected
* @inheritdoc
*/
protected function checkPermission($id = null)
protected function verifyPermission($id = null)
{
if ( !$this->isAdministrator($id) ) {
$code = ($this->hasDebug()) ? 401 : 200;
Expand Down Expand Up @@ -748,16 +748,20 @@ protected function purgePluginTransients() : bool
* [Filter: {plugin}-cache-key].
* [Filter: {plugin}-cache-lang].
* [Filter: {plugin}-cache-group].
* [Filter: {plugin}-get-cache].
* [Filter: {plugin}-cache-status].
*
* @access protected
* @inheritdoc
*/
protected function getPluginCache($key, ?string $group = null)
protected function getPluginCache($key, ?bool &$status = null, ?string $group = null)
{
$key = $this->applyNamespace($key);
$key = $this->lowercase(
$this->applyNamespace($key)
);
$key = $this->applyPluginFilter('cache-key', $key);

if ( $this->isMultilingual() ) {
if ( $this->hasMultilingual() ) {
$key = "{$key}-{$this->getLang()}";
$key = $this->applyPluginFilter('cache-lang', $key);
}
Expand All @@ -767,24 +771,32 @@ protected function getPluginCache($key, ?string $group = null)
$group = $this->applyPluginFilter('cache-group', $group);
}

return $this->getCache($key, $group);
if ( $this->hasPluginFilter('get-cache') ) {
$status = $this->applyPluginFilter('cache-status', $status, $key);
return $this->applyPluginFilter('get-cache', $key, $group);
}

return $this->getCache($key, $status, $group);
}

/**
* Set plugin cache value.
* [Filter: {plugin}-cache-key].
* [Filter: {plugin}-cache-lang].
* [Filter: {plugin}-cache-group].
* [Filter: {plugin}-set-cache].
*
* @access protected
* @inheritdoc
*/
protected function setPluginCache($key, $value, ?int $ttl = null, ?string $group = null) : bool
{
$key = $this->applyNamespace($key);
$key = $this->lowercase(
$this->applyNamespace($key)
);
$key = $this->applyPluginFilter('cache-key', $key);

if ( $this->isMultilingual() ) {
if ( $this->hasMultilingual() ) {
$key = "{$key}-{$this->getLang()}";
$key = $this->applyPluginFilter('cache-lang', $key);
}
Expand All @@ -799,6 +811,10 @@ protected function setPluginCache($key, $value, ?int $ttl = null, ?string $group
$ttl = $this->applyPluginFilter('cache-ttl', $ttl);
}

if ( $this->hasPluginFilter('set-cache') ) {
return $this->applyPluginFilter('set-cache', $key, $value, $ttl, $group);
}

return $this->setCache($key, $value, $ttl, $group);
}

Expand All @@ -807,16 +823,19 @@ protected function setPluginCache($key, $value, ?int $ttl = null, ?string $group
* [Filter: {plugin}-cache-key].
* [Filter: {plugin}-cache-lang].
* [Filter: {plugin}-cache-group].
* [Filter: {plugin}-add-cache].
*
* @access protected
* @inheritdoc
*/
protected function addPluginCache($key, $value, ?int $ttl = null, ?string $group = null) : bool
{
$key = $this->applyNamespace($key);
$key = $this->lowercase(
$this->applyNamespace($key)
);
$key = $this->applyPluginFilter('cache-key', $key);

if ( $this->isMultilingual() ) {
if ( $this->hasMultilingual() ) {
$key = "{$key}-{$this->getLang()}";
$key = $this->applyPluginFilter('cache-lang', $key);
}
Expand All @@ -831,6 +850,10 @@ protected function addPluginCache($key, $value, ?int $ttl = null, ?string $group
$ttl = $this->applyPluginFilter('cache-ttl', $ttl);
}

if ( $this->hasPluginFilter('add-cache') ) {
return $this->applyPluginFilter('add-cache', $key, $value, $ttl, $group);
}

return $this->addCache($key, $value, $ttl, $group);
}

Expand All @@ -839,16 +862,19 @@ protected function addPluginCache($key, $value, ?int $ttl = null, ?string $group
* [Filter: {plugin}-cache-key].
* [Filter: {plugin}-cache-lang].
* [Filter: {plugin}-cache-group].
* [Filter: {plugin}-update-cache].
*
* @access protected
* @inheritdoc
*/
protected function updatePluginCache($key, $value, ?int $ttl = null, ?string $group = null) : bool
{
$key = $this->applyNamespace($key);
$key = $this->lowercase(
$this->applyNamespace($key)
);
$key = $this->applyPluginFilter('cache-key', $key);

if ( $this->isMultilingual() ) {
if ( $this->hasMultilingual() ) {
$key = "{$key}-{$this->getLang()}";
$key = $this->applyPluginFilter('cache-lang', $key);
}
Expand All @@ -863,24 +889,31 @@ protected function updatePluginCache($key, $value, ?int $ttl = null, ?string $gr
$ttl = $this->applyPluginFilter('cache-ttl', $ttl);
}

return $this->updateCache($key, $value, $ttl);
if ( $this->hasPluginFilter('update-cache') ) {
return $this->applyPluginFilter('update-cache', $key, $value, $ttl, $group);
}

return $this->updateCache($key, $value, $ttl, $group);
}

/**
* Delete plugin cache.
* [Filter: {plugin}-cache-key].
* [Filter: {plugin}-cache-lang].
* [Filter: {plugin}-cache-group].
* [Filter: {plugin}-delete-cache].
*
* @access protected
* @inheritdoc
*/
protected function deletePluginCache($key, ?string $group = null) : bool
{
$key = $this->applyNamespace($key);
$key = $this->lowercase(
$this->applyNamespace($key)
);
$key = $this->applyPluginFilter('cache-key', $key);

if ( $this->isMultilingual() ) {
if ( $this->hasMultilingual() ) {
$key = "{$key}-{$this->getLang()}";
$key = $this->applyPluginFilter('cache-lang', $key);
}
Expand All @@ -890,17 +923,25 @@ protected function deletePluginCache($key, ?string $group = null) : bool
$group = $this->applyPluginFilter('cache-group', $group);
}

if ( $this->hasPluginFilter('delete-cache') ) {
return $this->applyPluginFilter('delete-cache', $key, $group);
}

return $this->deleteCache($key, $group);
}

/**
* Purge plugin cache.
* [Filter: {plugin}-purge-cache].
*
* @access protected
* @inheritdoc
*/
protected function purgePluginCache() : bool
{
if ( $this->hasPluginFilter('purge-cache') ) {
return $this->applyPluginFilter('purge-cache', false);
}
return $this->purgeCache();
}

Expand Down Expand Up @@ -1078,7 +1119,7 @@ protected function setResponse($msg, $content = [], string $status = 'success',
if ( $this->isType('array', $msg) && count($msg) == 2 ) {
$temp = $msg[0];
$args = (array)$msg[1];
$msg = $this->transVar($temp, $args);
$msg = $this->transVar($temp, $args);

} else {
$msg = $this->translate($msg);
Expand Down
23 changes: 0 additions & 23 deletions src/exc/CacheException.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/inc/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ final class Cache
* @param bool $found
* @return mixed
*/
public static function get($key, string $group = '', bool $force = false, ?bool &$found = null)
public static function get($key, string $group = '', bool $force = false, ?bool &$status = null)
{
return wp_cache_get($key, $group, $force, $found);
return wp_cache_get($key, $group, $force, $status);
}

/**
Expand Down
Loading

0 comments on commit 273ca6d

Please sign in to comment.