Skip Navigation

[Gelöst] Convert custom types created by 3rd party plugin without breaking plugin updates

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
Convert CPTs from LearnDash plugin under Types control.
Solution:
I don't think it is good idea to making LearnDash CPTs controlled by Types, it will conduct problems when you update LearnDash plugin
and please check the source codes of LearnDash plugin, file sfwd-lms\includes\class-ld-cpt.php, line
118~120:

$this->post_options = apply_filters( 'sfwd_cpt_options', $this->post_options, $this->post_type );
 
register_post_type( $this->post_type, $this->post_options );

There is a bulld-in feature within the plugin: "sfwd_cpt_options", you can use it to add your own options for those custom post types.
Relevant Documentation:
http://codex.wordpress.org/Function_Reference/register_post_type

This support ticket is created vor 8 Jahre, 1 Monat. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Author
Artikel
#371288

I am trying to follow advice given by Waqas in a topic found here https://toolset.com/forums/topic/3rd-part-post-type-not-showing-with-layput/ . Please provide best practice information for integrating Toolset with LearnDash.

A. I've copied the /templates folder from the LearnDash plugin to my theme (as suggested by LearnDash). I have updated each of the template files (Course, Lesson, Task, Quiz) to contain only one line: echo $content. This has removed the LearnDash generated content, so I think I am ready to continue to Step B.

B) When you are done with #A and are successfully able to remove that auto-generated output. Your layout will work just fine. However, if you would like to make it more controllable via Views and Types. You will need to bring these custom post types and fields under the Types control. Currently these are not been controlled (or even seen) by the Types, since these are private CPTs. Please see https://toolset.com/faq/how-do-i-convert-existing-custom-types-and-fields-to-types-control/ that how you can bring such CPTs under Types control, so you can build Views and Layouts with more control.

I have visited the link above and do not have enough experience to know where to begin. I also need to clearly understand any negative effects of following these instructions. Everything I do needs to be contained in my theme and must not prevent or cause issues with LearnDash updates.

At that point should I be continuing with the Woo Commerce information here: https://toolset.com/learn/create-an-ecommerce-wordpress-site/ ? I have a plugin installed that adds the course CPT to woo commerce in addition to products. Am I correct in thinking it should work in the same way (per the information for WooCommerce WooRei Shop Manager) ?

Please create a private response so that I can send you credentials for staging.learnwithus.training

Thank you!
Laurie Heer

#371636

I think it must be something like this in my child theme's functions.php (the code below is not working)

/**
 * Remove LearnDash custom post types
 */

add_action( 'init', 'unregister_learndash_cpts' );

function unregister_learndash_cpts() {
  if ( ! function_exists( 'unregister_post_type' ) ) :
     function unregister_post_type() {
         global $wp_post_types;
            if ( isset( $wp_post_types[ 'sfwd-courses' ] ) ) {
            unset( $wp_post_types[ 'sfwd-courses' ] );
            return true;
            }
      return false;
      }
  endif;

  if ( ! function_exists( 'unregister_post_type' ) ) :
     function unregister_post_type() {
         global $wp_post_types;
            if ( isset( $wp_post_types[ 'sfwd-lessons' ] ) ) {
            unset( $wp_post_types[ 'sfwd-lessons' ] );
            return true;
            }
      return false;
      }
  endif;

  if ( ! function_exists( 'unregister_post_type' ) ) :
     function unregister_post_type() {
         global $wp_post_types;
            if ( isset( $wp_post_types[ 'sfwd-quiz' ] ) ) {
            unset( $wp_post_types[ 'sfwd-quiz' ] );
            return true;
            }
      return false;
      }
  endif;

  if ( ! function_exists( 'unregister_post_type' ) ) :
     function unregister_post_type() {
         global $wp_post_types;
            if ( isset( $wp_post_types[ 'sfwd-topic' ] ) ) {
            unset( $wp_post_types[ 'sfwd-topic' ] );
            return true;
            }
      return false;
      }
  endif;
}

#371662

Dear laurie,

Since it is a compatibility problem, please fill below private detail box with a downloadable URL of the LearnDash plugin, and describe detail steps to duplicate same problem, I need test and debug it in my localhost, thanks

#372016

Thanks for the details, I am trying to test and debug in your website, will feedback if there is any found.

#372436

I still need more information to duplicate same problem:
According to the post URL you point out:
https://toolset.com/forums/topic/3rd-part-post-type-not-showing-with-layput/
It is a problem which the single post of post type "courses" can not be displayed with Layouts plugin, I tested it in my localhost with sfwd-lms + Layouts + Toolset Stater theme, it works fine, I can assign a layout to the "courses" post, and it does output the format as the layout

Could you describe detail steps to duplicate same problem?
Where do you want it to display?
How do you want it to display?
Could you point out the problem page URL in your own website? thanks

#372591

Luoy,

My problem is with understanding the instructions given by Waqas in the post, not a specific problem with my site. I have not used Toolset before and I want to make sure I understand how to use all the tools in the best way possible.

I started out with this problem: A default template is being injected for this "single-post" page. I was able to complete step A and remove the injected template. Thank you for confirming that I did this correctly and templates are now able to be used.

*** I am now trying to follow step B. ****

Waqas said:

B) When you are done with #A and are successfully able to remove that auto-generated output. Your layout will work just fine.

**** This is the part that I do not understand fully ****
However, if you would like to make it more controllable via Views and Types. You will need to bring these custom post types and fields under the Types control. Currently these are not been controlled (or even seen) by the Types, since these are private CPTs. Please see https://toolset.com/faq/how-do-i-convert-existing-custom-types-and-fields-to-types-control/ that how you can bring such CPTs under Types control, so you can build Views and Layouts with more control.
**********************************************

QUESTIONS:
1. What are the benefits of making LearnDash CPTs more controllable via Views and Types?
2. What, if any, negative impacts will making LearnDash CPTs more controllable have on future plugin (LearnDash) updates?
3. HOW do I bring the LearnDash CPTs under Types control? This article does not provide me with enough guidance to move forward. https://toolset.com/faq/how-do-i-convert-existing-custom-types-and-fields-to-types-control/
4. Provided I am able to complete step 3, which tutorial should I follow next to finish the setup of the site pages?

Thank you for your help,
Laurie

#372626

PROBLEM:
In looking at the staging site, I see that the content template has been applied to the the page called "Single Course Example Page" and everything is displayed as expected there, but I do not see content when I apply the template to the Courses post type and display the course page for "Executing Successful Projects with Microsoft Project".

#372810

Q1) What are the benefits of making LearnDash CPTs more controllable via Views and Types?
It is depends on your self, if you need the features of Types plugin when setup a new post type:
https://toolset.com/documentation/user-guides/create-a-custom-post-type/
You can control the post types with Types plugin by following our document:
https://toolset.com/faq/how-do-i-convert-existing-custom-types-and-fields-to-types-control/

Q2) What, if any, negative impacts will making LearnDash CPTs more controllable have on future plugin (LearnDash) updates?
Yes, I don't think it is good idea to making LearnDash CPTs controlled by Types, it will conduct problems when you update LearnDash plugin
and please check the source codes of LearnDash plugin, file sfwd-lms\includes\class-ld-cpt.php, line
118~120:

			$this->post_options = apply_filters( 'sfwd_cpt_options', $this->post_options, $this->post_type );

			register_post_type( $this->post_type, $this->post_options );

There is a bulld-in feature within the plugin: "sfwd_cpt_options", you can use it to add your own options for those custom post types.
More help:
http://codex.wordpress.org/Function_Reference/register_post_type

Q3) HOW do I bring the LearnDash CPTs under Types control?
As the document
https://toolset.com/faq/how-do-i-convert-existing-custom-types-and-fields-to-types-control/
Mentioned you will need to find/remove the codes which is using register_post_type function
For example, you can use a PHP editor tools(notepad++), search the string "register_post_type" in the source codes of LearnDash plugins

Then follow our documents to do the rest steps

Q4) PROBLEM
Are we talking about the problem page:
hidden link
If it is, I just make below modifications:
1) in metabox "Layout" choose option "None"
2) in metabox "Content template" choose "Content template for Courses"
Please test again, check if it is what you want

#372876

Thank you for your help and for answering all my questions.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.