Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 25.38 KB | None | 0 0
  1. <?php
  2. /**
  3.  * TwentyTen functions and definitions
  4.  *
  5.  * Sets up the theme and provides some helper functions. Some helper functions
  6.  * are used in the theme as custom template tags. Others are attached to action and
  7.  * filter hooks in WordPress to change core functionality.
  8.  *
  9.  * The first function, twentyten_setup(), sets up the theme by registering support
  10.  * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
  11.  *
  12.  * When using a child theme (see http://codex.wordpress.org/Theme_Development and
  13.  * http://codex.wordpress.org/Child_Themes), you can override certain functions
  14.  * (those wrapped in a function_exists() call) by defining them first in your child theme's
  15.  * functions.php file. The child theme's functions.php file is included before the parent
  16.  * theme's file, so the child theme functions would be used.
  17.  *
  18.  * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
  19.  * to a filter or action hook. The hook can be removed by using remove_action() or
  20.  * remove_filter() and you can attach your own function to the hook.
  21.  *
  22.  * We can remove the parent theme's hook only after it is attached, which means we need to
  23.  * wait until setting up the child theme:
  24.  *
  25.  * <code>
  26.  * add_action( 'after_setup_theme', 'my_child_theme_setup' );
  27.  * function my_child_theme_setup() {
  28.  *     // We are providing our own filter for excerpt_length (or using the unfiltered value)
  29.  *     remove_filter( 'excerpt_length', 'twentyten_excerpt_length' );
  30.  *     ...
  31.  * }
  32.  * </code>
  33.  *
  34.  * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
  35.  *
  36.  * @package WordPress
  37.  * @subpackage Twenty_Ten
  38.  * @since Twenty Ten 1.0
  39.  */
  40. /*
  41.  * Set the content width based on the theme's design and stylesheet.
  42.  *
  43.  * Used to set the width of images and content. Should be equal to the width the theme
  44.  * is designed for, generally via the style.css stylesheet.
  45.  */
  46. if ( ! isset( $content_width ) )
  47.     $content_width = 640;
  48. /* Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */
  49. add_action( 'after_setup_theme', 'twentyten_setup' );
  50. if ( ! function_exists( 'twentyten_setup' ) ):
  51. /**
  52.  * Set up theme defaults and registers support for various WordPress features.
  53.  *
  54.  * Note that this function is hooked into the after_setup_theme hook, which runs
  55.  * before the init hook. The init hook is too late for some features, such as indicating
  56.  * support post thumbnails.
  57.  *
  58.  * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's
  59.  * functions.php file.
  60.  *
  61.  * @uses add_theme_support()        To add support for post thumbnails, custom headers and backgrounds, and automatic feed links.
  62.  * @uses register_nav_menus()       To add support for navigation menus.
  63.  * @uses add_editor_style()         To style the visual editor.
  64.  * @uses load_theme_textdomain()    For translation/localization support.
  65.  * @uses register_default_headers() To register the default custom header images provided with the theme.
  66.  * @uses set_post_thumbnail_size()  To set a custom post thumbnail size.
  67.  *
  68.  * @since Twenty Ten 1.0
  69.  */
  70. function twentyten_setup() {
  71.     // This theme styles the visual editor with editor-style.css to match the theme style.
  72.     add_editor_style();
  73.     // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.
  74.     add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
  75.     // This theme uses post thumbnails
  76.     add_theme_support( 'post-thumbnails' );
  77.     // Add default posts and comments RSS feed links to head
  78.     add_theme_support( 'automatic-feed-links' );
  79.     /*
  80.      * Make theme available for translation.
  81.      * Translations can be filed in the /languages/ directory
  82.      */
  83.     load_theme_textdomain( 'twentyten', get_template_directory() . '/languages' );
  84.     // This theme uses wp_nav_menu() in one location.
  85.     register_nav_menus( array(
  86.         'user-login-menu' => __( 'User Login Navigation', 'twentyten' ),
  87.         'header-menu' => __( 'Header Navigation', 'twentyten' ),
  88.         'footer-menu' => __( 'Footer Navigation', 'twentyten' ),
  89.         'responsive-menu' => __( 'Responsive Navigation', 'twentyten' ),
  90.         'wob-footer-menu' => __( 'WOB Footer Navigation', 'twentyten' ),
  91.         'not-found-menu' => __( 'Page not found Navigation', 'twentyten' ),
  92.     ) );
  93. }
  94. endif;
  95. if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
  96. /**
  97.  * Style the header image displayed on the Appearance > Header admin panel.
  98.  *
  99.  * Referenced via add_custom_image_header() in twentyten_setup().
  100.  *
  101.  * @since Twenty Ten 1.0
  102.  */
  103. function twentyten_admin_header_style() {
  104. ?>
  105. <style type="text/css" id="twentyten-admin-header-css">
  106. /* Shows the same border as on front end */
  107. #headimg {
  108.     border-bottom: 1px solid #000;
  109.     border-top: 4px solid #000;
  110. }
  111. /* If header-text was supported, you would style the text with these selectors:
  112.     #headimg #name { }
  113.     #headimg #desc { }
  114. */
  115. </style>
  116. <?php
  117. }
  118. endif;
  119. /**
  120.  * Show a home link for our wp_nav_menu() fallback, wp_page_menu().
  121.  *
  122.  * To override this in a child theme, remove the filter and optionally add
  123.  * your own function tied to the wp_page_menu_args filter hook.
  124.  *
  125.  * @since Twenty Ten 1.0
  126.  *
  127.  * @param array $args An optional array of arguments. @see wp_page_menu()
  128.  */
  129. function twentyten_page_menu_args( $args ) {
  130.     if ( ! isset( $args['show_home'] ) )
  131.         $args['show_home'] = true;
  132.     return $args;
  133. }
  134. add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
  135. /**
  136.  * Set the post excerpt length to 40 characters.
  137.  *
  138.  * To override this length in a child theme, remove the filter and add your own
  139.  * function tied to the excerpt_length filter hook.
  140.  *
  141.  * @since Twenty Ten 1.0
  142.  *
  143.  * @param int $length The number of excerpt characters.
  144.  * @return int The filtered number of excerpt characters.
  145.  */
  146. function twentyten_excerpt_length( $length ) {
  147.     return 12;
  148. }
  149. add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
  150. if ( ! function_exists( 'twentyten_continue_reading_link' ) ) :
  151. /**
  152.  * Return a "Continue Reading" link for excerpts.
  153.  *
  154.  * @since Twenty Ten 1.0
  155.  *
  156.  * @return string "Continue Reading" link.
  157.  */
  158. function twentyten_continue_reading_link()
  159. {
  160.     return '<div class="readMore"><a href="'. get_permalink() . '" class="more">' . __( 'More', 'twentyten' ) . '</a></div>';
  161. }
  162. endif;
  163. /**
  164.  * Replace "[...]" with an ellipsis and twentyten_continue_reading_link().
  165.  *
  166.  * "[...]" is appended to automatically generated excerpts.
  167.  *
  168.  * To override this in a child theme, remove the filter and add your own
  169.  * function tied to the excerpt_more filter hook.
  170.  *
  171.  * @since Twenty Ten 1.0
  172.  *
  173.  * @param string $more The Read More text.
  174.  * @return string An ellipsis.
  175.  */
  176. function twentyten_auto_excerpt_more( $more )
  177. {
  178.     if ( ! is_admin() ) {
  179.         return ' &hellip;' . twentyten_continue_reading_link();
  180.     }
  181.     return $more;
  182. }
  183. add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
  184. /**
  185.  * Add a pretty "Continue Reading" link to custom post excerpts.
  186.  *
  187.  * To override this link in a child theme, remove the filter and add your own
  188.  * function tied to the get_the_excerpt filter hook.
  189.  *
  190.  * @since Twenty Ten 1.0
  191.  *
  192.  * @param string $output The "Coninue Reading" link.
  193.  * @return string Excerpt with a pretty "Continue Reading" link.
  194.  */
  195. function twentyten_custom_excerpt_more( $output ) {
  196.     if ( has_excerpt() && ! is_attachment() && ! is_admin() ) {
  197.         $output .= twentyten_continue_reading_link();
  198.     }
  199.     return $output;
  200. }
  201. add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
  202. /**
  203.  * Remove inline styles printed when the gallery shortcode is used.
  204.  *
  205.  * Galleries are styled by the theme in Twenty Ten's style.css. This is just
  206.  * a simple filter call that tells WordPress to not use the default styles.
  207.  *
  208.  * @since Twenty Ten 1.2
  209.  */
  210. add_filter( 'use_default_gallery_style', '__return_false' );
  211. /**
  212.  * Deprecated way to remove inline styles printed when the gallery shortcode is used.
  213.  *
  214.  * This function is no longer needed or used. Use the use_default_gallery_style
  215.  * filter instead, as seen above.
  216.  *
  217.  * @since Twenty Ten 1.0
  218.  * @deprecated Deprecated in Twenty Ten 1.2 for WordPress 3.1
  219.  *
  220.  * @return string The gallery style filter, with the styles themselves removed.
  221.  */
  222. function twentyten_remove_gallery_css( $css ) {
  223.     return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
  224. }
  225. // Backwards compatibility with WordPress 3.0.
  226. if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )
  227.     add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
  228. if ( ! function_exists( 'twentyten_comment' ) ) :
  229. /**
  230.  * Template for comments and pingbacks.
  231.  *
  232.  * To override this walker in a child theme without modifying the comments template
  233.  * simply create your own twentyten_comment(), and that function will be used instead.
  234.  *
  235.  * Used as a callback by wp_list_comments() for displaying the comments.
  236.  *
  237.  * @since Twenty Ten 1.0
  238.  *
  239.  * @param object $comment The comment object.
  240.  * @param array  $args    An array of arguments. @see get_comment_reply_link()
  241.  * @param int    $depth   The depth of the comment.
  242.  */
  243. function twentyten_comment( $comment, $args, $depth ) {
  244.     $GLOBALS['comment'] = $comment;
  245.     switch ( $comment->comment_type ) :
  246.         case '' :
  247.     ?>
  248.     <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  249.         <div id="comment-<?php comment_ID(); ?>">
  250.             <div class="comment_img_title">
  251.                 <div class="comment-author vcard">
  252.                     <div class="cmmentImg">
  253.                         <?php echo get_avatar( $comment, 55 ); ?>
  254.                     </div>
  255.                     <?php echo '<h5>'.get_comment_author_link().'</h5>' ?>
  256.                 </div>
  257.             </div>
  258.             <div class="comment_box">
  259.                 <?php if ( $comment->comment_approved == '0' ) : ?>
  260.                     <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
  261.                     <br />
  262.                 <?php endif; ?>
  263.                 <div class="comment-meta commentmetadata">
  264.                     <div class="date">
  265.                         <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  266.                         <?php
  267.                             /* translators: 1: date, 2: time */
  268.                             printf( __( '%1$s', 'twentyten' ), get_comment_date()); ?>
  269.                         </a>
  270.                     </div>
  271.                 </div><!-- .comment-meta .commentmetadata -->
  272.                 <div class="comment-body"><?php comment_text(); ?></div>
  273.                 <div class="reply">
  274.                     <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ,'reply_text'=>'reply this comment' ) ) ); ?>
  275.                 </div><!-- .reply -->
  276.             </div>
  277.         </div><!-- #comment-##  -->
  278.     <?php
  279.             break;
  280.         case 'pingback'  :
  281.         case 'trackback' :
  282.     ?>
  283.     <li class="post pingback">
  284.         <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>
  285.     <?php
  286.             break;
  287.     endswitch;
  288. }
  289. endif;
  290. /**
  291.  * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
  292.  *
  293.  * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
  294.  * function tied to the init hook.
  295.  *
  296.  * @since Twenty Ten 1.0
  297.  *
  298.  * @uses register_sidebar()
  299.  */
  300. function twentyten_widgets_init() {
  301.     // Area 1, located at the top of the sidebar.
  302.     register_sidebar( array(
  303.         'name' => __( 'Primary Widget Area', 'twentyten' ),
  304.         'id' => 'primary-widget-area',
  305.         'description' => __( 'Add widgets here to appear in your sidebar.', 'twentyten' ),
  306.         'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  307.         'after_widget' => '</li>',
  308.         'before_title' => '<h3 class="widget-title">',
  309.         'after_title' => '</h3>',
  310.     ) );
  311.     // Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
  312.     register_sidebar( array(
  313.         'name' => __( 'Secondary Widget Area', 'twentyten' ),
  314.         'id' => 'secondary-widget-area',
  315.         'description' => __( 'An optional secondary widget area, displays below the primary widget area in your sidebar.', 'twentyten' ),
  316.         'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  317.         'after_widget' => '</li>',
  318.         'before_title' => '<h3 class="widget-title">',
  319.         'after_title' => '</h3>',
  320.     ) );
  321.     // Area 3, located in the footer. Empty by default.
  322.     register_sidebar( array(
  323.         'name' => __( 'Third Footer Widget Area', 'twentyten' ),
  324.         'id' => 'third-footer-widget-area',
  325.         'description' => __( 'An optional widget area for your site footer.', 'twentyten' ),
  326.         'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  327.         'after_widget' => '</li>',
  328.         'before_title' => '<h3 class="widget-title">',
  329.         'after_title' => '</h3>',
  330.     ) );
  331.         // Area 4, located in the footer. Empty by default.
  332.     register_sidebar( array(
  333.         'name' => __( 'FAQ Widget Area', 'twentyten' ),
  334.         'id' => 'faq-widget-area',
  335.         'description' => __( 'An optional widget area for your site faq.', 'twentyten' ),
  336.         'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  337.         'after_widget' => '</li>',
  338.         'before_title' => '<h3 class="widget-title">',
  339.         'after_title' => '</h3>',
  340.     ) );
  341.    
  342. }
  343. /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
  344. add_action( 'widgets_init', 'twentyten_widgets_init' );
  345. /**
  346.  * Remove the default styles that are packaged with the Recent Comments widget.
  347.  *
  348.  * To override this in a child theme, remove the filter and optionally add your own
  349.  * function tied to the widgets_init action hook.
  350.  *
  351.  * This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
  352.  * to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
  353.  * but they won't have any effect on the widget in default Twenty Ten styling.
  354.  *
  355.  * @since Twenty Ten 1.0
  356.  */
  357. function twentyten_remove_recent_comments_style() {
  358.     add_filter( 'show_recent_comments_widget_style', '__return_false' );
  359. }
  360. add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
  361. if ( ! function_exists( 'twentyten_posted_on' ) ) :
  362. /**
  363.  * Print HTML with meta information for the current post-date/time and author.
  364.  *
  365.  * @since Twenty Ten 1.0
  366.  */
  367. function twentyten_posted_on() {
  368.     printf( __( '<span class="%1$s"><strong>By</strong></span> %3$s <span class="meta-sep"><strong>on</strong></span> %2$s', 'twentyten' ),
  369.         'meta-prep meta-prep-author',
  370.         sprintf( '<span class="entry-date">%3$s</span>',
  371.             get_permalink(),
  372.             esc_attr( get_the_time() ),
  373.             get_the_date('d M Y')
  374.         ),
  375.         sprintf( '<span class="author vcard"><span class="url fn n" href="%1$s" title="%2$s">%3$s</span></span>',
  376.             get_author_posts_url( get_the_author_meta( 'ID' ) ),
  377.             esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ),
  378.             get_the_author()
  379.         )
  380.     );
  381. }
  382. endif;
  383. if ( ! function_exists( 'twentyten_posted_in' ) ) :
  384. /**
  385.  * Print HTML with meta information for the current post (category, tags and permalink).
  386.  *
  387.  * @since Twenty Ten 1.0
  388.  */
  389. function twentyten_posted_in() {
  390.     // Retrieves tag list of current post, separated by commas.
  391.     $tag_list = get_the_tag_list( '', ', ' );
  392.     if ( $tag_list ) {
  393.         $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
  394.     } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
  395.         $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
  396.     } else {
  397.         $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
  398.     }
  399.     // Prints the string, replacing the placeholders.
  400.     printf(
  401.         $posted_in,
  402.         get_the_category_list( ', ' ),
  403.         $tag_list,
  404.         get_permalink(),
  405.         the_title_attribute( 'echo=0' )
  406.     );
  407. }
  408. endif;
  409. /**
  410.  * Retrieve the IDs for images in a gallery.
  411.  *
  412.  * @uses get_post_galleries() First, if available. Falls back to shortcode parsing,
  413.  *                            then as last option uses a get_posts() call.
  414.  *
  415.  * @since Twenty Ten 1.6.
  416.  *
  417.  * @return array List of image IDs from the post gallery.
  418.  */
  419. function twentyten_get_gallery_images() {
  420.     $images = array();
  421.     if ( function_exists( 'get_post_galleries' ) ) {
  422.         $galleries = get_post_galleries( get_the_ID(), false );
  423.         if ( isset( $galleries[0]['ids'] ) )
  424.             $images = explode( ',', $galleries[0]['ids'] );
  425.     } else {
  426.         $pattern = get_shortcode_regex();
  427.         preg_match( "/$pattern/s", get_the_content(), $match );
  428.         $atts = shortcode_parse_atts( $match[3] );
  429.         if ( isset( $atts['ids'] ) )
  430.             $images = explode( ',', $atts['ids'] );
  431.     }
  432.     if ( ! $images ) {
  433.         $images = get_posts( array(
  434.             'fields'         => 'ids',
  435.             'numberposts'    => 999,
  436.             'order'          => 'ASC',
  437.             'orderby'        => 'menu_order',
  438.             'post_mime_type' => 'image',
  439.             'post_parent'    => get_the_ID(),
  440.             'post_type'      => 'attachment',
  441.         ) );
  442.     }
  443.     return $images;
  444. }
  445. add_action( 'after_setup_theme', 'woocommerce_support' );
  446. function woocommerce_support()
  447. {
  448.     add_theme_support( 'woocommerce' );
  449. }
  450. if( ! class_exists( 'WP_List_Table' ) )
  451. {
  452.   require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
  453. }
  454. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
  455. add_action ('admin_print_scripts','life_backend_js');
  456. function life_backend_js()
  457. {
  458.     wp_enqueue_script('jquery');
  459.     wp_enqueue_script('editor');
  460.     wp_enqueue_script('jquery-ui-datepicker');
  461.     wp_enqueue_script('backend_js' ,get_template_directory_uri().'/js/life-style-backtend.js');
  462.     wp_enqueue_script('thickbox');
  463.     wp_enqueue_script('farbtastic');
  464.     wp_enqueue_script('media-upload'); 
  465.     wp_enqueue_script('wp-color-picker');
  466.     wp_enqueue_script( 'my-script-handle', get_template_directory_uri() .'/inc/js/options-custom.js', array( 'wp-color-picker' ), false, true );
  467. }
  468. add_action ('admin_print_styles','life_backend_css');
  469. function life_backend_css()
  470. {
  471.     wp_enqueue_style('thickbox');
  472.     wp_enqueue_style('farbtastic');
  473.     wp_enqueue_style('media-upload');
  474.     wp_enqueue_style('admin_css' ,get_template_directory_uri().'/css/admin_css.css');
  475.     wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
  476.     wp_enqueue_style( 'wp-color-picker' );  
  477. }
  478. add_action( 'wp_enqueue_scripts', 'life_frontend_scripts' );
  479. function life_frontend_scripts()
  480. {
  481.     wp_enqueue_script('jquery');   
  482.     wp_enqueue_style('jquery-style','//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css');
  483.     wp_enqueue_script('google-jquery-ui','//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js');
  484.     wp_enqueue_script('flex_js',get_template_directory_uri().'/js/flexslider/jquery.flexslider-min.js');
  485.     wp_enqueue_style('flex_css' ,get_template_directory_uri().'/css/flexslider.css');
  486.     wp_enqueue_script('front-quicksand-js' ,get_template_directory_uri().'/js/jquery.quicksand.js');
  487.     wp_enqueue_script('front-ease-js' ,get_template_directory_uri().'/js/filter/jquery.easing.1.3.js');
  488.     wp_enqueue_script('front-ease-com-js' ,get_template_directory_uri().'/js/filter/jquery.easing.compatibility.js');
  489.     wp_enqueue_script('spinner-js' ,get_template_directory_uri().'/js/jquery.spinner.js');
  490.     wp_enqueue_script('fancybox-js' ,get_template_directory_uri().'/js/popup/jquery.fancybox.js');
  491.     wp_enqueue_style('fancybox-css', get_template_directory_uri().'/css/popup/jquery.fancybox.css');
  492.     wp_enqueue_script('validation-js' ,'//ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.js');
  493.     wp_enqueue_script('countdown-js' ,get_template_directory_uri().'/js/flip-clock/countdown.js');
  494.     wp_enqueue_script('front-js' ,get_template_directory_uri().'/js/life-style-frontend.js');
  495. }
  496. add_action( 'wp_enqueue_scripts', 'life_footer_script' );
  497. function life_footer_script()
  498. {
  499.     wp_enqueue_script('footer-script1-js' ,get_template_directory_uri().'/js/bootstrap.min.js');
  500.     wp_enqueue_script('footer-script2-js' ,get_template_directory_uri().'/js/docs.min.js');
  501. }
  502. add_filter('widget_text', 'do_shortcode');
  503. if ( !function_exists( 'optionsframework_init' ) )
  504. {
  505.     define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/inc/' );
  506.     require_once dirname( __FILE__ ) . '/inc/options-framework.php';
  507. }
  508. require (get_template_directory().'/posttype-metabox.php');
  509. require (get_template_directory().'/shortcode.php');
  510. function BBL_change_password_form() {
  511.     global $post;  
  512.     if (is_singular()) :
  513.             $current_url = get_permalink($post->ID);
  514.     else :
  515.             $pageURL = 'http';
  516.             if ($_SERVER["HTTPS"] == "on") $pageURL .= "s";
  517.             $pageURL .= "://";
  518.             if ($_SERVER["SERVER_PORT"] != "80") $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  519.             else $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  520.             $current_url = $pageURL;
  521.     endif;     
  522.     $redirect = $current_url;
  523.     ob_start();
  524.     // show any error messages after form submission
  525.     BBL_show_error_messages();
  526. ?>
  527.     <?php if(isset($_GET['password-reset']) && $_GET['password-reset'] == 'true') { ?>
  528.             <div class="BBL_message success">
  529.                     <span><?php _e('Password changed successfully', 'rcp'); ?></span>
  530.             </div>
  531.     <?php } ?>
  532.     <form id="BBL_password_form" method="POST" action="<?php echo $current_url; ?>">
  533.         <fieldset>
  534.             <p>
  535.                 <label for="BBL_user_pass"><?php _e('New Password', 'rcp'); ?></label>
  536.                 <input name="BBL_user_pass" id="pippin_user_pass" class="required" type="password"/>
  537.             </p>
  538.             <p>
  539.                 <label for="BBL_user_pass_confirm"><?php _e('Password Confirm', 'rcp'); ?></label>
  540.                 <input name="BBL_user_pass_confirm" id="BBL_user_pass_confirm" class="required" type="password"/>
  541.             </p>
  542.             <p>
  543.                 <input type="hidden" name="BBL_action" value="reset-password"/>
  544.                 <input type="hidden" name="BBL_redirect" value="<?php echo $redirect; ?>"/>
  545.                 <input type="hidden" name="BBL_password_nonce" value="<?php echo wp_create_nonce('rcp-password-nonce'); ?>"/>
  546.                 <input id="BBL_password_submit" type="submit" class="yello_border_btn" value="<?php _e('Change Password', 'BBL'); ?>"/>
  547.             </p>
  548.         </fieldset>
  549.     </form>
  550.     <?php
  551.     return ob_get_clean(); 
  552. }
  553. // password reset form
  554. function BBL_reset_password_form()
  555. {
  556.     if(is_user_logged_in())
  557.     {
  558.             return BBL_change_password_form();
  559.     }
  560. }
  561. add_shortcode('password_form', 'BBL_reset_password_form');
  562. function BBL_reset_password() {
  563.     // reset a users password
  564.     if(isset($_POST['BBL_action']) && $_POST['BBL_action'] == 'reset-password')
  565.     {
  566.         global $user_ID;
  567.         if(!is_user_logged_in())
  568.                 return;
  569.         if(wp_verify_nonce($_POST['BBL_password_nonce'], 'rcp-password-nonce'))
  570.         {
  571.             if($_POST['BBL_user_pass'] == '' || $_POST['BBL_user_pass_confirm'] == '') {
  572.                     // password(s) field empty
  573.                     BBL_errors()->add('password_empty', __('Please enter a password, and confirm it', 'pippin'));
  574.             }
  575.             if($_POST['BBL_user_pass'] != $_POST['BBL_user_pass_confirm']) {
  576.                     // passwords do not match
  577.                     BBL_errors()->add('password_mismatch', __('Passwords do not match', 'pippin'));
  578.             }
  579.             // retrieve all error messages, if any
  580.             $errors = BBL_errors()->get_error_messages();
  581.             if(empty($errors))
  582.             {
  583.                 // change the password here
  584.                 $user_data = array(
  585.                         'ID' => $user_ID,
  586.                         'user_pass' => $_POST['BBL_user_pass']
  587.                 );
  588.                 wp_update_user($user_data);
  589.                 // send password change email here (if WP doesn't)
  590.                 wp_redirect(add_query_arg('password-reset', 'true', $_POST['BBL_redirect']));
  591.                 exit;
  592.             }
  593.         }
  594.     }  
  595. }
  596. add_action('init', 'BBL_reset_password');
  597. if(!function_exists('BBL_show_error_messages')) {
  598.     // displays error messages from form submissions
  599.     function BBL_show_error_messages()
  600.     {
  601.         if($codes = BBL_errors()->get_error_codes())
  602.         {
  603.             echo '<div class="BBL_message error">';
  604.                 // Loop error codes and display errors
  605.                foreach($codes as $code)
  606.                 {
  607.                     $message = BBL_errors()->get_error_message($code);
  608.                     echo '<span class="BBL_error"><strong>' . __('Error', 'rcp') . '</strong>: ' . $message . '</span><br/>';
  609.                 }
  610.             echo '</div>';
  611.         }  
  612.     }
  613. }
  614. if(!function_exists('BBL_errors'))
  615. {
  616.     // used for tracking error messages
  617.     function BBL_errors()
  618.     {
  619.         static $wp_error; // Will hold global variable safely
  620.         return isset($wp_error) ? $wp_error : ($wp_error = new WP_Error(null, null, null));
  621.     }
  622. }
  623.  
  624. /*add_action( 'init', 'setcookie_for_country' );
  625. function setcookie_for_country()
  626. {
  627.     if(!isset($_COOKIES['country-code']))
  628.     {
  629.     $ip = $_SERVER['REMOTE_ADDR']; 
  630.     $json = @file_get_contents("http://ipinfo.io/{$ip}");
  631.     $details = json_decode($json); 
  632.     $country_code = $details->country;     
  633.     setcookie( 'country-code', $country_code, time() + (3600*24*30), '/');
  634.     }
  635.  
  636.  
  637.  
  638. add_action( 'init', 'setcookie_for_country' );
  639. function setcookie_for_country()
  640. {
  641.     $ip = $_SERVER['REMOTE_ADDR']; 
  642.     $xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=".$ip);
  643.     $country_code =  $xml->geoplugin_countryCode ;
  644.     setcookie( 'country-code', $country_code, time() + (3600*24*30), '/');
  645. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement