/**
  * Check POST date for convert object on an another custom type.
  *
  * @return void
  * @author Amaury Balmer
  */
 function checkConversion()
 {
     if (isset($_POST['custom-type-convert']) && $_POST['custom-type-convert'] == '1') {
         check_admin_referer('convert-post_type');
         foreach ((array) $_POST['objects'] as $object_id => $new_post_type) {
             // Change the post type
             $object = get_post_to_edit($object_id);
             $object->post_type = $new_post_type;
             wp_update_post((array) $object);
             // Clean object cache
             clean_post_cache($object_id);
         }
         return true;
     }
     return false;
 }
 /**
  * Listen POST datas for make bulk posts conversion to new post type
  */
 function listenConversion()
 {
     global $pagenow, $wpdb;
     if ($pagenow != 'edit.php') {
         return false;
     }
     // Default values for CPT
     $typenow = isset($_REQUEST['post_type']) ? $_REQUEST['post_type'] : 'post';
     if (isset($_REQUEST['action']) && substr($_REQUEST['action'], 0, strlen('convert_cpt')) == 'convert_cpt') {
         check_admin_referer('bulk-posts');
         // Source CPT
         $source_cpt = get_post_type_object($typenow);
         if (!current_user_can($source_cpt->cap->edit_posts)) {
             wp_die(__('Cheatin’ uh?'));
         }
         // Destination CPT
         $destination_cpt = get_post_type_object(substr($_REQUEST['action'], strlen('convert_cpt') + 1));
         if (!current_user_can($destination_cpt->cap->edit_posts)) {
             wp_die(__('Cheatin’ uh?'));
         }
         // Loop on posts
         foreach ((array) $_REQUEST['post'] as $post_id) {
             // Change the post type
             $object = get_post_to_edit($post_id);
             $object->post_type = $destination_cpt->name;
             wp_update_post((array) $object);
             // Clean object cache
             clean_post_cache($post_id);
         }
         $location = 'edit.php?post_type=' . $typenow;
         if ($referer = wp_get_referer()) {
             if (false !== strpos($referer, 'edit.php')) {
                 $location = $referer;
             }
         }
         $location = add_query_arg('message', 991, $location);
         wp_redirect($location);
         exit;
     }
 }
	wp_redirect($location);
	exit();
	break;

case 'edit':
	$title = __('Edit');

	require_once('admin-header.php');

	$post_ID = $p = (int) $_GET['post'];

	if ( !current_user_can('edit_post', $post_ID) )
		die ( __('You are not allowed to edit this post.') );

	$post = get_post_to_edit($post_ID);
	
	if ($post->post_status == 'static')
		include('edit-page-form.php');
	else
		include('edit-form-advanced.php');

	?>
	<div id='preview' class='wrap'>
	<h2 id="preview-post"><?php _e('Post Preview (updated when post is saved)'); ?> <small class="quickjump"><a href="#write-post"><?php _e('edit &uarr;'); ?></a></small></h2>
		<iframe src="<?php echo attribute_escape(apply_filters('preview_post_link', add_query_arg('preview', 'true', get_permalink($post->ID)))); ?>" width="100%" height="600" ></iframe>
	</div>
	<?php
	break;

