plugin updates

This commit is contained in:
Tony Volpe
2024-11-15 13:53:04 -05:00
parent 1293d604ca
commit 0238f0c4ca
2009 changed files with 163492 additions and 89543 deletions

View File

@@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit0382efa3332217fe0a96bbbe57e91464::getLoader();
return ComposerAutoloaderInit4fff6e59f3e5ad878e4b5bf99ef89f0a::getLoader();

View File

@@ -6,6 +6,7 @@ $vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'WPMedia\\PluginFamily\\' => array($vendorDir . '/wp-media/plugin-family/src'),
'Imagify\\ThirdParty\\WPRocket\\' => array($baseDir . '/inc/3rd-party/wp-rocket/classes'),
'Imagify\\ThirdParty\\RegenerateThumbnails\\' => array($baseDir . '/inc/3rd-party/regenerate-thumbnails/classes'),
'Imagify\\ThirdParty\\NGG\\' => array($baseDir . '/inc/3rd-party/nextgen-gallery/classes'),

View File

@@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit0382efa3332217fe0a96bbbe57e91464
class ComposerAutoloaderInit4fff6e59f3e5ad878e4b5bf99ef89f0a
{
private static $loader;
@@ -24,12 +24,12 @@ class ComposerAutoloaderInit0382efa3332217fe0a96bbbe57e91464
require __DIR__ . '/platform_check.php';
spl_autoload_register(array('ComposerAutoloaderInit0382efa3332217fe0a96bbbe57e91464', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit4fff6e59f3e5ad878e4b5bf99ef89f0a', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\AutoloadWPMediaImagifyWordPressPlugin\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit0382efa3332217fe0a96bbbe57e91464', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit4fff6e59f3e5ad878e4b5bf99ef89f0a', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit0382efa3332217fe0a96bbbe57e91464::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit4fff6e59f3e5ad878e4b5bf99ef89f0a::getInitializer($loader));
$loader->register(true);

View File

@@ -7,9 +7,13 @@ namespace Composer\Autoload;
use Composer\AutoloadWPMediaImagifyWordPressPlugin\ClassLoader as ClassLoaderWPMediaImagifyWordPressPlugin;
class ComposerStaticInit0382efa3332217fe0a96bbbe57e91464
class ComposerStaticInit4fff6e59f3e5ad878e4b5bf99ef89f0a
{
public static $prefixLengthsPsr4 = array (
'W' =>
array (
'WPMedia\\PluginFamily\\' => 21,
),
'I' =>
array (
'Imagify\\ThirdParty\\WPRocket\\' => 28,
@@ -32,6 +36,10 @@ class ComposerStaticInit0382efa3332217fe0a96bbbe57e91464
);
public static $prefixDirsPsr4 = array (
'WPMedia\\PluginFamily\\' =>
array (
0 => __DIR__ . '/..' . '/wp-media/plugin-family/src',
),
'Imagify\\ThirdParty\\WPRocket\\' =>
array (
0 => __DIR__ . '/../..' . '/inc/3rd-party/wp-rocket/classes',
@@ -127,9 +135,9 @@ class ComposerStaticInit0382efa3332217fe0a96bbbe57e91464
public static function getInitializer(ClassLoaderWPMediaImagifyWordPressPlugin $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit0382efa3332217fe0a96bbbe57e91464::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0382efa3332217fe0a96bbbe57e91464::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit0382efa3332217fe0a96bbbe57e91464::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit4fff6e59f3e5ad878e4b5bf99ef89f0a::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit4fff6e59f3e5ad878e4b5bf99ef89f0a::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit4fff6e59f3e5ad878e4b5bf99ef89f0a::$classMap;
}, null, ClassLoaderWPMediaImagifyWordPressPlugin::class);
}

View File

@@ -2,17 +2,17 @@
"packages": [
{
"name": "composer/installers",
"version": "v2.2.0",
"version_normalized": "2.2.0.0",
"version": "v2.3.0",
"version_normalized": "2.3.0.0",
"source": {
"type": "git",
"url": "https://github.com/composer/installers.git",
"reference": "c29dc4b93137acb82734f672c37e029dfbd95b35"
"reference": "12fb2dfe5e16183de69e784a7b84046c43d97e8e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/installers/zipball/c29dc4b93137acb82734f672c37e029dfbd95b35",
"reference": "c29dc4b93137acb82734f672c37e029dfbd95b35",
"url": "https://api.github.com/repos/composer/installers/zipball/12fb2dfe5e16183de69e784a7b84046c43d97e8e",
"reference": "12fb2dfe5e16183de69e784a7b84046c43d97e8e",
"shasum": ""
},
"require": {
@@ -20,14 +20,14 @@
"php": "^7.2 || ^8.0"
},
"require-dev": {
"composer/composer": "1.6.* || ^2.0",
"composer/semver": "^1 || ^3",
"phpstan/phpstan": "^0.12.55",
"phpstan/phpstan-phpunit": "^0.12.16",
"symfony/phpunit-bridge": "^5.3",
"symfony/process": "^5"
"composer/composer": "^1.10.27 || ^2.7",
"composer/semver": "^1.7.2 || ^3.4.0",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-phpunit": "^1",
"symfony/phpunit-bridge": "^7.1.1",
"symfony/process": "^5 || ^6 || ^7"
},
"time": "2022-08-20T06:45:11+00:00",
"time": "2024-06-24T20:46:46+00:00",
"type": "composer-plugin",
"extra": {
"class": "Composer\\Installers\\Plugin",
@@ -84,6 +84,7 @@
"cockpit",
"codeigniter",
"concrete5",
"concreteCMS",
"croogo",
"dokuwiki",
"drupal",
@@ -130,7 +131,7 @@
],
"support": {
"issues": "https://github.com/composer/installers/issues",
"source": "https://github.com/composer/installers/tree/v2.2.0"
"source": "https://github.com/composer/installers/tree/v2.3.0"
},
"funding": [
{
@@ -186,6 +187,55 @@
"source": "https://github.com/dangoodman/composer-for-wordpress/tree/2.0.2"
},
"install-path": "../dangoodman/composer-for-wordpress"
},
{
"name": "wp-media/plugin-family",
"version": "v1.0.2",
"version_normalized": "1.0.2.0",
"source": {
"type": "git",
"url": "https://github.com/wp-media/plugin-family.git",
"reference": "1b827eed34842de10fa3c94fec3a0f32b14be8bd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/wp-media/plugin-family/zipball/1b827eed34842de10fa3c94fec3a0f32b14be8bd",
"reference": "1b827eed34842de10fa3c94fec3a0f32b14be8bd",
"shasum": ""
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"phpcompatibility/phpcompatibility-wp": "^2.0",
"phpstan/extension-installer": "^1.4",
"szepeviktor/phpstan-wordpress": "^1.3",
"wp-coding-standards/wpcs": "^3",
"wp-media/phpunit": "^3"
},
"time": "2024-10-25T16:27:40+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"WPMedia\\PluginFamily\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-3.0-or-later"
],
"authors": [
{
"name": "WP Media",
"email": "contact@wp-media.me",
"homepage": "https://wp-media.me"
}
],
"description": "Organizes and displays WP Media plugin family across other members.",
"support": {
"issues": "https://github.com/wp-media/plugin-family/issues",
"source": "https://github.com/wp-media/plugin-family/tree/v1.0.2"
},
"install-path": "../wp-media/plugin-family"
}
],
"dev": false,

View File

@@ -1,9 +1,9 @@
<?php return array(
'root' => array(
'name' => 'wp-media/imagify-plugin',
'pretty_version' => 'v2.2.2',
'version' => '2.2.2.0',
'reference' => '33e23dd026fd905ae6ae703be9456c84ae9ca591',
'pretty_version' => 'v2.2.3.2',
'version' => '2.2.3.2',
'reference' => '459768940c0ea4e9c483b42257f790dc51b3bde9',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -11,9 +11,9 @@
),
'versions' => array(
'composer/installers' => array(
'pretty_version' => 'v2.2.0',
'version' => '2.2.0.0',
'reference' => 'c29dc4b93137acb82734f672c37e029dfbd95b35',
'pretty_version' => 'v2.3.0',
'version' => '2.3.0.0',
'reference' => '12fb2dfe5e16183de69e784a7b84046c43d97e8e',
'type' => 'composer-plugin',
'install_path' => __DIR__ . '/./installers',
'aliases' => array(),
@@ -29,13 +29,22 @@
'dev_requirement' => false,
),
'wp-media/imagify-plugin' => array(
'pretty_version' => 'v2.2.2',
'version' => '2.2.2.0',
'reference' => '33e23dd026fd905ae6ae703be9456c84ae9ca591',
'pretty_version' => 'v2.2.3.2',
'version' => '2.2.3.2',
'reference' => '459768940c0ea4e9c483b42257f790dc51b3bde9',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'dev_requirement' => false,
),
'wp-media/plugin-family' => array(
'pretty_version' => 'v1.0.2',
'version' => '1.0.2.0',
'reference' => '1b827eed34842de10fa3c94fec3a0f32b14be8bd',
'type' => 'library',
'install_path' => __DIR__ . '/../wp-media/plugin-family',
'aliases' => array(),
'dev_requirement' => false,
),
),
);

View File

@@ -8,6 +8,9 @@ env:
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: "1"
permissions:
contents: read
jobs:
tests:
name: "CI"

View File

@@ -4,6 +4,9 @@ on:
- push
- pull_request
permissions:
contents: read
jobs:
tests:
name: "Lint"

View File

@@ -8,6 +8,9 @@ env:
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
SYMFONY_PHPUNIT_VERSION: ""
permissions:
contents: read
jobs:
tests:
name: "PHPStan"

View File

@@ -14,6 +14,7 @@
"Cockpit",
"CodeIgniter",
"concrete5",
"ConcreteCMS",
"Croogo",
"DokuWiki",
"Dolibarr",
@@ -102,15 +103,15 @@
"composer-plugin-api": "^1.0 || ^2.0"
},
"require-dev": {
"composer/composer": "1.6.* || ^2.0",
"composer/semver": "^1 || ^3",
"symfony/phpunit-bridge": "^5.3",
"phpstan/phpstan": "^0.12.55",
"symfony/process": "^5",
"phpstan/phpstan-phpunit": "^0.12.16"
"composer/composer": "^1.10.27 || ^2.7",
"composer/semver": "^1.7.2 || ^3.4.0",
"symfony/phpunit-bridge": "^7.1.1",
"phpstan/phpstan": "^1.11",
"symfony/process": "^5 || ^6 || ^7",
"phpstan/phpstan-phpunit": "^1"
},
"scripts": {
"test": "vendor/bin/simple-phpunit",
"phpstan": "vendor/bin/phpstan analyse"
"test": "@php vendor/bin/simple-phpunit",
"phpstan": "@php vendor/bin/phpstan analyse"
}
}

View File

@@ -1,12 +0,0 @@
parameters:
level: 8
paths:
- src
- tests
excludes_analyse:
- tests/Composer/Installers/Test/PolyfillTestCase.php
ignoreErrors:
- '~Test::[a-zA-Z0-9]+Provider\(\) return type~'
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon

View File

@@ -0,0 +1,12 @@
<?php
namespace Composer\Installers;
class BotbleInstaller extends BaseInstaller
{
/** @var array<string, string> */
protected $locations = array(
'plugin' => 'platform/plugins/{$name}/',
'theme' => 'platform/themes/{$name}/',
);
}

View File

@@ -46,7 +46,7 @@ class CakePHPInstaller extends BaseInstaller
/**
* Check if CakePHP version matches against a version
*
* @phpstan-param Constraint::STR_OP_* $matcher
* @phpstan-param '='|'=='|'<'|'<='|'>'|'>='|'<>'|'!=' $matcher
*/
protected function matchesCakeVersion(string $matcher, string $version): bool
{

View File

@@ -0,0 +1,15 @@
<?php
namespace Composer\Installers;
class ConcreteCMSInstaller extends BaseInstaller
{
/** @var array<string, string> */
protected $locations = array(
'core' => 'concrete/',
'block' => 'application/blocks/{$name}/',
'package' => 'packages/{$name}/',
'theme' => 'application/themes/{$name}/',
'update' => 'updates/{$name}/',
);
}

View File

@@ -20,5 +20,6 @@ class DrupalInstaller extends BaseInstaller
'console' => 'console/{$name}/',
'console-language' => 'console/language/{$name}/',
'config' => 'config/sync/',
'recipe' => 'recipes/{$name}',
);
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Composer\Installers;
class ForkCMSInstaller extends BaseInstaller
{
/** @var array<string, string> */
protected $locations = [
'module' => 'src/Modules/{$name}/',
'theme' => 'src/Themes/{$name}/'
];
/**
* Format package name.
*
* For package type fork-cms-module, cut off a trailing '-plugin' if present.
*
* For package type fork-cms-theme, cut off a trailing '-theme' if present.
*/
public function inflectPackageVars(array $vars): array
{
if ($vars['type'] === 'fork-cms-module') {
return $this->inflectModuleVars($vars);
}
if ($vars['type'] === 'fork-cms-theme') {
return $this->inflectThemeVars($vars);
}
return $vars;
}
/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectModuleVars(array $vars): array
{
$vars['name'] = $this->pregReplace('/^fork-cms-|-module|ForkCMS|ForkCms|Forkcms|forkcms|Module$/', '', $vars['name']);
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); // replace hyphens with spaces
$vars['name'] = str_replace(' ', '', ucwords($vars['name'])); // make module name camelcased
return $vars;
}
/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectThemeVars(array $vars): array
{
$vars['name'] = $this->pregReplace('/^fork-cms-|-theme|ForkCMS|ForkCms|Forkcms|forkcms|Theme$/', '', $vars['name']);
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); // replace hyphens with spaces
$vars['name'] = str_replace(' ', '', ucwords($vars['name'])); // make theme name camelcased
return $vars;
}
}

View File

@@ -26,6 +26,7 @@ class Installer extends LibraryInstaller
'agl' => 'AglInstaller',
'annotatecms' => 'AnnotateCmsInstaller',
'bitrix' => 'BitrixInstaller',
'botble' => 'BotbleInstaller',
'bonefish' => 'BonefishInstaller',
'cakephp' => 'CakePHPInstaller',
'chef' => 'ChefInstaller',
@@ -34,6 +35,7 @@ class Installer extends LibraryInstaller
'cockpit' => 'CockpitInstaller',
'codeigniter' => 'CodeIgniterInstaller',
'concrete5' => 'Concrete5Installer',
'concretecms' => 'ConcreteCMSInstaller',
'croogo' => 'CroogoInstaller',
'dframe' => 'DframeInstaller',
'dokuwiki' => 'DokuWikiInstaller',
@@ -45,6 +47,7 @@ class Installer extends LibraryInstaller
'ee3' => 'ExpressionEngineInstaller',
'ee2' => 'ExpressionEngineInstaller',
'ezplatform' => 'EzPlatformInstaller',
'fork' => 'ForkCMSInstaller',
'fuel' => 'FuelInstaller',
'fuelphp' => 'FuelphpInstaller',
'grav' => 'GravInstaller',
@@ -145,6 +148,9 @@ class Installer extends LibraryInstaller
}
$class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
/**
* @var BaseInstaller
*/
$installer = new $class($package, $this->composer, $this->getIO());
$path = $installer->getInstallPath($package, $frameworkType);
@@ -178,6 +184,8 @@ class Installer extends LibraryInstaller
/**
* {@inheritDoc}
*
* @param string $packageType
*/
public function supports($packageType)
{

View File

@@ -21,6 +21,7 @@ class MoodleInstaller extends BaseInstaller
'cachestore' => 'cache/stores/{$name}/',
'cachelock' => 'cache/locks/{$name}/',
'calendartype' => 'calendar/type/{$name}/',
'communication' => 'communication/provider/{$name}/',
'customfield' => 'customfield/field/{$name}/',
'fileconverter' => 'files/converter/{$name}/',
'format' => 'course/format/{$name}/',
@@ -33,20 +34,24 @@ class MoodleInstaller extends BaseInstaller
'editor' => 'lib/editor/{$name}/',
'enrol' => 'enrol/{$name}/',
'filter' => 'filter/{$name}/',
'forumreport' => 'mod/forum/report/{$name}/',
'gradeexport' => 'grade/export/{$name}/',
'gradeimport' => 'grade/import/{$name}/',
'gradereport' => 'grade/report/{$name}/',
'gradingform' => 'grade/grading/form/{$name}/',
'h5plib' => 'h5p/h5plib/{$name}/',
'local' => 'local/{$name}/',
'logstore' => 'admin/tool/log/store/{$name}/',
'ltisource' => 'mod/lti/source/{$name}/',
'ltiservice' => 'mod/lti/service/{$name}/',
'media' => 'media/player/{$name}/',
'message' => 'message/output/{$name}/',
'mlbackend' => 'lib/mlbackend/{$name}/',
'mnetservice' => 'mnet/service/{$name}/',
'paygw' => 'payment/gateway/{$name}/',
'plagiarism' => 'plagiarism/{$name}/',
'portfolio' => 'portfolio/{$name}/',
'qbank' => 'question/bank/{$name}/',
'qbehaviour' => 'question/behaviour/{$name}/',
'qformat' => 'question/format/{$name}/',
'qtype' => 'question/type/{$name}/',
@@ -57,6 +62,7 @@ class MoodleInstaller extends BaseInstaller
'scormreport' => 'mod/scorm/report/{$name}/',
'search' => 'search/engine/{$name}/',
'theme' => 'theme/{$name}/',
'tiny' => 'lib/editor/tiny/plugins/{$name}/',
'tinymce' => 'lib/editor/tinymce/plugins/{$name}/',
'profilefield' => 'user/profile/field/{$name}/',
'webservice' => 'webservice/{$name}/',

View File

@@ -0,0 +1,45 @@
{
"name": "wp-media/plugin-family",
"description": "Organizes and displays WP Media plugin family across other members.",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "WP Media",
"email": "contact@wp-media.me",
"homepage": "https://wp-media.me"
}
],
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"require-dev": {
"phpcompatibility/phpcompatibility-wp": "^2.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"wp-coding-standards/wpcs": "^3",
"wp-media/phpunit": "^3",
"phpstan/extension-installer": "^1.4",
"szepeviktor/phpstan-wordpress": "^1.3"
},
"autoload": {
"psr-4": {
"WPMedia\\PluginFamily\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"WPMedia\\PluginFamily\\Tests\\": "tests/"
}
},
"scripts": {
"install-codestandards": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run",
"phpcs": "phpcs --basepath=.",
"phpcs:fix": "phpcbf",
"test-unit": "\"vendor/bin/phpunit\" --testsuite unit --colors=always --configuration tests/Unit/phpunit.xml.dist --coverage-php tests/report/unit.cov",
"report-code-coverage": "\"vendor/bin/phpcov\" merge tests/report --clover tests/report/coverage.clover",
"phpstan": "vendor/bin/phpstan analyze --memory-limit=2G --no-progress"
}
}

View File

@@ -0,0 +1,254 @@
<?php
namespace WPMedia\PluginFamily\Controller;
/**
* Handles installation and Activation of plugin family members.
*/
class PluginFamily implements PluginFamilyInterface {
/**
* Error transient.
*
* @var string
*/
protected $error_transient = 'plugin_family_error';
/**
* Returns an array of events this subscriber listens to
*
* @return array
*/
public static function get_subscribed_events(): array {
$events = self::get_post_install_event();
$events['admin_notices'] = 'display_error_notice';
return $events;
}
/**
* Set post install event.
*
* @return array
*/
public static function get_post_install_event(): array {
$allowed_plugin = [
'uk-cookie-consent',
'backwpup',
'imagify',
'seo-by-rank-math',
'wp-rocket',
];
if ( ! isset( $_GET['action'], $_GET['_wpnonce'], $_GET['plugin_to_install'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return [];
}
$plugin = str_replace( 'plugin_family_install_', '', sanitize_text_field( wp_unslash( $_GET['action'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! in_array( $plugin, $allowed_plugin, true ) ) {
return [];
}
return [
'admin_post_plugin_family_install_' . $plugin => 'install_activate',
];
}
/**
* Process to install and activate plugin.
*
* @return void
*/
public function install_activate() {
if ( ! $this->is_allowed() ) {
wp_die(
'Plugin Installation is not allowed.',
'',
[ 'back_link' => true ]
);
}
// Install plugin.
$this->install();
// Activate plugin.
$result = activate_plugin( $this->get_plugin(), '', is_multisite() );
if ( is_wp_error( $result ) ) {
$this->set_error( $result );
}
wp_safe_redirect( wp_get_referer() );
exit;
}
/**
* Install plugin.
*
* @return void
*/
private function install() {
if ( $this->is_installed() ) {
return;
}
$upgrader_class = ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
if ( ! defined( 'ABSPATH' ) || ! file_exists( $upgrader_class ) ) {
wp_die(
'Plugin Installation failed. class-wp-upgrader.php not found',
'',
[ 'back_link' => true ]
);
}
require_once $upgrader_class; // @phpstan-ignore-line
$upgrader = new \Plugin_Upgrader( new \Automatic_Upgrader_Skin() );
$result = $upgrader->install( $this->get_download_url() );
if ( is_wp_error( $result ) ) {
$this->set_error( $result );
}
clearstatcache();
}
/**
* Check if plugin is installed.
*
* @return boolean
*/
private function is_installed(): bool {
return file_exists( WP_PLUGIN_DIR . '/' . $this->get_plugin() );
}
/**
* Check if installation is allowed.
*
* @return boolean
*/
private function is_allowed(): bool {
if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'plugin_family_install_' . $this->get_slug() ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
return false;
}
if ( ! current_user_can( is_multisite() ? 'manage_network_plugins' : 'install_plugins' ) ) {
return false;
}
return true;
}
/**
* Get plugin slug.
*
* @return string
*/
private function get_slug(): string {
return dirname( rawurldecode( sanitize_text_field( wp_unslash( $_GET['plugin_to_install'] ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
}
/**
* Get plugin identifier.
*
* @return string
*/
private function get_plugin(): string {
return rawurldecode( sanitize_text_field( wp_unslash( $_GET['plugin_to_install'] ) ) ) . '.php'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
}
/**
* Get plugin download url.
*
* @return string
*/
private function get_download_url(): string {
$plugin_install = ABSPATH . 'wp-admin/includes/plugin-install.php';
if ( ! defined( 'ABSPATH' ) || ! file_exists( $plugin_install ) ) {
wp_die(
'Plugin Installation failed. plugin-install.php not found',
'',
[ 'back_link' => true ]
);
}
require_once $plugin_install; // @phpstan-ignore-line
$data = [
'slug' => $this->get_slug(),
'fields' => [
'download_link' => true,
'short_description' => false,
'sections' => false,
'rating' => false,
'ratings' => false,
'downloaded' => false,
'last_updated' => false,
'added' => false,
'tags' => false,
'homepage' => false,
'donate_link' => false,
],
];
// Get Plugin Infos.
$plugin_info = plugins_api( 'plugin_information', $data );
if ( is_wp_error( $plugin_info ) ) {
$this->set_error( $plugin_info );
}
// Ensure that $plugin_info is an object before accessing the property.
if ( ! is_object( $plugin_info ) || ! isset( $plugin_info->download_link ) ) {
return '';
}
return $plugin_info->download_link;
}
/**
* Maybe display error notice.
*
* @return void
*/
public function display_error_notice() {
$errors = get_transient( $this->error_transient );
if ( ! $errors ) {
return;
}
if ( ! is_wp_error( $errors ) ) {
delete_transient( $this->error_transient );
return;
}
$errors = $errors->get_error_messages();
if ( ! $errors ) {
$errors[] = 'Installation process failed';
}
$notice = '<div class="error notice is-dismissible"><p>' . implode( '<br/>', $errors ) . '</p></div>';
echo wp_kses_post( $notice );
// Remove transient after displaying notice.
delete_transient( $this->error_transient );
}
/**
* Store an error message in a transient then redirect.
*
* @param object $error A WP_Error object.
* @return void
*/
private function set_error( $error ) {
set_transient( $this->error_transient, $error, 30 );
wp_safe_redirect( wp_get_referer() );
exit;
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace WPMedia\PluginFamily\Controller;
interface PluginFamilyInterface {
/**
* Process to install and activate plugin.
*
* @return void
*/
public function install_activate();
/**
* Maybe display error notice.
*
* @return void
*/
public function display_error_notice();
}

View File

@@ -0,0 +1,171 @@
<?php
namespace WPMedia\PluginFamily\Model;
/**
* Handles the data to be passed to the frontend.
*/
class PluginFamily {
/**
* An array of referrers for wp rocket.
*
* @var array
*/
protected $wp_rocket_referrer = [
'imagify' => 'imagify',
'seo-by-rank-math' => '',
'backwpup' => '',
'uk-cookie-consent' => '',
];
/**
* Get filtered plugins.
*
* @param string $main_plugin Main plugin installed.
*
* @return array
*/
public function get_filtered_plugins( string $main_plugin ): array {
$plugins = require_once 'wp_media_plugins.php';
return $this->filter_plugins_by_activation( $plugins, $main_plugin );
}
/**
* Filter plugins family data by activation status and returns both categorized and uncategorized format.
*
* @param array $plugins Array of family plugins.
* @param string $main_plugin Main plugin installed.
*
* @return array
*/
public function filter_plugins_by_activation( array $plugins, string $main_plugin ): array {
if ( empty( $plugins ) ) {
return [];
}
list( $active_plugins, $inactive_plugins ) = [ [], [] ];
foreach ( $plugins as $cat => $cat_data ) {
foreach ( $cat_data['plugins'] as $plugin => $data ) {
$plugin_path = $plugin . '.php';
$plugin_slug = dirname( $plugin );
$main_plugin_slug = dirname( $main_plugin );
$wpr_referrer = 'wp-rocket' !== $main_plugin_slug ? $this->wp_rocket_referrer[ $main_plugin_slug ] : '';
/**
* Check for activated plugins and pop them out of the array
* to re-add them back using array_merge to be displayed after
* plugins that are not installed or not activated.
*/
if ( is_plugin_active( $plugin_path ) && $main_plugin . '.php' !== $plugin_path ) {
// set cta data of active plugins.
$plugins[ $cat ]['plugins'][ $plugin ]['cta'] = [
'text' => 'Activated',
'url' => '#',
];
// Send active plugin to new array.
$active_plugins[ $plugin ] = $plugins[ $cat ]['plugins'][ $plugin ];
// Remove active plugin from current category.
$active_plugin = $plugins[ $cat ]['plugins'][ $plugin ];
unset( $plugins[ $cat ]['plugins'][ $plugin ] );
// Send active plugin to the end of array in current category.
$plugins[ $cat ]['plugins'][ $plugin ] = $active_plugin;
// Remove category with active plugin from current array.
$active_cat = $plugins[ $cat ];
unset( $plugins[ $cat ] );
// Send category with active plugins to the end of array.
$plugins[ $cat ] = $active_cat;
continue;
}
$install_activate_url = admin_url( 'admin-post.php' );
$args = [
'action' => 'plugin_family_install_' . $plugin_slug,
'_wpnonce' => wp_create_nonce( 'plugin_family_install_' . $plugin_slug ),
'plugin_to_install' => rawurlencode( $plugin ),
];
if ( 'imagify' === $plugin_slug ) {
$args = [
'action' => 'install_imagify_from_partner_' . $main_plugin_slug,
'_wpnonce' => wp_create_nonce( 'install_imagify_from_partner' ),
'_wp_http_referer' => rawurlencode( $this->get_current_url() ),
];
}
$install_activate_url = add_query_arg( $args, $install_activate_url );
// Set Installation link.
$plugins[ $cat ]['plugins'][ $plugin ]['cta'] = [
'text' => 'Install',
'url' => $install_activate_url,
];
// Create unique CTA data for WP Rocket.
if ( 'wp-rocket/wp-rocket' === $plugin ) {
$url = 'https://wp-rocket.me/?utm_source=' . $wpr_referrer . '-coupon&utm_medium=plugin&utm_campaign=' . $wpr_referrer;
$plugins[ $cat ]['plugins'][ $plugin ]['cta'] = [
'text' => 'Get it Now',
'url' => $url,
];
$plugins[ $cat ]['plugins'][ $plugin ]['link'] = $url;
}
// Set activation text.
if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_path ) ) {
$plugins[ $cat ]['plugins'][ $plugin ]['cta']['text'] = 'Activate';
if ( 'wp-rocket/wp-rocket' === $plugin ) {
$plugins[ $cat ]['plugins'][ $plugin ]['cta']['url'] = $install_activate_url;
}
}
// Send inactive plugins to new array.
$inactive_plugins[ $plugin ] = $plugins[ $cat ]['plugins'][ $plugin ];
}
// Remove main plugin from categorized array.
if ( isset( $plugins[ $cat ]['plugins'][ $main_plugin ] ) ) {
unset( $plugins[ $cat ]['plugins'][ $main_plugin ] );
}
}
$uncategorized = array_merge( $inactive_plugins, $active_plugins );
// Remove main plugin from uncategorized array.
unset( $uncategorized[ $main_plugin ] );
return [
'categorized' => $plugins,
'uncategorized' => $uncategorized,
];
}
/**
* Get the current URL.
* Gotten from Imagify_Partner Package.
*
* @return string
*/
protected function get_current_url(): string {
if ( ! isset( $_SERVER['SERVER_PORT'], $_SERVER['HTTP_HOST'] ) ) {
return '';
}
$port = (int) wp_unslash( $_SERVER['SERVER_PORT'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$port = 80 !== $port && 443 !== $port ? ( ':' . $port ) : '';
$url = ! empty( $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'] ) ? $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'] : ( ! empty( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
return 'http' . ( is_ssl() ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'] . $port . $url; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* WP Media plugin family data.
*/
return [
'optimize_performance' => [
'title' => 'Optimize Performance',
'plugins' => [
'wp-rocket/wp-rocket' => [
'logo' => [
'file' => 'logo-wp-rocket.svg',
'width' => '50%',
],
'title' => 'Speed Up Your Website, Instantly',
'desc' => 'WP Rocket is the easiest way to make your WordPress website faster and boost your Google PageSpeed score. Get more traffic, better engagement, and higher conversions effortlessly.',
'link' => '',
],
'imagify/imagify' => [
'logo' => [
'file' => 'logo-imagify.svg',
'width' => '50%',
],
'title' => 'Speed Up Your Website With Lighter Images',
'desc' => 'Imagify is the easiest WordPress image optimizer. It automatically compresses images, converts them to WebP and AVIF formats, and lets you resize and optimize with just one click!',
'link' => 'https://imagify.io/',
],
],
],
'boost_traffic' => [
'title' => 'Boost Traffic',
'plugins' => [
'seo-by-rank-math/rank-math' => [
'logo' => [
'file' => 'logo-rank-math.svg',
'width' => '60%',
],
'title' => 'The Swiss Army Knife of SEO Tools',
'desc' => 'Rank Math SEO is the Best WordPress SEO plugin with the features of many SEO and AI SEO tools in a single package to help multiply your SEO traffic.',
'link' => 'https://rankmath.com/wordpress/plugin/seo-suite/',
],
],
],
'protect_secure' => [
'title' => 'Protect & Secure',
'plugins' => [
'backwpup/backwpup' => [
'logo' => [
'file' => 'logo-backwpup.svg',
'width' => '60%',
],
'title' => 'The Easiest Way to Protect Your Website',
'desc' => 'BackWPup is the most comprehensive and user-friendly backup & restore plugin for WordPress. Easily schedule automatic backups, securely store and restore with just a few clicks!',
'link' => 'https://backwpup.com/',
],
'uk-cookie-consent/uk-cookie-consent' => [
'logo' => [
'file' => 'logo-termly.svg',
'width' => '50%',
],
'title' => 'GDPR/CCPA Cookie Consent Banner',
'desc' => 'One of the easiest, most comprehensive, and popular cookie consent plugins available. Google Gold Certified Partner to quickly comply with data privacy laws from around the world.',
'link' => 'https://termly.io/resources/articles/wordpress-cookies-guide/',
],
],
],
];