| 1 |
<?php |
| 2 |
namespace epiphyt\Embed_Privacy\admin; |
| 3 |
|
| 4 |
use WP_Screen; |
| 5 |
|
| 6 |
/** |
| 7 |
* Admin user interface functionality. |
| 8 |
* |
| 9 |
* @author Epiphyt |
| 10 |
* @license GPL2 |
| 11 |
* @package epiphyt\Embed_Privacy |
| 12 |
* @since 1.10.0 |
| 13 |
*/ |
| 14 |
final class User_Interface { |
| 15 |
/** |
| 16 |
* Initialize functions. |
| 17 |
*/ |
| 18 |
public static function init() { |
| 19 |
\add_action( 'admin_enqueue_scripts', [ self::class, 'enqueue_assets' ] ); |
| 20 |
\add_filter( 'plugin_row_meta', [ self::class, 'add_meta_link' ], 10, 2 ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Add plugin meta links. |
| 25 |
* |
| 26 |
* @param array $input Registered links |
| 27 |
* @param string $file Current plugin file |
| 28 |
* @return array Merged links |
| 29 |
*/ |
| 30 |
public static function add_meta_link( $input, $file ) { |
| 31 |
// bail on other plugins |
| 32 |
if ( $file !== \plugin_basename( \EPI_EMBED_PRIVACY_BASE ) ) { |
| 33 |
return $input; |
| 34 |
} |
| 35 |
|
| 36 |
return \array_merge( |
| 37 |
$input, |
| 38 |
[ |
| 39 |
'<a href="https://docs.epiph.yt/embed-privacy/?version=' . \rawurlencode( \EMBED_PRIVACY_VERSION ) . '" target="_blank" rel="noopener noreferrer">' . \esc_html__( 'Documentation', 'embed-privacy' ) . '</a>', |
| 40 |
] |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Enqueue admin assets. |
| 46 |
* |
| 47 |
* @param string $hook The current hook |
| 48 |
*/ |
| 49 |
public static function enqueue_assets( $hook ) { |
| 50 |
$screen = \get_current_screen(); |
| 51 |
$suffix = \defined( 'WP_DEBUG' ) && \WP_DEBUG || \defined( 'SCRIPT_DEBUG' ) && \SCRIPT_DEBUG ? '' : '.min'; |
| 52 |
|
| 53 |
if ( ! $screen instanceof WP_Screen ) { |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
if ( ( $hook === 'post.php' || $hook === 'post-new.php' ) || $screen->id === 'epi_embed' ) { |
| 58 |
$script_path = \EPI_EMBED_PRIVACY_BASE . 'assets/js/admin/image-upload' . $suffix . '.js'; |
| 59 |
$script_url = \EPI_EMBED_PRIVACY_URL . 'assets/js/admin/image-upload' . $suffix . '.js'; |
| 60 |
|
| 61 |
if ( \file_exists( $script_path ) ) { |
| 62 |
\wp_enqueue_script( 'embed-privacy-admin-image-upload', $script_url, [ 'jquery' ], (string) \filemtime( $script_path ), true ); |
| 63 |
\wp_localize_script( |
| 64 |
'embed-privacy-admin-image-upload', |
| 65 |
'embedPrivacyAdminImageUpload', |
| 66 |
[ |
| 67 |
'imageRemoved' => \__( 'Image removed.', 'embed-privacy' ), |
| 68 |
'imageSelected' => \__( 'Image selected.', 'embed-privacy' ), |
| 69 |
] |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
$style_path = \EPI_EMBED_PRIVACY_BASE . 'assets/style/embed-privacy-admin' . $suffix . '.css'; |
| 74 |
$style_url = \EPI_EMBED_PRIVACY_URL . 'assets/style/embed-privacy-admin' . $suffix . '.css'; |
| 75 |
|
| 76 |
if ( \file_exists( $style_path ) ) { |
| 77 |
\wp_enqueue_style( 'embed-privacy-admin-style', $style_url, [], (string) \filemtime( $style_path ) ); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
if ( $screen->id === 'settings_page_embed_privacy' ) { |
| 82 |
$script_path = \EPI_EMBED_PRIVACY_BASE . 'assets/js/admin/clipboard' . $suffix . '.js'; |
| 83 |
$script_url = \EPI_EMBED_PRIVACY_URL . 'assets/js/admin/clipboard' . $suffix . '.js'; |
| 84 |
|
| 85 |
if ( \file_exists( $script_path ) ) { |
| 86 |
\wp_enqueue_script( 'embed-privacy-admin-clipboard', $script_url, [], (string) \filemtime( $script_path ), true ); |
| 87 |
\wp_localize_script( |
| 88 |
'embed-privacy-admin-clipboard', |
| 89 |
'embedPrivacyAdminSettings', |
| 90 |
[ |
| 91 |
'supportDataCopiedToClipboardFailure' => \__( 'Support data could not be copied to clipboard!', 'embed-privacy' ), |
| 92 |
'supportDataCopiedToClipboardSuccess' => \__( 'Support data copied to clipboard!', 'embed-privacy' ), |
| 93 |
] |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
$style_path = \EPI_EMBED_PRIVACY_BASE . 'assets/style/settings' . $suffix . '.css'; |
| 98 |
$style_url = \EPI_EMBED_PRIVACY_URL . 'assets/style/settings' . $suffix . '.css'; |
| 99 |
|
| 100 |
if ( \file_exists( $style_path ) ) { |
| 101 |
\wp_enqueue_style( 'embed-privacy-admin-settings', $style_url, [], (string) \filemtime( $style_path ) ); |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|