Created
March 25, 2014 18:01
-
-
Save enejb/9767518 to your computer and use it in GitHub Desktop.
Example Plugin that extend the profile cct plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class My_Profile_CCT_Map extends Profile_CCT_Field { | |
var $default_options = array( | |
'type' => 'my_map', | |
'label' => 'map', | |
'description' => '', | |
'width' => 'full', | |
'before' => '', | |
'empty' => '', | |
'after' => '', | |
); | |
var $shell = array( | |
'class' => 'map', | |
); | |
/** | |
* field function. | |
* | |
* @access public | |
* @return void | |
*/ | |
function field() { | |
$this->input_text( array( | |
'field_id' => 'long', | |
'label' => 'Longitude', | |
'size' => 10, | |
) ); | |
$this->input_text( array( | |
'field_id' => 'lat', | |
'label' => 'latitude', | |
'size' => 10, | |
) ); | |
} | |
/** | |
* display function. | |
* | |
* @access public | |
* @return void | |
*/ | |
function display() { | |
// this doesn't work but hopefully you get the idea | |
echo '<input type="https://maps.googleapis.com/maps/api/staticmap?center='.$this->data['lat'].','.$this->data['long'].'&zoom=14&size=400x400&sensor=false" />'; | |
} | |
/** | |
* shell function. | |
* | |
* @access public | |
* @static | |
* @param mixed $options | |
* @param mixed $data | |
* @return void | |
*/ | |
public static function shell( $options, $data ) { | |
new My_Profile_CCT_Map( $options, $data ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: My Map Type - Profile Plugin | |
* Plugin URI: http://github.com/ubc/profile_cct | |
* Description: Adding new type to the profile plugin | |
* Version: 1.0.0 | |
* Author: Enej Bajgoric | |
* License: GPL-2.0+ | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
* Domain Path: /languages | |
* GitHub Plugin URI: https://github.com/ubc/profile_cct | |
*/ | |
/** | |
* It is important that you name your functios in this format | |
* profile_cct_TYPE_shell | |
*/ | |
function profile_cct_my_map_shell( $options, $data = null ) { | |
My_Profile_CCT_Map::shell( $options, $data ); | |
} | |
/** | |
* It is important that you name your functios in this format | |
* profile_cct_TYPE_display_shell | |
*/ | |
function profile_cct_my_map_display_shell( $options, $data=null ) { | |
My_Profile_CCT_Map::shell( $options, $data ); | |
} | |
function example_add_my_map_type( $fields ) { | |
$fields [] = array( 'type' => 'my_map' ); | |
return $fields; | |
} | |
function example_load_my_map_class(){ | |
require_once('class-example-my_map.php'); | |
} | |
add_action( 'init', 'example_load_my_map_class' ); | |
add_filter( 'profile_cct_dynamic_fields' , 'example_add_my_map_type' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks you very much for doing this for me. I haven't had time to play around with it until today. This seems to work great, however in the "Profile View" I can't see the new field anywhere amongst the "Inactive Fields" - am I missing something?
EDIT: Just to clarify, the field is available in the "Form" view, but not available in "Profile View" or "List View". Is this due to caching like @Ardnived mentioned?