Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ThomasKujawa
Created November 18, 2014 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ThomasKujawa/db9d0ed15ece5cbf260f to your computer and use it in GitHub Desktop.
Save ThomasKujawa/db9d0ed15ece5cbf260f to your computer and use it in GitHub Desktop.
Wordpress | Toolbox | neue Kontaktfelder
<?php
/*
Module Name: Kontaktfelder managen
Module URI: http://www.drweb.de/magazin/wordpress-autorenbox-ohne-plugin-erstellen/
Description: Manage WordPress contact fields. für die Autorenbox [Backend]
Author: "Thomas Scholz"
Author URI: http://toscho.de
*/
/* Sicherheitsabfrage */
if ( !class_exists('Toolbox') ) {
die();
}
/**
* 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
*/
$TTT_Contactfields = new TTT_Contactfields(
array (
'Twitter'
, 'Facebook'
, 'GooglePlus'
, 'Xing'
, 'Linkedin'
)
);
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment