Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Plugin Name: Youtube FrontPage
- Plugin URI: http://dolphinaura.com
- Description: This plugin sets the default frontpage youtube video.
- Version: 1.0
- Author: sandy(d)
- Author URI: http://dolphinaura.com
- License: GPL2
- */
- ?>
- <?php
- // create custom plugin settings menu
- add_action('admin_menu', 'ytfront_create_menu');
- function ytfront_create_menu() {
- //create new top-level menu
- add_menu_page('Youtube FrontPage Plugin Settings', 'Youtube Frontpage', 'administrator', 'ytfront', 'ytfront_settings_page');
- //call register settings function
- add_action( 'admin_init', 'register_mysettings' );
- }
- function register_mysettings() {
- //register our settings
- register_setting( 'ytfront-settings-group', 'ytfront_url' );
- }
- function ytfront_settings_page() {
- ?>
- <div class="wrap">
- <h2>Youtube FrontPage Plugin Settings</h2>
- <form method="post" action="options.php">
- <?php settings_fields( 'ytfront-settings-group' ); ?>
- <?php do_settings_sections( 'ytfront-settings-group' ); ?>
- <table class="form-table">
- <tr>This controls the Youtube Video seen on the front page.</tr>
- <tr valign="top">
- <th scope="row">Youtube Link</th>
- <td><input type="text" name="ytfront_url" value="<?php echo get_option('ytfront_url'); ?>" /></td>
- </tr>
- </table>
- <h2>Video Preview</h2>
- <?php
- //Match all Youtube Links (excluding youtu.be short links)
- $videoUrl = get_option('ytfront_url');
- preg_match('%https?://(www\.)?youtube\.com/watch\?v=[^&]+.*%', $videoUrl, $matches);
- //youtu.be short links
- if (substr(get_option('ytfront_url'),0, 15) =="http://youtu.be") {
- $strippedurl=substr(get_option('ytfront_url'),16, strlen(get_option('ytfront_url')));?>
- <iframe width="560" height="315" src="http://www.youtube.com/embed/<?php echo substr(get_option('ytfront_url'),16, strlen(get_option('ytfront_url'))); ?>" frameborder="0" allowfullscreen></iframe>
- <?php }
- //Not a Youtube Link (Does not match regex)
- elseif (implode(',', $matches) == "") { ?>
- <h3>This video link is invalid</h3>
- <?php }
- //Youtube Links with stuff like "&feature=player_embedded" at the back.
- //Those are stripped.
- elseif (strpos(get_option('ytfront_url'),'&') !== false) {
- $strippedurl=substr(get_option('ytfront_url'), 0, strpos(get_option('ytfront_url'), '&'));?>
- <iframe width="560" height="315" src="http://www.youtube.com/embed/<?php echo substr($strippedurl, strpos($strippedurl, '=')+1, strlen($strippedurl)); ?>" frameborder="0" allowfullscreen></iframe>
- <?php
- }
- //Standard Youtube Links
- else {
- $strippedurl=substr(get_option('ytfront_url'), strpos(get_option('ytfront_url'), '=')+1, strlen(get_option('ytfront_url')));
- ?>
- <iframe width="560" height="315" src="http://www.youtube.com/embed/<?php echo $strippedurl ?>" frameborder="0" allowfullscreen></iframe>
- <?php } ?>
- <div style="text-align:right"><img src="https://s3-us-west-1.amazonaws.com/daura-static/img/sandyd_production.png" alt="sandyd_production" /></div>
- <p class="submit">
- <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
- </p>
- </form>
- </div>
- <?php }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement