Skip to content

Commit

Permalink
Merge pull request #533 from katzwebservices/issue/532-user-registration
Browse files Browse the repository at this point in the history
Issue/532 user registration
  • Loading branch information
zackkatz committed Sep 30, 2015
2 parents fb86dc9 + 9d810f3 commit 1466128
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 20 deletions.
7 changes: 7 additions & 0 deletions includes/class-gv-license-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class GV_License_Handler {

const version = GravityView_Plugin::version;

/**
* Post ID on gravityview.co
* @since 1.14.4
*/
const item_id = 17;

private $EDD_SL_Plugin_Updater;

/**
Expand Down Expand Up @@ -145,6 +151,7 @@ function _get_edd_settings( $action = '', $license = '' ) {
'version' => self::version,
'license' => $license_key,
'item_name' => self::name,
'item_id' => self::item_id,
'author' => self::author,
'url' => home_url(),
);
Expand Down
7 changes: 4 additions & 3 deletions includes/extensions/edit-entry/class-edit-entry-render.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ function process_save() {
$this->after_update();

/**
* Perform an action after the entry has been updated using Edit Entry
*
* @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry
* @param array $form Gravity Forms form array
* @param string $entry_id Numeric ID of the entry that was updated
*/
Expand Down Expand Up @@ -526,7 +525,9 @@ public function edit_entry_form() {
* @param string $edit_entry_title Modify the "Edit Entry" title
* @param GravityView_Edit_Entry_Render $this This object
*/
echo esc_attr( apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ) );
$edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );

echo esc_attr( $edit_entry_title );
?></span>
</h2>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public function load() {
if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) {
add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 );

add_action( 'gform_user_updated', array( $this, 'restore_user_details' ), 10, 4 );
/**
* TODO: Should be removed once Gravity Forms allows for defining "Preserve current Display Name" option
*/
add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 );
}
}

Expand Down Expand Up @@ -89,17 +92,23 @@ public function update_user( $form = array(), $entry_id = 0 ) {
*/
$config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry );

$this->_user_before_update = get_userdata( $entry['created_by'] );
$is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' );

// The priority is set to 3 so that default priority (10) will still override it
add_filter( 'send_password_change_email', '__return_false', 3 );
add_filter( 'send_email_change_email', '__return_false', 3 );
// Only update if it's an update feed (not a create feed)
if( $is_update_feed ) {

// Trigger the User Registration update user method
GFUser::update_user( $entry, $form, $config );
$this->_user_before_update = get_userdata( $entry['created_by'] );

remove_filter( 'send_password_change_email', '__return_false', 3 );
remove_filter( 'send_email_change_email', '__return_false', 3 );
// The priority is set to 3 so that default priority (10) will still override it
add_filter( 'send_password_change_email', '__return_false', 3 );
add_filter( 'send_email_change_email', '__return_false', 3 );

// Trigger the User Registration update user method
GFUser::update_user( $entry, $form, $config );

remove_filter( 'send_password_change_email', '__return_false', 3 );
remove_filter( 'send_email_change_email', '__return_false', 3 );
}
}

/**
Expand All @@ -109,9 +118,28 @@ public function update_user( $form = array(), $entry_id = 0 ) {
* @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon
* @param array $config Gravity Forms User Registration Addon form feed configuration
* @param array $entry The Gravity Forms entry that was just updated
* @param string $password User password
* @return void
*/
public function restore_user_details( $user_id = 0, $config = array(), $entry = array() ) {
public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) {

/**
* @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry.
* Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed
* @since 1.14.4
* @param boolean $restore_display_name Restore Display Name? Default: true
*/
$restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true );

$is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' );

/**
* Don't restore display name: either disabled, or not an Update feed (it's a Create feed)
* @since 1.14.4
*/
if( ! $restore_display_name || ! $is_update_feed ) {
return;
}

$user_after_update = get_userdata( $user_id );

Expand All @@ -120,14 +148,8 @@ public function restore_user_details( $user_id = 0, $config = array(), $entry =
// Restore previous display_name
$restored_user->display_name = $this->_user_before_update->display_name;

// Restore previous roles
$restored_user->roles = array();
foreach( $this->_user_before_update->roles as $role ) {
$restored_user->add_role( $role );
}

// Don't have WP update the password.
unset( $restored_user->data->user_pass );
unset( $restored_user->data->user_pass, $restored_user->user_pass );

/**
* Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView
Expand All @@ -148,6 +170,7 @@ public function restore_user_details( $user_id = 0, $config = array(), $entry =
}

$this->_user_before_update = null;

unset( $updated, $restored_user, $user_after_update );
}

Expand Down
9 changes: 9 additions & 0 deletions templates/fields/checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
extract( $gravityview_view->getCurrentField() );

if( in_array( $field['type'], array( 'radio', 'checkbox' ) ) && !empty( $entry[ $field_id ] ) ) {

/**
* @filter `gravityview_field_tick` Change the output for a checkbox "check" symbol. Default is dashicons-yes icon
* @see https://developer.wordpress.org/resource/dashicons/#yes
* @param string $output HTML span with `dashicons dashicons-yes` class
* @param array $entry Gravity Forms entry array
* @param array $field GravityView field array
*/
$output = apply_filters( 'gravityview_field_tick', '<span class="dashicons dashicons-yes"></span>', $entry, $field);

} else {
$output = gravityview_get_field_value( $entry, $field_id, $display_value );
}
Expand Down

0 comments on commit 1466128

Please sign in to comment.