Couple Tools Page
How to create couple dashboard menu and page of content.
Hello everyone,
If you are developer or you wish to create custom couple tools menu + pages. you can use this code in your functions.php file and start new page.
Thank you.
<?php
/**
* WeddingDir - Couple Dashboard Page
* ----------------------------------
*/
if( ! class_exists( 'WeddingDir_Couple_Dashboard_Page' ) && class_exists( 'WeddingDir_Config' ) ){
/**
* WeddingDir - Couple Dashboard Page
* ----------------------------------
*/
class WeddingDir_Couple_Dashboard_Page extends WeddingDir_Config{
/**
* Member Variable
* ---------------
*/
private static $instance;
/**
* Initiator
* ---------
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Menu Name
* ---------
*/
public static function menu_name(){
return esc_attr__( 'Couple Menu', 'text-domain' );
}
/**
* Menu Slug
* ---------
*/
public static function menu_slug(){
return sanitize_title( 'couple-menu' );
}
/**
* Menu Icon
* ---------
*/
public static function menu_icon(){
return esc_attr( 'weddingdir-budget' );
}
/**
* Construct
* ---------
*/
public function __construct() {
/**
* Create Menu
* -----------
*/
add_filter( 'weddingdir/couple/dashboard/menu', [ $this, 'couple_menu' ], absint( '40' ), absint( '1' ) );
/**
* Create Page
* -----------
*/
add_action( 'weddingdir/couple-dashboard', [ $this, 'dashboard_page' ], absint( '40' ), absint( '1' ) );
}
/**
* Create Menu
* -----------
*/
public static function couple_menu( $args = [] ){
/**
* Menu Name
* ---------
*/
$menu_name = self:: menu_name();
/**
* Menu Slug
* ---------
*/
$menu_slug = self:: menu_slug();
/**
* Menu Icon
* ---------
*/
$menu_icon = self:: menu_icon();
/**
* Merge Menu Object
* -----------------
*/
return array_merge( $args, [ $menu_slug => [
'menu_show' => apply_filters( sprintf( 'weddingdir/couple-menu/%1$s/menu-show', $menu_slug ), true ),
'menu_class' => apply_filters( sprintf( 'weddingdir/couple-menu/%1$s/menu-class', $menu_slug ), '' ),
'menu_id' => apply_filters( sprintf( 'weddingdir/couple-menu/%1$s/menu-id', $menu_slug ), true ),
'menu_name' => apply_filters( sprintf( 'weddingdir/couple-menu/%1$s/menu-name', $menu_slug ), $menu_name ),
'menu_icon' => apply_filters( sprintf( 'weddingdir/couple-menu/%1$s/menu-icon', $menu_slug ), $menu_icon ),
'menu_active' => parent:: dashboard_page_set( $menu_slug ) ? sanitize_html_class( 'active' ) : null,
'menu_link' => apply_filters( 'weddingdir/couple-menu/page-link', esc_attr( $menu_slug ) )
] ] );
}
/**
* Create Page
* -----------
*/
public static function dashboard_page( $args = [] ){
/**
* Have Args
* ---------
*/
if( parent:: _is_array( $args ) ){
/**
* Extract
* -------
*/
extract( wp_parse_args( $args,[
'layout' => absint( '1' ),
'post_id' => '',
'page' => ''
] ) );
/**
* Make sure this page is couple dashboard page
* --------------------------------------------
*/
if( ! empty( $page ) && $page == esc_attr( self:: menu_slug() ) ){
?><div class="container"><?php
/**
* 2.1 Load Title
* --------------
*/
printf('<div class="section-title">
<div class="d-sm-flex justify-content-between align-items-center">
<h2 class="mb-xxl-0 mb-xl-0 mb-lg-0 mb-md-0 mb-sm-0 mb-3">%1$s</h2>
</div>
</div>',
/**
* 1. Title
* --------
*/
self:: menu_name()
);
?></div><?php
}
}
}
} /* class end **/
/**
* Kicking this off by calling 'get_instance()' method
* ---------------------------------------------------
*/
WeddingDir_Couple_Dashboard_Page:: get_instance();
}
After this code used in your function file you will get same layout in vendor dashboard.
Last updated