| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Admin Config Functions |
|---|
| 4 | * |
|---|
| 5 | * Various functions relating to the various administration screens |
|---|
| 6 | * |
|---|
| 7 | * @package youtube-embed |
|---|
| 8 | */ |
|---|
| 9 | |
|---|
| 10 | /** |
|---|
| 11 | * Add Settings link to plugin list |
|---|
| 12 | * |
|---|
| 13 | * Add a Settings link to the options listed against this plugin |
|---|
| 14 | * |
|---|
| 15 | * @param string $links Current links. |
|---|
| 16 | * @param string $file File in use. |
|---|
| 17 | * @return string Links, now with settings added. |
|---|
| 18 | */ |
|---|
| 19 | function ye_add_settings_link( $links, $file ) { |
|---|
| 20 | |
|---|
| 21 | static $this_plugin; |
|---|
| 22 | |
|---|
| 23 | if ( ! $this_plugin ) { |
|---|
| 24 | $this_plugin = plugin_basename( __FILE__ ); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | if ( strpos( $file, 'youtube-embed.php' ) !== false ) { |
|---|
| 28 | $settings_link = '<a href="admin.php?page=ye-general-options">' . __( 'Settings', 'youtube-embed' ) . '</a>'; |
|---|
| 29 | array_unshift( $links, $settings_link ); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | return $links; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | add_filter( 'plugin_action_links', 'ye_add_settings_link', 10, 2 ); |
|---|
| 36 | |
|---|
| 37 | /** |
|---|
| 38 | * Add meta to plugin details |
|---|
| 39 | * |
|---|
| 40 | * Add options to plugin meta line |
|---|
| 41 | * |
|---|
| 42 | * @param string $links Current links. |
|---|
| 43 | * @param string $file File in use. |
|---|
| 44 | * @return string Links, now with settings added. |
|---|
| 45 | */ |
|---|
| 46 | function ye_set_plugin_meta( $links, $file ) { |
|---|
| 47 | |
|---|
| 48 | if ( strpos( $file, 'youtube-embed.php' ) !== false ) { |
|---|
| 49 | |
|---|
| 50 | $links = array_merge( $links, array( '<a href="https://github.com/squaredcode/youtube-embed">' . __( 'Github', 'youtube-embed' ) . '</a>' ) ); |
|---|
| 51 | |
|---|
| 52 | $links = array_merge( $links, array( '<a href="https://wordpress.org/support/plugin/youtube-embed">' . __( 'Support', 'youtube-embed' ) . '</a>' ) ); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | return $links; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | add_filter( 'plugin_row_meta', 'ye_set_plugin_meta', 10, 2 ); |
|---|
| 59 | |
|---|
| 60 | /** |
|---|
| 61 | * Admin Screen Initialisation |
|---|
| 62 | * |
|---|
| 63 | * Set up admin menu and submenu options |
|---|
| 64 | * |
|---|
| 65 | * @uses ye_contextual_help_type Work out help type. |
|---|
| 66 | */ |
|---|
| 67 | function ye_menu_initialise() { |
|---|
| 68 | |
|---|
| 69 | // Get level access for menus. |
|---|
| 70 | |
|---|
| 71 | $options = ye_get_general_defaults(); |
|---|
| 72 | |
|---|
| 73 | $menu_access = $options['menu_access']; |
|---|
| 74 | |
|---|
| 75 | // Add main admin option. |
|---|
| 76 | |
|---|
| 77 | $menu_icon = 'dashicons-video-alt3'; |
|---|
| 78 | |
|---|
| 79 | add_menu_page( __( 'About Embeds for YouTube', 'youtube-embed' ), __( 'Embeds for YouTube', 'youtube-embed' ), $menu_access, 'ye-profile-options', 'ye_profile_options', $menu_icon, 12 ); |
|---|
| 80 | |
|---|
| 81 | // Add profiles sub-menu. |
|---|
| 82 | |
|---|
| 83 | global $ye_profiles_hook; |
|---|
| 84 | |
|---|
| 85 | $ye_profiles_hook = add_submenu_page( 'ye-profile-options', __( 'Embeds for YouTube Profiles', 'youtube-embed' ), __( 'Profiles', 'youtube-embed' ), $menu_access, 'ye-profile-options', 'ye_profile_options' ); |
|---|
| 86 | |
|---|
| 87 | add_action( 'load-' . $ye_profiles_hook, 'ye_add_profiles_help' ); |
|---|
| 88 | |
|---|
| 89 | // Add lists sub-menu. |
|---|
| 90 | |
|---|
| 91 | global $ye_lists_hook; |
|---|
| 92 | |
|---|
| 93 | $ye_lists_hook = add_submenu_page( 'ye-profile-options', __( 'Embeds for YouTube Lists', 'youtube-embed' ), __( 'Lists', 'youtube-embed' ), $menu_access, 'ye-list-options', 'ye_list_options' ); |
|---|
| 94 | |
|---|
| 95 | add_action( 'load-' . $ye_lists_hook, 'ye_add_lists_help' ); |
|---|
| 96 | |
|---|
| 97 | // If installed, add link to Video Overlay Ads plugin. |
|---|
| 98 | |
|---|
| 99 | if ( function_exists( 'video_overlay_create_menu' ) ) { |
|---|
| 100 | |
|---|
| 101 | add_submenu_page( 'ye-profile-options', __( 'Video Overlay Ads', 'youtube-embed' ), __( 'Video Overlay Ads', 'youtube-embed' ), 'administrator', 'ye-video-overlay', 'video_overlay_settings_page' ); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | // If installed, add link to Video SEO. |
|---|
| 105 | |
|---|
| 106 | if ( class_exists( 'wpseo_Video_Sitemap' ) ) { |
|---|
| 107 | |
|---|
| 108 | add_submenu_page( 'ye-profile-options', __( 'Video SEO', 'youtube-embed' ), __( 'Video SEO', 'youtube-embed' ), 'manage_options', 'ye-wpseo-video', 'wpseo_Video_Sitemap::admin_panel' ); |
|---|
| 109 | |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | // Add settings sub-menu. |
|---|
| 113 | |
|---|
| 114 | global $ye_options_hook; |
|---|
| 115 | |
|---|
| 116 | $ye_options_hook = add_submenu_page( 'options-general.php', __( 'Embeds for YouTube Settings', 'youtube-embed' ), __( 'Embeds for YouTube', 'youtube-embed' ), $menu_access, 'ye-general-options', 'ye_general_options' ); |
|---|
| 117 | |
|---|
| 118 | add_action( 'load-' . $ye_options_hook, 'ye_add_options_help' ); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | add_action( 'admin_menu', 'ye_menu_initialise' ); |
|---|
| 122 | |
|---|
| 123 | /** |
|---|
| 124 | * Include general options screen |
|---|
| 125 | * |
|---|
| 126 | * XHTML options screen to prompt and update some general plugin options |
|---|
| 127 | */ |
|---|
| 128 | function ye_general_options() { |
|---|
| 129 | |
|---|
| 130 | include_once plugin_dir_path( __FILE__ ) . 'options-general.php'; |
|---|
| 131 | |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | /** |
|---|
| 135 | * Include profile options screen |
|---|
| 136 | * |
|---|
| 137 | * XHTML options screen to prompt and update profile options |
|---|
| 138 | */ |
|---|
| 139 | function ye_profile_options() { |
|---|
| 140 | |
|---|
| 141 | include_once plugin_dir_path( __FILE__ ) . 'options-profiles.php'; |
|---|
| 142 | |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | /** |
|---|
| 146 | * Include list options screen |
|---|
| 147 | * |
|---|
| 148 | * XHTML options screen to prompt and update list options |
|---|
| 149 | */ |
|---|
| 150 | function ye_list_options() { |
|---|
| 151 | |
|---|
| 152 | include_once plugin_dir_path( __FILE__ ) . 'options-lists.php'; |
|---|
| 153 | |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | /** |
|---|
| 157 | * Add Options Help |
|---|
| 158 | * |
|---|
| 159 | * Add help tab to options screen |
|---|
| 160 | * |
|---|
| 161 | * @uses ye_options_help Return help text. |
|---|
| 162 | */ |
|---|
| 163 | function ye_add_options_help() { |
|---|
| 164 | |
|---|
| 165 | global $ye_options_hook; |
|---|
| 166 | $screen = get_current_screen(); |
|---|
| 167 | |
|---|
| 168 | if ( $screen->id != $ye_options_hook ) { |
|---|
| 169 | return; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | $screen->add_help_tab( |
|---|
| 173 | array( |
|---|
| 174 | 'id' => 'options-help-tab', |
|---|
| 175 | 'title' => __( 'Help', 'youtube-embed' ), |
|---|
| 176 | 'content' => youtube_embed_help( 'options' ), |
|---|
| 177 | ) |
|---|
| 178 | ); |
|---|
| 179 | |
|---|
| 180 | $screen->add_help_tab( |
|---|
| 181 | array( |
|---|
| 182 | 'id' => 'options-links-tab', |
|---|
| 183 | 'title' => __( 'Links', 'youtube-embed' ), |
|---|
| 184 | 'content' => youtube_embed_help( 'options', 'links' ), |
|---|
| 185 | ) |
|---|
| 186 | ); |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | /** |
|---|
| 190 | * Add Profiles Help |
|---|
| 191 | * |
|---|
| 192 | * Add help tab to profiles screen |
|---|
| 193 | * |
|---|
| 194 | * @uses ye_profiles_help Return help text. |
|---|
| 195 | */ |
|---|
| 196 | function ye_add_profiles_help() { |
|---|
| 197 | |
|---|
| 198 | global $ye_profiles_hook; |
|---|
| 199 | $screen = get_current_screen(); |
|---|
| 200 | |
|---|
| 201 | if ( $screen->id != $ye_profiles_hook ) { |
|---|
| 202 | return; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | $screen->add_help_tab( |
|---|
| 206 | array( |
|---|
| 207 | 'id' => 'profiles-help-tab', |
|---|
| 208 | 'title' => __( 'Help', 'youtube-embed' ), |
|---|
| 209 | 'content' => youtube_embed_help( 'profiles' ), |
|---|
| 210 | ) |
|---|
| 211 | ); |
|---|
| 212 | |
|---|
| 213 | $screen->add_help_tab( |
|---|
| 214 | array( |
|---|
| 215 | 'id' => 'profiles-links-tab', |
|---|
| 216 | 'title' => __( 'Links', 'youtube-embed' ), |
|---|
| 217 | 'content' => youtube_embed_help( 'profiles', 'links' ), |
|---|
| 218 | ) |
|---|
| 219 | ); |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | /** |
|---|
| 223 | * Add Lists Help |
|---|
| 224 | * |
|---|
| 225 | * Add help tab to lists screen |
|---|
| 226 | * |
|---|
| 227 | * @uses ye_lists_help Return help text. |
|---|
| 228 | */ |
|---|
| 229 | function ye_add_lists_help() { |
|---|
| 230 | |
|---|
| 231 | global $ye_lists_hook; |
|---|
| 232 | $screen = get_current_screen(); |
|---|
| 233 | |
|---|
| 234 | if ( $screen->id != $ye_lists_hook ) { |
|---|
| 235 | return; |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | $screen->add_help_tab( |
|---|
| 239 | array( |
|---|
| 240 | 'id' => 'lists-help-tab', |
|---|
| 241 | 'title' => __( 'Help', 'youtube-embed' ), |
|---|
| 242 | 'content' => youtube_embed_help( 'lists' ), |
|---|
| 243 | ) |
|---|
| 244 | ); |
|---|
| 245 | |
|---|
| 246 | $screen->add_help_tab( |
|---|
| 247 | array( |
|---|
| 248 | 'id' => 'lists-links-tab', |
|---|
| 249 | 'title' => __( 'Links', 'youtube-embed' ), |
|---|
| 250 | 'content' => youtube_embed_help( 'lists', 'links' ), |
|---|
| 251 | ) |
|---|
| 252 | ); |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | /** |
|---|
| 256 | * Help Screens |
|---|
| 257 | * |
|---|
| 258 | * Generate help screen text |
|---|
| 259 | * |
|---|
| 260 | * @param string $screen Which help screen to return text for. |
|---|
| 261 | * @param string $tab Which tab of the help this is for. |
|---|
| 262 | * @return string Help Text. |
|---|
| 263 | */ |
|---|
| 264 | function youtube_embed_help( $screen, $tab = 'help' ) { |
|---|
| 265 | |
|---|
| 266 | $text = ''; |
|---|
| 267 | |
|---|
| 268 | if ( 'options' == $screen && 'help' == $tab ) { |
|---|
| 269 | |
|---|
| 270 | $text .= '<p>' . __( 'This screen allows you to select non-specific options for the Embeds for YouTube plugin. For the default embedding settings, please select the <a href="admin.php?page=ye-profile-options">Profiles</a> administration option.', 'youtube-embed' ) . '</p>'; |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | if ( 'profiles' == $screen && 'help' == $tab ) { |
|---|
| 274 | |
|---|
| 275 | $text .= '<p>' . __( 'This screen allows you to set the options for the default and additional profiles. If you don\'t specify a specific parameter when displaying your YouTube video then the default profile option will be used instead. Additional profiles, which you may name, can be used as well and used as required.', 'youtube-embed' ) . '</p>'; |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | if ( 'lists' == $screen && 'help' == $tab ) { |
|---|
| 279 | |
|---|
| 280 | $text .= '<p>' . __( 'This screen allows you to create lists of YouTube videos, which may be named. These lists can then be used in preference to a single video ID.', 'youtube-embed' ) . '</p>'; |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | $text .= '<p>' . __( 'Remember to click the Save Changes button at the bottom of the screen for any changes to take effect.', 'youtube-embed' ) . '</p>'; |
|---|
| 284 | |
|---|
| 285 | if ( 'links' == $tab ) { |
|---|
| 286 | |
|---|
| 287 | $text .= '<p><strong>' . __( 'For more information:', 'youtube-embed' ) . '</strong></p>'; |
|---|
| 288 | $text .= '<p><a href="https://wordpress.org/plugins/youtube-embed/">' . __( 'Embeds for YouTube Plugin Documentation', 'youtube-embed' ) . '</a></p>'; |
|---|
| 289 | |
|---|
| 290 | if ( 'lists' != $screen ) { |
|---|
| 291 | $text .= '<p><a href="https://code.google.com/apis/youtube/player_parameters.html">' . __( 'YouTube Player Documentation', 'youtube-embed' ) . '</a></p>'; |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | if ( 'options' == $screen ) { |
|---|
| 295 | |
|---|
| 296 | $text .= '<p><a href="https://github.com/davatron5000/FitVids.js">FitVids.js</a></p>'; |
|---|
| 297 | $text .= '<p><a href="https://github.com/davidjbradshaw/iframe-resizer">iFrame Resizer</a></p>'; |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | return $text; |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | /** |
|---|
| 305 | * Show Admin Messages |
|---|
| 306 | * |
|---|
| 307 | * Display messages on the administration screen |
|---|
| 308 | */ |
|---|
| 309 | function youtube_embed_admin_messages() { |
|---|
| 310 | |
|---|
| 311 | $shortcode_site = get_option( 'youtube_embed_shortcode_site' ); |
|---|
| 312 | |
|---|
| 313 | $shortcode_admin = get_option( 'youtube_embed_shortcode_admin' ); |
|---|
| 314 | |
|---|
| 315 | if ( ( 0 != $shortcode_admin ) || ( 0 != $shortcode_site ) ) { |
|---|
| 316 | |
|---|
| 317 | $options = ye_get_general_defaults(); |
|---|
| 318 | |
|---|
| 319 | if ( 1 == $options['prompt'] ) { |
|---|
| 320 | |
|---|
| 321 | if ( 3 == $shortcode_site ) { |
|---|
| 322 | $message = __( 'For some reason the shortcode <strong>[youtube]</strong> is not working on the main site' ); |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | $alternative = __( 'An alternative plugin is using the <strong>[youtube]</strong> shortcode' ); |
|---|
| 326 | |
|---|
| 327 | if ( ( 1 == $shortcode_admin ) || ( 1 == $shortcode_site ) ) { |
|---|
| 328 | $message = $alternative; |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | if ( ( 2 == $shortcode_admin ) || ( 2 == $shortcode_site ) ) { |
|---|
| 332 | $message = __( $alternative . ', possibly the <a href="admin.php?page=jetpack_modules&activated=true">Shortcode Embeds module</a> in Jetpack' ); |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | echo '<div class="error notice"><p>Embeds for YouTube: ' . $message . '.</p></div>'; |
|---|
| 336 | } |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | add_action( 'admin_notices', 'youtube_embed_admin_messages' ); |
|---|