Created
June 4, 2022 08:41
-
-
Save wolfcoder/49e387ddf94551e0d46ded4829f49cb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| Plugin Name: Rentalist | |
| Description: Create a plugin with sub menu and script.js jquery included with ajax admin | |
| */ | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; | |
| } | |
| // plugin definitions | |
| define( 'RENTALIST_URL', plugin_dir_url( __FILE__ ) ); | |
| define( 'RENTALIST_DIR', WP_PLUGIN_DIR . '/rentalist' ); | |
| class Rentalist { | |
| function __construct() { | |
| $this->rentalist_setting = 'rentalist_settings'; | |
| $this->rentalist_sync = 'rentalist_sync'; | |
| add_action( 'admin_menu', array( $this, 'rentalist_add_menu' ) ); | |
| add_action( 'admin_enqueue_scripts', array( $this, 'rentalist_enqueue_scripts' ) ); | |
| } | |
| function rentalist_add_menu(): void { | |
| $rentalist_main_page_slug = $this->rentalist_sync; | |
| add_menu_page( "Rentalist", "Rentalist", "manage_options", $rentalist_main_page_slug, array( | |
| $this, | |
| 'rentalist_sync' | |
| ), 'dashicons-smiley', 7 ); | |
| add_submenu_page( $rentalist_main_page_slug, "Sync / Import", "Sync / Import", "manage_options", $this->rentalist_sync, array( | |
| $this, | |
| "rentalist_sync" | |
| ), 7 ); | |
| add_submenu_page( $rentalist_main_page_slug, "Setting", "Setting", "manage_options", $this->rentalist_setting, array( | |
| $this, | |
| "rentalist_setting" | |
| ), 7 ); | |
| } | |
| function rentalist_enqueue_scripts() { | |
| if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], [ | |
| $this->rentalist_setting, | |
| $this->rentalist_sync | |
| ] ) ) { | |
| wp_enqueue_script( 'rentalist_admin_js', RENTALIST_URL . 'js/rentalist.js', 'jQuery', 1, true ); | |
| wp_localize_script( 'rentalist_admin_js', 'rentalist_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); | |
| } | |
| } | |
| function rentalist_sync() { | |
| echo "<div class='wrap'>rentalist_sync</div>"; | |
| } | |
| function rentalist_setting() { | |
| global $rt_settings; | |
| $rt_settings->rt_display_settings(); | |
| } | |
| } | |
| //global $rentalist; | |
| $rentalist = new Rentalist(); | |
| include_once( RENTALIST_DIR . "/includes/rt_settings.class.php" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment