PageRenderTime 58ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/Divi/epanel/custom_functions.php

https://gitlab.com/gregtyka/lfmawordpress
PHP | 1441 lines | 947 code | 366 blank | 128 comment | 418 complexity | b14795c15edc583c9295e7e6d6df68c8 MD5 | raw file
  1. <?php
  2. // Prevent file from being loaded directly
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. die( '-1' );
  5. }
  6. add_theme_support( 'custom-background', apply_filters( 'et_custom_background_args', array() ) );
  7. if ( function_exists( 'add_post_type_support' ) ) {
  8. add_post_type_support( 'page', 'excerpt' );
  9. }
  10. add_theme_support( 'automatic-feed-links' );
  11. add_action( 'init', 'et_activate_features' );
  12. function et_activate_features(){
  13. define( 'ET_SHORTCODES_VERSION', et_get_theme_version() );
  14. /* activate shortcodes */
  15. require_once TEMPLATEPATH . '/epanel/shortcodes/shortcodes.php';
  16. /* activate page templates */
  17. require_once TEMPLATEPATH . '/epanel/page_templates/page_templates.php';
  18. /* import epanel settings */
  19. require_once TEMPLATEPATH . '/epanel/import_settings.php';
  20. }
  21. add_filter( 'widget_text', 'do_shortcode' );
  22. add_filter( 'the_excerpt', 'do_shortcode' );
  23. if ( ! function_exists( 'et_options_stored_in_one_row' ) ) {
  24. function et_options_stored_in_one_row(){
  25. global $et_store_options_in_one_row;
  26. return isset( $et_store_options_in_one_row ) ? (bool) $et_store_options_in_one_row : false;
  27. }
  28. }
  29. /**
  30. * Gets option value from the single theme option, stored as an array in the database
  31. * if all options stored in one row.
  32. * Stores the serialized array with theme options into the global variable on the first function run on the page.
  33. *
  34. * If options are stored as separate rows in database, it simply uses get_option() function.
  35. *
  36. * @param string $option_name Theme option name.
  37. * @param string $default_value Default value that should be set if the theme option isn't set.
  38. * @param string $used_for_object "Object" name that should be translated into corresponding "object" if WPML is activated.
  39. * @return mixed Theme option value or false if not found.
  40. */
  41. if ( ! function_exists( 'et_get_option' ) ) {
  42. function et_get_option( $option_name, $default_value = '', $used_for_object = '', $force_default_value = false ){
  43. global $et_theme_options, $shortname;
  44. if ( et_options_stored_in_one_row() ) {
  45. $et_theme_options_name = 'et_' . $shortname;
  46. if ( ! isset( $et_theme_options ) || isset( $_POST['wp_customize'] ) ) {
  47. $et_theme_options = get_option( $et_theme_options_name );
  48. }
  49. $option_value = isset( $et_theme_options[$option_name] ) ? $et_theme_options[$option_name] : false;
  50. } else {
  51. $option_value = get_option( $option_name );
  52. }
  53. // option value might be equal to false, so check if the option is not set in the database
  54. if ( ! isset( $et_theme_options[ $option_name ] ) && ( '' != $default_value || $force_default_value ) ) {
  55. $option_value = $default_value;
  56. }
  57. if ( '' != $used_for_object && in_array( $used_for_object, array( 'page', 'category' ) ) && is_array( $option_value ) )
  58. $option_value = et_generate_wpml_ids( $option_value, $used_for_object );
  59. return $option_value;
  60. }
  61. }
  62. if ( ! function_exists( 'et_update_option' ) ) {
  63. function et_update_option( $option_name, $new_value ){
  64. global $et_theme_options, $shortname;
  65. if ( et_options_stored_in_one_row() ) {
  66. $et_theme_options_name = 'et_' . $shortname;
  67. if ( ! isset( $et_theme_options ) ) $et_theme_options = get_option( $et_theme_options_name );
  68. $et_theme_options[$option_name] = $new_value;
  69. $option_name = $et_theme_options_name;
  70. $new_value = $et_theme_options;
  71. }
  72. update_option( $option_name, $new_value );
  73. }
  74. }
  75. if ( ! function_exists( 'et_delete_option' ) ) {
  76. function et_delete_option( $option_name ){
  77. global $et_theme_options, $shortname;
  78. if ( et_options_stored_in_one_row() ) {
  79. $et_theme_options_name = 'et_' . $shortname;
  80. if ( ! isset( $et_theme_options ) ) $et_theme_options = get_option( $et_theme_options_name );
  81. unset( $et_theme_options[$option_name] );
  82. update_option( $et_theme_options_name, $et_theme_options );
  83. } else {
  84. delete_option( $option_name );
  85. }
  86. }
  87. }
  88. add_filter( 'body_class', 'et_browser_body_class' );
  89. function et_browser_body_class($classes) {
  90. global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
  91. if($is_lynx) $classes[] = 'lynx';
  92. elseif($is_gecko) $classes[] = 'gecko';
  93. elseif($is_opera) $classes[] = 'opera';
  94. elseif($is_NS4) $classes[] = 'ns4';
  95. elseif($is_safari) $classes[] = 'safari';
  96. elseif($is_chrome) $classes[] = 'chrome';
  97. elseif($is_IE) $classes[] = 'ie';
  98. else $classes[] = 'unknown';
  99. if($is_iphone) $classes[] = 'iphone';
  100. return $classes;
  101. }
  102. /*this function allows for the auto-creation of post excerpts*/
  103. if ( ! function_exists( 'truncate_post' ) ) {
  104. function truncate_post( $amount, $echo = true, $post = '' ) {
  105. global $shortname;
  106. if ( '' == $post ) global $post;
  107. $post_excerpt = '';
  108. $post_excerpt = apply_filters( 'the_excerpt', $post->post_excerpt );
  109. if ( 'on' == et_get_option( $shortname . '_use_excerpt' ) && '' != $post_excerpt ) {
  110. if ( $echo ) echo $post_excerpt;
  111. else return $post_excerpt;
  112. } else {
  113. // get the post content
  114. $truncate = $post->post_content;
  115. // remove caption shortcode from the post content
  116. $truncate = preg_replace( '@\[caption[^\]]*?\].*?\[\/caption]@si', '', $truncate );
  117. // apply content filters
  118. $truncate = apply_filters( 'the_content', $truncate );
  119. // decide if we need to append dots at the end of the string
  120. if ( strlen( $truncate ) <= $amount ) {
  121. $echo_out = '';
  122. } else {
  123. $echo_out = '...';
  124. // $amount = $amount - 3;
  125. }
  126. // trim text to a certain number of characters, also remove spaces from the end of a string ( space counts as a character )
  127. $truncate = rtrim( et_wp_trim_words( $truncate, $amount, '' ) );
  128. // remove the last word to make sure we display all words correctly
  129. if ( '' != $echo_out ) {
  130. $new_words_array = (array) explode( ' ', $truncate );
  131. array_pop( $new_words_array );
  132. $truncate = implode( ' ', $new_words_array );
  133. // append dots to the end of the string
  134. $truncate .= $echo_out;
  135. }
  136. if ( $echo ) echo $truncate;
  137. else return $truncate;
  138. };
  139. }
  140. }
  141. if ( ! function_exists( 'et_wp_trim_words' ) ) {
  142. function et_wp_trim_words( $text, $num_words = 55, $more = null ) {
  143. if ( null === $more )
  144. $more = esc_html__( '&hellip;' );
  145. $original_text = $text;
  146. $text = wp_strip_all_tags( $text );
  147. $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
  148. preg_match_all( '/./u', $text, $words_array );
  149. $words_array = array_slice( $words_array[0], 0, $num_words + 1 );
  150. $sep = '';
  151. if ( count( $words_array ) > $num_words ) {
  152. array_pop( $words_array );
  153. $text = implode( $sep, $words_array );
  154. $text = $text . $more;
  155. } else {
  156. $text = implode( $sep, $words_array );
  157. }
  158. return $text;
  159. }
  160. }
  161. /*this function truncates titles to create preview excerpts*/
  162. if ( ! function_exists( 'truncate_title' ) ) {
  163. function truncate_title( $amount, $echo = true, $post = '' ) {
  164. if ( $post == '' ) $truncate = get_the_title();
  165. else $truncate = $post->post_title;
  166. if ( strlen( $truncate ) <= $amount ) $echo_out = '';
  167. else $echo_out = '...';
  168. $truncate = et_wp_trim_words( $truncate, $amount, '' );
  169. if ( '' != $echo_out ) $truncate .= $echo_out;
  170. if ( $echo )
  171. echo $truncate;
  172. else
  173. return $truncate;
  174. }
  175. }
  176. /*this function allows users to use the first image in their post as their thumbnail*/
  177. if ( ! function_exists( 'et_first_image' ) ) {
  178. function et_first_image() {
  179. global $post;
  180. $img = '';
  181. $output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches );
  182. if ( isset( $matches[1][0] ) ) $img = $matches[1][0];
  183. return trim( $img );
  184. }
  185. }
  186. /* this function gets thumbnail from Post Thumbnail or Custom field or First post image */
  187. if ( ! function_exists( 'get_thumbnail' ) ) {
  188. function get_thumbnail($width=100, $height=100, $class='', $alttext='', $titletext='', $fullpath=false, $custom_field='', $post='') {
  189. if ( $post == '' ) global $post;
  190. global $shortname;
  191. $thumb_array['thumb'] = '';
  192. $thumb_array['use_timthumb'] = true;
  193. if ($fullpath) $thumb_array['fullpath'] = ''; //full image url for lightbox
  194. $new_method = true;
  195. if ( has_post_thumbnail( $post->ID ) ) {
  196. $thumb_array['use_timthumb'] = false;
  197. $et_fullpath = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
  198. $thumb_array['fullpath'] = $et_fullpath[0];
  199. $thumb_array['thumb'] = $thumb_array['fullpath'];
  200. }
  201. if ($thumb_array['thumb'] == '') {
  202. if ($custom_field == '') $thumb_array['thumb'] = esc_attr( get_post_meta( $post->ID, 'Thumbnail', $single = true ) );
  203. else {
  204. $thumb_array['thumb'] = esc_attr( get_post_meta( $post->ID, $custom_field, $single = true ) );
  205. if ($thumb_array['thumb'] == '') $thumb_array['thumb'] = esc_attr( get_post_meta( $post->ID, 'Thumbnail', $single = true ) );
  206. }
  207. if (($thumb_array['thumb'] == '') && ((et_get_option( $shortname.'_grab_image' )) == 'on')) {
  208. $thumb_array['thumb'] = esc_attr( et_first_image() );
  209. if ( $fullpath ) $thumb_array['fullpath'] = $thumb_array['thumb'];
  210. }
  211. #if custom field used for small pre-cropped image, open Thumbnail custom field image in lightbox
  212. if ($fullpath) {
  213. $thumb_array['fullpath'] = $thumb_array['thumb'];
  214. if ($custom_field == '') $thumb_array['fullpath'] = apply_filters( 'et_fullpath', et_path_reltoabs( esc_attr( $thumb_array['thumb'] ) ) );
  215. elseif ( $custom_field <> '' && get_post_meta( $post->ID, 'Thumbnail', $single = true ) ) $thumb_array['fullpath'] = apply_filters( 'et_fullpath', et_path_reltoabs( esc_attr( get_post_meta( $post->ID, 'Thumbnail', $single = true ) ) ) );
  216. }
  217. }
  218. return $thumb_array;
  219. }
  220. }
  221. /* this function prints thumbnail from Post Thumbnail or Custom field or First post image */
  222. if ( ! function_exists( 'print_thumbnail' ) ) {
  223. function print_thumbnail($thumbnail = '', $use_timthumb = true, $alttext = '', $width = 100, $height = 100, $class = '', $echoout = true, $forstyle = false, $resize = true, $post='', $et_post_id = '' ) {
  224. if ( is_array( $thumbnail ) ) {
  225. extract( $thumbnail );
  226. }
  227. if ( $post == '' ) global $post, $et_theme_image_sizes;
  228. $output = '';
  229. $et_post_id = '' != $et_post_id ? (int) $et_post_id : $post->ID;
  230. if ( has_post_thumbnail( $et_post_id ) ) {
  231. $thumb_array['use_timthumb'] = false;
  232. $image_size_name = $width . 'x' . $height;
  233. $et_size = isset( $et_theme_image_sizes ) && array_key_exists( $image_size_name, $et_theme_image_sizes ) ? $et_theme_image_sizes[$image_size_name] : array( $width, $height );
  234. $et_attachment_image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id( $et_post_id ), $et_size );
  235. $thumbnail = $et_attachment_image_attributes[0];
  236. } else {
  237. $thumbnail_orig = $thumbnail;
  238. $thumbnail = et_multisite_thumbnail( $thumbnail );
  239. $cropPosition = '';
  240. $allow_new_thumb_method = false;
  241. $new_method = true;
  242. $new_method_thumb = '';
  243. $external_source = false;
  244. $allow_new_thumb_method = !$external_source && $new_method && $cropPosition == '';
  245. if ( $allow_new_thumb_method && $thumbnail <> '' ) {
  246. $et_crop = get_post_meta( $post->ID, 'et_nocrop', true ) == '' ? true : false;
  247. $new_method_thumb = et_resize_image( et_path_reltoabs( $thumbnail ), $width, $height, $et_crop );
  248. if ( is_wp_error( $new_method_thumb ) ) $new_method_thumb = '';
  249. }
  250. $thumbnail = $new_method_thumb;
  251. }
  252. if ( false === $forstyle ) {
  253. $output = '<img src="' . esc_url( $thumbnail ) . '"';
  254. if ($class <> '') $output .= " class='" . esc_attr( $class ) . "' ";
  255. $dimensions = apply_filters( 'et_print_thumbnail_dimensions', " width='" . esc_attr( $width ) . "' height='" .esc_attr( $height ) . "'" );
  256. $output .= " alt='" . esc_attr( strip_tags( $alttext ) ) . "'{$dimensions} />";
  257. if ( ! $resize ) $output = $thumbnail;
  258. } else {
  259. $output = $thumbnail;
  260. }
  261. if ($echoout) echo $output;
  262. else return $output;
  263. }
  264. }
  265. if ( ! function_exists( 'et_new_thumb_resize' ) ) {
  266. function et_new_thumb_resize( $thumbnail, $width, $height, $alt='', $forstyle = false ){
  267. global $shortname;
  268. $new_method = true;
  269. $new_method_thumb = '';
  270. $external_source = false;
  271. $allow_new_thumb_method = !$external_source && $new_method;
  272. if ( $allow_new_thumb_method && $thumbnail <> '' ) {
  273. $et_crop = true;
  274. $new_method_thumb = et_resize_image( $thumbnail, $width, $height, $et_crop );
  275. if ( is_wp_error( $new_method_thumb ) ) $new_method_thumb = '';
  276. }
  277. $thumb = esc_attr( $new_method_thumb );
  278. $output = '<img src="' . esc_url( $thumb ) . '" alt="' . esc_attr( $alt ) . '" width =' . esc_attr( $width ) . ' height=' . esc_attr( $height ) . ' />';
  279. return ( !$forstyle ) ? $output : $thumb;
  280. }
  281. }
  282. if ( ! function_exists( 'et_multisite_thumbnail' ) ) {
  283. function et_multisite_thumbnail( $thumbnail = '' ) {
  284. // do nothing if it's not a Multisite installation or current site is the main one
  285. if ( is_main_site() ) return $thumbnail;
  286. # get the real image url
  287. preg_match( '#([_0-9a-zA-Z-]+/)?files/(.+)#', $thumbnail, $matches );
  288. if ( isset( $matches[2] ) ) {
  289. $file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $matches[2] );
  290. if ( is_file( $file ) ) $thumbnail = str_replace( ABSPATH, trailingslashit( get_site_url( 1 ) ), $file );
  291. else $thumbnail = '';
  292. }
  293. return $thumbnail;
  294. }
  295. }
  296. if ( ! function_exists( 'et_is_portrait' ) ) {
  297. function et_is_portrait($imageurl, $post='', $ignore_cfields = false){
  298. if ( $post == '' ) global $post;
  299. if ( get_post_meta( $post->ID, 'et_disable_portrait', true ) == 1 ) return false;
  300. if ( !$ignore_cfields ) {
  301. if ( get_post_meta( $post->ID, 'et_imagetype', true ) == 'l' ) return false;
  302. if ( get_post_meta( $post->ID, 'et_imagetype', true ) == 'p' ) return true;
  303. }
  304. $imageurl = et_path_reltoabs( et_multisite_thumbnail( $imageurl ) );
  305. $et_thumb_size = @getimagesize( $imageurl );
  306. if ( empty( $et_thumb_size ) ) {
  307. $et_thumb_size = @getimagesize( str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $imageurl ) );
  308. if ( empty( $et_thumb_size ) ) return false;
  309. }
  310. $et_thumb_width = $et_thumb_size[0];
  311. $et_thumb_height = $et_thumb_size[1];
  312. $result = ($et_thumb_width < $et_thumb_height) ? true : false;
  313. return $result;
  314. }
  315. }
  316. if ( ! function_exists( 'et_path_reltoabs' ) ) {
  317. function et_path_reltoabs( $imageurl ){
  318. if ( strpos( strtolower( $imageurl ), 'http://' ) !== false || strpos( strtolower( $imageurl ), 'https://' ) !== false ) return $imageurl;
  319. if ( strpos( strtolower( $imageurl ), $_SERVER['HTTP_HOST'] ) !== false )
  320. return $imageurl;
  321. else {
  322. $imageurl = esc_url( apply_filters( 'et_path_relative_image', site_url() . '/' ) . $imageurl );
  323. }
  324. return $imageurl;
  325. }
  326. }
  327. if ( ! function_exists( 'in_subcat' ) ) {
  328. function in_subcat($blogcat,$current_cat='') {
  329. $in_subcategory = false;
  330. if (cat_is_ancestor_of( $blogcat, $current_cat ) || $blogcat == $current_cat) $in_subcategory = true;
  331. return $in_subcategory;
  332. }
  333. }
  334. if ( ! function_exists( 'show_page_menu' ) ) {
  335. function show_page_menu($customClass = 'nav clearfix', $addUlContainer = true, $addHomeLink = true){
  336. global $shortname, $themename, $exclude_pages, $strdepth, $page_menu, $is_footer;
  337. //excluded pages
  338. if ( et_get_option( $shortname.'_menupages' ) <> '' ) {
  339. $exclude_pages = implode( ",", et_get_option( $shortname.'_menupages' ) );
  340. }
  341. //dropdown for pages
  342. $strdepth = '';
  343. if ( et_get_option( $shortname.'_enable_dropdowns' ) == 'on' ) {
  344. $strdepth = "depth=".et_get_option( $shortname.'_tiers_shown_pages' );
  345. }
  346. if ( $strdepth == '' ) {
  347. $strdepth = "depth=1";
  348. }
  349. if ( $is_footer ) {
  350. $strdepth = "depth=1";
  351. $strdepth2 = $strdepth;
  352. }
  353. $page_menu = wp_list_pages( "sort_column=".et_get_option( $shortname.'_sort_pages' )."&sort_order=".et_get_option( $shortname.'_order_page' )."&".$strdepth."&exclude=".$exclude_pages."&title_li=&echo=0" );
  354. if ( $addUlContainer ) echo '<ul class="'.$customClass.'">';
  355. if (et_get_option( $shortname . '_home_link' ) == 'on' && $addHomeLink) { ?>
  356. <li <?php if ( is_front_page() || is_home() ) echo 'class="current_page_item"' ?>><a href="<?php echo esc_url( home_url() ); ?>"><?php esc_html_e( 'Home', $themename ); ?></a></li>
  357. <?php };
  358. echo $page_menu;
  359. if ( $addUlContainer ) echo '</ul>';
  360. }
  361. }
  362. if ( ! function_exists( 'show_categories_menu' ) ) {
  363. function show_categories_menu($customClass = 'nav clearfix', $addUlContainer = true){
  364. global $shortname, $themename, $category_menu, $exclude_cats, $hide, $strdepth2, $projects_cat;
  365. //excluded categories
  366. if (et_get_option( $shortname.'_menucats' ) <> '') $exclude_cats = implode( ",", et_get_option( $shortname.'_menucats' ) );
  367. //hide empty categories
  368. if (et_get_option( $shortname.'_categories_empty' ) == 'on') $hide = '1';
  369. else $hide = '0';
  370. //dropdown for categories
  371. $strdepth2 = '';
  372. if ( et_get_option( $shortname.'_enable_dropdowns_categories' ) == 'on' ) $strdepth2 = "depth=".et_get_option( $shortname.'_tiers_shown_categories' );
  373. if ( $strdepth2 == '' ) $strdepth2 = "depth=1";
  374. $args = "orderby=".et_get_option( $shortname.'_sort_cat' )."&order=".et_get_option( $shortname.'_order_cat' )."&".$strdepth2."&exclude=".$exclude_cats."&hide_empty=".$hide."&title_li=&echo=0";
  375. $categories = get_categories( $args );
  376. if ( !empty( $categories ) ) {
  377. $args_array = wp_parse_args( $args );
  378. if ( isset( $args_array['exclude'] ) && '' !== $args_array['exclude'] ) {
  379. $args_array['exclude'] = explode( ',', $args_array['exclude'] );
  380. }
  381. $category_menu = wp_list_categories( $args_array );
  382. if ( $addUlContainer ) echo '<ul class="'.$customClass.'">';
  383. echo $category_menu;
  384. if ( $addUlContainer ) echo '</ul>';
  385. }
  386. }
  387. }
  388. function head_addons(){
  389. global $shortname, $default_colorscheme;
  390. if ( apply_filters( 'et_get_additional_color_scheme', et_get_option( $shortname.'_color_scheme' ) ) <> $default_colorscheme ) { ?>
  391. <link rel="stylesheet" href="<?php echo esc_url( get_template_directory_uri() . '/style-' . et_get_option( $shortname.'_color_scheme' ) . '.css' ); ?>" type="text/css" media="screen" />
  392. <?php };
  393. if ( et_get_option( $shortname.'_child_css' ) == 'on' && et_get_option( $shortname.'_child_cssurl' ) <> '' ) { //Enable child stylesheet ?>
  394. <link rel="stylesheet" href="<?php echo esc_url( et_get_option( $shortname.'_child_cssurl' ) ); ?>" type="text/css" media="screen" />
  395. <?php };
  396. //prints the theme name, version in meta tag
  397. $theme_info = wp_get_theme();
  398. echo '<meta content="' . esc_attr( $theme_info->display( 'Name' ) . ' v.' . $theme_info->display( 'Version' ) ) . '" name="generator"/>';
  399. if ( et_get_option( $shortname . '_custom_colors' ) == 'on' ) et_epanel_custom_colors_css();
  400. }// end function head_addons()
  401. add_action( 'wp_head', 'head_addons', 7 );
  402. function integration_head(){
  403. global $shortname;
  404. if ( et_get_option( $shortname . '_integration_head' ) <> '' && et_get_option( $shortname . '_integrate_header_enable' ) == 'on' ) {
  405. echo et_get_option( $shortname . '_integration_head' );
  406. }
  407. }
  408. add_action( 'wp_head', 'integration_head', 12 );
  409. function integration_body(){
  410. global $shortname;
  411. if ( et_get_option( $shortname . '_integration_body' ) <> '' && et_get_option( $shortname . '_integrate_body_enable' ) == 'on' ) {
  412. echo et_get_option( $shortname . '_integration_body' );
  413. }
  414. }
  415. add_action( 'wp_footer', 'integration_body', 12 );
  416. function integration_single_top(){
  417. global $shortname;
  418. if ( et_get_option( $shortname . '_integration_single_top' ) <> '' && et_get_option( $shortname . '_integrate_body_enable' ) == 'on' ) {
  419. echo et_get_option( $shortname . '_integration_single_top' );
  420. }
  421. }
  422. add_action( 'et_before_post', 'integration_single_top', 12 );
  423. function integration_single_bottom(){
  424. global $shortname;
  425. if ( et_get_option( $shortname . '_integration_single_bottom' ) <> '' && et_get_option( $shortname . '_integrate_body_enable' ) == 'on' ) {
  426. echo et_get_option( $shortname . '_integration_single_bottom' );
  427. }
  428. }
  429. add_action( 'et_after_post', 'integration_single_bottom', 12 );
  430. /*this function gets page name by its id*/
  431. if ( ! function_exists( 'get_pagename' ) ) {
  432. function get_pagename( $page_id )
  433. {
  434. $page_object = get_page( $page_id );
  435. return apply_filters( 'the_title', $page_object->post_title, $page_id );
  436. }
  437. }
  438. /*this function gets category name by its id*/
  439. if ( ! function_exists( 'get_categname' ) ) {
  440. function get_categname( $cat_id )
  441. {
  442. return get_cat_name( $cat_id );
  443. }
  444. }
  445. /*this function gets category id by its name*/
  446. if ( ! function_exists( 'get_catId' ) ) {
  447. function get_catId( $cat_name, $taxonomy = 'category' )
  448. {
  449. $cat_name_id = is_numeric( $cat_name ) ? (int) $cat_name : (int) get_cat_ID( html_entity_decode( $cat_name, ENT_QUOTES ) );
  450. // wpml compatibility
  451. if ( function_exists( 'icl_object_id' ) ) {
  452. $cat_name_id = (int) icl_object_id( $cat_name_id, $taxonomy, true );
  453. }
  454. return $cat_name_id;
  455. }
  456. }
  457. /*this function gets page id by its name*/
  458. if ( ! function_exists( 'get_pageId' ) ) {
  459. function get_pageId( $page_name )
  460. {
  461. if ( is_numeric( $page_name ) ) {
  462. $page_id = intval( $page_name );
  463. } else {
  464. $page_name = html_entity_decode( $page_name, ENT_QUOTES );
  465. $page = get_page_by_title( $page_name );
  466. $page_id = intval( $page->ID );
  467. }
  468. // wpml compatibility
  469. if ( function_exists( 'icl_object_id' ) )
  470. $page_id = (int) icl_object_id( $page_id, 'page', true );
  471. return $page_id;
  472. }
  473. }
  474. /**
  475. * Transforms an array of posts, pages, post_tags or categories ids
  476. * into corresponding "objects" ids, if WPML plugin is installed
  477. *
  478. * @param array $ids_array Posts, pages, post_tags or categories ids.
  479. * @param string $type "Object" type.
  480. * @return array IDs.
  481. */
  482. if ( ! function_exists( 'et_generate_wpml_ids' ) ) {
  483. function et_generate_wpml_ids( $ids_array, $type ) {
  484. if ( function_exists( 'icl_object_id' ) ) {
  485. $wpml_ids = array();
  486. foreach ( $ids_array as $id ) {
  487. $translated_id = icl_object_id( $id, $type, false );
  488. if ( ! is_null( $translated_id ) ) $wpml_ids[] = $translated_id;
  489. }
  490. $ids_array = $wpml_ids;
  491. }
  492. return array_map( 'intval', $ids_array );
  493. }
  494. }
  495. if ( ! function_exists( 'elegant_is_blog_posts_page' ) ) {
  496. function elegant_is_blog_posts_page() {
  497. /**
  498. * Returns true if static page is set in WP-Admin / Settings / Reading
  499. * and Posts page is displayed
  500. */
  501. static $et_is_blog_posts_cached = null;
  502. if ( null === $et_is_blog_posts_cached ) {
  503. $et_is_blog_posts_cached = (bool) is_home() && 0 !== intval( get_option( 'page_for_posts', '0' ) );
  504. }
  505. return $et_is_blog_posts_cached;
  506. }
  507. }
  508. // Added for backwards compatibility
  509. if ( ! function_exists( 'elegant_titles' ) ) {
  510. function elegant_titles() {
  511. if ( ! function_exists( 'wp_get_document_title' ) ) {
  512. wp_title();
  513. } else {
  514. echo wp_get_document_title();
  515. }
  516. }
  517. }
  518. if ( ! function_exists( '_wp_render_title_tag' ) && ! function_exists( 'et_add_title_tag_back_compat' ) ) {
  519. /**
  520. * Manually add <title> tag in head for WordPress 4.1 below for backward compatibility
  521. * Title tag is automatically added for WordPress 4.1 above via theme support
  522. * @return void
  523. */
  524. function et_add_title_tag_back_compat() {
  525. ?>
  526. <title><?php wp_title( '-', true, 'right' ); ?></title>
  527. <?php
  528. }
  529. add_action( 'wp_head', 'et_add_title_tag_back_compat' );
  530. }
  531. /*this function controls the meta titles display*/
  532. if ( ! function_exists( 'elegant_titles_filter' ) ) {
  533. function elegant_titles_filter( $custom_title ) {
  534. global $shortname, $themename;
  535. $custom_title = '';
  536. $sitename = get_bloginfo( 'name' );
  537. $site_description = get_bloginfo( 'description' );
  538. #if the title is being displayed on the homepage
  539. if ( ( is_home() || is_front_page() ) && ! elegant_is_blog_posts_page() ) {
  540. if ( 'on' === et_get_option( $shortname . '_seo_home_title' ) ) {
  541. $custom_title = et_get_option( $shortname . '_seo_home_titletext' );
  542. } else {
  543. $seo_home_type = et_get_option( $shortname . '_seo_home_type' );
  544. $seo_home_separate = et_get_option( $shortname . '_seo_home_separate' );
  545. if ( $seo_home_type == 'BlogName | Blog description' ) {
  546. $custom_title = $sitename . esc_html( $seo_home_separate ) . $site_description;
  547. }
  548. if ( $seo_home_type == 'Blog description | BlogName') {
  549. $custom_title = $site_description . esc_html( $seo_home_separate ) . $sitename;
  550. }
  551. if ( $seo_home_type == 'BlogName only') {
  552. $custom_title = $sitename;
  553. }
  554. }
  555. }
  556. #if the title is being displayed on single posts/pages
  557. if ( ( ( is_single() || is_page() ) && ! is_front_page() ) || elegant_is_blog_posts_page() ) {
  558. global $wp_query;
  559. $postid = elegant_is_blog_posts_page() ? intval( get_option( 'page_for_posts' ) ) : $wp_query->post->ID;
  560. $key = et_get_option( $shortname . '_seo_single_field_title' );
  561. $exists3 = get_post_meta( $postid, '' . $key . '', true );
  562. if ( 'on' === et_get_option( $shortname . '_seo_single_title' ) && '' !== $exists3 ) {
  563. $custom_title = $exists3;
  564. } else {
  565. $seo_single_type = et_get_option( $shortname . '_seo_single_type' );
  566. $seo_single_separate = et_get_option( $shortname . '_seo_single_separate' );
  567. $page_title = single_post_title( '', false );
  568. if ( $seo_single_type == 'BlogName | Post title' ) {
  569. $custom_title = $sitename . esc_html( $seo_single_separate ) . $page_title;
  570. }
  571. if ( $seo_single_type == 'Post title | BlogName' ) {
  572. $custom_title = $page_title . esc_html( $seo_single_separate ) . $sitename;
  573. }
  574. if ( $seo_single_type == 'Post title only' ) {
  575. $custom_title = $page_title;
  576. }
  577. }
  578. }
  579. #if the title is being displayed on index pages (categories/archives/search results)
  580. if ( is_category() || is_archive() || is_search() || is_404() ) {
  581. $page_title = '';
  582. $seo_index_type = et_get_option( $shortname . '_seo_index_type' );
  583. $seo_index_separate = et_get_option( $shortname . '_seo_index_separate' );
  584. if ( is_category() || is_tag() || is_tax() ) {
  585. $page_title = single_term_title( '', false );
  586. } else if ( is_post_type_archive() ) {
  587. $page_title = post_type_archive_title( '', false );
  588. } else if ( is_author() ) {
  589. $page_title = get_the_author_meta( 'display_name', get_query_var( 'author' ) );
  590. } else if ( is_date() ) {
  591. $page_title = esc_html__( 'Archives', $themename );
  592. } else if ( is_search() ) {
  593. $page_title = sprintf( esc_html__( 'Search results for "%s"', $themename ), esc_attr( get_search_query() ) );
  594. } else if ( is_404() ) {
  595. $page_title = esc_html__( '404 Not Found', $themename );
  596. }
  597. if ( $seo_index_type == 'BlogName | Category name' ) {
  598. $custom_title = $sitename . esc_html( $seo_index_separate ) . $page_title;
  599. }
  600. if ( $seo_index_type == 'Category name | BlogName') {
  601. $custom_title = $page_title . esc_html( $seo_index_separate ) . $sitename;
  602. }
  603. if ( $seo_index_type == 'Category name only') {
  604. $custom_title = $page_title;
  605. }
  606. }
  607. $custom_title = wp_strip_all_tags( $custom_title );
  608. return $custom_title;
  609. }
  610. }
  611. add_filter( 'pre_get_document_title', 'elegant_titles_filter' );
  612. /*this function controls the meta description display*/
  613. if ( ! function_exists( 'elegant_description' ) ) {
  614. function elegant_description() {
  615. // Don't use ePanel SEO if WordPress SEO or All In One SEO Pack plugins are active
  616. if ( class_exists( 'WPSEO_Frontend' ) || class_exists( 'All_in_One_SEO_Pack' ) ) {
  617. return;
  618. }
  619. global $shortname, $themename;
  620. #homepage descriptions
  621. if ( et_get_option( $shortname.'_seo_home_description' ) == 'on' && ( ( is_home() || is_front_page() ) && ! elegant_is_blog_posts_page() ) ) {
  622. echo '<meta name="description" content="' . esc_attr( et_get_option( $shortname.'_seo_home_descriptiontext' ) ) .'" />';
  623. }
  624. #single page descriptions
  625. if ( et_get_option( $shortname.'_seo_single_description' ) == 'on' && ( is_single() || is_page() || elegant_is_blog_posts_page() ) ) {
  626. global $wp_query;
  627. if ( isset( $wp_query->post->ID ) || elegant_is_blog_posts_page() ) {
  628. $postid = elegant_is_blog_posts_page() ? intval( get_option( 'page_for_posts' ) ) : $wp_query->post->ID;
  629. }
  630. $key2 = et_get_option( $shortname.'_seo_single_field_description' );
  631. if ( isset( $postid ) ) $exists = get_post_meta( $postid, ''.$key2.'', true );
  632. if ( $exists !== '' ) {
  633. echo '<meta name="description" content="' . esc_attr( $exists ) . '" />';
  634. }
  635. }
  636. #index descriptions
  637. $seo_index_description = et_get_option( $shortname.'_seo_index_description' );
  638. if ( $seo_index_description == 'on' ) {
  639. $is_pre_4_4 = version_compare( $GLOBALS['wp_version'], '4.4', '<' );
  640. $description_added = false;
  641. if ( is_category() ) {
  642. remove_filter( 'term_description', 'wpautop' );
  643. $cat = get_query_var( 'cat' );
  644. $exists2 = category_description( $cat );
  645. if ( $exists2 !== '' ) {
  646. echo '<meta name="description" content="' . esc_attr( $exists2 ) . '" />';
  647. $description_added = true;
  648. }
  649. }
  650. if ( is_archive() && ! $description_added ) {
  651. $description_text = $is_pre_4_4 ? sprintf( esc_html__( 'Currently viewing archives from %1$s', $themename ),
  652. wp_title( '', false, '' )
  653. ) : get_the_archive_title();
  654. printf( '<meta name="description" content="%1$s" />',
  655. esc_attr( $description_text )
  656. );
  657. $description_added = true;
  658. }
  659. if ( is_search() && ! $description_added ) {
  660. $description_text = $is_pre_4_4 ? wp_title( '', false, '' ) : sprintf(
  661. esc_html__( 'Search Results for: %s', $themename ),
  662. get_search_query()
  663. );
  664. echo '<meta name="description" content="' . esc_attr( $description_text ) . '" />';
  665. $description_added = true;
  666. }
  667. }
  668. }
  669. }
  670. /*this function controls the meta keywords display*/
  671. if ( ! function_exists( 'elegant_keywords' ) ) {
  672. function elegant_keywords() {
  673. // Don't use ePanel SEO if WordPress SEO or All In One SEO Pack plugins are active
  674. if ( class_exists( 'WPSEO_Frontend' ) || class_exists( 'All_in_One_SEO_Pack' ) ) {
  675. return;
  676. }
  677. global $shortname;
  678. #homepage keywords
  679. if ( et_get_option( $shortname.'_seo_home_keywords' ) == 'on' && ( ( is_home() || is_front_page() ) && ! elegant_is_blog_posts_page() ) ) {
  680. echo '<meta name="keywords" content="' . esc_attr( et_get_option( $shortname.'_seo_home_keywordstext' ) ) . '" />';
  681. }
  682. #single page keywords
  683. if ( et_get_option( $shortname.'_seo_single_keywords' ) == 'on' ) {
  684. global $wp_query;
  685. if ( isset( $wp_query->post->ID ) || elegant_is_blog_posts_page() ) {
  686. $postid = elegant_is_blog_posts_page() ? intval( get_option( 'page_for_posts' ) ) : $wp_query->post->ID;
  687. }
  688. $key3 = et_get_option( $shortname.'_seo_single_field_keywords' );
  689. if (isset( $postid )) $exists4 = get_post_meta( $postid, ''.$key3.'', true );
  690. if ( isset( $exists4 ) && $exists4 !== '' ) {
  691. if ( is_single() || is_page() || elegant_is_blog_posts_page() ) echo '<meta name="keywords" content="' . esc_attr( $exists4 ) . '" />';
  692. }
  693. }
  694. }
  695. }
  696. /*this function controls canonical urls*/
  697. if ( ! function_exists( 'elegant_canonical' ) ) {
  698. function elegant_canonical() {
  699. // Don't use ePanel SEO if WordPress SEO or All In One SEO Pack plugins are active
  700. if ( class_exists( 'WPSEO_Frontend' ) || class_exists( 'All_in_One_SEO_Pack' ) ) {
  701. return;
  702. }
  703. global $shortname;
  704. #homepage urls
  705. if ( et_get_option( $shortname.'_seo_home_canonical' ) == 'on' && is_home() && ! elegant_is_blog_posts_page() ) {
  706. echo '<link rel="canonical" href="'. esc_url( home_url() ).'" />';
  707. }
  708. #single page urls
  709. if ( et_get_option( $shortname.'_seo_single_canonical' ) == 'on' ) {
  710. global $wp_query;
  711. if ( isset( $wp_query->post->ID ) || elegant_is_blog_posts_page() ) {
  712. $postid = elegant_is_blog_posts_page() ? intval( get_option( 'page_for_posts' ) ) : $wp_query->post->ID;
  713. }
  714. if ( ( is_single() || is_page() || elegant_is_blog_posts_page() ) && ! is_front_page() ) {
  715. echo '<link rel="canonical" href="' . esc_url( get_permalink( $postid ) ) . '" />';
  716. }
  717. }
  718. #index page urls
  719. if ( et_get_option( $shortname.'_seo_index_canonical' ) == 'on' ) {
  720. $current_page_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  721. if ( is_archive() || is_category() || is_search() ) echo '<link rel="canonical" href="'. esc_url( $current_page_url ).'" />';
  722. }
  723. }
  724. }
  725. add_action( 'wp_head', 'add_favicon' );
  726. function add_favicon(){
  727. global $shortname;
  728. $faviconUrl = et_get_option( $shortname.'_favicon' );
  729. if ( $faviconUrl <> '' ) {
  730. echo '<link rel="shortcut icon" href="'.esc_url( $faviconUrl ).'" />';
  731. }
  732. }
  733. add_action( 'init', 'et_create_images_temp_folder' );
  734. function et_create_images_temp_folder(){
  735. #clean et_temp folder once per week
  736. if ( false !== $last_time = get_option( 'et_schedule_clean_images_last_time' ) ) {
  737. $timeout = 86400 * 7;
  738. if ( ( $timeout < ( time() - $last_time ) ) && '' != get_option( 'et_images_temp_folder' ) ) et_clean_temp_images( get_option( 'et_images_temp_folder' ) );
  739. }
  740. if ( false !== get_option( 'et_images_temp_folder' ) ) return;
  741. $uploads_dir = wp_upload_dir();
  742. $destination_dir = ( false === $uploads_dir['error'] ) ? path_join( $uploads_dir['basedir'], 'et_temp' ) : null;
  743. if ( ! wp_mkdir_p( $destination_dir ) ) update_option( 'et_images_temp_folder', '' );
  744. else {
  745. update_option( 'et_images_temp_folder', preg_replace( '#\/\/#', '/', $destination_dir ) );
  746. update_option( 'et_schedule_clean_images_last_time', time() );
  747. }
  748. }
  749. if ( ! function_exists( 'et_clean_temp_images' ) ) {
  750. function et_clean_temp_images( $directory ){
  751. $dir_to_clean = @ opendir( $directory );
  752. if ( $dir_to_clean ) {
  753. while (($file = readdir( $dir_to_clean ) ) !== false ) {
  754. if ( substr( $file, 0, 1 ) == '.' )
  755. continue;
  756. if ( is_dir( $directory.'/'.$file ) )
  757. et_clean_temp_images( path_join( $directory, $file ) );
  758. else
  759. @ unlink( path_join( $directory, $file ) );
  760. }
  761. closedir( $dir_to_clean );
  762. }
  763. #set last time cleaning was performed
  764. update_option( 'et_schedule_clean_images_last_time', time() );
  765. }
  766. }
  767. add_filter( 'update_option_upload_path', 'et_update_uploads_dir' );
  768. function et_update_uploads_dir( $upload_path ){
  769. #check if we have 'et_temp' folder within $uploads_dir['basedir'] directory, if not - try creating it, if it's not possible $destination_dir = null
  770. $destination_dir = '';
  771. $uploads_dir = wp_upload_dir();
  772. $et_temp_dir = path_join( $uploads_dir['basedir'], 'et_temp' );
  773. if ( is_dir( $et_temp_dir ) || ( false === $uploads_dir['error'] && wp_mkdir_p( $et_temp_dir ) ) ) {
  774. $destination_dir = $et_temp_dir;
  775. update_option( 'et_schedule_clean_images_last_time', time() );
  776. }
  777. update_option( 'et_images_temp_folder', preg_replace( '#\/\/#', '/', $destination_dir ) );
  778. return $upload_path;
  779. }
  780. if ( ! function_exists( 'et_resize_image' ) ) {
  781. function et_resize_image( $thumb, $new_width, $new_height, $crop ){
  782. /*
  783. * Fixes the issue with x symbol between width and height values in the filename.
  784. * For instance, sports-400x400.jpg file results in 'image not found' in getimagesize() function.
  785. */
  786. $thumb = str_replace( '%26%23215%3B', 'x', rawurlencode( $thumb ) );
  787. $thumb = rawurldecode( $thumb );
  788. if ( is_ssl() ) $thumb = preg_replace( '#^http://#', 'https://', $thumb );
  789. $info = pathinfo( $thumb );
  790. $ext = $info['extension'];
  791. $name = wp_basename( $thumb, ".$ext" );
  792. $is_jpeg = false;
  793. $site_uri = apply_filters( 'et_resize_image_site_uri', site_url() );
  794. $site_dir = apply_filters( 'et_resize_image_site_dir', ABSPATH );
  795. // If multisite, not the main site, WordPress version < 3.5 or ms-files rewriting is enabled ( not the fresh WordPress installation, updated from the 3.4 version )
  796. if ( is_multisite() && ! is_main_site() && ( ! function_exists( 'wp_get_mime_types' ) || get_site_option( 'ms_files_rewriting' ) ) ) {
  797. //Get main site url on multisite installation
  798. switch_to_blog( 1 );
  799. $site_uri = site_url();
  800. restore_current_blog();
  801. }
  802. /*
  803. * If we're dealing with an external image ( might be the result of Grab the first image function ),
  804. * return original image url
  805. */
  806. if ( false === strpos( $thumb, $site_uri ) )
  807. return $thumb;
  808. if ( 'jpeg' == $ext ) {
  809. $ext = 'jpg';
  810. $name = preg_replace( '#.jpeg$#', '', $name );
  811. $is_jpeg = true;
  812. }
  813. $suffix = "{$new_width}x{$new_height}";
  814. $destination_dir = '' != get_option( 'et_images_temp_folder' ) ? preg_replace( '#\/\/#', '/', get_option( 'et_images_temp_folder' ) ) : null;
  815. $matches = apply_filters( 'et_resize_image_site_dir', array(), $site_dir );
  816. if ( !empty( $matches ) ) {
  817. preg_match( '#'.$matches[1].'$#', $site_uri, $site_uri_matches );
  818. if ( !empty( $site_uri_matches ) ) {
  819. $site_uri = str_replace( $matches[1], '', $site_uri );
  820. $site_uri = preg_replace( '#/$#', '', $site_uri );
  821. $site_dir = str_replace( $matches[1], '', $site_dir );
  822. $site_dir = preg_replace( '#\\\/$#', '', $site_dir );
  823. }
  824. }
  825. #get local name for use in file_exists() and get_imagesize() functions
  826. $localfile = str_replace( apply_filters( 'et_resize_image_localfile', $site_uri, $site_dir, et_multisite_thumbnail( $thumb ) ), $site_dir, et_multisite_thumbnail( $thumb ) );
  827. $add_to_suffix = '';
  828. if ( file_exists( $localfile ) ) $add_to_suffix = filesize( $localfile ) . '_';
  829. #prepend image filesize to be able to use images with the same filename
  830. $suffix = $add_to_suffix . $suffix;
  831. $destfilename_attributes = '-' . $suffix . '.' . strtolower( $ext );
  832. $checkfilename = ( '' != $destination_dir && null !== $destination_dir ) ? path_join( $destination_dir, $name ) : path_join( dirname( $localfile ), $name );
  833. $checkfilename .= $destfilename_attributes;
  834. if ( $is_jpeg ) $checkfilename = preg_replace( '#.jpg$#', '.jpeg', $checkfilename );
  835. $uploads_dir = wp_upload_dir();
  836. $uploads_dir['basedir'] = preg_replace( '#\/\/#', '/', $uploads_dir['basedir'] );
  837. if ( null !== $destination_dir && '' != $destination_dir && apply_filters( 'et_enable_uploads_detection', true ) ) {
  838. $site_dir = trailingslashit( preg_replace( '#\/\/#', '/', $uploads_dir['basedir'] ) );
  839. $site_uri = trailingslashit( $uploads_dir['baseurl'] );
  840. }
  841. #check if we have an image with specified width and height
  842. if ( file_exists( $checkfilename ) ) return str_replace( $site_dir, trailingslashit( $site_uri ), $checkfilename );
  843. $size = @getimagesize( $localfile );
  844. if ( !$size ) return new WP_Error( 'invalid_image_path', esc_html__( 'Image doesn\'t exist' ), $thumb );
  845. list($orig_width, $orig_height, $orig_type) = $size;
  846. #check if we're resizing the image to smaller dimensions
  847. if ( $orig_width > $new_width || $orig_height > $new_height ) {
  848. if ( $orig_width < $new_width || $orig_height < $new_height ) {
  849. #don't resize image if new dimensions > than its original ones
  850. if ( $orig_width < $new_width ) $new_width = $orig_width;
  851. if ( $orig_height < $new_height ) $new_height = $orig_height;
  852. #regenerate suffix and appended attributes in case we changed new width or new height dimensions
  853. $suffix = "{$add_to_suffix}{$new_width}x{$new_height}";
  854. $destfilename_attributes = '-' . $suffix . '.' . $ext;
  855. $checkfilename = ( '' != $destination_dir && null !== $destination_dir ) ? path_join( $destination_dir, $name ) : path_join( dirname( $localfile ), $name );
  856. $checkfilename .= $destfilename_attributes;
  857. #check if we have an image with new calculated width and height parameters
  858. if ( file_exists( $checkfilename ) ) return str_replace( $site_dir, trailingslashit( $site_uri ), $checkfilename );
  859. }
  860. #we didn't find the image in cache, resizing is done here
  861. $et_image_editor = wp_get_image_editor( $localfile );
  862. if ( ! is_wp_error( $et_image_editor ) ) {
  863. $et_image_editor->resize( $new_width, $new_height, $crop );
  864. // generate correct file name/path
  865. $et_new_image_name = $et_image_editor->generate_filename( $suffix, $destination_dir );
  866. do_action( 'et_resize_image_before_save', $et_image_editor, $et_new_image_name );
  867. $et_image_editor->save( $et_new_image_name );
  868. // assign new image path
  869. $result = $et_new_image_name;
  870. } else {
  871. // assign a WP_ERROR ( WP_Image_Editor instance wasn't created properly )
  872. $result = $et_image_editor;
  873. }
  874. if ( ! is_wp_error( $result ) ) {
  875. // transform local image path into URI
  876. if ( $is_jpeg ) $thumb = preg_replace( '#.jpeg$#', '.jpg', $thumb );
  877. $site_dir = str_replace( '\\', '/', $site_dir );
  878. $result = str_replace( '\\', '/', $result );
  879. $result = str_replace( '//', '/', $result );
  880. $result = str_replace( $site_dir, trailingslashit( $site_uri ), $result );
  881. }
  882. #returns resized image path or WP_Error ( if something went wrong during resizing )
  883. return $result;
  884. }
  885. #returns unmodified image, for example in case if the user is trying to resize 800x600px to 1920x1080px image
  886. return $thumb;
  887. }
  888. }
  889. add_action( 'pre_get_posts', 'et_custom_posts_per_page' );
  890. function et_custom_posts_per_page( $query = false ) {
  891. global $shortname;
  892. if ( is_admin() ) {
  893. return;
  894. }
  895. if ( ! is_a( $query, 'WP_Query' ) || ! $query->is_main_query() ) {
  896. return;
  897. }
  898. if ( $query->is_category ) {
  899. $query->set( 'posts_per_page', (int) et_get_option( $shortname . '_catnum_posts', '5' ) );
  900. } elseif ( $query->is_tag ) {
  901. $query->set( 'posts_per_page', (int) et_get_option( $shortname . '_tagnum_posts', '5' ) );
  902. } elseif ( $query->is_search ) {
  903. if ( isset( $_GET['et_searchform_submit'] ) ) {
  904. $postTypes = array();
  905. if ( !isset( $_GET['et-inc-posts'] ) && !isset( $_GET['et-inc-pages'] ) ) $postTypes = array('post');
  906. if ( isset( $_GET['et-inc-pages'] ) ) $postTypes = array('page');
  907. if ( isset( $_GET['et-inc-posts'] ) ) $postTypes[] = 'post';
  908. $query->set( 'post_type', $postTypes );
  909. if ( isset( $_GET['et-month-choice'] ) && $_GET['et-month-choice'] != 'no-choice' ) {
  910. $et_year = substr( $_GET['et-month-choice'], 0, 4 );
  911. $et_month = substr( $_GET['et-month-choice'], 4, strlen( $_GET['et-month-choice'] ) - 4 );
  912. $query->set( 'year', absint( $et_year ) );
  913. $query->set( 'monthnum', absint( $et_month ) );
  914. }
  915. if ( isset( $_GET['et-cat'] ) && $_GET['et-cat'] != 0 )
  916. $query->set( 'cat', absint( $_GET['et-cat'] ) );
  917. }
  918. $query->set( 'posts_per_page', (int) et_get_option( $shortname . '_searchnum_posts', '5' ) );
  919. } elseif ( $query->is_archive ) {
  920. $posts_number = (int) et_get_option( $shortname . '_archivenum_posts', '5' );
  921. if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
  922. $posts_number = (int) et_get_option( $shortname . '_woocommerce_archive_num_posts', '9' );
  923. }
  924. $query->set( 'posts_per_page', $posts_number );
  925. }
  926. }
  927. add_filter( 'pre_set_site_transient_update_themes', 'et_check_themes_updates' );
  928. function et_check_themes_updates( $update_transient ){
  929. global $wp_version;
  930. if ( !isset( $update_transient->checked ) ) return $update_transient;
  931. else $themes = $update_transient->checked;
  932. $send_to_api = array(
  933. 'action' => 'check_theme_updates',
  934. 'installed_themes' => $themes,
  935. );
  936. $options = array(
  937. 'timeout' => ( ( defined( 'DOING_CRON' ) && DOING_CRON ) ? 30 : 3),
  938. 'body' => $send_to_api,
  939. 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url(),
  940. );
  941. $last_update = new stdClass();
  942. $theme_request = wp_remote_post( 'http://www.elegantthemes.com/api/api.php', $options );
  943. if ( !is_wp_error( $theme_request ) && wp_remote_retrieve_response_code( $theme_request ) == 200 ) {
  944. $theme_response = unserialize( wp_remote_retrieve_body( $theme_request ) );
  945. if ( !empty( $theme_response ) ) {
  946. $update_transient->response = array_merge( !empty( $update_transient->response ) ? $update_transient->response : array(), $theme_response );
  947. $last_update->checked = $themes;
  948. $last_update->response = $theme_response;
  949. }
  950. }
  951. $last_update->last_checked = time();
  952. set_site_transient( 'et_update_themes', $last_update );
  953. return $update_transient;
  954. }
  955. add_filter( 'site_transient_update_themes', 'et_add_themes_to_update_notification' );
  956. function et_add_themes_to_update_notification( $update_transient ){
  957. $et_update_themes = get_site_transient( 'et_update_themes' );
  958. if ( !is_object( $et_update_themes ) || !isset( $et_update_themes->response ) ) return $update_transient;
  959. // Fix for warning messages on Dashboard / Updates page
  960. if ( ! is_object( $update_transient ) ) {
  961. $update_transient = new stdClass();
  962. }
  963. $update_transient->response = array_merge( !empty( $update_transient->response ) ? $update_transient->response : array(), $et_update_themes->response );
  964. return $update_transient;
  965. }
  966. add_filter( 'default_hidden_meta_boxes', 'et_show_hidden_metaboxes', 10, 2 );
  967. function et_show_hidden_metaboxes( $hidden, $screen ){
  968. # make custom fields and excerpt meta boxes show by default
  969. if ( 'post' == $screen->base || 'page' == $screen->base )
  970. $hidden = array(
  971. 'slugdiv',
  972. 'trackbacksdiv',
  973. 'commentstatusdiv',
  974. 'commentsdiv',
  975. 'authordiv',
  976. 'revisionsdiv',
  977. );
  978. return $hidden;
  979. }
  980. add_filter( 'widget_title', 'et_widget_force_title' );
  981. function et_widget_force_title( $title ){
  982. #add an empty title for widgets ( otherwise it might break the sidebar layout )
  983. if ( $title == '' ) $title = ' ';
  984. return $title;
  985. }
  986. //modify the comment counts to only reflect the number of comments minus pings
  987. if( version_compare( phpversion(), '4.4', '>=' ) ) add_filter( 'get_comments_number', 'et_comment_count', 0, 2 );
  988. function et_comment_count( $count, $post_id ) {
  989. $is_doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX ? true : false;
  990. if ( ! is_admin() || $is_doing_ajax ) {
  991. global $id;
  992. $post_id = $post_id ? $post_id : $id;
  993. $get_comments = get_comments( array('post_id' => $post_id, 'status' => 'approve') );
  994. $comments_by_type = separate_comments( $get_comments );
  995. return count( $comments_by_type['comment'] );
  996. } else {
  997. return $count;
  998. }
  999. }
  1000. add_action( 'admin_init', 'et_theme_check_clean_installation' );
  1001. function et_theme_check_clean_installation(){
  1002. add_action( 'admin_notices', 'et_theme_epanel_reminder' );
  1003. }
  1004. if ( ! function_exists( 'et_theme_epanel_reminder' ) ) {
  1005. function et_theme_epanel_reminder(){
  1006. global $shortname, $themename, $current_screen;
  1007. if ( false === et_get_option( $shortname . '_logo' ) && 'appearance_page_core_functions' != $current_screen->id ) {
  1008. printf( et_get_safe_localization( __( '<div class="updated"><p>This is a fresh installation of %1$s theme. Don\'t forget to go to <a href="%2$s">ePanel</a> to set it up. This message will disappear once you have clicked the Save button within the <a href="%2$s">theme\'s options page</a>.</p></div>', $themename ) ), wp_get_theme(), admin_url( 'themes.php?page=core_functions.php' ) );
  1009. }
  1010. }
  1011. }
  1012. add_filter( 'gettext', 'et_admin_update_theme_message', 20, 3 );
  1013. function et_admin_update_theme_message( $default_translated_text, $original_text, $domain ) {
  1014. global $themename;
  1015. $theme_page_message = 'There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>. <em>Automatic update is unavailable for this theme.</em>';
  1016. $updates_page_message = 'Update package not available.';
  1017. if ( is_admin() && $original_text === $theme_page_message ) {
  1018. return et_get_safe_localization( __( 'There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>. <em>Before you can update your Elegant Themes, you must first install the <a href="https://www.elegantthemes.com/members-area/documentation.html#updater" target="_blank">Elegant Updater Plugin</a> to authenticate your subscription.</em>', $themename ) );
  1019. }
  1020. if ( is_admin() && $original_text === $updates_page_message ) {
  1021. return et_get_safe_localization( __( 'Before you can update your Elegant Themes, you must first install the <a href="https://www.elegantthemes.com/members-area/documentation.html#updater" target="_blank">Elegant Updater Plugin</a> to authenticate your subscription.', $themename ) );
  1022. }
  1023. return $default_translated_text;
  1024. }
  1025. add_filter( 'body_class', 'et_add_fullwidth_body_class' );
  1026. function et_add_fullwidth_body_class( $classes ){
  1027. $fullwidth_view = false;
  1028. if ( is_page_template( 'page-full.php' ) ) $fullwidth_view = true;
  1029. if ( is_page() || is_single() ) {
  1030. $et_ptemplate_settings = get_post_meta( get_queried_object_id(), 'et_ptemplate_settings', true );
  1031. $fullwidth = isset( $et_ptemplate_settings['et_fullwidthpage'] ) ? (bool) $et_ptemplate_settings['et_fullwidthpage'] : false;
  1032. if ( $fullwidth ) $fullwidth_view = true;
  1033. }
  1034. if ( is_single() && 'on' == get_post_meta( get_queried_object_id(), '_et_full_post', true ) ) $fullwidth_view = true;
  1035. $classes[] = apply_filters( 'et_fullwidth_view_body_class', $fullwidth_view ) ? 'et_fullwidth_view' : 'et_includes_sidebar';
  1036. return $classes;
  1037. }
  1038. function et_add_responsive_shortcodes_css(){
  1039. global $shortname;
  1040. if ( 'on' == et_get_option( $shortname . '_responsive_shortcodes', 'on' ) )
  1041. wp_enqueue_style( 'et-shortcodes-responsive-css', ET_SHORTCODES_DIR . '/css/shortcodes_responsive.css', false, ET_SHORTCODES_VERSION, 'all' );
  1042. }
  1043. /**
  1044. * Loads theme settings
  1045. *
  1046. */
  1047. if ( ! function_exists( 'et_load_core_options' ) ) {
  1048. function et_load_core_options() {
  1049. global $shortname;
  1050. require_once get_template_directory() . esc_attr( "/options_{$shortname}.php" );
  1051. }
  1052. }
  1053. /**
  1054. * Adds custom css option content to <head>
  1055. *
  1056. */
  1057. function et_add_custom_css() {
  1058. global $shortname;
  1059. $custom_css = et_get_option( "{$shortname}_custom_css" );
  1060. if ( false === $custom_css || '' == $custom_css ) return;
  1061. /**
  1062. * The theme doesn't strip slashes from custom css, when saving to the database,
  1063. * so it does that before outputting the code on front-end
  1064. */
  1065. echo '<style type="text/css" id="et-custom-css">' . "\n" . stripslashes( $custom_css ) . "\n" . '</style>';
  1066. }
  1067. add_action( 'wp_head', 'et_add_custom_css', 100 );
  1068. if ( ! function_exists( 'et_get_google_fonts' ) ) :
  1069. /**
  1070. * Returns the list of popular google fonts
  1071. *
  1072. */
  1073. function et_get_google_fonts() {
  1074. $google_fonts = array(
  1075. 'Open Sans' => array(