18 add_action(
'gform_user_registered', array( $this,
'assign_new_user_to_lead' ), 10, 4 );
30 if ( apply_filters(
'gravityview_disable_change_entry_creator',
false ) ) {
39 add_action(
'init', array( $this,
'load' ), 100 );
41 add_action(
'plugins_loaded', array( $this,
'prevent_conflicts' ) );
44 add_action(
'admin_enqueue_scripts', array( $this,
'enqueue_selectwoo_assets' ) );
45 add_filter(
'gform_noconflict_scripts', array( $this,
'register_gform_noconflict' ) );
46 add_filter(
'gform_noconflict_styles', array( $this,
'register_gform_noconflict' ) );
49 add_action(
'wp_ajax_entry_creator_get_users', array( $this,
'entry_creator_get_users' ) );
59 if ( ! class_exists(
'GFForms' ) ) {
63 if ( ! in_array( GFForms::get_page(), array(
'entry_detail_edit' ) ) ) {
68 $script_debug = ( defined(
'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ?
'' :
'.min';
71 wp_deregister_script(
'gform_selectwoo' );
72 wp_dequeue_script(
'gform_selectwoo' );
75 wp_enqueue_script(
'gravityview_selectwoo', plugins_url(
'assets/lib/selectWoo/selectWoo.full.min.js',
GRAVITYVIEW_FILE ), array(), $version );
76 wp_enqueue_style(
'gravityview_selectwoo', plugins_url(
'assets/lib/selectWoo/selectWoo.min.css',
GRAVITYVIEW_FILE ), array(), $version );
78 wp_enqueue_script(
'gravityview_entry_creator', plugins_url(
'assets/js/admin-entry-creator' . $script_debug .
'.js',
GRAVITYVIEW_FILE ), array(
'jquery',
'gravityview_selectwoo' ), $version );
81 'gravityview_entry_creator',
84 'ajaxurl' => admin_url(
'admin-ajax.php' ),
85 'action' =>
'entry_creator_get_users',
88 'search_placeholder' => esc_html__(
'Search by ID, login, email, or name.',
'gk-gravityview' ),
102 $post_var = wp_parse_args(
103 wp_unslash( $_POST ),
110 if ( ! wp_verify_nonce( $post_var[
'gv_nonce'],
'gv_entry_creator' ) ) {
114 $search_string = $post_var[
'q'];
116 if ( is_numeric( $search_string ) ) {
118 'search' => $search_string .
'*',
119 'search_columns' => array(
'ID' ),
123 'search' =>
'*' . $search_string .
'*',
124 'search_columns' => array(
'user_login',
'user_email',
'user_nicename',
'display_name' ),
130 wp_send_json( $users, 200 );
153 $assign_to_lead = apply_filters(
'gravityview_assign_new_user_to_entry',
true, $user_id, $config,
$entry );
156 if ( empty( $assign_to_lead ) ) {
161 $result = RGFormsModel::update_entry_property( (
int)
$entry[
'id'],
'created_by', (
int) $user_id,
false,
true );
163 if (
false === $result ) {
164 $status = __(
'Error',
'gk-gravityview' );
166 $note = sprintf(
'%s: Failed to assign User ID #%d as the entry creator (Last database error: "%s")', $status, $user_id, $wpdb->last_error );
168 $status = __(
'Success',
'gk-gravityview' );
169 $note = sprintf( _x(
'%s: Assigned User ID #%d as the entry creator.',
'First parameter: Success or error of the action. Second: User ID number',
'gk-gravityview' ), $status, $user_id );
172 gravityview()->log->debug(
'GravityView_Change_Entry_Creator[assign_new_user_to_lead] - {note}', array(
'note' => $note ) );
179 if ( apply_filters(
'gravityview_disable_change_entry_creator_note',
false ) ) {
196 remove_action(
"gform_entry_info",
'gravityview_change_entry_creator_form', 10 );
197 remove_action(
"gform_after_update_entry",
'gravityview_update_entry_creator', 10 );
208 if ( ! class_exists(
'GFCommon' ) ) {
213 if ( !
GVCommon::has_cap( array(
'gravityforms_edit_entries',
'gravityview_edit_entries' ) ) ) {
218 if ( empty( $_REQUEST[
'screen_mode'] ) ) {
223 add_action(
'admin_init', array( &$this,
'set_screen_mode' ) );
225 add_action(
'gform_entry_info', array( &$this,
'add_select' ), 10, 2 );
227 add_action(
"gform_after_update_entry", array( &$this,
'update_entry_creator' ), 10, 2 );
238 if (
'view' === \
GV\Utils::_POST(
'screen_mode' ) ) {
243 if ( \
GV\Utils::_GET(
'screen_mode' ) ===
'edit' ) {
244 $_POST[
"screen_mode"] =
'edit';
258 global $current_user;
263 RGFormsModel::update_lead_property( $entry_id,
'created_by',
$created_by );
269 if ( empty( $originally_created_by ) && empty(
$created_by ) ) {
274 if ( absint( $originally_created_by ) !== absint(
$created_by ) ) {
276 $user_data = get_userdata( $current_user->ID );
278 $user_format = _x(
'%s (ID #%d)',
'The name and the ID of users who initiated changes to entry ownership',
'gk-gravityview' );
280 $original_name = $created_by_name = esc_attr_x(
'No User',
'To show that the entry was unassigned from an actual user to no user.',
'gk-gravityview' );
282 if ( ! empty( $originally_created_by ) ) {
283 $originally_created_by_user_data = get_userdata( $originally_created_by );
285 $original_name = ! empty( $originally_created_by_user_data ) ?
286 sprintf( $user_format, $originally_created_by_user_data->display_name, $originally_created_by_user_data->ID ) :
287 esc_attr_x(
'Deleted User',
'To show that the entry was created by a no longer existing user.',
'gk-gravityview' );
291 $created_by_user_data = get_userdata(
$created_by );
293 $created_by_name = ! empty( $created_by_user_data ) ?
294 sprintf( $user_format, $created_by_user_data->display_name, $created_by_user_data->ID ) :
295 esc_attr_x(
'Deleted User',
'To show that the entry was created by a no longer existing user.',
'gk-gravityview' );
298 GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __(
'Changed entry creator from %s to %s',
'gk-gravityview' ), $original_name, $created_by_name ),
'note' );
313 if (
'edit' !== \
GV\Utils::_POST(
'screen_mode' ) ) {
317 $output =
'<label for="change_created_by">';
318 $output .= esc_html__(
'Change Entry Creator:',
'gk-gravityview' );
320 $output .=
'<select name="created_by" id="change_created_by" class="widefat">';
324 $entry_creator_user =
GVCommon::get_users(
'change_entry_creator', array(
'include' => $entry_creator_user_id ) );
325 $entry_creator_user = isset( $entry_creator_user[0] ) ? $entry_creator_user[0] : array();
327 $output .=
'<option value="0" ' . selected(
true, empty( $entry_creator_user_id ),
false ) .
'> — ' . esc_attr_x(
'No User',
'No user assigned to the entry',
'gk-gravityview' ) .
' — </option>';
330 if ( ! empty( $entry_creator_user_id ) && ! empty( $entry_creator_user ) ) {
331 $output .=
'<option value="' . $entry_creator_user->ID .
'" selected="selected">' . esc_attr( $entry_creator_user->display_name .
' (' . $entry_creator_user->user_nicename .
')' ) .
'</option>';
334 $all_users =
GVCommon::get_users(
'change_entry_creator', array(
'number' => self::DEFAULT_NUMBER_OF_USERS ) );
335 foreach ( $all_users as
$user ) {
336 if ( $entry_creator_user_id === $user->ID ) {
340 $output .=
'<option value="' . esc_attr( $user->ID ) .
'">' . esc_attr( $user->display_name .
' (' . $user->user_nicename .
')' ) .
'</option>';
343 $user_count = count_users();
344 $user_count = $user_count[
'total_users'];
345 $users_displayed = self::DEFAULT_NUMBER_OF_USERS + ( ! empty( $entry_creator_user ) ? 1 : 0 );
346 if ( $user_count > $users_displayed ) {
347 $remaining_users = $user_count - $users_displayed;
348 $user_users = _n( esc_html__(
'user',
'gk-gravityview' ), esc_html__(
'users',
'gk-gravityview' ), $remaining_users );
349 $message = esc_html_x(
'Use the input above to search the remaining %d %s.',
'%d is replaced with user count %s is replaced with "user" or "users"',
'gk-gravityview' );
350 $message = sprintf( $message, $remaining_users, $user_users );
351 $output .=
'<option value="_user_count" disabled="disabled">' . esc_html( $message ) .
'</option>';
355 $output .=
'<input name="originally_created_by" value="' . esc_attr(
$entry[
'created_by'] ) .
'" type="hidden" />';
356 $output .= wp_nonce_field(
'gv_entry_creator',
'gv_entry_creator_nonce',
false,
false );
369 $assets[] =
'gravityview_selectwoo';
370 $assets[] =
'gravityview_entry_creator';
const DEFAULT_NUMBER_OF_USERS
register_gform_noconflict( $assets)
Allow UI assets.
if(gravityview() ->plugin->is_GF_25()) $form
update_entry_creator( $form, $entry_id)
When the entry creator is changed, add a note to the entry.
set_screen_mode()
Allows for edit links to work with a link instead of a form (GET instead of POST) ...
static get_users( $context='change_entry_creator', $args=array())
Get WordPress users with reasonable limits set.
entry_creator_get_users()
Get users list for entry creator.
const GRAVITYVIEW_FILE
Full path to the GravityView file "GRAVITYVIEW_FILE" "./gravityview.php".
assign_new_user_to_lead( $user_id, $config, $entry=array(), $password='')
When an user is created using the User Registration add-on, assign the entry to them.
if(empty( $created_by)) $form_id
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
static add_note( $lead_id, $user_id, $user_name, $note='', $note_type='gravityview')
Alias for GFFormsModel::add_note() with default note_type of 'gravityview'.
new GravityView_Change_Entry_Creator
gravityview()
The main GravityView wrapper function.
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
add_select( $form_id, $entry)
Output select element used to change the entry creator.
prevent_conflicts()
Disable previous functionality; use this one as the canonical.
enqueue_selectwoo_assets()
Enqueue selectWoo script and style.
static _POST( $name, $default=null)
Grab a value from the _POST superglobal or default.