HEX
Server: Apache/2.4.46 (Ubuntu)
System: Linux localhost 5.11.0-49-generic #55-Ubuntu SMP Wed Jan 12 17:36:34 UTC 2022 x86_64
User: root (0)
PHP: 7.4.16
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/salesforce-custom-component/wp-content/plugins/my-plugin/my-plugin.php
<?php

/**
 * Plugin Name: Custom Plugin
 * Description: This custom plugin 
 * Version: 1.0.1
 * Author: Kashyap Rohit
 * Author URI: https://www.google.com/
 **/
// if (!defined('ABSPATH')) {
//     header("Location:/my-plugin");
//     die("Can't Access");
// }
// Plugin Activation Hook
function my_plugin_activation()
{
    global $wpdb, $table_prefix;
    $wp_emp = $table_prefix . 'emp';
    $q = "CREATE TABLE IF NOT EXISTS `$wp_emp` (`ID` INT NOT NULL AUTO_INCREMENT, `name` VARCHAR(50) NOT NULL,
        `email` VARCHAR(50) NOT NULL,
        `status` BOOLEAN NOT NULL, PRIMARY KEY (`ID`)) ENGINE = MyISAM;";
    $wpdb->query($q);
    // $q = "INSERT INTO `$wp_emp` (`name`, `email`, `status`) VALUES ('Rohit', 'rohit@gmail.com', 1);";
    $data = array(
        "name" => "Rohit Kashyap",
        "email" => "kashyap@gmail.com",
        "status" => 1
    );
    $wpdb->insert($wp_emp, $data);
}

register_activation_hook(__FILE__, 'my_plugin_activation');

// Plugin Dectivation Hook
function my_plugin_deactivation()
{
    global $wpdb, $table_prefix;
    $wp_emp = $table_prefix . 'emp';
    $q = "TRUNCATE TABLE `customplugincode`.`$wp_emp`";
    $wpdb->query($q);
}
register_deactivation_hook(__FILE__, 'my_plugin_deactivation');

// Plugin ShortCode Function
function my_sc_fun()
{
    return 'function call';
}
add_shortcode('my-sc', 'my_sc_fun');
function my_plugin_page_func()
{
    echo 'Hello, Rohit Kashyap';
}

function my_plugin_subpage_func()
{
    echo 'Add New Salesforce Component';
}

function my_plugin_menu()
{
    add_menu_page('My Plugin Page', 'My Plugin Page', 'manage_options', 'my-plugin-page', 'my_plugin_page_func', '', 6);
    add_submenu_page('my-plugin-page', 'Add New Salesforce', 'Add New', 'manage_options', 'my-plugin-subpage', 'my_plugin_subpage_func');
}

add_action('admin_menu', 'my_plugin_menu');

// Create a Custom Post Type Using Custom Plugin Start Here
function custom_post_typ()
{
    $labels = array(
        'name' => "Salesforce",
        'singular_name' => 'Salesforce'
    );
    $supports = array('title', 'editor', 'thumbnail', 'comments', 'excerpt');
    $options = array(
        'labels' => $labels,
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'salesforces'),
        'show_in_rest' => true,
        'supports' => $supports,
        'taxonomies' => array('salesforce_types')
    );
    register_post_type('salesforces', $options);
}
add_action('init', 'custom_post_typ');

function register_salesforce_type()
{
    $labels = array(
        'name' => "Salesforce",
        'singular_name' => 'Salesforce'
    );
    $options = array(
        'hierarchical'        => true,
        'public'              => true,
        'show_ui'             => true,
        'show_admin_column'   => true,
        'query_var'           => true,
        'rewrite'             => array('slug' => 'salesforce-type'),
        'show_in_rest'        => true,
    );

    register_taxonomy('salesforce-type', array('salesforces'), $options);
}

add_action('init', 'register_salesforce_type');


// // show menu in sidebar after activate plugin in Admin Side
add_action('admin_menu', 'OTP_details_menu');
function OTP_details_menu()
{
    add_menu_page('OTP Details', 'OTP Details', 8, __FILE__, 'otp_list_details');
}

function otp_list_details()
{
    include('otp-details.php');
}

// Create a Custom Post Type Using Custom Plugin End Here