Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Create Custom Post
- function rapanui_productos() {
- $labels = array(
- 'name' => _x( 'Productos', 'post type general name' ),
- 'singular_name' => _x( 'Producto', 'post type singular name' ),
- 'add_new' => _x( 'Add New', 'Event' ),
- 'add_new_item' => __( 'Add New Producto' ),
- 'edit_item' => __( 'Edit Producto' ),
- 'new_item' => __( 'New Producto' ),
- 'all_items' => __( 'All Productos' ),
- 'view_item' => __( 'View Producto' ),
- 'search_items' => __( 'Search Productos' ),
- 'not_found' => __( 'No productos found' ),
- 'not_found_in_trash' => __( 'No productos found in the Trash' ),
- 'parent_item_colon' => '',
- 'menu_name' => 'Productos'
- );
- $args = array(
- 'labels' => $labels,
- 'description' => 'Productos de Rapa Nui Chocolates',
- 'public' => true,
- 'show_ui' => true,
- 'capability_type' => 'page',
- 'hierarchical' => true,
- 'menu_position' => 6,
- 'has_archive' => false,
- 'rewrite' => array('slug' => __('productos') , 'with_front' => true ),
- //'rewrite' => false,
- 'query_var' => true,
- 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'author','custom-fields', 'revisions','page-attributes','post-formats' ),
- );
- register_post_type( 'productos', $args );
- }
- add_action( 'init', 'rapanui_productos' );
- //Add custom messages
- function productMessages( $messages ) {
- global $post, $post_ID;
- $messages['productos'] = array(
- 0 => '',
- 1 => sprintf( __('Producto updated. <a href="%s">View product</a>'), esc_url( get_permalink($post_ID) ) ),
- 2 => __('Custom field updated.'),
- 3 => __('Custom field deleted.'),
- 4 => __('Producto updated.'),
- 5 => isset($_GET['revision']) ? sprintf( __('Producto restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
- 6 => sprintf( __('Producto published. <a href="%s">View Producto</a>'), esc_url( get_permalink($post_ID) ) ),
- 7 => __('Producto saved.'),
- 8 => sprintf( __('Producto submitted. <a target="_blank" href="%s">Preview Producto</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
- 9 => sprintf( __('Producto scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Producto</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
- 10 => sprintf( __('Producto draft updated. <a target="_blank" href="%s">Preview Producto</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
- );
- return $messages;
- }
- add_filter( 'post_updated_messages', 'productMessages' );
- // ----------------------------------------------------------------------------------------------
- // Start Custom Meta Box Stuff ------------------------------------------------------------------
- // Admin Meta Box for Products
- add_action( 'add_meta_boxes', 'product_data_box' );
- function product_data_box() {
- add_meta_box(
- 'product_data_box',
- __( 'Product Information', 'myplugin_textdomain' ),
- 'product_data_box_content',
- 'productos',
- 'normal',
- 'core',
- 'low'
- );
- }
- // The Product Admin Metabox
- function product_data_box_content() {
- global $post;
- // Noncename needed to verify where the data originated
- echo '<input type="hidden" name="product_noncename" id="product_noncename" value="' . wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
- // Get the location data if its already been entered
- $product_title = get_post_meta($post->ID, 'product_title', true);
- $product_desc = get_post_meta($post->ID, 'product_desc', true);
- $small_img = get_post_meta($post->ID, 'small_img', true);
- $large_img = get_post_meta($post->ID, 'large_img', true);
- // Echo out the field
- echo '<label>Titulo del Producto';
- echo '<input type="text" name="product_title" value="' . $product_title . '" class="widefat" />';
- echo '</label>';
- echo '<label>Descripción del Producto';
- echo '<textarea type="text" name="product_desc" class="widefat" >' . $product_desc . '</textarea>';
- echo '</label>';
- echo '<label>Imagen Pequeña';
- echo '<input type="text" name="small_img" value="' . $small_img . '" class="widefat" />';
- echo '</label>';
- echo '<label>Imagen Grande';
- echo '<input type="text" name="large_img" value="' . $large_img . '" class="widefat" />';
- echo '</label>';
- }
- // Save the Metabox Data
- function events_meta_save($post_id, $post) {
- // verify this came from the our screen and with proper authorization,
- // because save_post can be triggered at other times
- if ( !wp_verify_nonce( $_POST['eventmeta_noncename'], plugin_basename(__FILE__) )) {
- return $post->ID;
- }
- // Is the user allowed to edit the post or page?
- 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.
- $events_meta['product_title'] = $_POST['product_title'];
- $events_meta['product_desc'] = $_POST['product_desc'];
- $events_meta['small_img'] = $_POST['small_img'];
- $events_meta['large_img'] = $_POST['large_img'];
- // Add values of $events_meta as custom fields
- foreach ($events_meta 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
- }
- }
- // End Custom Meta Box Stuff
- //--------------------------------------------------------------------------------------------
- // Moving the editor lower in the Edit Page bellow my newly created Custom Meta Box
- add_action( 'add_meta_boxes', 'action_add_meta_boxes', 0 );
- function action_add_meta_boxes() {
- global $_wp_post_type_features;
- if (isset($_wp_post_type_features['productos']['editor']) && $_wp_post_type_features['productos']['editor']) {
- unset($_wp_post_type_features['productos']['editor']);
- add_meta_box(
- 'description_section',
- __('Description'),
- 'inner_custom_box',
- 'productos', 'normal', 'low'
- );
- }
- add_action( 'admin_head', 'action_admin_head'); //white background
- }
- function action_admin_head() {
- ?>
- <style type="text/css">
- .wp-editor-container{background-color:#fff;}
- </style>
- <?php
- }
- function inner_custom_box( $post ) {
- echo '<div class="wp-editor-wrap">';
- //the_editor is deprecated in WP3.3, use instead:
- wp_editor($post->post_content, 'content', array('dfw' => true, 'tabindex' => 1) );
- //the_editor($post->post_content);
- echo '</div>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement