Field Type Specific Arguments *
* array(
* 'field_id' => 'revealer_field_by_id',
* 'type' => 'revealer',
* 'title' => __( 'Reveal Hidden Fields', 'amazon-auto-links' ),
* 'default' => 'undefined',
* 'label' => array( // the keys represent the selector to reveal, in this case, their tag id : #fieldrow-{section id}_{field id}
* 'undefined' => __( '-- Select a Field --', 'amazon-auto-links' ),
* '#fieldrow-revealer_revealer_field_option_a' => __( 'Option A', 'amazon-auto-links' ),
* '#fieldrow-revealer_revealer_field_option_b, #fieldrow-revealer_revealer_field_option_c' => __( 'Option B and C', 'amazon-auto-links' ),
* '#fieldrow-revealer_another_revealer_field' => __( 'Another Revealer', 'amazon-auto-links' ),
* ),
* 'description' => __( 'Specify the selectors to reveal in the label argument keys in the field definition array.', 'amazon-auto-links' ),
* ),
* array(
* 'field_id' => 'revealer_field_option_a',
* 'type' => 'textarea',
* 'default' => __( 'Hi there!', 'amazon-auto-links' ),
* 'hidden' => true,
* ),
* array(
* 'field_id' => 'revealer_field_option_b',
* 'type' => 'password',
* 'description' => __( 'Type a password.', 'amazon-auto-links' ),
* 'hidden' => true,
* ),
* array(
* 'field_id' => 'revealer_field_option_c',
* 'type' => 'text',
* 'description' => __( 'Type text.', 'amazon-auto-links' ),
* 'hidden' => true,
* ),
* array(
* 'field_id' => 'another_revealer_field',
* 'type' => 'revealer',
* 'select_type' => 'radio',
* 'title' => __( 'Another Hidden Field', 'amazon-auto-links' ),
* 'label' => array( // the keys represent the selector to reveal, in this case, their tag id : #fieldrow-{field id}
* '.revealer_field_option_d' => __( 'Option D', 'amazon-auto-links' ),
* '.revealer_field_option_e' => __( 'Option E', 'amazon-auto-links' ),
* '.revealer_field_option_f' => __( 'Option F', 'amazon-auto-links' ),
* ),
* 'hidden' => true,
* 'default' => '.revealer_field_option_e',
* 'delimiter' => '
',
* // Sub-fields
* array(
* 'type' => 'textarea',
* 'class' => array(
* 'field' => 'revealer_field_option_d',
* ),
* 'label' => '',
* 'default' => '',
* 'delimiter' => '',
* ),
* array(
* 'type' => 'radio',
* 'label' => array(
* 'a' => __( 'A', 'amazon-auto-links' ),
* 'b' => __( 'B', 'amazon-auto-links' ),
* 'c' => __( 'C', 'amazon-auto-links' ),
* ),
* 'default' => 'a',
* 'class' => array(
* 'field' => 'revealer_field_option_e',
* ),
* 'delimiter' => '',
* ),
* array(
* 'type' => 'select',
* 'label' => array(
* 'i' => __( 'i', 'amazon-auto-links' ),
* 'ii' => __( 'ii', 'amazon-auto-links' ),
* 'iii' => __( 'iii', 'amazon-auto-links' ),
* ),
* 'default' => 'ii',
* 'class' => array(
* 'field' => 'revealer_field_option_f',
* ),
* 'delimiter' => '',
* ),
*
* ),
*
*
* @since 1.0.0
* @package AmazonAutoLinks_AdminPageFrameworkFieldTypePack
* @subpackage CustomFieldType
* @version 1.0.4
*/
class AmazonAutoLinks_RevealerCustomFieldType extends AmazonAutoLinks_AdminPageFramework_FieldType {
/**
* Defines the field type slugs used for this field type.
*/
public $aFieldTypeSlugs = array( 'revealer', );
/**
* Defines the default key-values of this field type.
*
* @remark $_aDefaultKeys holds shared default key-values defined in the base class.
*/
protected $aDefaultKeys = array(
'select_type' => 'select', // accepts 'radio', 'checkbox'
'is_multiple' => false,
'selectors' => array(),
'attributes' => array(
'select' => array(
'size' => 1,
'autofocusNew' => null,
'multiple' => null, // set 'multiple' for multiple selections. If 'is_multiple' is set, it takes the precedence.
'required' => null,
),
'optgroup' => array(),
'option' => array(),
),
);
/**
* Indicates whether the JavaScirpt script is inserted or not.
*/
private static $_bIsLoaded = false;
/**
* Loads the field type necessary components.
*/
protected function setUp() {
if ( ! self::$_bIsLoaded ) {
wp_enqueue_script( 'jquery' );
self::$_bIsLoaded = add_action( 'admin_print_footer_scripts', array( $this, '_replyToAddRevealerjQueryPlugin' ) );
}
$this->_checkFrameworkVersion();
}
/**
* @return void
*/
private function _checkFrameworkVersion() {
// Requires Admin Page Framework 3.7.1+
if (
method_exists( $this, 'getFrameworkVersion' )
&& version_compare( '3.7.1', $this->_getSuffixRemoved( $this->getFrameworkVersion(), '.dev' ), '<=' )
) {
return;
}
trigger_error(
$this->getFrameworkName() . ': '
. sprintf(
__( 'This revealer field type version requires Admin Page Framework %1$s to function properly.', 'amazon-auto-links' )
. ' ' . __( 'You are using the framework version %2$s.', 'amazon-auto-links' ),
'3.7.1',
$this->getFrameworkVersion()
),
E_USER_WARNING
);
}
/**
* @return string
*/
private function _getSuffixRemoved( $sString, $sSuffix ) {
$_iLength = strlen( $sSuffix );
if ( substr( $sString, $_iLength * -1 ) !== $sSuffix ) {
return $sString;
}
return substr( $sString, 0, $_iLength * - 1 );
}
/**
* Returns an array holding the urls of enqueuing scripts.
*/
protected function getEnqueuingScripts() {
return array(
// array( 'src' => dirname( __FILE__ ) . '/js/jquery.knob.js', 'dependencies' => array( 'jquery' ) ),
);
}
/**
* Returns an array holding the urls of enqueuing styles.
*/
protected function getEnqueuingStyles() {
return array();
}
/**
* Returns the field type specific JavaScript script.
*/
protected function getScripts() {
$_aJSArray = json_encode( $this->aFieldTypeSlugs );
$_sDoubleQuote = '\"';
return <<