· 10 years ago · Aug 24, 2016, 11:52 AM
1<?php
2/**
3 * FlatAds functions and definitions.
4 *
5 * Sets up the theme and provides some helper functions, which are used in the
6 * theme as custom template tags. Others are attached to action and filter
7 * hooks in WordPress to change core functionality.
8 *
9 * When using a child theme (see http://codex.wordpress.org/Theme_Development
10 * and http://codex.wordpress.org/Child_Themes), you can override certain
11 * functions (those wrapped in a function_exists() call) by defining them first
12 * in your child theme's functions.php file. The child theme's functions.php
13 * file is included before the parent theme's file, so the child theme
14 * functions would be used.
15 *
16 * Functions that are not pluggable (not wrapped in function_exists()) are
17 * instead attached to a filter or action hook.
18 *
19 * For more information on hooks, actions, and filters,
20 * see http://codex.wordpress.org/Plugin_API
21 *
22 * @package WordPress
23 * @subpackage FlatAds
24 * @since FlatAds 1.6.5
25 */
26
27
28add_action( 'after_setup_theme', 'flatads_theme_setup' );
29
30
31function flatads_theme_setup() {
32
33 add_theme_support( 'woocommerce' );
34
35 add_theme_support( 'custom-background' );
36
37 /**
38 * Adds post custom meta.
39 */
40 require get_template_directory() . '/inc/post_meta.php';
41
42 // Add Featured Post Prie Plans
43 require get_template_directory() . '/inc/plans.php';
44
45 // Add Page Meta Fields
46 require get_template_directory() . '/inc/page_meta.php';
47
48 // Add Shortcodes
49 require get_template_directory() . '/inc/shortcode.lib.php';
50
51 // Add Colors
52 require get_template_directory() . '/inc/colors.php';
53
54 // Add Colors
55 require get_template_directory() . '/inc/twitter.php';
56
57 /**
58 * Sets up the content width value based on the theme's design.
59 * @see FlatAds_content_width() for template-specific adjustments.
60 */
61 if ( ! isset( $content_width ) )
62 $content_width = 1060;
63
64 /**
65 * FlatAds only works in WordPress 3.6 or later.
66 */
67 if ( version_compare( $GLOBALS['wp_version'], '3.6-alpha', '<' ) )
68 require get_template_directory() . '/inc/back-compat.php';
69
70 /**
71 * Sets up theme defaults and registers the various WordPress features that
72 * FlatAds supports.
73 *
74 * @uses load_theme_textdomain() For translation/localization support.
75 * @uses add_editor_style() To add Visual Editor stylesheets.
76 * @uses add_theme_support() To add support for automatic feed links, post
77 * formats, and post thumbnails.
78 * @uses register_nav_menu() To add support for a navigation menu.
79 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
80 *
81 * @since FlatAds 1.0
82 *
83 * @return void
84 */
85
86 /*
87 * Makes FlatAds available for translation.
88 *
89 * Translations can be added to the /languages/ directory.
90 * If you're building a theme based on FlatAds, use a find and
91 * replace to change 'FlatAds' to the name of your theme in all
92 * template files.
93 */
94 load_theme_textdomain( 'agrg', get_template_directory() . '/languages' );
95
96 /*
97 * This theme styles the visual editor to resemble the theme style,
98 * specifically font, colors, icons, and column width.
99 */
100 add_editor_style( array( 'css/editor-style.css', 'fonts/genericons.css', FlatAds_fonts_url() ) );
101
102 // Adds RSS feed links to <head> for posts and comments.
103 add_theme_support( 'automatic-feed-links' );
104
105 // Switches default core markup for search form, comment form, and comments
106 // to output valid HTML5.
107 add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list' ) );
108
109 // This theme uses wp_nav_menu() in one location.
110 register_nav_menu( 'primary', __( 'Navigation Menu', 'agrg' ) );
111
112 /*
113 * This theme uses a custom image size for featured images, displayed on
114 * "standard" posts and pages.
115 */
116 add_theme_support( 'post-thumbnails' );
117 set_post_thumbnail_size( 440, 266, true );
118
119 // This theme uses its own gallery styles.
120 add_filter( 'use_default_gallery_style', '__return_false' );
121
122 // Disable Disqus commehts on woocommerce product //
123 add_filter( 'woocommerce_product_tabs', 'disqus_override_tabs', 98);
124
125 /* Add your nav menus function to the 'init' action hook. */
126 add_action( 'init', 'wpcrown_register_my_menu' );
127
128 // Custom admin scripts
129 add_action('admin_enqueue_scripts', 'wpcads_custom_admin_scripts' );
130
131 // Author add new contact details
132 add_filter('user_contactmethods','wpcrown_author_new_contact',10,1);
133
134 // Lost Password and Login Error
135 add_action( 'wp_login_failed', 'wpcrown_front_end_login_fail' ); // hook failed login
136
137 // Register the custom twitter widget
138 add_action( 'widgets_init', 'WPCrown_register_custom_twitter_widget' );
139
140 // Load scripts and styles
141 add_action( 'wp_enqueue_scripts', 'FlatAds_scripts_styles' );
142
143 // Add custom metas
144 add_action( 'add_meta_boxes', 'wpcrown_add_posts_metaboxes' );
145
146 // Save custom posts
147 add_action('save_post', 'wpcrown_save_post_meta', 1, 2); // save the custom fields
148
149 // Category new fields (the form)
150 add_filter('add_category_form', 'wpcrown_my_category_fields');
151 add_filter('edit_category_form', 'wpcrown_my_category_fields');
152
153 // Update category fields
154 add_action( 'edited_category', 'wpcrown_update_my_category_fields', 10, 2 );
155 add_action( 'create_category', 'wpcrown_update_my_category_fields', 10, 2 );
156
157 //Include the TGM_Plugin_Activation class.
158 require_once dirname( __FILE__ ) . '/inc/class-tgm-plugin-activation.php';
159 add_action( 'tgmpa_register', 'my_theme_register_required_plugins' );
160
161 // Google analitycs code
162 add_action( 'wp_enqueue_scripts', 'wpcrown_google_analityc_code' );
163
164 // Enqueue main font
165 add_action( 'wp_enqueue_scripts', 'wpcrown_main_font' );
166
167 // Enqueue main font
168 add_action( 'wp_enqueue_scripts', 'wpcrown_second_font_armata' );
169
170 // Track views
171 add_action( 'wp_head', 'wpb_track_post_views');
172
173 // Theme page titles
174 add_filter( 'wp_title', 'FlatAds_wp_title', 10, 2 );
175
176 // FlatAds sidebars spot
177 add_action( 'widgets_init', 'FlatAds_widgets_init' );
178
179 // FlatAds body class
180 add_filter( 'body_class', 'FlatAds_body_class' );
181
182 // FlatAds content width
183 add_action( 'template_redirect', 'FlatAds_content_width' );
184
185 // FlatAds customize register
186 add_action( 'customize_register', 'FlatAds_customize_register' );
187
188 // FlatAds customize preview
189 add_action( 'customize_preview_init', 'FlatAds_customize_preview_js' );
190
191 /* Add theme support for automatic feed links. */
192 add_theme_support( 'automatic-feed-links' );
193
194 // Reset permalinks
195 add_action( 'init', 'wpcook_reset_permalinks' );
196
197}
198
199function wpcook_reset_permalinks() {
200 global $wp_rewrite;
201 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
202}
203
204
205// Disable Disqus commehts on woocommerce product //
206function disqus_override_tabs($tabs){
207 if ( has_filter( 'comments_template', 'dsq_comments_template' ) ){
208 remove_filter( 'comments_template', 'dsq_comments_template' );
209 add_filter('comments_template', 'dsq_comments_template',90);//higher priority, so the filter is called after woocommerce filter
210 }
211 return $tabs;
212}
213
214
215
216/*
217 * Setup main navigation menu
218 */
219function wpcrown_register_my_menu() {
220 // register menu
221 register_nav_menus (
222 array(
223 'primary' =>__('Main menu'),
224 'secondary' =>__('Footer menu'),
225 )
226 );
227}
228
229
230
231function wpcook_get_attachment_id_from_src($image_src) {
232
233 global $wpdb;
234 $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
235 $id = $wpdb->get_var($query);
236 return $id;
237
238}
239
240
241// Custom admin scripts
242function wpcads_custom_admin_scripts() {
243 wp_enqueue_media();
244}
245
246
247function wpcook_add_media_upload_scripts() {
248 if ( is_admin() ) {
249 return;
250 }
251 wp_enqueue_media();
252}
253add_action('wp_enqueue_scripts', 'wpcook_add_media_upload_scripts');
254
255function wpcook_get_avatar_url($author_id, $size){
256 $get_avatar = get_avatar( $author_id, $size );
257 preg_match("/src='(.*?)'/i", $get_avatar, $matches);
258 return ( $matches[1] );
259}
260
261
262
263function allow_users_uploads() {
264
265 $contributor = get_role('subscriber');
266 $contributor->add_cap('upload_files');
267 $contributor->add_cap('delete_published_posts');
268
269}
270add_action('admin_init', 'allow_users_uploads');
271
272
273if ( current_user_can('subscriber') && !current_user_can('upload_files') ) {
274 add_action('admin_init', 'wpcook_allow_contributor_uploads');
275}
276function wpcook_allow_contributor_uploads() {
277 $contributor = get_role('subscriber');
278 $contributor->add_cap('upload_files');
279}
280
281
282add_filter( 'posts_where', 'wpcook_devplus_attachments_wpquery_where' );
283function wpcook_devplus_attachments_wpquery_where( $where ){
284 global $current_user;
285
286 if( is_user_logged_in() ){
287 // we spreken over een ingelogde user
288 if( isset( $_POST['action'] ) ){
289 // library query
290 if( $_POST['action'] == 'query-attachments' ){
291 $where .= ' AND post_author='.$current_user->data->ID;
292 }
293 }
294 }
295
296 return $where;
297}
298
299add_action('after_setup_theme', 'remove_admin_bar');
300function remove_admin_bar() {
301 if (!current_user_can('administrator') && !is_admin()) {
302 show_admin_bar(false);
303 }
304}
305
306
307// Author add new contact details
308function wpcrown_author_new_contact( $contactmethods ) {
309
310 // Add telefone
311 $contactmethods['phone'] = 'Phone';
312 // add address
313 $contactmethods['address'] = 'Address';
314
315 return $contactmethods;
316
317}
318
319
320// Add user price plan info
321function wpcrown_save_extra_profile_fields( $user_id ) {
322 update_user_meta( $user_id, 'price_plan' );
323 add_user_meta( $user_id, 'price_plan_id' );
324}
325
326
327
328// Lost Password and Login Error
329function wpcrown_front_end_login_fail( $username ) {
330 $referrer = $_SERVER['HTTP_REFERER']; // where did the post submission come from?
331 // if there's a valid referrer, and it's not the default log-in screen
332 if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') && $user!=null ) {
333 wp_redirect( $referrer . '?login=failed' ); // let's append some information (login=failed) to the URL for the theme to use
334 exit;
335 } elseif ( is_wp_error($user_verify) ) {
336 wp_redirect( $referrer . '?login=failed-user' ); // let's append some information (login=failed) to the URL for the theme to use
337 exit;
338 }
339}
340// End
341
342
343// Insert attachments front end
344function wpcads_insert_attachment($file_handler,$post_id,$setthumb='false') {
345
346 // check to make sure its a successful upload
347 if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
348
349 require_once(ABSPATH . "wp-admin" . '/includes/image.php');
350 require_once(ABSPATH . "wp-admin" . '/includes/file.php');
351 require_once(ABSPATH . "wp-admin" . '/includes/media.php');
352
353 $attach_id = media_handle_upload( $file_handler, $post_id );
354
355 if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id);
356 return $attach_id;
357}
358
359
360/**
361* Begin Twitter Custom Widgets
362**/
363class WPCrown_Custom_Twitter extends WP_Widget {
364 function WPCrown_Custom_Twitter() {
365 $widget_ops = array('classname' => 'WPCrown_Custom_Twitter', 'description' => 'Display your recent Twitter feed' );
366 $this->WP_Widget('WPCrown_Custom_Twitter', 'FlatAds Custom Twitter', $widget_ops);
367 }
368
369 function widget($args, $instance) {
370 // outputs the content of the widget
371 extract($args); // Make before_widget, etc available.
372
373 $twitter_consumer_key = isset($instance['twitter_consumer_key']) ? $instance['twitter_consumer_key'] : "";
374 $twitter_consumer_secret = isset($instance['twitter_consumer_secret']) ? $instance['twitter_consumer_secret'] : "";
375 $twitter_user_token = isset($instance['twitter_user_token']) ? $instance['twitter_user_token'] : "";
376 $twitter_user_secret = isset($instance['twitter_user_secret']) ? $instance['twitter_user_secret'] : "";
377 $twitter_username = isset($instance['twitter_username']) ? $instance['twitter_username'] : "";
378 $twitter_count = isset($instance['twitter_count']) ? $instance['twitter_count'] : "";
379
380 $twitter_title = empty($instance['title']) ? __('Twitter', TEMPLATE_DOMAIN) : apply_filters('widget_title', $instance['title']);
381 $unique_id = $args['widget_id'];
382
383
384 echo $before_widget;
385 echo $before_title . $twitter_title . $after_title; ?>
386 <ul class="twitterbox" id="twitter_update_list_<?php echo $unique_id; ?>">
387
388
389 <?php echo agurghis_twitter_timeline (
390 $twitter_username,
391 $twitter_count,
392 $twitter_consumer_key,
393 $twitter_consumer_secret,
394 $twitter_user_token,
395 $twitter_user_secret ); ?>
396
397 <li class="followme"><a style="font-weight: normal; letter-spacing: normal; font-size: 11px;" href="https://twitter.com/<?php echo $twitter_username; ?>"><?php _e("Joined ",'TEMPLATE_DOMAIN'); ?>
398 <?php echo agurghis_twitter_count (
399 $twitter_username,
400 $twitter_consumer_key,
401 $twitter_consumer_secret,
402 $twitter_user_token,
403 $twitter_user_secret );
404 ?> <?php _e("Followers @",'TEMPLATE_DOMAIN'); ?><?php echo $twitter_username; ?></a></li>
405
406 </ul>
407 <?php echo $after_widget;
408 }
409
410 function update($new_instance, $old_instance) {
411 //update and save the widget
412 return $new_instance;
413 }
414
415 function form($instance) {
416 // Get the options into variables, escaping html characters on the way
417 $twitter_consumer_key = isset($instance['twitter_consumer_key']) ? $instance['twitter_consumer_key'] : "";
418 $twitter_consumer_secret = isset($instance['twitter_consumer_secret']) ? $instance['twitter_consumer_secret'] : "";
419 $twitter_user_token = isset($instance['twitter_user_token']) ? $instance['twitter_user_token'] : "";
420 $twitter_user_secret = isset($instance['twitter_user_secret']) ? $instance['twitter_user_secret'] : "";
421 $twitter_username = isset($instance['twitter_username']) ? $instance['twitter_username'] : "";
422 $twitter_count = isset($instance['twitter_count']) ? $instance['twitter_count'] : "";
423 $twitter_title = empty($instance['title']) ? __('Twitter', TEMPLATE_DOMAIN) : apply_filters('widget_title', $instance['title']);
424 ?>
425
426 <p>
427 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e("Twitter Title:",TEMPLATE_DOMAIN); ?></label>
428 <input class="widefat" type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $twitter_title; ?>" />
429 </p>
430
431 <p><label for="<?php echo $this->get_field_id('twitter_consumer_key'); ?>">
432 <?php echo __('Twitter Consumer Key:', TEMPLATE_DOMAIN)?></label>
433 <input class="widefat" type="text" id="<?php echo $this->get_field_id('twitter_consumer_key'); ?>" name="<?php echo $this->get_field_name('twitter_consumer_key'); ?>" value="<?php echo $twitter_consumer_key; ?>" />
434 </p>
435
436 <p><label for="<?php echo $this->get_field_id('twitter_consumer_secret'); ?>">
437 <?php echo __('Twitter Consumer Secret:', TEMPLATE_DOMAIN)?></label>
438 <input class="widefat" type="text" id="<?php echo $this->get_field_id('twitter_consumer_secret'); ?>" name="<?php echo $this->get_field_name('twitter_consumer_secret'); ?>" value="<?php echo $twitter_consumer_secret; ?>" />
439 </p>
440
441 <p><label for="<?php echo $this->get_field_id('twitter_user_token'); ?>">
442 <?php echo __('Twitter User Token:', TEMPLATE_DOMAIN)?></label>
443 <input class="widefat" type="text" id="<?php echo $this->get_field_id('twitter_user_token'); ?>" name="<?php echo $this->get_field_name('twitter_user_token'); ?>" value="<?php echo $twitter_user_token; ?>" />
444 </p>
445
446 <p><label for="<?php echo $this->get_field_id('twitter_user_secret'); ?>">
447 <?php echo __('Twitter User Secret:', TEMPLATE_DOMAIN)?></label>
448 <input class="widefat" type="text" id="<?php echo $this->get_field_id('twitter_user_secret'); ?>" name="<?php echo $this->get_field_name('twitter_user_secret'); ?>" value="<?php echo $twitter_user_secret; ?>" />
449 </p>
450
451
452 <p><label for="<?php echo $this->get_field_id('twitter_username'); ?>">
453 <?php echo __('Twitter ID:', TEMPLATE_DOMAIN)?></label>
454 <input class="widefat" type="text" id="<?php echo $this->get_field_id('twitter_username'); ?>" name="<?php echo $this->get_field_name('twitter_username'); ?>" value="<?php echo $twitter_username; ?>" />
455 </p>
456
457 <p>
458 <label for="<?php echo $this->get_field_id('twitter_count'); ?>"><?php echo __('Number Of Tweets:', TEMPLATE_DOMAIN)?></label>
459 <input class="widefat" type="text" id="<?php echo $this->get_field_id('twitter_count'); ?>" name="<?php echo $this->get_field_name('twitter_count'); ?>" value="<?php echo $twitter_count; ?>" />
460 </p>
461
462 <?php
463 }
464}
465
466function WPCrown_register_custom_twitter_widget() {
467 register_widget('WPCrown_Custom_Twitter');
468}
469/**
470* End Twitter Feed Custom Widgets
471**/
472
473
474/*--------------------------------------*/
475/* Custom Post Meta */
476/*--------------------------------------*/
477// Add the Post Meta Boxes
478function wpcrown_add_posts_metaboxes() {
479 //add_meta_box('wpcrown_featured_post', 'Featured Post', 'wpcrown_featured_post', 'post', 'side', 'default');
480}
481
482// Show The Post On Slider Option
483function wpcrown_featured_post() {
484 global $post;
485
486 // Noncename needed to verify where the data originated
487 echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' .
488 wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
489
490 // Get the location data if its already been entered
491 $featured_post = get_post_meta($post->ID, 'featured_post', true);
492
493 // Echo out the field
494 echo '<span class="text overall" style="margin-right: 20px;">Check to have this as featured post:</span>';
495
496 $checked = get_post_meta($post->ID, 'featured_post', true) == '1' ? "checked" : "";
497
498 echo '<input type="checkbox" name="featured_post" id="featured_post" value="1" '. $checked .'/>';
499
500}
501
502// Save the Metabox Data
503function wpcrown_save_post_meta($post_id, $post) {
504
505 // verify this came from the our screen and with proper authorization,
506 // because save_post can be triggered at other times
507 if ( !wp_verify_nonce( isset( $_POST['eventmeta_noncename'] ) ? $_POST['eventmeta_noncename'] : '', plugin_basename(__FILE__) )) {
508 return $post->ID;
509 }
510
511 // Is the user allowed to edit the post or page?
512 if ( !current_user_can( 'edit_post', $post->ID ))
513 return $post->ID;
514
515 // OK, we're authenticated: we need to find and save the data
516 // We'll put it into an array to make it easier to loop though.
517
518 $events_meta['featured_post'] = $_POST['featured_post'];
519
520 $chk = ( isset( $_POST['featured_post'] ) && $_POST['featured_post'] ) ? '1' : '2';
521 update_post_meta( $post_id, 'featured_post', $chk );
522
523 // Add values of $events_meta as custom fields
524 foreach ($events_meta as $key => $value) { // Cycle through the $events_meta array!
525 if( $post->post_type == 'post' ) return; // Don't store custom data twice
526 $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
527 if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
528 update_post_meta($post->ID, $key, $value);
529 } else { // If the custom field doesn't have a value
530 add_post_meta($post->ID, $key, $value);
531 }
532 if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
533 }
534
535}
536/* End */
537
538
539
540
541/**
542 * Returns the Google font stylesheet URL, if available.
543 *
544 * The use of Source Sans Pro and Bitter by default is localized. For languages
545 * that use characters not supported by the font, the font can be disabled.
546 *
547 * @since FlatAds 1.0
548 *
549 * @return string Font stylesheet or empty string if disabled.
550 */
551function FlatAds_fonts_url() {
552 $fonts_url = '';
553
554 /* Translators: If there are characters in your language that are not
555 * supported by Source Sans Pro, translate this to 'off'. Do not translate
556 * into your own language.
557 */
558 $source_sans_pro = _x( 'on', 'Source Sans Pro font: on or off', 'FlatAds' );
559
560 /* Translators: If there are characters in your language that are not
561 * supported by Bitter, translate this to 'off'. Do not translate into your
562 * own language.
563 */
564 $bitter = _x( 'on', 'Bitter font: on or off', 'FlatAds' );
565
566 if ( 'off' !== $source_sans_pro || 'off' !== $bitter ) {
567 $font_families = array();
568
569 if ( 'off' !== $source_sans_pro )
570 $font_families[] = 'Source Sans Pro:300,400,700,300italic,400italic,700italic';
571
572 if ( 'off' !== $bitter )
573 $font_families[] = 'Bitter:400,700';
574
575 $query_args = array(
576 'family' => urlencode( implode( '|', $font_families ) ),
577 'subset' => urlencode( 'latin,latin-ext' ),
578 );
579 $fonts_url = add_query_arg( $query_args, "//fonts.googleapis.com/css" );
580 }
581
582 return $fonts_url;
583}
584
585//////////////////////////////////////////////////////////////////
586//// function to display extra info on category admin
587//////////////////////////////////////////////////////////////////
588// the option name
589define('MY_CATEGORY_FIELDS', 'my_category_fields_option');
590
591// your fields (the form)
592function wpcrown_my_category_fields($tag) {
593 $tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
594 $category_icon_code = isset( $tag_extra_fields[$tag->term_id]['category_icon_code'] ) ? esc_attr( $tag_extra_fields[$tag->term_id]['category_icon_code'] ) : '';
595 $category_icon_color = isset( $tag_extra_fields[$tag->term_id]['category_icon_color'] ) ? esc_attr( $tag_extra_fields[$tag->term_id]['category_icon_color'] ) : '';
596 $your_image_url = isset( $tag_extra_fields[$tag->term_id]['your_image_url'] ) ? esc_attr( $tag_extra_fields[$tag->term_id]['your_image_url'] ) : '';
597 ?>
598
599<div class="form-field">
600<table class="form-table">
601 <tr class="form-field">
602 <th scope="row" valign="top"><label for="category-page-slider">Icon Code</label></th>
603 <td>
604
605 <input id="category_icon_code" type="text" size="36" name="category_icon_code" value="<?php $category_icon = stripslashes($category_icon_code); echo esc_attr($category_icon); ?>" />
606 <p class="description">AwesomeFont code: <a href="http://fontawesome.io/icons/" target="_blank">fontawesome.io/icons</a></p>
607
608 </td>
609 </tr>
610 <tr class="form-field">
611 <th scope="row" valign="top"><label for="category-page-slider">Icon Background Color</label></th>
612 <td>
613
614 <link rel="stylesheet" media="screen" type="text/css" href="<?php echo get_template_directory_uri() ?>/inc/color-picker/css/colorpicker.css" />
615 <script type="text/javascript" src="<?php echo get_template_directory_uri() ?>/inc/color-picker/js/colorpicker.js"></script>
616 <script type="text/javascript">
617 jQuery.noConflict();
618 jQuery(document).ready(function(){
619 jQuery('#colorpickerHolder').ColorPicker({color: '<?php echo $category_icon_color; ?>', flat: true, onChange: function (hsb, hex, rgb) { jQuery('#category_icon_color').val('#' + hex); }});
620 });
621 </script>
622
623 <p id="colorpickerHolder"></p>
624
625 <input id="category_icon_color" type="text" size="36" name="category_icon_color" value="<?php echo $category_icon_color; ?>" style="margin-top: 20px; max-width: 90px; visibility: hidden;" />
626
627 </td>
628 </tr>
629 <tr class="form-field">
630 <th scope="row" valign="top"><label for="category-page-slider">Map Pin</label></th>
631 <td>
632 <?php
633
634 if(!empty($your_image_url)) {
635
636 echo '<div style="width: 100%; float: left;"><img id="your_image_url_img" src="'. $your_image_url .'" style="float: left; margin-bottom: 20px;" /> </div>';
637 echo '<input id="your_image_url" type="text" size="36" name="your_image_url" style="max-width: 200px; float: left; margin-top: 10px; display: none;" value="'.$your_image_url.'" />';
638 echo '<input id="your_image_url_button_remove" class="button" type="button" style="max-width: 140px; float: left; margin-top: 10px;" value="Remove" /> </br>';
639 echo '<input id="your_image_url_button" class="button" type="button" style="max-width: 140px; float: left; margin-top: 10px; display: none;" value="Upload Image" /> </br>';
640
641 } else {
642
643 echo '<div style="width: 100%; float: left;"><img id="your_image_url_img" src="'. $your_image_url .'" style="float: left; margin-bottom: 20px;" /> </div>';
644 echo '<input id="your_image_url" type="text" size="36" name="your_image_url" style="max-width: 200px; float: left; margin-top: 10px; display: none;" value="'.$your_image_url.'" />';
645 echo '<input id="your_image_url_button_remove" class="button" type="button" style="max-width: 140px; float: left; margin-top: 10px; display: none;" value="Remove" /> </br>';
646 echo '<input id="your_image_url_button" class="button" type="button" style="max-width: 140px; float: left; margin-top: 10px;" value="Upload Image" /> </br>';
647
648 }
649
650 ?>
651 </td>
652
653 <script>
654 var image_custom_uploader;
655 jQuery('#your_image_url_button').click(function(e) {
656 e.preventDefault();
657
658 //If the uploader object has already been created, reopen the dialog
659 if (image_custom_uploader) {
660 image_custom_uploader.open();
661 return;
662 }
663
664 //Extend the wp.media object
665 image_custom_uploader = wp.media.frames.file_frame = wp.media({
666 title: 'Choose Image',
667 button: {
668 text: 'Choose Image'
669 },
670 multiple: false
671 });
672
673 //When a file is selected, grab the URL and set it as the text field's value
674 image_custom_uploader.on('select', function() {
675 attachment = image_custom_uploader.state().get('selection').first().toJSON();
676 var url = '';
677 url = attachment['url'];
678 jQuery('#your_image_url').val(url);
679 jQuery( "img#your_image_url_img" ).attr({
680 src: url
681 });
682 jQuery("#your_image_url_button").css("display", "none");
683 jQuery("#your_image_url_button_remove").css("display", "block");
684 });
685
686 //Open the uploader dialog
687 image_custom_uploader.open();
688 });
689
690 jQuery('#your_image_url_button_remove').click(function(e) {
691 jQuery('#your_image_url').val('');
692 jQuery( "img#your_image_url_img" ).attr({
693 src: ''
694 });
695 jQuery("#your_image_url_button").css("display", "block");
696 jQuery("#your_image_url_button_remove").css("display", "none");
697 });
698 </script>
699 </tr>
700</table>
701</div>
702
703 <?php
704}
705
706
707// when the form gets submitted, and the category gets updated (in your case the option will get updated with the values of your custom fields above
708function wpcrown_update_my_category_fields($term_id) {
709 if($_POST['taxonomy'] == 'category'):
710 $tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
711 $tag_extra_fields[$term_id]['your_image_url'] = strip_tags($_POST['your_image_url']);
712 $tag_extra_fields[$term_id]['category_icon_code'] = $_POST['category_icon_code'];
713 $tag_extra_fields[$term_id]['category_icon_color'] = $_POST['category_icon_color'];
714 update_option(MY_CATEGORY_FIELDS, $tag_extra_fields);
715 endif;
716}
717
718
719// when a category is removed
720add_filter('deleted_term_taxonomy', 'wpcrown_remove_my_category_fields');
721function wpcrown_remove_my_category_fields($term_id) {
722 if($_POST['taxonomy'] == 'category'):
723 $tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
724 unset($tag_extra_fields[$term_id]);
725 update_option(MY_CATEGORY_FIELDS, $tag_extra_fields);
726 endif;
727}
728
729
730
731
732/**
733 * Register the required plugins for this theme.
734 *
735 * In this example, we register two plugins - one included with the TGMPA library
736 * and one from the .org repo.
737 *
738 * The variable passed to tgmpa_register_plugins() should be an array of plugin
739 * arrays.
740 *
741 * This function is hooked into tgmpa_init, which is fired within the
742 * TGM_Plugin_Activation class constructor.
743 */
744function my_theme_register_required_plugins() {
745
746 /**
747 * Array of plugin arrays. Required keys are name, slug and required.
748 * If the source is NOT from the .org repo, then source is also required.
749 */
750 $plugins = array(
751
752 // Facebook Connect
753 array(
754 'name' => 'Nextend Facebook Connect',
755 'slug' => 'nextend-facebook-connect',
756 'required' => false,
757 'force_activation' => true,
758 'force_deactivation' => true
759 ),
760
761 // Twitter Connect
762 array(
763 'name' => 'Nextend Twitter Connect',
764 'slug' => 'nextend-twitter-connect',
765 'required' => false,
766 'force_activation' => true,
767 'force_deactivation' => true
768 ),
769
770 // Google Connect
771 array(
772 'name' => 'Nextend Google Connect',
773 'slug' => 'nextend-google-connect',
774 'required' => false,
775 'force_activation' => true,
776 'force_deactivation' => true
777 ),
778
779 // Layer SLider
780 array(
781 'name' => 'LayerSlider WP',
782 'slug' => 'LayerSlider',
783 'source' => get_stylesheet_directory() . '/inc/plugins/layersliderwp-5.0.2.installable.zip',
784 'required' => false,
785 'version' => '5.0.2',
786 'force_activation' => true,
787 'force_deactivation' => true
788 ),
789
790 // Ratings
791 array(
792 'name' => 'WP-PostRatings',
793 'slug' => 'wp-postratings',
794 'source' => get_stylesheet_directory() . '/inc/plugins/wp-postratings.zip',
795 'required' => false,
796 'version' => '1.77',
797 'force_activation' => true,
798 'force_deactivation' => true
799 ),
800
801 // WooCommerce
802 array(
803 'name' => 'WooCommerce',
804 'slug' => 'woocommerce',
805 'required' => false,
806 'force_activation' => true,
807 'force_deactivation' => true
808 ),
809
810 );
811
812 // Change this to your theme text domain, used for internationalising strings
813 $theme_text_domain = 'wpcrown';
814
815 /**
816 * Array of configuration settings. Amend each line as needed.
817 * If you want the default strings to be available under your own theme domain,
818 * leave the strings uncommented.
819 * Some of the strings are added into a sprintf, so see the comments at the
820 * end of each line for what each argument will be.
821 */
822 $config = array(
823 'domain' => $theme_text_domain, // Text domain - likely want to be the same as your theme.
824 'default_path' => '', // Default absolute path to pre-packaged plugins
825 'parent_menu_slug' => 'themes.php', // Default parent menu slug
826 'parent_url_slug' => 'themes.php', // Default parent URL slug
827 'menu' => 'install-required-plugins', // Menu slug
828 'has_notices' => true, // Show admin notices or not
829 'is_automatic' => false, // Automatically activate plugins after installation or not
830 'message' => '', // Message to output right before the plugins table
831 'strings' => array(
832 'page_title' => __( 'Install Required Plugins', $theme_text_domain ),
833 'menu_title' => __( 'Install Plugins', $theme_text_domain ),
834 'installing' => __( 'Installing Plugin: %s', $theme_text_domain ), // %1$s = plugin name
835 'oops' => __( 'Something went wrong with the plugin API.', $theme_text_domain ),
836 'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.' ), // %1$s = plugin name(s)
837 'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.' ), // %1$s = plugin name(s)
838 'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.' ), // %1$s = plugin name(s)
839 'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.' ), // %1$s = plugin name(s)
840 'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.' ), // %1$s = plugin name(s)
841 'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.' ), // %1$s = plugin name(s)
842 'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.' ), // %1$s = plugin name(s)
843 'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.' ), // %1$s = plugin name(s)
844 'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins' ),
845 'activate_link' => _n_noop( 'Activate installed plugin', 'Activate installed plugins' ),
846 'return' => __( 'Return to Required Plugins Installer', $theme_text_domain ),
847 'plugin_activated' => __( 'Plugin activated successfully.', $theme_text_domain ),
848 'complete' => __( 'All plugins installed and activated successfully. %s', $theme_text_domain ) // %1$s = dashboard link
849 )
850 );
851
852 tgmpa( $plugins, $config );
853
854}
855
856
857
858/**
859* Google analytic code
860*/
861function wpcrown_google_analityc_code() { ?>
862
863 <script type="text/javascript">
864
865 var _gaq = _gaq || [];
866 _gaq.push(['_setAccount', '<?php global $redux_demo; $google_id = $redux_demo['google_id']; echo $google_id; ?>']);
867 _gaq.push(['_setDomainName', 'none']);
868 _gaq.push(['_setAllowLinker', true]);
869 _gaq.push(['_trackPageview']);
870
871 (function() {
872 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
873 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
874 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
875 })();
876
877</script>
878
879<?php }
880
881
882
883/**
884 * Enqueues scripts and styles for front end.
885 *
886 * @since FlatAds 1.0
887 *
888 * @return void
889 */
890function FlatAds_scripts_styles() {
891 // Adds JavaScript to pages with the comment form to support sites with
892 // threaded comments (when in use).
893 if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
894 wp_enqueue_script( 'comment-reply' );
895
896 // Adds Masonry to handle vertical alignment of footer widgets.
897 if ( is_active_sidebar( 'sidebar-1' ) )
898 wp_enqueue_script( 'jquery-masonry' );
899
900 // Loads JavaScript file with functionality specific to FlatAds.
901 wp_enqueue_script( 'FlatAds-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '2013-07-18', true );
902
903 // Add Open Sans and Bitter fonts, used in the main stylesheet.
904 wp_enqueue_style( 'FlatAds-fonts', FlatAds_fonts_url(), array(), null );
905
906 // Add Genericons font, used in the main stylesheet.
907 wp_enqueue_style( 'genericons', get_template_directory_uri() . '/fonts/genericons.css', array(), '2.09' );
908
909 // Loads our main stylesheet.
910 wp_enqueue_style( 'FlatAds-style', get_stylesheet_uri(), array(), '2013-07-18' );
911
912 // Loads the Internet Explorer specific stylesheet.
913 wp_enqueue_style( 'FlatAds-ie', get_template_directory_uri() . '/css/ie.css', array( 'FlatAds-style' ), '2013-11-08' );
914 wp_style_add_data( 'FlatAds-ie', 'conditional', 'lt IE 9' );
915
916
917
918 // Custom scripts ans styles //
919 // Load custom script
920 wp_enqueue_script( 'FlatAds-menu-script', get_template_directory_uri() . '/js/menu.js', array( 'jquery' ), '2013-07-18', true );
921
922 // Load boostratp script
923 wp_enqueue_script( 'FlatAds-boostrat-script', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ), '2013-07-18', true );
924
925 // Load chosen script
926 wp_enqueue_script( 'FlatAds-chosen-script', get_template_directory_uri() . '/js/chosen.jquery.min.js', array( 'jquery' ), '2013-07-18', true );
927
928 // Load isotope script
929 wp_enqueue_script( 'FlatAds-isotope-script', get_template_directory_uri() . '/js/jquery.isotope.min.js', array( 'jquery' ), '2013-07-18', true );
930
931 // Load google maps js
932 wp_enqueue_script( 'FlatAds-google-maps-script', 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', array( 'jquery' ), '2013-07-18', true );
933
934 // Load google maps js
935 wp_enqueue_script( 'FlatAds-google-maps-script2', get_template_directory_uri() . '/js/gmap3.min.js', array( 'jquery' ), '2013-07-18', true );
936
937 // Load google maps js
938 wp_enqueue_script( 'FlatAds-google-maps-infobox', get_template_directory_uri() . '/js/gmap3.infobox.js', array( 'jquery' ), '2013-07-18', true );
939
940 // Load jQuery UI script
941 wp_enqueue_script( 'FlatAds-jquery-ui-script', '//code.jquery.com/ui/1.10.4/jquery-ui.js', array( 'jquery' ), '2013-07-18', true );
942
943 // Load jQuery tools forms script
944 wp_enqueue_script( 'FlatAds-jquery-tools-forms-script', get_template_directory_uri() . '/js/jquery.tools.min.js', array( 'jquery' ), '2013-07-18', true );
945
946
947 if( is_page_template('template-add-post.php') ) {
948 /* add javascript */
949 //wp_enqueue_script( 'FlatAds-google-custom-script', get_template_directory_uri() . '/js/getlocation-map-script.js', array( 'jquery' ), '2013-07-18', true );
950 }
951
952 // Load google maps js
953 wp_enqueue_script( 'FlatAds-modernizer', get_template_directory_uri() . '/js/modernizr.touch.js', array( 'jquery' ), '2013-07-18', true );
954
955 // Load google maps js
956 wp_enqueue_script( 'FlatAds-slider-mobile', get_template_directory_uri() . '/js/jquery.ui.touch-punch.min.js', array( 'jquery' ), '2013-07-18', true );
957
958
959 if( is_single() ) {
960 // Load flexslider
961 wp_enqueue_script( 'FlatAds-flexslider-script', get_template_directory_uri() . '/js/jquery.flexslider.js', array( 'jquery' ), '2013-07-18', true );
962
963 // Load gallery
964 wp_enqueue_script( 'FlatAds-gallery-script', get_template_directory_uri() . '/js/galleria-1.3.5.min.js', array( 'jquery' ), '2013-07-18', true );
965
966 // Load gallery
967 wp_enqueue_script( 'FlatAds-gallery-theme-script', get_template_directory_uri() . '/js/galleria.classic.min.js', array( 'jquery' ), '2013-07-18', true );
968 }
969
970 // Load custom script
971 wp_enqueue_script( 'FlatAds-custom-script', get_template_directory_uri() . '/js/custom.js', array( 'jquery' ), '2013-07-18', true );
972
973
974 // Load boostratp style
975 wp_enqueue_style( 'boostrat-style', get_template_directory_uri() . '/css/bootstrap.css', array(), '2.3.2' );
976
977 // Load boostratp style
978 wp_enqueue_style( 'awesomefont-style', '//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', array(), '4.1.0' );
979
980 // Load chosen list style
981 wp_enqueue_style( 'boostrat-chosen', get_template_directory_uri() . '/css/chosen.min.css', array(), '1' );
982
983 // Load flexslider style
984 wp_enqueue_style( 'flexslider-style', get_template_directory_uri() . '/css/flexslider.css', array(), '1' );
985
986 // Load custom style
987 wp_enqueue_style( 'main-style-custom', get_template_directory_uri() . '/css/custom.css', array(), '1' );
988
989 // Load boostratp responsive
990 wp_enqueue_style( 'boostrat-style-responsive', get_template_directory_uri() . '/css/bootstrap-responsive.css', array(), '2.3.2' );
991
992
993 if(is_admin_bar_showing()) echo "<style type=\"text/css\">.navbar-fixed-top { margin-top: 28px; } </style>";
994
995}
996
997function wpcrown_main_font() {
998 $protocol = is_ssl() ? 'https' : 'http';
999 wp_enqueue_style( 'mytheme-roboto', "$protocol://fonts.googleapis.com/css?family=Roboto:400,400italic,500,300,300italic,500italic,700,700italic" );
1000}
1001
1002function wpcrown_second_font_armata() {
1003 $protocol = is_ssl() ? 'https' : 'http';
1004 wp_enqueue_style( 'mytheme-armata', "$protocol://fonts.googleapis.com/css?family=Armata" );
1005}
1006
1007
1008// Post views
1009function wpb_set_post_views($postID) {
1010 $count_key = 'wpb_post_views_count';
1011 $count = get_post_meta($postID, $count_key, true);
1012 if($count==''){
1013 $count = 0;
1014 delete_post_meta($postID, $count_key);
1015 add_post_meta($postID, $count_key, '0');
1016 }else{
1017 $count++;
1018 update_post_meta($postID, $count_key, $count);
1019 }
1020}
1021//To keep the count accurate, lets get rid of prefetching
1022
1023
1024function wpb_track_post_views ($post_id) {
1025 if ( !is_single() ) return;
1026 if ( empty ( $post_id) ) {
1027 global $post;
1028 $post_id = $post->ID;
1029 }
1030 wpb_set_post_views($post_id);
1031}
1032
1033
1034function wpb_get_post_views($postID){
1035 $count_key = 'wpb_post_views_count';
1036 $count = get_post_meta($postID, $count_key, true);
1037 if($count==''){
1038 delete_post_meta($postID, $count_key);
1039 add_post_meta($postID, $count_key, '0');
1040 return "0";
1041 }
1042 return $count;
1043}
1044
1045
1046
1047
1048/**
1049 * Creates a nicely formatted and more specific title element text for output
1050 * in head of document, based on current view.
1051 *
1052 * @since FlatAds 1.0
1053 *
1054 * @param string $title Default title text for current view.
1055 * @param string $sep Optional separator.
1056 * @return string The filtered title.
1057 */
1058function FlatAds_wp_title( $title, $sep ) {
1059 global $paged, $page;
1060
1061 if ( is_feed() )
1062 return $title;
1063
1064 // Add the site name.
1065 $title .= get_bloginfo( 'name' );
1066
1067 // Add the site description for the home/front page.
1068 $site_description = get_bloginfo( 'description', 'display' );
1069 if ( $site_description && ( is_home() || is_front_page() ) )
1070 $title = "$title $sep $site_description";
1071
1072 // Add a page number if necessary.
1073 if ( $paged >= 2 || $page >= 2 )
1074 $title = "$title $sep " . sprintf( __( 'Page %s', 'agrg' ), max( $paged, $page ) );
1075
1076 return $title;
1077}
1078
1079
1080/**
1081 * Registers two widget areas.
1082 *
1083 * @since FlatAds 1.0
1084 *
1085 * @return void
1086 */
1087function FlatAds_widgets_init() {
1088 register_sidebar( array(
1089 'name' => __( 'Footer Widget Area One', 'agrg' ),
1090 'id' => 'footer-one',
1091 'description' => __( 'Appears in the footer section of the site.', 'agrg' ),
1092 'before_widget' => '<div class="span3 first">',
1093 'after_widget' => '</div></div>',
1094 'before_title' => '<h4 class="block-title">',
1095 'after_title' => '</h4><div class="block-content clearfix">',
1096 ) );
1097
1098 register_sidebar( array(
1099 'name' => __( 'Footer Widget Area Two', 'agrg' ),
1100 'id' => 'footer-two',
1101 'description' => __( 'Appears in the footer section of the site.', 'agrg' ),
1102 'before_widget' => '<div class="span3">',
1103 'after_widget' => '</div></div>',
1104 'before_title' => '<h4 class="block-title">',
1105 'after_title' => '</h4><div class="block-content clearfix">',
1106 ) );
1107
1108 register_sidebar( array(
1109 'name' => __( 'Footer Widget Area Three', 'agrg' ),
1110 'id' => 'footer-three',
1111 'description' => __( 'Appears in the footer section of the site.', 'agrg' ),
1112 'before_widget' => '<div class="span3">',
1113 'after_widget' => '</div></div>',
1114 'before_title' => '<h4 class="block-title">',
1115 'after_title' => '</h4><div class="block-content clearfix">',
1116 ) );
1117
1118 register_sidebar( array(
1119 'name' => __( 'Footer Widget Area Four', 'agrg' ),
1120 'id' => 'footer-four',
1121 'description' => __( 'Appears in the footer section of the site.', 'agrg' ),
1122 'before_widget' => '<div class="span3">',
1123 'after_widget' => '</div></div>',
1124 'before_title' => '<h4 class="block-title">',
1125 'after_title' => '</h4><div class="block-content clearfix">',
1126 ) );
1127
1128 register_sidebar( array(
1129 'name' => __( 'Pages Widget Area', 'agrg' ),
1130 'id' => 'pages',
1131 'description' => __( 'Appears on posts and pages in the sidebar.', 'agrg' ),
1132 'before_widget' => '<div class="cat-widget"><div class="cat-widget-content">',
1133 'after_widget' => '</div></div>',
1134 'before_title' => '<div class="cat-widget-title"><h4>',
1135 'after_title' => '</h4></div>',
1136 ) );
1137
1138 register_sidebar( array(
1139 'name' => __( 'Forum Widget Area', 'agrg' ),
1140 'id' => 'forum',
1141 'description' => __( 'Appears on posts and pages in the sidebar.', 'agrg' ),
1142 'before_widget' => '<div class="cat-widget"><div class="cat-widget-content">',
1143 'after_widget' => '</div></div>',
1144 'before_title' => '<div class="cat-widget-title"><h4>',
1145 'after_title' => '</h4></div>',
1146 ) );
1147
1148 register_sidebar( array(
1149 'name' => __( 'Shop Widget Area', 'agrg' ),
1150 'id' => 'shop',
1151 'description' => __( 'Appears on posts and pages in the sidebar.', 'agrg' ),
1152 'before_widget' => '<div class="cat-widget"><div class="cat-widget-content">',
1153 'after_widget' => '</div></div>',
1154 'before_title' => '<div class="cat-widget-title"><h4>',
1155 'after_title' => '</h4></div>',
1156 ) );
1157}
1158
1159if ( ! function_exists( 'FlatAds_paging_nav' ) ) :
1160/**
1161 * Displays navigation to next/previous set of posts when applicable.
1162 *
1163 * @since FlatAds 1.0
1164 *
1165 * @return void
1166 */
1167function FlatAds_paging_nav() {
1168 global $wp_query;
1169
1170 // Don't print empty markup if there's only one page.
1171 if ( $wp_query->max_num_pages < 2 )
1172 return;
1173 ?>
1174 <nav class="navigation paging-navigation" role="navigation">
1175 <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'agrg' ); ?></h1>
1176 <div class="nav-links">
1177
1178 <?php if ( get_next_posts_link() ) : ?>
1179 <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'agrg' ) ); ?></div>
1180 <?php endif; ?>
1181
1182 <?php if ( get_previous_posts_link() ) : ?>
1183 <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'agrg' ) ); ?></div>
1184 <?php endif; ?>
1185
1186 </div><!-- .nav-links -->
1187 </nav><!-- .navigation -->
1188 <?php
1189}
1190endif;
1191
1192if ( ! function_exists( 'FlatAds_post_nav' ) ) :
1193/**
1194 * Displays navigation to next/previous post when applicable.
1195*
1196* @since FlatAds 1.0
1197*
1198* @return void
1199*/
1200function FlatAds_post_nav() {
1201 global $post;
1202
1203 // Don't print empty markup if there's nowhere to navigate.
1204 $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
1205 $next = get_adjacent_post( false, '', false );
1206
1207 if ( ! $next && ! $previous )
1208 return;
1209 ?>
1210 <nav class="navigation post-navigation" role="navigation">
1211 <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'agrg' ); ?></h1>
1212 <div class="nav-links">
1213
1214 <?php previous_post_link( '%link', _x( '<span class="meta-nav">←</span> %title', 'Previous post link', 'agrg' ) ); ?>
1215 <?php next_post_link( '%link', _x( '%title <span class="meta-nav">→</span>', 'Next post link', 'agrg' ) ); ?>
1216
1217 </div><!-- .nav-links -->
1218 </nav><!-- .navigation -->
1219 <?php
1220}
1221endif;
1222
1223if ( ! function_exists( 'FlatAds_entry_meta' ) ) :
1224/**
1225 * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
1226 *
1227 * Create your own FlatAds_entry_meta() to override in a child theme.
1228 *
1229 * @since FlatAds 1.0
1230 *
1231 * @return void
1232 */
1233function FlatAds_entry_meta() {
1234 if ( is_sticky() && is_home() && ! is_paged() )
1235 echo '<span class="featured-post">' . __( 'Sticky', 'agrg' ) . '</span>';
1236
1237 if ( ! has_post_format( 'link' ) && 'post' == get_post_type() )
1238 FlatAds_entry_date();
1239
1240 // Translators: used between list items, there is a space after the comma.
1241 $categories_list = get_the_category_list( __( ', ', 'agrg' ) );
1242 if ( $categories_list ) {
1243 echo '<span class="categories-links">' . $categories_list . '</span>';
1244 }
1245
1246 // Translators: used between list items, there is a space after the comma.
1247 $tag_list = get_the_tag_list( '', __( ', ', 'agrg' ) );
1248 if ( $tag_list ) {
1249 echo '<span class="tags-links">' . $tag_list . '</span>';
1250 }
1251
1252 // Post author
1253 if ( 'post' == get_post_type() ) {
1254 printf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
1255 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
1256 esc_attr( sprintf( __( 'View all posts by %s', 'agrg' ), get_the_author() ) ),
1257 get_the_author()
1258 );
1259 }
1260}
1261endif;
1262
1263if ( ! function_exists( 'FlatAds_entry_date' ) ) :
1264/**
1265 * Prints HTML with date information for current post.
1266 *
1267 * Create your own FlatAds_entry_date() to override in a child theme.
1268 *
1269 * @since FlatAds 1.0
1270 *
1271 * @param boolean $echo Whether to echo the date. Default true.
1272 * @return string The HTML-formatted post date.
1273 */
1274function FlatAds_entry_date( $echo = true ) {
1275 if ( has_post_format( array( 'chat', 'status' ) ) )
1276 $format_prefix = _x( '%1$s on %2$s', '1: post format name. 2: date', 'agrg' );
1277 else
1278 $format_prefix = '%2$s';
1279
1280 $date = sprintf( '<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span>',
1281 esc_url( get_permalink() ),
1282 esc_attr( sprintf( __( 'Permalink to %s', 'agrg' ), the_title_attribute( 'echo=0' ) ) ),
1283 esc_attr( get_the_date( 'c' ) ),
1284 esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
1285 );
1286
1287 if ( $echo )
1288 echo $date;
1289
1290 return $date;
1291}
1292endif;
1293
1294if ( ! function_exists( 'FlatAds_the_attached_image' ) ) :
1295/**
1296 * Prints the attached image with a link to the next attached image.
1297 *
1298 * @since FlatAds 1.0
1299 *
1300 * @return void
1301 */
1302function FlatAds_the_attached_image() {
1303 $post = get_post();
1304 $attachment_size = apply_filters( 'FlatAds_attachment_size', array( 724, 724 ) );
1305 $next_attachment_url = wp_get_attachment_url();
1306
1307 /**
1308 * Grab the IDs of all the image attachments in a gallery so we can get the URL
1309 * of the next adjacent image in a gallery, or the first image (if we're
1310 * looking at the last image in a gallery), or, in a gallery of one, just the
1311 * link to that image file.
1312 */
1313 $attachment_ids = get_posts( array(
1314 'post_parent' => $post->post_parent,
1315 'fields' => 'ids',
1316 'numberposts' => -1,
1317 'post_status' => 'inherit',
1318 'post_type' => 'attachment',
1319 'post_mime_type' => 'image',
1320 'order' => 'ASC',
1321 'orderby' => 'menu_order ID'
1322 ) );
1323
1324 // If there is more than 1 attachment in a gallery...
1325 if ( count( $attachment_ids ) > 1 ) {
1326 foreach ( $attachment_ids as $attachment_id ) {
1327 if ( $attachment_id == $post->ID ) {
1328 $next_id = current( $attachment_ids );
1329 break;
1330 }
1331 }
1332
1333 // get the URL of the next image attachment...
1334 if ( $next_id )
1335 $next_attachment_url = get_attachment_link( $next_id );
1336
1337 // or get the URL of the first image attachment.
1338 else
1339 $next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) );
1340 }
1341
1342 printf( '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>',
1343 esc_url( $next_attachment_url ),
1344 the_title_attribute( array( 'echo' => false ) ),
1345 wp_get_attachment_image( $post->ID, $attachment_size )
1346 );
1347}
1348endif;
1349
1350/**
1351 * Returns the URL from the post.
1352 *
1353 * @uses get_url_in_content() to get the URL in the post meta (if it exists) or
1354 * the first link found in the post content.
1355 *
1356 * Falls back to the post permalink if no URL is found in the post.
1357 *
1358 * @since FlatAds 1.0
1359 *
1360 * @return string The Link format URL.
1361 */
1362function FlatAds_get_link_url() {
1363 $content = get_the_content();
1364 $has_url = get_url_in_content( $content );
1365
1366 return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
1367}
1368
1369/**
1370 * Extends the default WordPress body classes.
1371 *
1372 * Adds body classes to denote:
1373 * 1. Single or multiple authors.
1374 * 2. Active widgets in the sidebar to change the layout and spacing.
1375 * 3. When avatars are disabled in discussion settings.
1376 *
1377 * @since FlatAds 1.0
1378 *
1379 * @param array $classes A list of existing body class values.
1380 * @return array The filtered body class list.
1381 */
1382function FlatAds_body_class( $classes ) {
1383 if ( ! is_multi_author() )
1384 $classes[] = 'single-author';
1385
1386 if ( is_active_sidebar( 'sidebar-2' ) && ! is_attachment() && ! is_404() )
1387 $classes[] = 'sidebar';
1388
1389 if ( ! get_option( 'show_avatars' ) )
1390 $classes[] = 'no-avatars';
1391
1392 return $classes;
1393}
1394
1395
1396/**
1397 * Adjusts content_width value for video post formats and attachment templates.
1398 *
1399 * @since FlatAds 1.0
1400 *
1401 * @return void
1402 */
1403function FlatAds_content_width() {
1404 global $content_width;
1405
1406 if ( is_attachment() )
1407 $content_width = 724;
1408 elseif ( has_post_format( 'audio' ) )
1409 $content_width = 484;
1410}
1411
1412/**
1413 * Add postMessage support for site title and description for the Customizer.
1414 *
1415 * @since FlatAds 1.0
1416 *
1417 * @param WP_Customize_Manager $wp_customize Customizer object.
1418 * @return void
1419 */
1420function FlatAds_customize_register( $wp_customize ) {
1421 $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
1422 $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
1423 $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
1424}
1425
1426
1427/**
1428 * Binds JavaScript handlers to make Customizer preview reload changes
1429 * asynchronously.
1430 *
1431 * @since FlatAds 1.0
1432 */
1433function FlatAds_customize_preview_js() {
1434 wp_enqueue_script( 'FlatAds-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20130226', true );
1435}
1436
1437// Add Redux Framework
1438if ( !class_exists( 'ReduxFramework' ) && file_exists( dirname( __FILE__ ) . '/ReduxFramework/ReduxCore/framework.php' ) ) {
1439 require_once( dirname( __FILE__ ) . '/ReduxFramework/ReduxCore/framework.php' );
1440}
1441if ( !isset( $redux_demo ) && file_exists( dirname( __FILE__ ) . '/ReduxFramework/sample/sample-config.php' ) ) {
1442 require_once( dirname( __FILE__ ) . '/ReduxFramework/sample/sample-config.php' );
1443}
1444
1445/*---------------------------------------------------
1446register categories custom fields page
1447----------------------------------------------------*/
1448function theme_settings_init(){
1449 register_setting( 'theme_settings', 'theme_settings' );
1450 wp_enqueue_style("panel_style", get_template_directory_uri()."/css/categories-custom-fields.css", false, "1.0", "all");
1451 wp_enqueue_script("panel_script", get_template_directory_uri()."/js/categories-custom-fields-script.js", false, "1.0");
1452}
1453
1454/*---------------------------------------------------
1455add categories custom fields page to menu
1456----------------------------------------------------*/
1457function add_settings_page() {
1458 add_menu_page( __( 'Categories Custom Fields' ), __( 'Categories Custom Fields' ), 'manage_options', 'settings', 'theme_settings_page');
1459}
1460
1461/*---------------------------------------------------
1462add actions
1463----------------------------------------------------*/
1464add_action( 'admin_init', 'theme_settings_init' );
1465add_action( 'admin_menu', 'add_settings_page' );
1466
1467/*---------------------------------------------------
1468Theme Panel Output
1469----------------------------------------------------*/
1470function theme_settings_page() {
1471 global $themename,$theme_options;
1472
1473 $i = 0;
1474 $message = '';
1475
1476 if ( 'savecat' == $_REQUEST['action'] ) {
1477
1478 $args = array(
1479 'orderby' => 'name',
1480 'order' => 'ASC'
1481 );
1482 $categories = get_categories($args);
1483 foreach($categories as $category) {
1484 $user_id = $category->term_id;
1485 $tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
1486 $tag_extra_fields[$user_id]['category_custom_fields'] = $_POST['wpcrown_category_custom_field_option_'.$user_id];
1487 update_option(MY_CATEGORY_FIELDS, $tag_extra_fields);
1488 }
1489 $message='saved';
1490 }
1491
1492 ?>
1493
1494 <div class="wrap">
1495 <div id="icon-options-general"></div>
1496 <h2><?php _e('Categories Custom Fields', 'agrg') ?></h2>
1497 <?php
1498 if ( $message == 'saved' ) echo '<div class="updated settings-error" id="setting-error-settings_updated">
1499 <p>Custom Fields saved.</strong></p></div>';
1500 ?>
1501 </div>
1502
1503 <form method="post">
1504
1505 <div class="wrap">
1506 <h3><?php _e('Select category:', 'agrg') ?></h3>
1507
1508 <select id="select-author">
1509 <?php
1510
1511 $cat_args = array ( 'parent' => 0 ) ;
1512 $parentcategories = get_terms ( "category", $cat_args ) ;
1513 $no_of_categories = count ( $parentcategories ) ;
1514
1515 if ( $no_of_categories > 0 ) {
1516
1517 foreach ( $parentcategories as $parentcategory ) {
1518
1519 echo '<option value=' . $parentcategory->term_id . '>' . $parentcategory->name . '</option>';
1520
1521 $parent_id = $parentcategory ->term_id;
1522 $subcategories = get_terms ( 'category', array ( 'child_of' => $parent_id, 'hide_empty' => false ) ) ;
1523
1524 foreach ( $subcategories as $subcategory ) {
1525
1526 $args = array (
1527 'post-type'=> 'questions',
1528 'orderby'=> 'title',
1529 'order'=> 'ASC',
1530 'post_per_page'=> -1,
1531 'nopaging'=> 'true',
1532 'taxonomy_name'=> $subcategory->name
1533 );
1534
1535 echo '<option value=' . $subcategory->term_id . '> - ' . $subcategory->name . '</option>';
1536
1537 }
1538 }
1539 }
1540 ?>
1541 </select>
1542 </div>
1543
1544 <div class="wrap">
1545 <?php
1546 $args = array(
1547 'hide_empty' => false,
1548 'orderby' => count,
1549 'order' => 'ASC'
1550 );
1551
1552 $inum = 0;
1553
1554 $categories = get_categories($args);
1555 foreach($categories as $category) {;
1556
1557 $inum++;
1558
1559 $user_name = $category->name;
1560 $user_id = $category->term_id;
1561
1562
1563 $tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
1564 $wpcrown_category_custom_field_option = $tag_extra_fields[$user_id]['category_custom_fields'];
1565 ?>
1566
1567 <div id="author-<?php echo $user_id; ?>" class="wrap-content" <?php if($inum == 1) { ?>style="display: block;"<?php } else { ?>style="display: none;"<?php } ?>>
1568
1569 <h4><?php _e('Add Custom Fields to: ', 'agrg') ?><?php echo $user_name; ?></h4>
1570
1571 <div id="badge_criteria_<?php echo $user_id; ?>">
1572 <?php
1573 for ($i = 0; $i < (count($wpcrown_category_custom_field_option)); $i++) {
1574 ?>
1575
1576 <div class="badge_item" id="<?php echo $i; ?>">
1577
1578 <span class='full' style="margin-bottom: 10px;">
1579
1580 <span class="text ingredient-title"><?php _e( 'Custom field title', 'agrg' ); ?></span>
1581 <input type='text' id='wpcrown_category_custom_field_option_<?php echo $user_id ?>[<?php echo $i; ?>][0]' name='wpcrown_category_custom_field_option_<?php echo $user_id ?>[<?php echo $i; ?>][0]' value='<?php if (!empty($wpcrown_category_custom_field_option[$i][0])) echo $wpcrown_category_custom_field_option[$i][0]; ?>' class='badge_name'>
1582
1583 </span>
1584
1585 <button name="button_del_badge" type="button" class="button-secondary button_del_badge_<?php echo $user_id; ?>">Delete</button>
1586
1587
1588 </div>
1589
1590 <?php
1591 }
1592 ?>
1593
1594
1595 </div>
1596
1597 <div id="template_badge_criterion_<?php echo $user_id; ?>" style="display: none;">
1598
1599 <div class="badge_item" id="999">
1600
1601 <span class='full' style="margin-bottom: 10px;">
1602
1603 <span class="text ingredient-title"><?php _e( 'Custom field title', 'agrg' ); ?></span>
1604 <input type='text' id='' name='' value='' class='badge_name'>
1605
1606 </span>
1607
1608 <button name="button_del_badge" type="button" class="button-secondary button_del_badge_<?php echo $user_id; ?>">Delete</button>
1609
1610 </div>
1611
1612 </div>
1613
1614 <fieldset class="input-full-width">
1615
1616 <p>All custom fields are text input type.</p>
1617
1618 <button type="button" name="submit_add_badge" id='submit_add_badge_<?php echo $user_id; ?>' value="add" class="button-secondary">Add new custom field</button>
1619
1620 </fieldset>
1621
1622 <span class="submit"><input name="save<?php echo $user_id; ?>" type="submit" class="button-primary" value="Save changes" /></span>
1623
1624 <script>
1625
1626 // Add Badge
1627 jQuery('#template_badge_criterion_<?php echo $user_id; ?>').hide();
1628 jQuery('#submit_add_badge_<?php echo $user_id; ?>').on('click', function() {
1629 $newItem = jQuery('#template_badge_criterion_<?php echo $user_id; ?> .badge_item').clone().appendTo('#badge_criteria_<?php echo $user_id; ?>').show();
1630 if ($newItem.prev('.badge_item').size() == 1) {
1631 var id = parseInt($newItem.prev('.badge_item').attr('id')) + 1;
1632 } else {
1633 var id = 0;
1634 }
1635 $newItem.attr('id', id);
1636
1637 var nameText = 'wpcrown_category_custom_field_option_<?php echo $user_id; ?>[' + id + '][0]';
1638 $newItem.find('.badge_name').attr('id', nameText).attr('name', nameText);
1639
1640 //event handler for newly created element
1641 $newItem.children('.button_del_badge_<?php echo $user_id; ?>').on('click', function () {
1642 jQuery(this).parent('.badge_item').remove();
1643 });
1644
1645 });
1646
1647 // Delete Ingredient
1648 jQuery('.button_del_badge_<?php echo $user_id; ?>').on('click', function() {
1649 jQuery(this).parent('.badge_item').remove();
1650 });
1651
1652 </script>
1653
1654 </div>
1655
1656 <?php } ?>
1657 </div>
1658
1659 <input type="hidden" name="action" value="savecat" />
1660 </form>
1661
1662 <?php
1663}