-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_plugink.php
75 lines (69 loc) · 2.43 KB
/
class_plugink.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
<?php
if (!class_exists('PluginK')) {
class PluginK
{
public static function create_type_post($type_name, $singular, $plural, $data = [])
{
if (!post_type_exists('subs_types')) {
$labels = [
'name' => $plural,
'singular_name' => $singular,
'add_new' => 'Añadir nuevo',
'add_new_item' => "Añadir nuevo $singular",
'edit_item' => "Editar $singular",
'featured_image' => 'Imagen destacada',
'set_featured_image' => 'Establecer imagen destacada'
];
$config = array(
'label' => $labels['singular_name'],
'labels' => $labels
);
foreach ($data as $key => $value) {
$config[$key] = $value;
}
register_post_type($type_name, $config);
}
}
public static function create_meta($type, $metas)
{
foreach ($metas as $meta) {
add_meta_box('id_' . $meta['title'], $meta['title'], $meta['render_callback'], $type, 'normal', 'high');
}
}
public static function set_var_meta($post_id, $vars)
{
foreach ($vars as $var) {
update_post_meta($post_id, $var, $_POST[$var]);
}
}
public static function get_var_meta($name, $post_id = null)
{
if (!$post_id) {
$post_id = get_the_ID();
}
$metas = get_post_meta($post_id);
if (isset($metas[$name])) {
$meta = $metas[$name];
if (count($meta) > 1) {
return $meta;
} else {
return $meta[0];
}
}
return null;
}
public static function create_db($tables, $pk)
{
global $wpdb;
$sql = "";
foreach ($tables as $tableName => $table) {
$sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}$tableName ` (";
foreach ($table as $field => $description) {
$sql .= " `$field` $description, ";
}
$sql .= "PRIMARY KEY (`" . $pk[$tableName] . "`)) ENGINE = InnoDB";
}
$wpdb->get_results($sql);
}
}
}