-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
805 lines (700 loc) · 29.4 KB
/
Copy pathfunctions.php
File metadata and controls
805 lines (700 loc) · 29.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
<?php
/**
* @package Oxygen
* @subpackage Functions
* @version 0.5.7
* @author AlienWP
* @author Justin Tadlock <justin@justintadlock.com>
* @link http://alienwp.com
* @link http://justintadlock.com
* @license http://www.gnu.org/licenses/gpl-2.0.html
*/
/* Load the core theme framework. */
require_once( trailingslashit( get_template_directory() ) . 'library/hybrid.php' );
$theme = new Hybrid();
/* Do theme setup on the 'after_setup_theme' hook. */
add_action( 'after_setup_theme', 'oxygen_theme_setup' );
/**
* Theme setup function. This function adds support for theme features and defines the default theme
* actions and filters.
*
*/
function oxygen_theme_setup() {
/* Admin functionality */
// if ( is_admin() ) {
// // Add Theme Documentation Page
// require_once( get_template_directory() . '/admin/getting-started/getting-started.php' );
// }
/* Get action/filter hook prefix. */
$prefix = hybrid_get_prefix();
/* Add theme support for core framework features. */
add_theme_support( 'hybrid-core-styles', array( 'style' ) );
add_theme_support( 'hybrid-core-menus', array( 'primary', 'secondary', 'subsidiary' ) );
add_theme_support( 'hybrid-core-sidebars', array( 'primary', 'secondary', 'subsidiary', 'after-singular', 'header' ) );
add_theme_support( 'hybrid-core-theme-settings', array( 'footer', 'about' ) );
add_theme_support( 'hybrid-core-meta-box-footer' );
add_theme_support( 'hybrid-core-shortcodes' );
add_theme_support( 'hybrid-core-template-hierarchy' );
/* Add theme support for framework extensions. */
add_theme_support( 'loop-pagination' );
add_theme_support( 'get-the-image' );
add_theme_support( 'cleaner-gallery' );
add_theme_support( 'breadcrumb-trail' );
add_theme_support( 'hybrid-core-scripts', array( 'comment-reply', 'drop-downs' ) );
/* Add theme support for WordPress features. */
add_theme_support( 'automatic-feed-links' );
/* Embed width/height defaults. */
add_filter( 'embed_defaults', 'oxygen_embed_defaults' );
/* Filter the sidebar widgets. */
add_filter( 'sidebars_widgets', 'oxygen_disable_sidebars' );
/* Image sizes */
add_action( 'init', 'oxygen_image_sizes' );
/* Excerpt ending */
add_filter( 'excerpt_more', 'oxygen_excerpt_more' );
/* Custom excerpt length */
add_filter( 'excerpt_length', 'oxygen_excerpt_length' );
/* Filter the pagination trail arguments. */
add_filter( 'loop_pagination_args', 'oxygen_pagination_args' );
/* Filter the comments arguments */
add_filter( "{$prefix}_list_comments_args", 'oxygen_comments_args' );
/* Filter the commentform arguments */
add_filter( 'comment_form_defaults', 'oxygen_commentform_args', 11, 1 );
/* Enqueue scripts (and related stylesheets) */
add_action( 'wp_enqueue_scripts', 'oxygen_scripts' );
/* Add the breadcrumb trail just after the container is open. */
add_action( "{$prefix}_open_content", 'breadcrumb_trail' );
/* Breadcrumb trail arguments. */
add_filter( 'breadcrumb_trail_args', 'oxygen_breadcrumb_trail_args' );
/* Add support for custom headers. */
$args = array(
'width' => 400,
'height' => 100,
'flex-height' => true,
'flex-width' => true,
'header-text' => false,
'uploads' => true,
);
add_theme_support( 'custom-header', $args );
/* Add support for custom backgrounds */
add_theme_support( 'custom-background' );
/* Add theme settings to the customizer. */
require_once( trailingslashit( get_template_directory() ) . 'admin/customize.php' );
/* Add support for Title Tag */
add_theme_support( 'title-tag' );
/* Metaboxes */
add_action( 'add_meta_boxes', 'oxygen_create_metabox' );
add_action( 'save_post', 'oxygen_save_meta', 1, 2 );
/**
* Disqus plugin: use higher priority.
* URL: http://themehybrid.com/support/topic/weird-problem-wit-disqus-plugin
*/
if( function_exists( 'dsq_comments_template' ) ) :
remove_filter( 'comments_template', 'dsq_comments_template' );
add_filter( 'comments_template', 'dsq_comments_template', 11 );
endif;
/* Remove the "Theme Settings" submenu. */
add_action( 'admin_menu', 'oxygen_remove_theme_settings_submenu', 11 );
}
/**
* Disables sidebars if viewing a one-column page.
*
*/
function oxygen_disable_sidebars( $sidebars_widgets ) {
global $wp_query;
if ( is_page_template( 'page-template-fullwidth.php' ) ) {
$sidebars_widgets['primary'] = false;
$sidebars_widgets['secondary'] = false;
}
return $sidebars_widgets;
}
/**
* Overwrites the default widths for embeds. This is especially useful for making sure videos properly
* expand the full width on video pages. This function overwrites what the $content_width variable handles
* with context-based widths.
*
*/
function oxygen_embed_defaults( $args ) {
$args['width'] = 470;
if ( is_page_template( 'page-template-fullwidth.php' ) )
$args['width'] = 940;
return $args;
}
/**
* Excerpt ending
*
*/
function oxygen_excerpt_more( $more ) {
return '...';
}
/**
* Custom excerpt lengths
*
*/
function oxygen_excerpt_length( $length ) {
return 25;
}
/**
* Enqueue scripts (and related stylesheets)
*
*/
function oxygen_scripts() {
if ( !is_admin() ) {
/* Enqueue Scripts */
wp_enqueue_script( 'oxygen_jquery', get_template_directory_uri() . '/libs/jquery-3.2.1.min.js', true );
wp_enqueue_script( 'oxygen_imagesloaded', get_template_directory_uri() . '/js/jquery.imagesloaded.js', array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'oxygen_masonry', get_template_directory_uri() . '/js/jquery.masonry.min.js', array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'oxygen_cycle', get_template_directory_uri() . '/libs/owl-carousel-2/owl.carousel.min.js', array( 'jquery' ), '3.0', true );
wp_enqueue_script( 'oxygen_fitvids', get_template_directory_uri() . '/js/fitvids/jquery.fitvids.js', array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'oxygen_navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20130301', true );
wp_enqueue_script( 'oxygen_footer_scripts', get_template_directory_uri() . '/js/footer-scripts.js', array( 'jquery', 'oxygen_imagesloaded', 'oxygen_masonry', 'oxygen_cycle', 'oxygen_fancybox', 'oxygen_fitvids' ), '1.0', true );
/* Enqueue Fancybox if enabled. */
if ( get_theme_mod( 'oxygen_fancybox_enable' ) ) {
wp_enqueue_script( 'oxygen_fancybox', get_template_directory_uri() . '/js/fancybox/jquery.fancybox-1.3.4.pack.js', array( 'jquery' ), '1.0', true );
wp_enqueue_style( 'fancybox-stylesheet', get_template_directory_uri() . '/js/fancybox/jquery.fancybox-1.3.4.css', false, 1.0, 'screen' );
wp_enqueue_script( 'oxygen_footer_scripts', get_template_directory_uri() . '/js/footer-scripts.js', array( 'jquery', 'oxygen_imagesloaded', 'oxygen_masonry', 'oxygen_cycle', 'oxygen_fancybox', 'oxygen_fitvids' ), '1.0', true );
} else {
wp_enqueue_script( 'oxygen_footer_scripts_light', get_template_directory_uri() . '/js/footer-scripts-light.js', array( 'jquery', 'oxygen_imagesloaded', 'oxygen_masonry', 'oxygen_cycle', 'oxygen_fitvids' ), '1.0', true );
}
}
}
/**
* Pagination args
*
*/
function oxygen_pagination_args( $args ) {
$args['prev_text'] = __( '← Previous', 'oxygen' );
$args['next_text'] = __( 'Next →', 'oxygen' );
return $args;
}
/**
* Image sizes
*
*/
function oxygen_image_sizes() {
add_image_size( 'archive-thumbnail', 470, 140, true );
add_image_size( 'single-thumbnail', 470, 260, true );
add_image_size( 'featured-thumbnail', 750, 380, true );
add_image_size( 'slider-nav-thumbnail', 110, 70, true );
}
/**
* Unregister Hybrid widgets
*
*/
function oxygen_unregister_widgets() {
unregister_widget( 'Hybrid_Widget_Search' );
register_widget( 'WP_Widget_Search' );
}
/**
* Custom comments arguments
*
*/
function oxygen_comments_args( $args ) {
$args['avatar_size'] = 40;
return $args;
}
/**
* Custom comment form arguments
*
*/
function oxygen_commentform_args( $args ) {
global $user_identity;
/* Get the current commenter. */
$commenter = wp_get_current_commenter();
/* Create the required <span> and <input> element class. */
$req = ( ( get_option( 'require_name_email' ) ) ? ' <span class="required">' . __( '*', 'oxygen' ) . '</span> ' : '' );
$input_class = ( ( get_option( 'require_name_email' ) ) ? ' req' : '' );
$fields = array(
'author' => '<p class="form-author' . $input_class . '"><input type="text" class="text-input" name="author" id="author" value="' . esc_attr( $commenter['comment_author'] ) . '" size="40" /><label for="author">' . __( 'Name', 'oxygen' ) . $req . '</label></p>',
'email' => '<p class="form-email' . $input_class . '"><input type="text" class="text-input" name="email" id="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="40" /><label for="email">' . __( 'Email', 'oxygen' ) . $req . '</label></p>',
'url' => '<p class="form-url"><input type="text" class="text-input" name="url" id="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="40" /><label for="url">' . __( 'Website', 'oxygen' ) . '</label></p>'
);
$args = array(
'fields' => apply_filters( 'comment_form_default_fields', $fields ),
'comment_field' => '<p class="form-textarea req"><!--<label for="comment">' . __( 'Comment', 'oxygen' ) . '</label>--><textarea name="comment" id="comment" cols="60" rows="10"></textarea></p>',
'must_log_in' => '<p class="alert">' . sprintf( __( 'You must be <a href="%1$s" title="Log in">logged in</a> to post a comment.', 'oxygen' ), wp_login_url( get_permalink() ) ) . '</p><!-- .alert -->',
'logged_in_as' => '<p class="log-in-out">' . sprintf( __( 'Logged in as <a href="%1$s" title="%2$s">%2$s</a>.', 'oxygen' ), admin_url( 'profile.php' ), esc_attr( $user_identity ) ) . ' <a href="' . wp_logout_url( get_permalink() ) . '" title="' . esc_attr__( 'Log out of this account', 'oxygen' ) . '">' . __( 'Log out →', 'oxygen' ) . '</a></p><!-- .log-in-out -->',
'comment_notes_before' => '',
'comment_notes_after' => '',
'id_form' => 'commentform',
'id_submit' => 'submit',
'title_reply' => __( 'Leave a Reply', 'oxygen' ),
'title_reply_to' => __( 'Leave a Reply to %s', 'oxygen' ),
'cancel_reply_link' => __( 'Click here to cancel reply.', 'oxygen' ),
'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',
'submit_field' => '<p class="form-submit">%1$s %2$s</p>',
'label_submit' => __( 'Post Comment →', 'oxygen' ),
);
return $args;
}
/**
* Breadcrumb trail arguments.
*
*/
function oxygen_breadcrumb_trail_args( $args ) {
$args['before'] = '';
$args['separator'] = ' / ';
$args['front_page'] = false;
return $args;
}
/**
* Metaboxes
*
*/
function oxygen_create_metabox() {
add_meta_box( 'oxygen_metabox', __( 'Location', 'oxygen' ), 'oxygen_metabox', ['post', 'oxygen_gallery'], 'advanced', 'default' );
}
function oxygen_metabox() {
global $post;
/* Retrieve metadata values if they already exist. */
$oxygen_post_location = get_post_meta( $post->ID, '_oxygen_post_location', true ); ?>
<p><label><input type="radio" name="oxygen_post_location" value="slider" <?php echo esc_attr( $oxygen_post_location ) == 'slider' ? 'checked="checked"' : '' ?> /> <?php echo __( 'Slider', 'oxygen' ) ?></label></p>
<p><label><input type="radio" name="oxygen_post_location" value="gallery" <?php echo esc_attr( $oxygen_post_location ) == 'gallery' ? 'checked="checked"' : '' ?> /> <?php echo __( 'Gallery', 'oxygen' ) ?></label></p>
<p><label><input type="radio" name="oxygen_post_location" value="standard" <?php echo esc_attr( $oxygen_post_location ) == 'standard' ? 'checked="checked"' : '' ?> /> <?php echo __( 'Standard', 'oxygen' ) ?></label></p>
<p><label><input type="radio" name="oxygen_post_location" value="primary" <?php echo esc_attr( $oxygen_post_location ) == 'primary' ? 'checked="checked"' : '' ?> /> <?php echo __( 'Primary', 'oxygen' ) ?></label></p>
<p><label><input type="radio" name="oxygen_post_location" value="secondary" <?php echo esc_attr( $oxygen_post_location ) == 'secondary' ? 'checked="checked"' : '' ?> /> <?php echo __( 'Secondary', 'oxygen' ) ?></label></p>
<p><label><input type="radio" name="oxygen_post_location" value="no-display" <?php echo esc_attr( $oxygen_post_location ) == 'no-display' ? 'checked="checked"' : '' ?> /> <?php echo __( 'Do not display', 'oxygen' ) ?></label></p>
<span class="description"><?php _e( 'Post location on the home page', 'oxygen' ); ?>
<?php
}
/* Save post metadata. */
function oxygen_save_meta( $post_id, $post ) {
if ( isset( $_POST['oxygen_post_location'] ) ) {
update_post_meta( $post_id, '_oxygen_post_location', strip_tags( $_POST['oxygen_post_location'] ) );
}
}
/**
* Oxygen site title.
*
*/
function oxygen_site_title() {
$tag = ( is_front_page() ) ? 'h1' : 'div';
if ( get_header_image() ) {
echo '<' . $tag . ' id="site-title">' . "\n";
echo '<a href="' . get_home_url() . '" title="' . get_bloginfo( 'name' ) . '" rel="Home">' . "\n";
echo '<img class="logo" src="' . get_header_image() . '" alt="' . get_bloginfo( 'name' ) . '" />' . "\n";
echo '</a>' . "\n";
echo '</' . $tag . '>' . "\n";
} elseif ( hybrid_get_setting( 'oxygen_logo_url' ) ) { // check for legacy setting
echo '<' . $tag . ' id="site-title">' . "\n";
echo '<a href="' . get_home_url() . '" title="' . get_bloginfo( 'name' ) . '" rel="Home">' . "\n";
echo '<img class="logo" src="' . esc_url( hybrid_get_setting( 'oxygen_logo_url' ) ) . '" alt="' . get_bloginfo( 'name' ) . '" />' . "\n";
echo '</a>' . "\n";
echo '</' . $tag . '>' . "\n";
} else {
hybrid_site_title();
}
}
/**
* Remove the "Theme Settings" submenu.
*
*/
function oxygen_remove_theme_settings_submenu() {
/* Remove the Theme Settings settings page. */
remove_submenu_page( 'themes.php', 'theme-settings' );
}
// register custom post type 'add_gallery_post_type'
add_action( 'init', 'add_gallery_post_type' );
function add_gallery_post_type() {
register_post_type( 'oxygen_gallery',
array(
'labels' => array(
'name' => __( 'Gallery' ),
'singular_name' => __( 'Gallery' ),
'all_items' => __( 'All Images' ),
),
'public' => true,
'menu_icon' => 'dashicons-images-alt',
'has_archive' => false,
'exclude_from_search' => true,
'rewrite' => array('slug' => 'gallery-item'),
'supports' => array( 'title', 'thumbnail' ),
'menu_position' => 4,
'show_in_admin_bar' => false,
'show_in_nav_menus' => false,
'publicly_queryable' => false,
'query_var' => false
)
);
}
function oxygen_get_backend_preview_thumb($post_ID) {
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
if ($post_thumbnail_id) {
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'thumbnail');
return $post_thumbnail_img[0];
}
}
function oxygen_preview_thumb_column_head($defaults) {
$defaults['featured_image'] = __( 'Image' );
return $defaults;
}
add_filter('manage_oxygen_gallery_posts_columns', 'oxygen_preview_thumb_column_head');
function oxygen_preview_thumb_column($column_name, $post_ID) {
if ($column_name == 'featured_image') {
$post_featured_image = oxygen_get_backend_preview_thumb($post_ID);
if ($post_featured_image) {
echo '<img src="' . $post_featured_image . '" />';
}
}
}
add_action('manage_posts_custom_column', 'oxygen_preview_thumb_column', 10, 2);
add_action( 'init', 'wp_add_gallery_cats' );
function wp_add_gallery_cats()
{
register_taxonomy_for_object_type( 'category', 'oxygen_gallery' );
}
add_action('do_meta_boxes', 'oxygen_move_meta_box');
function oxygen_move_meta_box(){
remove_meta_box( 'postimagediv', 'oxygen_gallery', 'side' );
add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', 'oxygen_gallery', 'normal', 'high');
}
class oxygenMetaBox {
function __construct($options) {
$this->options = $options;
$this->prefix = $this->options['id'] .'_';
add_action( 'add_meta_boxes', array( &$this, 'create' ) );
add_action( 'save_post', array( &$this, 'save' ), 1, 2 );
}
function create() {
foreach ($this->options['post'] as $post_type) {
if (current_user_can( $this->options['cap'])) {
add_meta_box($this->options['id'], $this->options['name'], array(&$this, 'fill'), $post_type, $this->options['pos'], $this->options['pri']);
}
}
}
function fill(){
global $post; $p_i_d = $post->ID;
wp_nonce_field( $this->options['id'], $this->options['id'].'_wpnonce', false, true );
?>
<table class="form-table"><tbody><?php
foreach ( $this->options['args'] as $param ) {
if (current_user_can( $param['cap'])) {
?><tr><?php
if(!$value = get_post_meta($post->ID, $this->prefix .$param['id'] , true)) $value = $param['std'];
switch ( $param['type'] ) {
case 'text':{ ?>
<th scope="row"><label for="<?php echo $this->prefix .$param['id'] ?>"><?php echo $param['title'] ?></label></th>
<td>
<input name="<?php echo $this->prefix .$param['id'] ?>" type="<?php echo $param['type'] ?>" id="<?php echo $this->prefix .$param['id'] ?>" value="<?php echo $value ?>" placeholder="<?php echo $param['placeholder'] ?>" class="regular-text" /><br />
<span class="description"><?php echo $param['desc'] ?></span>
</td>
<?php
break;
}
case 'textarea':{ ?>
<th scope="row"><label for="<?php echo $this->prefix .$param['id'] ?>"><?php echo $param['title'] ?></label></th>
<td>
<textarea name="<?php echo $this->prefix .$param['id'] ?>" type="<?php echo $param['type'] ?>" id="<?php echo $this->prefix .$param['id'] ?>" value="<?php echo $value ?>" placeholder="<?php echo $param['placeholder'] ?>" class="large-text" /><?php echo $value ?></textarea><br />
<span class="description"><?php echo $param['desc'] ?></span>
</td>
<?php
break;
}
case 'checkbox':{ ?>
<th scope="row"><label for="<?php echo $this->prefix .$param['id'] ?>"><?php echo $param['title'] ?></label></th>
<td>
<label for="<?php echo $this->prefix .$param['id'] ?>"><input name="<?php echo $this->prefix .$param['id'] ?>" type="<?php echo $param['type'] ?>" id="<?php echo $this->prefix .$param['id'] ?>"<?php echo ($value=='on') ? ' checked="checked"' : '' ?> />
<?php echo $param['desc'] ?></label>
</td>
<?php
break;
}
case 'select':{ ?>
<th scope="row"><label for="<?php echo $this->prefix .$param['id'] ?>"><?php echo $param['title'] ?></label></th>
<td>
<label for="<?php echo $this->prefix .$param['id'] ?>">
<select name="<?php echo $this->prefix .$param['id'] ?>" id="<?php echo $this->prefix .$param['id'] ?>"><option><?php echo $param['std']; ?></option><?php
foreach($param['args'] as $val=>$name){
?><option value="<?php echo $val ?>"<?php echo ( $value == $val ) ? ' selected="selected"' : '' ?>><?php echo $name ?></option><?php
}
?></select></label><br />
<span class="description"><?php echo $param['desc'] ?></span>
</td>
<?php
break;
}
}
?></tr><?php
}
}
?></tbody></table><?php
}
function save($post_id, $post){
if ( !wp_verify_nonce( $_POST[ $this->options['id'].'_wpnonce' ], $this->options['id'] ) ) return;
if ( !current_user_can( 'edit_post', $post_id ) ) return;
if ( !in_array($post->post_type, $this->options['post'])) return;
foreach ( $this->options['args'] as $param ) {
if ( current_user_can( $param['cap'] ) ) {
if ( isset( $_POST[ $this->prefix . $param['id'] ] ) && trim( $_POST[ $this->prefix . $param['id'] ] ) ) {
update_post_meta( $post_id, $this->prefix . $param['id'], trim($_POST[ $this->prefix . $param['id'] ]) );
} else {
delete_post_meta( $post_id, $this->prefix . $param['id'] );
}
}
}
}
}
$options = array(
array( // первый метабокс
'id' => 'departments', // ID метабокса, а также префикс названия произвольного поля
'name' => __('Контактна інформація відділів', 'oxygen'), // заголовок метабокса
'post' => array('page'), // типы постов для которых нужно отобразить метабокс
'pos' => 'normal', // расположение, параметр $context функции add_meta_box()
'pri' => 'high', // приоритет, параметр $priority функции add_meta_box()
'cap' => 'edit_posts', // какие права должны быть у пользователя
'args' => array(
array(
'id' => 'marketing_name',
'title' => __('Назва відділу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'desc' => __('введіть назву відділу', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'marketing_email',
'title' => __('E-mail відділу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'desc' => __('введіть email відділу', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'marketing_phone',
'title' => __('Телефон відділу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'desc' => __('введіть номер телефона відділу', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'marketing_display',
'title' => __('Чи показувати контактну інформацію цього віддіу?', 'oxygen'),
'type' => 'checkbox',
'desc' => __('якщо бажаєте то поставте/або зніміть відмітку', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'services_name',
'title' => __('Назва відділу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'desc' => __('введіть назву відділу', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'services_email',
'title' => __('E-mail відділу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'desc' => __('введіть email відділу', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'services_phone',
'title' => __('Телефон відділу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'desc' => __('введіть номер телефона відділу', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'services_display',
'title' => __('Чи показувати контактну інформацію цього віддіу?', 'oxygen'),
'type' => 'checkbox',
'desc' => __('якщо бажаєте то поставте/або зніміть відмітку', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'reservation_name',
'title' => __('Назва відділу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'desc' => __('введіть назву відділу', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'reservation_email',
'title' => __('E-mail відділу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'desc' => __('введіть email відділу', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'reservation_phone',
'title' => __('Телефон відділу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'desc' => __('введіть номер телефона відділу', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'reservation_display',
'title' => __('Чи показувати контактну інформацію цього віддіу?', 'oxygen'),
'type' => 'checkbox',
'desc' => __('якщо бажаєте то поставте/або зніміть відмітку', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'issues_name',
'title' => __('Назва відділу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'desc' => __('введіть назву відділу', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'issues_email',
'title' => __('E-mail відділу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'desc' => __('введіть email відділу', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'issues_phone',
'title' => __('Телефон відділу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'desc' => __('введіть номер телефона відділу', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'issues_display',
'title' => __('Чи показувати контактну інформацію цього віддіу?', 'oxygen'),
'type' => 'checkbox',
'desc' => __('якщо бажаєте то поставте/або зніміть відмітку', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
)
)
),
array( // второй метабокс
'id' => 'google_map',
'name' => __('Дані для Google крти', 'oxygen'),
'post' => array('page'), // не только для постов, но и для страниц
'pos' => 'normal',
'pri' => 'high',
'cap' => 'edit_posts',
'args' => array(
array(
'id' => 'api_key',
'title' => 'API key',
'desc' => __('введіть API key для Google карти', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'std' => 'YOUR_API_KEY',
'cap' => 'edit_posts'
),
array(
'id' => 'lat',
'title' => __('Широта', 'oxygen'),
'desc' => __('введіть координати - широту', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'std' => '50.450912',
'cap' => 'edit_posts'
),
array(
'id' => 'lng',
'title' => __('Довгота', 'oxygen'),
'desc' => __('введіть координати - довготу', 'oxygen'),
'type' => 'text',
'placeholder' => '',
'std' => '30.522663',
'cap' => 'edit_posts'
),
array(
'id' => 'zoom',
'title' => __('Зум карти', 'oxygen'),
'type' => 'select',
'desc' => __('виберіть зручне наближення до карти', 'oxygen'),
'cap' => 'edit_posts',
'std' => '5',
'args' => array('8' => '8', '10' => '10', '12' => '12', '14' => '14', '15' => '15', '17' => '17') // элементы списка задаются через массив args, по типу value=>лейбл
),
array(
'id' => 'description',
'title' => __('Додатковий опис', 'oxygen'),
'desc' => __('введіть опис, який буде відображатися при кліку на мркер карти', 'oxygen'),
'type' => 'textarea',
'placeholder' => '',
'std' => '',
'cap' => 'edit_posts'
),
array(
'id' => 'display',
'title' => __('Чи показувати карту?', 'oxygen'),
'type' => 'checkbox',
'desc' => __('якщо бажаєте то поставте/або зніміть відмітку', 'oxygen'),
'std' => '',
'cap' => 'edit_posts'
)
)
)
);
foreach ($options as $option) {
$oxygenmetabox = new oxygenMetaBox($option);
}
//Registration translation rows for departments
if (function_exists('pll_register_string')) {
pll_register_string('Емейл', 'E-mail:', 'Departments');
pll_register_string('Телефон', 'Phone:', 'Departments');
}
// AJAX get post
add_action( 'wp_ajax_load_more', 'load_posts' ); // For logged in users
add_action( 'wp_ajax_nopriv_load_more', 'load_posts' ); // For anonymous users
function load_posts(){
$args = unserialize(stripslashes($_POST['query']));
$args['paged'] = $_POST['page'] + 1;
$args['post_status'] = 'publish';
$args['post_type'] = 'oxygen_gallery';
$args['meta_key'] = '_oxygen_post_location';
$args['meta_value'] = 'gallery';
$args['post__not_in'] = get_option( 'sticky_posts' );
$q = new WP_Query($args);
if( $q->have_posts() ):
while($q->have_posts()): $q->the_post();
?>
<div class="secondary-img">
<img class="img-responsive" src="<?php the_post_thumbnail_url( 'large' ); ?>" alt="<?php the_title();?>">
</div>
<?php
endwhile;
endif;
wp_reset_postdata();
die();
}
function js_variables(){
$variables = array (
'ajax_url' => admin_url('admin-ajax.php'),
//'is_mobile' => wp_is_mobile()
// Тут обычно какие-то другие переменные
);
echo(
'<script type="text/javascript">window.wp_data = ' .
json_encode($variables) .
';</script>'
);
}
add_action('wp_head','js_variables');
function load_more_scripts() {
wp_enqueue_script( 'load_more', get_stylesheet_directory_uri() . '/libs/ajax/load-more.js', array('jquery') );
}
add_action( 'wp_enqueue_scripts', 'load_more_scripts' );
?>