LLMS_Post_Model::clone_post()
Clones the Post if the post is cloneable
Contents
Return Return
(WP_Error|int|null) WP_Error, WP Post ID of the clone (new) post, or null if post is not cloneable.
Source Source
File: includes/abstracts/abstract.llms.post.model.php
public function clone_post() {
// If post type doesn't support cloning, don't proceed.
if ( ! $this->is_cloneable() ) {
return null;
}
$this->allowed_post_tags_set();
$generator = new LLMS_Generator( $this->toArray() );
$generator->set_generator( 'LifterLMS/Single' . ucwords( $this->model_post_type ) . 'Cloner' );
if ( ! $generator->is_error() ) {
$generator->generate();
}
$this->allowed_post_tags_unset();
$generated = $generator->get_generated_content();
if ( isset( $generated[ $this->db_post_type ] ) ) {
return $generated[ $this->db_post_type ][0];
}
return new WP_Error( 'generator-error', __( 'An unknown error occurred during post cloning. Please try again.', 'lifterlms' ) );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 4.7.0 | Use LLMS_Generator::get_generated_content() in favor of deprecated LLMS_Generator::get_generated_posts(). |
| 3.3.0 | Introduced. |