Skip to content

Instantly share code, notes, and snippets.

@messica
Created December 31, 2018 18:26
Show Gist options
  • Save messica/e8bced18100ecdab6d771de8f6f5e1fe to your computer and use it in GitHub Desktop.
Save messica/e8bced18100ecdab6d771de8f6f5e1fe to your computer and use it in GitHub Desktop.
Register Helper: wp_editor() Field Example
<?php
/**
* Register Helper Fields
*/
function my_pmprorh_init() {
if(!function_exists('pmprorh_add_registration_field')) return;
$fields = array();
// wp_editor() Field Example
global $current_user;
$default_text = get_user_meta($current_user->ID, 'rich_text', true);
ob_start();
wp_editor($default_text, 'rich_text', array());
$html = ob_get_contents();
ob_end_clean();
$fields[] = new PMProRH_Field('rich_text', 'html', array(
'label' => 'Rich Text Test',
'html' => $html,
'save_function' => 'my_pmprorh_save_rich_text',
'profile' => true
));
foreach($fields as $field)
pmprorh_add_registration_field('checkout_boxes', $field);
}
add_action('init', 'my_pmprorh_init');
/**
* Function for saving wp_editor() Register Helper fields
*/
function my_pmprorh_save_rich_text($user_id, $field_name, $field_value) {
$sanitized = wp_kses_post( $field_value );
update_user_meta( $user_id, $field_name, $field_value );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment