-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvideo-player-logos.php
More file actions
139 lines (115 loc) · 4.97 KB
/
video-player-logos.php
File metadata and controls
139 lines (115 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/*
* Plugin Name: Video Player Logos
* Plugin URI: https://github.com/CodeParrots/video-player-logos
* Description: Add a custom logo to the WordPress media player and media player toolbar.
* Author: Code Parrots
* Author URI: https://www.codeparrots.com
* Version: 1.0.0
* Text Domain: video-player-logos
* License: GPL v2 or later
*/
class CP_Video_Player_Logos {
public static $version = '1.0.0';
public $options = [
'overlay_logo' => '',
'overlay_location' => 'top-left',
'toolbar_logo' => '',
];
public function __construct() {
add_action( 'admin_init', [ $this, 'media_settings' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
}
public function media_settings() {
$this->options = get_option( 'video_player_logo', $this->options );
/* Register Settings */
register_setting(
'media',
'video_player_logo',
function( $input ) {
$input['overlay_logo'] = isset( $input['overlay_logo'] ) ? esc_url( $input['overlay_logo'] ) : '';
$input['overlay_location'] = isset( $input['overlay_location'] ) ? sanitize_text_field( $input['overlay_location'] ) : 'top-left';
$input['toolbar_logo'] = isset( $input['toolbar_logo'] ) ? esc_url( $input['toolbar_logo'] ) : '';
return $input;
}
);
add_settings_section(
'cp-video-player',
esc_html__( 'Video Player', 'video-player-logos' ),
function() {
echo wpautop( __( 'Customize the video player globally on your site.', 'video-player-logos' ) );
},
'media'
);
add_settings_field(
'overlay_logo',
esc_html__( 'Video Player Overlay Logo', 'video-player-logos' ),
function() {
?>
<label for="overlay_logo">
<input id="overlay_logo" type="text" value="<?php echo $this->options['overlay_logo']; ?>" name="video_player_logo[overlay_logo]" class="widefat" />
</label>
<p class="description"><?php esc_html_e( 'Enter the URL to the image you would like to display in the video player.', 'video-player-logos' ); ?></p>
<?php
},
'media',
'cp-video-player'
);
add_settings_field(
'overlay_location',
esc_html__( 'Video Player Overlay Logo Location', 'video-player-logos' ),
function() {
?>
<label for="overlay_location-1">
<input id="overlay_location-1" type="radio" value="top-left" name="video_player_logo[overlay_location]" <?php checked( $this->options['overlay_location'], 'top-left' ); ?>>
<?php esc_html_e( 'Top Left', 'video-player-logos' ); ?>
</label>
<label for="overlay_location-2">
<input id="overlay_location-2" type="radio" value="top-right" name="video_player_logo[overlay_location]" <?php checked( $this->options['overlay_location'], 'top-right' ); ?>>
<?php esc_html_e( 'Top Right', 'video-player-logos' ); ?>
</label>
<label for="overlay_location-3">
<input id="overlay_location-3" type="radio" value="bottom-left" name="video_player_logo[overlay_location]" <?php checked( $this->options['overlay_location'], 'bottom-left' ); ?>>
<?php esc_html_e( 'Bottom Left', 'video-player-logos' ); ?>
</label>
<label for="overlay_location-4">
<input id="overlay_location-4" type="radio" value="bottom-right" name="video_player_logo[overlay_location]" <?php checked( $this->options['overlay_location'], 'bottom-right' ); ?>>
<?php esc_html_e( 'Bottom Right', 'video-player-logos' ); ?>
</label>
<label for="overlay_location-5">
<input id="overlay_location-5" type="radio" value="center" name="video_player_logo[overlay_location]" <?php checked( $this->options['overlay_location'], 'center' ); ?>>
<?php esc_html_e( 'Center', 'video-player-logos' ); ?>
</label>
<p class="description"><?php esc_html_e( 'Select the location of the video player overlay logo.', 'video-player-logos' ); ?></p>
<?php
},
'media',
'cp-video-player'
);
add_settings_field(
'toolbar_logo',
esc_html__( 'Video Player Toolbar Logo', 'video-player-logos' ),
function() {
?>
<label for="toolbar_logo">
<input id="toolbar_logo" type="text" value="<?php echo $this->options['toolbar_logo']; ?>" name="video_player_logo[toolbar_logo]" class="widefat" />
</label>
<p class="description"><?php esc_html_e( 'Enter the URL to the image you would like to display in the video player toolbar.', 'video-player-logos' ); ?></p>
<?php
},
'media',
'cp-video-player'
);
}
/**
* Enqueue the scripts and styles.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
wp_enqueue_script( 'video-player-logos', plugin_dir_url( __FILE__ ) . '/assets/js/video-player-logo.js', [ 'jquery', 'wp-mediaelement' ], self::$version, true );
wp_localize_script( 'video-player-logos', 'videoPlayerLogo', apply_filters( 'video_player_logos', get_option( 'video_player_logo', $this->options ) ) );
wp_enqueue_style( 'video-player-logos', plugin_dir_url( __FILE__ ) . '/assets/css/video-player-logo.css', [ 'wp-mediaelement' ], self::$version, 'all' );
}
}
new CP_Video_Player_Logos();