Skip to content

Commit

Permalink
New options field: Process
Browse files Browse the repository at this point in the history
  • Loading branch information
ykadosh committed Sep 9, 2014
1 parent c937bf6 commit f061ef5
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Options/UI/Process/controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Amarkal\Options\UI;

/**
* Implements a field that is able to run a function.
*
* Usage Example:
*
* $field = new Text(array(
* 'name' => 'process_1',
* 'title' => 'Title',
* 'label' => 'My Button',
* 'disabled' => false,
* 'help' => 'Some helpful text',
* 'description' => 'This is the title',
* 'callback' => function() {}
* 'hook' => 'ao_preprocess'
* ));
*/
class Process
extends \Amarkal\Options\AbstractField
implements \Amarkal\Options\DisableableFieldInterface
{
public function __construct( $config )
{
parent::__construct( $config );

$callable = $this->config['callback'];

if( is_callable( $callable ) && isset( $_POST[$this->name] ) )
{
add_action($this->config['hook'],$callable,4);
}
}

public function default_settings()
{
return array(
'name' => '',
'title' => '',
'label' => '',
'disabled' => false,
'help' => null,
'description' => '',
'callback' => function(){},
'hook' => 'ao_init'
);
}

public function required_settings()
{
return array('name');
}

/**
* {@inheritdoc}
*/
public function is_disabled()
{
return $this->config['disabled'];
}
}
17 changes: 17 additions & 0 deletions Options/UI/Process/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.ao-field-process {
button {
font-size: 14px;
padding: 3px 9px;
border: 1px solid rgba(0,0,0,0.3);
color: #444;
text-decoration: none;
outline: none;
cursor: pointer;
@include background-image(linear-gradient($theme-color1, $theme-color2));
@include box-shadow( inset 0 -1px rgba(0,0,0,0.1), inset 0 1px rgba(255,255,255,0.5) );
@include text-shadow( 0 1px 0 rgba(255,255,255,0.3) );
@include border-radius( 5px );

&:hover {@include background-image(linear-gradient( $theme-color2, $theme-color1 ));}
}
}
6 changes: 6 additions & 0 deletions Options/UI/Process/template.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="ao-field-process">
<button
id="<?php echo $this->name; ?>"
name="<?php echo $this->name; ?>"
<?php echo ($this->disabled ? 'disabled' : ''); ?>><?php echo $this->label ?></button>
</div>

0 comments on commit f061ef5

Please sign in to comment.