<?php



// Get rid of WP version footprint throughout site
function buso_remove_version() {
return '';
}
add_filter('the_generator', 'buso_remove_version');



// Remove stuff from wp_head function
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
remove_action('wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action('wp_head', 'parent_post_rel_link', 10, 0 ); // prev link
remove_action('wp_head', 'start_post_rel_link', 10, 0 );
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);



// Change Dashboard Footer Text
function change_footer_admin() { 
  echo '<span id="footer-thankyou">Theme design courtesy of <a href="http://www.buildersociety.com" target="_blank">Builder Society</a></span>'; 
}  
add_filter('admin_footer_text', 'change_footer_admin');



// Add a Dashboard Widget for Designer Contact Information
function buso_add_dashboard_widgets() {
  wp_add_dashboard_widget('wp_dashboard_widget', 'Theme Details', 'buso_theme_info');
}
add_action('wp_dashboard_setup', 'buso_add_dashboard_widgets');
function buso_theme_info() {
  echo "<ul>
  <li><strong>Developed By:</strong> Builder Society</li>
  <li><strong>Website:</strong> <a href='http://www.buildersociety.com' target='_blank'>www.buildersociety.com</a></li>
  <li><strong>Contact:</strong> <a href='mailto:contact@buildersociety.com'>contact@buildersociety.com</a></li>
  </ul>";
}

// Add a Dashboard Widget for Helpful Resources
function buso_add_dashboard_widgets2() {
  add_meta_box('wp_dashboard_widget2', 'Helpful Resources', 'buso_resources', 'dashboard', 'side', 'high');
}
add_action('wp_dashboard_setup', 'buso_add_dashboard_widgets2');
function buso_resources() {
  echo "<ul>
  <li>- Come join us at <a href=\"http://www.buildersociety.com\" target=\"_blank\">Builder Society</a> to talk about all aspects of digital entrepreneurship.</li>
  <li>- If knowledge is power, use <a href=\"https://www.serpwoo.com/#Lightning\" target=\"_blank\">SerpWoo</a> to help you bring in tons of organic traffic.</li>
  <li>- <a href=\"http://mbsy.co/dollarphotoclub/17765638\" target=\"_blank\">Dollar Photo Club</a> is our favorite place to get stock images. Find out why!</li>
  <li>- Need new hosting? <a href=\"http://asmallorange.com/?a_aid=BuSo\" target=\"_blank\">ASmallOrange</a> is our top pick for value, while <a href=\"http://www.knownhost.com/affiliate/idevaffiliate.php?id=1466&tid1=lightning\" target=\"_blank\">KnownHost</a> is the perfect place to upgrade.</li>
  </ul>";
}



// Remove replacement "fancy" quotations, etc. added by Wordpress
remove_filter ('single_post_title', 'wptexturize');
remove_filter ('bloginfo', 'wptexturize');
remove_filter ('wp_title', 'wptexturize');  
remove_filter ('category_description', 'wptexturize');
remove_filter ('list_cats', 'wptexturize');
remove_filter ('comment_author', 'wptexturize');
remove_filter ('comment_text', 'wptexturize');
remove_filter ('the_title', 'wptexturize');
remove_filter ('the_content', 'wptexturize');
remove_filter ('the_excerpt', 'wptexturize');




// Widgetizing Theme
function buso_widgets_init() {
	register_sidebar( array(
		'name' => 'Sidebar',
		'id' => 'sidebar',
		'before_widget' => '<div class="widget-wrap">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
        register_sidebar( array(
		'name' => 'Footer - Left',
		'id' => 'footer-left',
		'before_widget' => '<div class="widget-wrap-footer">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
        register_sidebar( array(
		'name' => 'Footer - Middle',
		'id' => 'footer-middle',
		'before_widget' => '<div class="widget-wrap-footer">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
        register_sidebar( array(
		'name' => 'Footer - Right',
		'id' => 'footer-right',
		'before_widget' => '<div class="widget-wrap-footer">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
}
add_action( 'widgets_init', 'buso_widgets_init' );



// Register Wordpress Menu Function
function register_my_menus() {
  register_nav_menus(
    array(
      'header-menu' => __( 'Header Menu', 'buso-lightning' ),
      'top-menu' => __( 'Top Menu', 'buso-lightning' )
    )
  );
}
add_action( 'init', 'register_my_menus' );



// Enable WordPress Features (Must Haves)
add_theme_support( 'post-thumbnails' );
add_theme_support( 'title-tag' );
add_theme_support( 'custom-header' );
add_theme_support( 'custom-background' );
add_theme_support( 'automatic-feed-links' );
if ( ! isset( $content_width ) ) $content_width = 557;



// Set Up 'Read More' Link for Excerpts
function new_excerpt_more( $more ) {
	return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More &raquo;', 'your-text-domain') . '</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );



// Text Domain - Language Issues for Wordpress
add_action('after_setup_theme', 'buso_crucial_setup');
function buso_crucial_setup(){
    load_theme_textdomain('buso-lightning', get_template_directory() . '/languages');
}












// Add Options to the Theme Menu
add_action( 'admin_init', 'theme_options_init' );
add_action( 'admin_menu', 'theme_options_add_page' ); 
function theme_options_init(){
 register_setting( 'buso_options', 'buso_theme_options');
} 

function theme_options_add_page() {
    add_theme_page( __('Theme Options', 'lightning-theme'), __('Theme Options', 'lightning-theme'),
        'edit_theme_options', 'theme_options', 'theme_buso_settings');
    }

// Create the Theme Options Page
function theme_buso_settings() { 

// Check that the user is allowed to update options
if (!current_user_can('manage_options')) {
    wp_die('You do not have sufficient permissions to access this page.');
}

// Define the Variables from Saved Data
$use_logo_image = get_option("buso_use_logo_image");
$logo_pic = get_option("buso_logo_pic");
$show_post_image = get_option("buso_show_post_image");
$use_top_menu = get_option("buso_use_top_menu");
?>
   <div class="wrap">
        <h2>Lightning Theme Options</h2>
        <h3>Logo Instructions</h3>
        <ul>
           <li>- Use a full URL including http:// for any images.</li>
           <li>- Save "Logo Image URL" as "text" without quotes to have your site's title appear instead of an image. You can change your site's title under Settings -> General.</li>
        </ul>
        <h3>Featured Image Instructions</h3>
        <ul>
           <li>- Use 800px in width and 500px in height for your featured images.</li>
        </ul>
    
<?php if(isset($_POST["update_settings"])) {
    // Do the saving if form is submitted

// For Use Logo Image
$use_logo_image = $_POST["use_logo_image"];
update_option("buso_use_logo_image", $use_logo_image);
// For Logo URL
$logo_pic = $_POST["logo_pic"];	
update_option("buso_logo_pic", $logo_pic);
// For Featured Image on Post
$show_post_image = $_POST["show_post_image"];	
update_option("buso_show_post_image", $show_post_image);
// For Top Menu
$use_top_menu = $_POST["use_top_menu"];	
update_option("buso_use_top_menu", $use_top_menu);

// Let people know their changes were saved
?>
<div id="message" class="updated">Your New Settings Have Been Saved</div>
<?php } ?>

<br /><hr />

        <form method="POST" action="">

<h3>Logo</h3>
            <table class="form-table">
                <tr valign="top">
                    <th scope="row">
                        <label for="use_logo_image">
                           Use an Image for Logo? :
                        </label> 
                    </th>
                    <td>
                        <input type="checkbox" name="use_logo_image" value="1" <?php if( $use_logo_image == true ) { ?>checked="checked"<?php } ?> />
                    </td>
                </tr>
            </table>

            <table class="form-table">
                <tr valign="top">
                    <th scope="row">
                        <label for="logo_pic">
                           Logo Image URL :
                        </label> 
                    </th>
                    <td>
                        <input type="text" name="logo_pic" value="<?php echo $logo_pic; ?>" size="70" />
                    </td>
                </tr>
            </table>

<br /><hr />

<h3>Featured Images</h3>
            <table class="form-table">
                <tr valign="top">
                    <th scope="row">
                        <label for="show_post_image">
                           Show on Post Page? :
                        </label> 
                    </th>
                    <td>
                        <input type="checkbox" name="show_post_image" value="1" <?php if( $show_post_image == true ) { ?>checked="checked"<?php } ?> />
                    </td>
                </tr>
            </table>

<br /><hr />

<h3>Top Menu</h3>
            <table class="form-table">
                <tr valign="top">
                    <th scope="row">
                        <label for="use_top_menu">
                           Disable the Top Menu? :
                        </label> 
                    </th>
                    <td>
                        <input type="checkbox" name="use_top_menu" value="1" <?php if( $use_top_menu == true ) { ?>checked="checked"<?php } ?> />
                    </td>
                </tr>
            </table>

<br /><hr />


	 <input type="hidden" name="update_settings" value="Y" />  
	 <p><input type="submit" value="Save settings" class="button-primary"/></p>
        </form>
    </div>
<?php
}





?>