PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 1.7.1
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v1.7.1
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / admin / includes / class-betterdocs-metabox.php

class-betterdocs-metabox.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 1.7.1, at admin/includes/class-betterdocs-metabox.php

134 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class BetterDocs_MetaBox {
4
5 public $type = 'betterdocs';
6
7 public static $args;
8 public static $prefix = 'betterdocs_meta_';
9 public static $post_id;
10 public static $object_types;
11
12 public $defaults = array(
13 'id' => '',
14 'title' => '',
15 'object_types' => array(),
16 'context' => 'normal',
17 'priority' => 'low',
18 'show_header' => true,
19 'prefix' => ''
20 );
21
22
23 public static function render_meta_field( $key = '', $field = [], $value = '', $idd = null ) {
24 global $pagenow;
25 $post_id = self::$post_id;
26 $attrs = $wrapper_attrs = '';
27 if( ! is_null( $idd ) ){
28 $post_id = $idd;
29 }
30 $name = self::$prefix . $key;
31 $field_id = $name;
32 $id = self::get_row_id( $key );
33 $file_name = isset( $field['type'] ) ? $field['type'] : '';
34
35 if( 'template' === $file_name ) {
36 $default = isset( $field['defaults'] ) ? $field['defaults'] : [];
37 } else {
38 $default = isset( $field['default'] ) ? $field['default'] : '';
39 }
40
41 if( empty( $value ) ) {
42 if( metadata_exists( 'post', $post_id, "_{$name}" ) ) {
43 $value = get_post_meta( $post_id, "_{$name}", true );
44 } else {
45 $value = $default;
46 }
47 } else {
48 $value = $value;
49 }
50
51 $default_attr = is_array( $default ) ? json_encode( $default ) : $default;
52
53 if( ! empty( $default_attr ) ) {
54 $attrs .= ' data-default="' . esc_attr( $default_attr ) . '"';
55 }
56
57 $class = 'betterdocs-meta-field';
58 $row_class = self::get_row_class( $file_name );
59
60 if( isset( $field['class'] ) && ! empty( $field['class'] ) ) {
61 $row_class .= ' ' . $field['class'];
62 }
63 $row_class .= ' betterdocs-' . $key;
64
65 $attrs .= ' data-key="' . esc_attr( $key ) . '"';
66
67 if( isset( $field['tab'] ) && $file_name == 'select' ) {
68 $attrs .= ' data-tab="' . esc_attr( json_encode( $field['tab'] ) ) . '"';
69 }
70
71 if( isset( $field['builder_hidden'] ) && $field['builder_hidden'] && $pagenow == 'admin.php' ) {
72 $row_class .= ' betterdocs-builder-hidden';
73 }
74
75 include BETTERDOCS_ADMIN_DIR_PATH . 'partials/betterdocs-field-display.php';
76 }
77 /**
78 * Get the row id ready
79 *
80 * @param string $key
81 * @return string
82 */
83 public static function get_row_id( $key ) {
84 return str_replace( '_', '-', self::$prefix ) . $key;
85 }
86 /**
87 * Get the row id ready
88 *
89 * @param string $key
90 * @return string
91 */
92 public static function get_row_class( $file ) {
93 $prefix = str_replace( '_', '-', self::$prefix );
94
95 switch( $file ) {
96 case 'group':
97 $row_class = $prefix .'group-row';
98 break;
99 case 'colorpicker':
100 $row_class = $prefix .'colorpicker-row';
101 break;
102 case 'message':
103 $row_class = $prefix . 'info-message-wrapper';
104 break;
105 case 'theme':
106 $row_class = $prefix . 'theme-field-wrapper';
107 break;
108 default :
109 $row_class = $prefix . $file;
110 break;
111 }
112
113 return $row_class;
114 }
115
116 public static function get_metabox_fields( $prefix = '' ) {
117 $args = self::get_args();
118 $tabs = $args['tabs'];
119
120 $new_fields = [];
121
122 foreach( $tabs as $tab ) {
123 $sections = $tab['sections'];
124 foreach( $sections as $section ) {
125 $fields = $section['fields'];
126 foreach( $fields as $id => $field ) {
127 $new_fields[ $prefix . $id ] = $field;
128 }
129 }
130 }
131
132 return apply_filters('betterdocs_meta_fields', $new_fields );
133 }
134 }