Advertisement
Guest User

Untitled

a guest
May 24th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.20 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Print-Service main plugin
  4. Plugin URI: http://wp.tutsplus.com/
  5. Description: Main plugin for project Print-Service by KontoraX
  6. Version: 1.0
  7. Author: Vadim Polh
  8. Author URI: http://werbdesign.com/
  9. License: GPLv2
  10. */
  11. add_action( 'init', 'create_post_types' );
  12. add_action( 'admin_init', 'my_custom_types_print' );
  13. add_action( 'admin_init', 'my_custom_types_stamp' );   
  14. add_action( 'save_post', 'add_print_fields', 10, 2 );
  15. //add_action( 'save_post', 'add_stamp_fields', 10, 2 );
  16.    
  17.     function create_post_types() {
  18.     register_post_type( 'print_items',
  19.         array(
  20.             'labels' => array(
  21.                 'name' => 'Печати',
  22.                 'singular_name' => 'Печати',
  23.                 'add_new' => 'Добавить новую',
  24.                 'add_new_item' => 'Добавить новую печать',
  25.                 'edit' => 'Редактировать',
  26.                 'edit_item' => 'Редактировать печать',
  27.                 'new_item' => 'Добавить новую печать',
  28.                 'view' => 'Просмотреть печать',
  29.                 'view_item' => 'Просмотреть печать',
  30.                 'search_items' => 'Поиск печати',
  31.                 'not_found' => 'Печати не найдены',
  32.                 'not_found_in_trash' => 'В корзине печатей не найдено',
  33.                 'parent' => 'Родительская печать'
  34.             ),
  35.             'public' => true,
  36.             'menu_position' => 10,
  37.             'supports' => array( 'title', 'thumbnail'),
  38.             'taxonomies' => array( '' ),
  39.             'menu_icon' => plugins_url( 'images/print.jpg', __FILE__ ),
  40.             'has_archive' => true
  41.         )
  42.     );
  43.     register_post_type( 'stamp_items',
  44.         array(
  45.             'labels' => array(
  46.                 'name' => 'Штампы',
  47.                 'singular_name' => 'Штампы',
  48.                 'add_new' => 'Добавить новый',
  49.                 'add_new_item' => 'Добавить новый штамп',
  50.                 'edit' => 'Редактировать',
  51.                 'edit_item' => 'Редактировать штамп',
  52.                 'new_item' => 'Добавить новый штамп',
  53.                 'view' => 'Просмотреть штамп',
  54.                 'view_item' => 'Просмотреть штамп',
  55.                 'search_items' => 'Поиск щтампа',
  56.                 'not_found' => 'Штампы не найдены',
  57.                 'not_found_in_trash' => 'В корзине штампов не найдено',
  58.                 'parent' => 'Родительский штамп'
  59.             ),
  60.             'public' => true,
  61.             'menu_position' => 10,
  62.             'supports' => array( 'title','thumbnail'),
  63.             'taxonomies' => array( '' ),
  64.             'menu_icon' => plugins_url( 'images/stamp.png', __FILE__ ),
  65.             'has_archive' => true
  66.         )
  67.     );
  68. }
  69. function my_custom_types_print() {
  70.     add_meta_box( 'print_items_box',
  71.         'Параметры печати',
  72.         'display_print_meta_box',
  73.         'print_items', 'normal', 'high'
  74.     );
  75. }
  76. function my_custom_types_stamp() {
  77.     add_meta_box( 'stamp_items_box',
  78.         'Параметры штампа',
  79.         'display_stamp_meta_box',
  80.         'stamp_items', 'normal', 'high'
  81.     );
  82. }
  83. ?>
  84. <?php
  85. function display_print_meta_box($print_items) {
  86.     // Retrieve current name of the Director and Movie Rating based on review ID
  87.     $price = esc_html( get_post_meta( $price->ID, 'price', true ) );
  88.     //$movie_rating = intval( get_post_meta( $movie_review->ID, 'movie_rating', true ) );
  89.     ?>
  90.     <table>
  91.         <tr>
  92.             <td style="width: 100%">Цена</td>
  93.             <td><input type="text" size="80" name="price_value" value="<?php echo $price; ?>" /></td>
  94.         </tr><?print_r($_POST)?>
  95.         <!-- <tr>
  96.             <td style="width: 150px">Movie Rating</td>
  97.             <td>
  98.                 <select style="width: 100px" name="movie_review_rating">
  99.                 <?php
  100.                 // Generate all items of drop-down list
  101.                 for ( $rating = 5; $rating >= 1; $rating -- ) {
  102.                 ?>
  103.                     <option value="<?php echo $rating; ?>" <?php echo selected( $rating, $movie_rating ); ?>>
  104.                     <?php echo $rating; ?> stars <?php } ?>
  105.                 </select>
  106.             </td>
  107.         </tr> -->
  108.     </table>
  109.     <?php
  110. }
  111. ?>
  112. <?php
  113. function display_stamp_meta_box( $stamp_items) {
  114.     // Retrieve current name of the Director and Movie Rating based on review ID
  115.     $price = esc_html( get_post_meta( $price->ID, 'price', true ) );
  116.     //$movie_rating = intval( get_post_meta( $movie_review->ID, 'movie_rating', true ) );
  117.     ?>
  118.     <table>
  119.         <tr>
  120.             <td style="width: 100%">Цена</td>
  121.             <td><input type="text" size="80" name="price_value" value="<?php echo $price;?>" /></td>
  122.         </tr>
  123.         <!-- <tr>
  124.             <td style="width: 150px">Movie Rating</td>
  125.             <td>
  126.                 <select style="width: 100px" name="movie_review_rating">
  127.                 <?php
  128.                 // Generate all items of drop-down list
  129.                 for ( $rating = 5; $rating >= 1; $rating -- ) {
  130.                 ?>
  131.                     <option value="<?php echo $rating; ?>" <?php echo selected( $rating, $movie_rating ); ?>>
  132.                     <?php echo $rating; ?> stars <?php } ?>
  133.                 </select>
  134.             </td>
  135.         </tr> -->
  136.     </table>
  137.     <?php
  138. }
  139. ?>
  140. <?
  141. function add_print_fields($print_items_id, $print_items) {
  142.     // Check post type for movie reviews
  143.     if ( $print_items->post_type == 'print_items' ) {
  144.         // Store data in post meta table if present in post data
  145.         if ( isset( $_POST['price_value'] ) && $_POST['price_value'] != '' ) {
  146.             update_post_meta( $print_items_id, 'price', $_POST['price_value'] );
  147.         }
  148.         // if ( isset( $_POST['movie_review_rating'] ) && $_POST['movie_review_rating'] != '' ) {
  149.         //     update_post_meta( $movie_review_id, 'movie_rating', $_POST['movie_review_rating'] );
  150.         // }
  151.     }
  152. }
  153.  
  154. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement