Skip to content

Instantly share code, notes, and snippets.

@alexpos
Last active December 10, 2015 12:58
Show Gist options
  • Save alexpos/4437328 to your computer and use it in GitHub Desktop.
Save alexpos/4437328 to your computer and use it in GitHub Desktop.
<?php
function location_setup() {
$prefix = PREFIX;
$config = array(
'id' => 'gmap3_meta_box', // meta box id, unique per meta box
'title' => __('City Guide Map', LOCALIZATION), // meta box title
'pages' => array('location','post'), // post types, accept custom post types as well, default is array('post'); optional
'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
'priority' => 'high', // order of meta box: high (default), low; optional
'fields' => array(), // list of meta fields (can be added by field arrays)
'local_images' => false, // Use local or hosted images (meta box images for add/remove)
// 'use_with_theme' => false //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false).
'use_with_theme' => PLUGINURL .'cityGuideMetaBox/meta-box-class' //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false).
);
$my_meta = new testClass($config);
// $my_meta->addLocation($prefix.'marker',array('name'=> __('Map ',LOCALIZATION), 'std'=> array('lat' => '46.578498', 'lng' => '2.457275', 'address' => 'TODO')));
$marker_fields[] = $my_meta->addText($prefix.'mark_lat',array('name'=> __('Lattitude ', LOCALIZATION)),true);
$marker_fields[] = $my_meta->addText($prefix.'mark_lng',array('name'=> __('Longitude ', LOCALIZATION)),true);
$marker_fields[] = $my_meta->addText($prefix.'mark_txt',array('name'=> __('Text ', LOCALIZATION)),true);
$marker_fields[] = $my_meta->addImage($prefix.'mark_img',array('name'=> __('Image ', LOCALIZATION)),true);
$marker_fields[] = $my_meta->addRadioImage(
// $marker_fields[] = $my_meta->addRadio(
$prefix.'mark_icon',
array(
'1' => '<img alt="red" src="http://maps.google.com/mapfiles/marker.png">',
'2' => '<img alt="black" src="http://maps.google.com/mapfiles/marker_black.png">',
'3' => '<img alt="grey" src="http://maps.google.com/mapfiles/marker_grey.png">',
'4' => '<img alt="orange" src="http://maps.google.com/mapfiles/marker_orange.png">',
'5' => '<img alt="white" src="http://maps.google.com/mapfiles/marker_white.png">',
'6' => '<img alt="yellow" src="http://maps.google.com/mapfiles/marker_yellow.png">',
'7' => '<img alt="purple" src="http://maps.google.com/mapfiles/marker_purple.png">',
'8' => '<img alt="green" src="http://maps.google.com/mapfiles/marker_green.png">'
),
array('name'=> 'Marker Icon ', 'std'=> array('red')
),true);
$my_meta->addRepeaterBlock('re_',array('inline' => true, 'name' => __('Add a marker to the map (doesn\'t yet work)',LOCALIZATION),'fields' => $marker_fields));
$my_meta->Finish();
}
<?php
require_once("meta-box-class/my-meta-box-class.php");
if (!class_exists('testClass')) {
class testClass extends AT_Meta_Box {
/**
* Check For location field to enqueue gmap3
* @since 1.1.3??
* @access public
*/
public function check_field_radioimage(){
if ( ! $this->has_field( 'radioimage' ) )
return;
wp_enqueue_script('cityguide-metabox-js', plugins_url( '/cityGuideMetaBox/js/cityGuideMetaBox.js' , dirname(__FILE__)), array('jquery'));
}
/**
* Add RadioImage Field to meta box
* @author Alex Poslavsky
* @since 1.0?
* @access public
* @param $id string field id, i.e. the meta key
* @param $options (array) array of key => value pairs for radio options
* @param $args mixed|array
* 'name' => // field name/label string optional
* 'desc' => // field description, string optional
* 'std' => // default value, string optional
* 'validate_func' => // validate function, string optional
* @param $repeater bool is this a field inside a repeatr? true|false(default)
*/
public function addRadioImage($id,$options,$args,$repeater=false){
$new_field = array('type' => 'radioimage','id'=> $id,'std' => array(),'desc' => '','style' =>'','name' => 'Radio Field','options' => $options);
$new_field = array_merge($new_field, $args);
if(false === $repeater){
$this->_fields[] = $new_field;
}else{
return $new_field;
}
}
/**
* Show Radio Field.
*
* @param string $field
* @param string $meta
* @since 1.0??
* @access public
*/
public function show_field_radioimage( $field, $meta ) {
if ( ! is_array( $meta ) )
$meta = (array) $meta;
$this->show_field_begin( $field, $meta );
$i = 0;
foreach ( $field['options'] as $key => $value ) {
$i++;
$checked = checked( in_array( $key, $meta ), true, false ); //orig
echo "<div class='radio_image'>";
echo "<input type='radio' ".( isset($field['style'])? "style='{$field['style']}' " : '' )." class='at-radio' id='{$field['id']}{$i}' name='{$field['id']}' value='{$key}'" . $checked . " />";
// // echo "<div class='at-radio-img-label'>". $key ."</div>"; //not needed, or as an option?
$class = "at-radio-img".( isset($field['class'])? ' ' . $field['class'] : '' ).( in_array( $key, $meta )? ' at-radio-img-selected' : '' );
echo "<span class='".$class."' onClick='document.getElementById(\"{$field['id']}{$i}\").checked = true;;'>{$value}</span>";
echo "</div>";
}
$this->show_field_end( $field, $meta );
}
public function Finish() {
parent::Finish();
$this->check_field_radioimage();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment