Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'quick_edit_custom_box', 'display_ir_quickedit_cena', 10, 2 );
- function display_ir_quickedit_cena( $column_name, $post_type ) {
- static $printNonce = TRUE;
- if ( $printNonce ) {
- $printNonce = FALSE;
- wp_nonce_field( 'ir_edit_cena', 'ir_darky_edit_nonce' );
- }
- ?>
- <fieldset class="inline-edit-col-right inline-edit-cena">
- <div class="inline-edit-col column-<?php echo $column_name; ?>">
- <label class="inline-edit-group">
- <?php
- switch ( $column_name ) {
- case 'cena':
- ?><span class="title">Cena v kreditech</span><input name="cena" /><?php
- break;
- }
- ?>
- </label>
- </div>
- </fieldset>
- <?php
- }
- add_action( 'save_post', 'save_cena_meta' );
- function save_cena_meta( $post_id ) {
- /* in production code, $slug should be set only once in the plugin,
- preferably as a class property, rather than in each function that needs it.
- */
- $slug = 'ir_darky';
- if ( $slug !== $_POST['post_type'] ) {
- return;
- }
- if ( !current_user_can( 'edit_post', $post_id ) ) {
- return;
- }
- $_POST += array("{$slug}_edit_nonce" => '');
- if ( !wp_verify_nonce( $_POST["{$slug}_edit_nonce"],
- 'ir_edit_cena' ) )
- {
- return;
- }
- if ( isset( $_REQUEST['cena'] ) ) {
- update_post_meta( $post_id, 'kbnt_cena', $_REQUEST['cena'] );
- }
- }
- /* load script in the footer */
- if ( ! function_exists('wp_ir_admin_enqueue_scripts') ):
- function wp_ir_admin_enqueue_scripts( $hook ) {
- if ( 'edit.php' === $hook &&
- isset( $_GET['post_type'] ) &&
- 'ir_darky' === $_GET['post_type'] ) {
- wp_enqueue_script( 'ir_custom_script', get_stylesheet_directory_uri().'/js/admin_edit.js',
- false, null, true );
- }
- }
- endif;
- add_action( 'admin_enqueue_scripts', 'wp_ir_admin_enqueue_scripts' );
- /* example of how an existing value can be stored in the table */
- add_action( 'manage_cena_posts_custom_column' , 'custom_cena_column', 10, 2 );
- function custom_cena_column( $column, $post_id ) {
- switch ( $column ) {
- case 'cena':
- // the !! means translate the following item to a boolean value
- if ( !!get_post_meta( $post_id , 'kbnt_cena' , true ) ) {
- $value = get_post_meta( $post_id , 'kbnt_cena' , true );
- }
- echo '<span class="title">Cena v kreditech</span><input name="cena" value="'.$value.'"/>';
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement