plugin updates
This commit is contained in:
@@ -1,26 +1,129 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Imagify\Admin;
|
||||
|
||||
use Imagify\Traits\InstanceGetterTrait;
|
||||
use Imagify\EventManagement\SubscriberInterface;
|
||||
use Imagify\User\User;
|
||||
use Imagify_Views;
|
||||
use WP_Admin_Bar;
|
||||
|
||||
/**
|
||||
* Admin bar handler
|
||||
*/
|
||||
class AdminBar {
|
||||
use InstanceGetterTrait;
|
||||
class AdminBar implements SubscriberInterface {
|
||||
/**
|
||||
* User instance.
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Launch the hooks.
|
||||
* AdminBar constructor.
|
||||
*
|
||||
* @return void
|
||||
* @param User $user User instance.
|
||||
*/
|
||||
public function init() {
|
||||
if ( wp_doing_ajax() ) {
|
||||
add_action( 'wp_ajax_imagify_get_admin_bar_profile', array( $this, 'get_admin_bar_profile_callback' ) );
|
||||
public function __construct( User $user ) {
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of events this subscriber listens to
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events(): array {
|
||||
return [
|
||||
'wp_ajax_imagify_get_admin_bar_profile' => 'get_admin_bar_profile_callback',
|
||||
'admin_bar_menu' => [ 'add_imagify_admin_bar_menu', IMAGIFY_INT_MAX ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Imagify menu in the admin bar.
|
||||
*
|
||||
* @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference.
|
||||
*/
|
||||
public function add_imagify_admin_bar_menu( $wp_admin_bar ) {
|
||||
if ( ! imagify_get_context( 'wp' )->current_user_can( 'manage' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! get_imagify_option( 'admin_bar_menu' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Parent.
|
||||
$wp_admin_bar->add_menu( array(
|
||||
'id' => 'imagify',
|
||||
'title' => 'Imagify',
|
||||
'href' => get_imagify_admin_url(),
|
||||
) );
|
||||
|
||||
// Settings.
|
||||
$wp_admin_bar->add_menu(array(
|
||||
'parent' => 'imagify',
|
||||
'id' => 'imagify-settings',
|
||||
'title' => __( 'Settings' ),
|
||||
'href' => get_imagify_admin_url(),
|
||||
) );
|
||||
|
||||
// Bulk Optimization.
|
||||
if ( ! is_network_admin() ) {
|
||||
$wp_admin_bar->add_menu(array(
|
||||
'parent' => 'imagify',
|
||||
'id' => 'imagify-bulk-optimization',
|
||||
'title' => __( 'Bulk Optimization', 'imagify' ),
|
||||
'href' => get_imagify_admin_url( 'bulk-optimization' ),
|
||||
) );
|
||||
}
|
||||
|
||||
// Documentation.
|
||||
$wp_admin_bar->add_menu(array(
|
||||
'parent' => 'imagify',
|
||||
'id' => 'imagify-documentation',
|
||||
'title' => __( 'Documentation', 'imagify' ),
|
||||
'href' => imagify_get_external_url( 'documentation' ),
|
||||
'meta' => array(
|
||||
'target' => '_blank',
|
||||
),
|
||||
) );
|
||||
|
||||
// Rate it.
|
||||
$wp_admin_bar->add_menu(array(
|
||||
'parent' => 'imagify',
|
||||
'id' => 'imagify-rate-it',
|
||||
/* translators: %s is WordPress.org. */
|
||||
'title' => sprintf( __( 'Rate Imagify on %s', 'imagify' ), 'WordPress.org' ),
|
||||
'href' => imagify_get_external_url( 'rate' ),
|
||||
'meta' => array(
|
||||
'target' => '_blank',
|
||||
),
|
||||
) );
|
||||
|
||||
// Quota & Profile informations.
|
||||
if ( defined( 'IMAGIFY_HIDDEN_ACCOUNT' ) && IMAGIFY_HIDDEN_ACCOUNT || ! get_imagify_option( 'api_key' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
$this->user->is_free()
|
||||
&&
|
||||
$this->user->get_percent_unconsumed_quota() > 20
|
||||
) {
|
||||
$wp_admin_bar->add_menu( [
|
||||
'parent' => 'imagify',
|
||||
'id' => 'imagify-upgrade-plan',
|
||||
'title' => '<button data-nonce="' . wp_create_nonce( 'imagify_get_pricing_' . get_current_user_id() ) . '" data-target="#imagify-pricing-modal" type="button" class="imagify-get-pricing-modal imagify-modal-trigger imagify-admin-bar-upgrade-plan">' . __( 'Upgrade Plan', 'imagify' ) . '</button>',
|
||||
] );
|
||||
}
|
||||
|
||||
$wp_admin_bar->add_menu( array(
|
||||
'parent' => 'imagify',
|
||||
'id' => 'imagify-profile',
|
||||
'title' => wp_nonce_field( 'imagify-get-admin-bar-profile', 'imagifygetadminbarprofilenonce', false, false ) . '<div id="wp-admin-bar-imagify-profile-loading" class="hide-if-no-js">' . __( 'Loading...', 'imagify' ) . '</div><div id="wp-admin-bar-imagify-profile-content" class="hide-if-no-js"></div>',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,22 +138,21 @@ class AdminBar {
|
||||
imagify_die();
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$views = Imagify_Views::get_instance();
|
||||
$unconsumed_quota = $views->get_quota_percent();
|
||||
$text = '';
|
||||
$button_text = '';
|
||||
$upgrade_link = '';
|
||||
|
||||
if ( $user->is_free() ) {
|
||||
if ( $this->user->is_free() ) {
|
||||
$text = esc_html__( 'Upgrade your plan now for more!', 'rocket' ) . '<br>' .
|
||||
esc_html__( 'From $5.99/month only, keep going with image optimization!', 'rocket' );
|
||||
$button_text = esc_html__( 'Upgrade My Plan', 'rocket' );
|
||||
$upgrade_link = IMAGIFY_APP_DOMAIN . '/subscription/?utm_source=plugin&utm_medium=notification';
|
||||
} elseif ( $user->is_growth() ) {
|
||||
} elseif ( $this->user->is_growth() ) {
|
||||
$text = esc_html__( 'Switch to Infinite plan for unlimited optimization:', 'rocket' ) . '<br>';
|
||||
|
||||
if ( $user->is_monthly ) {
|
||||
if ( $this->user->is_monthly ) {
|
||||
$text .= esc_html__( 'For $9.99/month, optimize as many images as you like!', 'rocket' );
|
||||
$upgrade_link = IMAGIFY_APP_DOMAIN . '/subscription/plan_switch/?label=infinite&payment_plan=1&utm_source=plugin&utm_medium=notification ';
|
||||
} else {
|
||||
@@ -64,11 +166,11 @@ class AdminBar {
|
||||
$data = [
|
||||
'quota_icon' => $views->get_quota_icon(),
|
||||
'quota_class' => $views->get_quota_class(),
|
||||
'plan_label' => $user->plan_label,
|
||||
'plan_with_quota' => $user->is_free() || $user->is_growth(),
|
||||
'plan_label' => $this->user->plan_label,
|
||||
'plan_with_quota' => $this->user->is_free() || $this->user->is_growth(),
|
||||
'unconsumed_quota' => $unconsumed_quota,
|
||||
'user_quota' => $user->quota,
|
||||
'next_update' => $user->next_date_update,
|
||||
'user_quota' => $this->user->quota,
|
||||
'next_update' => $this->user->next_date_update,
|
||||
'text' => $text,
|
||||
'button_text' => $button_text,
|
||||
'upgrade_link' => $upgrade_link,
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Imagify\Admin;
|
||||
|
||||
use Imagify\EventManagement\SubscriberInterface;
|
||||
use Imagify\User\User;
|
||||
|
||||
/**
|
||||
* Admin Subscriber
|
||||
*/
|
||||
class AdminSubscriber implements SubscriberInterface {
|
||||
|
||||
/**
|
||||
* User instance.
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Instantiate the class
|
||||
*
|
||||
* @param User $user User instance.
|
||||
*/
|
||||
public function __construct( User $user ) {
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of events this subscriber listens to
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
$basename = plugin_basename( IMAGIFY_FILE );
|
||||
|
||||
return [
|
||||
'plugin_action_links_' . $basename => 'plugin_action_links',
|
||||
'network_admin_plugin_action_links_' . $basename => 'plugin_action_links',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add links to the plugin row in the plugins list.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @param array $actions An array of action links.
|
||||
* @return array
|
||||
*/
|
||||
public function plugin_action_links( $actions ) {
|
||||
$text = 1 !== $this->user->plan_id ? __( 'Documentation', 'imagify' ) : __( 'Upgrade', 'imagify' );
|
||||
$url = 1 !== $this->user->plan_id ? 'documentation' : 'subscription';
|
||||
$class = 1 !== $this->user->plan_id ? '' : ' class="imagify-plugin-upgrade"';
|
||||
|
||||
array_unshift( $actions, sprintf( '<a href="%s" target="_blank"%s>%s</a>',
|
||||
esc_url( imagify_get_external_url( $url ) ),
|
||||
$class,
|
||||
$text
|
||||
) );
|
||||
|
||||
array_unshift( $actions, sprintf( '<a href="%s">%s</a>', esc_url( get_imagify_admin_url( 'bulk-optimization' ) ), __( 'Bulk Optimization', 'imagify' ) ) );
|
||||
array_unshift( $actions, sprintf( '<a href="%s">%s</a>', esc_url( get_imagify_admin_url() ), __( 'Settings', 'imagify' ) ) );
|
||||
return $actions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Imagify\Admin;
|
||||
|
||||
use Imagify\EventManagement\SubscriberInterface;
|
||||
use Imagify\Dependencies\WPMedia\PluginFamily\Controller\{ PluginFamily, PluginFamilyInterface };
|
||||
|
||||
/**
|
||||
* Process plugin family actions.
|
||||
*/
|
||||
class PluginFamilySubscriber implements SubscriberInterface, PluginFamilyInterface {
|
||||
|
||||
/**
|
||||
* PluginFamily instance.
|
||||
*
|
||||
* @var PluginFamily
|
||||
*/
|
||||
protected $plugin_family;
|
||||
|
||||
/**
|
||||
* Instantiate the class
|
||||
*
|
||||
* @param PluginFamily $plugin_family PluginFamily instance.
|
||||
*/
|
||||
public function __construct( PluginFamily $plugin_family ) {
|
||||
$this->plugin_family = $plugin_family;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of events this subscriber listens to
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
$events = PluginFamily::get_subscribed_events();
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process to install & activate plugin.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function install_activate() {
|
||||
$this->plugin_family->install_activate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display error notice if available.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function display_error_notice() {
|
||||
$this->plugin_family->display_error_notice();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Imagify\Admin;
|
||||
|
||||
use Imagify\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
|
||||
use Imagify\Dependencies\WPMedia\PluginFamily\Controller\PluginFamily;
|
||||
|
||||
/**
|
||||
* Service provider for Admin.
|
||||
*/
|
||||
class ServiceProvider extends AbstractServiceProvider {
|
||||
/**
|
||||
* Services provided by this provider
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $provides = [
|
||||
'admin_bar',
|
||||
'admin_subscriber',
|
||||
'plugin_family',
|
||||
'plugin_family_subscriber',
|
||||
];
|
||||
|
||||
/**
|
||||
* Subscribers provided by this provider
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $subscribers = [
|
||||
'admin_bar',
|
||||
'admin_subscriber',
|
||||
'plugin_family_subscriber',
|
||||
];
|
||||
|
||||
/**
|
||||
* Registers the provided classes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
|
||||
$this->getContainer()->share( 'admin_bar', AdminBar::class )
|
||||
->addArgument( $this->getContainer()->get( 'user' ) );
|
||||
$this->getContainer()->share( 'admin_subscriber', AdminSubscriber::class )
|
||||
->addArgument( $this->getContainer()->get( 'user' ) );
|
||||
|
||||
$this->getContainer()->add( 'plugin_family', PluginFamily::class );
|
||||
|
||||
$this->getContainer()->add( 'plugin_family_subscriber', PluginFamilySubscriber::class )
|
||||
->addArgument( $this->getContainer()->get( 'plugin_family' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subscribers array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_subscribers() {
|
||||
return $this->subscribers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
|
||||
namespace Imagify\Dependencies\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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Imagify\Dependencies\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();
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace Imagify\Dependencies\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
|
||||
}
|
||||
}
|
||||
@@ -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/',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -1638,7 +1638,7 @@ abstract class AbstractProcess implements ProcessInterface {
|
||||
|
||||
$keys = array_keys( $sizes );
|
||||
$non_next_gen_keys = array_values(array_filter($keys, function ( $key ) {
|
||||
return strpos( $key, $this->format ) === false;
|
||||
return strpos( (string) $key, $this->format ) === false;
|
||||
}));
|
||||
|
||||
return array_reduce($non_next_gen_keys, function ( $is_fully, $key ) use ( $sizes ) {
|
||||
|
||||
@@ -42,7 +42,7 @@ class Display implements SubscriberInterface {
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'template_redirect' => [ 'start_content_process', -1000 ],
|
||||
'template_redirect' => 'start_content_process',
|
||||
'imagify_process_webp_content' => 'process_content',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -115,7 +115,6 @@ class Plugin {
|
||||
\Imagify\Auth\Basic::get_instance()->init();
|
||||
\Imagify\Job\MediaOptimization::get_instance()->init();
|
||||
Bulk::get_instance()->init();
|
||||
AdminBar::get_instance()->init();
|
||||
|
||||
if ( is_admin() ) {
|
||||
Notices::get_instance()->init();
|
||||
@@ -190,7 +189,6 @@ class Plugin {
|
||||
require_once $inc_path . 'functions/i18n.php';
|
||||
require_once $inc_path . 'functions/partners.php';
|
||||
require_once $inc_path . 'common/attachments.php';
|
||||
require_once $inc_path . 'common/admin-bar.php';
|
||||
require_once $inc_path . 'common/partners.php';
|
||||
require_once $inc_path . '3rd-party/3rd-party.php';
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Imagify\User;
|
||||
|
||||
use Imagify\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
|
||||
|
||||
/**
|
||||
* Service provider for Picture display
|
||||
*/
|
||||
class ServiceProvider extends AbstractServiceProvider {
|
||||
/**
|
||||
* Services provided by this provider
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $provides = [
|
||||
'user',
|
||||
];
|
||||
|
||||
/**
|
||||
* Registers the provided classes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
$this->getContainer()->add( 'user', User::class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subscribers array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_subscribers() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class User {
|
||||
$this->next_date_update = $user->next_date_update;
|
||||
$this->is_active = $user->is_active;
|
||||
$this->is_monthly = $user->is_monthly;
|
||||
$this->error = false;
|
||||
$this->error = is_wp_error( $user );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user