Last active
July 18, 2018 23:18
-
-
Save karlazz/a637ffb7830d5ea3ac4677d786f16bb2 to your computer and use it in GitHub Desktop.
Wordpress OOP starter example tidbits
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
| class MyPlugin { | |
| function __construct() { | |
| add_shortcode('ShowMsg', [$this,'ShowMsg']); | |
| //add_action( 'admin_menu', [$this,'load_starter_tab'] ); | |
| add_action( 'admin_menu', | |
| function () { | |
| add_menu_page( 'Publications Upload', 'Publications Upload', | |
| 'manage_options', 'ha_pubs_load', [$this,'load_starter']); | |
| } ); | |
| } | |
| function ShowMsg($atts) { | |
| $data = shortcode_atts(array('phn' => '', 'msg' => ''), $atts); | |
| return 'You sent '.$data['msg'] .' from '.$data['phn'] ; | |
| } | |
| /* not necessary see construct */ | |
| function make_shortcode() { | |
| add_shortcode('ShowMsg', [$this,'ShowMsg']); | |
| } | |
| /* not necessary see construct */ | |
| function add_form() { | |
| add_action( 'admin_menu', [$this,'load_starter_tab'] ); | |
| } | |
| /* see alternate usage with anonymous function*/ | |
| function load_starter_tab() { | |
| add_menu_page( 'Publications Upload', 'Publications Upload', 'manage_options', 'ha_pubs_load', [$this,'load_starter']); | |
| } | |
| function load_starter() { | |
| ?><h1>HERE YOU ARE!</h1> | |
| <?php | |
| } | |
| } | |
| new MyPlugin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment