-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathx-custom-types.php
More file actions
69 lines (58 loc) · 1.91 KB
/
x-custom-types.php
File metadata and controls
69 lines (58 loc) · 1.91 KB
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
<?php
/**
* Register some new CPTs
*/
/**
* Security: Do not access directly.
*/
if ( count( get_included_files() ) === 1 ) {
echo 'Direct access not allowed';
exit();
}
$custom_types = array(
'posts' => array(
'id' => 'BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY',
'owner' => 'BIGINT UNSIGNED NOT NULL',
'uuid' => 'VARCHAR(255) NOT NULL',
'title' => 'TEXT NOT NULL',
'summary' => 'MEDIUMTEXT',
'content' => 'LONGTEXT',
'publicationdate' => 'DATETIME NOT NULL',
'editdate' => 'DATETIME NOT NULL',
),
);
function register_cpts( $custom_types ) {
$db = new X_Post();
foreach ( $custom_types as $table_name => $table_columns ) {
$tables = '';
foreach ( $table_columns as $key => $type ) {
$tables .= $key . ' ' . $type . ', ';
}
$tables = rtrim( $tables, ', ' );
$db->add_table( $table_name, $tables );
}
$db = null;
}
register_cpts( $custom_types );
$x_hooks = new X_Hooks();
$x_hooks->add_filter( 'x_public_tables', 'whitelist' );
function whitelist( $array ) {
$array[]='posts';
return $array;
}
$x_hooks->add_action( 'after_pages_menu', 'add_menu' );
function add_menu() {
?>
<a class="nav-link text-secondary collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#x_sidenav_collapse_posts" aria-expanded="false" aria-controls="x_sidenav_collapse_posts">
<div class="x-admin__sidebar-nav-icon"><span class="bi bi-file-post"></span></div>
Posts
<div class="x-admin__sidebar-nav-collapse-arrow"><span class="bi bi-chevron-down"></span></div>
</a>
<div class="collapse" id="x_sidenav_collapse_posts" data-bs-parent="#x_sidenav_accordion">
<nav class="x-admin-sidebar__nav-nested nav" aria-label="Posts">
<a class="nav-link text-secondary" href="/admin.php?x_action=list&x_type=posts">All Posts</a>
<a class="nav-link text-secondary" href="/admin.php?x_action=add&x_type=posts">Add Posts</a>
</nav>
</div>
<?php
}