| 1 |
<?php |
| 2 |
namespace Depicter\WordPress; |
| 3 |
|
| 4 |
use Depicter\Services\ClientService; |
| 5 |
use WPEmerge\ServiceProviders\ServiceProviderInterface; |
| 6 |
|
| 7 |
/** |
| 8 |
* Register admin-related entities and hooks, like admin menu pages. |
| 9 |
*/ |
| 10 |
class AdminServiceProvider implements ServiceProviderInterface { |
| 11 |
|
| 12 |
/** |
| 13 |
* {@inheritDoc} |
| 14 |
*/ |
| 15 |
public function register( $container ) { |
| 16 |
$app = $container[ WPEMERGE_APPLICATION_KEY ]; |
| 17 |
|
| 18 |
$container['depicter.system.check'] = function() { |
| 19 |
return new SystemCheckService(); |
| 20 |
}; |
| 21 |
|
| 22 |
// register deactivation feedback |
| 23 |
$container[ 'depicter.deactivation.feedback' ] = function () { |
| 24 |
return new DeactivationFeedbackService(); |
| 25 |
}; |
| 26 |
$app->alias( 'deactivationFeedback', 'depicter.deactivation.feedback' ); |
| 27 |
|
| 28 |
// register client service |
| 29 |
$container['depicter.services.client.api'] = function() { |
| 30 |
return new ClientService(); |
| 31 |
}; |
| 32 |
$app->alias( 'client', 'depicter.services.client.api' ); |
| 33 |
|
| 34 |
// register wp file upload service |
| 35 |
$container['depicter.services.file.uploader'] = function() { |
| 36 |
return new FileUploaderService(); |
| 37 |
}; |
| 38 |
$app->alias( 'fileUploader', 'depicter.services.file.uploader' ); |
| 39 |
|
| 40 |
// register wp scheduling service |
| 41 |
$container['depicter.services.schedule'] = function() { |
| 42 |
return new SchedulingService(); |
| 43 |
}; |
| 44 |
$app->alias( 'schedule', 'depicter.services.schedule' ); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* {@inheritDoc} |
| 49 |
*/ |
| 50 |
public function bootstrap( $container ) { |
| 51 |
|
| 52 |
if ( is_admin() ){ |
| 53 |
|
| 54 |
// Only executes in admin pages |
| 55 |
if( ! ( defined('DOING_AJAX') && DOING_AJAX ) ){ |
| 56 |
\Depicter::resolve('depicter.deactivation.feedback'); |
| 57 |
\Depicter::resolve('depicter.auto.update.check' ); |
| 58 |
\Depicter::resolve('depicter.system.check'); |
| 59 |
|
| 60 |
\Depicter::client()->authorize(); |
| 61 |
} |
| 62 |
|
| 63 |
add_filter( 'plugin_action_links_' . DEPICTER_PLUGIN_BASENAME, [ $this, 'plugin_action_links' ] ); |
| 64 |
add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 ); |
| 65 |
} |
| 66 |
|
| 67 |
\Depicter::schedule()->hooks(); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Adds action links to the plugin list table |
| 72 |
* |
| 73 |
* @param array $links An array of plugin action links. |
| 74 |
* |
| 75 |
* @return array An array of plugin action links. |
| 76 |
*/ |
| 77 |
public function plugin_action_links( $links ) { |
| 78 |
|
| 79 |
if ( \Depicter::auth()->isPaid() ) { |
| 80 |
return $links; |
| 81 |
} |
| 82 |
|
| 83 |
$links['go-pro'] = sprintf( '<a href="%1$s" target="_blank" class="depicter-go-pro">%2$s</a>', |
| 84 |
'https://depicter.com/pricing?utm_source=depicter&utm_medium=depicter-free&utm_campaign=free-to-pro&utm_term=unlock-plugins-table', |
| 85 |
esc_html__( 'Upgrade to PRO', 'depicter' ) |
| 86 |
); |
| 87 |
|
| 88 |
return $links; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Adds row meta links to the plugin list table |
| 93 |
* |
| 94 |
* @param array $plugin_meta An array of the plugin's metadata, including |
| 95 |
* the version, author, author URI, and plugin URI. |
| 96 |
* @param string $plugin_file Path to the plugin file, relative to the plugins |
| 97 |
* directory. |
| 98 |
* |
| 99 |
* @return array |
| 100 |
*/ |
| 101 |
public function plugin_row_meta( $plugin_meta, $plugin_file ) { |
| 102 |
if ( DEPICTER_PLUGIN_BASENAME === $plugin_file ) { |
| 103 |
$row_meta = [ |
| 104 |
'video' => '<a href="https://www.youtube.com/@depicterApp" target="_blank">' . esc_html__( 'Video Tutorials', 'depicter' ) . '</a>', |
| 105 |
]; |
| 106 |
|
| 107 |
$plugin_meta = array_merge( $plugin_meta, $row_meta ); |
| 108 |
} |
| 109 |
|
| 110 |
return $plugin_meta; |
| 111 |
} |
| 112 |
|
| 113 |
} |
| 114 |
|