Skip to content

Instantly share code, notes, and snippets.

@jazzsequence
Last active November 15, 2023 11:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jazzsequence/1a2137db8b4ee5ac08ce19e116b76359 to your computer and use it in GitHub Desktop.
Save jazzsequence/1a2137db8b4ee5ac08ce19e116b76359 to your computer and use it in GitHub Desktop.
<?php
/**
* Renders the admin page.
*/
function admin_page() {
$screen = get_current_screen();
$parent = get_admin_page_parent();
$user_meta = get_usermeta( get_current_user_id(), 'wordpress_screen_options_demo_options' );
?>
<div class="wrap <?php echo esc_attr( $parent ); ?>">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<div class="notice notice-info is-dismissable">
<p>
<?php
// Translators: %s is the URL to the GitHub repository.
echo wp_kses_post( sprintf( __( 'This is a demonstration of the Screen Options framework. More information can be found at <a href="%s">the GitHub repo</a>. Click on the Screen Options tab in the upper right hand corner of the page to test the screen options.', 'wordpress-screen-options-demo' ), 'https://github.com/jazzsequence/WordPress-Screen-Options-Framework' ) );
?>
</p>
</div> <!-- .notice -->
</div>
<div class="<?php echo esc_attr( $parent ); ?>-body">
<h2><?php esc_html_e( 'Screen option values', 'wordpress-screen-options-demo' ); ?></h2>
<div class="description">
<?php if ( $user_meta ) : ?>
<p>
<?php esc_html_e( 'Screen Options have been saved to user meta. Displaying the user settings below.', 'wordpress-screen-options-demo' ); ?>
</p>
<?php else : ?>
<p>
<?php esc_html_e( 'Screen Options have not yet been saved for this user. Displaying the default settings below.', 'wordpress-screen-options-demo' ); ?>
</p>
<?php endif; ?>
</div>
<ul class="screen-options-list">
<?php
foreach ( $this->options() as $option_name ) {
$option = "wordpress_screen_options_demo_$option_name";
if ( $user_meta ) {
$user_value = isset( $user_meta[ $option_name ] ) ? 'true' : 'false';
} else {
$user_value = var_export( $screen->get_option( $option, 'value' ), true );
}
?>
<li class="<?php echo esc_attr( $option_name ); ?>-option">
<strong><?php echo esc_html( ucwords( $option_name ) ); ?>:</strong> <code><?php echo esc_html( $user_value ); ?></code>
</li>
<?php } ?>
</ul>
</div>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment