|
1 <?php |
|
2 /** |
|
3 * OptionTree Post Formats. |
|
4 * |
|
5 * @package OptionTree |
|
6 */ |
|
7 |
|
8 if ( ! defined( 'OT_VERSION' ) ) { |
|
9 exit( 'No direct script access allowed' ); |
|
10 } |
|
11 |
|
12 if ( ! class_exists( 'OT_Post_Formats' ) ) { |
|
13 |
|
14 /** |
|
15 * OptionTree Post Formats class. |
|
16 * |
|
17 * This class loads all the methods and helpers specific to build a the post format metaboxes. |
|
18 */ |
|
19 class OT_Post_Formats { |
|
20 |
|
21 /** |
|
22 * Class Constructor |
|
23 * |
|
24 * @access public |
|
25 * @since 2.3.0 |
|
26 */ |
|
27 public function __construct() { |
|
28 $this->setup_actions(); |
|
29 } |
|
30 |
|
31 /** |
|
32 * Setup the default filters and actions. |
|
33 * |
|
34 * @uses add_action() To add various actions. |
|
35 * @uses add_filter() To add various filters. |
|
36 * |
|
37 * @access private |
|
38 * @since 2.3.0 |
|
39 */ |
|
40 private function setup_actions() { |
|
41 |
|
42 // Initialize the meta boxes. |
|
43 add_action( 'admin_init', array( $this, 'meta_boxes' ), 2 ); |
|
44 |
|
45 // Setup pings for the link & quote URLs. |
|
46 add_filter( 'pre_ping', array( $this, 'pre_ping_post_links' ), 10, 3 ); |
|
47 } |
|
48 |
|
49 /** |
|
50 * Builds the default Meta Boxes. |
|
51 * |
|
52 * @access private |
|
53 * @since 2.3.0 |
|
54 */ |
|
55 public function meta_boxes() { |
|
56 |
|
57 // Exit if called outside of WP admin. |
|
58 if ( ! is_admin() ) { |
|
59 return false; |
|
60 } |
|
61 |
|
62 /** |
|
63 * Filter the post formats meta boxes. |
|
64 * |
|
65 * @since 2.6.0 |
|
66 * |
|
67 * @param array $meta_boxes The meta boxes being registered. |
|
68 * @return array |
|
69 */ |
|
70 $meta_boxes = apply_filters( |
|
71 'ot_recognized_post_format_meta_boxes', |
|
72 array( |
|
73 ot_meta_box_post_format_gallery(), |
|
74 ot_meta_box_post_format_link(), |
|
75 ot_meta_box_post_format_quote(), |
|
76 ot_meta_box_post_format_video(), |
|
77 ot_meta_box_post_format_audio(), |
|
78 ) |
|
79 ); |
|
80 |
|
81 /** |
|
82 * Register our meta boxes using the |
|
83 * ot_register_meta_box() function. |
|
84 */ |
|
85 foreach ( $meta_boxes as $meta_box ) { |
|
86 ot_register_meta_box( $meta_box ); |
|
87 } |
|
88 } |
|
89 |
|
90 /** |
|
91 * Setup pings for the link & quote URLs |
|
92 * |
|
93 * @access public |
|
94 * @since 2.3.0 |
|
95 * |
|
96 * @param array $post_links The URLs to ping. |
|
97 * @param array $pung Pinged URLs. |
|
98 * @param int $post_id Post ID. |
|
99 */ |
|
100 public function pre_ping_post_links( $post_links, $pung, $post_id = null ) { |
|
101 |
|
102 $_link = get_post_meta( $post_id, '_format_link_url', true ); |
|
103 if ( ! empty( $_link ) && ! in_array( $_link, $pung, true ) && ! in_array( $_link, $post_links, true ) ) { |
|
104 $post_links[] = $_link; |
|
105 } |
|
106 |
|
107 $_quote = get_post_meta( $post_id, '_format_quote_source_url', true ); |
|
108 if ( ! empty( $_quote ) && ! in_array( $_quote, $pung, true ) && ! in_array( $_quote, $post_links, true ) ) { |
|
109 $post_links[] = $_quote; |
|
110 } |
|
111 } |
|
112 } |
|
113 } |
|
114 |
|
115 /** |
|
116 * Instantiate The Class. |
|
117 * |
|
118 * @since 1.0 |
|
119 */ |
|
120 if ( function_exists( 'ot_register_meta_box' ) ) { |
|
121 new OT_Post_Formats(); |
|
122 } |