Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions classes/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class Admin_Color_Schemer_Plugin {

private $colors;

/**
* The data needed for the input text form.
*
* @var array
*/
private $scheme_name_input;

protected function __construct() {
self::$instance = $this;
$this->base = dirname( dirname( __FILE__ ) );
Expand All @@ -27,6 +34,12 @@ public function init() {
// Initialize translations
load_plugin_textdomain( 'admin-color-schemer', false, basename( dirname( dirname( __FILE__ ) ) ) . '/languages' );

// Set up the label name for the scheme name input form
$this->scheme_name_input = array(
'label' => __( 'Your Scheme name', 'admin-color-schemer' ),
'attribute' => 'scheme_name',
);

// Set up color arrays - need translations
$this->colors['basic'] = array(
'base_color' => __( 'Base', 'admin-color-schemer' ),
Expand Down Expand Up @@ -161,6 +174,15 @@ protected function get_color_scheme( $id = null ) {
}
}

/**
* Gets the input data necessary for the text input form.
*
* @return mixed|array
*/
public function get_scheme_input() {
return $this->scheme_name_input;
}

public function get_colors( $set = null ) {
if ( 'basic' === $set ) {
return $this->colors['basic'];
Expand Down Expand Up @@ -321,6 +343,13 @@ public function save() {
die();
}

//add the scheme name to the settings array
$scheme->name = $_post[$this->scheme_name_input['attribute']];

if ( empty ( $scheme->name) ) {
$scheme->name = 'Custom';
}

$this->set_option( 'schemes', array( $scheme->id => $scheme->to_array() ) );

// switch to the scheme
Expand Down
13 changes: 10 additions & 3 deletions templates/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
<h2><?php echo esc_html( $GLOBALS['title'] ); ?></h2>

<form method="post" action="<?php echo admin_url( 'admin-post.php' ); ?>" class="color-schemer-pickers postbox">

<input type="hidden" name="action" value="admin-color-schemer-save" />
<?php wp_nonce_field( self::NONCE ); ?>
<?php
wp_nonce_field( self::NONCE );
$admin_schemer = Admin_Color_Schemer_Plugin::get_instance();
$scheme_label = $admin_schemer->get_scheme_input(); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="<?php echo esc_attr( $scheme_label['attribute'] ); ?>"><?php echo esc_html( $scheme_label['label'] ); ?></label></th>
<td><input id="<?php echo esc_attr( $scheme_label['attribute'] ); ?>" name="<?php echo esc_attr( $scheme_label['attribute'] ); ?>" type="text" value="<?php echo esc_attr( $scheme->name ) ?>"></td>
</tr>
<?php
$admin_schemer = Admin_Color_Schemer_Plugin::get_instance();
$loops = $admin_schemer->get_colors( 'basic' );
foreach ( $loops as $handle => $nicename ): ?>

Expand Down Expand Up @@ -44,4 +51,4 @@
<?php submit_button( __( 'Preview', 'admin-color-schemer' ), 'secondary preview-scheme hide-if-no-js', 'preview', false ); ?>
</p>
</form>
</div>
</div>