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