diff --git a/functions.php b/functions.php index 03659b5..f2d511d 100644 --- a/functions.php +++ b/functions.php @@ -15,6 +15,7 @@ require ABSPATH.'/vendor/autoload.php'; require get_template_directory().'/src/calend-block.php'; require get_template_directory().'/src/calendar.php'; +require get_template_directory().'/src/perevod.php'; //require ABSPATH.'vendor/masterforweb/db_lite/db_lite.php'; diff --git a/src/perevod.php b/src/perevod.php index 21c7af1..0316f10 100644 --- a/src/perevod.php +++ b/src/perevod.php @@ -1,39 +1,91 @@ true, - 'single' => true, - 'type' => 'string' - )); +add_action( 'load-post.php', 'perevod_post_meta_boxes_setup' ); +add_action( 'load-post-new.php', 'perevod_post_meta_boxes_setup' ); + +function perevod_post_meta_boxes_setup() { + + add_action( 'add_meta_boxes', function (){ + add_meta_box( + 'perevod-post', + 'Перевод', + 'perevod_post_class_meta_box', + 'post', + 'side', + 'default' + ); + }); + + + add_action( 'save_post', function ($post_id, $post){ + + // проверяем, может ли текущий юзер редактировать пост + $post_type = get_post_type_object( $post->post_type ); + + if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) { + return $post_id; + } + + // ничего не делаем для автосохранений + if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) { + return $post_id; + } + + + $curr_id = 0; + + if( isset( $_POST[ 'perevod_name' ] )) { + $curr_id = (int) $_POST[ 'perevod_name' ]; + } + + + if ($curr_id == 0) { + $meta_value = get_post_meta( $post_id, $meta_key, true ); + if ($meta_value !== false) { + delete_post_meta( $post_id, 'perevod_name' ); + } + } + else { + update_post_meta( $post_id, 'perevod_name', sanitize_text_field( $_POST[ 'perevod_name' ] ) ); + } + + return $post_id; -});**/ + } + , 10, 2 ); - -add_action( 'add_meta_boxes', function (){ - add_meta_box( - 'subscript-post', - 'Переводчик', - 'perevod_post_class_meta_box', - 'post', - 'side', - 'default' - ); -}); + +} function perevod_post_class_meta_box( $post ) {?> - -
- - -
-