Created
June 9, 2014 15:37
-
-
Save kellenmace/222069b1fd99b06799db to your computer and use it in GitHub Desktop.
OOP Settigns Page Full
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 | |
/** | |
* Facebook Conversion Pixel Options | |
* @version 1.0 | |
*/ | |
class Fb_Pxl_Admin { | |
/** | |
* Option key, and option page slug | |
* @var string | |
*/ | |
protected static $key = 'fb_pxl_options'; | |
/** | |
* Array of metaboxes/fields | |
* @var array | |
*/ | |
protected static $fb_pxl_options = array( 'posts' => '' ); | |
/** | |
* Options Page title | |
* @var string | |
*/ | |
protected $title = ''; | |
/** | |
* Constructor | |
* @since 0.1.0 | |
*/ | |
public function __construct() { | |
// Set our title | |
$this->title = __( 'Facebook Conversion Pixel', 'myprefix' ); | |
} | |
/** | |
* Initiate our hooks | |
* @since 0.1.0 | |
*/ | |
public function hooks() { | |
add_action( 'admin_init', array( $this, 'init' ) ); | |
add_action( 'admin_menu', array( $this, 'add_options_page' ) ); | |
} | |
/** | |
* Register setting to WP | |
* @since 0.1.0 | |
*/ | |
public function init() { | |
register_setting( self::$key, self::$key ); | |
} | |
/** | |
* Add menu options page | |
* @since 0.1.0 | |
*/ | |
public function add_options_page() { | |
$this->options_page = add_options_page( $this->title, $this->title, 'manage_options', self::$key, array( $this, 'admin_page_display' ) ); | |
} | |
/** | |
* Admin page markup | |
* @since 0.1.0 | |
*/ | |
public function admin_page_display() { | |
self::admin_page_setup(); | |
?> | |
<div class="wrap cmb_options_page <?php echo self::$key; ?>"> | |
<h2><?php echo esc_html( get_admin_page_title() ) . ' Settings'; ?></h2> | |
<form method="post" action="options.php"> | |
<?php settings_fields( self::$key ); ?> | |
<?php do_settings_sections( self::$key ); ?> | |
<?php submit_button(); ?> | |
</form> | |
</div> | |
<?php | |
} | |
/** | |
* Defines the plugin option page sections and fields | |
* @since 0.1.0 | |
* @return array | |
*/ | |
public static function admin_page_setup() { | |
add_settings_section( | |
'fb_pxl_display_on', | |
'Display Facebook Conversion Pixel fields on:', | |
'', | |
self::$key | |
); | |
add_settings_field( | |
'fb_pxl_display_on_posts', | |
'Posts', | |
array( $this, 'fb_pxl_display_on_posts_output' ), | |
self::$key, | |
'fb_pxl_display_on' | |
); | |
} | |
public static function fb_pxl_display_on_posts_output() { | |
$value = isset( self::$fb_pxl_options[ 'posts' ] ) ? | |
$options[ 'test_value' ] : ''; | |
$html = '<input type="checkbox" id="fb_pxl_disable_posts" name="self::$fb_pxl_options[posts]" value="on"' . checked($value, "on", false) . '/>'; | |
echo $html; | |
} | |
/** | |
* Make public the protected $key variable. | |
* @since 0.1.0 | |
* @return string Option key | |
*/ | |
public static function key() { | |
return self::$key; | |
} | |
} | |
function fb_pxl_display_on_posts_output( $args ) { | |
$value = isset( self::$fb_pxl_options[ 'posts' ] ) ? | |
$options[ 'ypi_disable_pages' ] : ''; | |
$html = '<input type="checkbox" id="fb_pxl_disable_posts" name="self::$fb_pxl_options[posts]" value="on"' . checked($value, "on", false) . '/>'; | |
echo $html; | |
} | |
// Get the party started | |
$Fb_Pxl_Admin = new Fb_Pxl_Admin(); | |
$Fb_Pxl_Admin->hooks(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment