-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwc_np_metbox.php
More file actions
58 lines (43 loc) · 1.41 KB
/
wc_np_metbox.php
File metadata and controls
58 lines (43 loc) · 1.41 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
<?php
namespace NP;
class Wc_np_metabox {
public function __construct() {
add_action( 'save_post', array( $this, 'NPEN_meta_box_save' ), 10, 2 );
}
function NPEN_meta_box_add() {
add_meta_box( 'novaposhta_declaration', 'Номер ЭН Новой почты', array( $this, 'NPEN_meta_box_cb' ),
'shop_order', 'normal',
'core' );
}
function NPEN_meta_box_cb( $post, $box ) {
global $nppost;
wp_nonce_field( "metatest_nonce", "metatest_nonce" );
include_once( WC_NP_DIR . 'views/npen_template.php' );
}
function NPEN_meta_box_save( $postID, $post ) {
// пришло ли поле наших данных?
if ( ! isset( $_POST['metadata_field'] ) && ! empty( $_POST['metadata_field'] ) ) {
return;
}
// не происходит ли автосохранение?
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// не ревизию ли сохраняем?
if ( wp_is_post_revision( $postID ) ) {
return;
}
// может ли юзер редактировать эту запись?
if ( ! current_user_can( 'edit_post', $postID ) ) {
return;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['metatest_nonce'], 'metatest_nonce' ) ) {
return;
}
// коррекция данных
$data = sanitize_text_field( $_POST['metadata_field'] );
// запись
update_post_meta( $postID, '_metatest_data', $data );
}
}