-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmeta_box.sublime-snippet
32 lines (28 loc) · 991 Bytes
/
meta_box.sublime-snippet
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
<snippet>
<content><![CDATA[
${13:// Put this into your __construct function
add_action('add_meta_boxes', array(\$this, 'add_$1_metabox'));
add_action('save_post${8:_${7:post_type_slug}}', array(\$this, 'save_$1_metabox_data'));}
public function add_${1:mymetaboxname}_metabox() {
add_meta_box('${2:$1}', ${3:__('${4:Title}'${5:, '${6:domain-name}'})}, array(\$this, '$1_metabox_callback'), '$7', '${9:normal}', '${10:low}');
}
public function $1_metabox_callback(\$post) { ?>
${11:<label>Enter your first name:</label>
<input type="text" name="$1[first_name]" />
<label>Enter your last name:</label>
<input type="text" name="$1[last_name]" />}
<?php
${0:// content goes here}
}
public function save_$1_metabox_data(\$post_id) {
${12:if (!isset(\$_POST['$1'])) {
return \$post_id;
\}
foreach (\$_POST['$1'] as \$key => \$field) {
update_post_meta(\$post_id, \$key, \$field);
\}}
}
]]></content>
<tabTrigger>wp_meta_box</tabTrigger>
<scope>source.php</scope>
</snippet>