<?php
/**
* Theme functions file
*
* Child theme Funtions.php
*
* @package ClassiPress
* @author AppThemes
*/
// current version
$app_theme = 'ClassiPress';
$app_abbr = 'cp';
$app_version = '3.1.9';
$app_edition = 'Ultimate Edition';
$app_stats = 'today';
// define rss feed urls
$app_rss_feed = 'http://feeds2.feedburner.com/appthemes';
$app_twitter_rss_feed = 'http://twitter.com/statuses/user_timeline/appthemes.rss';
$app_forum_rss_feed = 'http://www.appthemes.com/forum/external.php?type=RSS2';
// define the transients we use
$app_transients = array($app_abbr.'_cat_menu');
// Framework
require( dirname(__FILE__) . '/framework/load.php' );
scb_register_table( 'app_pop_daily', $app_abbr . '_ad_pop_daily' );
scb_register_table( 'app_pop_total', $app_abbr . '_ad_pop_total' );
require( dirname(__FILE__) . '/framework/includes/stats.php' );
// Theme-specific files
require( dirname(__FILE__) . '/includes/theme-functions.php' );
// display the custom fields
function at_custom_fields() {
?>
<fieldset class="at_fieldset">
<legend><?php _e('Personal Information (required)', 'appthemes'); ?></legend>
<p>
<label for="at_name"><?php _e('Name', 'appthemes'); ?></label><br/>
<input class="text" type="text" name="at_name" id="at_name" value=<?php if (isset($_POST['at_name'])) echo esc_attr($_POST['at_name']); ?>>
</p>
<p>
<input type="checkbox" name="at_age" id="at_age" value="yes" <?php echo checked( ! empty( $_POST['at_age'] ) )?> />
<label for="age"><?php _e('I\'m over 18 ', 'appthemes'); ?></label>
</p>
</fieldset>
<br/>
<fieldset class="at_fieldset">
<legend><?php _e('Additional Information', 'appthemes'); ?></legend>
<p>
<label for="at_referral"><?php _e( 'How did you find us?', 'appthemes' ); ?></label><br/>
<select name="at_referral" id="at_referral">
<option value=""></option>
<option value="Friend" <?php echo selected ( isset( $_POST['at_referral'] ) && 'Friend' == $_POST['at_referral'] ); ?> ><?php _e('Friend', 'appthemes'); ?></option>
<option value="Search Engine" <?php echo selected ( isset( $_POST['at_referral'] ) && 'Search Engine' == $_POST['at_referral'] ); ?> ><?php _e('Search Engine', 'appthemes'); ?></option>
<option value="Advertising" <?php echo selected ( isset( $_POST['at_referral'] ) && 'Advertising' == $_POST['at_referral'] ); ?> ><?php _e('Avertising', 'appthemes'); ?></option>
</select>
</p>
<p>
<label for="at_referral_id"><?php _e('Referral ID', 'appthemes'); ?></label><br/>
<input type="text" class="text" class="at_number" name="at_referral_id" id="at_referral_id" value=<?php if (isset($_POST['at_referral_id'])) echo esc_attr($_POST['at_referral_id']); ?>>
<p class="at_referral_note"><?php _e('If you have a Referral ID please insert in the field above. It will give you access to special discounts to you and the referral.', 'appthemes'); ?></p>
</p>
</fieldset>
<style type="text/css">
.at_fieldset { border: 1px solid #ccc; padding: 10px; border-radius: 5px; }
.at_referral_note { font-size: 12px; color: #ccc; }
.at_number { width: 100px }
</style>
<?php
}
// display the custom fields on registration form
add_action( 'register_form', 'at_custom_fields' );
// validate fields
function at_validate_custom_fields( $login, $email, $errors ) {
// fields to be validated
$fields = array(
'at_name' => __( 'Name', 'appthemes' ),
'at_age' => __( 'Age', 'appthemes' ),
);
// check for empty required fields an display notice
foreach ( $fields as $field => $value ) {
if ( empty( $_POST[$field] ) ) {
$errors->add('empty_fields', __('<strong>ERROR</strong>: “', 'appthemes').$value.__('” is a required field.', 'appthemes'));
}
}
// check for invalid names (letters and spaces)
if ( ! empty( $_POST['at_name'] ) && preg_match("/[^a-zA-Z ]/", $_POST['at_name']) ) {
$errors->add('invalid_name', __('<strong>ERROR</strong>: “', 'appthemes').$fields['at_name'].__('” does not contain a valid name.', 'appthemes'));
}
// additional custom fields validations here
}
// validate custom fields
add_action( 'register_post', 'at_validate_custom_fields', 10, 3 );
// register the extra fields as user metadata
function at_register_custom_fields( $user_id, $password = "", $meta = array() ) {
// custom fields
$fields = array(
'at_name',
'at_age',
'at_referral',
'at_referral_id',
);
// cleans and updates the custom fields
foreach ( $fields as $field ) {
$value = stripslashes( trim( $_POST[$field] ) ) ;
if ( ! empty( $value ) ) {
update_user_meta( $user_id, $field, $value );
}
}
}
// save the custom fields to the database as soon as the user is registered on the database
add_action( 'user_register', 'at_register_custom_fields' );
// display custom fields/values on the backend or frontend
function at_custom_fields_display( $user ) {
$user_id = $user->ID;
?>
<?php if ( is_admin() ) { ?>
<!-- // show the backend HTML -->
<h3><?php _e('Additional Information', 'appthemes'); ?></h3>
<table class="form-table">
<tr>
<th><label for="at_name"><?php _e('Name', 'appthemes'); ?></label></th>
<td>
<input class="text" type="text" name="at_name" id="at_name" value="<?php echo get_user_meta( $user_id, 'at_name', true ) ; ?>">
</td>
</tr>
<tr>
<th><label for="at_referral"><?php _e( 'How did you find us?', 'appthemes' ); ?></label></th>
<td>
<strong><?php echo get_user_meta( $user_id, 'at_referral', true ) ; ?></span>
</td>
</tr>
<tr>
<th><label for="at_referral_id"><?php _e('Referral ID', 'appthemes'); ?></label></th>
<td>
<strong><?php echo get_user_meta( $user_id, 'at_referral_id', true ) ; ?></strong>
</td>
</tr>
</table>
<?php } else { ?>
<!-- // show the frontend HTML -->
<fieldset>
<legend><?php _e('Personal Information', 'appthemes'); ?></legend>
<p>
<label for="at_name"><?php _e('Name', 'appthemes'); ?></label>
<input class="text" type="text" name="at_name" id="at_name" value="<?php echo get_user_meta( $user_id, 'at_name', true ) ; ?>">
</p>
</fieldset>
<br/>
<fieldset>
<legend><?php _e('Additional Information', 'appthemes'); ?></legend>
<p>
<label for="at_referral"><?php _e( 'How did you find us?', 'appthemes' ); ?></label>
<strong><?php echo get_user_meta( $user_id, 'at_referral', true ) ; ?></strong>
</p>
<p>
<label for="at_referral_id"><?php _e('Referral ID', 'appthemes'); ?></label>
<strong><?php echo get_user_meta( $user_id, 'at_referral_id', true ) ; ?></strong>
</p>
</fieldset>
<?php } ?>
<?php
}
// display the custom fields on the user profile page (frontend and admin)
add_action( 'show_user_profile', 'at_custom_fields_display' ); // frontend
add_action( 'edit_user_profile', 'at_custom_fields_display' ); // backend
// updates custom fields
function at_custom_fields_update( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
// updatable fields
$fields = array(
'at_name',
);
foreach ( $fields as $field ) {
$value = stripslashes( trim( $_POST[$field] ) ) ;
if ( ! empty( $value ) ) {
update_user_meta( $user_id, $field, $value );
}
}
}
// additional fields update
add_action( 'edit_user_profile_update', 'at_custom_fields_update' );
add_action( 'personal_options_update', 'at_custom_fields_update' );
There are currently 1 users browsing this thread. (0 members and 1 guests)