Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate_post_get_original & duplicate_post_create_duplicate not working #283

Open
3 of 5 tasks
sebastianhodapp opened this issue Dec 20, 2022 · 2 comments
Open
3 of 5 tasks

Comments

@sebastianhodapp
Copy link

sebastianhodapp commented Dec 20, 2022

  • I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened

I'm trying to make use of the functions duplicate_post_get_original & duplicate_post_create_duplicate without success with Yoast Duplicate Post Version 4.5 and Wordpress 6.1.1. The first does not create a duplicate/return the original post. The second seems not to be defined.

duplicate_post_get_original is neither duplicating a post nor returning the original post id. Calling duplicate_post_create_duplicate leads to a fatal/uncaught error: Call to undefined function duplicate_post_create_duplicate()

To Reproduce

Step-by-step reproduction instructions

I've created the folowwing simple test code as page template. Post ID 1 is the "Hello World" Blog Post

<?
  duplicate_post_clone_post_link("Link Text","Before","After",1);
?>
<br><br>
<?
  $original_post = duplicate_post_get_original(1);
  echo "Original post: '" . $original_post->ID . "'";
?>
<br><br>
<?
  $old_post = get_post(1);
  $new_post_id = duplicate_post_create_duplicate($old_post);
  echo "New post: '" . $new_post_id . "'";
?>

Expected results

  1. A link should be created, to duplicate the blog post with ID 1
  2. The blog post with ID one should be duplicated, but ID of old blog post (ID: 1) should be echoed
  3. Another duplicate should be created. ID of created blog post (ID: 3) should be echoed.

Actual results

The actual output looks like the following.

Before
[Link Text](https://logistik.at-fire.de/wp-admin/admin.php?action=duplicate_post_new_draft&post=1&_wpnonce=63f8d20dd5)
After


Warning
: Attempt to read property "ID" on null in
/homepages/14/####/htdocs/####/wp-content/themes/asset-management/geraet-copy.php
on line
32

Original post: ''


Fatal error
: Uncaught Error: Call to undefined function duplicate_post_create_duplicate() in /homepages/14/####/htdocs/####/wp-content/themes/asset-management/geraet-copy.php:37 
Stack trace: 
#0 /homepages/14/####/htdocs/####/wp-includes/template-loader.php(106): include() 
#1 /homepages/14/####/htdocs/####/wp-blog-header.php(19): require_once('/homepages/14/d...') 
#2 /homepages/14/####/htdocs/####/index.php(17): require('/homepages/14/d...') 
#3 {main} thrown in /homepages/14/####/htdocs/####/wp-content/themes/asset-management/geraet-copy.php on line 37
  • duplicate_post_clone_post_link creates the link correctly. On pressing, the blog post gets duplicated.
  • duplicate_post_get_original obviously does not return anything / null
  • duplicate_post_create_duplicate seems to be undefined.
  • Which browser is affected (or browsers):
  • Chrome
  • Firefox
  • Safari
  • Other:

Used versions

  • PHP version: 8.0
  • WordPress version: 6.1.1
  • WordPress Theme: Own
  • Yoast Duplicate Post version: 4.1
@geominy
Copy link

geominy commented Aug 31, 2023

Got the same issue

@geominy
Copy link

geominy commented Sep 1, 2023

Hey @sebastianhodapp , I figured it out. The reason is that this function is only available from the admin area, so it's not available if you call it somewhere else.

If you put the code below in your function, it should work.

if ( ! function_exists( 'duplicate_post_create_duplicate' ) ) { require_once( plugin_dir_path( __FILE__ ) . 'path-to-plugin-folder/admin-functions.php' ); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants