This WordPress plugin serves as a demonstration of Object-Oriented Programming (OOP) principles, offering a foundation for building modular and maintainable plugins. It provides a structured approach to creating custom post types, menus, meta boxes, taxonomies, widgets, and settings.
- Introduction
- Project Structure
- Getting Started
- Installation
- Usage
- Features
- Contributing
- Conclusion
- License
- Author
This WordPress plugin serves as a sample project to showcase the implementation of Object-Oriented Programming (OOP) principles in WordPress development. The plugin is organized into three main parts: Core, BaseClass, and Class.
- Core.php: Main class for initializing the plugin, setting up constants, and handling activation, deactivation, and asset registration.
- AutoLoad.php: Autoload class for automatic loading of other classes.
- BaseCustomPostType.php: Abstract class for creating custom post types.
- BaseMenu.php: Abstract class for creating menus in the WordPress admin.
- BaseMetaBox.php: Abstract class for creating meta boxes in the WordPress admin.
- BaseSetting.php: Abstract class providing a structure for settings.
- BaseTaxonomy.php: Abstract class for creating custom taxonomies.
- BaseWidget.php: Abstract class for creating custom dashboard widgets.
- AjaxHandler.php: Class handling AJAX requests.
- Menu_ExampleUser.php: Specific implementation of a menu for managing users.
- MetaBox_ExampleVideoUrl.php: Specific implementation of a meta box for handling video URLs in posts.
- PostType_ExampleBook.php: Specific implementation of a custom post type for books.
- Setting_ExampleGatePay.php: Example of extending the base setting class to create specific settings.
- Taxonomy_ExampleWriter.php: Specific implementation of a custom taxonomy for writers.
- Widget_ExampleInfo.php: Specific implementation of a custom dashboard widget.
- Clone the repository:
git clone https://github.com/sadeq-yaqobi/wp-oop-plugin.git
- Upload the
wp-oop-plugin
directory to the/wp-content/plugins/
directory. - Activate the plugin through the 'Plugins' menu in WordPress.
- After activating the plugin, navigate to the WordPress admin dashboard.
- Explore the provided menu, meta box, and custom post type functionalities.
- Customize and extend the plugin according to your project requirements.
-
Custom Post Type:
- Create a new class extending
BaseCustomPostType
. - Set specific values for your custom post type in the constructor.
- Create a new class extending
-
Custom Menu:
- Create a new class extending
BaseMenu
. - Set up the menu properties and define submenu items in the constructor.
- Create a new class extending
-
Custom Meta Box:
- Create a new class extending
BaseMetaBox
. - Set specific values for the meta box in the constructor.
- Create a new class extending
-
Custom Taxonomy:
- Create a new class extending
BaseTaxonomy
. - Set specific values for the taxonomy in the constructor.
- Create a new class extending
-
Custom Widget:
- Create a new class extending
BaseWidget
. - Set specific values for the widget in the constructor.
- Create a new class extending
-
Custom Setting:
- Create a new class extending
BaseSetting
. - Set specific values for the setting in the constructor.
- Create a new class extending
-
Create a new Action:
- Add an action name to the
$actions
array in theAjaxHandler
class.
- Add an action name to the
-
Define Action Logic:
- Create a function with the same name as your action in the appropriate class or trait.
-
Call AJAX in JavaScript:
- Use the
wp_ajax
orwp_ajax_nopriv
action in your JavaScript to make the AJAX request.
- Use the
- Demonstrates the use of Object-Oriented Programming in WordPress.
- Provides a structured approach to creating custom post types, menus, meta boxes, taxonomies, settings, and widgets.
- Includes examples of specific implementations for users, video URLs, books, writers, and dashboard widgets.
Contributions are welcome! Feel free to open issues or submit pull requests.
By extending the provided abstract classes and leveraging the OOP principles demonstrated in this plugin, you can create modular, maintainable, and extensible WordPress plugins with ease. Customize each component to fit your project's requirements and build powerful, organized solutions for your WordPress development.
This project is licensed under the GNU General Public License v2 or later - see the LICENSE file for details.
Sadeq Yaqobi