case 'editattachment':
function wp_upload_form() {
	$id = get_the_ID();
	global $post_id, $tab, $style;
	$enctype = $id ? '' : ' enctype="multipart/form-data"';
	$post_id = (int) $post_id;
?>
	<form<?php echo $enctype; ?> id="upload-file" method="post" action="<?php echo get_option('siteurl') . '/wp-admin/upload.php?style=' . attribute_escape($style . '&amp;tab=upload&amp;post_id=' . $post_id); ?>">
<?php
	if ( $id ) :
		$attachment = get_post_to_edit( $id );
		$attachment_data = wp_get_attachment_metadata( $id );
?>
		<div id="file-title">
			<h2><?php if ( !isset($attachment_data['width']) && 'inline' != $style )
					echo "<a href='" . wp_get_attachment_url() . "' title='" . __('Direct link to file') . "'>";
				the_title();
				if ( !isset($attachment_data['width']) && 'inline' != $style )
					echo '</a>';
			?></h2>
			<span><?php
				echo '[&nbsp;';
				echo '<a href="' . get_permalink() . '">' . __('view') . '</a>';
				echo '&nbsp;|&nbsp;';
					echo '<a href="' . clean_url(add_query_arg('action', 'view')) . '">' . __('links') . '</a>';
				echo '&nbsp;|&nbsp;';
				echo '<a href="' . clean_url(remove_query_arg(array('action','ID'))) . '" title="' . __('Browse your files') . '">' . __('cancel') . '</a>';
				echo '&nbsp;]'; ?></span>
		</div>

	<div id="upload-file-view" class="alignleft">
<?php		if ( isset($attachment_data['width']) && 'inline' != $style )
			echo "<a href='" . wp_get_attachment_url() . "' title='" . __('Direct link to file') . "'>";
		echo wp_upload_display( array(171, 128) );
		if ( isset($attachment_data['width']) && 'inline' != $style )
			echo '</a>'; ?>
	</div>
<?php	endif; ?>
		<table><col /><col class="widefat" />
<?php	if ( $id ): ?>
			<tr>
				<th scope="row"><label for="url"><?php _e('URL'); ?></label></th>
				<td><input type="text" id="url" class="readonly" value="<?php echo wp_get_attachment_url(); ?>" readonly="readonly" /></td>
			</tr>
<?php	else : ?>
			<tr>
				<th scope="row"><label for="upload"><?php _e('File'); ?></label></th>
				<td><input type="file" id="upload" name="image" /></td>
			</tr>
<?php	endif; ?>
			<tr>
				<th scope="row"><label for="post_title"><?php _e('Title'); ?></label></th>
				<td><input type="text" id="post_title" name="post_title" value="<?php echo $attachment->post_title; ?>" /></td>
			</tr>
			<tr>
				<th scope="row"><label for="post_content"><?php _e('Description'); ?></label></th>
				<td><textarea name="post_content" id="post_content"><?php echo $attachment->post_content; ?></textarea></td>
			</tr>
			<tr id="buttons" class="submit">
				<td colspan='2'>
<?php	if ( $id ) : ?>
					<input type="submit" name="delete" id="delete" class="delete alignleft" value="<?php _e('Delete File'); ?>" />
<?php	endif; ?>
					<input type="hidden" name="from_tab" value="<?php echo $tab; ?>" />
					<input type="hidden" name="action" value="<?php echo $id ? 'save' : 'upload'; ?>" />
<?php	if ( $post_id ) : ?>
					<input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
<?php	endif; if ( $id ) : ?>
					<input type="hidden" name="ID" value="<?php echo $id; ?>" />
<?php	endif; ?>
					<?php wp_nonce_field( 'inlineuploading' ); ?>
					<div class="submit">
						<input type="submit" value="<?php $id ? _e('Save') : _e('Upload'); ?> &raquo;" />
					</div>
				</td>
			</tr>
		</table>
	</form>
<?php
}
Beispiel #5
0
         if (isset($post_type_object) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true) {
             $parent_file = $post_type_object->show_in_menu;
         } else {
             $parent_file = "edit.php?post_type={$post_type}";
         }
         $submenu_file = "edit.php?post_type={$post_type}";
         $post_new_file = "post-new.php?post_type={$post_type}";
     }
     if ($last = wp_check_post_lock($post->ID)) {
         add_action('admin_notices', '_admin_notice_post_locked');
     } else {
         wp_set_post_lock($post->ID);
         wp_enqueue_script('autosave');
     }
     $title = $post_type_object->labels->edit_item;
     $post = get_post_to_edit($post_id);
     if (post_type_supports($post_type, 'comments')) {
         wp_enqueue_script('admin-comments');
         enqueue_comment_hotkeys_js();
     }
     include './edit-form-advanced.php';
     break;
 case 'editattachment':
     check_admin_referer('update-attachment_' . $post_id);
     // Don't let these be changed
     unset($_POST['guid']);
     $_POST['post_type'] = 'attachment';
     // Update the thumbnail filename
     $newmeta = wp_get_attachment_metadata($post_id, true);
     $newmeta['thumb'] = $_POST['thumb'];
     wp_update_attachment_metadata($post_id, $newmeta);
 private function get_post($post_ID)
 {
     $post = get_post_to_edit($post_ID);
     if (empty($post->ID)) {
         $this->base->ks_die(__("You attempted to edit a post that doesn't exist. Perhaps it was deleted?"));
     }
     if ('post' != $post->post_type) {
         $this->admin->redirect(get_edit_post_link($post->ID, 'url'));
         exit;
     }
     return $post;
 }
Beispiel #7
0
 function edit_products_copy_action()
 {
     $action = 'copy-product';
     if (isset($_GET['action']) && $_GET['action'] == "copy-product") {
         $sendback_href = remove_query_arg(array('_wpnonce', 'mp-action', 'post', 'trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer());
         if (isset($_GET['post'])) {
             $product_id = intval($_GET['post']);
         } else {
             wp_redirect($sendback_href);
         }
         if (isset($_GET['post_type'])) {
             $post_type = esc_attr($_GET['post_type']);
         } else {
             wp_redirect($sendback_href);
         }
         if (!isset($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], "{$action}-{$post_type}_{$product_id}")) {
             wp_redirect($sendback_href);
         }
         $product = (array) get_post_to_edit($product_id);
         $product['ID'] = 0;
         // Zero out the Product ID to force insert of new item
         $product['post_status'] = 'draft';
         $product['post_author'] = get_current_user_id();
         $new_product_id = wp_insert_post($product);
         if ($new_product_id && !is_wp_error(${$new_product_id})) {
             //If we have the a valid new product ID we copy the product meta...
             $product_meta_keys = get_post_custom_keys($product_id);
             if (!empty($product_meta_keys)) {
                 foreach ($product_meta_keys as $meta_key) {
                     $meta_values = get_post_custom_values($meta_key, $product_id);
                     foreach ($meta_values as $meta_value) {
                         $meta_value = maybe_unserialize($meta_value);
                         add_post_meta($new_product_id, $meta_key, $meta_value);
                     }
                 }
             }
             // ... thne we copy the product taxonomy terms
             $product_taxonomies = get_object_taxonomies($post_type);
             if (!empty($product_taxonomies)) {
                 foreach ($product_taxonomies as $product_taxonomy) {
                     $product_terms = wp_get_object_terms($product_id, $product_taxonomy, array('orderby' => 'term_order'));
                     if ($product_terms && count($product_terms)) {
                         $terms = array();
                         foreach ($product_terms as $product_term) {
                             $terms[] = $product_term->slug;
                         }
                     }
                     wp_set_object_terms($new_product_id, $terms, $product_taxonomy);
                 }
             }
         }
     }
     wp_redirect($sendback_href);
     die;
 }