Skip to content

Components

Nabeel Molham edited this page Jun 5, 2017 · 1 revision

Inside the classes folder holds the major components I might need across projects organized in a way which is simple for me to track.

Singular Component

All components are based on these 2 classes Singular.php & Component.php which insures each component can be loaded only once to avoid multiple execution times with main plugin's class instance as property Component::$plugin

Frontend

Holds any logic/code that runs on the end-user (frontend) side of the website (ie: website.com/* excluding wp-admin), ex: shortcode render, customizing WooCommerce product page content, etc.

Backend

Holds any logic/code that runs on the admin (backend) side of the website (ie: only website.com/wp-admin), ex: registering custom post type, meta boxes, etc.

AJAX

Ajax_Handler.php holds AJAX requests handlers add_action( 'wp_ajax_*' ) automatically if a public method with same action name exists, ex: ajax request with $_REQUEST['action'] = 'register_user' it will register action callback Ajax_Handler::register_user if exists

Also it contains helper methods to send JSON response:

Method Description example
Ajax_Handler::success success json response $this->success( $user_id )
Ajax_Handler::error faild json response due to logic error(s) $this->error( new WP_Error( 'invalid_id' ) )
Ajax_Handler::debug json response with raw data for debugging $this->debug( $user_info )
Ajax_Handler::dump json response with data dump for debugging $this->dump( $page_title )

ACF Pro

ACF_Pro_Loader.php is a component for loading embedded Advanced Custom Fields plugin with registered fields json file export/import path

Clone this wiki locally