How do i create a fluentcrm custom plugin on wordpress that allows for me to have two user roles; the super admin and the company/client

The roles should allow for creation of companies with contacts that can be linked to them, contacts and email campaigns as well as managing the contacts, campaigns and automation of e-mails. Meanwhile, users that log in with a company/client user role should be able create their own contacts on the wordpress dashboard that will be only related to their own companies without being able to access the contacts of other companies. I have added some of these functionalities to some extent but I am having issues creating my contacts with their details when logged in as a company/client user role on the company/client dashboard.

I have tried adding the necessary functionalities and capabilities for each roles while making them have their own access to their respective dashboard. You can see the code below

<?php
/*
Plugin Name: Custom Fluent CRM
Description: A custom CRM plugin for managing companies, campaigns, and contacts.
Version: 1.0
Author: Kaytech
*/

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

// Plugin Initialization
function custom_fluent_crm_init() {
    Super_Admin::init();
    Company_Client::init();
    Company_Management::init();
    Contact_Lists::init();
    Campaigns::init();
    Surveys::init();
    Reports::init();
}
add_action('plugins_loaded', 'custom_fluent_crm_init');

// Allow custom roles access to the dashboard
function custom_fluent_crm_allow_dashboard_access() {
    if (current_user_can('super_admin') || current_user_can('company_client')) {
        show_admin_bar(true);
    }
}
add_action('init', 'custom_fluent_crm_allow_dashboard_access');

// Create necessary database tables
function create_plugin_tables() {
    global $wpdb;
    $charset_collate = $wpdb->get_charset_collate();

    $company_table = $wpdb->prefix . 'custom_fluent_crm_companies';
    $sql = "CREATE TABLE $company_table (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        name tinytext NOT NULL,
        company_id tinytext NOT NULL,
        logo text,
        phone tinytext,
        PRIMARY KEY  (id)
    ) $charset_collate;";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta($sql);
}
register_activation_hook(__FILE__, 'create_plugin_tables');

// Super Admin Class
class Super_Admin {
    public static function init() {
        add_action('admin_init', array(__CLASS__, 'add_roles'));
        add_action('admin_menu', array(__CLASS__, 'add_menu_pages'));
    }

    public static function add_roles() {
        add_role(
            'super_admin',
            'Super Admin',
            array(
                'read' => true,
                'manage_options' => true,
                'create_companies' => true,
                'assign_plans' => true,
                'view_reports' => true,
                'manage_users' => true,
            )
        );

        add_role(
            'company_client',
            'Company Client',
            array(
                'read' => true,
                'manage_contact_lists' => true,
                'view_campaigns' => true,
                'view_reports' => true,
            )
        );
    }

    public static function add_menu_pages() {
        add_menu_page(
            'Super Admin Dashboard',
            'Super Admin',
            'manage_options',
            'super_admin_dashboard',
            array(__CLASS__, 'dashboard_page'),
            'dashicons-admin-users',
            2
        );

        add_submenu_page(
            'super_admin_dashboard',
            'Manage Companies',
            'Manage Companies',
            'manage_options',
            'manage_companies',
            array('Company_Management', 'manage_companies_page')
        );

        add_submenu_page(
            'super_admin_dashboard',
            'Manage Campaigns',
            'Manage Campaigns',
            'manage_options',
            'manage_campaigns',
            array('Campaigns', 'manage_campaigns_page')
        );

        add_submenu_page(
            'super_admin_dashboard',
            'Manage Surveys',
            'Manage Surveys',
            'manage_options',
            'manage_surveys',
            array('Surveys', 'manage_surveys_page')
        );

        add_submenu_page(
            'super_admin_dashboard',
            'View Reports',
            'View Reports',
            'view_reports',
            'view_reports',
            array('Reports', 'view_reports_page')
        );
    }

    public static function dashboard_page() {
        echo '<h1>Super Admin Dashboard</h1>';
    }
}

// Company Client Class
class Company_Client {
    public static function init() {
        add_action('admin_menu', array(__CLASS__, 'add_menu_pages'));
    }

    public static function add_menu_pages() {
        add_menu_page(
            'Company Dashboard',
            'Company',
            'manage_contact_lists',
            'company_dashboard',
            array(__CLASS__, 'dashboard_page'),
            'dashicons-building',
            3
        );

        add_submenu_page(
            'company_dashboard',
            'Contact Lists',
            'Contact Lists',
            'manage_contact_lists',
            'contact_lists',
            array('Contact_Lists', 'contact_lists_page')
        );

        add_submenu_page(
            'company_dashboard',
            'View Campaigns',
            'View Campaigns',
            'view_campaigns',
            'view_campaigns',
            array('Campaigns', 'view_campaigns_page')
        );

        add_submenu_page(
            'company_dashboard',
            'View Reports',
            'View Reports',
            'view_reports',
            'view_reports',
            array('Reports', 'view_reports_page')
        );
    }

    public static function dashboard_page() {
        echo '<h1>Company Dashboard</h1>';
    }
}

// Company Management Class
class Company_Management {
    public static function init() {
        add_action('admin_menu', array(__CLASS__, 'add_menu_pages'));
        add_action('admin_post_save_company', array(__CLASS__, 'save_company'));
    }

    public static function add_menu_pages() {
        add_submenu_page(
            'super_admin_dashboard',
            'Manage Companies',
            'Manage Companies',
            'manage_options',
            'manage_companies',
            array(__CLASS__, 'manage_companies_page')
        );
    }

    public static function manage_companies_page() {
        echo '<h1>Manage Companies</h1>';
        // Add form and logic for managing companies
    }

    public static function save_company() {
        check_admin_referer('save_company_nonce');
        // Save company data to the database
    }
}

// Contact Lists Class
class Contact_Lists {
    public static function init() {
        add_action('admin_menu', array(__CLASS__, 'add_menu_pages'));
    }

    public static function add_menu_pages() {
        add_submenu_page(
            'company_dashboard',
            'Contact Lists',
            'Contact Lists',
            'manage_contact_lists',
            'contact_lists',
            array(__CLASS__, 'contact_lists_page')
        );
    }

    public static function contact_lists_page() {
        echo '<h1>Contact Lists</h1>';
        // Add form and logic for managing contact lists
    }
}

// Campaigns Class
class Campaigns {
    public static function init() {
        add_action('admin_menu', array(__CLASS__, 'add_menu_pages'));
    }

    public static function add_menu_pages() {
        add_submenu_page(
            'super_admin_dashboard',
            'Manage Campaigns',
            'Manage Campaigns',
            'manage_options',
            'manage_campaigns',
            array(__CLASS__, 'manage_campaigns_page')
        );
    }

    public static function manage_campaigns_page() {
        echo '<h1>Manage Campaigns</h1>';
        // Add form and logic for managing campaigns
    }

    public static function view_campaigns_page() {
        echo '<h1>View Campaigns</h1>';
        // Add logic for viewing campaigns
    }
}

// Surveys Class
class Surveys {
    public static function init() {
        add_action('admin_menu', array(__CLASS__, 'add_menu_pages'));
    }

    public static function add_menu_pages() {
        add_submenu_page(
            'super_admin_dashboard',
            'Manage Surveys',
            'Manage Surveys',
            'manage_options',
            'manage_surveys',
            array(__CLASS__, 'manage_surveys_page')
        );
    }

    public static function manage_surveys_page() {
        echo '<h1>Manage Surveys</h1>';
        // Add form and logic for managing surveys
    }
}

// Reports Class
class Reports {
    public static function init() {
        add_action('admin_menu', array(__CLASS__, 'add_menu_pages'));
    }

    public static function add_menu_pages() {
        add_submenu_page(
            'super_admin_dashboard',
            'View Reports',
            'View Reports',
            'view_reports',
            'view_reports',
            array(__CLASS__, 'view_reports_page')
        );

        add_submenu_page(
            'company_dashboard',
            'View Reports',
            'View Reports',
            'view_reports',
            'view_reports',
            array(__CLASS__, 'view_reports_page')
        );
    }

    public static function view_reports_page() {
        echo '<h1>View Reports</h1>';
        // Add form and logic for viewing reports
    }
}
?>

New contributor

Kaytech19 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật