I am building my first oop based plugin.This main problem is that it is not showing settings field(font error input).So far my approach..
$plugin_settings = new WordPress_Plugin_Template_Settings( __FILE__ );
The class is
class WordPress_Plugin_Template_Settings {
private $dir;
private $file;
private $assets_dir;
private $assets_url;
public function __construct( $file ) {
$this->file = $file;
$this->dir = dirname( $this->file );
$this->assets_dir = trailingslashit( $this->dir ) . 'assets';
$this->assets_url = esc_url( trailingslashit( plugins_url( '/assets/', $this->file ) ) );
register_activation_hook( __FILE__,array( $this, 'ma_defaults_options' ) );
add_action( 'admin_init', array( $this, 'ma_admin_options_init' ) );
add_action( 'admin_menu', array( $this, 'add_menu_item' ) );
}
function ma_defaults_options() {
$default_options = get_option( 'ma_admin_styler' );
if( ( !is_array( $default_options ) ) ) {
$default = array(
"error_font_color" => "#ffff",
);
update_option( 'ma_admin_styler', $default );
}
}
public function add_menu_item() {
add_options_page( 'Plugin Settings', 'Plugin Settings', 'edit_theme_options', 'ma_admin_styler', array( $this, 'settings_page' ) );
}
public function ma_admin_options_init() {
register_setting( 'ma_admin_styler', 'ma_admin_styler', array( $this,'ma_admin_styler_validate' ) );
add_settings_section( 'main_section', '', array( $this,'section_text_default' ), __FILE__ );
add_settings_field( 'error_font_color', 'Error Font Color', array( $this,'ma_error_font_color' ), __FILE__, 'main_section' );
}
function section_text_default() {
}
function ma_error_font_color() {
$options = get_option( 'ma_admin_styler' );
echo "<input name='ma_admin_styler[error_font_color]' class='wp-color-picker-field' data-default-color='#ffffff' id='color'value='{$options['error_font_color']}' />";
}
function settings_page() {
echo '<div class="wrap">
<div class="icon32" id="plugin_settings-icon"><br/></div>
<h2>Plugin Settings</h2>
<form method="post" action="options.php" enctype="multipart/form-data">';
settings_fields( 'ma_admin_styler' );
do_settings_sections( 'ma_admin_styler' );
echo '<p class="submit">
<input name="Submit" type="submit" class="button-primary" value="' . esc_attr( __( 'Save Settings', 'plugin_textdomain' ) ) . '" />
</p>
</form>
</div>';
}
}
I think I have error in
add_settings_field('error_font_color', 'Error Font Color', array( $this,'ma_error_font_color'), __FILE__, 'main_section');