Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. add_action( 'quick_edit_custom_box', 'display_ir_quickedit_cena', 10, 2 );
  2.  
  3. function display_ir_quickedit_cena( $column_name, $post_type ) {
  4. static $printNonce = TRUE;
  5. if ( $printNonce ) {
  6. $printNonce = FALSE;
  7. wp_nonce_field( 'ir_edit_cena', 'ir_darky_edit_nonce' );
  8. }
  9.  
  10. ?>
  11. <fieldset class="inline-edit-col-right inline-edit-cena">
  12. <div class="inline-edit-col column-<?php echo $column_name; ?>">
  13. <label class="inline-edit-group">
  14. <?php
  15. switch ( $column_name ) {
  16. case 'cena':
  17. ?><span class="title">Cena v kreditech</span><input name="cena" /><?php
  18. break;
  19. }
  20. ?>
  21. </label>
  22. </div>
  23. </fieldset>
  24. <?php
  25. }
  26.  
  27. add_action( 'save_post', 'save_cena_meta' );
  28.  
  29. function save_cena_meta( $post_id ) {
  30. /* in production code, $slug should be set only once in the plugin,
  31. preferably as a class property, rather than in each function that needs it.
  32. */
  33. $slug = 'ir_darky';
  34. if ( $slug !== $_POST['post_type'] ) {
  35. return;
  36. }
  37. if ( !current_user_can( 'edit_post', $post_id ) ) {
  38. return;
  39. }
  40. $_POST += array("{$slug}_edit_nonce" => '');
  41. if ( !wp_verify_nonce( $_POST["{$slug}_edit_nonce"],
  42. 'ir_edit_cena' ) )
  43. {
  44. return;
  45. }
  46.  
  47. if ( isset( $_REQUEST['cena'] ) ) {
  48. update_post_meta( $post_id, 'kbnt_cena', $_REQUEST['cena'] );
  49. }
  50. }
  51.  
  52. /* load script in the footer */
  53. if ( ! function_exists('wp_ir_admin_enqueue_scripts') ):
  54. function wp_ir_admin_enqueue_scripts( $hook ) {
  55.  
  56. if ( 'edit.php' === $hook &&
  57. isset( $_GET['post_type'] ) &&
  58. 'ir_darky' === $_GET['post_type'] ) {
  59.  
  60. wp_enqueue_script( 'ir_custom_script', get_stylesheet_directory_uri().'/js/admin_edit.js',
  61. false, null, true );
  62. }
  63.  
  64. }
  65. endif;
  66. add_action( 'admin_enqueue_scripts', 'wp_ir_admin_enqueue_scripts' );
  67.  
  68.  
  69. /* example of how an existing value can be stored in the table */
  70. add_action( 'manage_cena_posts_custom_column' , 'custom_cena_column', 10, 2 );
  71. function custom_cena_column( $column, $post_id ) {
  72. switch ( $column ) {
  73. case 'cena':
  74. // the !! means translate the following item to a boolean value
  75. if ( !!get_post_meta( $post_id , 'kbnt_cena' , true ) ) {
  76. $value = get_post_meta( $post_id , 'kbnt_cena' , true );
  77. }
  78. echo '<span class="title">Cena v kreditech</span><input name="cena" value="'.$value.'"/>';
  79. break;
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement