<?php

function custom_theme_setup() {
	add_theme_support( $feature, $arguments );
}
add_action( 'after_setup_theme', 'custom_theme_setup' );

//disable auto p
//remove_filter ('the_content', 'wpautop');

//disable wptexturize
remove_filter('the_content', 'wptexturize');

// Display the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links_extra', 3 ); 
 // Display the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'feed_links', 2 );
 // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'rsd_link' );
// Display the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'wlwmanifest_link' );
// index link 
remove_action( 'wp_head', 'index_rel_link' ); 
// prev link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
// start link 
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); 
// Display relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); 
// Display the XHTML generator that is generated on the wp_head hook, WP version
remove_action( 'wp_head', 'wp_generator' );

// Add default posts and comments RSS feed links to head.
	add_theme_support( 'automatic-feed-links' );

	/*
	 * Let WordPress manage the document title.
	 * By adding theme support, we declare that this theme does not use a
	 * hard-coded <title> tag in the document head, and expect WordPress to
	 * provide it for us.
	 */
	add_theme_support( 'title-tag' );

	/*
	 * Enable support for Post Thumbnails on posts and pages.
	 *
	 * See: https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
	 */
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 825, 510, true );

	if ( ! isset( $content_width ) ) $content_width = 900;


	// Set up the WordPress core custom background feature.
	add_theme_support( 'custom-background', apply_filters( 'workfree_custom_background_args', array(
		'default-color' => 'ffffff',
		'default-image' => '',
	) ) );
	
	function orry_scripts() {
		wp_enqueue_style( 'workfree-style', get_stylesheet_uri());
		
		wp_enqueue_style('workfree-style-custom',get_template_directory_uri(). '/css/style.css');
		
		if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
			wp_enqueue_script( 'comment-reply' );
		}
	}

	add_action( 'wp_enqueue_scripts', 'orry_scripts' );

	$args = array(
	'flex-width'    => true,
	'width'         => 980,
	'flex-height'    => true,
	'height'        => 490,
	'default-image' => get_template_directory_uri() . '/images/header.jpg',
	);
	
	add_theme_support( 'custom-header', $args );

	register_default_headers( array(
		'default-image' => array(
		'url'   => get_template_directory_uri() . '/images/header.jpg',

		'thumbnail_url' => get_template_directory_uri() . '/images/header.jpg',


	)));

	the_post_thumbnail();   
	
	/*
	 * Pagination for theme
	 *
	 */
	 
function orry_pagination($pages = '', $range = 2)
{  
     $showitems = ($range * 2)+1;  

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   

     if(1 != $pages)
     {
         echo "<div class='pagination'>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
             }
         }

         if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
         echo "</div>\n";
     }
}

/* Pagination End */

/*escape space*/
function escape_space($content){

	$content = str_replace("<br />", '', $content);
    $content = str_replace("<br />\n", '', $content);
    $content = str_replace("<b>", '', $content);
    $content = str_replace("</b>\n", '', $content);

    return $content;
}

/* Add your nav menus function to the 'init' action hook. */
add_action( 'init', 'aptel_register_menus' );
add_action( 'widgets_init', 'aptel_widget' );

// Add Widget feature
function aptel_widget()
{
	register_widget("aptel_widget_info");
}

class aptel_widget_info extends WP_Widget {

	// Name of widget where the widget will be displayed as widget name
	function aptel_widget_info() {
		$this -> WP_Widget('aptel_widget_info', 'Aptel Contact', $widget_ops);
	}
	
	// Designing the form to be displayed in admin dashboard widget.
	public function form($instance) {
		if ( isset( $instance[ 'address' ]) && isset ($instance[ 'phone' ]) && isset($instance[ 'email' ]) ) {
		$address = $instance[ 'address' ];
		$phone = $instance[ 'phone' ];
		$email = $instance[ 'email' ];
		}
		else {
		$address = __( '', 'bc_widget_title' );
		$phone = __( '', 'bc_widget_title' );
		$email = __( '', 'bc_widget_title' );
		} ?>
		<p>Address: <textarea name="<?php echo $this->get_field_name( 'address' ); ?>" rows="4" cols="30"><?php echo esc_attr( $address );?></textarea>
		 
		<p>phone: <input name="<?php echo $this->get_field_name( 'phone' ); ?>" type="text" value="<?php echo esc_attr( $phone ); ?>" /></p>
		 
		<p>Email: <input name="<?php echo $this->get_field_name( 'email' ); ?>" type="text" value="<?php echo esc_attr( $email ); ?>" /></p>
		<?php
 
		}
		// update the new values in database
 
		function update($new_instance, $old_instance) {
		 
		$instance = $old_instance;
		 
		$instance['address'] = ( ! empty( $new_instance['address'] ) ) ? strip_tags( $new_instance['address'] ) : '';
		 
		$instance['phone'] = ( ! empty( $new_instance['phone'] ) ) ? strip_tags( $new_instance['phone'] ) : '';
		 
		$instance['email'] = ( ! empty( $new_instance['email'] ) ) ? strip_tags( $new_instance['email'] ) : '';
		 
		return $instance;
		 
		}
		 
		//Display the stored widget information in webpage.
		 
		function widget($args, $instance) {
		 
		extract($args);
		 
		echo $before_widget; //Widget starts to print information
		 
		$address = apply_filters( 'widget_title', $instance['address'] );
		 
		$phone = empty( $instance['phone'] ) ? '&nbsp;' : $instance['phone'];
		 
		$email = empty( $instance['email'] ) ? '&nbsp;' : $instance['email'];
		 
		//if ( !empty( $address ) ) { echo $before_title . $address . $after_title; };
		echo '<h3>Contact Details:</h3>
				<div class="jumbotron custom-jumbotron">
				<address><strong>Address</strong><BR>'. $address .'</address>';
		echo '<address>
						<strong>Phone</strong><br>
						<abbr title="Phone">P:</abbr> ' . $phone . '</address>';
		echo '<address class="no-margin">
						<strong>Email Address</strong><br>
						<a href="mailto:'.$email.'">' . $email . '</a></address>';
		echo $after_widget; //Widget ends printing information
		}
		
		}

	function update($new_instance, $old_instance) {}
	function widget($args, $instance) {}
	


// Add menu features 
function aptel_register_menus() {
	register_nav_menus(array('primary'=>__('Primary Menu'),));
}

if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>',
));

if ( function_exists('register_sidebar') )  
    register_sidebar(array(  
		'name' => 'Primary Sidebar',
		'id'   => 'primary-sidebar',
		'description'   => 'These are widgets for primary sidebar.',
		'before_widget' => '<div class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3>',
		'after_title'   => '</h3>'
));  


if ( function_exists('register_sidebar') )  
    register_sidebar(array(  
		'name' => 'Contact Sidebar',
		'id'   => 'contact-sidebar',
		'description'   => 'These are widgets for Contact Page.',
		'before_widget' => '<div class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3>',
		'after_title'   => '</h3>'
));  

/*******
 *
 * Sidebar Ends
 *
 **********/


add_action('init', 'init_theme_method');
 
function init_theme_method() {
   add_thickbox();
}

/*
* Limit the number of words in the excerpt
*/

function limit_words_count($string, $word_limit)
{
  $words = explode(' ', $string, ($word_limit + 1));
  if(count($words) > $word_limit)
  array_pop($words);
  return implode(' ', $words);
}

?>