| 1 |
<?php |
| 2 |
namespace epiphyt\Embed_Privacy\admin; |
| 3 |
|
| 4 |
/** |
| 5 |
* Admin user interface functionality. |
| 6 |
* |
| 7 |
* @author Epiphyt |
| 8 |
* @license GPL2 |
| 9 |
* @package epiphyt\Embed_Privacy |
| 10 |
* @since 1.10.0 |
| 11 |
*/ |
| 12 |
final class User_Interface { |
| 13 |
/** |
| 14 |
* Initialize functions. |
| 15 |
*/ |
| 16 |
public static function init() { |
| 17 |
\add_action( 'admin_enqueue_scripts', [ self::class, 'enqueue_assets' ] ); |
| 18 |
\add_filter( 'plugin_row_meta', [ self::class, 'add_meta_link' ], 10, 2 ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Add plugin meta links. |
| 23 |
* |
| 24 |
* @param array $input Registered links. |
| 25 |
* @param string $file Current plugin file. |
| 26 |
* @return array Merged links |
| 27 |
*/ |
| 28 |
public static function add_meta_link( $input, $file ) { |
| 29 |
// bail on other plugins |
| 30 |
if ( $file !== \plugin_basename( \EPI_EMBED_PRIVACY_BASE ) ) { |
| 31 |
return $input; |
| 32 |
} |
| 33 |
|
| 34 |
return \array_merge( |
| 35 |
$input, |
| 36 |
[ |
| 37 |
'<a href="https://epiph.yt/en/embed-privacy/documentation/?version=' . \rawurlencode( \EMBED_PRIVACY_VERSION ) . '" target="_blank" rel="noopener noreferrer">' . \esc_html__( 'Documentation', 'embed-privacy' ) . '</a>', |
| 38 |
] |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Enqueue admin assets. |
| 44 |
* |
| 45 |
* @param string $hook The current hook |
| 46 |
*/ |
| 47 |
public static function enqueue_assets( $hook ) { |
| 48 |
// we need it just on the post page |
| 49 |
if ( ( $hook !== 'post.php' && $hook !== 'post-new.php' ) || \get_current_screen()->id !== 'epi_embed' ) { |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
$suffix = \defined( 'WP_DEBUG' ) && \WP_DEBUG || \defined( 'SCRIPT_DEBUG' ) && \SCRIPT_DEBUG ? '' : '.min'; |
| 54 |
$script_path = \EPI_EMBED_PRIVACY_BASE . 'assets/js/admin/image-upload' . $suffix . '.js'; |
| 55 |
$script_url = \EPI_EMBED_PRIVACY_URL . 'assets/js/admin/image-upload' . $suffix . '.js'; |
| 56 |
|
| 57 |
\wp_enqueue_script( 'embed-privacy-admin-image-upload', $script_url, [ 'jquery' ], \filemtime( $script_path ), true ); |
| 58 |
|
| 59 |
$style_path = \EPI_EMBED_PRIVACY_BASE . 'assets/style/embed-privacy-admin' . $suffix . '.css'; |
| 60 |
$style_url = \EPI_EMBED_PRIVACY_URL . 'assets/style/embed-privacy-admin' . $suffix . '.css'; |
| 61 |
|
| 62 |
\wp_enqueue_style( 'embed-privacy-admin-style', $style_url, [], \filemtime( $style_path ) ); |
| 63 |
} |
| 64 |
} |
| 65 |
|