23 if( defined(
'DUPLICATE_POST_CURRENT_VERSION') ) {
36 add_filter(
'post_row_actions', array( $this,
'make_duplicate_link_row' ), 10, 2 );
41 add_action(
'admin_action_duplicate_view', array( $this,
'save_as_new_view' ) );
42 add_action(
'admin_action_duplicate_view_as_draft', array( $this,
'save_as_new_view_draft' ) );
45 add_action(
'gv_duplicate_view', array( $this,
'copy_view_meta_info' ), 10, 2 );
47 add_filter(
'gravityview_connected_form_links', array( $this,
'connected_form_links' ), 10, 2 );
66 $links[] =
'<span>' . $duplicate_links[
'edit_as_new_draft'] .
'</span>';
83 return $pagenow ===
'edit.php';
114 if (
$post->post_type !==
'gravityview' ) {
118 $new_view_author = wp_get_current_user();
126 $new_view_status = apply_filters(
'gravityview/duplicate-view/status', $status,
$post );
129 'menu_order' =>
$post->menu_order,
130 'comment_status' =>
$post->comment_status,
131 'ping_status' =>
$post->ping_status,
132 'post_author' => $new_view_author->ID,
133 'post_content' =>
$post->post_content,
134 'post_excerpt' =>
$post->post_excerpt,
135 'post_mime_type' =>
$post->post_mime_type,
136 'post_parent' =>
$post->post_parent,
137 'post_password' =>
$post->post_password,
138 'post_status' => ( empty( $new_view_status ) ) ?
$post->post_status : $new_view_status,
139 'post_title' =>
$post->post_title,
140 'post_type' =>
$post->post_type,
149 $copy_date = apply_filters(
'gravityview/duplicate-view/copy-date',
false,
$post );
152 $new_view[
'post_date'] = $new_post_date =
$post->post_date;
153 $new_view[
'post_date_gmt'] = get_gmt_from_date( $new_post_date );
162 $new_view = apply_filters(
'gravityview/duplicate-view/new-view', $new_view,
$post );
165 $new_view_id = wp_insert_post( $new_view );
168 if ( $new_view_status ==
'publish' || $new_view_status ==
'future' ) {
170 $view_name = wp_unique_post_slug(
$post->post_name, $new_view_id, $new_view_status,
$post->post_type,
$post->post_parent );
172 $new_view_name_array = array(
173 'ID' => $new_view_id,
174 'post_name' => $view_name,
178 wp_update_post( $new_view_name_array );
188 do_action(
'gv_duplicate_view', $new_view_id,
$post );
190 delete_post_meta( $new_view_id,
'_dp_original' );
192 add_post_meta( $new_view_id,
'_dp_original',
$post->ID,
false );
209 $post_meta_keys = get_post_custom_keys(
$post->ID );
211 if ( empty( $post_meta_keys ) ) {
215 foreach ( $post_meta_keys as $meta_key ) {
217 $meta_values = get_post_custom_values( $meta_key,
$post->ID );
219 foreach ( $meta_values as $meta_value ) {
221 $meta_value = maybe_unserialize( $meta_value );
223 add_post_meta( $new_id, $meta_key, $meta_value );
241 $clone_text = __(
'Clone',
'gk-gravityview' );
242 $clone_title = __(
'Clone this View',
'gk-gravityview' );
247 $clone_draft_text = $this->
is_all_views_page() ? __(
'New Draft',
'gk-gravityview' ) : __(
'Clone View',
'gk-gravityview' );
248 $clone_draft_title = __(
'Copy as a new draft View',
'gk-gravityview' );
250 $actions[
'edit_as_new_draft'] =
gravityview_get_link( $clone_draft_link, esc_html( $clone_draft_text ),
'title='.$clone_draft_title );
274 if ( !$view = get_post( $id ) ) {
278 $action_name = $draft ?
"duplicate_view_as_draft" :
"duplicate_view";
280 $action =
'?action=' . $action_name .
'&post=' . $view->ID;
282 if (
'display' == $context ) {
283 $action = esc_html( $action );
286 $post_type_object = get_post_type_object( $view->post_type );
289 if ( !$post_type_object ) {
290 gravityview()->log->error(
'No gravityview post type exists when trying to clone the View.', array(
'data' => $view ) );
301 $clone_view_link = apply_filters(
'gravityview/duplicate-view/get_clone_view_link', admin_url(
"admin.php". $action ), $view->ID, $context );
303 return $clone_view_link;
328 if ( ! ( isset( $_GET[
'post'] ) || isset( $_POST[
'post'] ) ) ) {
329 wp_die( __(
'No post to duplicate has been supplied!',
'gk-gravityview' ) );
333 $id = ( isset( $_GET[
'post'] ) ? $_GET[
'post'] : $_POST[
'post'] );
336 wp_die( __(
'You don\'t have permission to copy this View.',
'gk-gravityview' ) );
339 $post = get_post( $id );
346 if ( $status ==
'' ) {
348 wp_redirect( admin_url(
'edit.php?post_type=' .
$post->post_type ) );
351 wp_redirect( admin_url(
'post.php?action=edit&post=' . $new_id ) );
357 wp_die( sprintf( esc_attr__(
'Copy creation failed, could not find original View with ID #%d',
'gk-gravityview' ), $id ) );
add_hooks()
Add actions & filters.
connected_form_links( $links=array(), $form=array())
Add Duplicate View link to the Data Source metabox.
make_duplicate_link_row( $actions, $post)
Add the link to action list for post_row_actions.
gravityview_get_link( $href='', $anchor_text='', $atts=array())
Generate an HTML anchor tag with a list of supported attributes.
current_user_can_copy( $post)
Test if the user is allowed to copy Views.
save_as_new_view( $status='')
This function calls the creation of a new copy of the selected post (by default preserving the origin...
if(gravityview() ->plugin->is_GF_25()) $form
create_duplicate( $post, $status='')
Create a duplicate from a View $post.
get_clone_view_link( $id=0, $context='display', $draft=true)
Retrieve duplicate post link for post.
copy_view_meta_info( $new_id, $post)
Copy the meta information of a post to another View.
save_as_new_view_draft()
This function calls the creation of a new copy of the selected post (as a draft) then redirects to th...
gravityview()
The main GravityView wrapper function.
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
is_all_views_page()
Is the current screen the All Views screen?
new GravityView_Admin_Duplicate_View