Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_ajax_add_meta [ WordPress Function ]

wp_ajax_add_meta ( No parameters )
Defined at:



No description yet.

Source


<?php
function wp_ajax_add_meta() {
    
check_ajax_referer'add-meta''_ajax_nonce-add-meta' );
    
$c 0;
    
$pid = (int) $_POST['post_id'];
    
$post get_post$pid );

    if ( isset(
$_POST['metakeyselect']) || isset($_POST['metakeyinput']) ) {
        if ( !
current_user_can'edit_post'$pid ) )
            
wp_die( -);
        if ( isset(
$_POST['metakeyselect']) && '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) )
            
wp_die);
        if ( 
$post->post_status == 'auto-draft' ) {
            
$save_POST $_POST// Backup $_POST
            
$_POST = array(); // Make it empty for edit_post()
            
$_POST['action'] = 'draft'// Warning fix
            
$_POST['post_ID'] = $pid;
            
$_POST['post_type'] = $post->post_type;
            
$_POST['post_status'] = 'draft';
            
$now current_time('timestamp'1);
            
$_POST['post_title'] = sprintf('Draft created on %s at %s'date(get_option('date_format'), $now), date(get_option('time_format'), $now));

            if ( 
$pid edit_post() ) {
                if ( 
is_wp_error$pid ) ) {
                    
$x = new WP_Ajax_Response( array(
                        
'what' => 'meta',
                        
'data' => $pid
                    
) );
                    
$x->send();
                }
                
$_POST $save_POST// Now we can restore original $_POST again
                
if ( !$mid add_meta$pid ) )
                    
wp_die__'Please provide a custom field value.' ) );
            } else {
                
wp_die);
            }
        } else if ( !
$mid add_meta$pid ) ) {
            
wp_die__'Please provide a custom field value.' ) );
        }

        
$meta get_metadata_by_mid'post'$mid );
        
$pid = (int) $meta->post_id;
        
$meta get_object_vars$meta );
        
$x = new WP_Ajax_Response( array(
            
'what' => 'meta',
            
'id' => $mid,
            
'data' => _list_meta_row$meta$c ),
            
'position' => 1,
            
'supplemental' => array('postid' => $pid)
        ) );
    } else { 
// Update?
        
$mid = (int) key$_POST['meta'] );
        
$key stripslashes$_POST['meta'][$mid]['key'] );
        
$value stripslashes$_POST['meta'][$mid]['value'] );
        if ( 
'' == trim($key) )
            
wp_die__'Please provide a custom field name.' ) );
        if ( 
'' == trim($value) )
            
wp_die__'Please provide a custom field value.' ) );
        if ( ! 
$meta get_metadata_by_mid'post'$mid ) )
            
wp_die); // if meta doesn't exist
        
if ( is_protected_meta$meta->meta_key'post' ) || is_protected_meta$key'post' ) ||
            ! 
current_user_can'edit_post_meta'$meta->post_id$meta->meta_key ) ||
            ! 
current_user_can'edit_post_meta'$meta->post_id$key ) )
            
wp_die( -);
        if ( 
$meta->meta_value != $value || $meta->meta_key != $key ) {
            if ( !
$u update_metadata_by_mid'post'$mid$value$key ) )
                
wp_die); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
        
}

        
$x = new WP_Ajax_Response( array(
            
'what' => 'meta',
            
'id' => $mid'old_id' => $mid,
            
'data' => _list_meta_row( array(
                
'meta_key' => $key,
                
'meta_value' => $value,
                
'meta_id' => $mid
            
), $c ),
            
'position' => 0,
            
'supplemental' => array('postid' => $meta->post_id)
        ) );
    }
    
$x->send();
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics