all custom functions for shikshaadhar

<?php
/* This is for all custom function here */

add_theme_support( 'post-thumbnails' );
add_theme_support( 'woocommerce' );

function themeslug_theme_customizer( $wp_customize ) {
  $wp_customize->add_section( 'themeslug_logo_section' , array(
    'title'       => __( 'Logo', 'themeslug' ),
    'priority'    => 30,
    'description' => 'Upload a logo to replace the default site name and description in the header',
) );

$wp_customize->add_setting( 'themeslug_logo' );

$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'themeslug_logo', array(
    'label'    => __( 'Logo', 'themeslug' ),
    'section'  => 'themeslug_logo_section',
    'settings' => 'themeslug_logo',
) ) );
}
add_action( 'customize_register', 'themeslug_theme_customizer' );

/* Education Listing Post type  */
/**
 * Add Listing post type
 */

/* Session check for header  */
 function register_my_session()
{
  if( !session_id() )
  {
    session_start();
  }
}

add_action('init', 'register_my_session');

function create_listing_post_type() {
register_post_type( 'listing',
array(
'labels' => array(
'name' => esc_html__('Listings', 'shiksha-aadhar-list'),
'singular_name' => esc_html__('Listing', 'shiksha-aadhar-list'),
'add_new' => 'Add New',
'add_new_item' => 'Add New Listing',
'edit_item' => 'Edit Listing',
'new_item' => 'New Listing',
'view_item' => 'View Listing',
'search_items' => 'Search Listings',
'not_found' =>  'Nothing Found',
'not_found_in_trash' => 'Nothing found in the Trash',
'parent_item_colon' => ''
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => 'dashicons-building',
//'rewrite' => true,
'rewrite' => array('slug' => 'listing'),
//'rewrite' => array('slug' => '%education_type%'),
'capability_type' => 'post',
        'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'revisions', 'page-attributes', 'comments'),
'taxonomies'   => array( 'listing',  'post_tag' )
)
);
}
add_action( 'init', 'create_listing_post_type' );

register_taxonomy("education_type", array("listing"), array(
"hierarchical" => true,
"label" => "Categories",
"singular_label" => "Category",
'show_ui' => true,
        'query_var' => 'education_type',
        "rewrite" => true
       // 'rewrite' => array( 'slug' => 'education_type')
   
));

/* add_filter('post_type_link', 'education_type_permalink_structure', 10, 4);
function education_type_permalink_structure($post_link) {
    if (false !== strpos($post_link, '%education_type%')) {
        $projectscategory_type_term = get_the_terms($post->ID, 'education_type');
        if (!empty($projectscategory_type_term))
            $post_link = str_replace('%education_type%', array_pop($projectscategory_type_term)->
            slug, $post_link);
         else
            $post_link = str_replace('%education_type%', 'uncategorized', $post_link);
    }
    return $post_link;
}  */


/* Register widget area  */

function arphabet_widgets_init() {

register_sidebar(array(    //try not to enclose this in function
        'id'            => 'footer_address',
        'name'          => 'Footer Four Sidebar',
        'description'   => 'This is footer sidebar for Address.',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h3 class="social-widget-title footer_address_title">',
        'after_title'   => '</h3>',
));

register_sidebar(array(    //try not to enclose this in function
        'id'            => 'top_social_links',
        'name'          => 'Top Social Links',
        'description'   => 'This Is Sidebar For Show Top Social Links.',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h3 class="social-widget-title top_social_links">',
        'after_title'   => '</h3>',
));

register_sidebar(array(    //try not to enclose this in function
        'id'            => 'bottom_social_links',
        'name'          => 'Bottom Social Links',
        'description'   => 'This Is Sidebar For Show Bottom Social Links.',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h3 class="social-widget-title bottom_social_links">',
        'after_title'   => '</h3>',
));



}
add_action( 'widgets_init', 'arphabet_widgets_init' );

add_action( 'after_setup_theme', 'theme_nav_setup' );

if ( ! function_exists( 'theme_nav_setup' ) ){
  function theme_nav_setup() { 
    register_nav_menu( 'header-nav_new', __( 'Main Menu', 'text-domain' ) );
  }
}
/* Pagination Code  */

function kriesi_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";
     }
}

add_filter( 'wpcf7_validate_configuration', '__return_false' );

/* Adding option in custom taxonomy for listing page   */

if( ! class_exists( 'Showcase_Taxonomy_Images' ) ) {
  class Showcase_Taxonomy_Images {
   
    public function __construct() {
     //
    }

    /**
     * Initialize the class and start calling our hooks and filters
     */
     public function init() {
     // Image actions
     add_action( 'education_type_add_form_fields', array( $this, 'add_category_image' ), 10, 2 );
     add_action( 'created_education_type', array( $this, 'save_category_image' ), 10, 2 );
     add_action( 'education_type_edit_form_fields', array( $this, 'update_category_image' ), 10, 2 );
     add_action( 'edited_education_type', array( $this, 'updated_category_image' ), 10, 2 );
     add_action( 'admin_enqueue_scripts', array( $this, 'load_media' ) );
     add_action( 'admin_footer', array( $this, 'add_script' ) );
   }

   public function load_media() {
     if( ! isset( $_GET['taxonomy'] ) || $_GET['taxonomy'] != 'education_type' ) {
       return;
     }
     wp_enqueue_media();
   }
 
   /**
    * Add a form field in the new category page
    * @since 1.0.0
    */
 
   public function add_category_image( $taxonomy ) { ?>
     <div class="form-field term-group">
       <label for="showcase-taxonomy-image-id"><?php _e( 'Image', 'showcase' ); ?></label>
       <input type="hidden" id="showcase-taxonomy-image-id" name="showcase-taxonomy-image-id" class="custom_media_url" value="">
       <div id="category-image-wrapper"></div>
       <p>
         <input type="button" class="button button-secondary showcase_tax_media_button" id="showcase_tax_media_button" name="showcase_tax_media_button" value="<?php _e( 'Add Image', 'showcase' ); ?>" />
         <input type="button" class="button button-secondary showcase_tax_media_remove" id="showcase_tax_media_remove" name="showcase_tax_media_remove" value="<?php _e( 'Remove Image', 'showcase' ); ?>" />
       </p>
     </div>
   <?php }

   /**
    * Save the form field
    * @since 1.0.0
    */
   public function save_category_image( $term_id, $tt_id ) {
     if( isset( $_POST['showcase-taxonomy-image-id'] ) && '' !== $_POST['showcase-taxonomy-image-id'] ){
       add_term_meta( $term_id, 'showcase-taxonomy-image-id', absint( $_POST['showcase-taxonomy-image-id'] ), true );
     }
    }

    /**
     * Edit the form field
     * @since 1.0.0
     */
    public function update_category_image( $term, $taxonomy ) { ?>
      <tr class="form-field term-group-wrap">
        <th scope="row">
          <label for="showcase-taxonomy-image-id"><?php _e( 'Image', 'showcase' ); ?></label>
        </th>
        <td>
          <?php $image_id = get_term_meta( $term->term_id, 'showcase-taxonomy-image-id', true ); ?>
          <input type="hidden" id="showcase-taxonomy-image-id" name="showcase-taxonomy-image-id" value="<?php echo esc_attr( $image_id ); ?>">
          <div id="category-image-wrapper">
            <?php if( $image_id ) { ?>
              <?php echo wp_get_attachment_image( $image_id, 'thumbnail' ); ?>
            <?php } ?>
          </div>
          <p>
            <input type="button" class="button button-secondary showcase_tax_media_button" id="showcase_tax_media_button" name="showcase_tax_media_button" value="<?php _e( 'Add Image', 'showcase' ); ?>" />
            <input type="button" class="button button-secondary showcase_tax_media_remove" id="showcase_tax_media_remove" name="showcase_tax_media_remove" value="<?php _e( 'Remove Image', 'showcase' ); ?>" />
          </p>
        </td>
      </tr>
   <?php }

   /**
    * Update the form field value
    * @since 1.0.0
    */
   public function updated_category_image( $term_id, $tt_id ) {
     if( isset( $_POST['showcase-taxonomy-image-id'] ) && '' !== $_POST['showcase-taxonomy-image-id'] ){
       update_term_meta( $term_id, 'showcase-taxonomy-image-id', absint( $_POST['showcase-taxonomy-image-id'] ) );
     } else {
       update_term_meta( $term_id, 'showcase-taxonomy-image-id', '' );
     }
   }

   /**
    * Enqueue styles and scripts
    * @since 1.0.0
    */
   public function add_script() {
     if( ! isset( $_GET['taxonomy'] ) || $_GET['taxonomy'] != 'education_type' ) {
       return;
     } ?>
     <script> jQuery(document).ready( function($) {
       _wpMediaViewsL10n.insertIntoPost = '<?php _e( "Insert", "showcase" ); ?>';
       function ct_media_upload(button_class) {
         var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment;
         $('body').on('click', button_class, function(e) {
           var button_id = '#'+$(this).attr('id');
           var send_attachment_bkp = wp.media.editor.send.attachment;
           var button = $(button_id);
           _custom_media = true;
           wp.media.editor.send.attachment = function(props, attachment){
             if( _custom_media ) {
               $('#showcase-taxonomy-image-id').val(attachment.id);
               $('#category-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
               $( '#category-image-wrapper .custom_media_image' ).attr( 'src',attachment.url ).css( 'display','block' );
             } else {
               return _orig_send_attachment.apply( button_id, [props, attachment] );
             }
           }
           wp.media.editor.open(button); return false;
         });
       }
       ct_media_upload('.showcase_tax_media_button.button');
       $('body').on('click','.showcase_tax_media_remove',function(){
         $('#showcase-taxonomy-image-id').val('');
         $('#category-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
       });
       // Thanks: http://stackoverflow.com/questions/15281995/wordpress-create-category-ajax-response
       $(document).ajaxComplete(function(event, xhr, settings) {
         var queryStringArr = settings.data.split('&');
         if( $.inArray('action=add-tag', queryStringArr) !== -1 ){
           var xml = xhr.responseXML;
           $response = $(xml).find('term_id').text();
           if($response!=""){
             // Clear the thumb image
             $('#category-image-wrapper').html('');
           }
          }
        });
      });
    </script>
   <?php }
  }
$Showcase_Taxonomy_Images = new Showcase_Taxonomy_Images();
$Showcase_Taxonomy_Images->init(); }

/* Adding Custom BIP Role for Lising user  */
add_role('bip', 'BIP', array(
    'read' => true, // True allows that capability
    'edit_posts' => true,
    'delete_posts' => false, // Use false to explicitly deny
));

/* Hide admin bar for all user Except for Administrators   */
add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
  show_admin_bar(false);
}
}

/* handle ajax request  */
function example_ajax_request() {

    $user_login=$_POST['user_Login'];
$user_pass=$_POST['user_password'];

$sql="select `user_login`,`user_pass`,`user_email` from `wp_users` WHERE user_login='" . $user_login . "'";

global $session;
$message='';
$mydb = new wpdb('shikshaadharuser','dsv@2018','shikshaadhar_listing','localhost');
$rows = $mydb->get_results("select `ID`,`user_login`,`user_pass`,`user_email` from `wp_users` WHERE user_login='" . $user_login . "'");

if($rows)
{
foreach ($rows as $obj) :
$password_hashed=$obj->user_pass;
endforeach;
}

$check=wp_check_password( $user_pass, $password_hashed );


if($check==1)
{

$rows = $mydb->get_results("select `ID`,`user_login`,`user_pass`,`user_email` from `wp_users` WHERE user_login='" . $user_login . "' and user_pass= '". $password_hashed."'");

if($rows)
{
foreach ($rows as $obj) :
$_SESSION['user_login']=$obj->user_login;
$_SESSION['user_email']=$obj->user_email;
$_SESSION['ID']=$obj->ID;
endforeach;
}

$num_rows=$mydb->num_rows;

if($num_rows==1)

// wp_redirect(home_url());
// exit();
echo $message='success';
}
else
{
  echo $message='Username  And Password Invalid';
}
}
else
{
echo $message='Username  And Password Invalid';
}

 
   
   die();
}
//add_action( 'wp_ajax_example_ajax_request', 'example_ajax_request' );
// If you wanted to also use the function for non-logged in users (in a theme for example)
 add_action( 'wp_ajax_nopriv_example_ajax_request', 'example_ajax_request' );
 add_action('wp_ajax_example_ajax_request', 'example_ajax_request');


/* function for Get category id by category name  */
 function get_category_id($cat_name){
  $term = get_term_by('name', $cat_name, 'education_type');
  return $term->term_id;
}


/* handle ajax request  for search */
function search_ajax_request() {

    $query=$_POST['query'];
$search_args = array( 'post_type' => 'listing', 'orderby' => 'post_date', 's' => $_POST['query'], 'order' => 'DESC', 'post_status'  => 'publish');
$loop = new WP_Query( $search_args );
if( $loop->have_posts() ){
$data = array();
      while ( $loop->have_posts() ) : $loop->the_post();
 
   $data[] = get_the_title();
    endwhile;
echo json_encode($data);
}
   die();
}

add_action( 'wp_ajax_nopriv_search_ajax_request', 'search_ajax_request' );

add_action('wp_ajax_search_ajax_request', 'search_ajax_request');

/* handle ajax request  for Location */
function location_ajax_request() {

    $query=$_POST['query'];
$location_args = array(
 'post_type' => 'listing',
            'order' => 'DESC',
'orderby' => 'post_date',
            'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'business_address',
'value' => $query,
'compare' => 'LIKE'
)
)
);
$loop = new WP_Query( $location_args );
if( $loop->have_posts() ){
$data = array();
      while ( $loop->have_posts() ) : $loop->the_post();
  $post_id = get_the_ID();
   $data[] = get_post_meta( $post_id, 'business_address', true );
    endwhile;
echo json_encode($data);
}
   die();
}
add_action( 'wp_ajax_nopriv_location_ajax_request', 'location_ajax_request' );
add_action('wp_ajax_location_ajax_request', 'location_ajax_request');

add_action('pre_get_posts', function($query)
{
    if ($query->is_tax('education_type')) {
        $query->set('posts_per_page', 9);
    }
});

/* Testimonial post type */

function create_testimonial_post_type() {
register_post_type( 'testimonial',
array(
'labels' => array(
'name' => esc_html__('Testimonials', 'testimonial-list'),
'singular_name' => esc_html__('Testimonial', 'testimonial-list'),
'add_new' => 'Add New',
'add_new_item' => 'Add New Testimonial',
'edit_item' => 'Edit Testimonial',
'new_item' => 'New Testimonial',
'view_item' => 'View Testimonial',
'search_items' => 'Search Testimonials',
'not_found' =>  'Nothing Found',
'not_found_in_trash' => 'Nothing found in the Trash',
'parent_item_colon' => ''
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
// 'menu_icon' => 'dashicons-building',
     'menu_icon' => 'dashicons-format-status',
//'menu_icon' => get_stylesheet_directory_uri() . '/yourimage.png',
'rewrite' => true,
'rewrite' => array('slug' => 'testimonial'),
'capability_type' => 'post',
    'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'revisions', 'page-attributes', 'comments'),
'taxonomies'   => array( 'testimonial',  'post_tag' )
)
);
}
add_action( 'init', 'create_testimonial_post_type' );

register_taxonomy("testimonial_type", array("testimonial"), array(
"hierarchical" => true,
"label" => "Categories",
"singular_label" => "Category",
"rewrite" => true
));


function add_testimonial_meta_boxes() {
add_meta_box("cafe_contact_meta", "Testimoanial Other Details", "add_testimonial_details_cafe_meta_box", "testimonial", "normal", "low");
}
function add_testimonial_details_cafe_meta_box()
{
global $post;
$custom = get_post_custom( $post->ID );

?>
<style>.width99 {width:99%;}</style>
<p>
<label>Designation:</label><br />
<input type="text" name="designation" value="<?= @$custom["designation"][0] ?>" class="width99" />
</p>
<?php
}
/**
 * Save custom field data when creating/updating posts
 */
function save_testimonial_custom_fields(){
  global $post;

  if ( $post )
  {
 
    update_post_meta($post->ID, "designation", @$_POST["designation"]);
  }
}
add_action( 'admin_init', 'add_testimonial_meta_boxes' );
add_action( 'save_post', 'save_testimonial_custom_fields' );


/* Educational Blog post type */ 

function create_educational_post_type() {
register_post_type( 'educational',
array(
'labels' => array(
'name' => esc_html__('Educational Blogs', 'educational-blog-list'),
'singular_name' => esc_html__('Educational Blog', 'educational-blog-list'),
'add_new' => 'Add New',
'add_new_item' => 'Add New Educational Blog',
'edit_item' => 'Edit Educational Blog',
'new_item' => 'New Educational Blog',
'view_item' => 'View Educational Blog',
'search_items' => 'Search Educational Blogs',
'not_found' =>  'Nothing Found',
'not_found_in_trash' => 'Nothing found in the Trash',
'parent_item_colon' => ''
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => 'dashicons-building',
//'menu_icon' => get_stylesheet_directory_uri() . '/yourimage.png',
'rewrite' => true,
'rewrite' => array('slug' => 'educational'),
'capability_type' => 'post',
    'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'revisions', 'page-attributes', 'comments'),
'taxonomies'   => array( 'educational',  'post_tag' )
)
);
}
add_action( 'init', 'create_educational_post_type' );

register_taxonomy("educational_type", array("educational"), array(
"hierarchical" => true,
"label" => "Categories",
"singular_label" => "Category",
"rewrite" => true
));


/* Brand post type */ 

function create_brand_post_type() {
register_post_type( 'brand',
array(
'labels' => array(
'name' => esc_html__('Brands', 'brand-list'),
'singular_name' => esc_html__('Brand', 'brand-list'),
'add_new' => 'Add New',
'add_new_item' => 'Add New Brand',
'edit_item' => 'Edit Brand',
'new_item' => 'New Brand',
'view_item' => 'View Brand',
'search_items' => 'Search Brands',
'not_found' =>  'Nothing Found',
'not_found_in_trash' => 'Nothing found in the Trash',
'parent_item_colon' => ''
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => 'dashicons-building',
//'menu_icon' => get_stylesheet_directory_uri() . '/yourimage.png',
'rewrite' => true,
'rewrite' => array('slug' => 'brand'),
'capability_type' => 'post',
    'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'revisions', 'page-attributes', 'comments'),
'taxonomies'   => array( 'brand',  'post_tag' )
)
);
}
add_action( 'init', 'create_brand_post_type' );

register_taxonomy("brand_type", array("brand"), array(
"hierarchical" => true,
"label" => "Categories",
"singular_label" => "Category",
"rewrite" => true
));

/**
 * Add About Us custom fields
 */
function add_about_meta_boxes() {

  add_meta_box("about_content_meta", "About Content", "add_about_content_about_content_meta", "page", "normal", "low");
 
}
function add_about_content_about_content_meta()
{
global $post;
$custom = get_post_custom( $post->ID );
        $pageTemplate = get_post_meta($post->ID, '_wp_page_template', true);

        if($pageTemplate == 'about-page-template.php' )
        {
?>
<style>.width99 {width:99%;}</style>
<p>
<label>Our Mission:</label><br />
<textarea rows="5" name="our_mission" class="width99"><?= @$custom["our_mission"][0] ?></textarea>
</p>
    <p>
<label>Our Vission:</label><br />
<textarea rows="5" name="our_vission" class="width99"><?= @$custom["our_vission"][0] ?></textarea>
</p>
    <p>
<label>Our Goal:</label><br />
<textarea rows="5" name="our_goal" class="width99"><?= @$custom["our_goal"][0] ?></textarea>
</p>

<?php    }
}
/**
 * Save custom field data when creating/updating posts
 */
function save_about_custom_fields(){
  global $post;

  if ( $post )
  {
      update_post_meta($post->ID, "our_mission", @$_POST["our_mission"]);
  update_post_meta($post->ID, "our_vission", @$_POST["our_vission"]);
  update_post_meta($post->ID, "our_goal", @$_POST["our_goal"]);
   }
}
add_action( 'admin_init', 'add_about_meta_boxes' );
add_action( 'save_post', 'save_about_custom_fields' );

/* Post View Count  */

// function to display number of posts.
function getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0 View";
    }
    return $count.' Views';
}

// function to count views.
function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}

/* handle ajax request  for Comment*/
function comment_ajax_request() {

   $time = current_time('mysql');
 
   $selected_review_rate=$_POST['selected_review_rate'];
   $comment_author_name=$_POST['comment_author_name'];
   $comment_author_email=$_POST['comment_author_email'];
   $author_comment_message=$_POST['author_comment_message'];
   $comment_post_ID=$_POST['comment_post_ID'];
   $comment_parent=$_POST['comment_parent'];
 
   $comment_IP = gethostbyname(trim(exec("hostname")));

    $comment_agent=$_SERVER['HTTP_USER_AGENT'] . "\n\n";


 $data = array(
    'comment_post_ID' => $comment_post_ID,
    'comment_author' => $comment_author_name,
    'comment_author_email' => $comment_author_email,
    'comment_author_url' => '',
    'comment_content' => $author_comment_message,
    'comment_type' => '',
    'comment_parent' => $comment_parent,
    'user_id' => 0,
    'comment_author_IP' => $comment_IP,
    'comment_agent' => $comment_agent,
    'comment_date' => $time,
    'comment_approved' => 0,
);

  $comment_ID=wp_new_comment( $data, $avoid_die = false );
 
  if($comment_ID) {
  $mydb = new wpdb('shikshaadharuser','dsv@2018','shikshaadhar_listing','localhost');
  $commnetRows = $mydb->get_results("SELECT comment_ID FROM `wp_comments` ORDER BY comment_ID DESC LIMIT 1");
 
  if($commnetRows)
 
  {
foreach ($commnetRows as $obj) :
$commentID=$obj->comment_ID;
endforeach;

add_comment_meta( $commentID, 'rating', $_POST['selected_review_rate'] );
add_comment_meta( $commentID, 'verified', '0' );

echo 'Comment Sucessfully Submitted';

  }

  }
die();
}

add_action( 'wp_ajax_nopriv_comment_ajax_request', 'comment_ajax_request' );
add_action('wp_ajax_comment_ajax_request', 'comment_ajax_request');

/* Avarage Comment rating  */

function average_rating() {
    global $wpdb;
    $post_id = get_the_ID();
    $ratings = $wpdb->get_results("

        SELECT $wpdb->commentmeta.meta_value
        FROM $wpdb->commentmeta
        INNER JOIN $wpdb->comments on $wpdb->comments.comment_id=$wpdb->commentmeta.comment_id
        WHERE $wpdb->commentmeta.meta_key='rating'
        AND $wpdb->comments.comment_post_id=$post_id
        AND $wpdb->comments.comment_approved =1

        ");
    $counter = 0;
    $average_rating = 0;   
    if ($ratings) {
        foreach ($ratings as $rating) {
            $average_rating = $average_rating + $rating->meta_value;
            $counter++;
        }
        //round the average to the nearast 1/2 point
        return (round(($average_rating/$counter)*2,0)/2); 
    } else {
        //no ratings
        return '0';
    }
}


/* handle ajax request  for Like */

function hasAlreadyVoted($post_id)
{
    global $timebeforerevote;

    $meta_IP = get_post_meta($post_id, "voted_IP");
   
    $voted_IP = $meta_IP[0];
   
    if(!is_array($voted_IP))
        $voted_IP = array();
       
    $ip = $_SERVER['REMOTE_ADDR'];
   
   if(in_array($ip, array_keys($voted_IP)))
    {
        $time = $voted_IP[$ip];
       
        $now = time();
       
       if(round(($now - $time) / 60) > $timebeforerevote)
            return false;
           
        return true;
    }
   
    return false;
}



function like_ajax_request() {

     if(isset($_POST['like_post_id']))
    {
        // Retrieve user IP address
        $post_id=$_POST['like_post_id'];
         $ip = $_SERVER['REMOTE_ADDR'];
             
        // Get voters'IPs for the current post
        $meta_IP = get_post_meta($post_id, "voted_IP");
        $voted_IP = $meta_IP[0];

        if(!is_array($voted_IP))
            $voted_IP = array();
       
        // Get votes count for the current post
        $meta_count = get_post_meta($post_id, "votes_count", true);

        // Use has already voted ?
        if(!hasAlreadyVoted($post_id))
        {
            $voted_IP[$ip] = time();

            // Save IP and increase votes count
            update_post_meta($post_id, "voted_IP", $voted_IP);
            update_post_meta($post_id, "votes_count", ++$meta_count);
           
            // Display count (ie jQuery return value)
            echo $meta_count;
        }
        else
           echo "already";
       
    }
    exit;
     
     
}

add_action( 'wp_ajax_nopriv_like_ajax_request', 'like_ajax_request' );

add_action('wp_ajax_like_ajax_request', 'like_ajax_request');

/* remove taxonomy slug from url  */

add_filter('request', 'rudr_change_term_request', 1, 1 );

function rudr_change_term_request($query){

$tax_name = 'education_type'; // specify you taxonomy name here, it can be also 'category' or 'post_tag'

// Request for child terms differs, we should make an additional check
if( $query['attachment'] ) :
$include_children = true;
$name = $query['attachment'];
else:
$include_children = false;
$name = $query['name'];
endif;


$term = get_term_by('slug', $name, $tax_name); // get the current term to make sure it exists

if (isset($name) && $term && !is_wp_error($term)): // check it here

if( $include_children ) {
unset($query['attachment']);
$parent = $term->parent;
while( $parent ) {
$parent_term = get_term( $parent, $tax_name);
$name = $parent_term->slug . '/' . $name;
$parent = $parent_term->parent;
}
} else {
unset($query['name']);
}

switch( $tax_name ):
case 'category':{
$query['category_name'] = $name; // for categories
break;
}
case 'post_tag':{
$query['tag'] = $name; // for post tags
break;
}
default:{
$query[$tax_name] = $name; // for another taxonomies
break;
}
endswitch;

endif;

return $query;

}


add_filter( 'term_link', 'rudr_term_permalink', 10, 3 );

function rudr_term_permalink( $url, $term, $taxonomy ){

$taxonomy_name = 'education_type'; // your taxonomy name here
$taxonomy_slug = 'education_type'; // the taxonomy slug can be different with the taxonomy name (like 'post_tag' and 'tag' )

// exit the function if taxonomy slug is not in URL
if ( strpos($url, $taxonomy_slug) === FALSE || $taxonomy != $taxonomy_name ) return $url;

$url = str_replace('/' . $taxonomy_slug, '', $url);

return $url;
}

/* for seo purose  */

add_action('template_redirect', 'rudr_old_term_redirect');

function rudr_old_term_redirect() {

$taxonomy_name = 'education_type';
$taxonomy_slug = 'education_type';

// exit the redirect function if taxonomy slug is not in URL
if( strpos( $_SERVER['REQUEST_URI'], $taxonomy_slug ) === FALSE)
return;

if( ( is_category() && $taxonomy_name=='category' ) || ( is_tag() && $taxonomy_name=='post_tag' ) || is_tax( $taxonomy_name ) ) :

        wp_redirect( site_url( str_replace($taxonomy_slug, '', $_SERVER['REQUEST_URI']) ), 301 );
exit();

endif;

}


/* Custom Option For Customizer */
add_action( 'customize_register', 'genesischild_register_theme_customizer' );
/*
 * Register Our Customizer Stuff Here
 */
function genesischild_register_theme_customizer( $wp_customize ) {
 // Create custom panel.
 $wp_customize->add_panel( 'text_blocks', array(
  'priority'       => 500,
  'theme_supports' => '',
  'title'          => __( 'Text Blocks', 'genesischild' ),
  'description'    => __( 'Set editable text for certain content.', 'genesischild' ),
 ) );
 
 /* Customizer option for address and phone number  */
 $wp_customize->add_section( 'custom_email_text' , array(
  'title'    => __('Change Email Text','genesischild'),
  'panel'    => 'text_blocks',
  'priority' => 10
 ) );
 
 $wp_customize->add_setting( 'email_text_block', array(
   'default'           => __( 'default text', 'genesischild' ),
   'sanitize_callback' => 'sanitize_text'
 ) );

 $wp_customize->add_control( new WP_Customize_Control(
     $wp_customize,
  'custom_address_text',
      array(
          'label'    => __( 'Email Text', 'genesischild' ),
          'section'  => 'custom_email_text',
          'settings' => 'email_text_block',
          'type'     => 'text'
      )
     )
 );
 
 
 $wp_customize->add_section( 'custom_phone_text' , array(
  'title'    => __('Change Phone Text','genesischild'),
  'panel'    => 'text_blocks',
  'priority' => 10
 ) );
 
 $wp_customize->add_setting( 'phone_text_block', array(
   'default'           => __( 'default text', 'genesischild' ),
   'sanitize_callback' => 'sanitize_text'
 ) );

 $wp_customize->add_control( new WP_Customize_Control(
     $wp_customize,
  'custom_phone_text',
      array(
          'label'    => __( 'Phone Text', 'genesischild' ),
          'section'  => 'custom_phone_text',
          'settings' => 'phone_text_block',
          'type'     => 'text'
      )
     )
 );
 
 
  // Sanitize text
 function sanitize_text( $text ) {
     return sanitize_text_field( $text );
 }
}
<?php echo get_theme_mod( 'phone_text_block'); ?>
/* footer area */

<section class="gradient-bg">
                        <div class="cirle-bg">
                            <div class="bg" data-bg="<?php echo get_template_directory_uri(); ?>/images/bg/circle.png"></div>
                        </div>
                        <div class="container">
                            <div class="join-wrap fl-wrap">
                                <div class="row">
                                    <div class="col-md-8">
                                        <h3>Do You Have Questions ?</h3>
                                        <p>Lorem ipsum dolor sit amet, harum dolor nec in, usu molestiae at no.</p>
                                    </div>
                                    <div class="col-md-4"><a href="<?php echo get_permalink('95'); ?>" class="join-wrap-btn">Get In Touch <i class="fa fa-envelope-o"></i></a></div>
                                </div>
                            </div>
                        </div>
                    </section>
                    <!-- section end -->
                </div>
                <!-- Content end -->
            </div>
            <!-- wrapper end -->
            <!--footer -->
            <footer class="main-footer dark-footer  ">
                <div class="container">
                    <div class="row">
                        <div class="col-md-4">
                            <div class="footer-widget fl-wrap">
                                <h3>About Us</h3>
                                <div class="footer-contacts-widget fl-wrap">
                                 
                                     <?php
$my_page_id = 132;
$my_page = get_post($my_page_id);
$content = $my_page->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$title = $my_page->post_title;
$about_footer_contant=wp_trim_words( $content, 40);
?>
<p style="text-align:justify;"><?php echo $about_footer_contant; ?></p>
                                   
                                   
                                   
                                    <ul  class="footer-contacts fl-wrap">
                                        <li><span><i class="fa fa-envelope-o"></i> Mail :</span><a>digitalskillsvalley@gmail.com</a></li>
                                        <li> <span><i class="fa fa-map-marker"></i> Adress :</span><a>Address : Plot No. 25/III 2nd Floor , LIG Square in Front of BRTS Bus Stand Ab. Road , Indore, Madhya Pradesh 452001</a></li>
                                        <li><span><i class="fa fa-phone"></i> Phone :</span><a>+91-8817123606</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="footer-widget fl-wrap">
                                <h3>Our Last News</h3>
                                <div class="widget-posts fl-wrap">
                                    <ul>
                                    <?php
            $args = array( 'post_type' => 'post', 'posts_per_page' => 3, 'order' => 'DESC' );
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post();
            ?>
                                        <li class="clearfix">
                                            <a href="<?php echo get_permalink(); ?>"  class="widget-posts-img"><img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>" class="respimg" alt=""></a>
                                            <div class="widget-posts-descr">
                                                <a href="<?php echo get_permalink(); ?>" title=""><?php the_title(); ?></a>
                                            <!--<span class="widget-posts-date">     21 Mar 09.05 </span>-->
                                           <span class="widget-posts-date">   <?php echo( date( 'l, F j, Y', time() ) );  ?> </span>
                                            </div>
                                        </li>
                                       <?php endwhile; ?>
                                    </ul>
                                </div>
                            </div>
                        </div>
                       
                        <div class="col-md-4">
                            <div class="footer-widget fl-wrap">
                                <h3>Get A Quote</h3>
                                <div class="subscribe-widget fl-wrap">
                                    <p>Please Contact to administrator of shiksh aadhar .</p>
                                    <div class="subcribe-form">
                                        <?php echo do_shortcode('[contact-form-7 id="205" title="footer get a quote"]'); ?>
                                    </div>
                                </div>
                               
                            </div>
                        </div>
                    </div>
                </div>
                <div class="sub-footer fl-wrap">
                    <div class="container">
                        <div class="row">
                            <div class="col-md-4">
                               <!-- <div class="about-widget">
                                    <img src="<?php //echo get_template_directory_uri(); ?>/images/logo.png" alt="">
                                </div>-->
                            </div>
                            <div class="col-md-4">
                                <div class="copyright"> &#169; Shiksh Aadhar 2018 .  All rights reserved.</div>
                            </div>
                            <div class="col-md-4">
                                <div class="footer-social">
                                    <ul>
                                        <li><a href="#" target="_blank" ><i class="fa fa-facebook-official"></i></a></li>
                                        <li><a href="#" target="_blank"><i class="fa fa-twitter"></i></a></li>
                                        <li><a href="#" target="_blank" ><i class="fa fa-chrome"></i></a></li>
                                        <li><a href="#" target="_blank" ><i class="fa fa-vk"></i></a></li>
                                        <li><a href="#" target="_blank" ><i class="fa fa-whatsapp"></i></a></li>
                                    </ul>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </footer>
            <!--footer end  -->
            <!--register form -->
            <div class="main-register-wrap modal">
                <div class="main-overlay"></div>
                <div class="main-register-holder">
                    <div class="main-register fl-wrap">
                        <div class="close-reg"><i class="fa fa-times"></i></div>
                        <h3>Sign In <span>Shiksha<strong>&nbsp;Aadhar</strong></span></h3>
                           <div class="Bip_Login_Response"></div>
                       <!-- <div class="soc-log fl-wrap">
                            <p>For faster login use your social account.</p>
                            <a href="#" class="facebook-log"><i class="fa fa-facebook-official"></i>Log in with Facebook</a>
                            <a href="#" class="twitter-log"><i class="fa fa-twitter"></i> Log in with Twitter</a>
                        </div>
                        <div class="log-separator fl-wrap"><span>or</span></div>-->
                        <div id="tabs-container">
                            <ul class="tabs-menu">
                                <li class="current"><a href="#tab-1">Login</a></li>
                               <!-- <li><a href="#tab-2">Register</a></li>-->
                            </ul>
                            <div class="tab">
                                <div id="tab-1" class="tab-content">
                                    <div class="custom-form">
                                   
                                        <form method="post" id="Bip_Login"  name="registerform" method="post" action="">
                                       
                                            <label>Username or Email Address * </label>
                                            <input name="user_login" id="user_login" type="text"   onClick="this.select()" value="">
                                            <label >Password * </label>
                                            <input name="user_pass" id="user_pass" type="password"   onClick="this.select()" value="" >
                                           <!-- <button type="submit"  class="log-submit-btn"><span>Log In</span></button> -->
                                             <input type="submit" id="bip_login" class="log-submit-btn" name="user_login" value="Log In" />
                                           
                                           
                                            <div class="clearfix"></div>
                                            <div class="filter-tags">
                                                <input id="check-a" type="checkbox" name="check">
                                                <label for="check-a">Remember me</label>
                                            </div>
                                        </form>
                                        <div class="lost_password">
                                            <a href="#">Lost Your Password?</a>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab">
                                    <div id="tab-2" class="tab-content">
                                        <div class="custom-form">
                                            <form method="post"   name="registerform" class="main-register-form" id="main-register-form2">
                                                <label >First Name * </label>
                                                <input name="name" type="text"   onClick="this.select()" value="">
                                                <label>Second Name *</label>
                                                <input name="name2" type="text"  onClick="this.select()" value="">
                                                <label>Email Address *</label>
                                                <input name="email" type="text"  onClick="this.select()" value="">
                                                <label >Password *</label>
                                                <input name="password" type="password"   onClick="this.select()" value="" >
                                                <button type="submit"     class="log-submit-btn"  ><span>Register</span></button>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--register form end -->
            <a class="to-top"><i class="fa fa-angle-up"></i></a>
        </div>
        <!-- Main end -->
        <!--=============== scripts  ===============-->   
        <script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/jquery.min.js"></script>
        <script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/plugins.js"></script>
        <script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/scripts.js"></script>
          <script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/owl.carousel.min.js"></script>
<!-- <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDwJSRi0zFjDemECmFl9JtRj1FY7TiTRRo&libraries=places&callback=initAutocomplete"></script> -->
       <!-- <script type="text/javascript" src="<?php //echo get_template_directory_uri(); ?>/js/map_infobox.js"></script> -->
        <script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/markerclusterer.js"></script> 
        <!--<script type="text/javascript" src="<?php //echo get_template_directory_uri(); ?>/js/maps.js"></script> -->
       
         <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.min.js"></script> 
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> 

 
  <script src="//cdn.ckeditor.com/4.5.9/standard/ckeditor.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ckeditor/4.5.9/adapters/jquery.js"></script>
       
        <script type="text/javascript">
    var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
   
   jQuery(document).ready(function($) {
$('#bip_login').click(function(event){
event.preventDefault();
var user_login=$('#user_login').val();
  var user_pass=$('#user_pass').val();

var  login_data = $('#Bip_Login').serialize();

   // var fruit = 'Banana';

    $.ajax({
        url: ajaxurl,
type: 'POST',
data: {
            action:"example_ajax_request",
     user_Login : user_login,
user_password : user_pass,
        },
        success:function(data) {
          // console.log(data);
  if(data=='success'){
  $(location).attr('href', 'http://shikshaadhar.com/')

  }else{
   $('.Bip_Login_Response').html(data);
   }
        },
        error: function(errorThrown){
            console.log(errorThrown);
        }
    }); 
  });
 
  /* post name search post auto complete jquery Start  */

   $('.s').typeahead({
  source: function(query, result)
  {
  $.ajax({
        url: ajaxurl,
type: 'POST',
dataType:"json",
data: {
            action:"search_ajax_request",
     query : query,

        },
        success:function(data) {
result($.map(data, function(item){
  return item;
}));
        },
        error: function(errorThrown){
            console.log(errorThrown);
        }
    });
  }
 
 });
  /* type end  */
 
   /*  post name search post auto complete jquery End  */
 
    /* Location search post auto complete jquery Start  */
 
   $('.listing_location').typeahead({
  source: function(query, result)
  {
  $.ajax({
        url: ajaxurl,
type: 'POST',
dataType:"json",
data: {
            action:"location_ajax_request",
     query : query,

        },
        success:function(data) {
result($.map(data, function(item){
  return item;
}));
        },
        error: function(errorThrown){
            console.log(errorThrown);
        }
    });
  }
 
 });    /* type end  */
 
   /*  Location search post auto complete jquery End  */
 
});  /* Ready End  */
</script>

<script>
 jQuery(document).ready(function($) {
  $('textarea[name="post_excerpt"]').ckeditor();
});
</script>

<script>
jQuery(document).ready(function($){
$('input[name=rating]').change(function(){ 
var value = $( 'input[name=rating]:checked' ).val();
$('.selected_review_rate').val(value);
});
                                 
});

</script>

<script>
jQuery(document).ready(function($) {
$('#submit-comment').click(function(event){ 
  event.preventDefault();
  var selected_review_rate=$('.selected_review_rate').val();
  var comment_author_name=$('.comment_author_name').val();
  var comment_author_email=$('.comment_author_email').val();
  var author_comment_message=$('.author_comment_message').val();
  var comment_post_ID=$('.comment_post_ID').val();
  var comment_parent=$('.comment_parent').val();
 
   $.ajax({
        url: ajaxurl,
type: 'POST',
data: {
            action:"comment_ajax_request",
     selected_review_rate : selected_review_rate,
comment_author_name : comment_author_name,
comment_author_email : comment_author_email,
author_comment_message : author_comment_message,
comment_post_ID : comment_post_ID,
comment_parent : comment_parent,
},
        success:function(data) {
          // console.log(data);

$('.Comment_Response').html(data);




        },
        error: function(errorThrown){
            console.log(errorThrown);
        }
    });
 
});
});
</script>

<script>
jQuery(document).ready(function($) { 
$('.single_listing_user_form_submit').click(function(event){ 
  event.preventDefault();
  var customer_name=$('.customer_name').val();
  var customer_email=$('.customer_email').val();
  var customer_phone=$('.customer_phone').val();
  var customer_information=$('.customer_information').val();
  var business_email=$('.business_email').val();
 
 
  $.ajax({
  type: "POST",
  url: "http://shikshaadhar.com/bussiness_email.php",
 data:'customer_name='+customer_name+'&customer_email='+customer_email+'&customer_phone='+customer_phone+'&customer_information='+customer_information+'&business_email='+business_email,
 success: function(data){
        $(".single_listing_user_form_response").text(data);
$(".single_listing_user_form").trigger('reset');
//alert(data);

  }
 
});


  });
});

</script>

<script>
jQuery(document).ready(function($) { 
$('div.post_heart_like').click(function(event){   
  event.preventDefault(); 
  var post_id=$(this).attr("id");
 
            $.ajax({
        url: ajaxurl,
type: 'POST',
data: {
            action:"like_ajax_request",
     like_post_id: post_id,
},
        success:function(data) {
          // console.log(data);
$('.post_heart_like_count').html(data);
        },
        error: function(errorThrown){
            console.log(errorThrown);
        }
    });
 
});
});
</script>
<script>
    $(document).ready(function() {
    $('.home-campus-owl-carousel').owlCarousel({
    loop: true,
    margin: 10,
    responsiveClass: true,
    responsive: {
    0: {
    items: 1,
    nav: true
    },
    600: {
    items: 3,
    nav: false
    },
    1000: {
    items:4,
    nav: true,
    loop: false,
    margin: 20
    }
    }
    })
    })
    </script>


  <?php wp_footer(); ?>
    </body>
</html>

Comments

Popular posts from this blog

dynamic create multiple ckeditor onclick event using jquery

get lat and long from city name using jquery

membership registration and login system in php