| 1 |
<?php |
| 2 |
declare(strict_types=1); |
| 3 |
|
| 4 |
namespace Imagify\Admin; |
| 5 |
|
| 6 |
use Imagify\EventManagement\SubscriberInterface; |
| 7 |
use Imagify\User\User; |
| 8 |
|
| 9 |
/** |
| 10 |
* Admin Subscriber |
| 11 |
*/ |
| 12 |
class AdminSubscriber implements SubscriberInterface { |
| 13 |
|
| 14 |
/** |
| 15 |
* User instance. |
| 16 |
* |
| 17 |
* @var User |
| 18 |
*/ |
| 19 |
protected $user; |
| 20 |
|
| 21 |
/** |
| 22 |
* Instantiate the class |
| 23 |
* |
| 24 |
* @param User $user User instance. |
| 25 |
*/ |
| 26 |
public function __construct( User $user ) { |
| 27 |
$this->user = $user; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Returns an array of events this subscriber listens to |
| 32 |
* |
| 33 |
* @return array |
| 34 |
*/ |
| 35 |
public static function get_subscribed_events() { |
| 36 |
$basename = plugin_basename( IMAGIFY_FILE ); |
| 37 |
|
| 38 |
return [ |
| 39 |
'plugin_action_links_' . $basename => 'plugin_action_links', |
| 40 |
'network_admin_plugin_action_links_' . $basename => 'plugin_action_links', |
| 41 |
]; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Add links to the plugin row in the plugins list. |
| 46 |
* |
| 47 |
* @since 1.7 |
| 48 |
* |
| 49 |
* @param array $actions An array of action links. |
| 50 |
* @return array |
| 51 |
*/ |
| 52 |
public function plugin_action_links( $actions ) { |
| 53 |
$text = 1 !== $this->user->plan_id ? __( 'Documentation', 'imagify' ) : __( 'Upgrade', 'imagify' ); |
| 54 |
$url = 1 !== $this->user->plan_id ? 'documentation' : 'subscription'; |
| 55 |
$class = 1 !== $this->user->plan_id ? '' : ' class="imagify-plugin-upgrade"'; |
| 56 |
|
| 57 |
array_unshift( $actions, sprintf( '<a href="%s" target="_blank"%s>%s</a>', |
| 58 |
esc_url( imagify_get_external_url( $url ) ), |
| 59 |
$class, |
| 60 |
$text |
| 61 |
) ); |
| 62 |
|
| 63 |
array_unshift( $actions, sprintf( '<a href="%s">%s</a>', esc_url( get_imagify_admin_url( 'bulk-optimization' ) ), __( 'Bulk Optimization', 'imagify' ) ) ); |
| 64 |
array_unshift( $actions, sprintf( '<a href="%s">%s</a>', esc_url( get_imagify_admin_url() ), __( 'Settings', 'imagify' ) ) ); |
| 65 |
return $actions; |
| 66 |
} |
| 67 |
} |
| 68 |
|