Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Print-Service main plugin
- Plugin URI: http://wp.tutsplus.com/
- Description: Main plugin for project Print-Service by KontoraX
- Version: 1.0
- Author: Vadim Polh
- Author URI: http://werbdesign.com/
- License: GPLv2
- */
- add_action( 'init', 'create_post_types' );
- add_action( 'admin_init', 'my_custom_types_print' );
- add_action( 'admin_init', 'my_custom_types_stamp' );
- add_action( 'save_post', 'add_print_fields', 10, 2 );
- //add_action( 'save_post', 'add_stamp_fields', 10, 2 );
- function create_post_types() {
- register_post_type( 'print_items',
- array(
- 'labels' => array(
- 'name' => 'Печати',
- 'singular_name' => 'Печати',
- 'add_new' => 'Добавить новую',
- 'add_new_item' => 'Добавить новую печать',
- 'edit' => 'Редактировать',
- 'edit_item' => 'Редактировать печать',
- 'new_item' => 'Добавить новую печать',
- 'view' => 'Просмотреть печать',
- 'view_item' => 'Просмотреть печать',
- 'search_items' => 'Поиск печати',
- 'not_found' => 'Печати не найдены',
- 'not_found_in_trash' => 'В корзине печатей не найдено',
- 'parent' => 'Родительская печать'
- ),
- 'public' => true,
- 'menu_position' => 10,
- 'supports' => array( 'title', 'thumbnail'),
- 'taxonomies' => array( '' ),
- 'menu_icon' => plugins_url( 'images/print.jpg', __FILE__ ),
- 'has_archive' => true
- )
- );
- register_post_type( 'stamp_items',
- array(
- 'labels' => array(
- 'name' => 'Штампы',
- 'singular_name' => 'Штампы',
- 'add_new' => 'Добавить новый',
- 'add_new_item' => 'Добавить новый штамп',
- 'edit' => 'Редактировать',
- 'edit_item' => 'Редактировать штамп',
- 'new_item' => 'Добавить новый штамп',
- 'view' => 'Просмотреть штамп',
- 'view_item' => 'Просмотреть штамп',
- 'search_items' => 'Поиск щтампа',
- 'not_found' => 'Штампы не найдены',
- 'not_found_in_trash' => 'В корзине штампов не найдено',
- 'parent' => 'Родительский штамп'
- ),
- 'public' => true,
- 'menu_position' => 10,
- 'supports' => array( 'title','thumbnail'),
- 'taxonomies' => array( '' ),
- 'menu_icon' => plugins_url( 'images/stamp.png', __FILE__ ),
- 'has_archive' => true
- )
- );
- }
- function my_custom_types_print() {
- add_meta_box( 'print_items_box',
- 'Параметры печати',
- 'display_print_meta_box',
- 'print_items', 'normal', 'high'
- );
- }
- function my_custom_types_stamp() {
- add_meta_box( 'stamp_items_box',
- 'Параметры штампа',
- 'display_stamp_meta_box',
- 'stamp_items', 'normal', 'high'
- );
- }
- ?>
- <?php
- function display_print_meta_box($print_items) {
- // Retrieve current name of the Director and Movie Rating based on review ID
- $price = esc_html( get_post_meta( $price->ID, 'price', true ) );
- //$movie_rating = intval( get_post_meta( $movie_review->ID, 'movie_rating', true ) );
- ?>
- <table>
- <tr>
- <td style="width: 100%">Цена</td>
- <td><input type="text" size="80" name="price_value" value="<?php echo $price; ?>" /></td>
- </tr><?print_r($_POST)?>
- <!-- <tr>
- <td style="width: 150px">Movie Rating</td>
- <td>
- <select style="width: 100px" name="movie_review_rating">
- <?php
- // Generate all items of drop-down list
- for ( $rating = 5; $rating >= 1; $rating -- ) {
- ?>
- <option value="<?php echo $rating; ?>" <?php echo selected( $rating, $movie_rating ); ?>>
- <?php echo $rating; ?> stars <?php } ?>
- </select>
- </td>
- </tr> -->
- </table>
- <?php
- }
- ?>
- <?php
- function display_stamp_meta_box( $stamp_items) {
- // Retrieve current name of the Director and Movie Rating based on review ID
- $price = esc_html( get_post_meta( $price->ID, 'price', true ) );
- //$movie_rating = intval( get_post_meta( $movie_review->ID, 'movie_rating', true ) );
- ?>
- <table>
- <tr>
- <td style="width: 100%">Цена</td>
- <td><input type="text" size="80" name="price_value" value="<?php echo $price;?>" /></td>
- </tr>
- <!-- <tr>
- <td style="width: 150px">Movie Rating</td>
- <td>
- <select style="width: 100px" name="movie_review_rating">
- <?php
- // Generate all items of drop-down list
- for ( $rating = 5; $rating >= 1; $rating -- ) {
- ?>
- <option value="<?php echo $rating; ?>" <?php echo selected( $rating, $movie_rating ); ?>>
- <?php echo $rating; ?> stars <?php } ?>
- </select>
- </td>
- </tr> -->
- </table>
- <?php
- }
- ?>
- <?
- function add_print_fields($print_items_id, $print_items) {
- // Check post type for movie reviews
- if ( $print_items->post_type == 'print_items' ) {
- // Store data in post meta table if present in post data
- if ( isset( $_POST['price_value'] ) && $_POST['price_value'] != '' ) {
- update_post_meta( $print_items_id, 'price', $_POST['price_value'] );
- }
- // if ( isset( $_POST['movie_review_rating'] ) && $_POST['movie_review_rating'] != '' ) {
- // update_post_meta( $movie_review_id, 'movie_rating', $_POST['movie_review_rating'] );
- // }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement