-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.metas-admin.php
701 lines (612 loc) · 22.1 KB
/
class.metas-admin.php
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
<?php
/**
* Create metaboxes in admin
*/
class MetasAdmin
{
/**
* [__construct Initialize options]
*/
function __construct()
{
add_action( 'admin_enqueue_scripts', array( $this, 'addScriptsAdmin' ) );
add_action( 'admin_menu', array( $this, 'addAdminMenu' ) );
add_action( 'wp_ajax_ajCall', array( $this, 'ajaxCall') );
add_action( 'wp_ajax_nopriv_ajCall', array( $this, 'ajaxCall') );
add_action( 'add_meta_boxes', array( $this, 'registerMetaBoxes' ) );
add_action( 'save_post', array( $this, 'savePostMeta' ) );
}
/**
* [addScriptsAdmin Add scripts and css in the admin]
* @param [type] $hook [description]
*/
public function addScriptsAdmin($hook)
{
wp_enqueue_style( 'ccs-multiple-select', plugin_dir_url( __FILE__ ) . 'inc/multiple-select/css/multi-select.css');
wp_enqueue_style( 'css-admin', plugin_dir_url( __FILE__ ) . 'css/metas-admin.css');
wp_enqueue_script( 'js-multiple-select', plugin_dir_url( __FILE__ ) . 'inc/multiple-select/js/jquery.multi-select.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'add_scripts_admin', plugin_dir_url( __FILE__ ) . 'js/metas-admin.js', array('jquery','jquery-ui-sortable'), '1.0.0', true );
$data['ajax_url'] = admin_url('admin-ajax.php' );
wp_localize_script( 'add_scripts_admin', 'variables', $data );
}
/**
* [addAdminMenu Add tab in menu]
*/
public function addAdminMenu()
{
add_menu_page('Create Metas', 'Create Metas', 'manage_options', 'create-metas', array( $this, 'optionsPage' ), 'dashicons-admin-tools', 66 );
}
/**
* [optionsPage description]
* @return [type] [description]
*/
public function optionsPage()
{
// update_option('metas-custom', '');
// echo "<pre>";
// print_r(self::getDataMetas());
// echo "</pre>";
// exit();
if( !empty($_REQUEST['page']) && $_REQUEST['page'] == "create-metas" ) {
if (isset($_POST['metas-custom']) && $_POST['metas-custom']) {
self::saveData($_POST['metas-custom']);
}
}
$pages = self::getPages();
$post_types = self::getPostsTypes();
$allMetas = self::getDataMetas();
?>
<div class="wrap container-metas">
<h2><?php echo esc_html('Create Metas'); ?></h2>
<div id="content-metas">
<form action="<?php echo esc_url( admin_url( 'admin.php?page=create-metas' ) ); ?>" method="POST">
<table class="form-table">
<tbody>
<tr>
<th scope="row">Metas created</th>
<td>
<?php
if ( !empty($allMetas) ) {
?>
<select id="allMetas">
<option value="clear">Metas Creadas</option>
<?php
foreach ($allMetas as $key => $value) {
?>
<option value="<?php echo $value['_name_meta_box']; ?>"><?php echo $value['_title_meta_box']; ?></option>
<?php
}
?>
</select>
<?php
}
?>
</td>
</tr>
<tr>
<th scope="row">Title Meta Box</th>
<td>
<input type="text" name="metas-custom[_title_meta_box]" class="title_meta_box" />
</td>
</tr>
<tr>
<th scope="row">No. Inputs</th>
<td>
<input type="text" name="metas-custom[_no_inputs]" class="no_inputs" />
</td>
</tr>
<tr>
<th scope="row">No. Editors</th>
<td>
<input type="text" name="metas-custom[_no_editors]" class="no_editors" />
</td>
</tr>
<tr>
<th scope="row">Image Featured</th>
<td>
<input type="checkbox" name="metas-custom[_img_featured]" class="img_featured" value="yes"> Yes
</td>
</tr>
<tr>
<th scope="row">Gallery</th>
<td>
<input type="checkbox" name="metas-custom[_gallery]" value="yes"> Yes
</td>
</tr>
<tr>
<th scope="row">Video Featured</th>
<td>
<input type="checkbox" name="metas-custom[_video_featured]" class="video_featured" value="yes"> Yes
</td>
</tr>
<tr>
<th scope="row">Document Featured</th>
<td>
<input type="checkbox" name="metas-custom[_document_featured]" class="document_featured" value="yes"> Yes
</td>
</tr>
<tr>
<th><h2 class="title">Position of Meta</h2></th>
</tr>
<tr>
<th scope="row">Posts</th>
<td>
<input type="checkbox" name="metas-custom[_all_posts]" class="all_posts_meta" value="yes"> Yes
</td>
</tr>
<tr>
<th scope="row">Specific Page</th>
<td>
<select id="pages" name="metas-custom[_pages][]" class="pages_meta" multiple="multiple">
<option value="all">All pages</option>
<?php
if (!empty($pages)) {
foreach ($pages as $key => $page) {
echo '<option value="'.$page->ID.'">'.$page->post_title.'</option>';
}
}
?>
</select>
</td>
</tr>
<?php if (!empty($post_types)) { ?>
<tr>
<th scope="row">Specific Post Type</th>
<td>
<select id="posts_types" name="metas-custom[_posts_types][]" class="posts_types_meta" multiple="multiple">
<option value="all">All post types</option>
<?php
foreach ($post_types as $postType) {
echo '<option value="'.$postType.'">'.$postType.'</option>';
}
?>
</select>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php submit_button(); ?>
</form>
</div>
</div>
<?php
}
/**
* [getPages Get all pages]
* @return [type] [description]
*/
public function getPages()
{
$args = array(
'sort_order' => 'asc',
'sort_column' => 'post_title',
'hierarchical' => 1,
'child_of' => 0,
'parent' => -1,
'post_type' => 'page',
'post_status' => 'publish'
);
return get_pages($args);
}
/**
* [getPostsTypes Get all posts types]
* @return [type] [description]
*/
public function getPostsTypes()
{
$args = array(
'public' => true,
'_builtin' => false
);
$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
$post_types = get_post_types( $args, $output, $operator );
return $post_types;
}
/**
* [saveData Save info about metas]
* @param [type] $data [description]
* @return [type] [description]
*/
public function saveData($data)
{
$name = self::getNameMetaBox($data['_title_meta_box']);
$content = self::getDataMetas();
$data['_name_meta_box'] = $name;
$content[$name] = $data;
update_option('metas-custom', $content);
}
/**
* [getNameMetaBox Convert the title of meta to name of meta box]
* @param [type] $data [description]
* @return [type] [description]
*/
public function getNameMetaBox($data)
{
$name = strtolower($data);
$name = self::removeAccents($name);
$name = str_replace(" ", "_" , $name);
return '_'.$name;
}
public function removeAccents($name)
{
$unwanted_array = array( 'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y' );
return strtr( $name, $unwanted_array );
}
/**
* [registerMetaBoxes Method for register all metas boxes]
* @return [type] [description]
*/
public function registerMetaBoxes()
{
$dataMetas = self::getDataMetas();
if ( !empty($dataMetas) ) {
foreach ($dataMetas as $key => $meta) {
/* CHECK IF HAS PAGES */
if ( isset($meta["_pages"]) && !empty($meta["_pages"][0]) ) {
self::createMetasPages($meta);
}
/* POSTS TYPES REGISTER METAS */
if ( isset($meta["_posts_types"]) && !empty($meta["_posts_types"][0]) ) {
self::createMetasPostTypes($meta);
}
/* CHECK IF ALL POSTS IS true */
if ( isset($meta["_all_posts"]) && $meta['_all_posts'] == 'yes' ) {
self::createMetasPosts($meta);
}
}
}
}
public function createMetasPosts($meta)
{
$nameMetaBox = '';
$titleMetaBox = '';
$noInputs = '';
$noEditors = '';
$imgFeatured = '';
$videoFeatured = '';
$documentFeatured = '';
$gallery = '';
if (isset($meta['_title_meta_box'])) {
$titleMetaBox = $meta['_title_meta_box'];
}
if (isset($meta['_no_inputs'])) {
$noInputs = $meta['_no_inputs'];
}
if (isset($meta['_no_editors'])) {
$noEditors = $meta['_no_editors'];
}
if (isset($meta['_name_meta_box'])) {
$nameMetaBox = $meta['_name_meta_box'];
}
if ( isset($meta['_img_featured']) && $meta['_img_featured'] == 'yes' ) {
$imgFeatured = $meta['_img_featured'];
}
if ( isset($meta['_video_featured']) && $meta['_video_featured'] == 'yes' ) {
$videoFeatured = $meta['_video_featured'];
}
if ( isset($meta['_document_featured']) && $meta['_document_featured'] == 'yes' ) {
$documentFeatured = $meta['_document_featured'];
}
if ( isset($meta['_gallery']) && $meta['_gallery'] == 'yes' ) {
$gallery = $meta['_gallery'];
}
self::addMetaBox($nameMetaBox, $titleMetaBox, 'post' , $noInputs, $noEditors, $imgFeatured, $videoFeatured, $documentFeatured, $gallery);
}
/**
* [createMetasPages Method for register all metas in pages]
* @param [type] $meta [description]
* @return [type] [description]
*/
public function createMetasPages($meta)
{
if ( isset($_GET['post']) || isset($_POST['post_ID']) )
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
else
$post_id = null;
$nameMetaBox = '';
$titleMetaBox = '';
$noInputs = '';
$noEditors = '';
$imgFeatured = '';
$videoFeatured = '';
$documentFeatured = '';
$gallery = '';
if (isset($meta['_title_meta_box'])) {
$titleMetaBox = $meta['_title_meta_box'];
}
if (isset($meta['_no_inputs'])) {
$noInputs = $meta['_no_inputs'];
}
if (isset($meta['_no_editors'])) {
$noEditors = $meta['_no_editors'];
}
if (isset($meta['_name_meta_box'])) {
$nameMetaBox = $meta['_name_meta_box'];
}
if ( isset($meta['_img_featured']) && $meta['_img_featured'] == 'yes' ) {
$imgFeatured = $meta['_img_featured'];
}
if ( isset($meta['_video_featured']) && $meta['_video_featured'] == 'yes' ) {
$videoFeatured = $meta['_video_featured'];
}
if ( isset($meta['_document_featured']) && $meta['_document_featured'] == 'yes' ) {
$documentFeatured = $meta['_document_featured'];
}
if ( isset($meta['_gallery']) && $meta['_gallery'] == 'yes' ) {
$gallery = $meta['_gallery'];
}
foreach ($meta['_pages'] as $key => $value) {
$createMeta = false;
if ($post_id == $value) {
$createMeta = true;
} else if( $value == 'all' ) {
$createMeta = true;
}
if ($createMeta) {
self::addMetaBox($nameMetaBox, $titleMetaBox, 'page' , $noInputs, $noEditors, $imgFeatured, $videoFeatured, $documentFeatured, $gallery);
}
}
}
public function createMetasPostTypes($meta)
{
// echo "<pre>";
// print_r($meta);
// echo "</pre>";
// exit();
$nameMetaBox = '';
$titleMetaBox = '';
$noInputs = '';
$noEditors = '';
$imgFeatured = '';
$videoFeatured = '';
$documentFeatured = '';
$gallery = '';
if (isset($meta['_title_meta_box'])) {
$titleMetaBox = $meta['_title_meta_box'];
}
if (isset($meta['_no_inputs'])) {
$noInputs = $meta['_no_inputs'];
}
if (isset($meta['_no_editors'])) {
$noEditors = $meta['_no_editors'];
}
if (isset($meta['_name_meta_box'])) {
$nameMetaBox = $meta['_name_meta_box'];
}
if ( isset($meta['_img_featured']) && $meta['_img_featured'] == 'yes' ) {
$imgFeatured = $meta['_img_featured'];
}
if ( isset($meta['_video_featured']) && $meta['_video_featured'] == 'yes' ) {
$videoFeatured = $meta['_video_featured'];
}
if ( isset($meta['_document_featured']) && $meta['_document_featured'] == 'yes' ) {
$documentFeatured = $meta['_document_featured'];
}
if ( isset($meta['_gallery']) && $meta['_gallery'] == 'yes' ) {
$gallery = $meta['_gallery'];
}
foreach ($meta['_posts_types'] as $key => $postType) {
self::addMetaBox($nameMetaBox, $titleMetaBox, $postType , $noInputs, $noEditors, $imgFeatured, $videoFeatured, $documentFeatured, $gallery);
}
}
public function addMetaBox($nameMetaBox, $titleMetaBox, $screen ,$noInputs = '', $noEditors = '', $imgFeatured = '', $videoFeatured = '', $documentFeatured = '', $gallery = '')
{
add_meta_box( $nameMetaBox, $titleMetaBox, array($this, 'metaBoxDefault'), $screen, 'normal', 'default', array( 'name' => $nameMetaBox, 'noInputs' => $noInputs, 'noEditors' => $noEditors, 'imgFeatured' => $imgFeatured, 'videoFeatured' => $videoFeatured, 'documentFeatured' => $documentFeatured, 'gallery' => $gallery ) );
}
/**
* [metaBoxDefault MetaBox with all fields]
* @param [type] $post [description]
* @param [type] $metabox [description]
* @return [type] [description]
*/
public function metaBoxDefault($post, $metabox)
{
$nameMetaBox = $metabox['args']['name'];
$data = get_post_meta( $post->ID , $nameMetaBox , true );
?>
<div class="container form-wrap">
<!-- SECTION CALL FUNCTION -->
<div class="call_values">
<div class="form-field">
<label>Call function</label>
<span>get_post_meta( $post->ID , <?php echo $nameMetaBox; ?> , true )</span>
</div>
</div>
<!-- END SECTION CALL FUNCTION -->
<!-- SECTION IMAGE FEATURED -->
<?php if ( isset($metabox['args']['imgFeatured']) && $metabox['args']['imgFeatured'] ) {
$idImage = '';
$custom_class = $nameMetaBox.'_image_featured';
?>
<div class="form-field">
<?php
if( isset($data['id_image_featured']) && $data['id_image_featured'] ) {
$idImage = $data['id_image_featured'];
echo wp_get_attachment_image( $idImage, 'thumbnail', true, array('class' => 'image-attachment') );
}
?>
<div class="button-primary add_item width_add_image" data-id="<?php echo $custom_class; ?>" data-type="foto" >Agregar Imagen</div>
<input type="hidden" name="<?php echo $nameMetaBox; ?>[id_image_featured]" class="<?php echo $custom_class; ?>" value="<?php echo $idImage; ?>" />
</div>
<?php } ?>
<!-- END SECTION IMAGE FEATURED -->
<!-- SECTION VIDEO FEATURED -->
<?php if ( isset($metabox['args']['videoFeatured']) && $metabox['args']['videoFeatured'] ) {
$idVideo = '';
$custom_class = $nameMetaBox.'_video_featured';
?>
<div class="form-field">
<?php
if( isset($data['id_video_featured']) && $data['id_video_featured'] ) {
$idVideo = $data['id_video_featured'];
$attachment_title = get_the_title($idVideo);
echo wp_get_attachment_image( $idVideo, 'thumbnail', true, array('class' => 'image-attachment') );
echo "<label>".$attachment_title."</label>";
}
?>
<div class="button-primary add_item width_add_image" data-id="<?php echo $custom_class; ?>" data-type="video" >Agregar Video</div>
<input type="hidden" name="<?php echo $nameMetaBox; ?>[id_video_featured]" class="<?php echo $custom_class; ?>" value="<?php echo $idVideo; ?>" />
</div>
<?php } ?>
<!-- END SECTION VIDEO FEATURED -->
<!-- SECTION DOCUMENT FEATURED -->
<?php if ( isset($metabox['args']['documentFeatured']) && $metabox['args']['documentFeatured'] ) {
$idDocument = '';
$custom_class = $nameMetaBox.'_document_featured';
?>
<div class="form-field">
<?php
if( isset($data['id_document_featured']) && $data['id_document_featured'] ) {
$idDocument = $data['id_document_featured'];
$attachment_title = get_the_title($idDocument);
echo wp_get_attachment_image( $idDocument, 'thumbnail', true, array('class' => 'image-attachment') );
echo "<label>".$attachment_title."</label>";
}
?>
<div class="button-primary add_item width_add_image" data-id="<?php echo $custom_class; ?>" data-type="pdf" >Agregar Documento</div>
<input type="hidden" name="<?php echo $nameMetaBox; ?>[id_document_featured]" class="<?php echo $custom_class; ?>" value="<?php echo $idDocument; ?>" />
</div>
<?php } ?>
<!-- END SECTION DOCUMENT FEATURED -->
<!-- SECTION INPUTS -->
<?php
if ( isset($metabox['args']['noInputs']) && !empty($metabox['args']['noInputs']) ) {
$c = 0;
$val = '';
while ( $c < $metabox['args']['noInputs'] ) {
if(isset($data['text'][$c]) && !empty($data['text'][$c])) {
$val = $data['text'][$c];
} else {
$val = '';
}
?>
<div class="form-field">
<label>Titulo</label>
<input name="<?php echo $nameMetaBox; ?>[text][<?php echo $c; ?>]" size="40" type="text" value="<?php echo $val; ?>" />
</div>
<?php
$c++;
}
} ?>
<!-- END SECTION INPUTS -->
<!-- SECTION EDITORS -->
<?php
if ( isset($metabox['args']['noEditors']) && !empty($metabox['args']['noEditors']) ) {
$c = 0;
$val = '';
$description = '';
while ( $c < $metabox['args']['noEditors'] ) {
$description_name = $nameMetaBox."[textarea][$c]";
$editor_id = 'editor'.$nameMetaBox.'_'.$c;
if(isset($data) && !empty($data)) {
$description = $data['textarea'][$c];
}
?>
<div class="form-field">
<label>Descripción</label>
<?php wp_editor( htmlspecialchars_decode($description), $editor_id, $settings = array( 'textarea_name'=> $description_name, 'editor_height' => 180 ) ); ?>
</div>
<?php
$c++;
}
}
?>
<!-- END SECTION EDITORS -->
<!-- SECTION GALLERY -->
<?php
if ( isset($metabox['args']['gallery']) && !empty($metabox['args']['gallery']) ) {
$idImage = '';
$custom_class = $nameMetaBox.'_gallery';
?>
<div class="form-field">
<div class="button-primary gallery_add width_add_image" data-for="<?php echo $nameMetaBox; ?>" data-id="<?php echo $custom_class; ?>" >Agregar Gallery</div>
<ul id="gallery<?php echo $nameMetaBox; ?>" class="gallery-wrapper-sortable">
<?php
if(isset($data['gallery_media']) && !empty($data['gallery_media'])) {
foreach ($data['gallery_media'] as $key => $idImage) {
$img = wp_get_attachment_image_src( $idImage, 'thumbnail');
?>
<li class="gallery_thumnails">
<div>
<span class="gallery-movable"></span>
<a href="#" class="gallery_remove_item">
<span>delete</span>
</a>
<img src="<?php echo $img[0]; ?>">
<input type="hidden" name="<?php echo $nameMetaBox; ?>[gallery_media][]" value="<?php echo $idImage ?>" />
</div>
</li>
<?php
}
}
?>
<!-- <li class="gallery_thumnails">
<div>
<span class="gallery-movable"></span>
<a href="#" class="gallery_remove_item">
<span>delete</span>
</a>
<img src=" ">
<input type="hidden" name="<?php //echo $nameMetaBox; ?>[gallery_media][]" value="" />
</div>
</li> -->
</ul>
</div>
<?php
}
?>
<!-- END SECTION GALLERY -->
</div>
<?php
}
/**
* [savePostMeta Save the metas in each post]
* @param [type] $post_id [description]
* @return [type] [description]
*/
function savePostMeta($post_id)
{
$dataMetas = self::getDataMetas();
foreach ($dataMetas as $key => $meta) {
$nameMeta = $meta['_name_meta_box'];
if ( isset($_POST[$nameMeta]) ) {
update_post_meta( $post_id, $nameMeta, $_POST[$nameMeta] );
}
}
}
/**
* [ajaxCall Called ajax]
* @return [type] [description]
*/
public function ajaxCall()
{
switch ($_POST['method']) {
case 'getMetaData':
$dataMetas = self::getDataMetas();
$search = $_POST['search'];
foreach ($dataMetas as $key => $v) {
if($v["_name_meta_box"] == $search) {
print_r(json_encode($v));
break;
};
// if ($value['_name_meta_box'] == $search) {
//
// }
// break;
}
die();
break;
}
}
/**
* [getDataMetas Return value of Metas saved in the option]
* @return [type] [description]
*/
public function getDataMetas()
{
return get_option('metas-custom');
}
}
?>