Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action('add_meta_boxes', 'lonchera_add_infoproducto');
- function lonchera_add_infoproducto()
- {
- add_meta_box('lonchera_infoproducto', 'Información del producto', 'lonchera_infoproducto', 'post', 'normal', 'default');
- }
- function lonchera_infoproducto() {
- global $post, $wp_locale;
- wp_nonce_field( plugin_basename(__FILE__), 'lonchera_infoproducto_noncename' );
- $codigo = get_post_meta($post->ID, 'codigo', true);
- $lol = '<label for="marca">Código:</label> <input type="text" name="lonchera_codigo" value="'.$codigo.'" id="lonchera_marca" />';
- echo $lol;
- }
- function lonchera_save_infoproducto($post_id, $post) {
- if ( !wp_verify_nonce( $_POST['lonchera_infoproducto_noncename'], plugin_basename(__FILE__) )) {
- return $post_id;
- }
- // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want
- // to do anything
- if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
- return $post_id;
- }
- // Check permissions
- if ( 'page' == $_POST['post_type'] ) {
- if ( !current_user_can( 'edit_page', $post_id ) )
- return $post_id;
- } else {
- if ( !current_user_can( 'edit_post', $post_id ) )
- return $post_id;
- }
- // OK, we're authenticated: we need to find and save the data
- // We'll put it into an array to make it easier to loop though.
- $metas['codigo'] = $_POST['lonchera_codigo'];
- foreach ($metas as $key => $value) { // Cycle through the $events_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else { // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- //if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
- }
- }
- add_action('save_post', 'lonchera_save_infoproducto', 1, 2);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement