author | Anthony Ly <anthonyly.com@gmail.com> |
Tue, 12 Mar 2013 18:21:39 +0100 | |
changeset 206 | 919b4ddb13fa |
parent 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
3 |
* Post functions and post utility function. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Post |
|
7 |
* @since 1.5.0 |
|
8 |
*/ |
|
9 |
||
10 |
// |
|
11 |
// Post Type Registration |
|
12 |
// |
|
13 |
||
14 |
/** |
|
15 |
* Creates the initial post types when 'init' action is fired. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
16 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
17 |
* @since 2.9.0 |
136 | 18 |
*/ |
19 |
function create_initial_post_types() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
20 |
register_post_type( 'post', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
21 |
'labels' => array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
22 |
'name_admin_bar' => _x( 'Post', 'add new on admin bar' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
23 |
), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
24 |
'public' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
25 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
26 |
'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
27 |
'capability_type' => 'post', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
28 |
'map_meta_cap' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
29 |
'hierarchical' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
30 |
'rewrite' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
31 |
'query_var' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
32 |
'delete_with_user' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
33 |
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
34 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
35 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
36 |
register_post_type( 'page', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
37 |
'labels' => array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
38 |
'name_admin_bar' => _x( 'Page', 'add new on admin bar' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
39 |
), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
40 |
'public' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
41 |
'publicly_queryable' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
42 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
43 |
'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
44 |
'capability_type' => 'page', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
45 |
'map_meta_cap' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
46 |
'hierarchical' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
47 |
'rewrite' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
48 |
'query_var' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
49 |
'delete_with_user' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
50 |
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
51 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
52 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
53 |
register_post_type( 'attachment', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
54 |
'labels' => array( |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
55 |
'name' => _x('Media', 'post type general name'), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
56 |
'name_admin_bar' => _x( 'Media', 'add new from admin bar' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
57 |
'add_new' => _x( 'Add New', 'add new media' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
58 |
'edit_item' => __( 'Edit Media' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
59 |
'view_item' => __( 'View Attachment Page' ), |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
60 |
), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
61 |
'public' => true, |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
62 |
'show_ui' => true, |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
63 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
64 |
'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
65 |
'capability_type' => 'post', |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
66 |
'capabilities' => array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
67 |
'create_posts' => 'upload_files', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
68 |
), |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
69 |
'map_meta_cap' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
70 |
'hierarchical' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
71 |
'rewrite' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
72 |
'query_var' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
73 |
'show_in_nav_menus' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
74 |
'delete_with_user' => true, |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
75 |
'supports' => array( 'title', 'author', 'comments' ), |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
76 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
77 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
78 |
register_post_type( 'revision', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
79 |
'labels' => array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
80 |
'name' => __( 'Revisions' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
81 |
'singular_name' => __( 'Revision' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
82 |
), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
83 |
'public' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
84 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
85 |
'_edit_link' => 'revision.php?revision=%d', /* internal use only. don't use this when registering your own post type. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
86 |
'capability_type' => 'post', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
87 |
'map_meta_cap' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
88 |
'hierarchical' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
89 |
'rewrite' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
90 |
'query_var' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
91 |
'can_export' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
92 |
'delete_with_user' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
93 |
'supports' => array( 'author' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
94 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
95 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
96 |
register_post_type( 'nav_menu_item', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
97 |
'labels' => array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
98 |
'name' => __( 'Navigation Menu Items' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
99 |
'singular_name' => __( 'Navigation Menu Item' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
100 |
), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
101 |
'public' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
102 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
103 |
'hierarchical' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
104 |
'rewrite' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
105 |
'delete_with_user' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
106 |
'query_var' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
107 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
108 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
109 |
register_post_status( 'publish', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
110 |
'label' => _x( 'Published', 'post' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
111 |
'public' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
112 |
'_builtin' => true, /* internal use only. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
113 |
'label_count' => _n_noop( 'Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
114 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
115 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
116 |
register_post_status( 'future', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
117 |
'label' => _x( 'Scheduled', 'post' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
118 |
'protected' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
119 |
'_builtin' => true, /* internal use only. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
120 |
'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
121 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
122 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
123 |
register_post_status( 'draft', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
124 |
'label' => _x( 'Draft', 'post' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
125 |
'protected' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
126 |
'_builtin' => true, /* internal use only. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
127 |
'label_count' => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
128 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
129 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
130 |
register_post_status( 'pending', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
131 |
'label' => _x( 'Pending', 'post' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
132 |
'protected' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
133 |
'_builtin' => true, /* internal use only. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
134 |
'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
135 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
136 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
137 |
register_post_status( 'private', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
138 |
'label' => _x( 'Private', 'post' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
139 |
'private' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
140 |
'_builtin' => true, /* internal use only. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
141 |
'label_count' => _n_noop( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
142 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
143 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
144 |
register_post_status( 'trash', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
145 |
'label' => _x( 'Trash', 'post' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
146 |
'internal' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
147 |
'_builtin' => true, /* internal use only. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
148 |
'label_count' => _n_noop( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
149 |
'show_in_admin_status_list' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
150 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
151 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
152 |
register_post_status( 'auto-draft', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
153 |
'label' => 'auto-draft', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
154 |
'internal' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
155 |
'_builtin' => true, /* internal use only. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
156 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
157 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
158 |
register_post_status( 'inherit', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
159 |
'label' => 'inherit', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
160 |
'internal' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
161 |
'_builtin' => true, /* internal use only. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
162 |
'exclude_from_search' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
163 |
) ); |
136 | 164 |
} |
165 |
add_action( 'init', 'create_initial_post_types', 0 ); // highest priority |
|
166 |
||
167 |
/** |
|
168 |
* Retrieve attached file path based on attachment ID. |
|
169 |
* |
|
170 |
* You can optionally send it through the 'get_attached_file' filter, but by |
|
171 |
* default it will just return the file path unfiltered. |
|
172 |
* |
|
173 |
* The function works by getting the single post meta name, named |
|
174 |
* '_wp_attached_file' and returning it. This is a convenience function to |
|
175 |
* prevent looking up the meta name and provide a mechanism for sending the |
|
176 |
* attached filename through a filter. |
|
177 |
* |
|
178 |
* @since 2.0.0 |
|
179 |
* @uses apply_filters() Calls 'get_attached_file' on file path and attachment ID. |
|
180 |
* |
|
181 |
* @param int $attachment_id Attachment ID. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
182 |
* @param bool $unfiltered Whether to apply filters. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
183 |
* @return string|bool The file path to the attached file, or false if the attachment does not exist. |
136 | 184 |
*/ |
185 |
function get_attached_file( $attachment_id, $unfiltered = false ) { |
|
186 |
$file = get_post_meta( $attachment_id, '_wp_attached_file', true ); |
|
187 |
// If the file is relative, prepend upload dir |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
188 |
if ( $file && 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) ) |
136 | 189 |
$file = $uploads['basedir'] . "/$file"; |
190 |
if ( $unfiltered ) |
|
191 |
return $file; |
|
192 |
return apply_filters( 'get_attached_file', $file, $attachment_id ); |
|
193 |
} |
|
194 |
||
195 |
/** |
|
196 |
* Update attachment file path based on attachment ID. |
|
197 |
* |
|
198 |
* Used to update the file path of the attachment, which uses post meta name |
|
199 |
* '_wp_attached_file' to store the path of the attachment. |
|
200 |
* |
|
201 |
* @since 2.1.0 |
|
202 |
* @uses apply_filters() Calls 'update_attached_file' on file path and attachment ID. |
|
203 |
* |
|
204 |
* @param int $attachment_id Attachment ID |
|
205 |
* @param string $file File path for the attachment |
|
206 |
* @return bool False on failure, true on success. |
|
207 |
*/ |
|
208 |
function update_attached_file( $attachment_id, $file ) { |
|
209 |
if ( !get_post( $attachment_id ) ) |
|
210 |
return false; |
|
211 |
||
212 |
$file = apply_filters( 'update_attached_file', $file, $attachment_id ); |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
213 |
if ( $file = _wp_relative_upload_path( $file ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
214 |
return update_post_meta( $attachment_id, '_wp_attached_file', $file ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
215 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
216 |
return delete_post_meta( $attachment_id, '_wp_attached_file' ); |
136 | 217 |
} |
218 |
||
219 |
/** |
|
220 |
* Return relative path to an uploaded file. |
|
221 |
* |
|
222 |
* The path is relative to the current upload dir. |
|
223 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
224 |
* @since 2.9.0 |
136 | 225 |
* @uses apply_filters() Calls '_wp_relative_upload_path' on file path. |
226 |
* |
|
227 |
* @param string $path Full path to the file |
|
228 |
* @return string relative path on success, unchanged path on failure. |
|
229 |
*/ |
|
230 |
function _wp_relative_upload_path( $path ) { |
|
231 |
$new_path = $path; |
|
232 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
233 |
$uploads = wp_upload_dir(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
234 |
if ( 0 === strpos( $new_path, $uploads['basedir'] ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
235 |
$new_path = str_replace( $uploads['basedir'], '', $new_path ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
236 |
$new_path = ltrim( $new_path, '/' ); |
136 | 237 |
} |
238 |
||
239 |
return apply_filters( '_wp_relative_upload_path', $new_path, $path ); |
|
240 |
} |
|
241 |
||
242 |
/** |
|
243 |
* Retrieve all children of the post parent ID. |
|
244 |
* |
|
245 |
* Normally, without any enhancements, the children would apply to pages. In the |
|
246 |
* context of the inner workings of WordPress, pages, posts, and attachments |
|
247 |
* share the same table, so therefore the functionality could apply to any one |
|
248 |
* of them. It is then noted that while this function does not work on posts, it |
|
249 |
* does not mean that it won't work on posts. It is recommended that you know |
|
250 |
* what context you wish to retrieve the children of. |
|
251 |
* |
|
252 |
* Attachments may also be made the child of a post, so if that is an accurate |
|
253 |
* statement (which needs to be verified), it would then be possible to get |
|
254 |
* all of the attachments for a post. Attachments have since changed since |
|
255 |
* version 2.5, so this is most likely unaccurate, but serves generally as an |
|
256 |
* example of what is possible. |
|
257 |
* |
|
258 |
* The arguments listed as defaults are for this function and also of the |
|
259 |
* {@link get_posts()} function. The arguments are combined with the |
|
260 |
* get_children defaults and are then passed to the {@link get_posts()} |
|
261 |
* function, which accepts additional arguments. You can replace the defaults in |
|
262 |
* this function, listed below and the additional arguments listed in the |
|
263 |
* {@link get_posts()} function. |
|
264 |
* |
|
265 |
* The 'post_parent' is the most important argument and important attention |
|
266 |
* needs to be paid to the $args parameter. If you pass either an object or an |
|
267 |
* integer (number), then just the 'post_parent' is grabbed and everything else |
|
268 |
* is lost. If you don't specify any arguments, then it is assumed that you are |
|
269 |
* in The Loop and the post parent will be grabbed for from the current post. |
|
270 |
* |
|
271 |
* The 'post_parent' argument is the ID to get the children. The 'numberposts' |
|
272 |
* is the amount of posts to retrieve that has a default of '-1', which is |
|
273 |
* used to get all of the posts. Giving a number higher than 0 will only |
|
274 |
* retrieve that amount of posts. |
|
275 |
* |
|
276 |
* The 'post_type' and 'post_status' arguments can be used to choose what |
|
277 |
* criteria of posts to retrieve. The 'post_type' can be anything, but WordPress |
|
278 |
* post types are 'post', 'pages', and 'attachments'. The 'post_status' |
|
279 |
* argument will accept any post status within the write administration panels. |
|
280 |
* |
|
281 |
* @see get_posts() Has additional arguments that can be replaced. |
|
282 |
* @internal Claims made in the long description might be inaccurate. |
|
283 |
* |
|
284 |
* @since 2.0.0 |
|
285 |
* |
|
286 |
* @param mixed $args Optional. User defined arguments for replacing the defaults. |
|
287 |
* @param string $output Optional. Constant for return type, either OBJECT (default), ARRAY_A, ARRAY_N. |
|
288 |
* @return array|bool False on failure and the type will be determined by $output parameter. |
|
289 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
290 |
function get_children($args = '', $output = OBJECT) { |
136 | 291 |
$kids = array(); |
292 |
if ( empty( $args ) ) { |
|
293 |
if ( isset( $GLOBALS['post'] ) ) { |
|
294 |
$args = array('post_parent' => (int) $GLOBALS['post']->post_parent ); |
|
295 |
} else { |
|
296 |
return $kids; |
|
297 |
} |
|
298 |
} elseif ( is_object( $args ) ) { |
|
299 |
$args = array('post_parent' => (int) $args->post_parent ); |
|
300 |
} elseif ( is_numeric( $args ) ) { |
|
301 |
$args = array('post_parent' => (int) $args); |
|
302 |
} |
|
303 |
||
304 |
$defaults = array( |
|
305 |
'numberposts' => -1, 'post_type' => 'any', |
|
306 |
'post_status' => 'any', 'post_parent' => 0, |
|
307 |
); |
|
308 |
||
309 |
$r = wp_parse_args( $args, $defaults ); |
|
310 |
||
311 |
$children = get_posts( $r ); |
|
312 |
||
313 |
if ( !$children ) |
|
314 |
return $kids; |
|
315 |
||
316 |
update_post_cache($children); |
|
317 |
||
318 |
foreach ( $children as $key => $child ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
319 |
$kids[$child->ID] = $children[$key]; |
136 | 320 |
|
321 |
if ( $output == OBJECT ) { |
|
322 |
return $kids; |
|
323 |
} elseif ( $output == ARRAY_A ) { |
|
324 |
foreach ( (array) $kids as $kid ) |
|
325 |
$weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]); |
|
326 |
return $weeuns; |
|
327 |
} elseif ( $output == ARRAY_N ) { |
|
328 |
foreach ( (array) $kids as $kid ) |
|
329 |
$babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID])); |
|
330 |
return $babes; |
|
331 |
} else { |
|
332 |
return $kids; |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
/** |
|
337 |
* Get extended entry info (<!--more-->). |
|
338 |
* |
|
339 |
* There should not be any space after the second dash and before the word |
|
340 |
* 'more'. There can be text or space(s) after the word 'more', but won't be |
|
341 |
* referenced. |
|
342 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
343 |
* The returned array has 'main', 'extended', and 'more_text' keys. Main has the text before |
136 | 344 |
* the <code><!--more--></code>. The 'extended' key has the content after the |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
345 |
* <code><!--more--></code> comment. The 'more_text' key has the custom "Read More" text. |
136 | 346 |
* |
347 |
* @since 1.0.0 |
|
348 |
* |
|
349 |
* @param string $post Post content. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
350 |
* @return array Post before ('main'), after ('extended'), and custom readmore ('more_text'). |
136 | 351 |
*/ |
352 |
function get_extended($post) { |
|
353 |
//Match the new style more links |
|
354 |
if ( preg_match('/<!--more(.*?)?-->/', $post, $matches) ) { |
|
355 |
list($main, $extended) = explode($matches[0], $post, 2); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
356 |
$more_text = $matches[1]; |
136 | 357 |
} else { |
358 |
$main = $post; |
|
359 |
$extended = ''; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
360 |
$more_text = ''; |
136 | 361 |
} |
362 |
||
363 |
// Strip leading and trailing whitespace |
|
364 |
$main = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $main); |
|
365 |
$extended = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $extended); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
366 |
$more_text = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $more_text); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
367 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
368 |
return array( 'main' => $main, 'extended' => $extended, 'more_text' => $more_text ); |
136 | 369 |
} |
370 |
||
371 |
/** |
|
372 |
* Retrieves post data given a post ID or post object. |
|
373 |
* |
|
374 |
* See {@link sanitize_post()} for optional $filter values. Also, the parameter |
|
375 |
* $post, must be given as a variable, since it is passed by reference. |
|
376 |
* |
|
377 |
* @since 1.5.1 |
|
378 |
* @uses $wpdb |
|
379 |
* @link http://codex.wordpress.org/Function_Reference/get_post |
|
380 |
* |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
381 |
* @param int|object $post Post ID or post object. Optional, default is the current post from the loop. |
136 | 382 |
* @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N. |
383 |
* @param string $filter Optional, default is raw. |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
384 |
* @return WP_Post|null WP_Post on success or null on failure |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
385 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
386 |
function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
387 |
if ( empty( $post ) && isset( $GLOBALS['post'] ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
388 |
$post = $GLOBALS['post']; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
389 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
390 |
if ( is_a( $post, 'WP_Post' ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
391 |
$_post = $post; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
392 |
} elseif ( is_object( $post ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
393 |
if ( empty( $post->filter ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
394 |
$_post = sanitize_post( $post, 'raw' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
395 |
$_post = new WP_Post( $_post ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
396 |
} elseif ( 'raw' == $post->filter ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
397 |
$_post = new WP_Post( $post ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
398 |
} else { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
399 |
$_post = WP_Post::get_instance( $post->ID ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
400 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
401 |
} else { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
402 |
$_post = WP_Post::get_instance( $post ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
403 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
404 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
405 |
if ( ! $_post ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
406 |
return null; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
407 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
408 |
$_post = $_post->filter( $filter ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
409 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
410 |
if ( $output == ARRAY_A ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
411 |
return $_post->to_array(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
412 |
elseif ( $output == ARRAY_N ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
413 |
return array_values( $_post->to_array() ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
414 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
415 |
return $_post; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
416 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
417 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
418 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
419 |
* WordPress Post class. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
420 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
421 |
* @since 3.5.0 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
422 |
* |
136 | 423 |
*/ |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
424 |
final class WP_Post { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
425 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
426 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
427 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
428 |
* @var int |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
429 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
430 |
public $ID; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
431 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
432 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
433 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
434 |
* @var int |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
435 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
436 |
public $post_author = 0; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
437 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
438 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
439 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
440 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
441 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
442 |
public $post_date = '0000-00-00 00:00:00'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
443 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
444 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
445 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
446 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
447 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
448 |
public $post_date_gmt = '0000-00-00 00:00:00'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
449 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
450 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
451 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
452 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
453 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
454 |
public $post_content = ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
455 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
456 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
457 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
458 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
459 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
460 |
public $post_title = ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
461 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
462 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
463 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
464 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
465 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
466 |
public $post_excerpt = ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
467 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
468 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
469 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
470 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
471 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
472 |
public $post_status = 'publish'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
473 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
474 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
475 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
476 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
477 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
478 |
public $comment_status = 'open'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
479 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
480 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
481 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
482 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
483 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
484 |
public $ping_status = 'open'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
485 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
486 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
487 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
488 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
489 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
490 |
public $post_password = ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
491 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
492 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
493 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
494 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
495 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
496 |
public $post_name = ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
497 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
498 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
499 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
500 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
501 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
502 |
public $to_ping = ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
503 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
504 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
505 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
506 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
507 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
508 |
public $pinged = ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
509 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
510 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
511 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
512 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
513 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
514 |
public $post_modified = '0000-00-00 00:00:00'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
515 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
516 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
517 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
518 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
519 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
520 |
public $post_modified_gmt = '0000-00-00 00:00:00'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
521 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
522 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
523 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
524 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
525 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
526 |
public $post_content_filtered = ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
527 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
528 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
529 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
530 |
* @var int |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
531 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
532 |
public $post_parent = 0; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
533 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
534 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
535 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
536 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
537 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
538 |
public $guid = ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
539 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
540 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
541 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
542 |
* @var int |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
543 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
544 |
public $menu_order = 0; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
545 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
546 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
547 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
548 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
549 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
550 |
public $post_type = 'post'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
551 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
552 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
553 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
554 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
555 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
556 |
public $post_mime_type = ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
557 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
558 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
559 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
560 |
* @var int |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
561 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
562 |
public $comment_count = 0; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
563 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
564 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
565 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
566 |
* @var string |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
567 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
568 |
public $filter; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
569 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
570 |
public static function get_instance( $post_id ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
571 |
global $wpdb; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
572 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
573 |
$post_id = (int) $post_id; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
574 |
if ( ! $post_id ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
575 |
return false; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
576 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
577 |
$_post = wp_cache_get( $post_id, 'posts' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
578 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
579 |
if ( ! $_post ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
580 |
$_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
581 |
|
136 | 582 |
if ( ! $_post ) |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
583 |
return false; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
584 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
585 |
$_post = sanitize_post( $_post, 'raw' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
586 |
wp_cache_add( $_post->ID, $_post, 'posts' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
587 |
} elseif ( empty( $_post->filter ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
588 |
$_post = sanitize_post( $_post, 'raw' ); |
136 | 589 |
} |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
590 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
591 |
return new WP_Post( $_post ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
592 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
593 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
594 |
public function __construct( $post ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
595 |
foreach ( get_object_vars( $post ) as $key => $value ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
596 |
$this->$key = $value; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
597 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
598 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
599 |
public function __isset( $key ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
600 |
if ( 'ancestors' == $key ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
601 |
return true; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
602 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
603 |
if ( 'page_template' == $key ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
604 |
return ( 'page' == $this->post_type ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
605 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
606 |
if ( 'post_category' == $key ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
607 |
return true; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
608 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
609 |
if ( 'tags_input' == $key ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
610 |
return true; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
611 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
612 |
return metadata_exists( 'post', $this->ID, $key ); |
136 | 613 |
} |
614 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
615 |
public function __get( $key ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
616 |
if ( 'page_template' == $key && $this->__isset( $key ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
617 |
return get_post_meta( $this->ID, '_wp_page_template', true ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
618 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
619 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
620 |
if ( 'post_category' == $key ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
621 |
if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
622 |
$terms = get_the_terms( $this, 'category' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
623 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
624 |
if ( empty( $terms ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
625 |
return array(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
626 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
627 |
return wp_list_pluck( $terms, 'term_id' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
628 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
629 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
630 |
if ( 'tags_input' == $key ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
631 |
if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
632 |
$terms = get_the_terms( $this, 'post_tag' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
633 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
634 |
if ( empty( $terms ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
635 |
return array(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
636 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
637 |
return wp_list_pluck( $terms, 'name' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
638 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
639 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
640 |
// Rest of the values need filtering |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
641 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
642 |
if ( 'ancestors' == $key ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
643 |
$value = get_post_ancestors( $this ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
644 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
645 |
$value = get_post_meta( $this->ID, $key, true ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
646 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
647 |
if ( $this->filter ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
648 |
$value = sanitize_post_field( $key, $value, $this->ID, $this->filter ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
649 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
650 |
return $value; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
651 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
652 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
653 |
public function filter( $filter ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
654 |
if ( $this->filter == $filter ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
655 |
return $this; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
656 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
657 |
if ( $filter == 'raw' ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
658 |
return self::get_instance( $this->ID ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
659 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
660 |
return sanitize_post( $this, $filter ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
661 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
662 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
663 |
public function to_array() { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
664 |
$post = get_object_vars( $this ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
665 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
666 |
foreach ( array( 'ancestors', 'page_template', 'post_category', 'tags_input' ) as $key ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
667 |
if ( $this->__isset( $key ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
668 |
$post[ $key ] = $this->__get( $key ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
669 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
670 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
671 |
return $post; |
136 | 672 |
} |
673 |
} |
|
674 |
||
675 |
/** |
|
676 |
* Retrieve ancestors of a post. |
|
677 |
* |
|
678 |
* @since 2.5.0 |
|
679 |
* |
|
680 |
* @param int|object $post Post ID or post object |
|
681 |
* @return array Ancestor IDs or empty array if none are found. |
|
682 |
*/ |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
683 |
function get_post_ancestors( $post ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
684 |
if ( ! $post ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
685 |
return false; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
686 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
687 |
$post = get_post( $post ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
688 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
689 |
if ( empty( $post->post_parent ) || $post->post_parent == $post->ID ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
690 |
return array(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
691 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
692 |
$ancestors = array(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
693 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
694 |
$id = $ancestors[] = $post->post_parent; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
695 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
696 |
while ( $ancestor = get_post( $id ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
697 |
// Loop detection: If the ancestor has been seen before, break. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
698 |
if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
699 |
break; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
700 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
701 |
$id = $ancestors[] = $ancestor->post_parent; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
702 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
703 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
704 |
return $ancestors; |
136 | 705 |
} |
706 |
||
707 |
/** |
|
708 |
* Retrieve data from a post field based on Post ID. |
|
709 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
710 |
* Examples of the post field will be, 'post_type', 'post_status', 'post_content', |
136 | 711 |
* etc and based off of the post object property or key names. |
712 |
* |
|
713 |
* The context values are based off of the taxonomy filter functions and |
|
714 |
* supported values are found within those functions. |
|
715 |
* |
|
716 |
* @since 2.3.0 |
|
717 |
* @uses sanitize_post_field() See for possible $context values. |
|
718 |
* |
|
719 |
* @param string $field Post field name |
|
720 |
* @param id $post Post ID |
|
721 |
* @param string $context Optional. How to filter the field. Default is display. |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
722 |
* @return bool|string False on failure or returns the value in post field |
136 | 723 |
*/ |
724 |
function get_post_field( $field, $post, $context = 'display' ) { |
|
725 |
$post = get_post( $post ); |
|
726 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
727 |
if ( !$post ) |
136 | 728 |
return ''; |
729 |
||
730 |
if ( !isset($post->$field) ) |
|
731 |
return ''; |
|
732 |
||
733 |
return sanitize_post_field($field, $post->$field, $post->ID, $context); |
|
734 |
} |
|
735 |
||
736 |
/** |
|
737 |
* Retrieve the mime type of an attachment based on the ID. |
|
738 |
* |
|
739 |
* This function can be used with any post type, but it makes more sense with |
|
740 |
* attachments. |
|
741 |
* |
|
742 |
* @since 2.0.0 |
|
743 |
* |
|
744 |
* @param int $ID Optional. Post ID. |
|
745 |
* @return bool|string False on failure or returns the mime type |
|
746 |
*/ |
|
747 |
function get_post_mime_type($ID = '') { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
748 |
$post = get_post($ID); |
136 | 749 |
|
750 |
if ( is_object($post) ) |
|
751 |
return $post->post_mime_type; |
|
752 |
||
753 |
return false; |
|
754 |
} |
|
755 |
||
756 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
757 |
* Retrieve the format slug for a post |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
758 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
759 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
760 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
761 |
* @param int|object $post A post |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
762 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
763 |
* @return mixed The format if successful. False if no format is set. WP_Error if errors. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
764 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
765 |
function get_post_format( $post = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
766 |
$post = get_post($post); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
767 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
768 |
if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
769 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
770 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
771 |
$_format = get_the_terms( $post->ID, 'post_format' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
772 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
773 |
if ( empty( $_format ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
774 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
775 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
776 |
$format = array_shift( $_format ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
777 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
778 |
return ( str_replace('post-format-', '', $format->slug ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
779 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
780 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
781 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
782 |
* Check if a post has a particular format |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
783 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
784 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
785 |
* @uses has_term() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
786 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
787 |
* @param string $format The format to check for |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
788 |
* @param object|id $post The post to check. If not supplied, defaults to the current post if used in the loop. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
789 |
* @return bool True if the post has the format, false otherwise. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
790 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
791 |
function has_post_format( $format, $post = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
792 |
return has_term('post-format-' . sanitize_key($format), 'post_format', $post); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
793 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
794 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
795 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
796 |
* Assign a format to a post |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
797 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
798 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
799 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
800 |
* @param int|object $post The post for which to assign a format |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
801 |
* @param string $format A format to assign. Use an empty string or array to remove all formats from the post. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
802 |
* @return mixed WP_Error on error. Array of affected term IDs on success. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
803 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
804 |
function set_post_format( $post, $format ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
805 |
$post = get_post($post); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
806 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
807 |
if ( empty($post) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
808 |
return new WP_Error('invalid_post', __('Invalid post')); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
809 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
810 |
if ( !empty($format) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
811 |
$format = sanitize_key($format); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
812 |
if ( 'standard' == $format || !in_array( $format, array_keys( get_post_format_slugs() ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
813 |
$format = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
814 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
815 |
$format = 'post-format-' . $format; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
816 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
817 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
818 |
return wp_set_post_terms($post->ID, $format, 'post_format'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
819 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
820 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
821 |
/** |
136 | 822 |
* Retrieve the post status based on the Post ID. |
823 |
* |
|
824 |
* If the post ID is of an attachment, then the parent post status will be given |
|
825 |
* instead. |
|
826 |
* |
|
827 |
* @since 2.0.0 |
|
828 |
* |
|
829 |
* @param int $ID Post ID |
|
830 |
* @return string|bool Post status or false on failure. |
|
831 |
*/ |
|
832 |
function get_post_status($ID = '') { |
|
833 |
$post = get_post($ID); |
|
834 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
835 |
if ( !is_object($post) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
836 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
837 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
838 |
if ( 'attachment' == $post->post_type ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
839 |
if ( 'private' == $post->post_status ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
840 |
return 'private'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
841 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
842 |
// Unattached attachments are assumed to be published |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
843 |
if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
844 |
return 'publish'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
845 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
846 |
// Inherit status from the parent |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
847 |
if ( $post->post_parent && ( $post->ID != $post->post_parent ) ) |
136 | 848 |
return get_post_status($post->post_parent); |
849 |
} |
|
850 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
851 |
return $post->post_status; |
136 | 852 |
} |
853 |
||
854 |
/** |
|
855 |
* Retrieve all of the WordPress supported post statuses. |
|
856 |
* |
|
857 |
* Posts have a limited set of valid status values, this provides the |
|
858 |
* post_status values and descriptions. |
|
859 |
* |
|
860 |
* @since 2.5.0 |
|
861 |
* |
|
862 |
* @return array List of post statuses. |
|
863 |
*/ |
|
864 |
function get_post_statuses( ) { |
|
865 |
$status = array( |
|
866 |
'draft' => __('Draft'), |
|
867 |
'pending' => __('Pending Review'), |
|
868 |
'private' => __('Private'), |
|
869 |
'publish' => __('Published') |
|
870 |
); |
|
871 |
||
872 |
return $status; |
|
873 |
} |
|
874 |
||
875 |
/** |
|
876 |
* Retrieve all of the WordPress support page statuses. |
|
877 |
* |
|
878 |
* Pages have a limited set of valid status values, this provides the |
|
879 |
* post_status values and descriptions. |
|
880 |
* |
|
881 |
* @since 2.5.0 |
|
882 |
* |
|
883 |
* @return array List of page statuses. |
|
884 |
*/ |
|
885 |
function get_page_statuses( ) { |
|
886 |
$status = array( |
|
887 |
'draft' => __('Draft'), |
|
888 |
'private' => __('Private'), |
|
889 |
'publish' => __('Published') |
|
890 |
); |
|
891 |
||
892 |
return $status; |
|
893 |
} |
|
894 |
||
895 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
896 |
* Register a post status. Do not use before init. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
897 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
898 |
* A simple function for creating or modifying a post status based on the |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
899 |
* parameters given. The function will accept an array (second optional |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
900 |
* parameter), along with a string for the post status name. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
901 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
902 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
903 |
* Optional $args contents: |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
904 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
905 |
* label - A descriptive name for the post status marked for translation. Defaults to $post_status. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
906 |
* public - Whether posts of this status should be shown in the front end of the site. Defaults to true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
907 |
* exclude_from_search - Whether to exclude posts with this post status from search results. Defaults to false. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
908 |
* show_in_admin_all_list - Whether to include posts in the edit listing for their post type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
909 |
* show_in_admin_status_list - Show in the list of statuses with post counts at the top of the edit |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
910 |
* listings, e.g. All (12) | Published (9) | My Custom Status (2) ... |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
911 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
912 |
* Arguments prefixed with an _underscore shouldn't be used by plugins and themes. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
913 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
914 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
915 |
* @subpackage Post |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
916 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
917 |
* @uses $wp_post_statuses Inserts new post status object into the list |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
918 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
919 |
* @param string $post_status Name of the post status. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
920 |
* @param array|string $args See above description. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
921 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
922 |
function register_post_status($post_status, $args = array()) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
923 |
global $wp_post_statuses; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
924 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
925 |
if (!is_array($wp_post_statuses)) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
926 |
$wp_post_statuses = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
927 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
928 |
// Args prefixed with an underscore are reserved for internal use. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
929 |
$defaults = array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
930 |
'label' => false, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
931 |
'label_count' => false, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
932 |
'exclude_from_search' => null, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
933 |
'_builtin' => false, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
934 |
'public' => null, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
935 |
'internal' => null, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
936 |
'protected' => null, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
937 |
'private' => null, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
938 |
'publicly_queryable' => null, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
939 |
'show_in_admin_status_list' => null, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
940 |
'show_in_admin_all_list' => null, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
941 |
); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
942 |
$args = wp_parse_args($args, $defaults); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
943 |
$args = (object) $args; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
944 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
945 |
$post_status = sanitize_key($post_status); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
946 |
$args->name = $post_status; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
947 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
948 |
if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
949 |
$args->internal = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
950 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
951 |
if ( null === $args->public ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
952 |
$args->public = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
953 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
954 |
if ( null === $args->private ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
955 |
$args->private = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
956 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
957 |
if ( null === $args->protected ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
958 |
$args->protected = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
959 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
960 |
if ( null === $args->internal ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
961 |
$args->internal = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
962 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
963 |
if ( null === $args->publicly_queryable ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
964 |
$args->publicly_queryable = $args->public; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
965 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
966 |
if ( null === $args->exclude_from_search ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
967 |
$args->exclude_from_search = $args->internal; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
968 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
969 |
if ( null === $args->show_in_admin_all_list ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
970 |
$args->show_in_admin_all_list = !$args->internal; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
971 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
972 |
if ( null === $args->show_in_admin_status_list ) |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
973 |
$args->show_in_admin_status_list = !$args->internal; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
974 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
975 |
if ( false === $args->label ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
976 |
$args->label = $post_status; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
977 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
978 |
if ( false === $args->label_count ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
979 |
$args->label_count = array( $args->label, $args->label ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
980 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
981 |
$wp_post_statuses[$post_status] = $args; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
982 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
983 |
return $args; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
984 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
985 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
986 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
987 |
* Retrieve a post status object by name |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
988 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
989 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
990 |
* @subpackage Post |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
991 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
992 |
* @uses $wp_post_statuses |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
993 |
* @see register_post_status |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
994 |
* @see get_post_statuses |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
995 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
996 |
* @param string $post_status The name of a registered post status |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
997 |
* @return object A post status object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
998 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
999 |
function get_post_status_object( $post_status ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1000 |
global $wp_post_statuses; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1001 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1002 |
if ( empty($wp_post_statuses[$post_status]) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1003 |
return null; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1004 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1005 |
return $wp_post_statuses[$post_status]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1006 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1007 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1008 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1009 |
* Get a list of all registered post status objects. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1010 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1011 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1012 |
* @subpackage Post |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1013 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1014 |
* @uses $wp_post_statuses |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1015 |
* @see register_post_status |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1016 |
* @see get_post_status_object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1017 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1018 |
* @param array|string $args An array of key => value arguments to match against the post status objects. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1019 |
* @param string $output The type of output to return, either post status 'names' or 'objects'. 'names' is the default. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1020 |
* @param string $operator The logical operation to perform. 'or' means only one element |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1021 |
* from the array needs to match; 'and' means all elements must match. The default is 'and'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1022 |
* @return array A list of post status names or objects |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1023 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1024 |
function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1025 |
global $wp_post_statuses; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1026 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1027 |
$field = ('names' == $output) ? 'name' : false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1028 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1029 |
return wp_filter_object_list($wp_post_statuses, $args, $operator, $field); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1030 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1031 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1032 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1033 |
* Whether the post type is hierarchical. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1034 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1035 |
* A false return value might also mean that the post type does not exist. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1036 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1037 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1038 |
* @see get_post_type_object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1039 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1040 |
* @param string $post_type Post type name |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1041 |
* @return bool Whether post type is hierarchical. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1042 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1043 |
function is_post_type_hierarchical( $post_type ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1044 |
if ( ! post_type_exists( $post_type ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1045 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1046 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1047 |
$post_type = get_post_type_object( $post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1048 |
return $post_type->hierarchical; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1049 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1050 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1051 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1052 |
* Checks if a post type is registered. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1053 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1054 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1055 |
* @uses get_post_type_object() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1056 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1057 |
* @param string $post_type Post type name |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1058 |
* @return bool Whether post type is registered. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1059 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1060 |
function post_type_exists( $post_type ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1061 |
return (bool) get_post_type_object( $post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1062 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1063 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1064 |
/** |
136 | 1065 |
* Retrieve the post type of the current post or of a given post. |
1066 |
* |
|
1067 |
* @since 2.1.0 |
|
1068 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1069 |
* @uses $post The Loop current post global |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1070 |
* |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1071 |
* @param mixed $post Optional. Post object or post ID. |
136 | 1072 |
* @return bool|string post type or false on failure. |
1073 |
*/ |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1074 |
function get_post_type( $post = null ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1075 |
if ( $post = get_post( $post ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1076 |
return $post->post_type; |
136 | 1077 |
|
1078 |
return false; |
|
1079 |
} |
|
1080 |
||
1081 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1082 |
* Retrieve a post type object by name |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1083 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1084 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1085 |
* @subpackage Post |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1086 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1087 |
* @uses $wp_post_types |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1088 |
* @see register_post_type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1089 |
* @see get_post_types |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1090 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1091 |
* @param string $post_type The name of a registered post type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1092 |
* @return object A post type object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1093 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1094 |
function get_post_type_object( $post_type ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1095 |
global $wp_post_types; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1096 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1097 |
if ( empty($wp_post_types[$post_type]) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1098 |
return null; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1099 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1100 |
return $wp_post_types[$post_type]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1101 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1102 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1103 |
/** |
136 | 1104 |
* Get a list of all registered post type objects. |
1105 |
* |
|
1106 |
* @package WordPress |
|
1107 |
* @subpackage Post |
|
1108 |
* @since 2.9.0 |
|
1109 |
* @uses $wp_post_types |
|
1110 |
* @see register_post_type |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1111 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1112 |
* @param array|string $args An array of key => value arguments to match against the post type objects. |
136 | 1113 |
* @param string $output The type of output to return, either post type 'names' or 'objects'. 'names' is the default. |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1114 |
* @param string $operator The logical operation to perform. 'or' means only one element |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1115 |
* from the array needs to match; 'and' means all elements must match. The default is 'and'. |
136 | 1116 |
* @return array A list of post type names or objects |
1117 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1118 |
function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) { |
136 | 1119 |
global $wp_post_types; |
1120 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1121 |
$field = ('names' == $output) ? 'name' : false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1122 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1123 |
return wp_filter_object_list($wp_post_types, $args, $operator, $field); |
136 | 1124 |
} |
1125 |
||
1126 |
/** |
|
1127 |
* Register a post type. Do not use before init. |
|
1128 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1129 |
* A function for creating or modifying a post type based on the |
136 | 1130 |
* parameters given. The function will accept an array (second optional |
1131 |
* parameter), along with a string for the post type name. |
|
1132 |
* |
|
1133 |
* Optional $args contents: |
|
1134 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1135 |
* - label - Name of the post type shown in the menu. Usually plural. If not set, labels['name'] will be used. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1136 |
* - labels - An array of labels for this post type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1137 |
* * If not set, post labels are inherited for non-hierarchical types and page labels for hierarchical ones. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1138 |
* * You can see accepted values in {@link get_post_type_labels()}. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1139 |
* - description - A short descriptive summary of what the post type is. Defaults to blank. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1140 |
* - public - Whether a post type is intended for use publicly either via the admin interface or by front-end users. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1141 |
* * Defaults to false. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1142 |
* * While the default settings of exclude_from_search, publicly_queryable, show_ui, and show_in_nav_menus are |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1143 |
* inherited from public, each does not rely on this relationship and controls a very specific intention. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1144 |
* - exclude_from_search - Whether to exclude posts with this post type from front end search results. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1145 |
* * If not set, the the opposite of public's current value is used. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1146 |
* - publicly_queryable - Whether queries can be performed on the front end for the post type as part of parse_request(). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1147 |
* * ?post_type={post_type_key} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1148 |
* * ?{post_type_key}={single_post_slug} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1149 |
* * ?{post_type_query_var}={single_post_slug} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1150 |
* * If not set, the default is inherited from public. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1151 |
* - show_ui - Whether to generate a default UI for managing this post type in the admin. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1152 |
* * If not set, the default is inherited from public. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1153 |
* - show_in_nav_menus - Makes this post type available for selection in navigation menus. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1154 |
* * If not set, the default is inherited from public. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1155 |
* - show_in_menu - Where to show the post type in the admin menu. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1156 |
* * If true, the post type is shown in its own top level menu. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1157 |
* * If false, no menu is shown |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1158 |
* * If a string of an existing top level menu (eg. 'tools.php' or 'edit.php?post_type=page'), the post type will |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1159 |
* be placed as a sub menu of that. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1160 |
* * show_ui must be true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1161 |
* * If not set, the default is inherited from show_ui |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1162 |
* - show_in_admin_bar - Makes this post type available via the admin bar. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1163 |
* * If not set, the default is inherited from show_in_menu |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1164 |
* - menu_position - The position in the menu order the post type should appear. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1165 |
* * show_in_menu must be true |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1166 |
* * Defaults to null, which places it at the bottom of its area. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1167 |
* - menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1168 |
* - capability_type - The string to use to build the read, edit, and delete capabilities. Defaults to 'post'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1169 |
* * May be passed as an array to allow for alternative plurals when using this argument as a base to construct the |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1170 |
* capabilities, e.g. array('story', 'stories'). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1171 |
* - capabilities - Array of capabilities for this post type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1172 |
* * By default the capability_type is used as a base to construct capabilities. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1173 |
* * You can see accepted values in {@link get_post_type_capabilities()}. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1174 |
* - map_meta_cap - Whether to use the internal default meta capability handling. Defaults to false. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1175 |
* - hierarchical - Whether the post type is hierarchical (e.g. page). Defaults to false. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1176 |
* - supports - An alias for calling add_post_type_support() directly. Defaults to title and editor. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1177 |
* * See {@link add_post_type_support()} for documentation. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1178 |
* - register_meta_box_cb - Provide a callback function that will be called when setting up the |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1179 |
* meta boxes for the edit form. Do remove_meta_box() and add_meta_box() calls in the callback. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1180 |
* - taxonomies - An array of taxonomy identifiers that will be registered for the post type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1181 |
* * Default is no taxonomies. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1182 |
* * Taxonomies can be registered later with register_taxonomy() or register_taxonomy_for_object_type(). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1183 |
* - has_archive - True to enable post type archives. Default is false. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1184 |
* * Will generate the proper rewrite rules if rewrite is enabled. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1185 |
* - rewrite - Triggers the handling of rewrites for this post type. Defaults to true, using $post_type as slug. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1186 |
* * To prevent rewrite, set to false. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1187 |
* * To specify rewrite rules, an array can be passed with any of these keys |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1188 |
* * 'slug' => string Customize the permastruct slug. Defaults to $post_type key |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1189 |
* * 'with_front' => bool Should the permastruct be prepended with WP_Rewrite::$front. Defaults to true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1190 |
* * 'feeds' => bool Should a feed permastruct be built for this post type. Inherits default from has_archive. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1191 |
* * 'pages' => bool Should the permastruct provide for pagination. Defaults to true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1192 |
* * 'ep_mask' => const Assign an endpoint mask. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1193 |
* * If not specified and permalink_epmask is set, inherits from permalink_epmask. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1194 |
* * If not specified and permalink_epmask is not set, defaults to EP_PERMALINK |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1195 |
* - query_var - Sets the query_var key for this post type. Defaults to $post_type key |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1196 |
* * If false, a post type cannot be loaded at ?{query_var}={post_slug} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1197 |
* * If specified as a string, the query ?{query_var_string}={post_slug} will be valid. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1198 |
* - can_export - Allows this post type to be exported. Defaults to true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1199 |
* - delete_with_user - Whether to delete posts of this type when deleting a user. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1200 |
* * If true, posts of this type belonging to the user will be moved to trash when then user is deleted. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1201 |
* * If false, posts of this type belonging to the user will *not* be trashed or deleted. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1202 |
* * If not set (the default), posts are trashed if post_type_supports('author'). Otherwise posts are not trashed or deleted. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1203 |
* - _builtin - true if this post type is a native or "built-in" post_type. THIS IS FOR INTERNAL USE ONLY! |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1204 |
* - _edit_link - URL segement to use for edit link of this post type. THIS IS FOR INTERNAL USE ONLY! |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1205 |
* |
136 | 1206 |
* @since 2.9.0 |
1207 |
* @uses $wp_post_types Inserts new post type object into the list |
|
1208 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1209 |
* @param string $post_type Post type key, must not exceed 20 characters |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1210 |
* @param array|string $args See optional args description above. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1211 |
* @return object|WP_Error the registered post type object, or an error object |
136 | 1212 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1213 |
function register_post_type( $post_type, $args = array() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1214 |
global $wp_post_types, $wp_rewrite, $wp; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1215 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1216 |
if ( !is_array($wp_post_types) ) |
136 | 1217 |
$wp_post_types = array(); |
1218 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1219 |
// Args prefixed with an underscore are reserved for internal use. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1220 |
$defaults = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1221 |
'labels' => array(), 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1222 |
'capability_type' => 'post', 'capabilities' => array(), 'map_meta_cap' => null, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1223 |
'_builtin' => false, '_edit_link' => 'post.php?post=%d', 'hierarchical' => false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1224 |
'public' => false, 'rewrite' => true, 'has_archive' => false, 'query_var' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1225 |
'supports' => array(), 'register_meta_box_cb' => null, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1226 |
'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1227 |
'can_export' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1228 |
'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1229 |
'delete_with_user' => null, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1230 |
); |
136 | 1231 |
$args = wp_parse_args($args, $defaults); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1232 |
$args = (object) $args; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1233 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1234 |
$post_type = sanitize_key($post_type); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1235 |
$args->name = $post_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1236 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1237 |
if ( strlen( $post_type ) > 20 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1238 |
return new WP_Error( 'post_type_too_long', __( 'Post types cannot exceed 20 characters in length' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1239 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1240 |
// If not set, default to the setting for public. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1241 |
if ( null === $args->publicly_queryable ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1242 |
$args->publicly_queryable = $args->public; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1243 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1244 |
// If not set, default to the setting for public. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1245 |
if ( null === $args->show_ui ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1246 |
$args->show_ui = $args->public; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1247 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1248 |
// If not set, default to the setting for show_ui. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1249 |
if ( null === $args->show_in_menu || ! $args->show_ui ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1250 |
$args->show_in_menu = $args->show_ui; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1251 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1252 |
// If not set, default to the whether the full UI is shown. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1253 |
if ( null === $args->show_in_admin_bar ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1254 |
$args->show_in_admin_bar = true === $args->show_in_menu; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1255 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1256 |
// Whether to show this type in nav-menus.php. Defaults to the setting for public. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1257 |
if ( null === $args->show_in_nav_menus ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1258 |
$args->show_in_nav_menus = $args->public; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1259 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1260 |
// If not set, default to true if not public, false if public. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1261 |
if ( null === $args->exclude_from_search ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1262 |
$args->exclude_from_search = !$args->public; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1263 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1264 |
// Back compat with quirky handling in version 3.0. #14122 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1265 |
if ( empty( $args->capabilities ) && null === $args->map_meta_cap && in_array( $args->capability_type, array( 'post', 'page' ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1266 |
$args->map_meta_cap = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1267 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1268 |
if ( null === $args->map_meta_cap ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1269 |
$args->map_meta_cap = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1270 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1271 |
$args->cap = get_post_type_capabilities( $args ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1272 |
unset($args->capabilities); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1273 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1274 |
if ( is_array( $args->capability_type ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1275 |
$args->capability_type = $args->capability_type[0]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1276 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1277 |
if ( ! empty($args->supports) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1278 |
add_post_type_support($post_type, $args->supports); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1279 |
unset($args->supports); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1280 |
} elseif ( false !== $args->supports ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1281 |
// Add default features |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1282 |
add_post_type_support($post_type, array('title', 'editor')); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1283 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1284 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1285 |
if ( false !== $args->query_var && !empty($wp) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1286 |
if ( true === $args->query_var ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1287 |
$args->query_var = $post_type; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1288 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1289 |
$args->query_var = sanitize_title_with_dashes($args->query_var); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1290 |
$wp->add_query_var($args->query_var); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1291 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1292 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1293 |
if ( false !== $args->rewrite && ( is_admin() || '' != get_option('permalink_structure') ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1294 |
if ( ! is_array( $args->rewrite ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1295 |
$args->rewrite = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1296 |
if ( empty( $args->rewrite['slug'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1297 |
$args->rewrite['slug'] = $post_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1298 |
if ( ! isset( $args->rewrite['with_front'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1299 |
$args->rewrite['with_front'] = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1300 |
if ( ! isset( $args->rewrite['pages'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1301 |
$args->rewrite['pages'] = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1302 |
if ( ! isset( $args->rewrite['feeds'] ) || ! $args->has_archive ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1303 |
$args->rewrite['feeds'] = (bool) $args->has_archive; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1304 |
if ( ! isset( $args->rewrite['ep_mask'] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1305 |
if ( isset( $args->permalink_epmask ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1306 |
$args->rewrite['ep_mask'] = $args->permalink_epmask; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1307 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1308 |
$args->rewrite['ep_mask'] = EP_PERMALINK; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1309 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1310 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1311 |
if ( $args->hierarchical ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1312 |
add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name="); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1313 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1314 |
add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name="); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1315 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1316 |
if ( $args->has_archive ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1317 |
$archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1318 |
if ( $args->rewrite['with_front'] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1319 |
$archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1320 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1321 |
$archive_slug = $wp_rewrite->root . $archive_slug; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1322 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1323 |
add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1324 |
if ( $args->rewrite['feeds'] && $wp_rewrite->feeds ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1325 |
$feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1326 |
add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1327 |
add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1328 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1329 |
if ( $args->rewrite['pages'] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1330 |
add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1331 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1332 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1333 |
add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%", $args->rewrite ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1334 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1335 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1336 |
if ( $args->register_meta_box_cb ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1337 |
add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1338 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1339 |
$args->labels = get_post_type_labels( $args ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1340 |
$args->label = $args->labels->name; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1341 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1342 |
$wp_post_types[$post_type] = $args; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1343 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1344 |
add_action( 'future_' . $post_type, '_future_post_hook', 5, 2 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1345 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1346 |
foreach ( $args->taxonomies as $taxonomy ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1347 |
register_taxonomy_for_object_type( $taxonomy, $post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1348 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1349 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1350 |
do_action( 'registered_post_type', $post_type, $args ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1351 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1352 |
return $args; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1353 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1354 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1355 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1356 |
* Builds an object with all post type capabilities out of a post type object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1357 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1358 |
* Post type capabilities use the 'capability_type' argument as a base, if the |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1359 |
* capability is not set in the 'capabilities' argument array or if the |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1360 |
* 'capabilities' argument is not supplied. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1361 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1362 |
* The capability_type argument can optionally be registered as an array, with |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1363 |
* the first value being singular and the second plural, e.g. array('story, 'stories') |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1364 |
* Otherwise, an 's' will be added to the value for the plural form. After |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1365 |
* registration, capability_type will always be a string of the singular value. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1366 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1367 |
* By default, seven keys are accepted as part of the capabilities array: |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1368 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1369 |
* - edit_post, read_post, and delete_post are meta capabilities, which are then |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1370 |
* generally mapped to corresponding primitive capabilities depending on the |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1371 |
* context, which would be the post being edited/read/deleted and the user or |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1372 |
* role being checked. Thus these capabilities would generally not be granted |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1373 |
* directly to users or roles. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1374 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1375 |
* - edit_posts - Controls whether objects of this post type can be edited. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1376 |
* - edit_others_posts - Controls whether objects of this type owned by other users |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1377 |
* can be edited. If the post type does not support an author, then this will |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1378 |
* behave like edit_posts. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1379 |
* - publish_posts - Controls publishing objects of this post type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1380 |
* - read_private_posts - Controls whether private objects can be read. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1381 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1382 |
* These four primitive capabilities are checked in core in various locations. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1383 |
* There are also seven other primitive capabilities which are not referenced |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1384 |
* directly in core, except in map_meta_cap(), which takes the three aforementioned |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1385 |
* meta capabilities and translates them into one or more primitive capabilities |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1386 |
* that must then be checked against the user or role, depending on the context. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1387 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1388 |
* - read - Controls whether objects of this post type can be read. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1389 |
* - delete_posts - Controls whether objects of this post type can be deleted. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1390 |
* - delete_private_posts - Controls whether private objects can be deleted. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1391 |
* - delete_published_posts - Controls whether published objects can be deleted. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1392 |
* - delete_others_posts - Controls whether objects owned by other users can be |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1393 |
* can be deleted. If the post type does not support an author, then this will |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1394 |
* behave like delete_posts. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1395 |
* - edit_private_posts - Controls whether private objects can be edited. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1396 |
* - edit_published_posts - Controls whether published objects can be edited. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1397 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1398 |
* These additional capabilities are only used in map_meta_cap(). Thus, they are |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1399 |
* only assigned by default if the post type is registered with the 'map_meta_cap' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1400 |
* argument set to true (default is false). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1401 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1402 |
* @see map_meta_cap() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1403 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1404 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1405 |
* @param object $args Post type registration arguments |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1406 |
* @return object object with all the capabilities as member variables |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1407 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1408 |
function get_post_type_capabilities( $args ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1409 |
if ( ! is_array( $args->capability_type ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1410 |
$args->capability_type = array( $args->capability_type, $args->capability_type . 's' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1411 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1412 |
// Singular base for meta capabilities, plural base for primitive capabilities. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1413 |
list( $singular_base, $plural_base ) = $args->capability_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1414 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1415 |
$default_capabilities = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1416 |
// Meta capabilities |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1417 |
'edit_post' => 'edit_' . $singular_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1418 |
'read_post' => 'read_' . $singular_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1419 |
'delete_post' => 'delete_' . $singular_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1420 |
// Primitive capabilities used outside of map_meta_cap(): |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1421 |
'edit_posts' => 'edit_' . $plural_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1422 |
'edit_others_posts' => 'edit_others_' . $plural_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1423 |
'publish_posts' => 'publish_' . $plural_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1424 |
'read_private_posts' => 'read_private_' . $plural_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1425 |
); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1426 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1427 |
// Primitive capabilities used within map_meta_cap(): |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1428 |
if ( $args->map_meta_cap ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1429 |
$default_capabilities_for_mapping = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1430 |
'read' => 'read', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1431 |
'delete_posts' => 'delete_' . $plural_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1432 |
'delete_private_posts' => 'delete_private_' . $plural_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1433 |
'delete_published_posts' => 'delete_published_' . $plural_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1434 |
'delete_others_posts' => 'delete_others_' . $plural_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1435 |
'edit_private_posts' => 'edit_private_' . $plural_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1436 |
'edit_published_posts' => 'edit_published_' . $plural_base, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1437 |
); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1438 |
$default_capabilities = array_merge( $default_capabilities, $default_capabilities_for_mapping ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1439 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1440 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1441 |
$capabilities = array_merge( $default_capabilities, $args->capabilities ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1442 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1443 |
// Post creation capability simply maps to edit_posts by default: |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1444 |
if ( ! isset( $capabilities['create_posts'] ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1445 |
$capabilities['create_posts'] = $capabilities['edit_posts']; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1446 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1447 |
// Remember meta capabilities for future reference. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1448 |
if ( $args->map_meta_cap ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1449 |
_post_type_meta_capabilities( $capabilities ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1450 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1451 |
return (object) $capabilities; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1452 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1453 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1454 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1455 |
* Stores or returns a list of post type meta caps for map_meta_cap(). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1456 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1457 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1458 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1459 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1460 |
function _post_type_meta_capabilities( $capabilities = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1461 |
static $meta_caps = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1462 |
if ( null === $capabilities ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1463 |
return $meta_caps; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1464 |
foreach ( $capabilities as $core => $custom ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1465 |
if ( in_array( $core, array( 'read_post', 'delete_post', 'edit_post' ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1466 |
$meta_caps[ $custom ] = $core; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1467 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1468 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1469 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1470 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1471 |
* Builds an object with all post type labels out of a post type object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1472 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1473 |
* Accepted keys of the label array in the post type object: |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1474 |
* - name - general name for the post type, usually plural. The same and overridden by $post_type_object->label. Default is Posts/Pages |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1475 |
* - singular_name - name for one object of this post type. Default is Post/Page |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1476 |
* - add_new - Default is Add New for both hierarchical and non-hierarchical types. When internationalizing this string, please use a {@link http://codex.wordpress.org/I18n_for_WordPress_Developers#Disambiguation_by_context gettext context} matching your post type. Example: <code>_x('Add New', 'product');</code> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1477 |
* - add_new_item - Default is Add New Post/Add New Page |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1478 |
* - edit_item - Default is Edit Post/Edit Page |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1479 |
* - new_item - Default is New Post/New Page |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1480 |
* - view_item - Default is View Post/View Page |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1481 |
* - search_items - Default is Search Posts/Search Pages |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1482 |
* - not_found - Default is No posts found/No pages found |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1483 |
* - not_found_in_trash - Default is No posts found in Trash/No pages found in Trash |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1484 |
* - parent_item_colon - This string isn't used on non-hierarchical types. In hierarchical ones the default is Parent Page: |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1485 |
* - all_items - String for the submenu. Default is All Posts/All Pages |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1486 |
* - menu_name - Default is the same as <code>name</code> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1487 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1488 |
* Above, the first default value is for non-hierarchical post types (like posts) and the second one is for hierarchical post types (like pages). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1489 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1490 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1491 |
* @param object $post_type_object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1492 |
* @return object object with all the labels as member variables |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1493 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1494 |
function get_post_type_labels( $post_type_object ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1495 |
$nohier_vs_hier_defaults = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1496 |
'name' => array( _x('Posts', 'post type general name'), _x('Pages', 'post type general name') ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1497 |
'singular_name' => array( _x('Post', 'post type singular name'), _x('Page', 'post type singular name') ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1498 |
'add_new' => array( _x('Add New', 'post'), _x('Add New', 'page') ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1499 |
'add_new_item' => array( __('Add New Post'), __('Add New Page') ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1500 |
'edit_item' => array( __('Edit Post'), __('Edit Page') ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1501 |
'new_item' => array( __('New Post'), __('New Page') ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1502 |
'view_item' => array( __('View Post'), __('View Page') ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1503 |
'search_items' => array( __('Search Posts'), __('Search Pages') ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1504 |
'not_found' => array( __('No posts found.'), __('No pages found.') ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1505 |
'not_found_in_trash' => array( __('No posts found in Trash.'), __('No pages found in Trash.') ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1506 |
'parent_item_colon' => array( null, __('Parent Page:') ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1507 |
'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1508 |
); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1509 |
$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1510 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1511 |
$labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1512 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1513 |
$post_type = $post_type_object->name; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1514 |
return apply_filters( "post_type_labels_{$post_type}", $labels ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1515 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1516 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1517 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1518 |
* Builds an object with custom-something object (post type, taxonomy) labels out of a custom-something object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1519 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1520 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1521 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1522 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1523 |
function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1524 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1525 |
if ( isset( $object->label ) && empty( $object->labels['name'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1526 |
$object->labels['name'] = $object->label; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1527 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1528 |
if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1529 |
$object->labels['singular_name'] = $object->labels['name']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1530 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1531 |
if ( ! isset( $object->labels['name_admin_bar'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1532 |
$object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1533 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1534 |
if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1535 |
$object->labels['menu_name'] = $object->labels['name']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1536 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1537 |
if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1538 |
$object->labels['all_items'] = $object->labels['menu_name']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1539 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1540 |
foreach ( $nohier_vs_hier_defaults as $key => $value ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1541 |
$defaults[$key] = $object->hierarchical ? $value[1] : $value[0]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1542 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1543 |
$labels = array_merge( $defaults, $object->labels ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1544 |
return (object)$labels; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1545 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1546 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1547 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1548 |
* Adds submenus for post types. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1549 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1550 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1551 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1552 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1553 |
function _add_post_type_submenus() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1554 |
foreach ( get_post_types( array( 'show_ui' => true ) ) as $ptype ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1555 |
$ptype_obj = get_post_type_object( $ptype ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1556 |
// Submenus only. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1557 |
if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1558 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1559 |
add_submenu_page( $ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1560 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1561 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1562 |
add_action( 'admin_menu', '_add_post_type_submenus' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1563 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1564 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1565 |
* Register support of certain features for a post type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1566 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1567 |
* All features are directly associated with a functional area of the edit screen, such as the |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1568 |
* editor or a meta box: 'title', 'editor', 'comments', 'revisions', 'trackbacks', 'author', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1569 |
* 'excerpt', 'page-attributes', 'thumbnail', and 'custom-fields'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1570 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1571 |
* Additionally, the 'revisions' feature dictates whether the post type will store revisions, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1572 |
* and the 'comments' feature dictates whether the comments count will show on the edit screen. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1573 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1574 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1575 |
* @param string $post_type The post type for which to add the feature |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1576 |
* @param string|array $feature the feature being added, can be an array of feature strings or a single string |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1577 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1578 |
function add_post_type_support( $post_type, $feature ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1579 |
global $_wp_post_type_features; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1580 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1581 |
$features = (array) $feature; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1582 |
foreach ($features as $feature) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1583 |
if ( func_num_args() == 2 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1584 |
$_wp_post_type_features[$post_type][$feature] = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1585 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1586 |
$_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1587 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1588 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1589 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1590 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1591 |
* Remove support for a feature from a post type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1592 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1593 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1594 |
* @param string $post_type The post type for which to remove the feature |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1595 |
* @param string $feature The feature being removed |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1596 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1597 |
function remove_post_type_support( $post_type, $feature ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1598 |
global $_wp_post_type_features; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1599 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1600 |
if ( !isset($_wp_post_type_features[$post_type]) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1601 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1602 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1603 |
if ( isset($_wp_post_type_features[$post_type][$feature]) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1604 |
unset($_wp_post_type_features[$post_type][$feature]); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1605 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1606 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1607 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1608 |
* Get all the post type features |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1609 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1610 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1611 |
* @param string $post_type The post type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1612 |
* @return array |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1613 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1614 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1615 |
function get_all_post_type_supports( $post_type ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1616 |
global $_wp_post_type_features; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1617 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1618 |
if ( isset( $_wp_post_type_features[$post_type] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1619 |
return $_wp_post_type_features[$post_type]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1620 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1621 |
return array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1622 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1623 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1624 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1625 |
* Checks a post type's support for a given feature |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1626 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1627 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1628 |
* @param string $post_type The post type being checked |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1629 |
* @param string $feature the feature being checked |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1630 |
* @return boolean |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1631 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1632 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1633 |
function post_type_supports( $post_type, $feature ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1634 |
global $_wp_post_type_features; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1635 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1636 |
if ( !isset( $_wp_post_type_features[$post_type][$feature] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1637 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1638 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1639 |
// If no args passed then no extra checks need be performed |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1640 |
if ( func_num_args() <= 2 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1641 |
return true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1642 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1643 |
// @todo Allow pluggable arg checking |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1644 |
//$args = array_slice( func_get_args(), 2 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1645 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1646 |
return true; |
136 | 1647 |
} |
1648 |
||
1649 |
/** |
|
1650 |
* Updates the post type for the post ID. |
|
1651 |
* |
|
1652 |
* The page or post cache will be cleaned for the post ID. |
|
1653 |
* |
|
1654 |
* @since 2.5.0 |
|
1655 |
* |
|
1656 |
* @uses $wpdb |
|
1657 |
* |
|
1658 |
* @param int $post_id Post ID to change post type. Not actually optional. |
|
1659 |
* @param string $post_type Optional, default is post. Supported values are 'post' or 'page' to |
|
1660 |
* name a few. |
|
1661 |
* @return int Amount of rows changed. Should be 1 for success and 0 for failure. |
|
1662 |
*/ |
|
1663 |
function set_post_type( $post_id = 0, $post_type = 'post' ) { |
|
1664 |
global $wpdb; |
|
1665 |
||
1666 |
$post_type = sanitize_post_field('post_type', $post_type, $post_id, 'db'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1667 |
$return = $wpdb->update( $wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1668 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1669 |
clean_post_cache( $post_id ); |
136 | 1670 |
|
1671 |
return $return; |
|
1672 |
} |
|
1673 |
||
1674 |
/** |
|
1675 |
* Retrieve list of latest posts or posts matching criteria. |
|
1676 |
* |
|
1677 |
* The defaults are as follows: |
|
1678 |
* 'numberposts' - Default is 5. Total number of posts to retrieve. |
|
1679 |
* 'offset' - Default is 0. See {@link WP_Query::query()} for more. |
|
1680 |
* 'category' - What category to pull the posts from. |
|
1681 |
* 'orderby' - Default is 'post_date'. How to order the posts. |
|
1682 |
* 'order' - Default is 'DESC'. The order to retrieve the posts. |
|
1683 |
* 'include' - See {@link WP_Query::query()} for more. |
|
1684 |
* 'exclude' - See {@link WP_Query::query()} for more. |
|
1685 |
* 'meta_key' - See {@link WP_Query::query()} for more. |
|
1686 |
* 'meta_value' - See {@link WP_Query::query()} for more. |
|
1687 |
* 'post_type' - Default is 'post'. Can be 'page', or 'attachment' to name a few. |
|
1688 |
* 'post_parent' - The parent of the post or post type. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1689 |
* 'post_status' - Default is 'publish'. Post status to retrieve. |
136 | 1690 |
* |
1691 |
* @since 1.2.0 |
|
1692 |
* @uses $wpdb |
|
1693 |
* @uses WP_Query::query() See for more default arguments and information. |
|
1694 |
* @link http://codex.wordpress.org/Template_Tags/get_posts |
|
1695 |
* |
|
1696 |
* @param array $args Optional. Overrides defaults. |
|
1697 |
* @return array List of posts. |
|
1698 |
*/ |
|
1699 |
function get_posts($args = null) { |
|
1700 |
$defaults = array( |
|
1701 |
'numberposts' => 5, 'offset' => 0, |
|
1702 |
'category' => 0, 'orderby' => 'post_date', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1703 |
'order' => 'DESC', 'include' => array(), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1704 |
'exclude' => array(), 'meta_key' => '', |
136 | 1705 |
'meta_value' =>'', 'post_type' => 'post', |
1706 |
'suppress_filters' => true |
|
1707 |
); |
|
1708 |
||
1709 |
$r = wp_parse_args( $args, $defaults ); |
|
1710 |
if ( empty( $r['post_status'] ) ) |
|
1711 |
$r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1712 |
if ( ! empty($r['numberposts']) && empty($r['posts_per_page']) ) |
136 | 1713 |
$r['posts_per_page'] = $r['numberposts']; |
1714 |
if ( ! empty($r['category']) ) |
|
1715 |
$r['cat'] = $r['category']; |
|
1716 |
if ( ! empty($r['include']) ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1717 |
$incposts = wp_parse_id_list( $r['include'] ); |
136 | 1718 |
$r['posts_per_page'] = count($incposts); // only the number of posts included |
1719 |
$r['post__in'] = $incposts; |
|
1720 |
} elseif ( ! empty($r['exclude']) ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1721 |
$r['post__not_in'] = wp_parse_id_list( $r['exclude'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1722 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1723 |
$r['ignore_sticky_posts'] = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1724 |
$r['no_found_rows'] = true; |
136 | 1725 |
|
1726 |
$get_posts = new WP_Query; |
|
1727 |
return $get_posts->query($r); |
|
1728 |
||
1729 |
} |
|
1730 |
||
1731 |
// |
|
1732 |
// Post meta functions |
|
1733 |
// |
|
1734 |
||
1735 |
/** |
|
1736 |
* Add meta data field to a post. |
|
1737 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1738 |
* Post meta data is called "Custom Fields" on the Administration Screen. |
136 | 1739 |
* |
1740 |
* @since 1.5.0 |
|
1741 |
* @uses $wpdb |
|
1742 |
* @link http://codex.wordpress.org/Function_Reference/add_post_meta |
|
1743 |
* |
|
1744 |
* @param int $post_id Post ID. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1745 |
* @param string $meta_key Metadata name. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1746 |
* @param mixed $meta_value Metadata value. |
136 | 1747 |
* @param bool $unique Optional, default is false. Whether the same key should not be added. |
1748 |
* @return bool False for failure. True for success. |
|
1749 |
*/ |
|
1750 |
function add_post_meta($post_id, $meta_key, $meta_value, $unique = false) { |
|
1751 |
// make sure meta is added to the post, not a revision |
|
1752 |
if ( $the_post = wp_is_post_revision($post_id) ) |
|
1753 |
$post_id = $the_post; |
|
1754 |
||
1755 |
return add_metadata('post', $post_id, $meta_key, $meta_value, $unique); |
|
1756 |
} |
|
1757 |
||
1758 |
/** |
|
1759 |
* Remove metadata matching criteria from a post. |
|
1760 |
* |
|
1761 |
* You can match based on the key, or key and value. Removing based on key and |
|
1762 |
* value, will keep from removing duplicate metadata with the same key. It also |
|
1763 |
* allows removing all metadata matching key, if needed. |
|
1764 |
* |
|
1765 |
* @since 1.5.0 |
|
1766 |
* @uses $wpdb |
|
1767 |
* @link http://codex.wordpress.org/Function_Reference/delete_post_meta |
|
1768 |
* |
|
1769 |
* @param int $post_id post ID |
|
1770 |
* @param string $meta_key Metadata name. |
|
1771 |
* @param mixed $meta_value Optional. Metadata value. |
|
1772 |
* @return bool False for failure. True for success. |
|
1773 |
*/ |
|
1774 |
function delete_post_meta($post_id, $meta_key, $meta_value = '') { |
|
1775 |
// make sure meta is added to the post, not a revision |
|
1776 |
if ( $the_post = wp_is_post_revision($post_id) ) |
|
1777 |
$post_id = $the_post; |
|
1778 |
||
1779 |
return delete_metadata('post', $post_id, $meta_key, $meta_value); |
|
1780 |
} |
|
1781 |
||
1782 |
/** |
|
1783 |
* Retrieve post meta field for a post. |
|
1784 |
* |
|
1785 |
* @since 1.5.0 |
|
1786 |
* @uses $wpdb |
|
1787 |
* @link http://codex.wordpress.org/Function_Reference/get_post_meta |
|
1788 |
* |
|
1789 |
* @param int $post_id Post ID. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1790 |
* @param string $key Optional. The meta key to retrieve. By default, returns data for all keys. |
136 | 1791 |
* @param bool $single Whether to return a single value. |
1792 |
* @return mixed Will be an array if $single is false. Will be value of meta data field if $single |
|
1793 |
* is true. |
|
1794 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1795 |
function get_post_meta($post_id, $key = '', $single = false) { |
136 | 1796 |
return get_metadata('post', $post_id, $key, $single); |
1797 |
} |
|
1798 |
||
1799 |
/** |
|
1800 |
* Update post meta field based on post ID. |
|
1801 |
* |
|
1802 |
* Use the $prev_value parameter to differentiate between meta fields with the |
|
1803 |
* same key and post ID. |
|
1804 |
* |
|
1805 |
* If the meta field for the post does not exist, it will be added. |
|
1806 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1807 |
* @since 1.5.0 |
136 | 1808 |
* @uses $wpdb |
1809 |
* @link http://codex.wordpress.org/Function_Reference/update_post_meta |
|
1810 |
* |
|
1811 |
* @param int $post_id Post ID. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1812 |
* @param string $meta_key Metadata key. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1813 |
* @param mixed $meta_value Metadata value. |
136 | 1814 |
* @param mixed $prev_value Optional. Previous value to check before removing. |
1815 |
* @return bool False on failure, true if success. |
|
1816 |
*/ |
|
1817 |
function update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '') { |
|
1818 |
// make sure meta is added to the post, not a revision |
|
1819 |
if ( $the_post = wp_is_post_revision($post_id) ) |
|
1820 |
$post_id = $the_post; |
|
1821 |
||
1822 |
return update_metadata('post', $post_id, $meta_key, $meta_value, $prev_value); |
|
1823 |
} |
|
1824 |
||
1825 |
/** |
|
1826 |
* Delete everything from post meta matching meta key. |
|
1827 |
* |
|
1828 |
* @since 2.3.0 |
|
1829 |
* @uses $wpdb |
|
1830 |
* |
|
1831 |
* @param string $post_meta_key Key to search for when deleting. |
|
1832 |
* @return bool Whether the post meta key was deleted from the database |
|
1833 |
*/ |
|
1834 |
function delete_post_meta_by_key($post_meta_key) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1835 |
return delete_metadata( 'post', null, $post_meta_key, '', true ); |
136 | 1836 |
} |
1837 |
||
1838 |
/** |
|
1839 |
* Retrieve post meta fields, based on post ID. |
|
1840 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1841 |
* The post meta fields are retrieved from the cache where possible, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1842 |
* so the function is optimized to be called more than once. |
136 | 1843 |
* |
1844 |
* @since 1.2.0 |
|
1845 |
* @link http://codex.wordpress.org/Function_Reference/get_post_custom |
|
1846 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1847 |
* @param int $post_id Post ID. |
136 | 1848 |
* @return array |
1849 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1850 |
function get_post_custom( $post_id = 0 ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1851 |
$post_id = absint( $post_id ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1852 |
if ( ! $post_id ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1853 |
$post_id = get_the_ID(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1854 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1855 |
return get_post_meta( $post_id ); |
136 | 1856 |
} |
1857 |
||
1858 |
/** |
|
1859 |
* Retrieve meta field names for a post. |
|
1860 |
* |
|
1861 |
* If there are no meta fields, then nothing (null) will be returned. |
|
1862 |
* |
|
1863 |
* @since 1.2.0 |
|
1864 |
* @link http://codex.wordpress.org/Function_Reference/get_post_custom_keys |
|
1865 |
* |
|
1866 |
* @param int $post_id post ID |
|
1867 |
* @return array|null Either array of the keys, or null if keys could not be retrieved. |
|
1868 |
*/ |
|
1869 |
function get_post_custom_keys( $post_id = 0 ) { |
|
1870 |
$custom = get_post_custom( $post_id ); |
|
1871 |
||
1872 |
if ( !is_array($custom) ) |
|
1873 |
return; |
|
1874 |
||
1875 |
if ( $keys = array_keys($custom) ) |
|
1876 |
return $keys; |
|
1877 |
} |
|
1878 |
||
1879 |
/** |
|
1880 |
* Retrieve values for a custom post field. |
|
1881 |
* |
|
1882 |
* The parameters must not be considered optional. All of the post meta fields |
|
1883 |
* will be retrieved and only the meta field key values returned. |
|
1884 |
* |
|
1885 |
* @since 1.2.0 |
|
1886 |
* @link http://codex.wordpress.org/Function_Reference/get_post_custom_values |
|
1887 |
* |
|
1888 |
* @param string $key Meta field key. |
|
1889 |
* @param int $post_id Post ID |
|
1890 |
* @return array Meta field values. |
|
1891 |
*/ |
|
1892 |
function get_post_custom_values( $key = '', $post_id = 0 ) { |
|
1893 |
if ( !$key ) |
|
1894 |
return null; |
|
1895 |
||
1896 |
$custom = get_post_custom($post_id); |
|
1897 |
||
1898 |
return isset($custom[$key]) ? $custom[$key] : null; |
|
1899 |
} |
|
1900 |
||
1901 |
/** |
|
1902 |
* Check if post is sticky. |
|
1903 |
* |
|
1904 |
* Sticky posts should remain at the top of The Loop. If the post ID is not |
|
1905 |
* given, then The Loop ID for the current post will be used. |
|
1906 |
* |
|
1907 |
* @since 2.7.0 |
|
1908 |
* |
|
1909 |
* @param int $post_id Optional. Post ID. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1910 |
* @return bool Whether post is sticky. |
136 | 1911 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1912 |
function is_sticky( $post_id = 0 ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1913 |
$post_id = absint( $post_id ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1914 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1915 |
if ( ! $post_id ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1916 |
$post_id = get_the_ID(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1917 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1918 |
$stickies = get_option( 'sticky_posts' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1919 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1920 |
if ( ! is_array( $stickies ) ) |
136 | 1921 |
return false; |
1922 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1923 |
if ( in_array( $post_id, $stickies ) ) |
136 | 1924 |
return true; |
1925 |
||
1926 |
return false; |
|
1927 |
} |
|
1928 |
||
1929 |
/** |
|
1930 |
* Sanitize every post field. |
|
1931 |
* |
|
1932 |
* If the context is 'raw', then the post object or array will get minimal santization of the int fields. |
|
1933 |
* |
|
1934 |
* @since 2.3.0 |
|
1935 |
* @uses sanitize_post_field() Used to sanitize the fields. |
|
1936 |
* |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1937 |
* @param object|WP_Post|array $post The Post Object or Array |
136 | 1938 |
* @param string $context Optional, default is 'display'. How to sanitize post fields. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1939 |
* @return object|WP_Post|array The now sanitized Post Object or Array (will be the same type as $post) |
136 | 1940 |
*/ |
1941 |
function sanitize_post($post, $context = 'display') { |
|
1942 |
if ( is_object($post) ) { |
|
1943 |
// Check if post already filtered for this context |
|
1944 |
if ( isset($post->filter) && $context == $post->filter ) |
|
1945 |
return $post; |
|
1946 |
if ( !isset($post->ID) ) |
|
1947 |
$post->ID = 0; |
|
1948 |
foreach ( array_keys(get_object_vars($post)) as $field ) |
|
1949 |
$post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context); |
|
1950 |
$post->filter = $context; |
|
1951 |
} else { |
|
1952 |
// Check if post already filtered for this context |
|
1953 |
if ( isset($post['filter']) && $context == $post['filter'] ) |
|
1954 |
return $post; |
|
1955 |
if ( !isset($post['ID']) ) |
|
1956 |
$post['ID'] = 0; |
|
1957 |
foreach ( array_keys($post) as $field ) |
|
1958 |
$post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context); |
|
1959 |
$post['filter'] = $context; |
|
1960 |
} |
|
1961 |
return $post; |
|
1962 |
} |
|
1963 |
||
1964 |
/** |
|
1965 |
* Sanitize post field based on context. |
|
1966 |
* |
|
1967 |
* Possible context values are: 'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The |
|
1968 |
* 'display' context is used by default. 'attribute' and 'js' contexts are treated like 'display' |
|
1969 |
* when calling filters. |
|
1970 |
* |
|
1971 |
* @since 2.3.0 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1972 |
* @uses apply_filters() Calls 'edit_$field' and '{$field_no_prefix}_edit_pre' passing $value and |
136 | 1973 |
* $post_id if $context == 'edit' and field name prefix == 'post_'. |
1974 |
* |
|
1975 |
* @uses apply_filters() Calls 'edit_post_$field' passing $value and $post_id if $context == 'db'. |
|
1976 |
* @uses apply_filters() Calls 'pre_$field' passing $value if $context == 'db' and field name prefix == 'post_'. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1977 |
* @uses apply_filters() Calls '{$field}_pre' passing $value if $context == 'db' and field name prefix != 'post_'. |
136 | 1978 |
* |
1979 |
* @uses apply_filters() Calls '$field' passing $value, $post_id and $context if $context == anything |
|
1980 |
* other than 'raw', 'edit' and 'db' and field name prefix == 'post_'. |
|
1981 |
* @uses apply_filters() Calls 'post_$field' passing $value if $context == anything other than 'raw', |
|
1982 |
* 'edit' and 'db' and field name prefix != 'post_'. |
|
1983 |
* |
|
1984 |
* @param string $field The Post Object field name. |
|
1985 |
* @param mixed $value The Post Object value. |
|
1986 |
* @param int $post_id Post ID. |
|
1987 |
* @param string $context How to sanitize post fields. Looks for 'raw', 'edit', 'db', 'display', |
|
1988 |
* 'attribute' and 'js'. |
|
1989 |
* @return mixed Sanitized value. |
|
1990 |
*/ |
|
1991 |
function sanitize_post_field($field, $value, $post_id, $context) { |
|
1992 |
$int_fields = array('ID', 'post_parent', 'menu_order'); |
|
1993 |
if ( in_array($field, $int_fields) ) |
|
1994 |
$value = (int) $value; |
|
1995 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1996 |
// Fields which contain arrays of ints. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1997 |
$array_int_fields = array( 'ancestors' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1998 |
if ( in_array($field, $array_int_fields) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1999 |
$value = array_map( 'absint', $value); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2000 |
return $value; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2001 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2002 |
|
136 | 2003 |
if ( 'raw' == $context ) |
2004 |
return $value; |
|
2005 |
||
2006 |
$prefixed = false; |
|
2007 |
if ( false !== strpos($field, 'post_') ) { |
|
2008 |
$prefixed = true; |
|
2009 |
$field_no_prefix = str_replace('post_', '', $field); |
|
2010 |
} |
|
2011 |
||
2012 |
if ( 'edit' == $context ) { |
|
2013 |
$format_to_edit = array('post_content', 'post_excerpt', 'post_title', 'post_password'); |
|
2014 |
||
2015 |
if ( $prefixed ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2016 |
$value = apply_filters("edit_{$field}", $value, $post_id); |
136 | 2017 |
// Old school |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2018 |
$value = apply_filters("{$field_no_prefix}_edit_pre", $value, $post_id); |
136 | 2019 |
} else { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2020 |
$value = apply_filters("edit_post_{$field}", $value, $post_id); |
136 | 2021 |
} |
2022 |
||
2023 |
if ( in_array($field, $format_to_edit) ) { |
|
2024 |
if ( 'post_content' == $field ) |
|
2025 |
$value = format_to_edit($value, user_can_richedit()); |
|
2026 |
else |
|
2027 |
$value = format_to_edit($value); |
|
2028 |
} else { |
|
2029 |
$value = esc_attr($value); |
|
2030 |
} |
|
2031 |
} else if ( 'db' == $context ) { |
|
2032 |
if ( $prefixed ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2033 |
$value = apply_filters("pre_{$field}", $value); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2034 |
$value = apply_filters("{$field_no_prefix}_save_pre", $value); |
136 | 2035 |
} else { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2036 |
$value = apply_filters("pre_post_{$field}", $value); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2037 |
$value = apply_filters("{$field}_pre", $value); |
136 | 2038 |
} |
2039 |
} else { |
|
2040 |
// Use display filters by default. |
|
2041 |
if ( $prefixed ) |
|
2042 |
$value = apply_filters($field, $value, $post_id, $context); |
|
2043 |
else |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2044 |
$value = apply_filters("post_{$field}", $value, $post_id, $context); |
136 | 2045 |
} |
2046 |
||
2047 |
if ( 'attribute' == $context ) |
|
2048 |
$value = esc_attr($value); |
|
2049 |
else if ( 'js' == $context ) |
|
2050 |
$value = esc_js($value); |
|
2051 |
||
2052 |
return $value; |
|
2053 |
} |
|
2054 |
||
2055 |
/** |
|
2056 |
* Make a post sticky. |
|
2057 |
* |
|
2058 |
* Sticky posts should be displayed at the top of the front page. |
|
2059 |
* |
|
2060 |
* @since 2.7.0 |
|
2061 |
* |
|
2062 |
* @param int $post_id Post ID. |
|
2063 |
*/ |
|
2064 |
function stick_post($post_id) { |
|
2065 |
$stickies = get_option('sticky_posts'); |
|
2066 |
||
2067 |
if ( !is_array($stickies) ) |
|
2068 |
$stickies = array($post_id); |
|
2069 |
||
2070 |
if ( ! in_array($post_id, $stickies) ) |
|
2071 |
$stickies[] = $post_id; |
|
2072 |
||
2073 |
update_option('sticky_posts', $stickies); |
|
2074 |
} |
|
2075 |
||
2076 |
/** |
|
2077 |
* Unstick a post. |
|
2078 |
* |
|
2079 |
* Sticky posts should be displayed at the top of the front page. |
|
2080 |
* |
|
2081 |
* @since 2.7.0 |
|
2082 |
* |
|
2083 |
* @param int $post_id Post ID. |
|
2084 |
*/ |
|
2085 |
function unstick_post($post_id) { |
|
2086 |
$stickies = get_option('sticky_posts'); |
|
2087 |
||
2088 |
if ( !is_array($stickies) ) |
|
2089 |
return; |
|
2090 |
||
2091 |
if ( ! in_array($post_id, $stickies) ) |
|
2092 |
return; |
|
2093 |
||
2094 |
$offset = array_search($post_id, $stickies); |
|
2095 |
if ( false === $offset ) |
|
2096 |
return; |
|
2097 |
||
2098 |
array_splice($stickies, $offset, 1); |
|
2099 |
||
2100 |
update_option('sticky_posts', $stickies); |
|
2101 |
} |
|
2102 |
||
2103 |
/** |
|
2104 |
* Count number of posts of a post type and is user has permissions to view. |
|
2105 |
* |
|
2106 |
* This function provides an efficient method of finding the amount of post's |
|
2107 |
* type a blog has. Another method is to count the amount of items in |
|
2108 |
* get_posts(), but that method has a lot of overhead with doing so. Therefore, |
|
2109 |
* when developing for 2.5+, use this function instead. |
|
2110 |
* |
|
2111 |
* The $perm parameter checks for 'readable' value and if the user can read |
|
2112 |
* private posts, it will display that for the user that is signed in. |
|
2113 |
* |
|
2114 |
* @since 2.5.0 |
|
2115 |
* @link http://codex.wordpress.org/Template_Tags/wp_count_posts |
|
2116 |
* |
|
2117 |
* @param string $type Optional. Post type to retrieve count |
|
2118 |
* @param string $perm Optional. 'readable' or empty. |
|
2119 |
* @return object Number of posts for each status |
|
2120 |
*/ |
|
2121 |
function wp_count_posts( $type = 'post', $perm = '' ) { |
|
2122 |
global $wpdb; |
|
2123 |
||
2124 |
$user = wp_get_current_user(); |
|
2125 |
||
2126 |
$cache_key = $type; |
|
2127 |
||
2128 |
$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; |
|
2129 |
if ( 'readable' == $perm && is_user_logged_in() ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2130 |
$post_type_object = get_post_type_object($type); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2131 |
if ( !current_user_can( $post_type_object->cap->read_private_posts ) ) { |
136 | 2132 |
$cache_key .= '_' . $perm . '_' . $user->ID; |
2133 |
$query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))"; |
|
2134 |
} |
|
2135 |
} |
|
2136 |
$query .= ' GROUP BY post_status'; |
|
2137 |
||
2138 |
$count = wp_cache_get($cache_key, 'counts'); |
|
2139 |
if ( false !== $count ) |
|
2140 |
return $count; |
|
2141 |
||
2142 |
$count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); |
|
2143 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2144 |
$stats = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2145 |
foreach ( get_post_stati() as $state ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2146 |
$stats[$state] = 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2147 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2148 |
foreach ( (array) $count as $row ) |
136 | 2149 |
$stats[$row['post_status']] = $row['num_posts']; |
2150 |
||
2151 |
$stats = (object) $stats; |
|
2152 |
wp_cache_set($cache_key, $stats, 'counts'); |
|
2153 |
||
2154 |
return $stats; |
|
2155 |
} |
|
2156 |
||
2157 |
/** |
|
2158 |
* Count number of attachments for the mime type(s). |
|
2159 |
* |
|
2160 |
* If you set the optional mime_type parameter, then an array will still be |
|
2161 |
* returned, but will only have the item you are looking for. It does not give |
|
2162 |
* you the number of attachments that are children of a post. You can get that |
|
2163 |
* by counting the number of children that post has. |
|
2164 |
* |
|
2165 |
* @since 2.5.0 |
|
2166 |
* |
|
2167 |
* @param string|array $mime_type Optional. Array or comma-separated list of MIME patterns. |
|
2168 |
* @return array Number of posts for each mime type. |
|
2169 |
*/ |
|
2170 |
function wp_count_attachments( $mime_type = '' ) { |
|
2171 |
global $wpdb; |
|
2172 |
||
2173 |
$and = wp_post_mime_type_where( $mime_type ); |
|
2174 |
$count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A ); |
|
2175 |
||
2176 |
$stats = array( ); |
|
2177 |
foreach( (array) $count as $row ) { |
|
2178 |
$stats[$row['post_mime_type']] = $row['num_posts']; |
|
2179 |
} |
|
2180 |
$stats['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and"); |
|
2181 |
||
2182 |
return (object) $stats; |
|
2183 |
} |
|
2184 |
||
2185 |
/** |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2186 |
* Get default post mime types |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2187 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2188 |
* @since 2.9.0 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2189 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2190 |
* @return array |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2191 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2192 |
function get_post_mime_types() { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2193 |
$post_mime_types = array( // array( adj, noun ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2194 |
'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2195 |
'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2196 |
'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2197 |
); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2198 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2199 |
return apply_filters('post_mime_types', $post_mime_types); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2200 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2201 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2202 |
/** |
136 | 2203 |
* Check a MIME-Type against a list. |
2204 |
* |
|
2205 |
* If the wildcard_mime_types parameter is a string, it must be comma separated |
|
2206 |
* list. If the real_mime_types is a string, it is also comma separated to |
|
2207 |
* create the list. |
|
2208 |
* |
|
2209 |
* @since 2.5.0 |
|
2210 |
* |
|
2211 |
* @param string|array $wildcard_mime_types e.g. audio/mpeg or image (same as image/*) or |
|
2212 |
* flash (same as *flash*). |
|
2213 |
* @param string|array $real_mime_types post_mime_type values |
|
2214 |
* @return array array(wildcard=>array(real types)) |
|
2215 |
*/ |
|
2216 |
function wp_match_mime_types($wildcard_mime_types, $real_mime_types) { |
|
2217 |
$matches = array(); |
|
2218 |
if ( is_string($wildcard_mime_types) ) |
|
2219 |
$wildcard_mime_types = array_map('trim', explode(',', $wildcard_mime_types)); |
|
2220 |
if ( is_string($real_mime_types) ) |
|
2221 |
$real_mime_types = array_map('trim', explode(',', $real_mime_types)); |
|
2222 |
$wild = '[-._a-z0-9]*'; |
|
2223 |
foreach ( (array) $wildcard_mime_types as $type ) { |
|
2224 |
$type = str_replace('*', $wild, $type); |
|
2225 |
$patternses[1][$type] = "^$type$"; |
|
2226 |
if ( false === strpos($type, '/') ) { |
|
2227 |
$patternses[2][$type] = "^$type/"; |
|
2228 |
$patternses[3][$type] = $type; |
|
2229 |
} |
|
2230 |
} |
|
2231 |
asort($patternses); |
|
2232 |
foreach ( $patternses as $patterns ) |
|
2233 |
foreach ( $patterns as $type => $pattern ) |
|
2234 |
foreach ( (array) $real_mime_types as $real ) |
|
2235 |
if ( preg_match("#$pattern#", $real) && ( empty($matches[$type]) || false === array_search($real, $matches[$type]) ) ) |
|
2236 |
$matches[$type][] = $real; |
|
2237 |
return $matches; |
|
2238 |
} |
|
2239 |
||
2240 |
/** |
|
2241 |
* Convert MIME types into SQL. |
|
2242 |
* |
|
2243 |
* @since 2.5.0 |
|
2244 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2245 |
* @param string|array $post_mime_types List of mime types or comma separated string of mime types. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2246 |
* @param string $table_alias Optional. Specify a table alias, if needed. |
136 | 2247 |
* @return string The SQL AND clause for mime searching. |
2248 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2249 |
function wp_post_mime_type_where($post_mime_types, $table_alias = '') { |
136 | 2250 |
$where = ''; |
2251 |
$wildcards = array('', '%', '%/%'); |
|
2252 |
if ( is_string($post_mime_types) ) |
|
2253 |
$post_mime_types = array_map('trim', explode(',', $post_mime_types)); |
|
2254 |
foreach ( (array) $post_mime_types as $mime_type ) { |
|
2255 |
$mime_type = preg_replace('/\s/', '', $mime_type); |
|
2256 |
$slashpos = strpos($mime_type, '/'); |
|
2257 |
if ( false !== $slashpos ) { |
|
2258 |
$mime_group = preg_replace('/[^-*.a-zA-Z0-9]/', '', substr($mime_type, 0, $slashpos)); |
|
2259 |
$mime_subgroup = preg_replace('/[^-*.+a-zA-Z0-9]/', '', substr($mime_type, $slashpos + 1)); |
|
2260 |
if ( empty($mime_subgroup) ) |
|
2261 |
$mime_subgroup = '*'; |
|
2262 |
else |
|
2263 |
$mime_subgroup = str_replace('/', '', $mime_subgroup); |
|
2264 |
$mime_pattern = "$mime_group/$mime_subgroup"; |
|
2265 |
} else { |
|
2266 |
$mime_pattern = preg_replace('/[^-*.a-zA-Z0-9]/', '', $mime_type); |
|
2267 |
if ( false === strpos($mime_pattern, '*') ) |
|
2268 |
$mime_pattern .= '/*'; |
|
2269 |
} |
|
2270 |
||
2271 |
$mime_pattern = preg_replace('/\*+/', '%', $mime_pattern); |
|
2272 |
||
2273 |
if ( in_array( $mime_type, $wildcards ) ) |
|
2274 |
return ''; |
|
2275 |
||
2276 |
if ( false !== strpos($mime_pattern, '%') ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2277 |
$wheres[] = empty($table_alias) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; |
136 | 2278 |
else |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2279 |
$wheres[] = empty($table_alias) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; |
136 | 2280 |
} |
2281 |
if ( !empty($wheres) ) |
|
2282 |
$where = ' AND (' . join(' OR ', $wheres) . ') '; |
|
2283 |
return $where; |
|
2284 |
} |
|
2285 |
||
2286 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2287 |
* Trashes or deletes a post or page. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2288 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2289 |
* When the post and page is permanently deleted, everything that is tied to it is deleted also. |
136 | 2290 |
* This includes comments, post meta fields, and terms associated with the post. |
2291 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2292 |
* The post or page is moved to trash instead of permanently deleted unless trash is |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2293 |
* disabled, item is already in the trash, or $force_delete is true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2294 |
* |
136 | 2295 |
* @since 1.0.0 |
2296 |
* @uses do_action() on 'delete_post' before deletion unless post type is 'attachment'. |
|
2297 |
* @uses do_action() on 'deleted_post' after deletion unless post type is 'attachment'. |
|
2298 |
* @uses wp_delete_attachment() if post type is 'attachment'. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2299 |
* @uses wp_trash_post() if item should be trashed. |
136 | 2300 |
* |
2301 |
* @param int $postid Post ID. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2302 |
* @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false. |
136 | 2303 |
* @return mixed False on failure |
2304 |
*/ |
|
2305 |
function wp_delete_post( $postid = 0, $force_delete = false ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2306 |
global $wpdb; |
136 | 2307 |
|
2308 |
if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) ) |
|
2309 |
return $post; |
|
2310 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2311 |
if ( !$force_delete && ( $post->post_type == 'post' || $post->post_type == 'page') && get_post_status( $postid ) != 'trash' && EMPTY_TRASH_DAYS ) |
136 | 2312 |
return wp_trash_post($postid); |
2313 |
||
2314 |
if ( $post->post_type == 'attachment' ) |
|
2315 |
return wp_delete_attachment( $postid, $force_delete ); |
|
2316 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2317 |
do_action('before_delete_post', $postid); |
136 | 2318 |
|
2319 |
delete_post_meta($postid,'_wp_trash_meta_status'); |
|
2320 |
delete_post_meta($postid,'_wp_trash_meta_time'); |
|
2321 |
||
2322 |
wp_delete_object_term_relationships($postid, get_object_taxonomies($post->post_type)); |
|
2323 |
||
2324 |
$parent_data = array( 'post_parent' => $post->post_parent ); |
|
2325 |
$parent_where = array( 'post_parent' => $postid ); |
|
2326 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2327 |
if ( is_post_type_hierarchical( $post->post_type ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2328 |
// Point children of this page to its parent, also clean the cache of affected children |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2329 |
$children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2330 |
$children = $wpdb->get_results( $children_query ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2331 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2332 |
$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2333 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2334 |
|
136 | 2335 |
if ( 'page' == $post->post_type) { |
2336 |
// if the page is defined in option page_on_front or post_for_posts, |
|
2337 |
// adjust the corresponding options |
|
2338 |
if ( get_option('page_on_front') == $postid ) { |
|
2339 |
update_option('show_on_front', 'posts'); |
|
2340 |
delete_option('page_on_front'); |
|
2341 |
} |
|
2342 |
if ( get_option('page_for_posts') == $postid ) { |
|
2343 |
delete_option('page_for_posts'); |
|
2344 |
} |
|
2345 |
} else { |
|
2346 |
unstick_post($postid); |
|
2347 |
} |
|
2348 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2349 |
// Do raw query. wp_get_post_revisions() is filtered |
136 | 2350 |
$revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2351 |
// Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up. |
136 | 2352 |
foreach ( $revision_ids as $revision_id ) |
2353 |
wp_delete_post_revision( $revision_id ); |
|
2354 |
||
2355 |
// Point all attachments to this post up one level |
|
2356 |
$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) ); |
|
2357 |
||
2358 |
$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid )); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2359 |
foreach ( $comment_ids as $comment_id ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2360 |
wp_delete_comment( $comment_id, true ); |
136 | 2361 |
|
2362 |
$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid )); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2363 |
foreach ( $post_meta_ids as $mid ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2364 |
delete_metadata_by_mid( 'post', $mid ); |
136 | 2365 |
|
2366 |
do_action( 'delete_post', $postid ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2367 |
$wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) ); |
136 | 2368 |
do_action( 'deleted_post', $postid ); |
2369 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2370 |
clean_post_cache( $post ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2371 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2372 |
if ( is_post_type_hierarchical( $post->post_type ) && $children ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2373 |
foreach ( $children as $child ) |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2374 |
clean_post_cache( $child ); |
136 | 2375 |
} |
2376 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2377 |
wp_clear_scheduled_hook('publish_future_post', array( $postid ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2378 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2379 |
do_action('after_delete_post', $postid); |
136 | 2380 |
|
2381 |
return $post; |
|
2382 |
} |
|
2383 |
||
2384 |
/** |
|
2385 |
* Moves a post or page to the Trash |
|
2386 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2387 |
* If trash is disabled, the post or page is permanently deleted. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2388 |
* |
136 | 2389 |
* @since 2.9.0 |
2390 |
* @uses do_action() on 'trash_post' before trashing |
|
2391 |
* @uses do_action() on 'trashed_post' after trashing |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2392 |
* @uses wp_delete_post() if trash is disabled |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2393 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2394 |
* @param int $post_id Post ID. |
136 | 2395 |
* @return mixed False on failure |
2396 |
*/ |
|
2397 |
function wp_trash_post($post_id = 0) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2398 |
if ( !EMPTY_TRASH_DAYS ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2399 |
return wp_delete_post($post_id, true); |
136 | 2400 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2401 |
if ( !$post = get_post($post_id, ARRAY_A) ) |
136 | 2402 |
return $post; |
2403 |
||
2404 |
if ( $post['post_status'] == 'trash' ) |
|
2405 |
return false; |
|
2406 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2407 |
do_action('wp_trash_post', $post_id); |
136 | 2408 |
|
2409 |
add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']); |
|
2410 |
add_post_meta($post_id,'_wp_trash_meta_time', time()); |
|
2411 |
||
2412 |
$post['post_status'] = 'trash'; |
|
2413 |
wp_insert_post($post); |
|
2414 |
||
2415 |
wp_trash_post_comments($post_id); |
|
2416 |
||
2417 |
do_action('trashed_post', $post_id); |
|
2418 |
||
2419 |
return $post; |
|
2420 |
} |
|
2421 |
||
2422 |
/** |
|
2423 |
* Restores a post or page from the Trash |
|
2424 |
* |
|
2425 |
* @since 2.9.0 |
|
2426 |
* @uses do_action() on 'untrash_post' before undeletion |
|
2427 |
* @uses do_action() on 'untrashed_post' after undeletion |
|
2428 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2429 |
* @param int $post_id Post ID. |
136 | 2430 |
* @return mixed False on failure |
2431 |
*/ |
|
2432 |
function wp_untrash_post($post_id = 0) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2433 |
if ( !$post = get_post($post_id, ARRAY_A) ) |
136 | 2434 |
return $post; |
2435 |
||
2436 |
if ( $post['post_status'] != 'trash' ) |
|
2437 |
return false; |
|
2438 |
||
2439 |
do_action('untrash_post', $post_id); |
|
2440 |
||
2441 |
$post_status = get_post_meta($post_id, '_wp_trash_meta_status', true); |
|
2442 |
||
2443 |
$post['post_status'] = $post_status; |
|
2444 |
||
2445 |
delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
2446 |
delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
2447 |
||
2448 |
wp_insert_post($post); |
|
2449 |
||
2450 |
wp_untrash_post_comments($post_id); |
|
2451 |
||
2452 |
do_action('untrashed_post', $post_id); |
|
2453 |
||
2454 |
return $post; |
|
2455 |
} |
|
2456 |
||
2457 |
/** |
|
2458 |
* Moves comments for a post to the trash |
|
2459 |
* |
|
2460 |
* @since 2.9.0 |
|
2461 |
* @uses do_action() on 'trash_post_comments' before trashing |
|
2462 |
* @uses do_action() on 'trashed_post_comments' after trashing |
|
2463 |
* |
|
2464 |
* @param int $post Post ID or object. |
|
2465 |
* @return mixed False on failure |
|
2466 |
*/ |
|
2467 |
function wp_trash_post_comments($post = null) { |
|
2468 |
global $wpdb; |
|
2469 |
||
2470 |
$post = get_post($post); |
|
2471 |
if ( empty($post) ) |
|
2472 |
return; |
|
2473 |
||
2474 |
$post_id = $post->ID; |
|
2475 |
||
2476 |
do_action('trash_post_comments', $post_id); |
|
2477 |
||
2478 |
$comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id) ); |
|
2479 |
if ( empty($comments) ) |
|
2480 |
return; |
|
2481 |
||
2482 |
// Cache current status for each comment |
|
2483 |
$statuses = array(); |
|
2484 |
foreach ( $comments as $comment ) |
|
2485 |
$statuses[$comment->comment_ID] = $comment->comment_approved; |
|
2486 |
add_post_meta($post_id, '_wp_trash_meta_comments_status', $statuses); |
|
2487 |
||
2488 |
// Set status for all comments to post-trashed |
|
2489 |
$result = $wpdb->update($wpdb->comments, array('comment_approved' => 'post-trashed'), array('comment_post_ID' => $post_id)); |
|
2490 |
||
2491 |
clean_comment_cache( array_keys($statuses) ); |
|
2492 |
||
2493 |
do_action('trashed_post_comments', $post_id, $statuses); |
|
2494 |
||
2495 |
return $result; |
|
2496 |
} |
|
2497 |
||
2498 |
/** |
|
2499 |
* Restore comments for a post from the trash |
|
2500 |
* |
|
2501 |
* @since 2.9.0 |
|
2502 |
* @uses do_action() on 'untrash_post_comments' before trashing |
|
2503 |
* @uses do_action() on 'untrashed_post_comments' after trashing |
|
2504 |
* |
|
2505 |
* @param int $post Post ID or object. |
|
2506 |
* @return mixed False on failure |
|
2507 |
*/ |
|
2508 |
function wp_untrash_post_comments($post = null) { |
|
2509 |
global $wpdb; |
|
2510 |
||
2511 |
$post = get_post($post); |
|
2512 |
if ( empty($post) ) |
|
2513 |
return; |
|
2514 |
||
2515 |
$post_id = $post->ID; |
|
2516 |
||
2517 |
$statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true); |
|
2518 |
||
2519 |
if ( empty($statuses) ) |
|
2520 |
return true; |
|
2521 |
||
2522 |
do_action('untrash_post_comments', $post_id); |
|
2523 |
||
2524 |
// Restore each comment to its original status |
|
2525 |
$group_by_status = array(); |
|
2526 |
foreach ( $statuses as $comment_id => $comment_status ) |
|
2527 |
$group_by_status[$comment_status][] = $comment_id; |
|
2528 |
||
2529 |
foreach ( $group_by_status as $status => $comments ) { |
|
2530 |
// Sanity check. This shouldn't happen. |
|
2531 |
if ( 'post-trashed' == $status ) |
|
2532 |
$status = '0'; |
|
2533 |
$comments_in = implode( "', '", $comments ); |
|
2534 |
$wpdb->query( "UPDATE $wpdb->comments SET comment_approved = '$status' WHERE comment_ID IN ('" . $comments_in . "')" ); |
|
2535 |
} |
|
2536 |
||
2537 |
clean_comment_cache( array_keys($statuses) ); |
|
2538 |
||
2539 |
delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
2540 |
||
2541 |
do_action('untrashed_post_comments', $post_id); |
|
2542 |
} |
|
2543 |
||
2544 |
/** |
|
2545 |
* Retrieve the list of categories for a post. |
|
2546 |
* |
|
2547 |
* Compatibility layer for themes and plugins. Also an easy layer of abstraction |
|
2548 |
* away from the complexity of the taxonomy layer. |
|
2549 |
* |
|
2550 |
* @since 2.1.0 |
|
2551 |
* |
|
2552 |
* @uses wp_get_object_terms() Retrieves the categories. Args details can be found here. |
|
2553 |
* |
|
2554 |
* @param int $post_id Optional. The Post ID. |
|
2555 |
* @param array $args Optional. Overwrite the defaults. |
|
2556 |
* @return array |
|
2557 |
*/ |
|
2558 |
function wp_get_post_categories( $post_id = 0, $args = array() ) { |
|
2559 |
$post_id = (int) $post_id; |
|
2560 |
||
2561 |
$defaults = array('fields' => 'ids'); |
|
2562 |
$args = wp_parse_args( $args, $defaults ); |
|
2563 |
||
2564 |
$cats = wp_get_object_terms($post_id, 'category', $args); |
|
2565 |
return $cats; |
|
2566 |
} |
|
2567 |
||
2568 |
/** |
|
2569 |
* Retrieve the tags for a post. |
|
2570 |
* |
|
2571 |
* There is only one default for this function, called 'fields' and by default |
|
2572 |
* is set to 'all'. There are other defaults that can be overridden in |
|
2573 |
* {@link wp_get_object_terms()}. |
|
2574 |
* |
|
2575 |
* @package WordPress |
|
2576 |
* @subpackage Post |
|
2577 |
* @since 2.3.0 |
|
2578 |
* |
|
2579 |
* @uses wp_get_object_terms() Gets the tags for returning. Args can be found here |
|
2580 |
* |
|
2581 |
* @param int $post_id Optional. The Post ID |
|
2582 |
* @param array $args Optional. Overwrite the defaults |
|
2583 |
* @return array List of post tags. |
|
2584 |
*/ |
|
2585 |
function wp_get_post_tags( $post_id = 0, $args = array() ) { |
|
2586 |
return wp_get_post_terms( $post_id, 'post_tag', $args); |
|
2587 |
} |
|
2588 |
||
2589 |
/** |
|
2590 |
* Retrieve the terms for a post. |
|
2591 |
* |
|
2592 |
* There is only one default for this function, called 'fields' and by default |
|
2593 |
* is set to 'all'. There are other defaults that can be overridden in |
|
2594 |
* {@link wp_get_object_terms()}. |
|
2595 |
* |
|
2596 |
* @package WordPress |
|
2597 |
* @subpackage Post |
|
2598 |
* @since 2.8.0 |
|
2599 |
* |
|
2600 |
* @uses wp_get_object_terms() Gets the tags for returning. Args can be found here |
|
2601 |
* |
|
2602 |
* @param int $post_id Optional. The Post ID |
|
2603 |
* @param string $taxonomy The taxonomy for which to retrieve terms. Defaults to post_tag. |
|
2604 |
* @param array $args Optional. Overwrite the defaults |
|
2605 |
* @return array List of post tags. |
|
2606 |
*/ |
|
2607 |
function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array() ) { |
|
2608 |
$post_id = (int) $post_id; |
|
2609 |
||
2610 |
$defaults = array('fields' => 'all'); |
|
2611 |
$args = wp_parse_args( $args, $defaults ); |
|
2612 |
||
2613 |
$tags = wp_get_object_terms($post_id, $taxonomy, $args); |
|
2614 |
||
2615 |
return $tags; |
|
2616 |
} |
|
2617 |
||
2618 |
/** |
|
2619 |
* Retrieve number of recent posts. |
|
2620 |
* |
|
2621 |
* @since 1.0.0 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2622 |
* @uses wp_parse_args() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2623 |
* @uses get_posts() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2624 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2625 |
* @param string $deprecated Deprecated. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2626 |
* @param array $args Optional. Overrides defaults. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2627 |
* @param string $output Optional. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2628 |
* @return unknown. |
136 | 2629 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2630 |
function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2631 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2632 |
if ( is_numeric( $args ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2633 |
_deprecated_argument( __FUNCTION__, '3.1', __( 'Passing an integer number of posts is deprecated. Pass an array of arguments instead.' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2634 |
$args = array( 'numberposts' => absint( $args ) ); |
136 | 2635 |
} |
2636 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2637 |
// Set default arguments |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2638 |
$defaults = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2639 |
'numberposts' => 10, 'offset' => 0, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2640 |
'category' => 0, 'orderby' => 'post_date', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2641 |
'order' => 'DESC', 'include' => '', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2642 |
'exclude' => '', 'meta_key' => '', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2643 |
'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2644 |
'suppress_filters' => true |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2645 |
); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2646 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2647 |
$r = wp_parse_args( $args, $defaults ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2648 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2649 |
$results = get_posts( $r ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2650 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2651 |
// Backward compatibility. Prior to 3.1 expected posts to be returned in array |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2652 |
if ( ARRAY_A == $output ){ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2653 |
foreach( $results as $key => $result ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2654 |
$results[$key] = get_object_vars( $result ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2655 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2656 |
return $results ? $results : array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2657 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2658 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2659 |
return $results ? $results : false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2660 |
|
136 | 2661 |
} |
2662 |
||
2663 |
/** |
|
2664 |
* Insert a post. |
|
2665 |
* |
|
2666 |
* If the $postarr parameter has 'ID' set to a value, then post will be updated. |
|
2667 |
* |
|
2668 |
* You can set the post date manually, but setting the values for 'post_date' |
|
2669 |
* and 'post_date_gmt' keys. You can close the comments or open the comments by |
|
2670 |
* setting the value for 'comment_status' key. |
|
2671 |
* |
|
2672 |
* The defaults for the parameter $postarr are: |
|
2673 |
* 'post_status' - Default is 'draft'. |
|
2674 |
* 'post_type' - Default is 'post'. |
|
2675 |
* 'post_author' - Default is current user ID ($user_ID). The ID of the user who added the post. |
|
2676 |
* 'ping_status' - Default is the value in 'default_ping_status' option. |
|
2677 |
* Whether the attachment can accept pings. |
|
2678 |
* 'post_parent' - Default is 0. Set this for the post it belongs to, if any. |
|
2679 |
* 'menu_order' - Default is 0. The order it is displayed. |
|
2680 |
* 'to_ping' - Whether to ping. |
|
2681 |
* 'pinged' - Default is empty string. |
|
2682 |
* 'post_password' - Default is empty string. The password to access the attachment. |
|
2683 |
* 'guid' - Global Unique ID for referencing the attachment. |
|
2684 |
* 'post_content_filtered' - Post content filtered. |
|
2685 |
* 'post_excerpt' - Post excerpt. |
|
2686 |
* |
|
2687 |
* @since 1.0.0 |
|
2688 |
* @uses $wpdb |
|
2689 |
* @uses $user_ID |
|
2690 |
* @uses do_action() Calls 'pre_post_update' on post ID if this is an update. |
|
2691 |
* @uses do_action() Calls 'edit_post' action on post ID and post data if this is an update. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2692 |
* @uses do_action() Calls 'save_post' and 'wp_insert_post' on post id and post data just before returning. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2693 |
* @uses apply_filters() Calls 'wp_insert_post_data' passing $data, $postarr prior to database update or insert. |
136 | 2694 |
* @uses wp_transition_post_status() |
2695 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2696 |
* @param array $postarr Elements that make up post to insert. |
136 | 2697 |
* @param bool $wp_error Optional. Allow return of WP_Error on failure. |
2698 |
* @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success. |
|
2699 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2700 |
function wp_insert_post($postarr, $wp_error = false) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2701 |
global $wpdb, $user_ID; |
136 | 2702 |
|
2703 |
$defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID, |
|
2704 |
'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, |
|
2705 |
'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2706 |
'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2707 |
'post_content' => '', 'post_title' => ''); |
136 | 2708 |
|
2709 |
$postarr = wp_parse_args($postarr, $defaults); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2710 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2711 |
unset( $postarr[ 'filter' ] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2712 |
|
136 | 2713 |
$postarr = sanitize_post($postarr, 'db'); |
2714 |
||
2715 |
// export array as variables |
|
2716 |
extract($postarr, EXTR_SKIP); |
|
2717 |
||
2718 |
// Are we updating or creating? |
|
2719 |
$update = false; |
|
2720 |
if ( !empty($ID) ) { |
|
2721 |
$update = true; |
|
2722 |
$previous_status = get_post_field('post_status', $ID); |
|
2723 |
} else { |
|
2724 |
$previous_status = 'new'; |
|
2725 |
} |
|
2726 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2727 |
$maybe_empty = ! $post_content && ! $post_title && ! $post_excerpt && post_type_supports( $post_type, 'editor' ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2728 |
&& post_type_supports( $post_type, 'title' ) && post_type_supports( $post_type, 'excerpt' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2729 |
if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) { |
136 | 2730 |
if ( $wp_error ) |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2731 |
return new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) ); |
136 | 2732 |
else |
2733 |
return 0; |
|
2734 |
} |
|
2735 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2736 |
if ( empty($post_type) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2737 |
$post_type = 'post'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2738 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2739 |
if ( empty($post_status) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2740 |
$post_status = 'draft'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2741 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2742 |
if ( !empty($post_category) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2743 |
$post_category = array_filter($post_category); // Filter out empty terms |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2744 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2745 |
// Make sure we set a valid category. |
136 | 2746 |
if ( empty($post_category) || 0 == count($post_category) || !is_array($post_category) ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2747 |
// 'post' requires at least one category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2748 |
if ( 'post' == $post_type && 'auto-draft' != $post_status ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2749 |
$post_category = array( get_option('default_category') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2750 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2751 |
$post_category = array(); |
136 | 2752 |
} |
2753 |
||
2754 |
if ( empty($post_author) ) |
|
2755 |
$post_author = $user_ID; |
|
2756 |
||
2757 |
$post_ID = 0; |
|
2758 |
||
2759 |
// Get the post ID and GUID |
|
2760 |
if ( $update ) { |
|
2761 |
$post_ID = (int) $ID; |
|
2762 |
$guid = get_post_field( 'guid', $post_ID ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2763 |
$post_before = get_post($post_ID); |
136 | 2764 |
} |
2765 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2766 |
// Don't allow contributors to set the post slug for pending review posts |
136 | 2767 |
if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) ) |
2768 |
$post_name = ''; |
|
2769 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2770 |
// Create a valid post name. Drafts and pending posts are allowed to have an empty |
136 | 2771 |
// post name. |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2772 |
if ( empty($post_name) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2773 |
if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) |
136 | 2774 |
$post_name = sanitize_title($post_title); |
2775 |
else |
|
2776 |
$post_name = ''; |
|
2777 |
} else { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2778 |
// On updates, we need to check to see if it's using the old, fixed sanitization context. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2779 |
$check_name = sanitize_title( $post_name, '', 'old-save' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2780 |
if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && get_post_field( 'post_name', $ID ) == $check_name ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2781 |
$post_name = $check_name; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2782 |
else // new post, or slug has changed. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2783 |
$post_name = sanitize_title($post_name); |
136 | 2784 |
} |
2785 |
||
2786 |
// If the post date is empty (due to having been new or a draft) and status is not 'draft' or 'pending', set date to now |
|
2787 |
if ( empty($post_date) || '0000-00-00 00:00:00' == $post_date ) |
|
2788 |
$post_date = current_time('mysql'); |
|
2789 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2790 |
// validate the date |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2791 |
$mm = substr( $post_date, 5, 2 ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2792 |
$jj = substr( $post_date, 8, 2 ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2793 |
$aa = substr( $post_date, 0, 4 ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2794 |
$valid_date = wp_checkdate( $mm, $jj, $aa, $post_date ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2795 |
if ( !$valid_date ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2796 |
if ( $wp_error ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2797 |
return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2798 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2799 |
return 0; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2800 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2801 |
|
136 | 2802 |
if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2803 |
if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) |
136 | 2804 |
$post_date_gmt = get_gmt_from_date($post_date); |
2805 |
else |
|
2806 |
$post_date_gmt = '0000-00-00 00:00:00'; |
|
2807 |
} |
|
2808 |
||
2809 |
if ( $update || '0000-00-00 00:00:00' == $post_date ) { |
|
2810 |
$post_modified = current_time( 'mysql' ); |
|
2811 |
$post_modified_gmt = current_time( 'mysql', 1 ); |
|
2812 |
} else { |
|
2813 |
$post_modified = $post_date; |
|
2814 |
$post_modified_gmt = $post_date_gmt; |
|
2815 |
} |
|
2816 |
||
2817 |
if ( 'publish' == $post_status ) { |
|
2818 |
$now = gmdate('Y-m-d H:i:59'); |
|
2819 |
if ( mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false) ) |
|
2820 |
$post_status = 'future'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2821 |
} elseif( 'future' == $post_status ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2822 |
$now = gmdate('Y-m-d H:i:59'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2823 |
if ( mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2824 |
$post_status = 'publish'; |
136 | 2825 |
} |
2826 |
||
2827 |
if ( empty($comment_status) ) { |
|
2828 |
if ( $update ) |
|
2829 |
$comment_status = 'closed'; |
|
2830 |
else |
|
2831 |
$comment_status = get_option('default_comment_status'); |
|
2832 |
} |
|
2833 |
if ( empty($ping_status) ) |
|
2834 |
$ping_status = get_option('default_ping_status'); |
|
2835 |
||
2836 |
if ( isset($to_ping) ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2837 |
$to_ping = sanitize_trackback_urls( $to_ping ); |
136 | 2838 |
else |
2839 |
$to_ping = ''; |
|
2840 |
||
2841 |
if ( ! isset($pinged) ) |
|
2842 |
$pinged = ''; |
|
2843 |
||
2844 |
if ( isset($post_parent) ) |
|
2845 |
$post_parent = (int) $post_parent; |
|
2846 |
else |
|
2847 |
$post_parent = 0; |
|
2848 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2849 |
// Check the post_parent to see if it will cause a hierarchy loop |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2850 |
$post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr ); |
136 | 2851 |
|
2852 |
if ( isset($menu_order) ) |
|
2853 |
$menu_order = (int) $menu_order; |
|
2854 |
else |
|
2855 |
$menu_order = 0; |
|
2856 |
||
2857 |
if ( !isset($post_password) || 'private' == $post_status ) |
|
2858 |
$post_password = ''; |
|
2859 |
||
2860 |
$post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent); |
|
2861 |
||
2862 |
// expected_slashed (everything!) |
|
2863 |
$data = compact( array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'guid' ) ); |
|
2864 |
$data = apply_filters('wp_insert_post_data', $data, $postarr); |
|
2865 |
$data = stripslashes_deep( $data ); |
|
2866 |
$where = array( 'ID' => $post_ID ); |
|
2867 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2868 |
if ( $update ) { |
136 | 2869 |
do_action( 'pre_post_update', $post_ID ); |
2870 |
if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) { |
|
2871 |
if ( $wp_error ) |
|
2872 |
return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error); |
|
2873 |
else |
|
2874 |
return 0; |
|
2875 |
} |
|
2876 |
} else { |
|
2877 |
if ( isset($post_mime_type) ) |
|
2878 |
$data['post_mime_type'] = stripslashes( $post_mime_type ); // This isn't in the update |
|
2879 |
// If there is a suggested ID, use it if not already present |
|
2880 |
if ( !empty($import_id) ) { |
|
2881 |
$import_id = (int) $import_id; |
|
2882 |
if ( ! $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id) ) ) { |
|
2883 |
$data['ID'] = $import_id; |
|
2884 |
} |
|
2885 |
} |
|
2886 |
if ( false === $wpdb->insert( $wpdb->posts, $data ) ) { |
|
2887 |
if ( $wp_error ) |
|
2888 |
return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error); |
|
2889 |
else |
|
2890 |
return 0; |
|
2891 |
} |
|
2892 |
$post_ID = (int) $wpdb->insert_id; |
|
2893 |
||
2894 |
// use the newly generated $post_ID |
|
2895 |
$where = array( 'ID' => $post_ID ); |
|
2896 |
} |
|
2897 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2898 |
if ( empty($data['post_name']) && !in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { |
136 | 2899 |
$data['post_name'] = sanitize_title($data['post_title'], $post_ID); |
2900 |
$wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where ); |
|
2901 |
} |
|
2902 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2903 |
if ( is_object_in_taxonomy($post_type, 'category') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2904 |
wp_set_post_categories( $post_ID, $post_category ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2905 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2906 |
if ( isset( $tags_input ) && is_object_in_taxonomy($post_type, 'post_tag') ) |
136 | 2907 |
wp_set_post_tags( $post_ID, $tags_input ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2908 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2909 |
// new-style support for all custom taxonomies |
136 | 2910 |
if ( !empty($tax_input) ) { |
2911 |
foreach ( $tax_input as $taxonomy => $tags ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2912 |
$taxonomy_obj = get_taxonomy($taxonomy); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2913 |
if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2914 |
$tags = array_filter($tags); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2915 |
if ( current_user_can($taxonomy_obj->cap->assign_terms) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2916 |
wp_set_post_terms( $post_ID, $tags, $taxonomy ); |
136 | 2917 |
} |
2918 |
} |
|
2919 |
||
2920 |
$current_guid = get_post_field( 'guid', $post_ID ); |
|
2921 |
||
2922 |
// Set GUID |
|
2923 |
if ( !$update && '' == $current_guid ) |
|
2924 |
$wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_ID ) ), $where ); |
|
2925 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2926 |
clean_post_cache( $post_ID ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2927 |
|
136 | 2928 |
$post = get_post($post_ID); |
2929 |
||
2930 |
if ( !empty($page_template) && 'page' == $data['post_type'] ) { |
|
2931 |
$post->page_template = $page_template; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2932 |
$page_templates = wp_get_theme()->get_page_templates(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2933 |
if ( 'default' != $page_template && ! isset( $page_templates[ $page_template ] ) ) { |
136 | 2934 |
if ( $wp_error ) |
2935 |
return new WP_Error('invalid_page_template', __('The page template is invalid.')); |
|
2936 |
else |
|
2937 |
return 0; |
|
2938 |
} |
|
2939 |
update_post_meta($post_ID, '_wp_page_template', $page_template); |
|
2940 |
} |
|
2941 |
||
2942 |
wp_transition_post_status($data['post_status'], $previous_status, $post); |
|
2943 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2944 |
if ( $update ) { |
136 | 2945 |
do_action('edit_post', $post_ID, $post); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2946 |
$post_after = get_post($post_ID); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2947 |
do_action( 'post_updated', $post_ID, $post_after, $post_before); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2948 |
} |
136 | 2949 |
|
2950 |
do_action('save_post', $post_ID, $post); |
|
2951 |
do_action('wp_insert_post', $post_ID, $post); |
|
2952 |
||
2953 |
return $post_ID; |
|
2954 |
} |
|
2955 |
||
2956 |
/** |
|
2957 |
* Update a post with new post data. |
|
2958 |
* |
|
2959 |
* The date does not have to be set for drafts. You can set the date and it will |
|
2960 |
* not be overridden. |
|
2961 |
* |
|
2962 |
* @since 1.0.0 |
|
2963 |
* |
|
2964 |
* @param array|object $postarr Post data. Arrays are expected to be escaped, objects are not. |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2965 |
* @param bool $wp_error Optional. Allow return of WP_Error on failure. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2966 |
* @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success. |
136 | 2967 |
*/ |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2968 |
function wp_update_post( $postarr = array(), $wp_error = false ) { |
136 | 2969 |
if ( is_object($postarr) ) { |
2970 |
// non-escaped post was passed |
|
2971 |
$postarr = get_object_vars($postarr); |
|
2972 |
$postarr = add_magic_quotes($postarr); |
|
2973 |
} |
|
2974 |
||
2975 |
// First, get all of the original fields |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2976 |
$post = get_post($postarr['ID'], ARRAY_A); |
136 | 2977 |
|
2978 |
// Escape data pulled from DB. |
|
2979 |
$post = add_magic_quotes($post); |
|
2980 |
||
2981 |
// Passed post category list overwrites existing category list if not empty. |
|
2982 |
if ( isset($postarr['post_category']) && is_array($postarr['post_category']) |
|
2983 |
&& 0 != count($postarr['post_category']) ) |
|
2984 |
$post_cats = $postarr['post_category']; |
|
2985 |
else |
|
2986 |
$post_cats = $post['post_category']; |
|
2987 |
||
2988 |
// Drafts shouldn't be assigned a date unless explicitly done so by the user |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2989 |
if ( isset( $post['post_status'] ) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) && |
136 | 2990 |
('0000-00-00 00:00:00' == $post['post_date_gmt']) ) |
2991 |
$clear_date = true; |
|
2992 |
else |
|
2993 |
$clear_date = false; |
|
2994 |
||
2995 |
// Merge old and new fields with new fields overwriting old ones. |
|
2996 |
$postarr = array_merge($post, $postarr); |
|
2997 |
$postarr['post_category'] = $post_cats; |
|
2998 |
if ( $clear_date ) { |
|
2999 |
$postarr['post_date'] = current_time('mysql'); |
|
3000 |
$postarr['post_date_gmt'] = ''; |
|
3001 |
} |
|
3002 |
||
3003 |
if ($postarr['post_type'] == 'attachment') |
|
3004 |
return wp_insert_attachment($postarr); |
|
3005 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3006 |
return wp_insert_post( $postarr, $wp_error ); |
136 | 3007 |
} |
3008 |
||
3009 |
/** |
|
3010 |
* Publish a post by transitioning the post status. |
|
3011 |
* |
|
3012 |
* @since 2.1.0 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3013 |
* @uses wp_update_post() |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3014 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3015 |
* @param mixed $post Post ID or object. |
136 | 3016 |
*/ |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3017 |
function wp_publish_post( $post ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3018 |
if ( ! $post = get_post( $post ) ) |
136 | 3019 |
return; |
3020 |
if ( 'publish' == $post->post_status ) |
|
3021 |
return; |
|
3022 |
||
3023 |
$post->post_status = 'publish'; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3024 |
wp_update_post( $post ); |
136 | 3025 |
} |
3026 |
||
3027 |
/** |
|
3028 |
* Publish future post and make sure post ID has future post status. |
|
3029 |
* |
|
3030 |
* Invoked by cron 'publish_future_post' event. This safeguard prevents cron |
|
3031 |
* from publishing drafts, etc. |
|
3032 |
* |
|
3033 |
* @since 2.5.0 |
|
3034 |
* |
|
3035 |
* @param int $post_id Post ID. |
|
3036 |
* @return null Nothing is returned. Which can mean that no action is required or post was published. |
|
3037 |
*/ |
|
3038 |
function check_and_publish_future_post($post_id) { |
|
3039 |
||
3040 |
$post = get_post($post_id); |
|
3041 |
||
3042 |
if ( empty($post) ) |
|
3043 |
return; |
|
3044 |
||
3045 |
if ( 'future' != $post->post_status ) |
|
3046 |
return; |
|
3047 |
||
3048 |
$time = strtotime( $post->post_date_gmt . ' GMT' ); |
|
3049 |
||
3050 |
if ( $time > time() ) { // Uh oh, someone jumped the gun! |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3051 |
wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); // clear anything else in the system |
136 | 3052 |
wp_schedule_single_event( $time, 'publish_future_post', array( $post_id ) ); |
3053 |
return; |
|
3054 |
} |
|
3055 |
||
3056 |
return wp_publish_post($post_id); |
|
3057 |
} |
|
3058 |
||
3059 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3060 |
* Computes a unique slug for the post, when given the desired slug and some post details. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3061 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3062 |
* @since 2.8.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3063 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3064 |
* @global wpdb $wpdb |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3065 |
* @global WP_Rewrite $wp_rewrite |
136 | 3066 |
* @param string $slug the desired slug (post_name) |
3067 |
* @param integer $post_ID |
|
3068 |
* @param string $post_status no uniqueness checks are made if the post is still draft or pending |
|
3069 |
* @param string $post_type |
|
3070 |
* @param integer $post_parent |
|
3071 |
* @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) |
|
3072 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3073 |
function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3074 |
if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) |
136 | 3075 |
return $slug; |
3076 |
||
3077 |
global $wpdb, $wp_rewrite; |
|
3078 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3079 |
$original_slug = $slug; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3080 |
|
136 | 3081 |
$feeds = $wp_rewrite->feeds; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3082 |
if ( ! is_array( $feeds ) ) |
136 | 3083 |
$feeds = array(); |
3084 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3085 |
$hierarchical_post_types = get_post_types( array('hierarchical' => true) ); |
136 | 3086 |
if ( 'attachment' == $post_type ) { |
3087 |
// Attachment slugs must be unique across all types. |
|
3088 |
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3089 |
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3090 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3091 |
if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) { |
136 | 3092 |
$suffix = 2; |
3093 |
do { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3094 |
$alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3095 |
$post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID ) ); |
136 | 3096 |
$suffix++; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3097 |
} while ( $post_name_check ); |
136 | 3098 |
$slug = $alt_post_name; |
3099 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3100 |
} elseif ( in_array( $post_type, $hierarchical_post_types ) ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3101 |
if ( 'nav_menu_item' == $post_type ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3102 |
return $slug; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3103 |
// Page slugs must be unique within their own trees. Pages are in a separate |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3104 |
// namespace than posts so page slugs are allowed to overlap post slugs. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3105 |
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode( "', '", esc_sql( $hierarchical_post_types ) ) . "' ) AND ID != %d AND post_parent = %d LIMIT 1"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3106 |
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID, $post_parent ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3107 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3108 |
if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) { |
136 | 3109 |
$suffix = 2; |
3110 |
do { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3111 |
$alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3112 |
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID, $post_parent ) ); |
136 | 3113 |
$suffix++; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3114 |
} while ( $post_name_check ); |
136 | 3115 |
$slug = $alt_post_name; |
3116 |
} |
|
3117 |
} else { |
|
3118 |
// Post slugs must be unique across all posts. |
|
3119 |
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3120 |
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3121 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3122 |
if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) { |
136 | 3123 |
$suffix = 2; |
3124 |
do { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3125 |
$alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3126 |
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) ); |
136 | 3127 |
$suffix++; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3128 |
} while ( $post_name_check ); |
136 | 3129 |
$slug = $alt_post_name; |
3130 |
} |
|
3131 |
} |
|
3132 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3133 |
return apply_filters( 'wp_unique_post_slug', $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ); |
136 | 3134 |
} |
3135 |
||
3136 |
/** |
|
3137 |
* Adds tags to a post. |
|
3138 |
* |
|
3139 |
* @uses wp_set_post_tags() Same first two parameters, but the last parameter is always set to true. |
|
3140 |
* |
|
3141 |
* @package WordPress |
|
3142 |
* @subpackage Post |
|
3143 |
* @since 2.3.0 |
|
3144 |
* |
|
3145 |
* @param int $post_id Post ID |
|
3146 |
* @param string $tags The tags to set for the post, separated by commas. |
|
3147 |
* @return bool|null Will return false if $post_id is not an integer or is 0. Will return null otherwise |
|
3148 |
*/ |
|
3149 |
function wp_add_post_tags($post_id = 0, $tags = '') { |
|
3150 |
return wp_set_post_tags($post_id, $tags, true); |
|
3151 |
} |
|
3152 |
||
3153 |
/** |
|
3154 |
* Set the tags for a post. |
|
3155 |
* |
|
3156 |
* @since 2.3.0 |
|
3157 |
* @uses wp_set_object_terms() Sets the tags for the post. |
|
3158 |
* |
|
3159 |
* @param int $post_id Post ID. |
|
3160 |
* @param string $tags The tags to set for the post, separated by commas. |
|
3161 |
* @param bool $append If true, don't delete existing tags, just add on. If false, replace the tags with the new tags. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3162 |
* @return mixed Array of affected term IDs. WP_Error or false on failure. |
136 | 3163 |
*/ |
3164 |
function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) { |
|
3165 |
return wp_set_post_terms( $post_id, $tags, 'post_tag', $append); |
|
3166 |
} |
|
3167 |
||
3168 |
/** |
|
3169 |
* Set the terms for a post. |
|
3170 |
* |
|
3171 |
* @since 2.8.0 |
|
3172 |
* @uses wp_set_object_terms() Sets the tags for the post. |
|
3173 |
* |
|
3174 |
* @param int $post_id Post ID. |
|
3175 |
* @param string $tags The tags to set for the post, separated by commas. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3176 |
* @param string $taxonomy Taxonomy name. Defaults to 'post_tag'. |
136 | 3177 |
* @param bool $append If true, don't delete existing tags, just add on. If false, replace the tags with the new tags. |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3178 |
* @return mixed Array of affected term IDs. WP_Error or false on failure. |
136 | 3179 |
*/ |
3180 |
function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $append = false ) { |
|
3181 |
$post_id = (int) $post_id; |
|
3182 |
||
3183 |
if ( !$post_id ) |
|
3184 |
return false; |
|
3185 |
||
3186 |
if ( empty($tags) ) |
|
3187 |
$tags = array(); |
|
3188 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3189 |
if ( ! is_array( $tags ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3190 |
$comma = _x( ',', 'tag delimiter' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3191 |
if ( ',' !== $comma ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3192 |
$tags = str_replace( $comma, ',', $tags ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3193 |
$tags = explode( ',', trim( $tags, " \n\t\r\0\x0B," ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3194 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3195 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3196 |
// Hierarchical taxonomies must always pass IDs rather than names so that children with the same |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3197 |
// names but different parents aren't confused. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3198 |
if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3199 |
$tags = array_unique( array_map( 'intval', $tags ) ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3200 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3201 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3202 |
return wp_set_object_terms( $post_id, $tags, $taxonomy, $append ); |
136 | 3203 |
} |
3204 |
||
3205 |
/** |
|
3206 |
* Set categories for a post. |
|
3207 |
* |
|
3208 |
* If the post categories parameter is not set, then the default category is |
|
3209 |
* going used. |
|
3210 |
* |
|
3211 |
* @since 2.1.0 |
|
3212 |
* |
|
3213 |
* @param int $post_ID Post ID. |
|
3214 |
* @param array $post_categories Optional. List of categories. |
|
3215 |
* @return bool|mixed |
|
3216 |
*/ |
|
3217 |
function wp_set_post_categories($post_ID = 0, $post_categories = array()) { |
|
3218 |
$post_ID = (int) $post_ID; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3219 |
$post_type = get_post_type( $post_ID ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3220 |
$post_status = get_post_status( $post_ID ); |
136 | 3221 |
// If $post_categories isn't already an array, make it one: |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3222 |
if ( !is_array($post_categories) || empty($post_categories) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3223 |
if ( 'post' == $post_type && 'auto-draft' != $post_status ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3224 |
$post_categories = array( get_option('default_category') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3225 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3226 |
$post_categories = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3227 |
} else if ( 1 == count($post_categories) && '' == reset($post_categories) ) { |
136 | 3228 |
return true; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3229 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3230 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3231 |
return wp_set_post_terms($post_ID, $post_categories, 'category'); |
136 | 3232 |
} |
3233 |
||
3234 |
/** |
|
3235 |
* Transition the post status of a post. |
|
3236 |
* |
|
3237 |
* Calls hooks to transition post status. |
|
3238 |
* |
|
3239 |
* The first is 'transition_post_status' with new status, old status, and post data. |
|
3240 |
* |
|
3241 |
* The next action called is 'OLDSTATUS_to_NEWSTATUS' the 'NEWSTATUS' is the |
|
3242 |
* $new_status parameter and the 'OLDSTATUS' is $old_status parameter; it has the |
|
3243 |
* post data. |
|
3244 |
* |
|
3245 |
* The final action is named 'NEWSTATUS_POSTTYPE', 'NEWSTATUS' is from the $new_status |
|
3246 |
* parameter and POSTTYPE is post_type post data. |
|
3247 |
* |
|
3248 |
* @since 2.3.0 |
|
3249 |
* @link http://codex.wordpress.org/Post_Status_Transitions |
|
3250 |
* |
|
3251 |
* @uses do_action() Calls 'transition_post_status' on $new_status, $old_status and |
|
3252 |
* $post if there is a status change. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3253 |
* @uses do_action() Calls '{$old_status}_to_{$new_status}' on $post if there is a status change. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3254 |
* @uses do_action() Calls '{$new_status}_{$post->post_type}' on post ID and $post. |
136 | 3255 |
* |
3256 |
* @param string $new_status Transition to this post status. |
|
3257 |
* @param string $old_status Previous post status. |
|
3258 |
* @param object $post Post data. |
|
3259 |
*/ |
|
3260 |
function wp_transition_post_status($new_status, $old_status, $post) { |
|
3261 |
do_action('transition_post_status', $new_status, $old_status, $post); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3262 |
do_action("{$old_status}_to_{$new_status}", $post); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3263 |
do_action("{$new_status}_{$post->post_type}", $post->ID, $post); |
136 | 3264 |
} |
3265 |
||
3266 |
// |
|
3267 |
// Trackback and ping functions |
|
3268 |
// |
|
3269 |
||
3270 |
/** |
|
3271 |
* Add a URL to those already pung. |
|
3272 |
* |
|
3273 |
* @since 1.5.0 |
|
3274 |
* @uses $wpdb |
|
3275 |
* |
|
3276 |
* @param int $post_id Post ID. |
|
3277 |
* @param string $uri Ping URI. |
|
3278 |
* @return int How many rows were updated. |
|
3279 |
*/ |
|
3280 |
function add_ping($post_id, $uri) { |
|
3281 |
global $wpdb; |
|
3282 |
$pung = $wpdb->get_var( $wpdb->prepare( "SELECT pinged FROM $wpdb->posts WHERE ID = %d", $post_id )); |
|
3283 |
$pung = trim($pung); |
|
3284 |
$pung = preg_split('/\s/', $pung); |
|
3285 |
$pung[] = $uri; |
|
3286 |
$new = implode("\n", $pung); |
|
3287 |
$new = apply_filters('add_ping', $new); |
|
3288 |
// expected_slashed ($new) |
|
3289 |
$new = stripslashes($new); |
|
3290 |
return $wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post_id ) ); |
|
3291 |
} |
|
3292 |
||
3293 |
/** |
|
3294 |
* Retrieve enclosures already enclosed for a post. |
|
3295 |
* |
|
3296 |
* @since 1.5.0 |
|
3297 |
* @uses $wpdb |
|
3298 |
* |
|
3299 |
* @param int $post_id Post ID. |
|
3300 |
* @return array List of enclosures |
|
3301 |
*/ |
|
3302 |
function get_enclosed($post_id) { |
|
3303 |
$custom_fields = get_post_custom( $post_id ); |
|
3304 |
$pung = array(); |
|
3305 |
if ( !is_array( $custom_fields ) ) |
|
3306 |
return $pung; |
|
3307 |
||
3308 |
foreach ( $custom_fields as $key => $val ) { |
|
3309 |
if ( 'enclosure' != $key || !is_array( $val ) ) |
|
3310 |
continue; |
|
3311 |
foreach( $val as $enc ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3312 |
$enclosure = explode( "\n", $enc ); |
136 | 3313 |
$pung[] = trim( $enclosure[ 0 ] ); |
3314 |
} |
|
3315 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3316 |
$pung = apply_filters('get_enclosed', $pung, $post_id); |
136 | 3317 |
return $pung; |
3318 |
} |
|
3319 |
||
3320 |
/** |
|
3321 |
* Retrieve URLs already pinged for a post. |
|
3322 |
* |
|
3323 |
* @since 1.5.0 |
|
3324 |
* @uses $wpdb |
|
3325 |
* |
|
3326 |
* @param int $post_id Post ID. |
|
3327 |
* @return array |
|
3328 |
*/ |
|
3329 |
function get_pung($post_id) { |
|
3330 |
global $wpdb; |
|
3331 |
$pung = $wpdb->get_var( $wpdb->prepare( "SELECT pinged FROM $wpdb->posts WHERE ID = %d", $post_id )); |
|
3332 |
$pung = trim($pung); |
|
3333 |
$pung = preg_split('/\s/', $pung); |
|
3334 |
$pung = apply_filters('get_pung', $pung); |
|
3335 |
return $pung; |
|
3336 |
} |
|
3337 |
||
3338 |
/** |
|
3339 |
* Retrieve URLs that need to be pinged. |
|
3340 |
* |
|
3341 |
* @since 1.5.0 |
|
3342 |
* @uses $wpdb |
|
3343 |
* |
|
3344 |
* @param int $post_id Post ID |
|
3345 |
* @return array |
|
3346 |
*/ |
|
3347 |
function get_to_ping($post_id) { |
|
3348 |
global $wpdb; |
|
3349 |
$to_ping = $wpdb->get_var( $wpdb->prepare( "SELECT to_ping FROM $wpdb->posts WHERE ID = %d", $post_id )); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3350 |
$to_ping = sanitize_trackback_urls( $to_ping ); |
136 | 3351 |
$to_ping = preg_split('/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY); |
3352 |
$to_ping = apply_filters('get_to_ping', $to_ping); |
|
3353 |
return $to_ping; |
|
3354 |
} |
|
3355 |
||
3356 |
/** |
|
3357 |
* Do trackbacks for a list of URLs. |
|
3358 |
* |
|
3359 |
* @since 1.0.0 |
|
3360 |
* |
|
3361 |
* @param string $tb_list Comma separated list of URLs |
|
3362 |
* @param int $post_id Post ID |
|
3363 |
*/ |
|
3364 |
function trackback_url_list($tb_list, $post_id) { |
|
3365 |
if ( ! empty( $tb_list ) ) { |
|
3366 |
// get post data |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3367 |
$postdata = get_post($post_id, ARRAY_A); |
136 | 3368 |
|
3369 |
// import postdata as variables |
|
3370 |
extract($postdata, EXTR_SKIP); |
|
3371 |
||
3372 |
// form an excerpt |
|
3373 |
$excerpt = strip_tags($post_excerpt ? $post_excerpt : $post_content); |
|
3374 |
||
3375 |
if (strlen($excerpt) > 255) { |
|
3376 |
$excerpt = substr($excerpt,0,252) . '...'; |
|
3377 |
} |
|
3378 |
||
3379 |
$trackback_urls = explode(',', $tb_list); |
|
3380 |
foreach( (array) $trackback_urls as $tb_url) { |
|
3381 |
$tb_url = trim($tb_url); |
|
3382 |
trackback($tb_url, stripslashes($post_title), $excerpt, $post_id); |
|
3383 |
} |
|
3384 |
} |
|
3385 |
} |
|
3386 |
||
3387 |
// |
|
3388 |
// Page functions |
|
3389 |
// |
|
3390 |
||
3391 |
/** |
|
3392 |
* Get a list of page IDs. |
|
3393 |
* |
|
3394 |
* @since 2.0.0 |
|
3395 |
* @uses $wpdb |
|
3396 |
* |
|
3397 |
* @return array List of page IDs. |
|
3398 |
*/ |
|
3399 |
function get_all_page_ids() { |
|
3400 |
global $wpdb; |
|
3401 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3402 |
$page_ids = wp_cache_get('all_page_ids', 'posts'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3403 |
if ( ! is_array( $page_ids ) ) { |
136 | 3404 |
$page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'page'"); |
3405 |
wp_cache_add('all_page_ids', $page_ids, 'posts'); |
|
3406 |
} |
|
3407 |
||
3408 |
return $page_ids; |
|
3409 |
} |
|
3410 |
||
3411 |
/** |
|
3412 |
* Retrieves page data given a page ID or page object. |
|
3413 |
* |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3414 |
* Use get_post() instead of get_page(). |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3415 |
* |
136 | 3416 |
* @since 1.5.1 |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3417 |
* @deprecated 3.5.0 |
136 | 3418 |
* |
3419 |
* @param mixed $page Page object or page ID. Passed by reference. |
|
3420 |
* @param string $output What to output. OBJECT, ARRAY_A, or ARRAY_N. |
|
3421 |
* @param string $filter How the return value should be filtered. |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3422 |
* @return WP_Post|null WP_Post on success or null on failure |
136 | 3423 |
*/ |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3424 |
function get_page( $page, $output = OBJECT, $filter = 'raw') { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3425 |
return get_post( $page, $output, $filter ); |
136 | 3426 |
} |
3427 |
||
3428 |
/** |
|
3429 |
* Retrieves a page given its path. |
|
3430 |
* |
|
3431 |
* @since 2.1.0 |
|
3432 |
* @uses $wpdb |
|
3433 |
* |
|
3434 |
* @param string $page_path Page path |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3435 |
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3436 |
* @param string $post_type Optional. Post type. Default page. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3437 |
* @return WP_Post|null WP_Post on success or null on failure |
136 | 3438 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3439 |
function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') { |
136 | 3440 |
global $wpdb; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3441 |
|
136 | 3442 |
$page_path = rawurlencode(urldecode($page_path)); |
3443 |
$page_path = str_replace('%2F', '/', $page_path); |
|
3444 |
$page_path = str_replace('%20', ' ', $page_path); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3445 |
$parts = explode( '/', trim( $page_path, '/' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3446 |
$parts = array_map( 'esc_sql', $parts ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3447 |
$parts = array_map( 'sanitize_title_for_query', $parts ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3448 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3449 |
$in_string = "'". implode( "','", $parts ) . "'"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3450 |
$post_type_sql = $post_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3451 |
$wpdb->escape_by_ref( $post_type_sql ); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3452 |
$pages = $wpdb->get_results( "SELECT ID, post_name, post_parent, post_type FROM $wpdb->posts WHERE post_name IN ($in_string) AND (post_type = '$post_type_sql' OR post_type = 'attachment')", OBJECT_K ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3453 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3454 |
$revparts = array_reverse( $parts ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3455 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3456 |
$foundid = 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3457 |
foreach ( (array) $pages as $page ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3458 |
if ( $page->post_name == $revparts[0] ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3459 |
$count = 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3460 |
$p = $page; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3461 |
while ( $p->post_parent != 0 && isset( $pages[ $p->post_parent ] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3462 |
$count++; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3463 |
$parent = $pages[ $p->post_parent ]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3464 |
if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3465 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3466 |
$p = $parent; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3467 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3468 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3469 |
if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3470 |
$foundid = $page->ID; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3471 |
if ( $page->post_type == $post_type ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3472 |
break; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3473 |
} |
136 | 3474 |
} |
3475 |
} |
|
3476 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3477 |
if ( $foundid ) |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3478 |
return get_post( $foundid, $output ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3479 |
|
136 | 3480 |
return null; |
3481 |
} |
|
3482 |
||
3483 |
/** |
|
3484 |
* Retrieve a page given its title. |
|
3485 |
* |
|
3486 |
* @since 2.1.0 |
|
3487 |
* @uses $wpdb |
|
3488 |
* |
|
3489 |
* @param string $page_title Page title |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3490 |
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3491 |
* @param string $post_type Optional. Post type. Default page. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3492 |
* @return WP_Post|null WP_Post on success or null on failure |
136 | 3493 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3494 |
function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page' ) { |
136 | 3495 |
global $wpdb; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3496 |
$page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type= %s", $page_title, $post_type ) ); |
136 | 3497 |
if ( $page ) |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3498 |
return get_post( $page, $output ); |
136 | 3499 |
|
3500 |
return null; |
|
3501 |
} |
|
3502 |
||
3503 |
/** |
|
3504 |
* Retrieve child pages from list of pages matching page ID. |
|
3505 |
* |
|
3506 |
* Matches against the pages parameter against the page ID. Also matches all |
|
3507 |
* children for the same to retrieve all children of a page. Does not make any |
|
3508 |
* SQL queries to get the children. |
|
3509 |
* |
|
3510 |
* @since 1.5.1 |
|
3511 |
* |
|
3512 |
* @param int $page_id Page ID. |
|
3513 |
* @param array $pages List of pages' objects. |
|
3514 |
* @return array |
|
3515 |
*/ |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3516 |
function get_page_children($page_id, $pages) { |
136 | 3517 |
$page_list = array(); |
3518 |
foreach ( (array) $pages as $page ) { |
|
3519 |
if ( $page->post_parent == $page_id ) { |
|
3520 |
$page_list[] = $page; |
|
3521 |
if ( $children = get_page_children($page->ID, $pages) ) |
|
3522 |
$page_list = array_merge($page_list, $children); |
|
3523 |
} |
|
3524 |
} |
|
3525 |
return $page_list; |
|
3526 |
} |
|
3527 |
||
3528 |
/** |
|
3529 |
* Order the pages with children under parents in a flat list. |
|
3530 |
* |
|
3531 |
* It uses auxiliary structure to hold parent-children relationships and |
|
3532 |
* runs in O(N) complexity |
|
3533 |
* |
|
3534 |
* @since 2.0.0 |
|
3535 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3536 |
* @param array $pages Posts array. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3537 |
* @param int $page_id Parent page ID. |
136 | 3538 |
* @return array A list arranged by hierarchy. Children immediately follow their parents. |
3539 |
*/ |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3540 |
function get_page_hierarchy( &$pages, $page_id = 0 ) { |
136 | 3541 |
if ( empty( $pages ) ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3542 |
$result = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3543 |
return $result; |
136 | 3544 |
} |
3545 |
||
3546 |
$children = array(); |
|
3547 |
foreach ( (array) $pages as $p ) { |
|
3548 |
$parent_id = intval( $p->post_parent ); |
|
3549 |
$children[ $parent_id ][] = $p; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3550 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3551 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3552 |
$result = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3553 |
_page_traverse_name( $page_id, $children, $result ); |
136 | 3554 |
|
3555 |
return $result; |
|
3556 |
} |
|
3557 |
||
3558 |
/** |
|
3559 |
* function to traverse and return all the nested children post names of a root page. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3560 |
* $children contains parent-children relations |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3561 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3562 |
* @since 2.9.0 |
136 | 3563 |
*/ |
3564 |
function _page_traverse_name( $page_id, &$children, &$result ){ |
|
3565 |
if ( isset( $children[ $page_id ] ) ){ |
|
3566 |
foreach( (array)$children[ $page_id ] as $child ) { |
|
3567 |
$result[ $child->ID ] = $child->post_name; |
|
3568 |
_page_traverse_name( $child->ID, $children, $result ); |
|
3569 |
} |
|
3570 |
} |
|
3571 |
} |
|
3572 |
||
3573 |
/** |
|
3574 |
* Builds URI for a page. |
|
3575 |
* |
|
3576 |
* Sub pages will be in the "directory" under the parent page post name. |
|
3577 |
* |
|
3578 |
* @since 1.5.0 |
|
3579 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3580 |
* @param mixed $page Page object or page ID. |
136 | 3581 |
* @return string Page URI. |
3582 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3583 |
function get_page_uri($page) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3584 |
if ( ! is_object($page) ) |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3585 |
$page = get_post( $page ); |
136 | 3586 |
$uri = $page->post_name; |
3587 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3588 |
foreach ( $page->ancestors as $parent ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3589 |
$uri = get_post( $parent )->post_name . "/" . $uri; |
136 | 3590 |
} |
3591 |
||
3592 |
return $uri; |
|
3593 |
} |
|
3594 |
||
3595 |
/** |
|
3596 |
* Retrieve a list of pages. |
|
3597 |
* |
|
3598 |
* The defaults that can be overridden are the following: 'child_of', |
|
3599 |
* 'sort_order', 'sort_column', 'post_title', 'hierarchical', 'exclude', |
|
3600 |
* 'include', 'meta_key', 'meta_value','authors', 'number', and 'offset'. |
|
3601 |
* |
|
3602 |
* @since 1.5.0 |
|
3603 |
* @uses $wpdb |
|
3604 |
* |
|
3605 |
* @param mixed $args Optional. Array or string of options that overrides defaults. |
|
3606 |
* @return array List of pages matching defaults or $args |
|
3607 |
*/ |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3608 |
function get_pages($args = '') { |
136 | 3609 |
global $wpdb; |
3610 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3611 |
$pages = false; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3612 |
|
136 | 3613 |
$defaults = array( |
3614 |
'child_of' => 0, 'sort_order' => 'ASC', |
|
3615 |
'sort_column' => 'post_title', 'hierarchical' => 1, |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3616 |
'exclude' => array(), 'include' => array(), |
136 | 3617 |
'meta_key' => '', 'meta_value' => '', |
3618 |
'authors' => '', 'parent' => -1, 'exclude_tree' => '', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3619 |
'number' => '', 'offset' => 0, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3620 |
'post_type' => 'page', 'post_status' => 'publish', |
136 | 3621 |
); |
3622 |
||
3623 |
$r = wp_parse_args( $args, $defaults ); |
|
3624 |
extract( $r, EXTR_SKIP ); |
|
3625 |
$number = (int) $number; |
|
3626 |
$offset = (int) $offset; |
|
3627 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3628 |
// Make sure the post type is hierarchical |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3629 |
$hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3630 |
if ( !in_array( $post_type, $hierarchical_post_types ) ) |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3631 |
return $pages; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3632 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3633 |
// Make sure we have a valid post status |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3634 |
if ( !is_array( $post_status ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3635 |
$post_status = explode( ',', $post_status ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3636 |
if ( array_diff( $post_status, get_post_stati() ) ) |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3637 |
return $pages; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3638 |
|
136 | 3639 |
$cache = array(); |
3640 |
$key = md5( serialize( compact(array_keys($defaults)) ) ); |
|
3641 |
if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3642 |
if ( is_array($cache) && isset( $cache[ $key ] ) && is_array( $cache[ $key ] ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3643 |
// Convert to WP_Post instances |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3644 |
$pages = array_map( 'get_post', $cache[ $key ] ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3645 |
$pages = apply_filters( 'get_pages', $pages, $r ); |
136 | 3646 |
return $pages; |
3647 |
} |
|
3648 |
} |
|
3649 |
||
3650 |
if ( !is_array($cache) ) |
|
3651 |
$cache = array(); |
|
3652 |
||
3653 |
$inclusions = ''; |
|
3654 |
if ( !empty($include) ) { |
|
3655 |
$child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include |
|
3656 |
$parent = -1; |
|
3657 |
$exclude = ''; |
|
3658 |
$meta_key = ''; |
|
3659 |
$meta_value = ''; |
|
3660 |
$hierarchical = false; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3661 |
$incpages = wp_parse_id_list( $include ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3662 |
if ( ! empty( $incpages ) ) { |
136 | 3663 |
foreach ( $incpages as $incpage ) { |
3664 |
if (empty($inclusions)) |
|
3665 |
$inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage); |
|
3666 |
else |
|
3667 |
$inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage); |
|
3668 |
} |
|
3669 |
} |
|
3670 |
} |
|
3671 |
if (!empty($inclusions)) |
|
3672 |
$inclusions .= ')'; |
|
3673 |
||
3674 |
$exclusions = ''; |
|
3675 |
if ( !empty($exclude) ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3676 |
$expages = wp_parse_id_list( $exclude ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3677 |
if ( ! empty( $expages ) ) { |
136 | 3678 |
foreach ( $expages as $expage ) { |
3679 |
if (empty($exclusions)) |
|
3680 |
$exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage); |
|
3681 |
else |
|
3682 |
$exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage); |
|
3683 |
} |
|
3684 |
} |
|
3685 |
} |
|
3686 |
if (!empty($exclusions)) |
|
3687 |
$exclusions .= ')'; |
|
3688 |
||
3689 |
$author_query = ''; |
|
3690 |
if (!empty($authors)) { |
|
3691 |
$post_authors = preg_split('/[\s,]+/',$authors); |
|
3692 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3693 |
if ( ! empty( $post_authors ) ) { |
136 | 3694 |
foreach ( $post_authors as $post_author ) { |
3695 |
//Do we have an author id or an author login? |
|
3696 |
if ( 0 == intval($post_author) ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3697 |
$post_author = get_user_by('login', $post_author); |
136 | 3698 |
if ( empty($post_author) ) |
3699 |
continue; |
|
3700 |
if ( empty($post_author->ID) ) |
|
3701 |
continue; |
|
3702 |
$post_author = $post_author->ID; |
|
3703 |
} |
|
3704 |
||
3705 |
if ( '' == $author_query ) |
|
3706 |
$author_query = $wpdb->prepare(' post_author = %d ', $post_author); |
|
3707 |
else |
|
3708 |
$author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author); |
|
3709 |
} |
|
3710 |
if ( '' != $author_query ) |
|
3711 |
$author_query = " AND ($author_query)"; |
|
3712 |
} |
|
3713 |
} |
|
3714 |
||
3715 |
$join = ''; |
|
3716 |
$where = "$exclusions $inclusions "; |
|
3717 |
if ( ! empty( $meta_key ) || ! empty( $meta_value ) ) { |
|
3718 |
$join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )"; |
|
3719 |
||
3720 |
// meta_key and meta_value might be slashed |
|
3721 |
$meta_key = stripslashes($meta_key); |
|
3722 |
$meta_value = stripslashes($meta_value); |
|
3723 |
if ( ! empty( $meta_key ) ) |
|
3724 |
$where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key); |
|
3725 |
if ( ! empty( $meta_value ) ) |
|
3726 |
$where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value); |
|
3727 |
||
3728 |
} |
|
3729 |
||
3730 |
if ( $parent >= 0 ) |
|
3731 |
$where .= $wpdb->prepare(' AND post_parent = %d ', $parent); |
|
3732 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3733 |
if ( 1 == count( $post_status ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3734 |
$where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $post_type, array_shift( $post_status ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3735 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3736 |
$post_status = implode( "', '", $post_status ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3737 |
$where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3738 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3739 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3740 |
$orderby_array = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3741 |
$allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3742 |
'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3743 |
'ID', 'rand', 'comment_count'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3744 |
foreach ( explode( ',', $sort_column ) as $orderby ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3745 |
$orderby = trim( $orderby ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3746 |
if ( !in_array( $orderby, $allowed_keys ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3747 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3748 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3749 |
switch ( $orderby ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3750 |
case 'menu_order': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3751 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3752 |
case 'ID': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3753 |
$orderby = "$wpdb->posts.ID"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3754 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3755 |
case 'rand': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3756 |
$orderby = 'RAND()'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3757 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3758 |
case 'comment_count': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3759 |
$orderby = "$wpdb->posts.comment_count"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3760 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3761 |
default: |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3762 |
if ( 0 === strpos( $orderby, 'post_' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3763 |
$orderby = "$wpdb->posts." . $orderby; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3764 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3765 |
$orderby = "$wpdb->posts.post_" . $orderby; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3766 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3767 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3768 |
$orderby_array[] = $orderby; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3769 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3770 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3771 |
$sort_column = ! empty( $orderby_array ) ? implode( ',', $orderby_array ) : "$wpdb->posts.post_title"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3772 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3773 |
$sort_order = strtoupper( $sort_order ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3774 |
if ( '' !== $sort_order && !in_array( $sort_order, array( 'ASC', 'DESC' ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3775 |
$sort_order = 'ASC'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3776 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3777 |
$query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where "; |
136 | 3778 |
$query .= $author_query; |
3779 |
$query .= " ORDER BY " . $sort_column . " " . $sort_order ; |
|
3780 |
||
3781 |
if ( !empty($number) ) |
|
3782 |
$query .= ' LIMIT ' . $offset . ',' . $number; |
|
3783 |
||
3784 |
$pages = $wpdb->get_results($query); |
|
3785 |
||
3786 |
if ( empty($pages) ) { |
|
3787 |
$pages = apply_filters('get_pages', array(), $r); |
|
3788 |
return $pages; |
|
3789 |
} |
|
3790 |
||
3791 |
// Sanitize before caching so it'll only get done once |
|
3792 |
$num_pages = count($pages); |
|
3793 |
for ($i = 0; $i < $num_pages; $i++) { |
|
3794 |
$pages[$i] = sanitize_post($pages[$i], 'raw'); |
|
3795 |
} |
|
3796 |
||
3797 |
// Update cache. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3798 |
update_post_cache( $pages ); |
136 | 3799 |
|
3800 |
if ( $child_of || $hierarchical ) |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3801 |
$pages = get_page_children($child_of, $pages); |
136 | 3802 |
|
3803 |
if ( !empty($exclude_tree) ) { |
|
3804 |
$exclude = (int) $exclude_tree; |
|
3805 |
$children = get_page_children($exclude, $pages); |
|
3806 |
$excludes = array(); |
|
3807 |
foreach ( $children as $child ) |
|
3808 |
$excludes[] = $child->ID; |
|
3809 |
$excludes[] = $exclude; |
|
3810 |
$num_pages = count($pages); |
|
3811 |
for ( $i = 0; $i < $num_pages; $i++ ) { |
|
3812 |
if ( in_array($pages[$i]->ID, $excludes) ) |
|
3813 |
unset($pages[$i]); |
|
3814 |
} |
|
3815 |
} |
|
3816 |
||
3817 |
$cache[ $key ] = $pages; |
|
3818 |
wp_cache_set( 'get_pages', $cache, 'posts' ); |
|
3819 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3820 |
// Convert to WP_Post instances |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3821 |
$pages = array_map( 'get_post', $pages ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3822 |
|
136 | 3823 |
$pages = apply_filters('get_pages', $pages, $r); |
3824 |
||
3825 |
return $pages; |
|
3826 |
} |
|
3827 |
||
3828 |
// |
|
3829 |
// Attachment functions |
|
3830 |
// |
|
3831 |
||
3832 |
/** |
|
3833 |
* Check if the attachment URI is local one and is really an attachment. |
|
3834 |
* |
|
3835 |
* @since 2.0.0 |
|
3836 |
* |
|
3837 |
* @param string $url URL to check |
|
3838 |
* @return bool True on success, false on failure. |
|
3839 |
*/ |
|
3840 |
function is_local_attachment($url) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3841 |
if (strpos($url, home_url()) === false) |
136 | 3842 |
return false; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3843 |
if (strpos($url, home_url('/?attachment_id=')) !== false) |
136 | 3844 |
return true; |
3845 |
if ( $id = url_to_postid($url) ) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3846 |
$post = get_post($id); |
136 | 3847 |
if ( 'attachment' == $post->post_type ) |
3848 |
return true; |
|
3849 |
} |
|
3850 |
return false; |
|
3851 |
} |
|
3852 |
||
3853 |
/** |
|
3854 |
* Insert an attachment. |
|
3855 |
* |
|
3856 |
* If you set the 'ID' in the $object parameter, it will mean that you are |
|
3857 |
* updating and attempt to update the attachment. You can also set the |
|
3858 |
* attachment name or title by setting the key 'post_name' or 'post_title'. |
|
3859 |
* |
|
3860 |
* You can set the dates for the attachment manually by setting the 'post_date' |
|
3861 |
* and 'post_date_gmt' keys' values. |
|
3862 |
* |
|
3863 |
* By default, the comments will use the default settings for whether the |
|
3864 |
* comments are allowed. You can close them manually or keep them open by |
|
3865 |
* setting the value for the 'comment_status' key. |
|
3866 |
* |
|
3867 |
* The $object parameter can have the following: |
|
3868 |
* 'post_status' - Default is 'draft'. Can not be overridden, set the same as parent post. |
|
3869 |
* 'post_type' - Default is 'post', will be set to attachment. Can not override. |
|
3870 |
* 'post_author' - Default is current user ID. The ID of the user, who added the attachment. |
|
3871 |
* 'ping_status' - Default is the value in default ping status option. Whether the attachment |
|
3872 |
* can accept pings. |
|
3873 |
* 'post_parent' - Default is 0. Can use $parent parameter or set this for the post it belongs |
|
3874 |
* to, if any. |
|
3875 |
* 'menu_order' - Default is 0. The order it is displayed. |
|
3876 |
* 'to_ping' - Whether to ping. |
|
3877 |
* 'pinged' - Default is empty string. |
|
3878 |
* 'post_password' - Default is empty string. The password to access the attachment. |
|
3879 |
* 'guid' - Global Unique ID for referencing the attachment. |
|
3880 |
* 'post_content_filtered' - Attachment post content filtered. |
|
3881 |
* 'post_excerpt' - Attachment excerpt. |
|
3882 |
* |
|
3883 |
* @since 2.0.0 |
|
3884 |
* @uses $wpdb |
|
3885 |
* @uses $user_ID |
|
3886 |
* @uses do_action() Calls 'edit_attachment' on $post_ID if this is an update. |
|
3887 |
* @uses do_action() Calls 'add_attachment' on $post_ID if this is not an update. |
|
3888 |
* |
|
3889 |
* @param string|array $object Arguments to override defaults. |
|
3890 |
* @param string $file Optional filename. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3891 |
* @param int $parent Parent post ID. |
136 | 3892 |
* @return int Attachment ID. |
3893 |
*/ |
|
3894 |
function wp_insert_attachment($object, $file = false, $parent = 0) { |
|
3895 |
global $wpdb, $user_ID; |
|
3896 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3897 |
$defaults = array('post_status' => 'inherit', 'post_type' => 'post', 'post_author' => $user_ID, |
136 | 3898 |
'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, |
3899 |
'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3900 |
'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'context' => ''); |
136 | 3901 |
|
3902 |
$object = wp_parse_args($object, $defaults); |
|
3903 |
if ( !empty($parent) ) |
|
3904 |
$object['post_parent'] = $parent; |
|
3905 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3906 |
unset( $object[ 'filter' ] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3907 |
|
136 | 3908 |
$object = sanitize_post($object, 'db'); |
3909 |
||
3910 |
// export array as variables |
|
3911 |
extract($object, EXTR_SKIP); |
|
3912 |
||
3913 |
if ( empty($post_author) ) |
|
3914 |
$post_author = $user_ID; |
|
3915 |
||
3916 |
$post_type = 'attachment'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3917 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3918 |
if ( ! in_array( $post_status, array( 'inherit', 'private' ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3919 |
$post_status = 'inherit'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3920 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3921 |
if ( !empty($post_category) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3922 |
$post_category = array_filter($post_category); // Filter out empty terms |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3923 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3924 |
// Make sure we set a valid category. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3925 |
if ( empty($post_category) || 0 == count($post_category) || !is_array($post_category) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3926 |
$post_category = array(); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3927 |
} |
136 | 3928 |
|
3929 |
// Are we updating or creating? |
|
3930 |
if ( !empty($ID) ) { |
|
3931 |
$update = true; |
|
3932 |
$post_ID = (int) $ID; |
|
3933 |
} else { |
|
3934 |
$update = false; |
|
3935 |
$post_ID = 0; |
|
3936 |
} |
|
3937 |
||
3938 |
// Create a valid post name. |
|
3939 |
if ( empty($post_name) ) |
|
3940 |
$post_name = sanitize_title($post_title); |
|
3941 |
else |
|
3942 |
$post_name = sanitize_title($post_name); |
|
3943 |
||
3944 |
// expected_slashed ($post_name) |
|
3945 |
$post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent); |
|
3946 |
||
3947 |
if ( empty($post_date) ) |
|
3948 |
$post_date = current_time('mysql'); |
|
3949 |
if ( empty($post_date_gmt) ) |
|
3950 |
$post_date_gmt = current_time('mysql', 1); |
|
3951 |
||
3952 |
if ( empty($post_modified) ) |
|
3953 |
$post_modified = $post_date; |
|
3954 |
if ( empty($post_modified_gmt) ) |
|
3955 |
$post_modified_gmt = $post_date_gmt; |
|
3956 |
||
3957 |
if ( empty($comment_status) ) { |
|
3958 |
if ( $update ) |
|
3959 |
$comment_status = 'closed'; |
|
3960 |
else |
|
3961 |
$comment_status = get_option('default_comment_status'); |
|
3962 |
} |
|
3963 |
if ( empty($ping_status) ) |
|
3964 |
$ping_status = get_option('default_ping_status'); |
|
3965 |
||
3966 |
if ( isset($to_ping) ) |
|
3967 |
$to_ping = preg_replace('|\s+|', "\n", $to_ping); |
|
3968 |
else |
|
3969 |
$to_ping = ''; |
|
3970 |
||
3971 |
if ( isset($post_parent) ) |
|
3972 |
$post_parent = (int) $post_parent; |
|
3973 |
else |
|
3974 |
$post_parent = 0; |
|
3975 |
||
3976 |
if ( isset($menu_order) ) |
|
3977 |
$menu_order = (int) $menu_order; |
|
3978 |
else |
|
3979 |
$menu_order = 0; |
|
3980 |
||
3981 |
if ( !isset($post_password) ) |
|
3982 |
$post_password = ''; |
|
3983 |
||
3984 |
if ( ! isset($pinged) ) |
|
3985 |
$pinged = ''; |
|
3986 |
||
3987 |
// expected_slashed (everything!) |
|
3988 |
$data = compact( array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'guid' ) ); |
|
3989 |
$data = stripslashes_deep( $data ); |
|
3990 |
||
3991 |
if ( $update ) { |
|
3992 |
$wpdb->update( $wpdb->posts, $data, array( 'ID' => $post_ID ) ); |
|
3993 |
} else { |
|
3994 |
// If there is a suggested ID, use it if not already present |
|
3995 |
if ( !empty($import_id) ) { |
|
3996 |
$import_id = (int) $import_id; |
|
3997 |
if ( ! $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id) ) ) { |
|
3998 |
$data['ID'] = $import_id; |
|
3999 |
} |
|
4000 |
} |
|
4001 |
||
4002 |
$wpdb->insert( $wpdb->posts, $data ); |
|
4003 |
$post_ID = (int) $wpdb->insert_id; |
|
4004 |
} |
|
4005 |
||
4006 |
if ( empty($post_name) ) { |
|
4007 |
$post_name = sanitize_title($post_title, $post_ID); |
|
4008 |
$wpdb->update( $wpdb->posts, compact("post_name"), array( 'ID' => $post_ID ) ); |
|
4009 |
} |
|
4010 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4011 |
if ( is_object_in_taxonomy($post_type, 'category') ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4012 |
wp_set_post_categories( $post_ID, $post_category ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4013 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4014 |
if ( isset( $tags_input ) && is_object_in_taxonomy($post_type, 'post_tag') ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4015 |
wp_set_post_tags( $post_ID, $tags_input ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4016 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4017 |
// support for all custom taxonomies |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4018 |
if ( !empty($tax_input) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4019 |
foreach ( $tax_input as $taxonomy => $tags ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4020 |
$taxonomy_obj = get_taxonomy($taxonomy); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4021 |
if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4022 |
$tags = array_filter($tags); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4023 |
if ( current_user_can($taxonomy_obj->cap->assign_terms) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4024 |
wp_set_post_terms( $post_ID, $tags, $taxonomy ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4025 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4026 |
} |
136 | 4027 |
|
4028 |
if ( $file ) |
|
4029 |
update_attached_file( $post_ID, $file ); |
|
4030 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4031 |
clean_post_cache( $post_ID ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4032 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4033 |
if ( ! empty( $context ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4034 |
add_post_meta( $post_ID, '_wp_attachment_context', $context, true ); |
136 | 4035 |
|
4036 |
if ( $update) { |
|
4037 |
do_action('edit_attachment', $post_ID); |
|
4038 |
} else { |
|
4039 |
do_action('add_attachment', $post_ID); |
|
4040 |
} |
|
4041 |
||
4042 |
return $post_ID; |
|
4043 |
} |
|
4044 |
||
4045 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4046 |
* Trashes or deletes an attachment. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4047 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4048 |
* When an attachment is permanently deleted, the file will also be removed. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4049 |
* Deletion removes all post meta fields, taxonomy, comments, etc. associated |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4050 |
* with the attachment (except the main post). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4051 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4052 |
* The attachment is moved to the trash instead of permanently deleted unless trash |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4053 |
* for media is disabled, item is already in the trash, or $force_delete is true. |
136 | 4054 |
* |
4055 |
* @since 2.0.0 |
|
4056 |
* @uses $wpdb |
|
4057 |
* @uses do_action() Calls 'delete_attachment' hook on Attachment ID. |
|
4058 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4059 |
* @param int $post_id Attachment ID. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4060 |
* @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false. |
136 | 4061 |
* @return mixed False on failure. Post data on success. |
4062 |
*/ |
|
4063 |
function wp_delete_attachment( $post_id, $force_delete = false ) { |
|
4064 |
global $wpdb; |
|
4065 |
||
4066 |
if ( !$post = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id) ) ) |
|
4067 |
return $post; |
|
4068 |
||
4069 |
if ( 'attachment' != $post->post_type ) |
|
4070 |
return false; |
|
4071 |
||
4072 |
if ( !$force_delete && EMPTY_TRASH_DAYS && MEDIA_TRASH && 'trash' != $post->post_status ) |
|
4073 |
return wp_trash_post( $post_id ); |
|
4074 |
||
4075 |
delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
4076 |
delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
4077 |
||
4078 |
$meta = wp_get_attachment_metadata( $post_id ); |
|
4079 |
$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true ); |
|
4080 |
$file = get_attached_file( $post_id ); |
|
4081 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4082 |
$intermediate_sizes = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4083 |
foreach ( get_intermediate_image_sizes() as $size ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4084 |
if ( $intermediate = image_get_intermediate_size( $post_id, $size ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4085 |
$intermediate_sizes[] = $intermediate; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4086 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4087 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4088 |
if ( is_multisite() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4089 |
delete_transient( 'dirsize_cache' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4090 |
|
136 | 4091 |
do_action('delete_attachment', $post_id); |
4092 |
||
4093 |
wp_delete_object_term_relationships($post_id, array('category', 'post_tag')); |
|
4094 |
wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type)); |
|
4095 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4096 |
delete_metadata( 'post', null, '_thumbnail_id', $post_id, true ); // delete all for any posts. |
136 | 4097 |
|
4098 |
$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id )); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4099 |
foreach ( $comment_ids as $comment_id ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4100 |
wp_delete_comment( $comment_id, true ); |
136 | 4101 |
|
4102 |
$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id )); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4103 |
foreach ( $post_meta_ids as $mid ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4104 |
delete_metadata_by_mid( 'post', $mid ); |
136 | 4105 |
|
4106 |
do_action( 'delete_post', $post_id ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4107 |
$wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) ); |
136 | 4108 |
do_action( 'deleted_post', $post_id ); |
4109 |
||
4110 |
$uploadpath = wp_upload_dir(); |
|
4111 |
||
4112 |
if ( ! empty($meta['thumb']) ) { |
|
4113 |
// Don't delete the thumb if another attachment uses it |
|
4114 |
if (! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $meta['thumb'] . '%', $post_id)) ) { |
|
4115 |
$thumbfile = str_replace(basename($file), $meta['thumb'], $file); |
|
4116 |
$thumbfile = apply_filters('wp_delete_file', $thumbfile); |
|
4117 |
@ unlink( path_join($uploadpath['basedir'], $thumbfile) ); |
|
4118 |
} |
|
4119 |
} |
|
4120 |
||
4121 |
// remove intermediate and backup images if there are any |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4122 |
foreach ( $intermediate_sizes as $intermediate ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4123 |
$intermediate_file = apply_filters( 'wp_delete_file', $intermediate['path'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4124 |
@ unlink( path_join($uploadpath['basedir'], $intermediate_file) ); |
136 | 4125 |
} |
4126 |
||
4127 |
if ( is_array($backup_sizes) ) { |
|
4128 |
foreach ( $backup_sizes as $size ) { |
|
4129 |
$del_file = path_join( dirname($meta['file']), $size['file'] ); |
|
4130 |
$del_file = apply_filters('wp_delete_file', $del_file); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4131 |
@ unlink( path_join($uploadpath['basedir'], $del_file) ); |
136 | 4132 |
} |
4133 |
} |
|
4134 |
||
4135 |
$file = apply_filters('wp_delete_file', $file); |
|
4136 |
||
4137 |
if ( ! empty($file) ) |
|
4138 |
@ unlink($file); |
|
4139 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4140 |
clean_post_cache( $post ); |
136 | 4141 |
|
4142 |
return $post; |
|
4143 |
} |
|
4144 |
||
4145 |
/** |
|
4146 |
* Retrieve attachment meta field for attachment ID. |
|
4147 |
* |
|
4148 |
* @since 2.1.0 |
|
4149 |
* |
|
4150 |
* @param int $post_id Attachment ID |
|
4151 |
* @param bool $unfiltered Optional, default is false. If true, filters are not run. |
|
4152 |
* @return string|bool Attachment meta field. False on failure. |
|
4153 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4154 |
function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) { |
136 | 4155 |
$post_id = (int) $post_id; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4156 |
if ( !$post = get_post( $post_id ) ) |
136 | 4157 |
return false; |
4158 |
||
4159 |
$data = get_post_meta( $post->ID, '_wp_attachment_metadata', true ); |
|
4160 |
||
4161 |
if ( $unfiltered ) |
|
4162 |
return $data; |
|
4163 |
||
4164 |
return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID ); |
|
4165 |
} |
|
4166 |
||
4167 |
/** |
|
4168 |
* Update metadata for an attachment. |
|
4169 |
* |
|
4170 |
* @since 2.1.0 |
|
4171 |
* |
|
4172 |
* @param int $post_id Attachment ID. |
|
4173 |
* @param array $data Attachment data. |
|
4174 |
* @return int |
|
4175 |
*/ |
|
4176 |
function wp_update_attachment_metadata( $post_id, $data ) { |
|
4177 |
$post_id = (int) $post_id; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4178 |
if ( !$post = get_post( $post_id ) ) |
136 | 4179 |
return false; |
4180 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4181 |
if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4182 |
return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4183 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4184 |
return delete_post_meta( $post->ID, '_wp_attachment_metadata' ); |
136 | 4185 |
} |
4186 |
||
4187 |
/** |
|
4188 |
* Retrieve the URL for an attachment. |
|
4189 |
* |
|
4190 |
* @since 2.1.0 |
|
4191 |
* |
|
4192 |
* @param int $post_id Attachment ID. |
|
4193 |
* @return string |
|
4194 |
*/ |
|
4195 |
function wp_get_attachment_url( $post_id = 0 ) { |
|
4196 |
$post_id = (int) $post_id; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4197 |
if ( !$post = get_post( $post_id ) ) |
136 | 4198 |
return false; |
4199 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4200 |
if ( 'attachment' != $post->post_type ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4201 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4202 |
|
136 | 4203 |
$url = ''; |
4204 |
if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { //Get attached file |
|
4205 |
if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { //Get upload directory |
|
4206 |
if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location |
|
4207 |
$url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); //replace file location with url location |
|
4208 |
elseif ( false !== strpos($file, 'wp-content/uploads') ) |
|
4209 |
$url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 ); |
|
4210 |
else |
|
4211 |
$url = $uploads['baseurl'] . "/$file"; //Its a newly uploaded file, therefor $file is relative to the basedir. |
|
4212 |
} |
|
4213 |
} |
|
4214 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4215 |
if ( empty($url) ) //If any of the above options failed, Fallback on the GUID as used pre-2.7, not recommended to rely upon this. |
136 | 4216 |
$url = get_the_guid( $post->ID ); |
4217 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4218 |
$url = apply_filters( 'wp_get_attachment_url', $url, $post->ID ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4219 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4220 |
if ( empty( $url ) ) |
136 | 4221 |
return false; |
4222 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4223 |
return $url; |
136 | 4224 |
} |
4225 |
||
4226 |
/** |
|
4227 |
* Retrieve thumbnail for an attachment. |
|
4228 |
* |
|
4229 |
* @since 2.1.0 |
|
4230 |
* |
|
4231 |
* @param int $post_id Attachment ID. |
|
4232 |
* @return mixed False on failure. Thumbnail file path on success. |
|
4233 |
*/ |
|
4234 |
function wp_get_attachment_thumb_file( $post_id = 0 ) { |
|
4235 |
$post_id = (int) $post_id; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4236 |
if ( !$post = get_post( $post_id ) ) |
136 | 4237 |
return false; |
4238 |
if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) |
|
4239 |
return false; |
|
4240 |
||
4241 |
$file = get_attached_file( $post->ID ); |
|
4242 |
||
4243 |
if ( !empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile) ) |
|
4244 |
return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID ); |
|
4245 |
return false; |
|
4246 |
} |
|
4247 |
||
4248 |
/** |
|
4249 |
* Retrieve URL for an attachment thumbnail. |
|
4250 |
* |
|
4251 |
* @since 2.1.0 |
|
4252 |
* |
|
4253 |
* @param int $post_id Attachment ID |
|
4254 |
* @return string|bool False on failure. Thumbnail URL on success. |
|
4255 |
*/ |
|
4256 |
function wp_get_attachment_thumb_url( $post_id = 0 ) { |
|
4257 |
$post_id = (int) $post_id; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4258 |
if ( !$post = get_post( $post_id ) ) |
136 | 4259 |
return false; |
4260 |
if ( !$url = wp_get_attachment_url( $post->ID ) ) |
|
4261 |
return false; |
|
4262 |
||
4263 |
$sized = image_downsize( $post_id, 'thumbnail' ); |
|
4264 |
if ( $sized ) |
|
4265 |
return $sized[0]; |
|
4266 |
||
4267 |
if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) ) |
|
4268 |
return false; |
|
4269 |
||
4270 |
$url = str_replace(basename($url), basename($thumb), $url); |
|
4271 |
||
4272 |
return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID ); |
|
4273 |
} |
|
4274 |
||
4275 |
/** |
|
4276 |
* Check if the attachment is an image. |
|
4277 |
* |
|
4278 |
* @since 2.1.0 |
|
4279 |
* |
|
4280 |
* @param int $post_id Attachment ID |
|
4281 |
* @return bool |
|
4282 |
*/ |
|
4283 |
function wp_attachment_is_image( $post_id = 0 ) { |
|
4284 |
$post_id = (int) $post_id; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4285 |
if ( !$post = get_post( $post_id ) ) |
136 | 4286 |
return false; |
4287 |
||
4288 |
if ( !$file = get_attached_file( $post->ID ) ) |
|
4289 |
return false; |
|
4290 |
||
4291 |
$ext = preg_match('/\.([^.]+)$/', $file, $matches) ? strtolower($matches[1]) : false; |
|
4292 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4293 |
$image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ); |
136 | 4294 |
|
4295 |
if ( 'image/' == substr($post->post_mime_type, 0, 6) || $ext && 'import' == $post->post_mime_type && in_array($ext, $image_exts) ) |
|
4296 |
return true; |
|
4297 |
return false; |
|
4298 |
} |
|
4299 |
||
4300 |
/** |
|
4301 |
* Retrieve the icon for a MIME type. |
|
4302 |
* |
|
4303 |
* @since 2.1.0 |
|
4304 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4305 |
* @param string|int $mime MIME type or attachment ID. |
136 | 4306 |
* @return string|bool |
4307 |
*/ |
|
4308 |
function wp_mime_type_icon( $mime = 0 ) { |
|
4309 |
if ( !is_numeric($mime) ) |
|
4310 |
$icon = wp_cache_get("mime_type_icon_$mime"); |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4311 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4312 |
$post_id = 0; |
136 | 4313 |
if ( empty($icon) ) { |
4314 |
$post_mimes = array(); |
|
4315 |
if ( is_numeric($mime) ) { |
|
4316 |
$mime = (int) $mime; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4317 |
if ( $post = get_post( $mime ) ) { |
136 | 4318 |
$post_id = (int) $post->ID; |
4319 |
$ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid); |
|
4320 |
if ( !empty($ext) ) { |
|
4321 |
$post_mimes[] = $ext; |
|
4322 |
if ( $ext_type = wp_ext2type( $ext ) ) |
|
4323 |
$post_mimes[] = $ext_type; |
|
4324 |
} |
|
4325 |
$mime = $post->post_mime_type; |
|
4326 |
} else { |
|
4327 |
$mime = 0; |
|
4328 |
} |
|
4329 |
} else { |
|
4330 |
$post_mimes[] = $mime; |
|
4331 |
} |
|
4332 |
||
4333 |
$icon_files = wp_cache_get('icon_files'); |
|
4334 |
||
4335 |
if ( !is_array($icon_files) ) { |
|
4336 |
$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' ); |
|
4337 |
$icon_dir_uri = apply_filters( 'icon_dir_uri', includes_url('images/crystal') ); |
|
4338 |
$dirs = apply_filters( 'icon_dirs', array($icon_dir => $icon_dir_uri) ); |
|
4339 |
$icon_files = array(); |
|
4340 |
while ( $dirs ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4341 |
$keys = array_keys( $dirs ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4342 |
$dir = array_shift( $keys ); |
136 | 4343 |
$uri = array_shift($dirs); |
4344 |
if ( $dh = opendir($dir) ) { |
|
4345 |
while ( false !== $file = readdir($dh) ) { |
|
4346 |
$file = basename($file); |
|
4347 |
if ( substr($file, 0, 1) == '.' ) |
|
4348 |
continue; |
|
4349 |
if ( !in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg') ) ) { |
|
4350 |
if ( is_dir("$dir/$file") ) |
|
4351 |
$dirs["$dir/$file"] = "$uri/$file"; |
|
4352 |
continue; |
|
4353 |
} |
|
4354 |
$icon_files["$dir/$file"] = "$uri/$file"; |
|
4355 |
} |
|
4356 |
closedir($dh); |
|
4357 |
} |
|
4358 |
} |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4359 |
wp_cache_add( 'icon_files', $icon_files, 'default', 600 ); |
136 | 4360 |
} |
4361 |
||
4362 |
// Icon basename - extension = MIME wildcard |
|
4363 |
foreach ( $icon_files as $file => $uri ) |
|
4364 |
$types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file]; |
|
4365 |
||
4366 |
if ( ! empty($mime) ) { |
|
4367 |
$post_mimes[] = substr($mime, 0, strpos($mime, '/')); |
|
4368 |
$post_mimes[] = substr($mime, strpos($mime, '/') + 1); |
|
4369 |
$post_mimes[] = str_replace('/', '_', $mime); |
|
4370 |
} |
|
4371 |
||
4372 |
$matches = wp_match_mime_types(array_keys($types), $post_mimes); |
|
4373 |
$matches['default'] = array('default'); |
|
4374 |
||
4375 |
foreach ( $matches as $match => $wilds ) { |
|
4376 |
if ( isset($types[$wilds[0]])) { |
|
4377 |
$icon = $types[$wilds[0]]; |
|
4378 |
if ( !is_numeric($mime) ) |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4379 |
wp_cache_add("mime_type_icon_$mime", $icon); |
136 | 4380 |
break; |
4381 |
} |
|
4382 |
} |
|
4383 |
} |
|
4384 |
||
4385 |
return apply_filters( 'wp_mime_type_icon', $icon, $mime, $post_id ); // Last arg is 0 if function pass mime type. |
|
4386 |
} |
|
4387 |
||
4388 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4389 |
* Checked for changed slugs for published post objects and save the old slug. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4390 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4391 |
* The function is used when a post object of any type is updated, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4392 |
* by comparing the current and previous post objects. |
136 | 4393 |
* |
4394 |
* If the slug was changed and not already part of the old slugs then it will be |
|
4395 |
* added to the post meta field ('_wp_old_slug') for storing old slugs for that |
|
4396 |
* post. |
|
4397 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4398 |
* The most logically usage of this function is redirecting changed post objects, so |
136 | 4399 |
* that those that linked to an changed post will be redirected to the new post. |
4400 |
* |
|
4401 |
* @since 2.1.0 |
|
4402 |
* |
|
4403 |
* @param int $post_id Post ID. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4404 |
* @param object $post The Post Object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4405 |
* @param object $post_before The Previous Post Object |
136 | 4406 |
* @return int Same as $post_id |
4407 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4408 |
function wp_check_for_changed_slugs($post_id, $post, $post_before) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4409 |
// dont bother if it hasnt changed |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4410 |
if ( $post->post_name == $post_before->post_name ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4411 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4412 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4413 |
// we're only concerned with published, non-hierarchical objects |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4414 |
if ( $post->post_status != 'publish' || is_post_type_hierarchical( $post->post_type ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4415 |
return; |
136 | 4416 |
|
4417 |
$old_slugs = (array) get_post_meta($post_id, '_wp_old_slug'); |
|
4418 |
||
4419 |
// if we haven't added this old slug before, add it now |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4420 |
if ( !empty( $post_before->post_name ) && !in_array($post_before->post_name, $old_slugs) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4421 |
add_post_meta($post_id, '_wp_old_slug', $post_before->post_name); |
136 | 4422 |
|
4423 |
// if the new slug was used previously, delete it from the list |
|
4424 |
if ( in_array($post->post_name, $old_slugs) ) |
|
4425 |
delete_post_meta($post_id, '_wp_old_slug', $post->post_name); |
|
4426 |
} |
|
4427 |
||
4428 |
/** |
|
4429 |
* Retrieve the private post SQL based on capability. |
|
4430 |
* |
|
4431 |
* This function provides a standardized way to appropriately select on the |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4432 |
* post_status of a post type. The function will return a piece of SQL code |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4433 |
* that can be added to a WHERE clause; this SQL is constructed to allow all |
136 | 4434 |
* published posts, and all private posts to which the user has access. |
4435 |
* |
|
4436 |
* @since 2.2.0 |
|
4437 |
* |
|
4438 |
* @uses $user_ID |
|
4439 |
* |
|
4440 |
* @param string $post_type currently only supports 'post' or 'page'. |
|
4441 |
* @return string SQL code that can be added to a where clause. |
|
4442 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4443 |
function get_private_posts_cap_sql( $post_type ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4444 |
return get_posts_by_author_sql( $post_type, false ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4445 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4446 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4447 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4448 |
* Retrieve the post SQL based on capability, author, and type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4449 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4450 |
* @see get_private_posts_cap_sql() for full description. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4451 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4452 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4453 |
* @param string $post_type Post type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4454 |
* @param bool $full Optional. Returns a full WHERE statement instead of just an 'andalso' term. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4455 |
* @param int $post_author Optional. Query posts having a single author ID. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4456 |
* @param bool $public_only Optional. Only return public posts. Skips cap checks for $current_user. Default is false. |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4457 |
* @return string SQL WHERE code that can be added to a query. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4458 |
*/ |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4459 |
function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4460 |
global $user_ID, $wpdb; |
136 | 4461 |
|
4462 |
// Private posts |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4463 |
$post_type_obj = get_post_type_object( $post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4464 |
if ( ! $post_type_obj ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4465 |
return $full ? 'WHERE 1 = 0' : ' 1 = 0 '; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4466 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4467 |
// This hook is deprecated. Why you'd want to use it, I dunno. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4468 |
if ( ! $cap = apply_filters( 'pub_priv_sql_capability', '' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4469 |
$cap = $post_type_obj->cap->read_private_posts; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4470 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4471 |
if ( $full ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4472 |
if ( null === $post_author ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4473 |
$sql = $wpdb->prepare( 'WHERE post_type = %s AND ', $post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4474 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4475 |
$sql = $wpdb->prepare( 'WHERE post_author = %d AND post_type = %s AND ', $post_author, $post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4476 |
} |
136 | 4477 |
} else { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4478 |
$sql = ''; |
136 | 4479 |
} |
4480 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4481 |
$sql .= "(post_status = 'publish'"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4482 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4483 |
// Only need to check the cap if $public_only is false |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4484 |
if ( false === $public_only ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4485 |
if ( current_user_can( $cap ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4486 |
// Does the user have the capability to view private posts? Guess so. |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4487 |
$sql .= " OR post_status = 'private'"; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4488 |
} elseif ( is_user_logged_in() ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4489 |
// Users can view their own private posts. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4490 |
$id = (int) $user_ID; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4491 |
if ( null === $post_author || ! $full ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4492 |
$sql .= " OR post_status = 'private' AND post_author = $id"; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4493 |
} elseif ( $id == (int) $post_author ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4494 |
$sql .= " OR post_status = 'private'"; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4495 |
} // else none |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4496 |
} // else none |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4497 |
} |
136 | 4498 |
|
4499 |
$sql .= ')'; |
|
4500 |
||
4501 |
return $sql; |
|
4502 |
} |
|
4503 |
||
4504 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4505 |
* Retrieve the date that the last post was published. |
136 | 4506 |
* |
4507 |
* The server timezone is the default and is the difference between GMT and |
|
4508 |
* server time. The 'blog' value is the date when the last post was posted. The |
|
4509 |
* 'gmt' is when the last post was posted in GMT formatted date. |
|
4510 |
* |
|
4511 |
* @since 0.71 |
|
4512 |
* |
|
4513 |
* @uses apply_filters() Calls 'get_lastpostdate' filter |
|
4514 |
* |
|
4515 |
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'. |
|
4516 |
* @return string The date of the last post. |
|
4517 |
*/ |
|
4518 |
function get_lastpostdate($timezone = 'server') { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4519 |
return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date' ), $timezone ); |
136 | 4520 |
} |
4521 |
||
4522 |
/** |
|
4523 |
* Retrieve last post modified date depending on timezone. |
|
4524 |
* |
|
4525 |
* The server timezone is the default and is the difference between GMT and |
|
4526 |
* server time. The 'blog' value is just when the last post was modified. The |
|
4527 |
* 'gmt' is when the last post was modified in GMT time. |
|
4528 |
* |
|
4529 |
* @since 1.2.0 |
|
4530 |
* @uses apply_filters() Calls 'get_lastpostmodified' filter |
|
4531 |
* |
|
4532 |
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'. |
|
4533 |
* @return string The date the post was last modified. |
|
4534 |
*/ |
|
4535 |
function get_lastpostmodified($timezone = 'server') { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4536 |
$lastpostmodified = _get_last_post_time( $timezone, 'modified' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4537 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4538 |
$lastpostdate = get_lastpostdate($timezone); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4539 |
if ( $lastpostdate > $lastpostmodified ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4540 |
$lastpostmodified = $lastpostdate; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4541 |
|
136 | 4542 |
return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone ); |
4543 |
} |
|
4544 |
||
4545 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4546 |
* Retrieve latest post date data based on timezone. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4547 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4548 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4549 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4550 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4551 |
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4552 |
* @param string $field Field to check. Can be 'date' or 'modified'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4553 |
* @return string The date. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4554 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4555 |
function _get_last_post_time( $timezone, $field ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4556 |
global $wpdb; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4557 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4558 |
if ( !in_array( $field, array( 'date', 'modified' ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4559 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4560 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4561 |
$timezone = strtolower( $timezone ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4562 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4563 |
$key = "lastpost{$field}:$timezone"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4564 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4565 |
$date = wp_cache_get( $key, 'timeinfo' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4566 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4567 |
if ( !$date ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4568 |
$add_seconds_server = date('Z'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4569 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4570 |
$post_types = get_post_types( array( 'public' => true ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4571 |
array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4572 |
$post_types = "'" . implode( "', '", $post_types ) . "'"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4573 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4574 |
switch ( $timezone ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4575 |
case 'gmt': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4576 |
$date = $wpdb->get_var("SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4577 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4578 |
case 'blog': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4579 |
$date = $wpdb->get_var("SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4580 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4581 |
case 'server': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4582 |
$date = $wpdb->get_var("SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4583 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4584 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4585 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4586 |
if ( $date ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4587 |
wp_cache_set( $key, $date, 'timeinfo' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4588 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4589 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4590 |
return $date; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4591 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4592 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4593 |
/** |
136 | 4594 |
* Updates posts in cache. |
4595 |
* |
|
4596 |
* @package WordPress |
|
4597 |
* @subpackage Cache |
|
4598 |
* @since 1.5.1 |
|
4599 |
* |
|
4600 |
* @param array $posts Array of post objects |
|
4601 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4602 |
function update_post_cache( &$posts ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4603 |
if ( ! $posts ) |
136 | 4604 |
return; |
4605 |
||
4606 |
foreach ( $posts as $post ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4607 |
wp_cache_add( $post->ID, $post, 'posts' ); |
136 | 4608 |
} |
4609 |
||
4610 |
/** |
|
4611 |
* Will clean the post in the cache. |
|
4612 |
* |
|
4613 |
* Cleaning means delete from the cache of the post. Will call to clean the term |
|
4614 |
* object cache associated with the post ID. |
|
4615 |
* |
|
4616 |
* This function not run if $_wp_suspend_cache_invalidation is not empty. See |
|
4617 |
* wp_suspend_cache_invalidation(). |
|
4618 |
* |
|
4619 |
* @package WordPress |
|
4620 |
* @subpackage Cache |
|
4621 |
* @since 2.0.0 |
|
4622 |
* |
|
4623 |
* @uses do_action() Calls 'clean_post_cache' on $id before adding children (if any). |
|
4624 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4625 |
* @param object|int $post The post object or ID to remove from the cache |
136 | 4626 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4627 |
function clean_post_cache( $post ) { |
136 | 4628 |
global $_wp_suspend_cache_invalidation, $wpdb; |
4629 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4630 |
if ( ! empty( $_wp_suspend_cache_invalidation ) ) |
136 | 4631 |
return; |
4632 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4633 |
$post = get_post( $post ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4634 |
if ( empty( $post ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4635 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4636 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4637 |
wp_cache_delete( $post->ID, 'posts' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4638 |
wp_cache_delete( $post->ID, 'post_meta' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4639 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4640 |
clean_object_term_cache( $post->ID, $post->post_type ); |
136 | 4641 |
|
4642 |
wp_cache_delete( 'wp_get_archives', 'general' ); |
|
4643 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4644 |
do_action( 'clean_post_cache', $post->ID, $post ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4645 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4646 |
if ( is_post_type_hierarchical( $post->post_type ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4647 |
wp_cache_delete( 'get_pages', 'posts' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4648 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4649 |
if ( 'page' == $post->post_type ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4650 |
wp_cache_delete( 'all_page_ids', 'posts' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4651 |
do_action( 'clean_page_cache', $post->ID ); |
136 | 4652 |
} |
4653 |
} |
|
4654 |
||
4655 |
/** |
|
4656 |
* Call major cache updating functions for list of Post objects. |
|
4657 |
* |
|
4658 |
* @package WordPress |
|
4659 |
* @subpackage Cache |
|
4660 |
* @since 1.5.0 |
|
4661 |
* |
|
4662 |
* @uses $wpdb |
|
4663 |
* @uses update_post_cache() |
|
4664 |
* @uses update_object_term_cache() |
|
4665 |
* @uses update_postmeta_cache() |
|
4666 |
* |
|
4667 |
* @param array $posts Array of Post objects |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4668 |
* @param string $post_type The post type of the posts in $posts. Default is 'post'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4669 |
* @param bool $update_term_cache Whether to update the term cache. Default is true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4670 |
* @param bool $update_meta_cache Whether to update the meta cache. Default is true. |
136 | 4671 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4672 |
function update_post_caches(&$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true) { |
136 | 4673 |
// No point in doing all this work if we didn't match any posts. |
4674 |
if ( !$posts ) |
|
4675 |
return; |
|
4676 |
||
4677 |
update_post_cache($posts); |
|
4678 |
||
4679 |
$post_ids = array(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4680 |
foreach ( $posts as $post ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4681 |
$post_ids[] = $post->ID; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4682 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4683 |
if ( ! $post_type ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4684 |
$post_type = 'any'; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4685 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4686 |
if ( $update_term_cache ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4687 |
if ( is_array($post_type) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4688 |
$ptypes = $post_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4689 |
} elseif ( 'any' == $post_type ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4690 |
// Just use the post_types in the supplied posts. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4691 |
foreach ( $posts as $post ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4692 |
$ptypes[] = $post->post_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4693 |
$ptypes = array_unique($ptypes); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4694 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4695 |
$ptypes = array($post_type); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4696 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4697 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4698 |
if ( ! empty($ptypes) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4699 |
update_object_term_cache($post_ids, $ptypes); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4700 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4701 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4702 |
if ( $update_meta_cache ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4703 |
update_postmeta_cache($post_ids); |
136 | 4704 |
} |
4705 |
||
4706 |
/** |
|
4707 |
* Updates metadata cache for list of post IDs. |
|
4708 |
* |
|
4709 |
* Performs SQL query to retrieve the metadata for the post IDs and updates the |
|
4710 |
* metadata cache for the posts. Therefore, the functions, which call this |
|
4711 |
* function, do not need to perform SQL queries on their own. |
|
4712 |
* |
|
4713 |
* @package WordPress |
|
4714 |
* @subpackage Cache |
|
4715 |
* @since 2.1.0 |
|
4716 |
* |
|
4717 |
* @uses $wpdb |
|
4718 |
* |
|
4719 |
* @param array $post_ids List of post IDs. |
|
4720 |
* @return bool|array Returns false if there is nothing to update or an array of metadata. |
|
4721 |
*/ |
|
4722 |
function update_postmeta_cache($post_ids) { |
|
4723 |
return update_meta_cache('post', $post_ids); |
|
4724 |
} |
|
4725 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4726 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4727 |
* Will clean the attachment in the cache. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4728 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4729 |
* Cleaning means delete from the cache. Optionally will clean the term |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4730 |
* object cache associated with the attachment ID. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4731 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4732 |
* This function will not run if $_wp_suspend_cache_invalidation is not empty. See |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4733 |
* wp_suspend_cache_invalidation(). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4734 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4735 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4736 |
* @subpackage Cache |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4737 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4738 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4739 |
* @uses do_action() Calls 'clean_attachment_cache' on $id. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4740 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4741 |
* @param int $id The attachment ID in the cache to clean |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4742 |
* @param bool $clean_terms optional. Whether to clean terms cache |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4743 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4744 |
function clean_attachment_cache($id, $clean_terms = false) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4745 |
global $_wp_suspend_cache_invalidation; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4746 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4747 |
if ( !empty($_wp_suspend_cache_invalidation) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4748 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4749 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4750 |
$id = (int) $id; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4751 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4752 |
wp_cache_delete($id, 'posts'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4753 |
wp_cache_delete($id, 'post_meta'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4754 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4755 |
if ( $clean_terms ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4756 |
clean_object_term_cache($id, 'attachment'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4757 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4758 |
do_action('clean_attachment_cache', $id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4759 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4760 |
|
136 | 4761 |
// |
4762 |
// Hooks |
|
4763 |
// |
|
4764 |
||
4765 |
/** |
|
4766 |
* Hook for managing future post transitions to published. |
|
4767 |
* |
|
4768 |
* @since 2.3.0 |
|
4769 |
* @access private |
|
4770 |
* @uses $wpdb |
|
4771 |
* @uses do_action() Calls 'private_to_published' on post ID if this is a 'private_to_published' call. |
|
4772 |
* @uses wp_clear_scheduled_hook() with 'publish_future_post' and post ID. |
|
4773 |
* |
|
4774 |
* @param string $new_status New post status |
|
4775 |
* @param string $old_status Previous post status |
|
4776 |
* @param object $post Object type containing the post information |
|
4777 |
*/ |
|
4778 |
function _transition_post_status($new_status, $old_status, $post) { |
|
4779 |
global $wpdb; |
|
4780 |
||
4781 |
if ( $old_status != 'publish' && $new_status == 'publish' ) { |
|
4782 |
// Reset GUID if transitioning to publish and it is empty |
|
4783 |
if ( '' == get_the_guid($post->ID) ) |
|
4784 |
$wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) ); |
|
4785 |
do_action('private_to_published', $post->ID); // Deprecated, use private_to_publish |
|
4786 |
} |
|
4787 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4788 |
// If published posts changed clear the lastpostmodified cache |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4789 |
if ( 'publish' == $new_status || 'publish' == $old_status) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4790 |
foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4791 |
wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4792 |
wp_cache_delete( "lastpostdate:$timezone", 'timeinfo' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4793 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4794 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4795 |
|
136 | 4796 |
// Always clears the hook in case the post status bounced from future to draft. |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4797 |
wp_clear_scheduled_hook('publish_future_post', array( $post->ID ) ); |
136 | 4798 |
} |
4799 |
||
4800 |
/** |
|
4801 |
* Hook used to schedule publication for a post marked for the future. |
|
4802 |
* |
|
4803 |
* The $post properties used and must exist are 'ID' and 'post_date_gmt'. |
|
4804 |
* |
|
4805 |
* @since 2.3.0 |
|
4806 |
* @access private |
|
4807 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4808 |
* @param int $deprecated Not used. Can be set to null. Never implemented. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4809 |
* Not marked as deprecated with _deprecated_argument() as it conflicts with |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4810 |
* wp_transition_post_status() and the default filter for _future_post_hook(). |
136 | 4811 |
* @param object $post Object type containing the post information |
4812 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4813 |
function _future_post_hook( $deprecated = '', $post ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4814 |
wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4815 |
wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT') , 'publish_future_post', array( $post->ID ) ); |
136 | 4816 |
} |
4817 |
||
4818 |
/** |
|
4819 |
* Hook to schedule pings and enclosures when a post is published. |
|
4820 |
* |
|
4821 |
* @since 2.3.0 |
|
4822 |
* @access private |
|
4823 |
* @uses $wpdb |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4824 |
* @uses XMLRPC_REQUEST constant. |
136 | 4825 |
* @uses do_action() Calls 'xmlprc_publish_post' on post ID if XMLRPC_REQUEST is defined. |
4826 |
* |
|
4827 |
* @param int $post_id The ID in the database table of the post being published |
|
4828 |
*/ |
|
4829 |
function _publish_post_hook($post_id) { |
|
4830 |
global $wpdb; |
|
4831 |
||
4832 |
if ( defined('XMLRPC_REQUEST') ) |
|
4833 |
do_action('xmlrpc_publish_post', $post_id); |
|
4834 |
||
4835 |
if ( defined('WP_IMPORTING') ) |
|
4836 |
return; |
|
4837 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4838 |
if ( get_option('default_pingback_flag') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4839 |
add_post_meta( $post_id, '_pingme', '1' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4840 |
add_post_meta( $post_id, '_encloseme', '1' ); |
136 | 4841 |
|
4842 |
wp_schedule_single_event(time(), 'do_pings'); |
|
4843 |
} |
|
4844 |
||
4845 |
/** |
|
4846 |
* Determines which fields of posts are to be saved in revisions. |
|
4847 |
* |
|
4848 |
* Does two things. If passed a post *array*, it will return a post array ready |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4849 |
* to be inserted into the posts table as a post revision. Otherwise, returns |
136 | 4850 |
* an array whose keys are the post fields to be saved for post revisions. |
4851 |
* |
|
4852 |
* @package WordPress |
|
4853 |
* @subpackage Post_Revisions |
|
4854 |
* @since 2.6.0 |
|
4855 |
* @access private |
|
4856 |
* @uses apply_filters() Calls '_wp_post_revision_fields' on 'title', 'content' and 'excerpt' fields. |
|
4857 |
* |
|
4858 |
* @param array $post Optional a post array to be processed for insertion as a post revision. |
|
4859 |
* @param bool $autosave optional Is the revision an autosave? |
|
4860 |
* @return array Post array ready to be inserted as a post revision or array of fields that can be versioned. |
|
4861 |
*/ |
|
4862 |
function _wp_post_revision_fields( $post = null, $autosave = false ) { |
|
4863 |
static $fields = false; |
|
4864 |
||
4865 |
if ( !$fields ) { |
|
4866 |
// Allow these to be versioned |
|
4867 |
$fields = array( |
|
4868 |
'post_title' => __( 'Title' ), |
|
4869 |
'post_content' => __( 'Content' ), |
|
4870 |
'post_excerpt' => __( 'Excerpt' ), |
|
4871 |
); |
|
4872 |
||
4873 |
// Runs only once |
|
4874 |
$fields = apply_filters( '_wp_post_revision_fields', $fields ); |
|
4875 |
||
4876 |
// WP uses these internally either in versioning or elsewhere - they cannot be versioned |
|
4877 |
foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) |
|
4878 |
unset( $fields[$protect] ); |
|
4879 |
} |
|
4880 |
||
4881 |
if ( !is_array($post) ) |
|
4882 |
return $fields; |
|
4883 |
||
4884 |
$return = array(); |
|
4885 |
foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) |
|
4886 |
$return[$field] = $post[$field]; |
|
4887 |
||
4888 |
$return['post_parent'] = $post['ID']; |
|
4889 |
$return['post_status'] = 'inherit'; |
|
4890 |
$return['post_type'] = 'revision'; |
|
4891 |
$return['post_name'] = $autosave ? "$post[ID]-autosave" : "$post[ID]-revision"; |
|
4892 |
$return['post_date'] = isset($post['post_modified']) ? $post['post_modified'] : ''; |
|
4893 |
$return['post_date_gmt'] = isset($post['post_modified_gmt']) ? $post['post_modified_gmt'] : ''; |
|
4894 |
||
4895 |
return $return; |
|
4896 |
} |
|
4897 |
||
4898 |
/** |
|
4899 |
* Saves an already existing post as a post revision. |
|
4900 |
* |
|
4901 |
* Typically used immediately prior to post updates. |
|
4902 |
* |
|
4903 |
* @package WordPress |
|
4904 |
* @subpackage Post_Revisions |
|
4905 |
* @since 2.6.0 |
|
4906 |
* |
|
4907 |
* @uses _wp_put_post_revision() |
|
4908 |
* |
|
4909 |
* @param int $post_id The ID of the post to save as a revision. |
|
4910 |
* @return mixed Null or 0 if error, new revision ID, if success. |
|
4911 |
*/ |
|
4912 |
function wp_save_post_revision( $post_id ) { |
|
4913 |
// We do autosaves manually with wp_create_post_autosave() |
|
4914 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
|
4915 |
return; |
|
4916 |
||
4917 |
// WP_POST_REVISIONS = 0, false |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4918 |
if ( ! WP_POST_REVISIONS ) |
136 | 4919 |
return; |
4920 |
||
4921 |
if ( !$post = get_post( $post_id, ARRAY_A ) ) |
|
4922 |
return; |
|
4923 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4924 |
if ( 'auto-draft' == $post['post_status'] ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4925 |
return; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
4926 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4927 |
if ( !post_type_supports($post['post_type'], 'revisions') ) |
136 | 4928 |
return; |
4929 |
||
4930 |
$return = _wp_put_post_revision( $post ); |
|
4931 |
||
4932 |
// WP_POST_REVISIONS = true (default), -1 |
|
4933 |
if ( !is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 ) |
|
4934 |
return $return; |
|
4935 |
||
4936 |
// all revisions and (possibly) one autosave |
|
4937 |
$revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) ); |
|
4938 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4939 |
// WP_POST_REVISIONS = (int) (# of autosaves to save) |
136 | 4940 |
$delete = count($revisions) - WP_POST_REVISIONS; |
4941 |
||
4942 |
if ( $delete < 1 ) |
|
4943 |
return $return; |
|
4944 |
||
4945 |
$revisions = array_slice( $revisions, 0, $delete ); |
|
4946 |
||
4947 |
for ( $i = 0; isset($revisions[$i]); $i++ ) { |
|
4948 |
if ( false !== strpos( $revisions[$i]->post_name, 'autosave' ) ) |
|
4949 |
continue; |
|
4950 |
wp_delete_post_revision( $revisions[$i]->ID ); |
|
4951 |
} |
|
4952 |
||
4953 |
return $return; |
|
4954 |
} |
|
4955 |
||
4956 |
/** |
|
4957 |
* Retrieve the autosaved data of the specified post. |
|
4958 |
* |
|
4959 |
* Returns a post object containing the information that was autosaved for the |
|
4960 |
* specified post. |
|
4961 |
* |
|
4962 |
* @package WordPress |
|
4963 |
* @subpackage Post_Revisions |
|
4964 |
* @since 2.6.0 |
|
4965 |
* |
|
4966 |
* @param int $post_id The post ID. |
|
4967 |
* @return object|bool The autosaved data or false on failure or when no autosave exists. |
|
4968 |
*/ |
|
4969 |
function wp_get_post_autosave( $post_id ) { |
|
4970 |
||
4971 |
if ( !$post = get_post( $post_id ) ) |
|
4972 |
return false; |
|
4973 |
||
4974 |
$q = array( |
|
4975 |
'name' => "{$post->ID}-autosave", |
|
4976 |
'post_parent' => $post->ID, |
|
4977 |
'post_type' => 'revision', |
|
4978 |
'post_status' => 'inherit' |
|
4979 |
); |
|
4980 |
||
4981 |
// Use WP_Query so that the result gets cached |
|
4982 |
$autosave_query = new WP_Query; |
|
4983 |
||
4984 |
add_action( 'parse_query', '_wp_get_post_autosave_hack' ); |
|
4985 |
$autosave = $autosave_query->query( $q ); |
|
4986 |
remove_action( 'parse_query', '_wp_get_post_autosave_hack' ); |
|
4987 |
||
4988 |
if ( $autosave && is_array($autosave) && is_object($autosave[0]) ) |
|
4989 |
return $autosave[0]; |
|
4990 |
||
4991 |
return false; |
|
4992 |
} |
|
4993 |
||
4994 |
/** |
|
4995 |
* Internally used to hack WP_Query into submission. |
|
4996 |
* |
|
4997 |
* @package WordPress |
|
4998 |
* @subpackage Post_Revisions |
|
4999 |
* @since 2.6.0 |
|
5000 |
* |
|
5001 |
* @param object $query WP_Query object |
|
5002 |
*/ |
|
5003 |
function _wp_get_post_autosave_hack( $query ) { |
|
5004 |
$query->is_single = false; |
|
5005 |
} |
|
5006 |
||
5007 |
/** |
|
5008 |
* Determines if the specified post is a revision. |
|
5009 |
* |
|
5010 |
* @package WordPress |
|
5011 |
* @subpackage Post_Revisions |
|
5012 |
* @since 2.6.0 |
|
5013 |
* |
|
5014 |
* @param int|object $post Post ID or post object. |
|
5015 |
* @return bool|int False if not a revision, ID of revision's parent otherwise. |
|
5016 |
*/ |
|
5017 |
function wp_is_post_revision( $post ) { |
|
5018 |
if ( !$post = wp_get_post_revision( $post ) ) |
|
5019 |
return false; |
|
5020 |
return (int) $post->post_parent; |
|
5021 |
} |
|
5022 |
||
5023 |
/** |
|
5024 |
* Determines if the specified post is an autosave. |
|
5025 |
* |
|
5026 |
* @package WordPress |
|
5027 |
* @subpackage Post_Revisions |
|
5028 |
* @since 2.6.0 |
|
5029 |
* |
|
5030 |
* @param int|object $post Post ID or post object. |
|
5031 |
* @return bool|int False if not a revision, ID of autosave's parent otherwise |
|
5032 |
*/ |
|
5033 |
function wp_is_post_autosave( $post ) { |
|
5034 |
if ( !$post = wp_get_post_revision( $post ) ) |
|
5035 |
return false; |
|
5036 |
if ( "{$post->post_parent}-autosave" !== $post->post_name ) |
|
5037 |
return false; |
|
5038 |
return (int) $post->post_parent; |
|
5039 |
} |
|
5040 |
||
5041 |
/** |
|
5042 |
* Inserts post data into the posts table as a post revision. |
|
5043 |
* |
|
5044 |
* @package WordPress |
|
5045 |
* @subpackage Post_Revisions |
|
5046 |
* @since 2.6.0 |
|
5047 |
* |
|
5048 |
* @uses wp_insert_post() |
|
5049 |
* |
|
5050 |
* @param int|object|array $post Post ID, post object OR post array. |
|
5051 |
* @param bool $autosave Optional. Is the revision an autosave? |
|
5052 |
* @return mixed Null or 0 if error, new revision ID if success. |
|
5053 |
*/ |
|
5054 |
function _wp_put_post_revision( $post = null, $autosave = false ) { |
|
5055 |
if ( is_object($post) ) |
|
5056 |
$post = get_object_vars( $post ); |
|
5057 |
elseif ( !is_array($post) ) |
|
5058 |
$post = get_post($post, ARRAY_A); |
|
5059 |
if ( !$post || empty($post['ID']) ) |
|
5060 |
return; |
|
5061 |
||
5062 |
if ( isset($post['post_type']) && 'revision' == $post['post_type'] ) |
|
5063 |
return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); |
|
5064 |
||
5065 |
$post = _wp_post_revision_fields( $post, $autosave ); |
|
5066 |
$post = add_magic_quotes($post); //since data is from db |
|
5067 |
||
5068 |
$revision_id = wp_insert_post( $post ); |
|
5069 |
if ( is_wp_error($revision_id) ) |
|
5070 |
return $revision_id; |
|
5071 |
||
5072 |
if ( $revision_id ) |
|
5073 |
do_action( '_wp_put_post_revision', $revision_id ); |
|
5074 |
return $revision_id; |
|
5075 |
} |
|
5076 |
||
5077 |
/** |
|
5078 |
* Gets a post revision. |
|
5079 |
* |
|
5080 |
* @package WordPress |
|
5081 |
* @subpackage Post_Revisions |
|
5082 |
* @since 2.6.0 |
|
5083 |
* |
|
5084 |
* @uses get_post() |
|
5085 |
* |
|
5086 |
* @param int|object $post Post ID or post object |
|
5087 |
* @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5088 |
* @param string $filter Optional sanitation filter. @see sanitize_post() |
136 | 5089 |
* @return mixed Null if error or post object if success |
5090 |
*/ |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
5091 |
function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') { |
136 | 5092 |
$null = null; |
5093 |
if ( !$revision = get_post( $post, OBJECT, $filter ) ) |
|
5094 |
return $revision; |
|
5095 |
if ( 'revision' !== $revision->post_type ) |
|
5096 |
return $null; |
|
5097 |
||
5098 |
if ( $output == OBJECT ) { |
|
5099 |
return $revision; |
|
5100 |
} elseif ( $output == ARRAY_A ) { |
|
5101 |
$_revision = get_object_vars($revision); |
|
5102 |
return $_revision; |
|
5103 |
} elseif ( $output == ARRAY_N ) { |
|
5104 |
$_revision = array_values(get_object_vars($revision)); |
|
5105 |
return $_revision; |
|
5106 |
} |
|
5107 |
||
5108 |
return $revision; |
|
5109 |
} |
|
5110 |
||
5111 |
/** |
|
5112 |
* Restores a post to the specified revision. |
|
5113 |
* |
|
5114 |
* Can restore a past revision using all fields of the post revision, or only selected fields. |
|
5115 |
* |
|
5116 |
* @package WordPress |
|
5117 |
* @subpackage Post_Revisions |
|
5118 |
* @since 2.6.0 |
|
5119 |
* |
|
5120 |
* @uses wp_get_post_revision() |
|
5121 |
* @uses wp_update_post() |
|
5122 |
* @uses do_action() Calls 'wp_restore_post_revision' on post ID and revision ID if wp_update_post() |
|
5123 |
* is successful. |
|
5124 |
* |
|
5125 |
* @param int|object $revision_id Revision ID or revision object. |
|
5126 |
* @param array $fields Optional. What fields to restore from. Defaults to all. |
|
5127 |
* @return mixed Null if error, false if no fields to restore, (int) post ID if success. |
|
5128 |
*/ |
|
5129 |
function wp_restore_post_revision( $revision_id, $fields = null ) { |
|
5130 |
if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) ) |
|
5131 |
return $revision; |
|
5132 |
||
5133 |
if ( !is_array( $fields ) ) |
|
5134 |
$fields = array_keys( _wp_post_revision_fields() ); |
|
5135 |
||
5136 |
$update = array(); |
|
5137 |
foreach( array_intersect( array_keys( $revision ), $fields ) as $field ) |
|
5138 |
$update[$field] = $revision[$field]; |
|
5139 |
||
5140 |
if ( !$update ) |
|
5141 |
return false; |
|
5142 |
||
5143 |
$update['ID'] = $revision['post_parent']; |
|
5144 |
||
5145 |
$update = add_magic_quotes( $update ); //since data is from db |
|
5146 |
||
5147 |
$post_id = wp_update_post( $update ); |
|
5148 |
if ( is_wp_error( $post_id ) ) |
|
5149 |
return $post_id; |
|
5150 |
||
5151 |
if ( $post_id ) |
|
5152 |
do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] ); |
|
5153 |
||
5154 |
return $post_id; |
|
5155 |
} |
|
5156 |
||
5157 |
/** |
|
5158 |
* Deletes a revision. |
|
5159 |
* |
|
5160 |
* Deletes the row from the posts table corresponding to the specified revision. |
|
5161 |
* |
|
5162 |
* @package WordPress |
|
5163 |
* @subpackage Post_Revisions |
|
5164 |
* @since 2.6.0 |
|
5165 |
* |
|
5166 |
* @uses wp_get_post_revision() |
|
5167 |
* @uses wp_delete_post() |
|
5168 |
* |
|
5169 |
* @param int|object $revision_id Revision ID or revision object. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5170 |
* @return mixed Null or WP_Error if error, deleted post if success. |
136 | 5171 |
*/ |
5172 |
function wp_delete_post_revision( $revision_id ) { |
|
5173 |
if ( !$revision = wp_get_post_revision( $revision_id ) ) |
|
5174 |
return $revision; |
|
5175 |
||
5176 |
$delete = wp_delete_post( $revision->ID ); |
|
5177 |
if ( is_wp_error( $delete ) ) |
|
5178 |
return $delete; |
|
5179 |
||
5180 |
if ( $delete ) |
|
5181 |
do_action( 'wp_delete_post_revision', $revision->ID, $revision ); |
|
5182 |
||
5183 |
return $delete; |
|
5184 |
} |
|
5185 |
||
5186 |
/** |
|
5187 |
* Returns all revisions of specified post. |
|
5188 |
* |
|
5189 |
* @package WordPress |
|
5190 |
* @subpackage Post_Revisions |
|
5191 |
* @since 2.6.0 |
|
5192 |
* |
|
5193 |
* @uses get_children() |
|
5194 |
* |
|
5195 |
* @param int|object $post_id Post ID or post object |
|
5196 |
* @return array empty if no revisions |
|
5197 |
*/ |
|
5198 |
function wp_get_post_revisions( $post_id = 0, $args = null ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5199 |
if ( ! WP_POST_REVISIONS ) |
136 | 5200 |
return array(); |
5201 |
if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) ) |
|
5202 |
return array(); |
|
5203 |
||
5204 |
$defaults = array( 'order' => 'DESC', 'orderby' => 'date' ); |
|
5205 |
$args = wp_parse_args( $args, $defaults ); |
|
5206 |
$args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) ); |
|
5207 |
||
5208 |
if ( !$revisions = get_children( $args ) ) |
|
5209 |
return array(); |
|
5210 |
return $revisions; |
|
5211 |
} |
|
5212 |
||
5213 |
function _set_preview($post) { |
|
5214 |
||
5215 |
if ( ! is_object($post) ) |
|
5216 |
return $post; |
|
5217 |
||
5218 |
$preview = wp_get_post_autosave($post->ID); |
|
5219 |
||
5220 |
if ( ! is_object($preview) ) |
|
5221 |
return $post; |
|
5222 |
||
5223 |
$preview = sanitize_post($preview); |
|
5224 |
||
5225 |
$post->post_content = $preview->post_content; |
|
5226 |
$post->post_title = $preview->post_title; |
|
5227 |
$post->post_excerpt = $preview->post_excerpt; |
|
5228 |
||
5229 |
return $post; |
|
5230 |
} |
|
5231 |
||
5232 |
function _show_post_preview() { |
|
5233 |
||
5234 |
if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) { |
|
5235 |
$id = (int) $_GET['preview_id']; |
|
5236 |
||
5237 |
if ( false == wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) ) |
|
5238 |
wp_die( __('You do not have permission to preview drafts.') ); |
|
5239 |
||
5240 |
add_filter('the_preview', '_set_preview'); |
|
5241 |
} |
|
5242 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5243 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5244 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5245 |
* Returns the post's parent's post_ID |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5246 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5247 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5248 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5249 |
* @param int $post_id |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5250 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5251 |
* @return int|bool false on error |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5252 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5253 |
function wp_get_post_parent_id( $post_ID ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5254 |
$post = get_post( $post_ID ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5255 |
if ( !$post || is_wp_error( $post ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5256 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5257 |
return (int) $post->post_parent; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5258 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5259 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5260 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5261 |
* Checks the given subset of the post hierarchy for hierarchy loops. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5262 |
* Prevents loops from forming and breaks those that it finds. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5263 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5264 |
* Attached to the wp_insert_post_parent filter. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5265 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5266 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5267 |
* @uses wp_find_hierarchy_loop() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5268 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5269 |
* @param int $post_parent ID of the parent for the post we're checking. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5270 |
* @param int $post_ID ID of the post we're checking. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5271 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5272 |
* @return int The new post_parent for the post. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5273 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5274 |
function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5275 |
// Nothing fancy here - bail |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5276 |
if ( !$post_parent ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5277 |
return 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5278 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5279 |
// New post can't cause a loop |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5280 |
if ( empty( $post_ID ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5281 |
return $post_parent; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5282 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5283 |
// Can't be its own parent |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5284 |
if ( $post_parent == $post_ID ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5285 |
return 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5286 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5287 |
// Now look for larger loops |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5288 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5289 |
if ( !$loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5290 |
return $post_parent; // No loop |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5291 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5292 |
// Setting $post_parent to the given value causes a loop |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5293 |
if ( isset( $loop[$post_ID] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5294 |
return 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5295 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5296 |
// There's a loop, but it doesn't contain $post_ID. Break the loop. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5297 |
foreach ( array_keys( $loop ) as $loop_member ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5298 |
wp_update_post( array( 'ID' => $loop_member, 'post_parent' => 0 ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5299 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5300 |
return $post_parent; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5301 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5302 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5303 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5304 |
* Returns an array of post format slugs to their translated and pretty display versions |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5305 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5306 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5307 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5308 |
* @return array The array of translations |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5309 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5310 |
function get_post_format_strings() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5311 |
$strings = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5312 |
'standard' => _x( 'Standard', 'Post format' ), // Special case. any value that evals to false will be considered standard |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5313 |
'aside' => _x( 'Aside', 'Post format' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5314 |
'chat' => _x( 'Chat', 'Post format' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5315 |
'gallery' => _x( 'Gallery', 'Post format' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5316 |
'link' => _x( 'Link', 'Post format' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5317 |
'image' => _x( 'Image', 'Post format' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5318 |
'quote' => _x( 'Quote', 'Post format' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5319 |
'status' => _x( 'Status', 'Post format' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5320 |
'video' => _x( 'Video', 'Post format' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5321 |
'audio' => _x( 'Audio', 'Post format' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5322 |
); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5323 |
return $strings; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5324 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5325 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5326 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5327 |
* Retrieves an array of post format slugs. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5328 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5329 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5330 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5331 |
* @return array The array of post format slugs. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5332 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5333 |
function get_post_format_slugs() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5334 |
$slugs = array_keys( get_post_format_strings() ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5335 |
return array_combine( $slugs, $slugs ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5336 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5337 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5338 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5339 |
* Returns a pretty, translated version of a post format slug |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5340 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5341 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5342 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5343 |
* @param string $slug A post format slug |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5344 |
* @return string The translated post format name |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5345 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5346 |
function get_post_format_string( $slug ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5347 |
$strings = get_post_format_strings(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5348 |
if ( !$slug ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5349 |
return $strings['standard']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5350 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5351 |
return ( isset( $strings[$slug] ) ) ? $strings[$slug] : ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5352 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5353 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5354 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5355 |
* Sets a post thumbnail. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5356 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5357 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5358 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5359 |
* @param int|object $post Post ID or object where thumbnail should be attached. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5360 |
* @param int $thumbnail_id Thumbnail to attach. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5361 |
* @return bool True on success, false on failure. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5362 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5363 |
function set_post_thumbnail( $post, $thumbnail_id ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5364 |
$post = get_post( $post ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5365 |
$thumbnail_id = absint( $thumbnail_id ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5366 |
if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
5367 |
if ( $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5368 |
return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id ); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
5369 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
5370 |
return delete_post_meta( $post->ID, '_thumbnail_id' ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5371 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5372 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5373 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5374 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5375 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5376 |
* Removes a post thumbnail. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5377 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5378 |
* @since 3.3.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5379 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5380 |
* @param int|object $post Post ID or object where thumbnail should be removed from. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5381 |
* @return bool True on success, false on failure. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5382 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5383 |
function delete_post_thumbnail( $post ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5384 |
$post = get_post( $post ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5385 |
if ( $post ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5386 |
return delete_post_meta( $post->ID, '_thumbnail_id' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5387 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5388 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5389 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5390 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5391 |
* Returns a link to a post format index. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5392 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5393 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5394 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5395 |
* @param string $format Post format |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5396 |
* @return string Link |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5397 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5398 |
function get_post_format_link( $format ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5399 |
$term = get_term_by('slug', 'post-format-' . $format, 'post_format' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5400 |
if ( ! $term || is_wp_error( $term ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5401 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5402 |
return get_term_link( $term ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5403 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5404 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5405 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5406 |
* Deletes auto-drafts for new posts that are > 7 days old |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5407 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5408 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5409 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5410 |
function wp_delete_auto_drafts() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5411 |
global $wpdb; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5412 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5413 |
// Cleanup old auto-drafts more than 7 days old |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5414 |
$old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5415 |
foreach ( (array) $old_posts as $delete ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5416 |
wp_delete_post( $delete, true ); // Force delete |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5417 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5418 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5419 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5420 |
* Filters the request to allow for the format prefix. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5421 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5422 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5423 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5424 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5425 |
function _post_format_request( $qvs ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5426 |
if ( ! isset( $qvs['post_format'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5427 |
return $qvs; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5428 |
$slugs = get_post_format_slugs(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5429 |
if ( isset( $slugs[ $qvs['post_format'] ] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5430 |
$qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5431 |
$tax = get_taxonomy( 'post_format' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5432 |
if ( ! is_admin() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5433 |
$qvs['post_type'] = $tax->object_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5434 |
return $qvs; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5435 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5436 |
add_filter( 'request', '_post_format_request' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5437 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5438 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5439 |
* Filters the post format term link to remove the format prefix. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5440 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5441 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5442 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5443 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5444 |
function _post_format_link( $link, $term, $taxonomy ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5445 |
global $wp_rewrite; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5446 |
if ( 'post_format' != $taxonomy ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5447 |
return $link; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5448 |
if ( $wp_rewrite->get_extra_permastruct( $taxonomy ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5449 |
return str_replace( "/{$term->slug}", '/' . str_replace( 'post-format-', '', $term->slug ), $link ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5450 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5451 |
$link = remove_query_arg( 'post_format', $link ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5452 |
return add_query_arg( 'post_format', str_replace( 'post-format-', '', $term->slug ), $link ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5453 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5454 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5455 |
add_filter( 'term_link', '_post_format_link', 10, 3 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5456 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5457 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5458 |
* Remove the post format prefix from the name property of the term object created by get_term(). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5459 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5460 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5461 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5462 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5463 |
function _post_format_get_term( $term ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5464 |
if ( isset( $term->slug ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5465 |
$term->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5466 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5467 |
return $term; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5468 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5469 |
add_filter( 'get_post_format', '_post_format_get_term' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5470 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5471 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5472 |
* Remove the post format prefix from the name property of the term objects created by get_terms(). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5473 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5474 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5475 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5476 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5477 |
function _post_format_get_terms( $terms, $taxonomies, $args ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5478 |
if ( in_array( 'post_format', (array) $taxonomies ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5479 |
if ( isset( $args['fields'] ) && 'names' == $args['fields'] ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5480 |
foreach( $terms as $order => $name ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5481 |
$terms[$order] = get_post_format_string( str_replace( 'post-format-', '', $name ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5482 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5483 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5484 |
foreach ( (array) $terms as $order => $term ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5485 |
if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5486 |
$terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5487 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5488 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5489 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5490 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5491 |
return $terms; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5492 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5493 |
add_filter( 'get_terms', '_post_format_get_terms', 10, 3 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5494 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5495 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5496 |
* Remove the post format prefix from the name property of the term objects created by wp_get_object_terms(). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5497 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5498 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5499 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5500 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5501 |
function _post_format_wp_get_object_terms( $terms ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5502 |
foreach ( (array) $terms as $order => $term ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5503 |
if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5504 |
$terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5505 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5506 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5507 |
return $terms; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5508 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5509 |
add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5510 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5511 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5512 |
* Update the custom taxonomies' term counts when a post's status is changed. For example, default posts term counts (for custom taxonomies) don't include private / draft posts. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5513 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5514 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5515 |
* @param string $new_status |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5516 |
* @param string $old_status |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5517 |
* @param object $post |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5518 |
* @since 3.3.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5519 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5520 |
function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5521 |
// Update counts for the post's terms. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5522 |
foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5523 |
$tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5524 |
wp_update_term_count( $tt_ids, $taxonomy ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5525 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5526 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5527 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5528 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5529 |
* Adds any posts from the given ids to the cache that do not already exist in cache |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5530 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5531 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5532 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5533 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5534 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5535 |
* @param array $post_ids ID list |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5536 |
* @param bool $update_term_cache Whether to update the term cache. Default is true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5537 |
* @param bool $update_meta_cache Whether to update the meta cache. Default is true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5538 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5539 |
function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache = true ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5540 |
global $wpdb; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5541 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5542 |
$non_cached_ids = _get_non_cached_ids( $ids, 'posts' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5543 |
if ( !empty( $non_cached_ids ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5544 |
$fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ",", $non_cached_ids ) ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5545 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5546 |
update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5547 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5548 |
} |