Advertisement
rdusnr

Untitled

Jul 24th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 61.06 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package WordPress
  4. * @subpackage Kleo
  5. * @author SeventhQueen <themesupport@seventhqueen.com>
  6. * @since Kleo 1.0
  7. */
  8.  
  9. /***************************************************
  10. * :: Load Kleo framework
  11. ***************************************************/
  12.  
  13. require_once( trailingslashit( get_template_directory() ) . 'kleo-framework/kleo.php' );
  14.  
  15.  
  16. if ( ! isset( $content_width ) ) {
  17. $content_width = 1200;
  18. }
  19.  
  20.  
  21. /***************************************************
  22. * :: Load Theme specific functions
  23. ***************************************************/
  24.  
  25. require_once( trailingslashit( get_template_directory() ) . 'lib/theme-functions.php' );
  26.  
  27.  
  28. /***************************************************
  29. * :: SideKick Integration
  30. ***************************************************/
  31.  
  32. define( 'SK_PRODUCT_ID', 457 );
  33. define( 'SK_ENVATO_PARTNER', 'Qjq0CBU+3zqUohNf6gfTpvfnRX3eCVM+HwoqKeVL4/k=' );
  34. define( 'SK_ENVATO_SECRET', 'RqjBt/YyaTOjDq+lKLWhL10sFCMCJciT9SPUKLBBmso=' );
  35.  
  36.  
  37. /**
  38. * Sets up theme defaults and registers the various WordPress features
  39. *
  40. * @uses load_theme_textdomain() For translation/localization support.
  41. * @uses add_editor_style() To add a Visual Editor stylesheet.
  42. * @uses add_theme_support() To add support for post thumbnails, automatic feed links,
  43. * custom background, and post formats.
  44. * @uses register_nav_menu() To add support for navigation menus.
  45. * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  46. *
  47. * @since Kleo Framework 1.0
  48. */
  49. function kleo_setup() {
  50.  
  51. global $kleo_config;
  52.  
  53. /*
  54. * Makes theme available for translation.
  55. * Translations can be added to the /languages/ directory.
  56. */
  57. load_theme_textdomain( 'kleo_framework', get_template_directory() . '/languages' );
  58.  
  59. /* This theme styles the visual editor with editor-style.css to match the theme style. */
  60. add_editor_style();
  61.  
  62. /* Adds RSS feed links to <head> for posts and comments. */
  63. add_theme_support( 'automatic-feed-links' );
  64.  
  65. /*
  66. * Enable support for Post Formats.
  67. * See http://codex.wordpress.org/Post_Formats
  68. */
  69. add_theme_support( 'post-formats', array(
  70. 'aside',
  71. 'image',
  72. 'video',
  73. 'audio',
  74. 'quote',
  75. 'link',
  76. 'gallery',
  77. ) );
  78.  
  79. /* This theme uses wp_nav_menu() in two locations. */
  80. register_nav_menu( 'primary', __( 'Primary Menu', 'kleo_framework' ) );
  81. register_nav_menu( 'secondary', __( 'Secondary Menu', 'kleo_framework' ) );
  82. register_nav_menu( 'top', __( 'Top Menu', 'kleo_framework' ) );
  83. register_nav_menu( 'side', __( 'Side Menu', 'kleo_framework' ) );
  84.  
  85. /* This theme uses a custom image size for featured images, displayed on "standard" posts. */
  86. add_theme_support( 'post-thumbnails' );
  87. set_post_thumbnail_size( 672, 9999 ); // Unlimited height, soft crop
  88.  
  89. $blog_img_single_crop = sq_option( 'blog_img_single_crop', false ) ? true : false;
  90. $blog_img_standard_crop = sq_option( 'blog_img_standard_crop', true ) ? true : false;
  91. $blog_img_grid_crop = sq_option( 'blog_img_grid_crop', false ) ? true : false;
  92. $blog_img_small_crop = sq_option( 'blog_img_small_crop', true ) ? true : false;
  93.  
  94. //Single post image size
  95. add_image_size( 'kleo-full-width',
  96. sq_option( 'blog_img_single_width', 1038 ),
  97. sq_option( 'blog_img_single_height', 9999 ),
  98. $blog_img_single_crop
  99. ); //default 480x270
  100.  
  101. //check for custom image sizes
  102. if ( sq_option( 'blog_custom_img', 0 ) == 1 ) {
  103. add_image_size( 'kleo-post-gallery',
  104. sq_option( 'blog_img_standard_width', $kleo_config['post_gallery_img_width'] ),
  105. sq_option( 'blog_img_standard_height', $kleo_config['post_gallery_img_height'] ),
  106. $blog_img_standard_crop
  107. ); //default 480x270
  108. add_image_size( 'kleo-post-grid',
  109. sq_option( 'blog_img_grid_width', $kleo_config['post_gallery_img_width'] ),
  110. sq_option( 'blog_img_grid_height', 9999 ),
  111. $blog_img_grid_crop
  112. ); //default 480xauto-height
  113. add_image_size( 'kleo-post-small-thumb',
  114. sq_option( 'blog_img_small_width', $kleo_config['post_gallery_img_width'] ),
  115. sq_option( 'blog_img_small_height', $kleo_config['post_gallery_img_height'] ),
  116. $blog_img_small_crop
  117. ); //default 480xauto-height
  118. }
  119.  
  120. /*
  121. * Switch default core markup for search form, comment form, and comments
  122. * to output valid HTML5.
  123. */
  124. add_theme_support( 'html5', array(
  125. 'search-form',
  126. 'comment-form',
  127. 'comment-list',
  128. ) );
  129.  
  130. // Add support for featured content.
  131. add_theme_support( 'featured-content', array(
  132. 'featured_content_filter' => 'kleo_get_featured_posts',
  133. 'max_posts' => 6,
  134. ) );
  135.  
  136. /* Specific framework functionality */
  137. add_theme_support( 'kleo-sidebar-generator' );
  138. add_theme_support( 'kleo-facebook-login' );
  139. add_theme_support( 'kleo-mega-menu' );
  140. add_theme_support( 'kleo-menu-items' );
  141.  
  142. /* Third-party plugins */
  143. add_theme_support( 'bbpress' );
  144. add_theme_support( 'woocommerce' );
  145.  
  146. add_theme_support( 'title-tag' );
  147.  
  148. add_theme_support( 'customize-selective-refresh-widgets' );
  149.  
  150. }
  151.  
  152. add_action( 'after_setup_theme', 'kleo_setup' );
  153.  
  154.  
  155. if ( ! function_exists( '_wp_render_title_tag' ) ) {
  156. function kleo_slug_render_title() {
  157. ?>
  158. <title><?php wp_title( '|', true, 'right' ); ?></title>
  159. <?php
  160. }
  161.  
  162. add_action( 'wp_head', 'kleo_slug_render_title' );
  163. }
  164.  
  165.  
  166. if ( ! function_exists( 'kleo_wp_title' ) ):
  167. /**
  168. * Creates a nicely formatted and more specific title element text
  169. * for output in head of document, based on current view.
  170. *
  171. * @since Kleo Framework 1.0
  172. *
  173. * @param string $title Default title text for current view.
  174. * @param string $sep Optional separator.
  175. *
  176. * @return string Filtered title.
  177. */
  178. function kleo_wp_title( $title, $sep ) {
  179. global $paged, $page;
  180.  
  181. if ( is_feed() ) {
  182. return $title;
  183. }
  184. // Add the site name.
  185. $title .= get_bloginfo( 'name' );
  186.  
  187. // Add the site description for the home/front page.
  188. $site_description = get_bloginfo( 'description', 'display' );
  189. if ( $site_description && ( is_home() || is_front_page() ) ) {
  190. $title = "$title $sep $site_description";
  191. }
  192. // Add a page number if necessary.
  193. if ( $paged >= 2 || $page >= 2 ) {
  194. $title = "$title $sep " . sprintf( __( 'Page %s', 'kleo_framework' ), max( $paged, $page ) );
  195. }
  196.  
  197. return $title;
  198. }
  199.  
  200. if ( ! function_exists( '_wp_render_title_tag' ) ) {
  201. add_filter( 'wp_title', 'kleo_wp_title', 10, 2 );
  202. }
  203. endif;
  204.  
  205.  
  206. /***************************************************
  207. * :: Main menu Navigation
  208. ***************************************************/
  209.  
  210. require_once( KLEO_LIB_DIR . '/menu-walker.php' );
  211.  
  212.  
  213. /***************************************************
  214. * :: Featured content
  215. ***************************************************/
  216.  
  217. /**
  218. * Getter function for Featured Content Plugin.
  219. *
  220. * @since Kleo 1.0
  221. *
  222. * @return array An array of WP_Post objects.
  223. */
  224. function kleo_get_featured_posts() {
  225. /**
  226. * Filter the featured posts to return in Kleo.
  227. *
  228. * @since Kleo 1.0
  229. *
  230. * @param array|bool $posts Array of featured posts, otherwise false.
  231. */
  232. return apply_filters( 'kleo_get_featured_posts', array() );
  233. }
  234.  
  235. /**
  236. * A helper conditional function that returns a boolean value.
  237. *
  238. * @since Kleo 1.0
  239. *
  240. * @return bool Whether there are featured posts.
  241. */
  242. function kleo_has_featured_posts() {
  243. return ! is_paged() && (bool) kleo_get_featured_posts();
  244. }
  245.  
  246.  
  247. /*
  248. * Add Featured Content functionality.
  249. *
  250. * To overwrite in a plugin, define your own Featured_Content class on or
  251. * before the 'setup_theme' hook.
  252. */
  253. if ( ! class_exists( 'Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {
  254. require get_template_directory() . '/lib/featured-content/featured-content.php';
  255. }
  256. //------------------------------------------------------------------------------
  257.  
  258.  
  259. if ( ! function_exists( 'kleo_widgets_init' ) ) :
  260. /**
  261. * Registers our main widget area and the front page widget areas.
  262. *
  263. * @since Kleo 1.0
  264. */
  265. function kleo_widgets_init() {
  266. register_sidebar( array(
  267. 'name' => __( 'Main Sidebar', 'kleo_framework' ),
  268. 'id' => 'sidebar-1',
  269. 'description' => __( 'Default sidebar', 'kleo_framework' ),
  270. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  271. 'after_widget' => '</div>',
  272. 'before_title' => '<h4 class="widget-title">',
  273. 'after_title' => '</h4>',
  274. ) );
  275. register_sidebar( array(
  276. 'name' => 'Footer column 1',
  277. 'id' => 'footer-1',
  278. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  279. 'after_widget' => '</div>',
  280. 'before_title' => '<h4 class="widget-title">',
  281. 'after_title' => '</h4>',
  282. ) );
  283.  
  284. register_sidebar( array(
  285. 'name' => 'Footer column 2',
  286. 'id' => 'footer-2',
  287. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  288. 'after_widget' => '</div>',
  289. 'before_title' => '<h4 class="widget-title">',
  290. 'after_title' => '</h4>',
  291. ) );
  292.  
  293. register_sidebar( array(
  294. 'name' => 'Footer column 3',
  295. 'id' => 'footer-3',
  296. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  297. 'after_widget' => '</div>',
  298. 'before_title' => '<h4 class="widget-title">',
  299. 'after_title' => '</h4>',
  300. ) );
  301.  
  302. register_sidebar( array(
  303. 'name' => 'Footer column 4',
  304. 'id' => 'footer-4',
  305. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  306. 'after_widget' => '</div>',
  307. 'before_title' => '<h4 class="widget-title">',
  308. 'after_title' => '</h4>',
  309. ) );
  310. register_sidebar( array(
  311. 'name' => 'Extra - for 3 columns pages',
  312. 'id' => 'extra',
  313. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  314. 'after_widget' => '</div>',
  315. 'before_title' => '<h4 class="widget-title">',
  316. 'after_title' => '</h4>',
  317. ) );
  318. register_sidebar( array(
  319. 'name' => 'Shop sidebar',
  320. 'id' => 'shop-1',
  321. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  322. 'after_widget' => '</div>',
  323. 'before_title' => '<h4 class="widget-title">',
  324. 'after_title' => '</h4>',
  325. ) );
  326.  
  327. }
  328. endif;
  329. add_action( 'widgets_init', 'kleo_widgets_init' );
  330.  
  331.  
  332. if ( ! function_exists( 'kleo_entry_meta' ) ) :
  333. /**
  334. * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
  335. * Create your own kleo_entry_meta() to override in a child theme.
  336. * @since 1.0
  337. */
  338. function kleo_entry_meta( $echo = true, $att = array() ) {
  339.  
  340. global $kleo_config;
  341. $meta_list = array();
  342. $author_links = '';
  343. $meta_elements = sq_option( 'blog_meta_elements', $kleo_config['blog_meta_defaults'] );
  344.  
  345. // Translators: used between list items, there is a space after the comma.
  346. if ( in_array( 'categories', $meta_elements ) ) {
  347. $categories_list = get_the_category_list( __( ', ', 'kleo_framework' ) );
  348. }
  349.  
  350. // Translators: used between list items, there is a space after the comma.
  351. if ( in_array( 'tags', $meta_elements ) ) {
  352. $tag_list = get_the_tag_list( '', __( ', ', 'kleo_framework' ) );
  353. }
  354.  
  355. $date = sprintf( '<a href="%1$s" rel="bookmark" class="post-time">' .
  356. '<time class="entry-date" datetime="%2$s">%3$s</time>' .
  357. '<time class="modify-date hide hidden updated" datetime="%4$s">%5$s</time>' .
  358. '</a>',
  359. esc_url( get_permalink() ),
  360. esc_attr( get_the_date( 'c' ) ),
  361. esc_html( get_the_date() ),
  362. esc_html( get_the_modified_date( 'c' ) ),
  363. esc_html( get_the_modified_date() )
  364. );
  365.  
  366.  
  367. if ( is_array( $meta_elements ) && ! empty( $meta_elements ) ) {
  368.  
  369.  
  370. if ( in_array( 'author_link', $meta_elements ) || in_array( 'avatar', $meta_elements ) ) {
  371.  
  372. /* If buddypress is active then create a link to Buddypress profile instead */
  373. if ( function_exists( 'bp_is_active' ) ) {
  374. $author_link = esc_url( bp_core_get_userlink( get_the_author_meta( 'ID' ), $no_anchor = false, $just_link = true ) );
  375. $author_title = esc_attr( sprintf( __( 'View %s\'s profile', 'kleo_framework' ), get_the_author() ) );
  376. } else {
  377. $author_link = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
  378. $author_title = esc_attr( sprintf( __( 'View all POSTS by %s', 'kleo_framework' ), get_the_author() ) );
  379. }
  380.  
  381. $author = sprintf( '<a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s %4$s</a>',
  382. $author_link,
  383. $author_title,
  384. in_array( 'avatar', $meta_elements ) ? get_avatar( get_the_author_meta( 'ID' ), 50 ) : '',
  385. in_array( 'author_link', $meta_elements ) ? '<span class="author-name">' . get_the_author() . '</span>' : ''
  386. );
  387.  
  388. $meta_list[] = '<small class="meta-author author vcard">' . $author . '</small>';
  389. }
  390.  
  391. if ( function_exists( 'bp_is_active' ) ) {
  392. if ( in_array( 'profile', $meta_elements ) ) {
  393. $author_links .= '<a href="' . bp_core_get_userlink( get_the_author_meta( 'ID' ), $no_anchor = false, $just_link = true ) . '">' .
  394. '<i class="icon-user-1 hover-tip" ' .
  395. 'data-original-title="' . esc_attr( sprintf( __( 'View profile', 'kleo_framework' ), get_the_author() ) ) . '"' .
  396. 'data-toggle="tooltip"' .
  397. 'data-placement="top"></i>' .
  398. '</a>';
  399. }
  400.  
  401. if ( bp_is_active( 'messages' ) && is_user_logged_in() ) {
  402. if ( in_array( 'message', $meta_elements ) ) {
  403. $author_links .= '<a href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username( get_the_author_meta( 'ID' ) ) ) . '">' .
  404. '<i class="icon-mail hover-tip" ' .
  405. 'data-original-title="' . esc_attr( sprintf( __( 'Contact %s', 'kleo_framework' ), get_the_author() ) ) . '" ' .
  406. 'data-toggle="tooltip" ' .
  407. 'data-placement="top"></i>' .
  408. '</a>';
  409. }
  410. }
  411. }
  412.  
  413. if ( in_array( 'archive', $meta_elements ) ) {
  414. $author_links .= '<a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' .
  415. '<i class="icon-docs hover-tip" ' .
  416. 'data-original-title="' . esc_attr( sprintf( __( 'View all posts by %s', 'kleo_framework' ), get_the_author() ) ) . '" ' .
  417. 'data-toggle="tooltip" ' .
  418. 'data-placement="top"></i>' .
  419. '</a>';
  420. }
  421. }
  422.  
  423. if ( '' != $author_links ) {
  424. $meta_list[] = '<small class="meta-links">' . $author_links . '</small>';
  425. }
  426.  
  427. if ( in_array( 'date', $meta_elements ) ) {
  428. $meta_list[] = '<small>' . $date . '</small>';
  429. }
  430.  
  431. $cat_tag = array();
  432.  
  433. if ( isset( $categories_list ) && $categories_list ) {
  434. $cat_tag[] = $categories_list;
  435. }
  436.  
  437. if ( isset( $tag_list ) && $tag_list ) {
  438. $cat_tag[] = $tag_list;
  439. }
  440. if ( ! empty( $cat_tag ) ) {
  441. $meta_list[] = '<small class="meta-category">' . implode( ', ', $cat_tag ) . '</small>';
  442. }
  443.  
  444. //comments
  445. if ( ( ! isset( $att['comments'] ) || ( isset( $att['comments'] ) && false != $att['comments'] ) ) && in_array( 'comments', $meta_elements ) ) {
  446. $meta_list[] = '<small class="meta-comment-count"><a href="' . get_permalink() . '#comments">' . get_comments_number() .
  447. ' <i class="icon-chat-1 hover-tip" ' .
  448. 'data-original-title="' . sprintf( _n( 'This article has one comment', 'This article has %1$s comments', get_comments_number(), 'kleo_framework' ), number_format_i18n( get_comments_number() ) ) . '" ' .
  449. 'data-toggle="tooltip" ' .
  450. 'data-placement="top"></i>' .
  451. '</a></small>';
  452. }
  453.  
  454. $meta_separator = isset( $att['separator'] ) ? $att['separator'] : sq_option( 'blog_meta_sep', ', ' );
  455.  
  456. if ( $echo ) {
  457. echo implode( $meta_separator, $meta_list );
  458. } else {
  459. return implode( $meta_separator, $meta_list );
  460. }
  461.  
  462.  
  463. }
  464. endif;
  465.  
  466.  
  467. /***************************************************
  468. * :: Comments functions
  469. ***************************************************/
  470.  
  471.  
  472. if ( ! function_exists( 'kleo_custom_comments' ) ) {
  473. /**
  474. * Display customized comments
  475. *
  476. * @param object $comment
  477. * @param array $args
  478. * @param integer $depth
  479. */
  480. function kleo_custom_comments( $comment, $args, $depth ) {
  481. $GLOBALS['comment'] = $comment;
  482. $GLOBALS['comment_depth'] = $depth;
  483. ?>
  484. <li id="comment-<?php comment_ID() ?>" <?php comment_class( 'clearfix' ) ?>>
  485. <div class="comment-wrap clearfix">
  486. <div class="comment-avatar kleo-rounded">
  487. <?php
  488. if ( function_exists( 'get_avatar' ) ) {
  489. echo get_avatar( $comment, '100' );
  490. }
  491. ?>
  492. <?php if ( get_the_author_meta( 'email' ) == $comment->comment_author_email ) { ?>
  493. <span class="tooltip"><?php _e( 'Author', 'kleo_framework' ); ?><span class="arrow"></span></span>
  494. <?php } ?>
  495. </div>
  496. <div class="comment-content">
  497. <div class="comment-meta">
  498. <?php
  499. printf( '<span class="comment-author">%1$s</span> <span class="comment-date">%2$s</span>',
  500. get_comment_author_link(),
  501. human_time_diff( get_comment_time( 'U' ), current_time( 'timestamp' ) ) . ' ' . __( 'ago', 'kleo_framework' )
  502. );
  503. ?>
  504. </div>
  505. <?php
  506. if ( '0' == $comment->comment_approved ) {
  507. _e( "<span class='unapproved'>Your comment is awaiting moderation.</span>\n", 'kleo_framework' );
  508. }
  509. ?>
  510. <div class="comment-body">
  511. <?php comment_text() ?>
  512. </div>
  513. <div class="comment-meta-actions">
  514. <?php
  515. edit_comment_link( __( 'Edit', 'kleo_framework' ), '<span class="edit-link">', '</span><span class="meta-sep"> |</span>' );
  516. ?>
  517. <?php if ( 'all' == $args['type'] || 'comment' == get_comment_type() ) :
  518. comment_reply_link( array_merge( $args, array(
  519. 'reply_text' => __( 'Reply', 'kleo_framework' ),
  520. 'login_text' => __( 'Log in to reply.', 'kleo_framework' ),
  521. 'depth' => $depth,
  522. 'before' => '<span class="comment-reply">',
  523. 'after' => '</span>',
  524. ) ) );
  525. endif; ?>
  526. </div>
  527. </div>
  528. </div>
  529. <?php }
  530. } // end kleo_custom_comments
  531.  
  532.  
  533. if ( ! function_exists( 'kleo_comment_form' ) ) :
  534. /**
  535. * Outputs a complete commenting form for use within a template.
  536. * Most strings and form fields may be controlled through the $args array passed
  537. * into the function, while you may also choose to use the comment_form_default_fields
  538. * filter to modify the array of default fields if you'd just like to add a new
  539. * one or remove a single field. All fields are also individually passed through
  540. * a filter of the form comment_form_field_$name where $name is the key used
  541. * in the array of fields.
  542. *
  543. * @param array $args Options for strings, fields etc in the form
  544. * @param mixed $post_id Post ID to generate the form for, uses the current post if null
  545. *
  546. * @return void
  547. */
  548. function kleo_comment_form( $args = array(), $post_id = null ) {
  549. global $id;
  550.  
  551. $user = wp_get_current_user();
  552. $user_identity = $user->exists() ? $user->display_name : '';
  553.  
  554. if ( null === $post_id ) {
  555. $post_id = $id;
  556. } else {
  557. $id = $post_id;
  558. }
  559.  
  560. if ( comments_open( $post_id ) ) :
  561. ?>
  562. <div id="respond-wrap">
  563. <?php
  564. $commenter = wp_get_current_commenter();
  565. $req = get_option( 'require_name_email' );
  566. $aria_req = ( $req ? " aria-required='true'" : '' );
  567. $consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
  568. $fields = array(
  569. 'author' => '<div class="row"><p class="comment-form-author col-sm-4"><label for="author">' . __( 'Name', 'kleo_framework' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="author" name="author" type="text" class="form-control" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
  570. 'email' => '<p class="comment-form-email col-sm-4"><label for="email">' . __( 'Email', 'kleo_framework' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="email" name="email" type="text" class="form-control" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
  571. 'url' => '<p class="comment-form-url col-sm-4"><label for="url">' . __( 'Website', 'kleo_framework' ) . '</label><input id="url" name="url" type="text" class="form-control" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p></div>',
  572. 'cookies' => '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' .
  573. '<label for="wp-comment-cookies-consent">' . __( 'Save my name, email, and website in this browser for the next time I comment.', 'kleo_framework' ) . '</label></p>',
  574. );
  575.  
  576. if ( function_exists( 'bp_is_active' ) ) {
  577. $profile_link = bp_get_loggedin_user_link();
  578. } else {
  579. $profile_link = admin_url( 'profile.php' );
  580. }
  581.  
  582. $comments_args = array(
  583. 'fields' => apply_filters( 'comment_form_default_fields', $fields ),
  584. 'logged_in_as' => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>', 'kleo_framework' ), $profile_link, $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink() ) ) ) . '</p>',
  585. 'title_reply' => __( 'Leave a reply', 'kleo_framework' ),
  586. 'title_reply_to' => __( 'Leave a reply to %s', 'kleo_framework' ),
  587. 'cancel_reply_link' => __( 'Click here to cancel the reply', 'kleo_framework' ),
  588. 'label_submit' => __( 'Post comment', 'kleo_framework' ),
  589. 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . __( 'Comment', 'kleo_framework' ) . '</label><textarea class="form-control" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
  590. 'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.', 'kleo_framework' ), wp_login_url( apply_filters( 'the_permalink', get_permalink() ) ) ) . '</p>',
  591. );
  592.  
  593. comment_form( $comments_args );
  594. ?>
  595. </div>
  596.  
  597. <?php
  598. endif;
  599.  
  600. }
  601. endif;
  602.  
  603.  
  604. if ( ! function_exists( 'kleo_the_attached_image' ) ) :
  605. /**
  606. * Print the attached image with a link to the next attached image.
  607. *
  608. * @since Kleo 1.0
  609. *
  610. * @return void
  611. */
  612. function kleo_the_attached_image() {
  613. $post = get_post();
  614. /**
  615. * Filter the default attachment size.
  616. *
  617. * @since Kleo 1.0
  618. *
  619. * @param array $dimensions {
  620. * An array of height and width dimensions.
  621. *
  622. * @type int $height Height of the image in pixels. Default 810.
  623. * @type int $width Width of the image in pixels. Default 810.
  624. * }
  625. */
  626. $attachment_size = apply_filters( 'kleo_attachment_size', array( 810, 810 ) );
  627. $next_attachment_url = wp_get_attachment_url();
  628.  
  629. /*
  630. * Grab the IDs of all the image attachments in a gallery so we can get the URL
  631. * of the next adjacent image in a gallery, or the first image (if we're
  632. * looking at the last image in a gallery), or, in a gallery of one, just the
  633. * link to that image file.
  634. */
  635. $attachment_ids = get_posts( array(
  636. 'post_parent' => $post->post_parent,
  637. 'fields' => 'ids',
  638. 'numberposts' => - 1,
  639. 'post_status' => 'inherit',
  640. 'post_type' => 'attachment',
  641. 'post_mime_type' => 'image',
  642. 'order' => 'ASC',
  643. 'orderby' => 'menu_order ID',
  644. ) );
  645.  
  646. // If there is more than 1 attachment in a gallery...
  647. if ( count( $attachment_ids ) > 1 ) {
  648. foreach ( $attachment_ids as $attachment_id ) {
  649. if ( $attachment_id == $post->ID ) {
  650. $next_id = current( $attachment_ids );
  651. break;
  652. }
  653. }
  654.  
  655. // get the URL of the next image attachment...
  656. if ( isset( $next_id ) && $next_id ) {
  657. $next_attachment_url = get_attachment_link( $next_id );
  658. } // or get the URL of the first image attachment.
  659. else {
  660. $next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) );
  661. }
  662. }
  663.  
  664. printf( '<a href="%1$s" rel="attachment">%2$s</a>',
  665. esc_url( $next_attachment_url ),
  666. wp_get_attachment_image( $post->ID, $attachment_size )
  667. );
  668. }
  669. endif;
  670.  
  671.  
  672. /***************************************************
  673. * :: Sidebar logic
  674. ***************************************************/
  675. if ( ! function_exists( 'kleo_switch_layout' ) ) {
  676. /**
  677. * Change site layout
  678. *
  679. * @param bool $layout
  680. * @param int $priority
  681. */
  682. function kleo_switch_layout( $layout = false, $priority = 10 ) {
  683. if ( false == $layout ) {
  684. $layout = sq_option( 'global_sidebar', 'right' );
  685. }
  686.  
  687. $main_width_2cols = (int) sq_option( 'main_width_2cols', 9 ) == 0 ? 9 : (int) sq_option( 'main_width_2cols', 9 );
  688. $main_width_3cols = (int) sq_option( 'main_width_3cols', 6 ) == 0 ? 6 : (int) sq_option( 'main_width_3cols', 6 );
  689.  
  690. $sidebar_width_2cols = 12 - $main_width_2cols;
  691. $sidebar_width_3cols = ( 12 - $main_width_3cols ) / 2;
  692.  
  693. switch ( $layout ) {
  694.  
  695. case 'left':
  696. add_action( 'kleo_after_content', 'kleo_sidebar', $priority );
  697. remove_action( 'kleo_after_content', 'kleo_extra_sidebar' );
  698.  
  699. add_filter( 'kleo_main_template_classes', function( $cols ) use( $main_width_2cols, $sidebar_width_2cols ) {
  700. $cols = "col-sm-$main_width_2cols col-sm-push-$sidebar_width_2cols tpl-left";
  701. return $cols;
  702. }, $priority );
  703.  
  704. add_filter( 'kleo_sidebar_classes', function( $cols ) use( $sidebar_width_2cols, $main_width_2cols ) {
  705. $cols = "col-sm-$sidebar_width_2cols sidebar-left col-sm-pull-$main_width_2cols";
  706. return $cols;
  707. }, $priority );
  708.  
  709. remove_filter( 'kleo_main_container_class', 'kleo_ret_full_container', $priority );
  710. break;
  711.  
  712. case 'no': //full width
  713. case 'full': //full width
  714. remove_action( 'kleo_after_content', 'kleo_sidebar' );
  715. remove_action( 'kleo_after_content', 'kleo_extra_sidebar' );
  716.  
  717. add_filter( 'kleo_main_template_classes', function() {
  718. $cols = 'col-sm-12 tpl-no';
  719. return $cols;
  720. }, $priority );
  721.  
  722. //enable full-width elements
  723. $has_vc = kleo_has_shortcode( 'vc_row' );
  724. sq_kleo()->set_option( 'has_vc_shortcode', $has_vc );
  725.  
  726. if ( ! is_singular( 'product' ) && $has_vc ) {
  727. add_filter( 'kleo_main_container_class', 'kleo_ret_full_container', $priority );
  728. }
  729.  
  730. break;
  731.  
  732. case '3ll':
  733. add_action( 'kleo_after_content', 'kleo_sidebar', $priority );
  734. add_action( 'kleo_after_content', 'kleo_extra_sidebar', $priority );
  735.  
  736. add_filter( 'kleo_main_template_classes', function( $cols ) use( $main_width_3cols, $sidebar_width_3cols ) {
  737. $cols = 'col-sm-' . $main_width_3cols . ' col-sm-push-' . ( $sidebar_width_3cols * 2 ) . ' tpl-3ll';
  738. return $cols;
  739. }, $priority );
  740.  
  741. add_filter( 'kleo_sidebar_classes', function( $cols ) use( $sidebar_width_3cols, $main_width_3cols ) {
  742. $cols = 'col-sm-' . $sidebar_width_3cols . ' col-sm-pull-' . $main_width_3cols . ' sidebar-3ll';
  743. return $cols;
  744. }, $priority );
  745.  
  746. add_filter( 'kleo_extra_sidebar_classes', function( $cols ) use( $sidebar_width_3cols, $main_width_3cols ) {
  747. $cols = 'col-sm-' . $sidebar_width_3cols . ' col-sm-pull-' . '$main_width_3cols' . ' sidebar-3ll';
  748. return $cols;
  749. }, $priority );
  750.  
  751. remove_filter( 'kleo_main_container_class', 'kleo_ret_full_container', $priority );
  752. break;
  753.  
  754. case '3lr':
  755. add_action( 'kleo_after_content', 'kleo_sidebar', $priority );
  756. add_action( 'kleo_after_content', 'kleo_extra_sidebar', $priority );
  757. add_filter( 'kleo_main_template_classes', function( $cols) use( $main_width_3cols, $sidebar_width_3cols ) {
  758. $cols = 'col-sm-' . $main_width_3cols . ' col-sm-push-' . $sidebar_width_3cols . ' tpl-3lr';
  759. return $cols;
  760. }, $priority );
  761.  
  762. add_filter( 'kleo_sidebar_classes', function( $cols ) use( $sidebar_width_3cols, $main_width_3cols ) {
  763. $cols = 'col-sm-' . $sidebar_width_3cols . ' col-sm-pull-' . $main_width_3cols . ' sidebar-3lr';
  764. return $cols;
  765. }, $priority );
  766.  
  767. add_filter( 'kleo_extra_sidebar_classes', function( $cols ) use( $sidebar_width_3cols ) {
  768. $cols = 'col-sm-' . $sidebar_width_3cols . ' sidebar-3lr';
  769. return $cols;
  770. }, $priority );
  771.  
  772. remove_filter( 'kleo_main_container_class', 'kleo_ret_full_container', $priority );
  773. break;
  774.  
  775. case '3rr':
  776. add_action( 'kleo_after_content', 'kleo_sidebar', $priority );
  777. add_action( 'kleo_after_content', 'kleo_extra_sidebar', $priority );
  778.  
  779. add_filter( 'kleo_main_template_classes', function( $cols ) use ( $main_width_3cols ) {
  780. $cols = "col-sm-$main_width_3cols tpl-3rr";
  781. return $cols;
  782. }, $priority );
  783.  
  784. add_filter( 'kleo_sidebar_classes', function( $cols ) use( $sidebar_width_3cols ) {
  785. $cols = "col-sm-$sidebar_width_3cols sidebar-3rr";
  786. return $cols;
  787. }, $priority );
  788.  
  789. add_filter( 'kleo_extra_sidebar_classes', function( $cols ) use( $sidebar_width_3cols ) {
  790. $cols = "col-sm-$sidebar_width_3cols sidebar-3rr";
  791. return $cols;
  792. }, $priority );
  793.  
  794. remove_filter( 'kleo_main_container_class', 'kleo_ret_full_container', $priority );
  795. break;
  796.  
  797. case 'right':
  798. default:
  799. add_action( 'kleo_after_content', 'kleo_sidebar', $priority );
  800. remove_action( 'kleo_after_content', 'kleo_extra_sidebar' );
  801.  
  802. add_filter( 'kleo_main_template_classes', function( $cols ) use( $main_width_2cols ) {
  803. $cols = "col-sm-$main_width_2cols tpl-right";
  804. return $cols;
  805. }, $priority );
  806.  
  807. add_filter( 'kleo_sidebar_classes', function( $cols ) use( $sidebar_width_2cols ) {
  808. $cols = "col-sm-$sidebar_width_2cols sidebar-right";
  809. return $cols;
  810. }, $priority );
  811.  
  812. remove_filter( 'kleo_main_container_class', 'kleo_ret_full_container', $priority );
  813. break;
  814. }
  815. }
  816. }
  817.  
  818. if ( ! function_exists( 'kleo_prepare_layout' ) ) {
  819. /**
  820. * Prepare site layout with different customizations
  821. * @global string $kleo_custom_logo
  822. */
  823. function kleo_prepare_layout() {
  824.  
  825. //Change the template
  826. $layout = sq_option( 'global_sidebar', 'right' );
  827.  
  828. if ( is_home() ) {
  829. $layout = sq_option( 'blog_layout', 'right' );
  830. } elseif ( is_archive() ) {
  831. $layout = sq_option( 'cat_layout', 'right' );
  832. } elseif ( is_single() ) {
  833. if ( get_cfield( 'post_layout' ) && get_cfield( 'post_layout' ) != 'default' ) {
  834. $layout = get_cfield( 'post_layout' );
  835. } elseif ( sq_option( 'blog_post_layout', 'default' ) != 'default' ) {
  836. $layout = sq_option( 'blog_post_layout', 'right' );
  837. }
  838. }
  839.  
  840. $layout = apply_filters( 'kleo_page_layout', $layout );
  841. kleo_switch_layout( $layout );
  842.  
  843. /* Single post of any post type */
  844. if ( is_singular() || is_home() ) {
  845. $topbar_status = get_cfield( 'topbar_status' );
  846. //Top bar
  847. if ( isset( $topbar_status ) ) {
  848. if ( '1' === $topbar_status ) {
  849. add_filter( 'kleo_show_top_bar', function() { return 1; } );
  850. } elseif ( '0' === $topbar_status ) {
  851. add_filter( 'kleo_show_top_bar', '__return_zero' );
  852. }
  853. }
  854.  
  855. //Header and Footer settings
  856. if ( get_cfield( 'hide_header' ) && get_cfield( 'hide_header' ) == 1 ) {
  857. remove_action( 'kleo_header', 'kleo_show_header' );
  858. }
  859. if ( get_cfield( 'hide_footer' ) && get_cfield( 'hide_footer' ) == 1 ) {
  860. add_filter( 'kleo_footer_hidden', '__return_true' );
  861. }
  862. if ( get_cfield( 'hide_socket' ) && get_cfield( 'hide_socket' ) == 1 ) {
  863. remove_action( 'kleo_after_footer', 'kleo_show_socket' );
  864. }
  865.  
  866. //Custom logo
  867. if ( get_cfield( 'logo' ) ) {
  868. global $kleo_custom_logo;
  869. $kleo_custom_logo = get_cfield( 'logo' );
  870. add_filter( 'kleo_logo', function() use( $kleo_custom_logo ) {
  871. return $kleo_custom_logo;
  872. });
  873. }
  874.  
  875. //Remove shop icon
  876. if ( get_cfield( 'hide_shop_icon' ) && get_cfield( 'hide_shop_icon' ) == 1 ) {
  877. remove_filter( 'wp_nav_menu_items', 'kleo_woo_header_cart', 9 );
  878. remove_filter( 'kleo_mobile_header_icons', 'kleo_woo_mobile_icon', 10 );
  879. }
  880. //Remove search icon
  881. if ( get_cfield( 'hide_search_icon' ) && get_cfield( 'hide_search_icon' ) == 1 ) {
  882. remove_filter( 'wp_nav_menu_items', 'kleo_search_menu_item', 200, 2 );
  883. }
  884.  
  885. if ( get_cfield( 'header_layout' ) && get_cfield( 'header_layout' ) != 'default' ) {
  886. add_filter( 'sq_option', 'kleo_override_header_layout', 10, 2 );
  887. }
  888.  
  889. //title section css
  890. global $kleo_theme;
  891. if ( get_cfield( 'title_top_padding' ) && get_cfield( 'title_top_padding' ) != '' ) {
  892. $kleo_theme->add_css( '.main-title {padding-top: ' . get_cfield( 'title_top_padding' ) . 'px;}' );
  893. }
  894. if ( get_cfield( 'title_bottom_padding' ) && get_cfield( 'title_bottom_padding' ) != '' ) {
  895. $kleo_theme->add_css( '.main-title {padding-bottom: ' . get_cfield( 'title_bottom_padding' ) . 'px;}' );
  896. }
  897. if ( get_cfield( 'title_color' ) && get_cfield( 'title_color' ) != '#' && get_cfield( 'title_color' ) != '' ) {
  898. $kleo_theme->add_css( '.main-title, .main-title h1, .main-title a, .main-title span, .breadcrumb > li + li:before {color: ' . get_cfield( 'title_color' ) . ' !important;}' );
  899. }
  900. if ( get_cfield( 'title_bg_color' ) && get_cfield( 'title_bg_color' ) != '#' && get_cfield( 'title_bg_color' ) != '' ) {
  901. $kleo_theme->add_css( '.main-title {background-color: ' . get_cfield( 'title_bg_color' ) . ' !important;}' );
  902. }
  903. if ( get_cfield( 'title_bg' ) && is_array( get_cfield( 'title_bg' ) ) ) {
  904. $title_bg = get_cfield( 'title_bg' );
  905. if ( isset( $title_bg['url'] ) && '' != $title_bg['url'] ) {
  906. $kleo_theme->add_css( '.main-title {' .
  907. 'background-image: url("' . $title_bg['url'] . '");' .
  908. 'background-repeat: ' . $title_bg['repeat'] . ';' .
  909. 'background-size: ' . $title_bg['size'] . ';' .
  910. 'background-attachment: ' . $title_bg['attachment'] . ';' .
  911. 'background-position: ' . $title_bg['position'] . ';' .
  912. '}'
  913. );
  914. }
  915. }
  916. }
  917.  
  918. //Show title in main content - if set from Theme options
  919. add_action( 'kleo_before_main_content', 'kleo_title_main_content' );
  920. }
  921. }
  922.  
  923. add_action( 'wp_head', 'kleo_prepare_layout' );
  924.  
  925.  
  926. //get the global sidebar
  927. if ( ! function_exists( 'kleo_sidebar' ) ) :
  928. function kleo_sidebar() {
  929. get_sidebar();
  930. }
  931. endif;
  932.  
  933. //get the extra sidebar
  934. if ( ! function_exists( 'kleo_extra_sidebar' ) ) :
  935. function kleo_extra_sidebar() {
  936. $classes = apply_filters( 'kleo_extra_sidebar_classes', '' );
  937.  
  938. echo '<div class="sidebar sidebar-extra ' . $classes . '">'
  939. . '<div class="inner-content">';
  940.  
  941. generated_dynamic_sidebar( 'extra' );
  942.  
  943. echo '</div>'
  944. . '</div> <!--end sidebar columns-->';
  945. }
  946. endif;
  947.  
  948. function kleo_ret_full_container() {
  949. return 'container-full';
  950. }
  951.  
  952. if ( ! function_exists( 'kleo_title_main_content' ) ) {
  953. /**
  954. * Echo the title if it was set to show in main content area
  955. */
  956. function kleo_title_main_content() {
  957. if ( sq_option( 'title_location', 'breadcrumb' ) == 'main' && sq_option( 'title_status', 1 ) != 0 ) {
  958.  
  959. $title_status = true;
  960. if ( ( is_singular() || is_home() ) && get_cfield( 'title_checkbox' ) == 1 ) {
  961. $title_status = false;
  962. }
  963.  
  964. if ( $title_status ) {
  965. if ( ( is_singular() || is_home() ) && get_cfield( 'custom_title' ) && get_cfield( 'custom_title' ) != '' ) {
  966. $title = get_cfield( 'custom_title' );
  967. } else {
  968. $title = kleo_title();
  969. }
  970.  
  971. echo '<div class="container">';
  972. echo '<h1 class="page-title">' . $title . '</h1>';
  973. echo '</div>';
  974. }
  975. }
  976. }
  977. }
  978.  
  979. /* Change the html page title if we set a custom title */
  980. add_filter( 'single_post_title', 'kleo_check_single_post_title', 10, 2 );
  981. function kleo_check_single_post_title( $title, $post = false ) {
  982.  
  983. if ( ! $post || ! isset( $post->ID ) ) {
  984. return $title;
  985. }
  986.  
  987. if ( get_cfield( 'custom_title', $post->ID ) && get_cfield( 'custom_title', $post->ID ) != '' ) {
  988. return get_cfield( 'custom_title', $post->ID );
  989. }
  990.  
  991. return $title;
  992. }
  993.  
  994.  
  995. /***************************************************
  996. * :: Render the header section with the menus
  997. ***************************************************/
  998.  
  999. function kleo_show_header() {
  1000. get_template_part( 'page-parts/general-header-section' );
  1001. }
  1002.  
  1003. add_action( 'kleo_header', 'kleo_show_header' );
  1004.  
  1005.  
  1006. /***************************************************
  1007. * :: Extra body classes
  1008. ***************************************************/
  1009.  
  1010. add_filter( 'body_class', 'kleo_body_classes' );
  1011.  
  1012. /**
  1013. * Adds specific classes to body element
  1014. *
  1015. * @param array $classes
  1016. *
  1017. * @return array
  1018. * @since 1.0
  1019. */
  1020. function kleo_body_classes( $classes = array() ) {
  1021.  
  1022. if ( is_admin_bar_showing() && sq_option( 'admin_bar', 1 ) == 1 ) {
  1023. $classes[] = 'adminbar-enable';
  1024. }
  1025.  
  1026. if ( sq_option( 'responsive_design', 1 ) == 0 ) {
  1027. $classes[] = 'not-responsive';
  1028. }
  1029.  
  1030. if ( sq_option( 'sticky_menu', 1 ) == 1 ) {
  1031. $classes[] = 'kleo-navbar-fixed';
  1032.  
  1033. if ( sq_option( 'resize_logo', 1 ) == 1 ) {
  1034. $classes[] = 'navbar-resize';
  1035. }
  1036. }
  1037.  
  1038. if ( ( sq_option( 'sticky_menu', 1 ) == 1 && sq_option( 'transparent_logo', 1 ) == 1 )
  1039. || ( ( is_singular() || ( is_home() && get_option( 'page_for_posts' ) ) ) && get_cfield( 'transparent_menu' ) )
  1040. ) {
  1041. $classes[] = 'navbar-transparent';
  1042.  
  1043. if ( get_cfield( 'transparent_menu_color' ) === 'black' ) {
  1044. $classes[] = 'on-light-bg';
  1045. } else {
  1046. $classes[] = 'on-dark-bg';
  1047. }
  1048.  
  1049. if ( sq_option( 'header_overlay_hover', 0 ) == 1 ) {
  1050. $classes[] = 'navbar-hover-opacity';
  1051. }
  1052. }
  1053.  
  1054. if ( sq_option( 'sitewide_animations', 'enabled' ) == 'disable-all' ) {
  1055. $classes[] = 'disable-all-animations';
  1056. }
  1057.  
  1058. if ( sq_option( 'sitewide_animations', 'enabled' ) == 'disable-mobile' ) {
  1059. $classes[] = 'disable-all-animations-on-mobile';
  1060. }
  1061.  
  1062. if ( sq_option( 'menu_full_width', 0 ) == 1 || ( is_singular() && get_cfield( 'menu_full_width' ) ) ) {
  1063. $classes[] = 'navbar-full-width';
  1064. }
  1065.  
  1066. /* Flexmenu */
  1067. if ( sq_option( 'header_flexmenu', 0 ) == 1 ) {
  1068. $classes[] = 'header-overflow';
  1069. $classes[] = 'header-flexmenu';
  1070. }
  1071.  
  1072. /* Two row header */
  1073. $header_style = sq_option( 'header_layout', 'normal' );
  1074. if ( 'left_logo' == $header_style || 'center_logo' == $header_style ) {
  1075. $classes[] = 'header-two-rows';
  1076. }
  1077.  
  1078. /* Stick footer */
  1079. if ( 1 == sq_option( 'footer_bottom', 0 ) ) {
  1080. $classes[] = 'footer-bottom';
  1081. }
  1082.  
  1083. return $classes;
  1084. }
  1085.  
  1086. // -----------------------------------------------------------------------------
  1087.  
  1088.  
  1089. /***************************************************
  1090. * :: Theme options link in Admin bar
  1091. ***************************************************/
  1092.  
  1093. add_action( 'admin_bar_menu', 'kleo_add_adminbar_options', 100 );
  1094.  
  1095. /**
  1096. * @param WP_Admin_Bar $admin_bar
  1097. */
  1098. function kleo_add_adminbar_options( $admin_bar ) {
  1099. if ( is_super_admin() && ! is_admin() ) {
  1100. $admin_bar->add_menu( array(
  1101. 'id' => 'theme-options',
  1102. 'title' => __( 'Theme options', 'kleo_framework' ),
  1103. 'href' => get_admin_url() . 'admin.php?page=kleo_options',
  1104. 'meta' => array(
  1105. 'title' => __( 'Theme options', 'kleo_framework' ),
  1106. 'target' => '_blank',
  1107. ),
  1108. ) );
  1109. }
  1110.  
  1111. }
  1112.  
  1113. /***************************************************
  1114. * :: Add mp4, webm and ogv mimes for uploads
  1115. ***************************************************/
  1116.  
  1117. add_filter( 'upload_mimes', 'kleo_add_upload_mimes' );
  1118. if ( ! function_exists( 'kleo_add_upload_mimes' ) ) {
  1119. function kleo_add_upload_mimes( $mimes ) {
  1120. return array_merge( $mimes, array( 'mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm' ) );
  1121. }
  1122. }
  1123.  
  1124.  
  1125. /***************************************************
  1126. * :: Scripts/Styles load
  1127. ***************************************************/
  1128.  
  1129. add_action( 'wp_enqueue_scripts', 'kleo_frontend_files' );
  1130. if ( ! function_exists( 'kleo_frontend_files' ) ) :
  1131. // Register some javascript files
  1132. function kleo_frontend_files() {
  1133. $min = sq_option( 'dev_mode', 0 ) == 1 ? '' : '.min';
  1134.  
  1135. /* If remove query option is ON */
  1136. if ( sq_option( 'perf_remove_query', 0 ) == 1 ) {
  1137. $version = null;
  1138. } else {
  1139. $version = KLEO_THEME_VERSION;
  1140. }
  1141.  
  1142. //head scripts
  1143. //wp_register_script( 'kleo-init', get_template_directory_uri() . '/assets/js/init.js', array(), $version, false );
  1144. wp_register_script( 'modernizr', get_template_directory_uri() . '/assets/js/modernizr.custom.46504.js', array(), $version, false );
  1145.  
  1146. /* Footer scripts */
  1147. if ( sq_option( 'perf_combine_js', 0 ) == 1 ) {
  1148. wp_register_script( 'kleo-combined', get_template_directory_uri() . '/assets/js/combined' . $min . '.js', array( 'jquery' ), $version, true );
  1149. } else {
  1150. wp_register_script( 'bootstrap', get_template_directory_uri() . '/assets/js/bootstrap' . $min . '.js', array( 'jquery' ), $version, true );
  1151. wp_register_script( 'waypoints', get_template_directory_uri() . '/assets/js/plugins/waypoints.min.js', array( 'jquery' ), $version, true );
  1152. wp_register_script( 'magnific-popup', get_template_directory_uri() . '/assets/js/plugins/magnific-popup/magnific.min.js', array( 'jquery' ), $version, true );
  1153. wp_register_script( 'caroufredsel', get_template_directory_uri() . '/assets/js/plugins/carouFredSel/jquery.carouFredSel-6.2.0-packed.js', array( 'jquery' ), $version, true );
  1154. wp_register_script( 'jquery-mousewheel', get_template_directory_uri() . '/assets/js/plugins/carouFredSel/helper-plugins/jquery.mousewheel.min.js', array(
  1155. 'jquery',
  1156. 'caroufredsel',
  1157. ), $version, true );
  1158. wp_register_script( 'jquery-touchswipe', get_template_directory_uri() . '/assets/js/plugins/carouFredSel/helper-plugins/jquery.touchSwipe.min.js', array(
  1159. 'jquery',
  1160. 'caroufredsel',
  1161. ), $version, true );
  1162. wp_register_script( 'isotope', get_template_directory_uri() . '/assets/js/plugins/jquery.isotope.min.js', array( 'jquery' ), $version, true );
  1163.  
  1164. }
  1165. wp_register_script( 'app', get_template_directory_uri() . '/assets/js/app' . $min . '.js', array( 'jquery' ), $version, true );
  1166.  
  1167. //not loaded by default. Only when needed by shortcodes
  1168. wp_register_script( 'three-canvas', get_template_directory_uri() . '/assets/js/plugins/snow/ThreeCanvas.js', array( 'app' ), $version, true );
  1169. wp_register_script( 'snow', get_template_directory_uri() . '/assets/js/plugins/snow/Snow.js', array( 'three-canvas' ), $version, true );
  1170. wp_register_script( 'particles-js', get_template_directory_uri() . '/assets/js/plugins/particles.min.js', array( 'jquery' ), $version, true );
  1171. wp_register_script( 'bootstrap-multiselect', get_template_directory_uri() . '/assets/js/plugins/bootstrap-multiselect.js', array( 'jquery' ), $version, true );
  1172.  
  1173. //enqueue them
  1174. //wp_enqueue_script( 'kleo-init' );
  1175. wp_enqueue_script( 'modernizr' );
  1176.  
  1177. if ( sq_option( 'perf_combine_js', 0 ) == 1 ) {
  1178. wp_enqueue_script( 'kleo-combined' );
  1179. } else {
  1180. wp_enqueue_script( 'bootstrap' );
  1181. wp_enqueue_script( 'waypoints' );
  1182. wp_enqueue_script( 'magnific-popup' );
  1183. wp_enqueue_script( 'caroufredsel' );
  1184. wp_enqueue_script( 'jquery-touchswipe' );
  1185. wp_enqueue_script( 'isotope' );
  1186. }
  1187. wp_enqueue_script( 'mediaelement' );
  1188. wp_enqueue_script( 'app' );
  1189.  
  1190.  
  1191. $regular_logo = sq_option_url('logo', '');
  1192. if (is_singular() && get_cfield('logo')) {
  1193. $regular_logo = get_cfield('logo');
  1194. }
  1195. $retina_logo = sq_option_url('logo_retina') != '' ? sq_option_url('logo_retina') : '';
  1196. if (is_singular() && get_cfield('logo_retina')) {
  1197. $retina_logo = get_cfield('logo_retina');
  1198. }
  1199.  
  1200. if( wp_is_mobile() ) {
  1201. $mobile_logo = false;
  1202. if(sq_option_url('mobile_logo', '') != '') {
  1203. $regular_logo = sq_option_url('mobile_logo', '');
  1204. $mobile_logo = true;
  1205. }
  1206. if (is_singular() && get_cfield('mobile_logo')) {
  1207. $regular_logo = get_cfield('mobile_logo');
  1208. $mobile_logo = true;
  1209. }
  1210. if($mobile_logo) {
  1211. add_filter('kleo_logo', function ($logo) use ($regular_logo) {
  1212. return $regular_logo;
  1213. });
  1214. }
  1215. if( sq_option_url('mobile_logo_retina') != '' ) {
  1216. $retina_logo = sq_option_url('mobile_logo_retina');
  1217. }
  1218. if (is_singular() && get_cfield('mobile_logo_retina')) {
  1219. $retina_logo = get_cfield('mobile_logo_retina');
  1220. }
  1221. }
  1222.  
  1223. $header_height = intval( sq_option( 'menu_height', 88 ) );
  1224. $header_height_scrolled = intval( sq_option( 'menu_height_scrolled', '' ) );
  1225. $header_two_height = intval( sq_option( 'menu_two_height', 88 ) );
  1226. $header_two_height_scrolled = intval( sq_option( 'menu_two_height_scrolled', '' ) );
  1227. $header_resize_offset = sq_option( 'menu_scroll_offset', '' ) != '' ? intval( sq_option( 'menu_scroll_offset', '' ) ) : '';
  1228.  
  1229. $obj_array = array(
  1230. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  1231. 'themeUrl' => get_template_directory_uri(),
  1232. 'loginUrl' => site_url( 'wp-login.php', 'login_post' ),
  1233. 'goTop' => sq_option( 'go_top', 1 ),
  1234. 'ajaxSearch' => sq_option( 'ajax_search', 1 ),
  1235. 'alreadyLiked' => sq_option( 'likes_already', 'You already like this' ),
  1236. 'logo' => $regular_logo,
  1237. 'retinaLogo' => $retina_logo,
  1238. 'headerHeight' => $header_height,
  1239. 'headerHeightScrolled' => $header_height_scrolled,
  1240. 'headerTwoRowHeight' => $header_two_height,
  1241. 'headerTwoRowHeightScrolled' => $header_two_height_scrolled,
  1242. 'headerResizeOffset' => $header_resize_offset,
  1243. 'loadingmessage' => '<i class="icon icon-spin5 animate-spin"></i> ' . __( 'Sending info, please wait...', 'kleo_framework' ),
  1244. 'DisableMagnificGallery' => sq_option( 'magnific_disable_gallery', '0' ),
  1245. 'flexMenuEnabled' => sq_option( 'header_flexmenu', 0 ),
  1246. 'errorOcurred' => __('Sorry, an error occurred','kleo_framework'),
  1247. );
  1248. $obj_array = apply_filters( 'kleo_localize_app', $obj_array );
  1249.  
  1250. wp_localize_script( 'app', 'kleoFramework', $obj_array );
  1251.  
  1252. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  1253. wp_enqueue_script( 'comment-reply' );
  1254. }
  1255.  
  1256. /* Register the styles */
  1257.  
  1258. /* register only when Theme options - combine option is OFF */
  1259. if ( sq_option( 'perf_combine_css', 0 ) == 0 ) {
  1260. wp_register_style( 'bootstrap', get_template_directory_uri() . '/assets/css/bootstrap' . $min . '.css', array(), $version, 'all' );
  1261. wp_register_style( 'kleo-app', get_template_directory_uri() . '/assets/css/app' . $min . '.css', array(), $version, 'all' );
  1262. wp_register_style( 'magnific-popup', get_template_directory_uri() . '/assets/js/plugins/magnific-popup/magnific.css', array(), $version, 'all' );
  1263.  
  1264. wp_enqueue_style( 'bootstrap' );
  1265. wp_enqueue_style( 'kleo-app' );
  1266. wp_enqueue_style( 'magnific-popup' );
  1267. }
  1268.  
  1269. /* Load font icons */
  1270. $override_fonts = false;
  1271. if ( is_child_theme() && file_exists( get_stylesheet_directory() . '/assets/css/fontello.css' ) ) {
  1272. $fonts_path = get_stylesheet_directory_uri() . '/assets/css/fontello.css';
  1273. $override_fonts = true;
  1274. } else {
  1275. $fonts_path = get_template_directory_uri() . '/assets/css/fontello' . $min . '.css';
  1276. }
  1277.  
  1278. wp_register_style( 'kleo-fonts', $fonts_path, array(), $version, 'all' );
  1279. wp_register_style( 'kleo-style', CHILD_THEME_URI . '/style.css', array(), $version, 'all' );
  1280. wp_register_style( 'kleo-rtl', get_template_directory_uri() . '/rtl.css', array(), $version, 'all' );
  1281.  
  1282. //load fonts file if we not overriding font file in child theme
  1283. if ( 0 == sq_option( 'perf_combine_css', 0 ) || ( 1 == sq_option( 'perf_combine_css', 0 ) && true === $override_fonts ) ) {
  1284. wp_enqueue_style( 'kleo-fonts' );
  1285. }
  1286.  
  1287. //enqueue required styles
  1288. wp_enqueue_style( 'mediaelement' );
  1289.  
  1290. } // end kleo_frontend_files()
  1291. endif;
  1292.  
  1293.  
  1294. add_action( 'wp_enqueue_scripts', 'kleo_load_files_plugin_compat', 1000 );
  1295.  
  1296. function kleo_load_files_plugin_compat() {
  1297. $min = sq_option( 'dev_mode', 0 ) == 0 ? '.min' : '';
  1298.  
  1299. /* If remove query option is ON */
  1300. if ( 1 == sq_option( 'perf_remove_query', 0 ) ) {
  1301. $version = null;
  1302. } else {
  1303. $version = KLEO_THEME_VERSION;
  1304. }
  1305.  
  1306. /* Combine CSS option */
  1307. if ( sq_option( 'perf_combine_css', 0 ) == 0 ) {
  1308. wp_register_style( 'kleo-plugins', get_template_directory_uri() . '/assets/css/plugins' . $min . '.css', array(), $version, 'all' );
  1309. wp_enqueue_style( 'kleo-plugins' );
  1310. }
  1311.  
  1312. //wp_enqueue_style( 'mediaelement-skin' );
  1313.  
  1314. do_action( 'kleo_late_styles' );
  1315.  
  1316. //enqueue child theme style only if activated
  1317. if ( is_child_theme() ) {
  1318. if ( is_rtl() ) {
  1319. wp_enqueue_style( 'kleo-rtl' );
  1320. }
  1321. wp_enqueue_style( 'kleo-style' );
  1322. }
  1323.  
  1324.  
  1325. } // kleo_load_css_files_plugin_compat()
  1326.  
  1327. add_action( 'wp_enqueue_scripts', 'kleo_load_combined_files', 20 );
  1328.  
  1329. function kleo_load_combined_files() {
  1330. $min = sq_option( 'dev_mode', 0 ) == 0 ? '.min' : '';
  1331.  
  1332. /* If remove query option is ON */
  1333. if ( sq_option( 'perf_remove_query', 0 ) == 1 ) {
  1334. $version = null;
  1335. } else {
  1336. $version = KLEO_THEME_VERSION;
  1337. }
  1338.  
  1339. if ( sq_option( 'perf_combine_css', 0 ) == 1 ) {
  1340.  
  1341. $override_fonts = false;
  1342. if ( is_child_theme() && file_exists( get_stylesheet_directory() . '/assets/css/fontello.css' ) ) {
  1343. $override_fonts = true;
  1344. }
  1345.  
  1346. //Load
  1347. if ( true === $override_fonts ) {
  1348. $combined_file = 'combined';
  1349. } else {
  1350. $combined_file = 'combined-and-fonts';
  1351. }
  1352.  
  1353. wp_register_style( 'kleo-combined', get_template_directory_uri() . '/assets/css/' . $combined_file . $min . '.css', array(), $version, 'all' );
  1354. wp_enqueue_style( 'kleo-combined' );
  1355. }
  1356. }
  1357.  
  1358. /* Remove all query strings from all static resources */
  1359.  
  1360. if ( sq_option( 'perf_remove_query', 0 ) == 1 ) {
  1361.  
  1362. function pre_remove_query_strings_static_resources()
  1363. {
  1364. function remove_cssjs_ver($src)
  1365. {
  1366. if (strpos($src, '?ver='))
  1367. $src = remove_query_arg('ver', $src);
  1368. return $src;
  1369. }
  1370.  
  1371. add_filter('style_loader_src', 'remove_cssjs_ver', 10, 2);
  1372. add_filter('script_loader_src', 'remove_cssjs_ver', 10, 2);
  1373. }
  1374.  
  1375. add_action('init', 'pre_remove_query_strings_static_resources');
  1376. }
  1377.  
  1378. function kleo_add_inline_js_helper_classes() {
  1379. ?>
  1380. <script type="text/javascript">
  1381. /*
  1382. prevent dom flickering for elements hidden with js
  1383. */
  1384. "use strict";
  1385.  
  1386. document.documentElement.className += ' js-active ';
  1387. document.documentElement.className += 'ontouchstart' in document.documentElement ? ' kleo-mobile ' : ' kleo-desktop ';
  1388.  
  1389. var prefix = ['-webkit-', '-o-', '-moz-', '-ms-', ""];
  1390. for (var i in prefix) {
  1391. if (prefix[i] + 'transform' in document.documentElement.style) document.documentElement.className += " kleo-transform ";
  1392. }
  1393. </script>
  1394. <?php
  1395. }
  1396.  
  1397. add_action( 'wp_head', 'kleo_add_inline_js_helper_classes' );
  1398.  
  1399.  
  1400. if ( ! function_exists( 'remove_wp_open_sans' ) ) {
  1401. /**
  1402. * Remove duplicate Open Sans from WordPress
  1403. */
  1404. function kleo_remove_wp_open_sans() {
  1405. $font_link = get_transient( KLEO_DOMAIN . '_google_link' );
  1406. if ( strpos( $font_link, 'Open+Sans' ) !== false ) {
  1407. wp_deregister_style( 'open-sans' );
  1408. wp_register_style( 'open-sans', false );
  1409. }
  1410. }
  1411.  
  1412. add_action( 'wp_enqueue_scripts', 'kleo_remove_wp_open_sans' );
  1413. }
  1414.  
  1415.  
  1416. /***************************************************
  1417. * :: ADMIN CSS & JS
  1418. ***************************************************/
  1419. function kleo_admin_styles() {
  1420.  
  1421. wp_register_style( 'kleo-admin', KLEO_LIB_URI . '/assets/admin-custom.css', array(), KLEO_THEME_VERSION, 'all' );
  1422. wp_register_style( 'kleo-fonts', kleo_get_fonts_path(), array(), KLEO_THEME_VERSION, 'all' );
  1423.  
  1424. wp_enqueue_style( 'kleo-admin' );
  1425.  
  1426. wp_register_script( 'kleo-admin', KLEO_LIB_URI . '/assets/admin-custom.js', array(), KLEO_THEME_VERSION, true );
  1427. wp_enqueue_script( 'kleo-admin' );
  1428. }
  1429.  
  1430. add_action( 'admin_enqueue_scripts', 'kleo_admin_styles' );
  1431.  
  1432.  
  1433.  
  1434. function kleo_get_fonts_path() {
  1435. $fonts_path = get_template_directory_uri() . '/assets/css/fontello.css';
  1436. if ( is_child_theme() && file_exists( get_stylesheet_directory() . '/assets/css/fontello.css' ) ) {
  1437. $fonts_path = get_stylesheet_directory_uri() . '/assets/css/fontello.css';
  1438. }
  1439.  
  1440. return $fonts_path;
  1441. }
  1442.  
  1443. /***************************************************
  1444. * :: Customize wp-login.php
  1445. ***************************************************/
  1446. function custom_login_css() {
  1447.  
  1448. echo "\n<style>";
  1449.  
  1450. //echo $kleo_theme->get_bg_css('header_background', 'body.login');
  1451.  
  1452. echo '.login h1 a { background-image: url("' . sq_option_url( 'logo', 'none' ) . '");background-size: contain;min-height: 88px;width:auto;}';
  1453. echo '#login {padding: 20px 0 0;}';
  1454. echo '.login #nav a, .login #backtoblog a {color:' . sq_option( 'header_primary_color' ) . '!important;text-shadow:none;}';
  1455.  
  1456. echo "</style>\n";
  1457. }
  1458.  
  1459. add_action( 'login_head', 'custom_login_css', 12 );
  1460.  
  1461. function kleo_new_wp_login_url() {
  1462. return home_url();
  1463. }
  1464.  
  1465. add_filter( 'login_headerurl', 'kleo_new_wp_login_url' );
  1466.  
  1467. function kleo_new_wp_login_title() {
  1468. return get_option( 'blogname' );
  1469. }
  1470.  
  1471. add_filter( 'login_headertitle', 'kleo_new_wp_login_title' );
  1472.  
  1473.  
  1474. /***************************************************
  1475. * :: Load Fonts and Quick CSS
  1476. ***************************************************/
  1477. sq_kleo()->add_google_fonts_link();
  1478. add_action( 'wp_head', array( $kleo_theme, 'render_css' ), 15 );
  1479.  
  1480.  
  1481. /***************************************************
  1482. * :: Dynamic CSS Logic
  1483. ***************************************************/
  1484. require_once( KLEO_LIB_DIR . '/dynamic-css.php' );
  1485.  
  1486.  
  1487. /***************************************************
  1488. * :: Modal Ajax login && Modal Lost Password
  1489. ***************************************************/
  1490.  
  1491. add_action( 'wp_footer', 'kleo_load_popups', 12 );
  1492.  
  1493. function kleo_load_popups() {
  1494. if ( ! is_user_logged_in() ) {
  1495. get_template_part( 'page-parts/general-popups' );
  1496. }
  1497. }
  1498.  
  1499. add_action( 'init', 'kleo_ajax_login' );
  1500.  
  1501. if ( ! function_exists( 'kleo_ajax_login' ) ) {
  1502. function kleo_ajax_login() {
  1503.  
  1504. /* If not our action, bail out */
  1505. if ( ! isset( $_POST['action'] ) || ( isset( $_POST['action'] ) && 'kleoajaxlogin' != $_POST['action'] ) ) {
  1506. return false;
  1507. }
  1508.  
  1509. /* If user is already logged in print a specific message */
  1510. if ( is_user_logged_in() ) {
  1511. $link = 'javascript:window.location.reload();return false;';
  1512. echo wp_json_encode( array(
  1513. 'loggedin' => false,
  1514. 'message' => '<i class="icon icon-info-circled"></i> ' . sprintf( __( 'You are already logged in. Please <a href="#" onclick="%s">refresh</a> page', 'kleo_framework' ), $link ),
  1515. ) );
  1516. die();
  1517. }
  1518.  
  1519. // Check the nonce, if it fails the function will break
  1520. check_ajax_referer( 'kleo-ajax-login-nonce', 'security' );
  1521.  
  1522. // Nonce is checked, continue
  1523. $secure_cookie = '';
  1524.  
  1525. // If the user wants ssl but the session is not ssl, force a secure cookie.
  1526. if ( ! empty( $_POST['log'] ) && ! force_ssl_admin() ) {
  1527. $user_name = sanitize_user( $_POST['log'] );
  1528. if ( $user = get_user_by( 'login', $user_name ) ) {
  1529. if ( get_user_option( 'use_ssl', $user->ID ) ) {
  1530. $secure_cookie = true;
  1531. force_ssl_admin( true );
  1532. }
  1533. }
  1534. }
  1535.  
  1536. if ( isset( $_REQUEST['redirect_to'] ) ) {
  1537. $redirect_to = $_REQUEST['redirect_to'];
  1538. // Redirect to https if user wants ssl
  1539. if ( $secure_cookie && false !== strpos( $redirect_to, 'wp-admin' ) ) {
  1540. $redirect_to = preg_replace( '|^http://|', 'https://', $redirect_to );
  1541. }
  1542. } else {
  1543. $redirect_to = '';
  1544. }
  1545.  
  1546. $user_signon = wp_signon( '', $secure_cookie );
  1547. if ( is_wp_error( $user_signon ) ) {
  1548. $error_msg = $user_signon->get_error_message();
  1549. $error_msg = apply_filters( 'login_errors', $error_msg );
  1550. echo wp_json_encode( array(
  1551. 'loggedin' => false,
  1552. 'message' => '<span class="wrong-response"><i class="icon icon-attention"></i> ' . $error_msg . '</span>',
  1553. ) );
  1554. //echo json_encode(array( 'loggedin' => false, 'message' => '<span class="wrong-response"><i class="icon icon-attention"></i> ' . __( 'Wrong username or password. Please try again.', 'kleo_framework' ) . '</span>' ));
  1555. } else {
  1556. if ( sq_option( 'login_redirect', 'default' ) == 'reload' ) {
  1557. $redirecturl = null;
  1558. } else {
  1559. $requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
  1560. /**
  1561. * Filter the login redirect URL.
  1562. *
  1563. * @since 3.0.0
  1564. *
  1565. * @param string $redirect_to The redirect destination URL.
  1566. * @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
  1567. * @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise.
  1568. */
  1569. $redirecturl = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user_signon );
  1570.  
  1571. }
  1572.  
  1573. echo wp_json_encode( array(
  1574. 'loggedin' => true,
  1575. 'redirecturl' => $redirecturl,
  1576. 'message' => '<span class="good-response"><i class="icon icon-ok-circled"></i> ' . __( 'Login successful, redirecting...', 'kleo_framework' ) . '</span>',
  1577. ) );
  1578. }
  1579.  
  1580. die();
  1581. }
  1582. }
  1583.  
  1584.  
  1585. if ( ! function_exists( 'kleo_lost_password_ajax' ) ) {
  1586. function kleo_lost_password_ajax() {
  1587. // Check the nonce, if it fails the function will break
  1588. check_ajax_referer( 'kleo-ajax-login-nonce', 'security' );
  1589.  
  1590. $errors = new WP_Error();
  1591.  
  1592. if ( isset( $_POST ) ) {
  1593.  
  1594. if ( empty( $_POST['user_login'] ) ) {
  1595. $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Enter a username or e-mail address.' ) );
  1596. } elseif ( strpos( $_POST['user_login'], '@' ) ) {
  1597. $user_data = get_user_by( 'email', trim( $_POST['user_login'] ) );
  1598. if ( empty( $user_data ) ) {
  1599. $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: There is no user registered with that email address.' ) );
  1600. }
  1601. } else {
  1602. $login = trim( $_POST['user_login'] );
  1603. $user_data = get_user_by( 'login', $login );
  1604. }
  1605.  
  1606. /**
  1607. * Fires before errors are returned from a password reset request.
  1608. *
  1609. * @since 2.1.0
  1610. * @since 4.4.0 Added the `$errors` parameter.
  1611. *
  1612. * @param WP_Error $errors A WP_Error object containing any errors generated
  1613. * by using invalid credentials.
  1614. */
  1615. do_action( 'lostpassword_post', $errors );
  1616.  
  1617. if ( $errors->get_error_code() ) {
  1618. echo '<span class="wrong-response">' . $errors->get_error_message() . '</span>';
  1619. die();
  1620. }
  1621.  
  1622. if ( ! $user_data ) {
  1623. $errors->add(
  1624. 'invalidcombo', wp_kses_data( __( '<strong>ERROR</strong>: Invalid username or e-mail.', 'default' ) )
  1625. );
  1626. echo '<span class="wrong-response">' . $errors->get_error_message() . '</span>';
  1627. die();
  1628. }
  1629.  
  1630. // Redefining user_login ensures we return the right case in the email.
  1631. $user_login = $user_data->user_login;
  1632. $user_email = $user_data->user_email;
  1633. $key = get_password_reset_key( $user_data );
  1634.  
  1635. if ( is_wp_error( $key ) ) {
  1636. echo '<span class="wrong-response">' . $key->get_error_message() . '</span>';
  1637. die();
  1638. }
  1639.  
  1640. $message = __( 'Someone requested that the password be reset for the following account:', 'kleo_framework' ) . "\r\n\r\n";
  1641. $message .= network_home_url( '/' ) . "\r\n\r\n";
  1642. $message .= sprintf( __( 'Username: %s' ), $user_login ) . "\r\n\r\n";
  1643. $message .= __( 'If this was a mistake, just ignore this email and nothing will happen.', 'kleo_framework' ) . "\r\n\r\n";
  1644. $message .= __( 'To reset your password, visit the following address:', 'kleo_framework' ) . "\r\n\r\n";
  1645. $message .= '<' . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . ">\r\n";
  1646.  
  1647. if ( is_multisite() ) {
  1648. $blogname = get_network()->site_name;
  1649. } else /*
  1650. * The blogname option is escaped with esc_html on the way into the database
  1651. * in sanitize_option we want to reverse this for the plain text arena of emails.
  1652. */ {
  1653. $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
  1654. }
  1655.  
  1656. $title = sprintf( esc_html__( '[%s] Password Reset' ), $blogname );
  1657.  
  1658. /**
  1659. * Filters the subject of the password reset email.
  1660. *
  1661. * @since 2.8.0
  1662. * @since 4.4.0 Added the `$user_login` and `$user_data` parameters.
  1663. *
  1664. * @param string $title Default email title.
  1665. * @param string $user_login The username for the user.
  1666. * @param WP_User $user_data WP_User object.
  1667. */
  1668. $title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );
  1669.  
  1670. /**
  1671. * Filters the message body of the password reset mail.
  1672. *
  1673. * @since 2.8.0
  1674. * @since 4.1.0 Added `$user_login` and `$user_data` parameters.
  1675. *
  1676. * @param string $message Default mail message.
  1677. * @param string $key The activation key.
  1678. * @param string $user_login The username for the user.
  1679. * @param WP_User $user_data WP_User object.
  1680. */
  1681. $message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
  1682.  
  1683.  
  1684. if ( $message && ! wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) ) {
  1685. echo '<span class="wrong-response">' . __( 'Failure!', 'kleo_framework' );
  1686. echo __( 'The e-mail could not be sent.' );
  1687. echo '</span>';
  1688. die();
  1689. } else {
  1690. echo '<span class="good-response">' . __( 'Email successfully sent!', 'kleo_framework' ) . '</span>';
  1691. die();
  1692. }
  1693. }
  1694. die();
  1695. }
  1696. }
  1697. add_action( "wp_ajax_kleo_lost_password", "kleo_lost_password_ajax" );
  1698. add_action( 'wp_ajax_nopriv_kleo_lost_password', 'kleo_lost_password_ajax' );
  1699. // -----------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement