admin管理员组

文章数量:1395381

In a plugin, I need to create a custom post type and the associated admin menu modifications with a class rather than procedural code. What is the basic skeleton that I need to build off of in order to do so, and how does that class get hooked into WordPress (i.e., how do I do the "add_action('init','register_my_custom_post_type'), etc. with a class)?

In a plugin, I need to create a custom post type and the associated admin menu modifications with a class rather than procedural code. What is the basic skeleton that I need to build off of in order to do so, and how does that class get hooked into WordPress (i.e., how do I do the "add_action('init','register_my_custom_post_type'), etc. with a class)?

Share Improve this question edited Oct 6, 2013 at 11:12 philosophyguy asked Oct 5, 2013 at 15:21 philosophyguyphilosophyguy 1932 silver badges8 bronze badges 2
  • This very resource: wordpress.stackexchange/… – brasofilo Commented Oct 5, 2013 at 20:03
  • Just for fun I did a quick google search »wordpress oop«. I'm not going to post links here, but I can tell you, the first page alone is very resourceful. You might want to start there, besides looking deeper into what WPSE already offers - like brasofilo suggested. Another hint would be looking for those existing wordpress plugin boilerplates/skeletons. – Nicolai Grossherr Commented Oct 6, 2013 at 11:35
Add a comment  | 

1 Answer 1

Reset to default 0

(i.e., how do I do the add_action('init','register_my_custom_post_type'), etc. with a class)?

You pass the callback from inside the class, using $this:

add_action( 'init', array( $this, 'register_my_custom_post_type' ) );

本文标签: Resources to learn OOP for WordPress pluginscustom post typesetc