$this->addSettingFields(
* array(
* 'section_id' => '...',
* 'type' => 'github', // <--- THIS PART
* 'field_id' => '...',
* 'title' => '...',
* )
* );
*/
public $aFieldTypeSlugs = array( 'github', );
/**
* Defines the default key-values of this field type.
*
* The keys are used for the field definition array.
* $this->addSettingFields(
* array(
* 'section_id' => '...',
* 'type' => '...',
* 'field_id' => '...',
* 'my_custom_key' => '...', // <-- THIS PART
* )
* );
* @remark $_aDefaultKeys holds shared default key-values defined in the base class.
*/
protected $aDefaultKeys = array(
'user_name' => 'michaeluno',
'button_type' => 'follow', // either of the followings: follow, star, watch, fork, issue
'count' => true, // whether or not the count should be displayed
'repository' => null, // the default value is assigned in the user constructor.
'size' => null,
'attributes' => array(
'href' => null,
'data-style' => null,
'data-icon' => null,
'data-text' => null,
'data-count-href' => null,
'data-count-api' => null,
),
);
/**
* User constructor.
*
* Loaded at the end of the constructor.
*/
protected function construct() {
$this->aDefaultKeys[ 'repository' ] = 'admin' . '-page' . '-framework' ; // avoid text-domain conversion by the Generator.
}
/**
* Loads the field type necessary components.
*
* This method is triggered when a field definition array that calls this field type is parsed.
*/
protected function setUp() {
add_action( 'admin_footer', array( $this, '_replyToAddScript' ) );
}
static public $_bAddedScriptToFooter;
public function _replyToAddScript() {
if ( isset( self::$_bAddedScriptToFooter ) && self::$_bAddedScriptToFooter ) {
return;
}
self::$_bAddedScriptToFooter = true;
echo "";
}
/**
* Returns an array holding the urls of enqueuing scripts.
*
* The returning array should be composed with all numeric keys. Each element can be either a string( the url or the path of the source file) or an array of custom argument.
*
*
false.array( 'async' => '', 'data-id' => '...' )array(
* 'src' => dirname( __FILE__ ) . '/asset/github-buttons/buttons.js',
* 'handle_id' => 'github-bjs',
* 'in_footer' => true,
* 'attributes' => array(
* 'async' => '',
* 'defer' => '',
* ),
* )
*/
protected function getEnqueuingScripts() {
return array(
// array(
// 'src' => dirname( __FILE__ ) . '/asset/github-buttons/buttons.js',
// 'handle_id' => 'github-bjs',
// 'in_footer' => true,
// 'attributes' => array(
// 'async' => '',
// 'defer' => '',
// 'id' => 'github-bjs',
// ),
// ),
);
}
/**
* Returns an array holding the urls of enqueuing styles.
*
* array( 'data-id' => '...' )array(
* array(
* 'src' => dirname( __FILE__ ) . '/assets/css/main.css',
* 'handle_id' => 'custom_button_css',
* ),
* );
*/
protected function getEnqueuingStyles() {
return array(
// array(
// 'src' => dirname( __FILE__ ) . '/asset/github-buttons/assets/css/main.css',
// 'handle_id' => 'github_button_css',
// ),
);
}
/**
* Returns the field type specific JavaScript script.
*/
protected function getScripts() {
$aJSArray = json_encode( $this->aFieldTypeSlugs );
/*
* The below function will be triggered when a new repeatable field is added.
*
* Use the registerAPFCallback method to register a callback.
* Available callbacks are:
* added_repeatable_field - triggered when a repeatable field gets repeated. Parameters 1. (object) the jQuery element object. 2. (string) the field type slug. 3. (string) the field tag id.
* removed_repeatable_field - triggered when a repeatable field gets removed. Parameters 1. (object) the jQuery element object. 2. (string) the field type slug. 3. (string) the field tag id.
* sorted_fields - triggered when a sortable field gets sorted. Parameters 1. (object) the jQuery element object. 2. (string) the field type slug. 3. (string) the field tag id.
* stopped_sorting_fields - triggered when sorting fields finishes.
* */
return "" . PHP_EOL;
}
/**
* Returns IE specific CSS rules.
*/
protected function getIEStyles() { return ''; }
/**
* Returns the field type specific CSS rules.
*/
protected function getStyles() {
return "
.github-button-container {
vertical-align: middle;
display: inline-block;
margin-top: 0.2em;
}
";
}
/**
* Returns the output of the geometry custom field type.
*
*/
/**
* Returns the output of the field type.
*/
protected function getField( $aField ) {
$_aAttributes = $aField['attributes'];
$_aAttributes['class'] .= ' github github-button';
$_aAttributes = $this->uniteArrays(
$_aAttributes,
array(
'href' => $this->_getHrefByType( $aField['button_type'], $aField['user_name'], $aField['repository'] ),
'class' => $_aAttributes['class'],
'data-count-href' => $aField['count'] ? $this->_getCountHrefByType( $aField['button_type'], $aField['user_name'], $aField['repository'] ) : null,
'data-count-api' => $aField['count'] ? $this->_getCountAPIByType( $aField['button_type'], $aField['user_name'], $aField['repository'] ) : null,
'data-style' => strtolower( $aField['size'] ),
'data-icon' => $this->_getIcontByType( $aField['button_type'] ),
'data-text' => $this->_getButtonLabelByType( $aField['button_type'], $aField['user_name'], $aField['value'] ),
)
);
return
$aField['before_label']
. "