public
Created

Manager for WordPress’ contact fields

  • Download Gist
class.TTT_Contactfields.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
<?php
/**
* Manage WordPress contact fields.
* Usage:
require './class.TTT_Contactfields.php';
 
$TTT_Contactfields = new TTT_Contactfields(
array (
'Twitter'
, 'Facebook'
, 'Xing'
, 'Country'
, 'City'
, 'Latitude'
, 'Longitude'
)
);
* @author "Thomas Scholz" http://toscho.de
* @version 1.0
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
*/
class TTT_Contactfields {
public
$new_fields
, $active_fields
, $replace
;
 
/**
* @param array $fields New fields: array ('Twitter', 'Facebook')
* @param bool $replace Replace default fields?
*/
public function __construct($fields, $replace = TRUE)
{
foreach ( $fields as $field )
{
$this->new_fields[ mb_strtolower($field, 'utf-8') ] = $field;
}
 
$this->replace = (bool) $replace;
 
add_filter('user_contactmethods', array( $this, 'add_fields' ) );
}
 
/**
* Changes the contact fields.
* @param $original_fields Original WP fields
* @return array
*/
public function add_fields($original_fields)
{
if ( $this->replace )
{
$this->active_fields = $this->new_fields;
return $this->new_fields;
}
 
$this->active_fields = array_merge($original_fields, $this->new_fields);
return $this->active_fields;
}
 
/**
* Helper function for your theme
* @return array The currently active fields.
*/
public function get_active_fields()
{
return $this->active_fields;
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.