Created
March 22, 2014 21:19
-
-
Save skeltoac/9714526 to your computer and use it in GitHub Desktop.
This file contains 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 | |
class some_plugin_admin { | |
public static function plugins_loaded() { | |
add_action( 'admin_init', 'some_plugin_admin::admin_init' ); | |
add_action( 'admin_menu', 'some_plugin_admin::admin_menu' ); | |
} | |
public static function admin_init() { | |
register_setting( 'some_plugin', 'some_plugin_options' ); | |
add_settings_section( 'some_plugin_general', __( 'General', 'some_plugin' ), 'some_plugin_admin::render_general', 'some_plugin' ); | |
add_settings_field( 'some_plugin_number', __( 'Footer Number', 'some_plugin' ), 'some_plugin_admin::render_number', 'some_plugin', 'some_plugin_general' ); | |
} | |
public static function admin_menu() { | |
add_options_page( __( 'Some Plugin', 'some_plugin' ), __( 'Some Plugin!', 'some_plugin' ), 'publish_posts', 'some_plugin', 'some_plugin_admin::render' ); | |
} | |
public static function render() { | |
?> | |
<div class="wrap" id="some-plugin-admin"> | |
<h2><?php _e('Some Plugin', 'some_plugin'); ?></h2> | |
<form action="options.php" method="POST"> | |
<?php settings_fields('some_plugin'); ?> | |
<?php do_settings_sections('some_plugin'); ?> | |
<?php submit_button(); ?> | |
</form> | |
</div> | |
<?php | |
} | |
public static function render_general() { | |
?> | |
<p><?php _e( 'Configure Some Plugin.', 'some_plugin' ); ?></p> | |
<?php | |
} | |
public static function render_number() { | |
?> | |
<input id="some_plugin_number" name="some_plugin_options[number]" type="number" value="<?php echo esc_attr( some_plugin_options::get( 'number', 1 ) ); ?>" /> | |
<?php | |
} | |
} |
This file contains 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 | |
class some_plugin_options { | |
private static $options; | |
private static function load() { | |
if ( ! isset( self::$options ) ) | |
self::$options = get_option( 'some_plugin_options' ); | |
if ( ! is_array( self::$options ) ) | |
self::$options = array(); | |
} | |
public static function save() { | |
update_option( 'some_plugin_options', self::$options ); | |
} | |
public static function get( $name, $default ) { | |
self::load(); | |
if ( self::has( $name ) ) | |
return self::$options[$name]; | |
return $default; | |
} | |
public static function has( $name ) { | |
self::load(); | |
return isset( self::$options[$name] ); | |
} | |
public static function set( $name, $value ) { | |
self::load(); | |
self::$options[$name] = $value; | |
self::save(); | |
} | |
public static function delete( $name ) { | |
self::load(); | |
unset( self::$options[$name] ); | |
self::save(); | |
} | |
} |
This file contains 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: Some Plugin | |
*/ | |
if ( function_exists( 'add_action' ) ) | |
add_action( 'plugins_loaded', 'some_plugin::plugins_loaded' ); | |
class some_plugin { | |
public static function load_classes() { | |
$path = dirname( __FILE__ ) . '/'; | |
require( $path . 'some-plugin-admin.php' ); | |
require( $path . 'some-plugin-footer.php' ); | |
require( $path . 'some-plugin-options.php' ); | |
} | |
public static function plugins_loaded() { | |
some_plugin_admin::plugins_loaded(); | |
some_plugin_footer::plugins_loaded(); | |
} | |
} | |
some_plugin::load_classes(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment