Last active
October 15, 2022 13:10
-
-
Save bugsysop/5b81d62ae49415df4e9c3cc657964118 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: My Plugin */ | |
include( dirname( __FILE__ ) . '/library/admin-page-framework.php' ); | |
if ( ! class_exists( 'MyPluginName_AdminPageFramework' ) ) { | |
return; | |
} | |
class MyPluginName extends MyPluginName_AdminPageFramework { | |
//... Start code here ... | |
// Create admin page | |
public function setUp() { | |
// https://wordpress.org/support/topic/is-it-possible-to-specify-user-capability-to-edit-a-plugin/ | |
// http://codex.wordpress.org/Roles_and_Capabilities | |
$this->setCapability( 'administrator' ); | |
$this->setRootMenuPage( 'Settings' ); | |
$this->addSubMenuItem( | |
array( | |
'title' => 'My plugin Options Page', | |
'menu_title' => 'My Plugin', | |
// The slug should not contain characters which cannot be used | |
// in function names such as dots and hyphens | |
'page_slug' => 'my_plugin_page', | |
) | |
); | |
// Add Sections | |
// https://admin-page-framework.michaeluno.jp/en/v3/class-AdminPageFramework_Factory_Controller.html#_addSettingField | |
$this->addSettingSections( | |
'my_plugin_page', | |
array( | |
// Dirty Hack: this is a dummy section to add an intro text | |
// See here: https://wordpress.org/support/topic/custom-html-section/ | |
'section_id' => 'global_section', | |
// 'title' => __( 'My global section', 'my_text_domain' ), | |
'content' => __( '<p><br>This is a global section with an intro text.</p>', 'my_text_domain' ), | |
), | |
array( | |
'section_id' => 'my_first_section', | |
'title' => __( 'My first section', 'my_text_domain' ), | |
'description' => __( 'My nice first section with some checkbox.', 'my_text_domain' ), | |
), | |
array( | |
'section_id' => 'my_second_section', | |
'title' => __( 'My second section', 'my_text_domain' ), | |
'description' => __( 'This is a section with more checkbox.', 'my_text_domain' ), | |
) | |
); | |
// Add Fields | |
// https://admin-page-framework.michaeluno.jp/en/v3/class-AdminPageFramework_Factory_Controller.html#_addSettingField | |
$this->addSettingFields( | |
'my_first_section', | |
array( | |
'field_id' => 'my_checkbox_1', | |
'type' => 'checkbox', | |
'title' => __( 'Checkbox 1', 'my_text_domain' ), | |
'label' => __( 'Check me.', 'my_text_domain' ), | |
'default' => false, | |
), | |
array( | |
'field_id' => 'my_checkbox_2', | |
'type' => 'checkbox', | |
'title' => __( 'Checkbox 2', 'my_text_domain' ), | |
'label' => __( 'Check me.', 'my_text_domain' ), | |
'default' => false, | |
) | |
); | |
$this->addSettingFields( | |
'my_second_section', | |
array( | |
'field_id' => 'my_checkbox_3', | |
'type' => 'checkbox', | |
'title' => __( 'Checkbox 3', 'my_text_domain' ), | |
'label' => __( 'Check me.', 'my_text_domain' ), | |
'description' => __( 'The description for the field.', 'my_text_domain' ), // More | |
'tip' => __( 'This is a Tip.', 'my_text_domain' ), // More | |
'default' => false, | |
), | |
array( | |
'field_id' => 'my_checkbox_4', | |
'type' => 'checkbox', | |
'title' => __( 'Checkbox 4', 'my_text_domain' ), | |
'label' => __( 'Check me.', 'my_text_domain' ), | |
'default' => false, | |
), | |
array( // Submit button | |
'field_id' => 'submit_button_b', | |
'type' => 'submit', | |
'show_title_column' => false, | |
'label' => __( 'Submit', 'my_text_domain' ), | |
), | |
array( // Reset button | |
'field_id' => 'submit_button_reset', | |
'title' => __( 'Reset Button', 'my_text_domain' ), | |
'type' => 'submit', | |
'reset' => true, | |
'label' => __( 'Reset', 'my_text_domain' ), | |
'show_title_column' => false, | |
'attributes' => array( | |
'class' => 'button button-secondary', | |
//'style' => 'float:right; clear:none; display: inline;', | |
), // End of Button CC Class Array | |
) | |
); | |
} // End of public function setUp() | |
/* | |
* Create content at the end of admin page | |
* Notice that the name of the method is 'do_' + the page slug: do_{page slug} | |
* So the slug should not contain characters which cannot be used in function names such as dots and hyphens | |
*/ | |
public function do_my_plugin_page() { | |
?> | |
<h4>Say Something</h4> | |
<p>This is my first admin page!</p> | |
<?php | |
} | |
// ... End of Code ... | |
} | |
new MyPluginName; | |
/* | |
if (AdminPageFramework::getOption( 'MyPluginName', 'my_checkbox_2', true ) == '1' ) { | |
remove_action( 'wp_head', 'feed_links', 2 ); | |
remove_action( 'wp_head', 'feed_links_extra', 3 ); | |
} else {} | |
*/ | |
if (AdminPageFramework::getOption( 'MyPluginName', 'my_checkbox_2', '1' )) { | |
remove_action( 'wp_head', 'feed_links', 2 ); | |
remove_action( 'wp_head', 'feed_links_extra', 3 ); | |
} else {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment