settings = array(
'path' => apply_filters('acf/helpers/get_path', __FILE__),
'dir' => plugin_dir_url( __FILE__ ),
'version' => '1.0.0'
);
$this->name = 'google_font_selector';
$this->label = __( 'Google Font Selector', 'acf-google-font-selector-field');
$this->category = __( 'Choice' , 'acf' );
$this->defaults = array(
'include_web_safe_fonts' => true,
'enqueue_font' => true,
'default_font' => 'Droid Sans',
);
parent::__construct();
add_action( 'wp_ajax_acfgfs_get_font_details', 'acfgfs_action_get_font_details' );
if( !defined( 'ACFGFS_NOENQUEUE' ) ) {
add_action( 'wp_enqueue_scripts', 'acfgfs_google_font_enqueue' );
}
}
/**
* Field Options
*
* Creates the options for the field, they are shown when the user
* creates a field in the back-end. Currently there are three fields.
*
* The Web Safe Fonts setting allows you to add regular fonts available
* in any browser to the list
*
* The Enqueue Font setting will load the fonts on the appropriate page
* when checked.
*
* The default font settings allows you to specify the font set as the
* default for the field.
*
* @param array $field The details of this field
* @author Daniel Pataki
* @since 3.0.0
*
*/
function create_options( $field ) {
$field = array_merge($this->defaults, $field);
$key = $field['name'];
?>
settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version'] );
wp_enqueue_style( 'acf-input-google_font_selector', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version'] );
}
/**
* Pre-Save Value Modification
*
* This filter is applied to the $value before it is updated in the db
*
* @param mixed $value The value which will be saved in the database
* @param int $post_id The $post_id of which the value will be saved
* @param array $field The field array holding all the field options
* @return mixed The new value
* @author Daniel Pataki
* @since 3.0.0
*
*/
function update_value( $value, $post_id, $field ) {
$new_value = array();
$new_value['font'] = $value;
if( empty( $_POST[$field['key'] . '_variants'] ) ) {
$_POST[$field['key'] . '_variants'] = acfgfs_get_font_variant_array( $new_value['font'] );
}
if( empty( $_POST[$field['key'] . '_subsets'] ) ) {
$_POST[$field['key'] . '_subsets'] = acfgfs_get_font_subset_array( $new_value['font'] );
}
$new_value['variants'] = $_POST[$field['key'] . '_variants'];
$new_value['subsets'] = $_POST[$field['key'] . '_subsets'];
return $new_value;
}
}
// create field
new acf_field_google_font_selector();
?>