-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-posts.php
1073 lines (816 loc) · 21.6 KB
/
class-posts.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
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
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Query Posts
*
* @package WP Grid Builder
* @author Loïc Blascos
* @copyright 2019-2023 Loïc Blascos
*/
namespace WP_Grid_Builder\FrontEnd\Sources;
use WP_Grid_Builder\Includes\Helpers;
use WP_Grid_Builder\Includes\First_Media;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Post class.
*
* @class WP_Grid_Builder\FrontEnd\Sources\Post
* @since 1.0.0
*/
class Posts {
/**
* Holds settings instance
*
* @since 1.0.0
* @access protected
*
* @var array
*/
protected $settings;
/**
* Holds attachment instance
*
* @since 1.0.0
* @access protected
*
* @var array
*/
protected $attachment;
/**
* WP_Query args
*
* @since 1.0.0
* @access private
*
* @var array
*/
private $query_args;
/**
* Hold queried taxonomy terms
*
* @since 1.0.0
* @access private
*
* @var array
*/
private $term_taxonomies = [];
/**
* WP_Query
*
* @since 1.0.0
* @access private
*
* @var object
*/
private $query;
/**
* Holds queried posts
*
* @since 1.0.0
* @access public
*
* @var array
*/
public $posts = [];
/**
* Holds post object
*
* @since 1.0.0
* @access public
*
* @var object
*/
public $post = [];
/**
* Constructor
*
* @since 1.0.0
* @access public
*
* @param array $settings Holds grid settings.
*/
public function __construct( $settings ) {
$this->settings = $settings;
$this->attachment = new Attachment( $settings );
}
/**
* Parse posts query args
*
* @since 1.4.0
* @access public
*/
public function parse_query() {
if ( $this->settings->is_main_query ) {
$this->main_query();
} else {
$this->build_query();
$this->run_query();
}
}
/**
* Retrieves posts based on query variables
*
* @since 1.4.0
* @access public
*
* @return array Queried objects
*/
public function get_results() {
if ( ! $this->query || ! $this->query->have_posts() ) {
return [];
}
$this->do_loop();
$this->get_attachments();
return apply_filters( 'wp_grid_builder/grid/the_objects', $this->posts );
}
/**
* Get attachment
*
* @since 1.0.0
* @access public
*/
public function get_attachments() {
if ( empty( $this->attachment->ids ) ) {
return;
}
$this->attachment->query( $this->posts );
}
/**
* Run main WP query
*
* @since 1.0.0
* @access public
*/
public function main_query() {
global $wp_query;
if ( wpgb_doing_ajax() && ! empty( $this->settings->main_query ) ) {
// Add language to prevent issue when querying asynchronously.
$this->settings->main_query['lang'] = $this->settings->lang;
// Turns off SQL_CALC_FOUND_ROWS even when limits are present.
$this->settings->main_query['no_found_rows'] = true;
// Add WP Grid Builder to query args.
$this->settings->main_query['wp_grid_builder'] = $this->settings->id;
$this->query = new \WP_Query( $this->settings->main_query );
} elseif ( is_main_query() && ! is_admin() ) {
$this->query = $wp_query;
}
}
/**
* Build custom query
*
* @since 1.0.0
* @access public
*/
public function build_query() {
$this->set_post_type();
$this->set_post_status();
$this->set_posts_per_page();
$this->set_offset();
$this->set_orderby();
$this->set_author__in();
$this->set_post__in();
$this->set_post__not_in();
$this->set_attachments();
$this->set_mime_types();
$this->set_meta_key();
$this->set_meta_query();
$this->set_taxonomies();
$this->set_tax_query();
}
/**
* Run custom query
*
* @since 1.0.0
* @access public
*/
public function run_query() {
// Add language to prevent issue when querying asynchronously.
$this->query_args['lang'] = $this->settings->lang;
// Turns off SQL_CALC_FOUND_ROWS even when limits are present.
$this->query_args['no_found_rows'] = true;
// Add WP Grid Builder to query args.
$this->query_args['wp_grid_builder'] = $this->settings->id;
// Filter the query args.
$this->query_args = apply_filters( 'wp_grid_builder/grid/query_args', $this->query_args, $this->settings->id );
// Run the query.
$this->query = new \WP_Query( $this->query_args );
}
/**
* Set post_type parameter
*
* @since 1.0.0
* @access public
*/
public function set_post_type() {
$post_type = $this->settings->post_type;
$post_type = ! empty( $post_type ) ? $post_type : 'any';
$this->query_args['post_type'] = (array) $post_type;
}
/**
* Set post_status parameter
*
* @since 1.0.0
* @access public
*/
public function set_post_status() {
$post_status = $this->settings->post_status;
if ( empty( $post_status ) ) {
$post_status = [ 'publish' ];
if ( is_user_logged_in() ) {
$post_status[] = 'private';
}
}
$this->query_args['post_status'] = (array) $post_status;
}
/**
* Set posts_per_page parameter
*
* @since 1.0.0
* @access public
*/
public function set_posts_per_page() {
$this->query_args['posts_per_page'] = (int) $this->settings->posts_per_page;
}
/**
* Set offset parameter
*
* @since 1.0.0
* @access public
*/
public function set_offset() {
$this->query_args['offset'] = (int) $this->settings->offset;
}
/**
* Set order and orderby parameters
*
* @since 1.0.0
* @access public
*/
public function set_orderby() {
$this->query_args['order'] = $this->settings->order;
$this->query_args['orderby'] = implode( ' ', (array) $this->settings->orderby );
}
/**
* Set author__in parameter
*
* @since 1.0.0
* @access public
*/
public function set_author__in() {
$this->query_args['author__in'] = (array) $this->settings->author__in;
}
/**
* Set post__in parameter
*
* @since 1.0.0
* @access public
*/
public function set_post__in() {
$this->query_args['post__in'] = (array) $this->settings->post__in;
}
/**
* Set post__not_in parameter
*
* @since 1.0.0
* @access public
*/
public function set_post__not_in() {
$this->query_args['post__not_in'] = (array) $this->settings->post__not_in;
}
/**
* Set attachments ids in post__in or post__not_in
*
* @since 1.0.0
* @access public
*/
public function set_attachments() {
global $wpdb;
$attachment_ids = (array) $this->settings->attachment_ids;
$attachment_ids = array_filter( $attachment_ids );
// If no attachment post type selected.
if ( ! in_array( 'attachment', $this->query_args['post_type'], true ) ) {
return;
}
// Add "inherit" status to retrieve attachments.
array_push( $this->query_args['post_status'], 'publish' );
array_push( $this->query_args['post_status'], 'inherit' );
$this->query_args['post_status'] = array_unique( $this->query_args['post_status'] );
if ( empty( $attachment_ids ) ) {
return;
}
// Merge post__in if not empty.
if ( ! empty( $this->query_args['post__in'] ) ) {
$this->query_args['post__in'] = array_merge( $this->query_args['post__in'], $attachment_ids );
return;
}
// If several post types set.
if ( count( $this->query_args['post_type'] ) > 1 ) {
$all_attachment_ids = wp_cache_get( 'wpgb_all_attachment_ids' );
if ( ! is_array( $all_attachment_ids ) ) {
$all_attachment_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment'" );
wp_cache_add( 'wpgb_all_attachment_ids', $all_attachment_ids );
}
$post__not_in = array_diff( $all_attachment_ids, $attachment_ids );
$this->query_args['post__not_in'] = array_merge( $this->query_args['post__not_in'], $post__not_in );
} else {
if ( array_search( 'rand', (array) $this->query_args['orderby'], true ) === false ) {
$this->query_args['orderby'] .= $this->query_args['orderby'] ? ' post__in' : 'post__in';
}
$this->query_args['post__in'] = $attachment_ids;
}
}
/**
* Set post mime types
*
* @since 1.0.0
* @access public
*/
public function set_mime_types() {
// If no attachment post type selected or media selected.
if ( ! in_array( 'attachment', $this->query_args['post_type'], true )
|| ! empty( $this->settings->attachment_ids )
|| count( $this->query_args['post_type'] ) > 1 ) {
return;
}
$this->query_args['post_mime_type'] = (array) $this->settings->post_mime_type;
}
/**
* Set meta_key parameter
*
* @since 1.0.0
* @access public
*/
public function set_meta_key() {
if ( empty( $this->query_args['orderby'] ) ) {
return;
}
if (
strpos( $this->query_args['orderby'], 'meta_value' ) === false &&
strpos( $this->query_args['orderby'], 'meta_value_num' ) === false
) {
return;
}
$this->query_args['meta_key'] = $this->settings->meta_key;
}
/**
* Set taxonomies from term IDs if children are included in tax_query
*
* @since 1.4.0
* @access public
*/
public function set_taxonomies() {
if ( empty( $this->settings->tax_query_children ) || empty( $this->settings->tax_query ) ) {
return;
}
$query = new \WP_Term_Query(
[
'term_taxonomy_id' => $this->settings->tax_query,
'hide_empty' => false,
]
);
if ( is_wp_error( $query ) || empty( $query ) ) {
return;
}
foreach ( (array) $query->terms as $term ) {
$this->term_taxonomies[ $term->term_taxonomy_id ] = $term->taxonomy;
}
}
/**
* Set tax_query parameter
*
* @since 1.0.0
* @access public
*/
public function set_tax_query() {
$tax_query = $this->settings->tax_query;
if ( empty( $tax_query ) ) {
return;
}
$this->query_args['tax_query'] = array_map(
function( $term_id ) {
$clause = [
'field' => 'term_taxonomy_id',
'terms' => (array) $term_id,
'operator' => $this->settings->tax_query_operator,
'include_children' => (bool) $this->settings->tax_query_children,
];
// We add taxonomy parameter if available.
if ( ! empty( $this->term_taxonomies[ $term_id ] ) ) {
$clause['taxonomy'] = $this->term_taxonomies[ $term_id ];
}
return $clause;
},
(array) $tax_query
);
$this->query_args['tax_query']['relation'] = $this->settings->tax_query_relation;
}
/**
* Set meta_query parameter
*
* @since 1.0.0
* @access public
*
* @param array $meta_query Holds meta query args.
*/
public function set_meta_query( $meta_query = false ) {
if ( empty( $this->settings->meta_query ) ) {
return;
}
$this->query_args['meta_query'] = $this->process_meta_query( (array) $this->settings->meta_query );
}
/**
* Process meta_query arguments
*
* @since 1.0.0
* @access public
*
* @param array $meta_query Holds meta query args.
*/
public function process_meta_query( $meta_query ) {
return array_map(
function( $clause ) {
if ( isset( $clause['value'], $clause['type'] ) && in_array( $clause['type'], [ 'DATE', 'DATETIME', 'TIME' ], true ) ) {
$dates = explode( ' ', $clause['value'] );
$dates = array_map( 'date', $dates );
$clause['value'] = implode( ' ', $dates );
}
if ( isset( $clause['value'], $clause['compare'] ) && in_array( $clause['compare'], [ 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ], true ) ) {
$values = explode( ',', $clause['value'] );
// Set at least 2 values to match wpdb::prepare placeholders.
$values = array_pad( $values, 2, '' );
$clause['value'] = $values;
} elseif ( is_array( $clause ) ) {
$clause = $this->process_meta_query( $clause );
}
return $clause;
},
$meta_query
);
}
/**
* Custom query loop
*
* @since 1.2.0 Parse attachment ids after the object is filtered.
* @since 1.0.0
* @access public
*/
public function do_loop() {
while ( $this->query->have_posts() ) {
$this->query->the_post();
$this->get_post();
$this->get_post_meta();
$this->get_permalink();
$this->get_post_terms();
$this->get_post_format();
$this->get_post_author();
$this->get_post_media();
$this->get_product_data();
$this->posts[] = apply_filters( 'wp_grid_builder/grid/the_object', $this->post );
$this->attachment->parse_attachment_ids( $this->post );
}
wp_reset_postdata();
}
/**
* Build item array
*
* @since 1.0.0
* @access public
*/
public function get_post() {
global $post;
$this->post = clone $post;
$this->post->object_type = 'post';
$this->post->post_sticky = is_sticky();
$this->post->post_status = get_post_status();
$this->post->post_date = get_the_date( 'U' );
$this->post->post_modified = get_the_modified_date( 'U' );
$this->post->post_title = get_the_title();
$this->post->post_content = get_the_content( null, false, $post->ID );
}
/**
* Get meta data
*
* @since 1.0.0
* @access public
*/
public function get_post_meta() {
$meta = array_map( 'current', (array) get_post_meta( $this->post->ID ) );
$meta = array_map( 'maybe_unserialize', $meta );
if ( isset( $meta[ '_' . WPGB_SLUG ] ) ) {
$meta[ WPGB_SLUG ] = $meta[ '_' . WPGB_SLUG ];
unset( $meta[ '_' . WPGB_SLUG ] );
} else {
$meta[ WPGB_SLUG ] = [];
}
$defaults = require WPGB_PATH . 'admin/settings/defaults/post.php';
$meta[ WPGB_SLUG ] = wp_parse_args( $meta[ WPGB_SLUG ], $defaults );
$this->post->metadata = $meta;
}
/**
* Get post permalink
*
* @since 1.0.0
* @access public
*/
public function get_permalink() {
$this->post->permalink = $this->post->metadata[ WPGB_SLUG ]['permalink'];
if ( empty( $this->post->permalink ) ) {
$this->post->permalink = get_the_permalink( $this->post->ID );
}
}
/**
* Get taxonomy terms
*
* @since 1.2.0 Exclude language taxonomy (Polylang)
* @since 1.0.0
* @access public
*/
public function get_post_terms() {
$post_terms = [];
$taxonomies = Helpers::get_taxonomies( (array) $this->post->post_type );
foreach ( $taxonomies as $taxonomy => $args ) {
// Ignore Polylang taxonomy.
if ( 'language' === $taxonomy ) {
continue;
}
$terms = get_the_terms( $this->post->ID, $taxonomy );
if ( is_wp_error( $terms ) || empty( $terms ) ) {
continue;
}
foreach ( $terms as $term ) {
if ( empty( $term ) ) {
continue;
}
$link = get_term_link( $term->term_id );
$meta = get_term_meta( $term->term_id, '_' . WPGB_SLUG, true );
$term->link = ! is_wp_error( $link ) ? $link : '';
$term->color = isset( $meta['color'] ) ? $meta['color'] : '';
$term->background = isset( $meta['background'] ) ? $meta['background'] : '';
$post_terms[] = $term;
}
}
$this->post->post_terms = $post_terms;
}
/**
* Get post format
*
* @since 1.1.8 Preserve unsupported post formats.
* @since 1.0.0
* @access public
*/
public function get_post_format() {
$post_format = $this->post->metadata[ WPGB_SLUG ]['post_format'];
$post_format = empty( $post_format ) ? get_post_format() : $post_format;
$post_format = empty( $post_format ) ? 'standard' : $post_format;
$supported_formats = [ 'gallery', 'audio', 'video' ];
$format_supported = in_array( $post_format, $supported_formats, true );
$format_allowed = in_array( $post_format, $this->settings->post_formats, true );
// We keep not supported formats (to assign cards to them) and we exclude support for not allowed formats.
$this->post->post_format = ! $format_supported || $format_allowed ? $post_format : 'standard';
}
/**
* Get author data
*
* @since 1.0.0
* @access public
*/
public function get_post_author() {
$author = get_the_author_meta( 'ID' );
$avatar = get_avatar_data( $author );
$this->post->post_author = [
'ID' => $author,
'display_name' => get_the_author_meta( 'display_name' ),
'posts_url' => get_author_posts_url( $author ),
'avatar' => $avatar,
];
}
/**
* Get media content according to post format
*
* @since 1.0.0
* @access public
*/
public function get_post_media() {
$source = '';
$format = $this->post->post_format;
// Add post_media key to post.
$this->post->post_media = null;
// Fetch media from post_meta.
switch ( $format ) {
case 'gallery':
$source = $this->get_gallery_format();
break;
case 'video':
$source = $this->get_video_format();
break;
case 'audio':
$source = $this->get_audio_format();
break;
}
// If no alternative format available, get default attachement format and source.
if ( empty( $source ) && 'attachment' === $this->post->post_type ) {
$format = $this->get_attachment_format();
$source = $this->get_attachment_url();
}
// Get thumbnail whatever the post format.
$this->get_thumbnail();
file_put_contents('get_thumbnail.txt', $this->post->post_thumbnail."\n", FILE_APPEND);
if ( 'standard' === $format ) {
return;
}
// Try to fetch first media (audio, video & gallery) if missng.
if ( empty( $source ) && $this->settings->first_media ) {
$source = ( new First_Media( $this->post ) )->get( $format );
}
// If not content found set post to standard format.
if ( empty( $source ) || ! is_array( $source ) ) {
return;
}
$source['format'] = $format;
$this->post->post_media = $source;
}
/**
* Get thumbnail ID or data
*
* @since 1.0.0
* @access public
*/
public function get_thumbnail() {
$post_type = $this->post->post_type;
if($post_type == 'product') {
$metadata = $this->post->metadata;
$attributes = $metadata['_product_attributes'];
if(isset($attributes['images'])) {
$images = explode('|', $attributes['images']['value']);
file_put_contents('images.json', json_encode($images[0]), FILE_APPEND);
if(count($images)) {
$this->post->post_thumbnail = "https://staging-newpemamalllive-staging.kinsta.cloud/wp-content/uploads/2022/01/heart-regular-svg-3.png";
// file_put_contents('count_image.txt', $images[0]."\n", FILE_APPEND);
return;
}
}
}
// Get alternative attachment ID (from metadata).
$thumb = (int) $this->post->metadata[ WPGB_SLUG ]['attachment_id'];
// If image attachment directly get image.
if ( $thumb < 1 && 'attachment' === $this->post->post_type && wp_attachment_is_image( $this->post->ID ) ) {
$this->post->post_thumbnail = $this->attachment->get_attachment( $this->post );
return;
}
// Get thumbnail id.
if ( $thumb < 1 ) {
$thumb = get_post_thumbnail_id();
}
// Try to get first image in post content if thumb missing.
if ( empty( $thumb ) && $this->settings->first_media && 'attachment' !== $this->post->post_type ) {
$thumb = ( new First_Media( $this->post ) )->get();
}
if ( empty( $thumb ) ) {
return;
}
$post_type = $this->post->post_type;
$this->post->post_thumbnail = $thumb;
}
/**
* Get alternative gallery IDs
*
* @since 1.0.0
* @access public
*
* @return array
*/
public function get_gallery_format() {
if ( empty( $this->post->metadata[ WPGB_SLUG ]['gallery_ids'] ) ) {
return;
}
return [
'sources' => $this->post->metadata[ WPGB_SLUG ]['gallery_ids'],
];
}
/**
* Get alternative audio content
*
* @since 1.0.0
* @access public
*
* @return array
*/
public function get_audio_format() {
$sources = [
$this->post->metadata[ WPGB_SLUG ]['mp3_url'],
$this->post->metadata[ WPGB_SLUG ]['ogg_url'],
];
$sources = array_filter( $sources );
if ( empty( $sources ) ) {
return;
}
return [
'type' => 'hosted',
'sources' => $sources,
];
}
/**
* Get alternative video content
*
* @since 1.0.1 Fix condition to fetch video attachment.
* @since 1.0.0
* @access public
*
* @return array
*/
public function get_video_format() {
$sources = [
$this->post->metadata[ WPGB_SLUG ]['mp4_url'],
$this->post->metadata[ WPGB_SLUG ]['ogv_url'],
$this->post->metadata[ WPGB_SLUG ]['webm_url'],
];
$sources = array_filter( $sources );
if ( ! empty( $sources ) ) {
return [
'type' => 'hosted',
'sources' => $sources,
];
}
$embed = $this->post->metadata[ WPGB_SLUG ]['embed_video_url'];
if ( empty( $embed ) ) {
return;
}
$providers = Helpers::get_embed_providers();
foreach ( $providers as $provider => $media ) {
if ( ! preg_match( $provider, $embed, $match ) ) {
continue;
}
return [
'type' => 'embedded',
'sources' => [
'provider' => $media,
'url' => $match[0],
'id' => $match[1],
],
];
}
}
/**
* Get attachment media format (audi or video)
*
* @since 1.1.8
* @access public
*/
public function get_attachment_format() {