Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: Test
- * Description: A test plugin.
- */
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly.
- }
- // Create custom (user) roles.
- register_activation_hook( __FILE__, function(){
- $permissions = get_role( 'editor' );
- $permissions = $permissions->capabilities;
- $permissions[ 'custom_capability' ] = 1;
- add_role( 'custom_role', __( 'Custom Role' ), $permissions );
- } );
- // Register custom admin menus.
- add_action( 'admin_menu', function(){
- add_menu_page( 'Custom Plugins',
- 'Custom Plugins',
- 'custom_capability',
- 'custom-plugins',
- 'add_custom_options_page' );
- add_submenu_page( 'custom-plugins',
- 'Custom Plugins Addon',
- 'Addon',
- 'custom_capability',
- 'custom-plugins-addon',
- 'add_custom_addon_options_page' );
- } );
- // Register custom option group.
- add_action( 'admin_init', function(){
- register_setting( 'my-group', 'test_option' );
- } );
- // Allows custom role to save options in the above group (my-group).
- add_filter( 'option_page_capability_my-group', function( $capability ){
- return 'custom_capability';
- } );
- // Render the "Custom Plugins" admin page.
- function add_custom_options_page() {
- ?>
- <div class="wrap">
- <h1>Custom Plugins</h1>
- <p>Foo bar baz, test.</p>
- </div>
- <?php
- }
- // Render the "Custom Plugins Addon" admin page.
- function add_custom_addon_options_page() {
- ?>
- <div class="wrap">
- <h1>Custom Plugins Addon</h1>
- <?php settings_errors(); ?>
- <form method="post" action="options.php">
- <p>
- <label>Text field:</label>
- <input name="test_option" value="<?php echo esc_attr( get_option( 'test_option' ) ); ?>">
- </p>
- <?php settings_fields( 'my-group' ); ?>
- <?php submit_button(); ?>
- </form>
- </div>
- <?php
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement