-
Notifications
You must be signed in to change notification settings - Fork 261
/
debug.php
207 lines (187 loc) · 4.73 KB
/
debug.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
require_once __DIR__ . '/debug-utils.php';
add_action( 'p2p_init', array( 'P2P_Debug', 'init' ), 11 );
class P2P_Debug {
static function init() {
if ( defined( 'WP_CLI' ) )
require_once __DIR__ . '/command.php';
self::posts_to_attachments();
self::posts_to_users();
self::contacts_and_tickets();
self::actors_and_movies();
}
static function posts_to_attachments() {
p2p_register_connection_type( array(
'name' => 'posts_to_attachments',
'from' => 'post',
'to' => 'attachment'
) );
}
static function posts_to_users() {
p2p_register_connection_type( array(
'name' => 'pages_to_users',
'from' => 'page',
'to' => 'user',
'to_query_vars' => array(
'role' => 'editor'
),
'title' => array( 'from' => 'Pages 2 Editors' ),
'admin_column' => 'any'
) );
p2p_register_connection_type( array(
'name' => 'users_to_posts',
'from' => 'user',
'cardinality' => 'one-to-one',
'title' => array( 'to' => 'Users 2 Posts' ),
'fields' => array(
'text' => array(
'title' => 'Text',
'default' => 'foobar'
),
'select' => array(
'type' => 'select',
'title' => 'Select',
'values' => range(1, 10),
'default' => 5
),
'single_checkbox' => array(
'title' => 'Ya?',
'type' => 'checkbox',
'default' => true
),
'color' => array(
'title' => 'Color',
'type' => 'checkbox',
'values' => array( 'white', 'red', 'green', 'blue' ),
'default' => 'green'
),
),
'admin_box' => array(
'context' => 'advanced'
),
'admin_dropdown' => 'any',
'sortable' => true,
) );
}
static function contacts_and_tickets() {
$types = array(
'bug' => 'Bug',
'feature' => 'Feature'
);
foreach ( $types as $type => $title ) {
p2p_register_connection_type( array(
'name' => "contact_to_$type",
'from' => 'contact',
'to' => 'ticket',
'to_query_vars' => array(
'meta_key' => 'type',
'meta_value' => $type
),
'title' => array( 'from' => $title ),
'show_ui' => 'from'
) );
}
p2p_register_connection_type(array(
'name' => 'ticket_to_contact',
'from' => 'ticket',
'to' => 'contact',
'cardinality' => 'one-to-many'
));
p2p_register_connection_type(array(
'name' => 'posts_to_contact',
'from' => 'contact',
'to' => 'contact',
'title' => 'Registry',
));
p2p_register_connection_type(array(
'name' => 'ticket_to_stuff',
'from' => 'ticket',
'to' => array( 'post', 'page' )
));
}
static function actors_and_movies() {
register_post_type('actor', array(
'public' => true,
'labels' => array(
'name' => 'Actors',
'singular_name' => 'Actor',
'search_items' => 'Search Actors',
'new_item' => 'New Actor',
'not_found' => 'No actors found.',
'add_new_item' => 'Add new àctor'
),
'has_archive' => 'actors',
'supports' => array( 'title' )
));
register_post_type('movie', array(
'public' => true,
'labels' => array(
'name' => 'Movies',
'singular_name' => 'Movie',
'search_items' => 'Search movies',
'new_item' => 'New Movie',
'not_found' => 'No movies found.',
),
'supports' => array( 'title' )
) );
p2p_register_connection_type( array(
'name' => 'actor_movie',
'from' => 'actor',
'to' => 'movie',
'fields' => array(
'role' => 'Role',
'role_type' => array(
'title' => 'Role Type',
'values' => array( 'lead', 'secondary', '\\episodic' )
),
),
'sortable' => 'any',
'prevent_duplicates' => false,
'admin_box' => array(
'show' => 'any',
'context' => 'advanced',
'priority' => 'high'
),
'admin_column' => 'any',
'admin_dropdown' => 'any',
'title' => array(
'from' => 'Played In',
'to' => 'Cast'
)
) );
p2p_register_connection_type( array(
'name' => 'actor_doubles',
'from' => 'actor',
'to' => 'actor',
'cardinality' => 'one-to-many',
'title' => array( 'from' => 'Doubles', 'to' => 'Main Actor' ),
'data' => array( 'type' => 'doubles' ),
'sortable' => 'order',
'admin_column' => 'any',
'admin_dropdown' => 'any',
'can_create_post' => false,
'from_labels' => array(
'help' => 'The main actor this actor was doubling for.',
),
'to_labels' => array(
'help' => 'Other actors that have played as doubles for this actor.',
'column_title' => 'XXX Doubles',
'singular_name' => 'Double',
'search_items' => 'Search doubles',
'not_found' => 'No doubles found'
),
) );
p2p_register_connection_type( array(
'name' => 'actor_friends',
'from' => array( 'actor' ),
'to' => 'actor',
'reciprocal' => true,
'title' => 'Friends with',
'data' => array( 'type' => 'friends' ),
'to_labels' => array(
'create' => 'Add friends'
),
'admin_column' => 'any'
) );
}
}