@@ -183,7 +183,7 @@ |
||
| 183 | 183 | |
| 184 | 184 | $parent_label = ''; |
| 185 | 185 | |
| 186 | - if ( ! empty( $this->item['parent'] ) ) { |
|
| 186 | + if ( ! empty( $this->item['parent'] ) ) { |
|
| 187 | 187 | $parent_label = ' <small>(' . esc_attr( $this->item['parent']['label'] ) . ')</small>'; |
| 188 | 188 | } |
| 189 | 189 | |
@@ -62,28 +62,28 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * When on the Add/Edit View screen, suggest most popular articles related to that |
|
| 66 | - * |
|
| 65 | + * When on the Add/Edit View screen, suggest most popular articles related to that |
|
| 66 | + * |
|
| 67 | 67 | * @param array $localization_data Data to be passed to the Support Port JS |
| 68 | 68 | * |
| 69 | 69 | * @return array |
| 70 | 70 | */ |
| 71 | 71 | function suggest_support_articles( $localization_data = array() ) { |
| 72 | 72 | |
| 73 | - if( ! gravityview()->request->is_view() ) { |
|
| 74 | - return $localization_data; |
|
| 75 | - } |
|
| 73 | + if( ! gravityview()->request->is_view() ) { |
|
| 74 | + return $localization_data; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | $localization_data['suggest'] = array( |
| 78 | - '57ef23539033602e61d4a560', |
|
| 79 | - '54c67bb9e4b0512429885513', |
|
| 80 | - '54c67bb9e4b0512429885512', |
|
| 81 | - '54c67bbbe4b07997ea3f3f6b', |
|
| 82 | - '54d1a33ae4b086c0c0964ce9', |
|
| 83 | - '57ef253c9033602e61d4a563', |
|
| 84 | - '552355bfe4b0221aadf2572b', |
|
| 85 | - '54c67bcde4b051242988553e', |
|
| 86 | - ); |
|
| 78 | + '57ef23539033602e61d4a560', |
|
| 79 | + '54c67bb9e4b0512429885513', |
|
| 80 | + '54c67bb9e4b0512429885512', |
|
| 81 | + '54c67bbbe4b07997ea3f3f6b', |
|
| 82 | + '54d1a33ae4b086c0c0964ce9', |
|
| 83 | + '57ef253c9033602e61d4a563', |
|
| 84 | + '552355bfe4b0221aadf2572b', |
|
| 85 | + '54c67bcde4b051242988553e', |
|
| 86 | + ); |
|
| 87 | 87 | |
| 88 | 88 | return $localization_data; |
| 89 | 89 | } |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | if( 'form_list' === GFForms::get_page() ) { |
| 176 | 176 | $priority = 790; |
| 177 | - } |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | 179 | if( empty( $connected_views ) ) { |
| 180 | 180 | |
| 181 | - $menu_items['gravityview'] = array( |
|
| 181 | + $menu_items['gravityview'] = array( |
|
| 182 | 182 | 'label' => esc_attr__( 'Create a View', 'gravityview' ), |
| 183 | 183 | 'icon' => '<i class="fa fa-lg gv-icon-astronaut-head gv-icon"></i>', |
| 184 | 184 | 'title' => esc_attr__( 'Create a View using this form as a data source', 'gravityview' ), |
@@ -209,14 +209,14 @@ discard block |
||
| 209 | 209 | // If there were no items added, then let's create the parent menu |
| 210 | 210 | if( $sub_menu_items ) { |
| 211 | 211 | |
| 212 | - $sub_menu_items[] = array( |
|
| 213 | - 'label' => esc_attr__( 'Create a View', 'gravityview' ), |
|
| 214 | - 'link_class' => 'gv-create-view', |
|
| 215 | - 'icon' => '<i> + </i>', |
|
| 216 | - 'title' => esc_attr__( 'Create a View using this form as a data source', 'gravityview' ), |
|
| 217 | - 'url' => admin_url( 'post-new.php?post_type=gravityview&form_id=' . $id ), |
|
| 218 | - 'capabilities' => array( 'edit_gravityviews' ), |
|
| 219 | - ); |
|
| 212 | + $sub_menu_items[] = array( |
|
| 213 | + 'label' => esc_attr__( 'Create a View', 'gravityview' ), |
|
| 214 | + 'link_class' => 'gv-create-view', |
|
| 215 | + 'icon' => '<i> + </i>', |
|
| 216 | + 'title' => esc_attr__( 'Create a View using this form as a data source', 'gravityview' ), |
|
| 217 | + 'url' => admin_url( 'post-new.php?post_type=gravityview&form_id=' . $id ), |
|
| 218 | + 'capabilities' => array( 'edit_gravityviews' ), |
|
| 219 | + ); |
|
| 220 | 220 | |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -619,16 +619,16 @@ discard block |
||
| 619 | 619 | /** |
| 620 | 620 | * Render html for displaying available fields based on a Form ID |
| 621 | 621 | * |
| 622 | - * @see GravityView_Ajax::get_available_fields_html() Triggers `gravityview_render_available_fields` action |
|
| 622 | + * @see GravityView_Ajax::get_available_fields_html() Triggers `gravityview_render_available_fields` action |
|
| 623 | 623 | * |
| 624 | 624 | * @param int $form Gravity Forms Form ID (default: '') |
| 625 | 625 | * @param string $context (default: 'single') |
| 626 | - * |
|
| 626 | + * |
|
| 627 | 627 | * @return void |
| 628 | 628 | */ |
| 629 | 629 | function render_available_fields( $form = 0, $context = 'single' ) { |
| 630 | 630 | |
| 631 | - // Determine if form is a preset and convert it to an array with fields |
|
| 631 | + // Determine if form is a preset and convert it to an array with fields |
|
| 632 | 632 | $form = ( is_string( $form ) && preg_match( '/^preset_/', $form ) ) ? GravityView_Ajax::pre_get_form_fields( $form ) : $form; |
| 633 | 633 | |
| 634 | 634 | /** |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | |
| 641 | 641 | if ( ! is_array( $blacklist_field_types ) ) { |
| 642 | 642 | |
| 643 | - gravityview()->log->error( '$blacklist_field_types is not an array', array( 'data' => print_r( $blacklist_field_types, true ) ) ); |
|
| 643 | + gravityview()->log->error( '$blacklist_field_types is not an array', array( 'data' => print_r( $blacklist_field_types, true ) ) ); |
|
| 644 | 644 | |
| 645 | 645 | $blacklist_field_types = array(); |
| 646 | 646 | } |
@@ -778,12 +778,12 @@ discard block |
||
| 778 | 778 | /** |
| 779 | 779 | * @since 1.7.2 |
| 780 | 780 | */ |
| 781 | - 'other_entries' => array( |
|
| 782 | - 'label' => __('Other Entries', 'gravityview'), |
|
| 783 | - 'type' => 'other_entries', |
|
| 784 | - 'desc' => __('Display other entries created by the entry creator.', 'gravityview'), |
|
| 785 | - ), |
|
| 786 | - ); |
|
| 781 | + 'other_entries' => array( |
|
| 782 | + 'label' => __('Other Entries', 'gravityview'), |
|
| 783 | + 'type' => 'other_entries', |
|
| 784 | + 'desc' => __('Display other entries created by the entry creator.', 'gravityview'), |
|
| 785 | + ), |
|
| 786 | + ); |
|
| 787 | 787 | |
| 788 | 788 | if( 'single' !== $zone) { |
| 789 | 789 | |
@@ -955,9 +955,9 @@ discard block |
||
| 955 | 955 | |
| 956 | 956 | $joined_forms = gravityview_get_joined_forms( $post->ID ); |
| 957 | 957 | |
| 958 | - foreach ( $joined_forms as $form ) { |
|
| 959 | - $available_items[ $form->ID ] = $this->get_available_fields( $form->ID, $zone ); |
|
| 960 | - } |
|
| 958 | + foreach ( $joined_forms as $form ) { |
|
| 959 | + $available_items[ $form->ID ] = $this->get_available_fields( $form->ID, $zone ); |
|
| 960 | + } |
|
| 961 | 961 | } else { |
| 962 | 962 | $available_items[ $form ] = \GV\Widget::registered(); |
| 963 | 963 | } |
@@ -985,9 +985,9 @@ discard block |
||
| 985 | 985 | |
| 986 | 986 | if ( $form_id ) { |
| 987 | 987 | $original_item = isset( $available_items[ $form_id ] [ $field['id'] ] ) ? $available_items[ $form_id ] [ $field['id'] ] : false ; |
| 988 | - } else { |
|
| 988 | + } else { |
|
| 989 | 989 | $original_item = isset( $available_items[ $field['id'] ] ) ? $available_items[ $field['id'] ] : false ; |
| 990 | - } |
|
| 990 | + } |
|
| 991 | 991 | |
| 992 | 992 | if ( !$original_item ) { |
| 993 | 993 | gravityview()->log->error( 'An item was not available when rendering the output; maybe it was added by a plugin that is now de-activated.', array(' data' => array('available_items' => $available_items, 'field' => $field ) ) ); |
@@ -1039,7 +1039,7 @@ discard block |
||
| 1039 | 1039 | |
| 1040 | 1040 | /** |
| 1041 | 1041 | * Render the widget active areas |
| 1042 | - * @param string $template_id The current slug of the selected View template |
|
| 1042 | + * @param string $template_id The current slug of the selected View template |
|
| 1043 | 1043 | * @param string $zone Either 'header' or 'footer' |
| 1044 | 1044 | * @param string $post_id Current Post ID (view) |
| 1045 | 1045 | * @return string html |
@@ -1230,7 +1230,7 @@ discard block |
||
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | // Add the GV font (with the Astronaut) |
| 1233 | - wp_enqueue_style( 'gravityview_global', plugins_url('assets/css/admin-global.css', GRAVITYVIEW_FILE), array(), \GV\Plugin::$version ); |
|
| 1233 | + wp_enqueue_style( 'gravityview_global', plugins_url('assets/css/admin-global.css', GRAVITYVIEW_FILE), array(), \GV\Plugin::$version ); |
|
| 1234 | 1234 | wp_register_style( 'gravityview_views_styles', plugins_url( 'assets/css/admin-views.css', GRAVITYVIEW_FILE ), array( 'dashicons', 'wp-jquery-ui-dialog' ), \GV\Plugin::$version ); |
| 1235 | 1235 | |
| 1236 | 1236 | wp_register_script( 'gravityview-jquery-cookie', plugins_url('assets/lib/jquery.cookie/jquery.cookie.min.js', GRAVITYVIEW_FILE), array( 'jquery' ), \GV\Plugin::$version, true ); |
@@ -1238,64 +1238,64 @@ discard block |
||
| 1238 | 1238 | if( GFForms::get_page() === 'form_list' ) { |
| 1239 | 1239 | wp_enqueue_style( 'gravityview_views_styles' ); |
| 1240 | 1240 | return; |
| 1241 | - } |
|
| 1241 | + } |
|
| 1242 | 1242 | |
| 1243 | 1243 | // Don't process any scripts below here if it's not a GravityView page. |
| 1244 | 1244 | if( ! gravityview()->request->is_admin( $hook, 'single' ) && ! $is_widgets_page ) { |
| 1245 | - return; |
|
| 1245 | + return; |
|
| 1246 | 1246 | } |
| 1247 | 1247 | |
| 1248 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 1249 | - wp_enqueue_style( 'gravityview_views_datepicker', plugins_url('assets/css/admin-datepicker.css', GRAVITYVIEW_FILE), \GV\Plugin::$version ); |
|
| 1250 | - |
|
| 1251 | - // Enqueue scripts |
|
| 1252 | - wp_enqueue_script( 'gravityview_views_scripts', plugins_url( 'assets/js/admin-views' . $script_debug . '.js', GRAVITYVIEW_FILE ), array( 'jquery-ui-tabs', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-ui-tooltip', 'jquery-ui-dialog', 'gravityview-jquery-cookie', 'jquery-ui-datepicker', 'underscore' ), \GV\Plugin::$version ); |
|
| 1253 | - |
|
| 1254 | - wp_localize_script('gravityview_views_scripts', 'gvGlobals', array( |
|
| 1255 | - 'cookiepath' => COOKIEPATH, |
|
| 1256 | - 'passed_form_id' => (bool) \GV\Utils::_GET( 'form_id' ), |
|
| 1257 | - 'nonce' => wp_create_nonce( 'gravityview_ajaxviews' ), |
|
| 1258 | - 'label_viewname' => __( 'Enter View name here', 'gravityview' ), |
|
| 1259 | - 'label_reorder_search_fields' => __( 'Reorder Search Fields', 'gravityview' ), |
|
| 1260 | - 'label_add_search_field' => __( 'Add Search Field', 'gravityview' ), |
|
| 1261 | - 'label_remove_search_field' => __( 'Remove Search Field', 'gravityview' ), |
|
| 1262 | - 'label_close' => __( 'Close', 'gravityview' ), |
|
| 1263 | - 'label_cancel' => __( 'Cancel', 'gravityview' ), |
|
| 1264 | - 'label_continue' => __( 'Continue', 'gravityview' ), |
|
| 1265 | - 'label_ok' => __( 'Ok', 'gravityview' ), |
|
| 1266 | - 'label_publisherror' => __( 'Error while creating the View for you. Check the settings or contact GravityView support.', 'gravityview' ), |
|
| 1267 | - 'loading_text' => esc_html__( 'Loading…', 'gravityview' ), |
|
| 1268 | - 'loading_error' => esc_html__( 'There was an error loading dynamic content.', 'gravityview' ), |
|
| 1269 | - 'field_loaderror' => __( 'Error while adding the field. Please try again or contact GravityView support.', 'gravityview' ), |
|
| 1270 | - 'remove_all_fields' => __( 'Would you like to remove all fields in this zone? (You are seeing this message because you were holding down the ALT key)', 'gravityview' ), |
|
| 1271 | - )); |
|
| 1248 | + wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 1249 | + wp_enqueue_style( 'gravityview_views_datepicker', plugins_url('assets/css/admin-datepicker.css', GRAVITYVIEW_FILE), \GV\Plugin::$version ); |
|
| 1250 | + |
|
| 1251 | + // Enqueue scripts |
|
| 1252 | + wp_enqueue_script( 'gravityview_views_scripts', plugins_url( 'assets/js/admin-views' . $script_debug . '.js', GRAVITYVIEW_FILE ), array( 'jquery-ui-tabs', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-ui-tooltip', 'jquery-ui-dialog', 'gravityview-jquery-cookie', 'jquery-ui-datepicker', 'underscore' ), \GV\Plugin::$version ); |
|
| 1253 | + |
|
| 1254 | + wp_localize_script('gravityview_views_scripts', 'gvGlobals', array( |
|
| 1255 | + 'cookiepath' => COOKIEPATH, |
|
| 1256 | + 'passed_form_id' => (bool) \GV\Utils::_GET( 'form_id' ), |
|
| 1257 | + 'nonce' => wp_create_nonce( 'gravityview_ajaxviews' ), |
|
| 1258 | + 'label_viewname' => __( 'Enter View name here', 'gravityview' ), |
|
| 1259 | + 'label_reorder_search_fields' => __( 'Reorder Search Fields', 'gravityview' ), |
|
| 1260 | + 'label_add_search_field' => __( 'Add Search Field', 'gravityview' ), |
|
| 1261 | + 'label_remove_search_field' => __( 'Remove Search Field', 'gravityview' ), |
|
| 1262 | + 'label_close' => __( 'Close', 'gravityview' ), |
|
| 1263 | + 'label_cancel' => __( 'Cancel', 'gravityview' ), |
|
| 1264 | + 'label_continue' => __( 'Continue', 'gravityview' ), |
|
| 1265 | + 'label_ok' => __( 'Ok', 'gravityview' ), |
|
| 1266 | + 'label_publisherror' => __( 'Error while creating the View for you. Check the settings or contact GravityView support.', 'gravityview' ), |
|
| 1267 | + 'loading_text' => esc_html__( 'Loading…', 'gravityview' ), |
|
| 1268 | + 'loading_error' => esc_html__( 'There was an error loading dynamic content.', 'gravityview' ), |
|
| 1269 | + 'field_loaderror' => __( 'Error while adding the field. Please try again or contact GravityView support.', 'gravityview' ), |
|
| 1270 | + 'remove_all_fields' => __( 'Would you like to remove all fields in this zone? (You are seeing this message because you were holding down the ALT key)', 'gravityview' ), |
|
| 1271 | + )); |
|
| 1272 | 1272 | |
| 1273 | 1273 | wp_enqueue_style( 'gravityview_views_styles' ); |
| 1274 | 1274 | |
| 1275 | - // Enqueue scripts needed for merge tags |
|
| 1276 | - self::enqueue_gravity_forms_scripts(); |
|
| 1275 | + // Enqueue scripts needed for merge tags |
|
| 1276 | + self::enqueue_gravity_forms_scripts(); |
|
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | 1279 | /** |
| 1280 | 1280 | * Enqueue Gravity Forms scripts, needed for Merge Tags |
| 1281 | - * |
|
| 1282 | - * @since 1.0.5-beta |
|
| 1283 | - * |
|
| 1284 | - * @return void |
|
| 1281 | + * |
|
| 1282 | + * @since 1.0.5-beta |
|
| 1283 | + * |
|
| 1284 | + * @return void |
|
| 1285 | 1285 | */ |
| 1286 | 1286 | static function enqueue_gravity_forms_scripts() { |
| 1287 | 1287 | GFForms::register_scripts(); |
| 1288 | 1288 | |
| 1289 | 1289 | $scripts = array( |
| 1290 | - 'sack', |
|
| 1291 | - 'gform_gravityforms', |
|
| 1292 | - 'gform_forms', |
|
| 1293 | - 'gform_form_admin', |
|
| 1294 | - 'jquery-ui-autocomplete' |
|
| 1290 | + 'sack', |
|
| 1291 | + 'gform_gravityforms', |
|
| 1292 | + 'gform_forms', |
|
| 1293 | + 'gform_form_admin', |
|
| 1294 | + 'jquery-ui-autocomplete' |
|
| 1295 | 1295 | ); |
| 1296 | 1296 | |
| 1297 | 1297 | if ( wp_is_mobile() ) { |
| 1298 | - $scripts[] = 'jquery-touch-punch'; |
|
| 1298 | + $scripts[] = 'jquery-touch-punch'; |
|
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | 1301 | wp_enqueue_script( $scripts ); |
@@ -10,42 +10,42 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | if ( ! defined( 'WPINC' ) ) { |
| 13 | - die; |
|
| 13 | + die; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | class GravityView_Edit_Entry_Admin { |
| 18 | 18 | |
| 19 | - protected $loader; |
|
| 19 | + protected $loader; |
|
| 20 | 20 | |
| 21 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
| 22 | - $this->loader = $loader; |
|
| 23 | - } |
|
| 21 | + function __construct( GravityView_Edit_Entry $loader ) { |
|
| 22 | + $this->loader = $loader; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - function load() { |
|
| 25 | + function load() { |
|
| 26 | 26 | |
| 27 | - if( !is_admin() ) { |
|
| 28 | - return; |
|
| 29 | - } |
|
| 27 | + if( !is_admin() ) { |
|
| 28 | + return; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - // Add Edit Link as a default field, outside those set in the Gravity Form form |
|
| 32 | - add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 ); |
|
| 31 | + // Add Edit Link as a default field, outside those set in the Gravity Form form |
|
| 32 | + add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 ); |
|
| 33 | 33 | |
| 34 | - // For the Edit Entry Link, you don't want visible to all users. |
|
| 35 | - add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 ); |
|
| 34 | + // For the Edit Entry Link, you don't want visible to all users. |
|
| 35 | + add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 ); |
|
| 36 | 36 | |
| 37 | - // Modify the field options based on the name of the field type |
|
| 38 | - add_filter( 'gravityview_template_edit_link_options', array( $this, 'edit_link_field_options' ), 10, 5 ); |
|
| 37 | + // Modify the field options based on the name of the field type |
|
| 38 | + add_filter( 'gravityview_template_edit_link_options', array( $this, 'edit_link_field_options' ), 10, 5 ); |
|
| 39 | 39 | |
| 40 | - // add tooltips |
|
| 41 | - add_filter( 'gravityview/metaboxes/tooltips', array( $this, 'tooltips') ); |
|
| 40 | + // add tooltips |
|
| 41 | + add_filter( 'gravityview/metaboxes/tooltips', array( $this, 'tooltips') ); |
|
| 42 | 42 | |
| 43 | - // custom fields' options for zone EDIT |
|
| 44 | - add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 6 ); |
|
| 43 | + // custom fields' options for zone EDIT |
|
| 44 | + add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 6 ); |
|
| 45 | 45 | |
| 46 | - // Add Edit Entry settings to View Settings |
|
| 47 | - add_action( 'gravityview/metaboxes/edit_entry', array( $this, 'view_settings_metabox' ) ); |
|
| 48 | - } |
|
| 46 | + // Add Edit Entry settings to View Settings |
|
| 47 | + add_action( 'gravityview/metaboxes/edit_entry', array( $this, 'view_settings_metabox' ) ); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Render Edit Entry View metabox settings |
@@ -69,101 +69,101 @@ discard block |
||
| 69 | 69 | GravityView_Render_Settings::render_setting_row( 'edit_redirect_url', $current_settings ); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Add Edit Link as a default field, outside those set in the Gravity Form form |
|
| 74 | - * @param array $entry_default_fields Existing fields |
|
| 75 | - * @param string|array $form form_ID or form object |
|
| 76 | - * @param string $zone Either 'single', 'directory', 'header', 'footer' |
|
| 77 | - */ |
|
| 78 | - function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
| 79 | - |
|
| 80 | - if( $zone !== 'edit' ) { |
|
| 81 | - |
|
| 82 | - $entry_default_fields['edit_link'] = array( |
|
| 83 | - 'label' => __('Edit Entry', 'gravityview'), |
|
| 84 | - 'type' => 'edit_link', |
|
| 85 | - 'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
| 86 | - 'icon' => 'dashicons-welcome-write-blog', |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return $entry_default_fields; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Change wording for the Edit context to read Entry Creator |
|
| 96 | - * |
|
| 97 | - * @param array $visibility_caps Array of capabilities to display in field dropdown. |
|
| 98 | - * @param string $field_type Type of field options to render (`field` or `widget`) |
|
| 99 | - * @param string $template_id Table slug |
|
| 100 | - * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
|
| 101 | - * @param string $context What context are we in? Example: `single` or `directory` |
|
| 102 | - * @param string $input_type (textarea, list, select, etc.) |
|
| 103 | - * @return array Array of field options with `label`, `value`, `type`, `default` keys |
|
| 104 | - */ |
|
| 105 | - function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
| 106 | - |
|
| 107 | - $caps = $visibility_caps; |
|
| 108 | - |
|
| 109 | - // If we're configuring fields in the edit context, we want a limited selection |
|
| 110 | - if( $context === 'edit' ) { |
|
| 111 | - |
|
| 112 | - // Remove other built-in caps. |
|
| 113 | - unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
| 114 | - |
|
| 115 | - $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return $caps; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Add "Edit Link Text" setting to the edit_link field settings |
|
| 123 | - * |
|
| 124 | - * @param array $field_options |
|
| 125 | - * @param string $template_id |
|
| 126 | - * @param string $field_id |
|
| 127 | - * @param string $context |
|
| 128 | - * @param string $input_type |
|
| 129 | - * |
|
| 130 | - * @return array $field_options, with "Edit Link Text" field option |
|
| 131 | - */ |
|
| 132 | - function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 133 | - |
|
| 134 | - // Always a link, never a filter |
|
| 135 | - unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
| 136 | - |
|
| 137 | - // Edit Entry link should only appear to visitors capable of editing entries |
|
| 138 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 139 | - |
|
| 140 | - $add_option['edit_link'] = array( |
|
| 141 | - 'type' => 'text', |
|
| 142 | - 'label' => __( 'Edit Link Text', 'gravityview' ), |
|
| 143 | - 'desc' => NULL, |
|
| 144 | - 'value' => __('Edit Entry', 'gravityview'), |
|
| 145 | - 'merge_tags' => true, |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - return array_merge( $add_option, $field_options ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Add tooltips |
|
| 153 | - * @param array $tooltips Existing tooltips |
|
| 154 | - * @return array Modified tooltips |
|
| 155 | - */ |
|
| 156 | - function tooltips( $tooltips ) { |
|
| 157 | - |
|
| 158 | - $return = $tooltips; |
|
| 159 | - |
|
| 160 | - $return['allow_edit_cap'] = array( |
|
| 161 | - 'title' => __('Limiting Edit Access', 'gravityview'), |
|
| 162 | - 'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
| 163 | - ); |
|
| 164 | - |
|
| 165 | - return $return; |
|
| 166 | - } |
|
| 72 | + /** |
|
| 73 | + * Add Edit Link as a default field, outside those set in the Gravity Form form |
|
| 74 | + * @param array $entry_default_fields Existing fields |
|
| 75 | + * @param string|array $form form_ID or form object |
|
| 76 | + * @param string $zone Either 'single', 'directory', 'header', 'footer' |
|
| 77 | + */ |
|
| 78 | + function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
| 79 | + |
|
| 80 | + if( $zone !== 'edit' ) { |
|
| 81 | + |
|
| 82 | + $entry_default_fields['edit_link'] = array( |
|
| 83 | + 'label' => __('Edit Entry', 'gravityview'), |
|
| 84 | + 'type' => 'edit_link', |
|
| 85 | + 'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
| 86 | + 'icon' => 'dashicons-welcome-write-blog', |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return $entry_default_fields; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Change wording for the Edit context to read Entry Creator |
|
| 96 | + * |
|
| 97 | + * @param array $visibility_caps Array of capabilities to display in field dropdown. |
|
| 98 | + * @param string $field_type Type of field options to render (`field` or `widget`) |
|
| 99 | + * @param string $template_id Table slug |
|
| 100 | + * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
|
| 101 | + * @param string $context What context are we in? Example: `single` or `directory` |
|
| 102 | + * @param string $input_type (textarea, list, select, etc.) |
|
| 103 | + * @return array Array of field options with `label`, `value`, `type`, `default` keys |
|
| 104 | + */ |
|
| 105 | + function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
| 106 | + |
|
| 107 | + $caps = $visibility_caps; |
|
| 108 | + |
|
| 109 | + // If we're configuring fields in the edit context, we want a limited selection |
|
| 110 | + if( $context === 'edit' ) { |
|
| 111 | + |
|
| 112 | + // Remove other built-in caps. |
|
| 113 | + unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
| 114 | + |
|
| 115 | + $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return $caps; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Add "Edit Link Text" setting to the edit_link field settings |
|
| 123 | + * |
|
| 124 | + * @param array $field_options |
|
| 125 | + * @param string $template_id |
|
| 126 | + * @param string $field_id |
|
| 127 | + * @param string $context |
|
| 128 | + * @param string $input_type |
|
| 129 | + * |
|
| 130 | + * @return array $field_options, with "Edit Link Text" field option |
|
| 131 | + */ |
|
| 132 | + function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 133 | + |
|
| 134 | + // Always a link, never a filter |
|
| 135 | + unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
| 136 | + |
|
| 137 | + // Edit Entry link should only appear to visitors capable of editing entries |
|
| 138 | + unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 139 | + |
|
| 140 | + $add_option['edit_link'] = array( |
|
| 141 | + 'type' => 'text', |
|
| 142 | + 'label' => __( 'Edit Link Text', 'gravityview' ), |
|
| 143 | + 'desc' => NULL, |
|
| 144 | + 'value' => __('Edit Entry', 'gravityview'), |
|
| 145 | + 'merge_tags' => true, |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + return array_merge( $add_option, $field_options ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Add tooltips |
|
| 153 | + * @param array $tooltips Existing tooltips |
|
| 154 | + * @return array Modified tooltips |
|
| 155 | + */ |
|
| 156 | + function tooltips( $tooltips ) { |
|
| 157 | + |
|
| 158 | + $return = $tooltips; |
|
| 159 | + |
|
| 160 | + $return['allow_edit_cap'] = array( |
|
| 161 | + 'title' => __('Limiting Edit Access', 'gravityview'), |
|
| 162 | + 'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
| 163 | + ); |
|
| 164 | + |
|
| 165 | + return $return; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | 169 | * Add "Edit Link Text" setting to the edit_link field settings |
@@ -179,37 +179,37 @@ discard block |
||
| 179 | 179 | */ |
| 180 | 180 | public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) { |
| 181 | 181 | |
| 182 | - // We only want to modify the settings for the edit context |
|
| 183 | - if( 'edit' !== $context ) { |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @since 1.8.4 |
|
| 187 | - */ |
|
| 188 | - $field_options['new_window'] = array( |
|
| 189 | - 'type' => 'checkbox', |
|
| 190 | - 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
| 191 | - 'value' => false, |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - return $field_options; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // Entry field is only for logged in users |
|
| 198 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 199 | - |
|
| 200 | - $add_options = array( |
|
| 201 | - 'allow_edit_cap' => array( |
|
| 202 | - 'type' => 'select', |
|
| 203 | - 'label' => __( 'Make field editable to:', 'gravityview' ), |
|
| 204 | - 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
| 205 | - 'tooltip' => 'allow_edit_cap', |
|
| 206 | - 'class' => 'widefat', |
|
| 207 | - 'value' => 'read', // Default: entry creator |
|
| 208 | - ), |
|
| 209 | - ); |
|
| 210 | - |
|
| 211 | - return array_merge( $field_options, $add_options ); |
|
| 212 | - } |
|
| 182 | + // We only want to modify the settings for the edit context |
|
| 183 | + if( 'edit' !== $context ) { |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @since 1.8.4 |
|
| 187 | + */ |
|
| 188 | + $field_options['new_window'] = array( |
|
| 189 | + 'type' => 'checkbox', |
|
| 190 | + 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
| 191 | + 'value' => false, |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + return $field_options; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // Entry field is only for logged in users |
|
| 198 | + unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 199 | + |
|
| 200 | + $add_options = array( |
|
| 201 | + 'allow_edit_cap' => array( |
|
| 202 | + 'type' => 'select', |
|
| 203 | + 'label' => __( 'Make field editable to:', 'gravityview' ), |
|
| 204 | + 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
| 205 | + 'tooltip' => 'allow_edit_cap', |
|
| 206 | + 'class' => 'widefat', |
|
| 207 | + 'value' => 'read', // Default: entry creator |
|
| 208 | + ), |
|
| 209 | + ); |
|
| 210 | + |
|
| 211 | + return array_merge( $field_options, $add_options ); |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | 214 | |
| 215 | 215 | } // end class |
@@ -5,295 +5,295 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class GravityView_Change_Entry_Creator { |
| 7 | 7 | |
| 8 | - function __construct() { |
|
| 9 | - |
|
| 10 | - /** |
|
| 11 | - * @since 1.5.1 |
|
| 12 | - */ |
|
| 13 | - add_action('gform_user_registered', array( $this, 'assign_new_user_to_lead'), 10, 4 ); |
|
| 14 | - |
|
| 15 | - // ONLY ADMIN FROM HERE ON. |
|
| 16 | - if( !is_admin() ) { return; } |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @filter `gravityview_disable_change_entry_creator` Disable the Change Entry Creator functionality |
|
| 20 | - * @since 1.7.4 |
|
| 21 | - * @param boolean $disable Disable the Change Entry Creator functionality. Default: false. |
|
| 22 | - */ |
|
| 23 | - if( apply_filters('gravityview_disable_change_entry_creator', false ) ) { |
|
| 24 | - return; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Use `init` to fix bbPress warning |
|
| 29 | - * @see https://bbpress.trac.wordpress.org/ticket/2309 |
|
| 30 | - */ |
|
| 31 | - add_action('init', array( $this, 'load'), 100 ); |
|
| 32 | - |
|
| 33 | - add_action('plugins_loaded', array( $this, 'prevent_conflicts') ); |
|
| 34 | - |
|
| 35 | - // Enqueues SelectWoo script and style. |
|
| 36 | - add_action( 'admin_enqueue_scripts', array( $this, 'add_selectwoo_assets') ); |
|
| 37 | - |
|
| 38 | - // Ajax callback to get users to change entry creator. |
|
| 39 | - add_action( 'wp_ajax_entry_creator_get_users', array( $this, 'entry_creator_get_users' ) ); |
|
| 40 | - |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Enqueues SelectWoo script and style. |
|
| 45 | - * |
|
| 46 | - * @since 2.9.1 |
|
| 47 | - * |
|
| 48 | - */ |
|
| 49 | - function add_selectwoo_assets() { |
|
| 50 | - |
|
| 51 | - $version = GravityView_Plugin::version; |
|
| 52 | - $script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
| 53 | - |
|
| 54 | - wp_enqueue_script( 'gravityview-selectWoo', plugins_url( 'assets/lib/selectWoo/selectWoo.full.min.js', GRAVITYVIEW_FILE ), array(), $version ); |
|
| 55 | - wp_enqueue_style( 'gravityview-selectWoo', plugins_url( 'assets/lib/selectWoo/selectWoo.min.css', GRAVITYVIEW_FILE ), array(), $version ); |
|
| 56 | - |
|
| 57 | - wp_enqueue_script( 'gravityview_entry_creator', plugins_url( 'assets/js/admin-entry-creator' . $script_debug . '.js', GRAVITYVIEW_FILE ), array( 'gravityview-selectWoo' ), $version ); |
|
| 58 | - |
|
| 59 | - wp_localize_script( |
|
| 60 | - 'gravityview_entry_creator', |
|
| 61 | - 'GVEntryCreator', |
|
| 62 | - array( |
|
| 63 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
| 64 | - 'action' => 'entry_creator_get_users', |
|
| 65 | - ) |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Get users list for entry creator. |
|
| 71 | - * |
|
| 72 | - * @since 2.9.1 |
|
| 73 | - * |
|
| 74 | - */ |
|
| 75 | - function entry_creator_get_users() { |
|
| 76 | - |
|
| 77 | - $post_var = wp_parse_args( |
|
| 78 | - wp_unslash( $_POST ), |
|
| 79 | - array( |
|
| 80 | - 'q' => '', |
|
| 81 | - 'gv_nonce' => '', |
|
| 82 | - ) |
|
| 83 | - ); |
|
| 84 | - |
|
| 85 | - if( !wp_verify_nonce( $post_var['gv_nonce'], 'gv_entry_creator' )) { |
|
| 86 | - die(); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $search_string = $post_var['q']; |
|
| 90 | - |
|
| 91 | - $user_args = array( |
|
| 92 | - 'search' => $search_string . '*', |
|
| 93 | - 'search_columns' => array( 'ID', 'user_login', 'user_email', 'user_nicename', 'display_name' ), |
|
| 94 | - ); |
|
| 95 | - |
|
| 96 | - $users = GVCommon::get_users( 'change_entry_creator', $user_args ); |
|
| 97 | - |
|
| 98 | - echo wp_send_json( $users, 200 ); |
|
| 99 | - |
|
| 100 | - die(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * When an user is created using the User Registration add-on, assign the entry to them |
|
| 105 | - * |
|
| 106 | - * @since 1.5.1 |
|
| 107 | - * @uses RGFormsModel::update_lead_property() Modify the entry `created_by` field |
|
| 108 | - * @param int $user_id WordPress User ID |
|
| 109 | - * @param array $config User registration feed configuration |
|
| 110 | - * @param array $entry GF Entry array |
|
| 111 | - * @param string $password User password |
|
| 112 | - * @return void |
|
| 113 | - */ |
|
| 114 | - function assign_new_user_to_lead( $user_id, $config, $entry = array(), $password = '' ) { |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Disable assigning the new user to the entry by returning false. |
|
| 118 | - * @param int $user_id WordPress User ID |
|
| 119 | - * @param array $config User registration feed configuration |
|
| 120 | - * @param array $entry GF Entry array |
|
| 121 | - */ |
|
| 122 | - $assign_to_lead = apply_filters( 'gravityview_assign_new_user_to_entry', true, $user_id, $config, $entry ); |
|
| 123 | - |
|
| 124 | - // If filter returns false, do not process |
|
| 125 | - if( empty( $assign_to_lead ) ) { |
|
| 126 | - return; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // Update the entry. The `false` prevents checking Akismet; `true` disables the user updated hook from firing |
|
| 130 | - $result = RGFormsModel::update_entry_property( (int) $entry['id'], 'created_by', (int) $user_id, false, true ); |
|
| 131 | - |
|
| 132 | - if ( false === $result ) { |
|
| 133 | - $status = __('Error', 'gravityview'); |
|
| 134 | - global $wpdb; |
|
| 135 | - $note = sprintf( '%s: Failed to assign User ID #%d as the entry creator (Last database error: "%s")', $status, $user_id, $wpdb->last_error ); |
|
| 136 | - } else { |
|
| 137 | - $status = __('Success', 'gravityview'); |
|
| 138 | - $note = sprintf( _x('%s: Assigned User ID #%d as the entry creator.', 'First parameter: Success or error of the action. Second: User ID number', 'gravityview'), $status, $user_id ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - gravityview()->log->debug( 'GravityView_Change_Entry_Creator[assign_new_user_to_lead] - {note}', array( 'note' => $note ) ); |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @filter `gravityview_disable_change_entry_creator_note` Disable adding a note when changing the entry creator |
|
| 145 | - * @since 1.21.5 |
|
| 146 | - * @param boolean $disable Disable the Change Entry Creator note. Default: false. |
|
| 147 | - */ |
|
| 148 | - if( apply_filters('gravityview_disable_change_entry_creator_note', false ) ) { |
|
| 149 | - return; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - GravityView_Entry_Notes::add_note( $entry['id'], -1, 'GravityView', $note, 'gravityview' ); |
|
| 153 | - |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Disable previous functionality; use this one as the canonical. |
|
| 158 | - * @return void |
|
| 159 | - */ |
|
| 160 | - function prevent_conflicts() { |
|
| 161 | - |
|
| 162 | - // Plugin that was provided here: |
|
| 163 | - // @link https://gravityview.co/support/documentation/201991205/ |
|
| 164 | - remove_action("gform_entry_info", 'gravityview_change_entry_creator_form', 10 ); |
|
| 165 | - remove_action("gform_after_update_entry", 'gravityview_update_entry_creator', 10 ); |
|
| 166 | - |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @since 3.6.3 |
|
| 171 | - * @return void |
|
| 172 | - */ |
|
| 173 | - function load() { |
|
| 174 | - |
|
| 175 | - // Does GF exist? |
|
| 176 | - if( !class_exists('GFCommon') ) { |
|
| 177 | - return; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // Can the user edit entries? |
|
| 181 | - if( ! GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_entries' ) ) ) { |
|
| 182 | - return; |
|
| 183 | - } |
|
| 8 | + function __construct() { |
|
| 9 | + |
|
| 10 | + /** |
|
| 11 | + * @since 1.5.1 |
|
| 12 | + */ |
|
| 13 | + add_action('gform_user_registered', array( $this, 'assign_new_user_to_lead'), 10, 4 ); |
|
| 14 | + |
|
| 15 | + // ONLY ADMIN FROM HERE ON. |
|
| 16 | + if( !is_admin() ) { return; } |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @filter `gravityview_disable_change_entry_creator` Disable the Change Entry Creator functionality |
|
| 20 | + * @since 1.7.4 |
|
| 21 | + * @param boolean $disable Disable the Change Entry Creator functionality. Default: false. |
|
| 22 | + */ |
|
| 23 | + if( apply_filters('gravityview_disable_change_entry_creator', false ) ) { |
|
| 24 | + return; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Use `init` to fix bbPress warning |
|
| 29 | + * @see https://bbpress.trac.wordpress.org/ticket/2309 |
|
| 30 | + */ |
|
| 31 | + add_action('init', array( $this, 'load'), 100 ); |
|
| 32 | + |
|
| 33 | + add_action('plugins_loaded', array( $this, 'prevent_conflicts') ); |
|
| 34 | + |
|
| 35 | + // Enqueues SelectWoo script and style. |
|
| 36 | + add_action( 'admin_enqueue_scripts', array( $this, 'add_selectwoo_assets') ); |
|
| 37 | + |
|
| 38 | + // Ajax callback to get users to change entry creator. |
|
| 39 | + add_action( 'wp_ajax_entry_creator_get_users', array( $this, 'entry_creator_get_users' ) ); |
|
| 40 | + |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Enqueues SelectWoo script and style. |
|
| 45 | + * |
|
| 46 | + * @since 2.9.1 |
|
| 47 | + * |
|
| 48 | + */ |
|
| 49 | + function add_selectwoo_assets() { |
|
| 50 | + |
|
| 51 | + $version = GravityView_Plugin::version; |
|
| 52 | + $script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
| 53 | + |
|
| 54 | + wp_enqueue_script( 'gravityview-selectWoo', plugins_url( 'assets/lib/selectWoo/selectWoo.full.min.js', GRAVITYVIEW_FILE ), array(), $version ); |
|
| 55 | + wp_enqueue_style( 'gravityview-selectWoo', plugins_url( 'assets/lib/selectWoo/selectWoo.min.css', GRAVITYVIEW_FILE ), array(), $version ); |
|
| 56 | + |
|
| 57 | + wp_enqueue_script( 'gravityview_entry_creator', plugins_url( 'assets/js/admin-entry-creator' . $script_debug . '.js', GRAVITYVIEW_FILE ), array( 'gravityview-selectWoo' ), $version ); |
|
| 58 | + |
|
| 59 | + wp_localize_script( |
|
| 60 | + 'gravityview_entry_creator', |
|
| 61 | + 'GVEntryCreator', |
|
| 62 | + array( |
|
| 63 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
| 64 | + 'action' => 'entry_creator_get_users', |
|
| 65 | + ) |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Get users list for entry creator. |
|
| 71 | + * |
|
| 72 | + * @since 2.9.1 |
|
| 73 | + * |
|
| 74 | + */ |
|
| 75 | + function entry_creator_get_users() { |
|
| 76 | + |
|
| 77 | + $post_var = wp_parse_args( |
|
| 78 | + wp_unslash( $_POST ), |
|
| 79 | + array( |
|
| 80 | + 'q' => '', |
|
| 81 | + 'gv_nonce' => '', |
|
| 82 | + ) |
|
| 83 | + ); |
|
| 84 | + |
|
| 85 | + if( !wp_verify_nonce( $post_var['gv_nonce'], 'gv_entry_creator' )) { |
|
| 86 | + die(); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $search_string = $post_var['q']; |
|
| 90 | + |
|
| 91 | + $user_args = array( |
|
| 92 | + 'search' => $search_string . '*', |
|
| 93 | + 'search_columns' => array( 'ID', 'user_login', 'user_email', 'user_nicename', 'display_name' ), |
|
| 94 | + ); |
|
| 95 | + |
|
| 96 | + $users = GVCommon::get_users( 'change_entry_creator', $user_args ); |
|
| 97 | + |
|
| 98 | + echo wp_send_json( $users, 200 ); |
|
| 99 | + |
|
| 100 | + die(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * When an user is created using the User Registration add-on, assign the entry to them |
|
| 105 | + * |
|
| 106 | + * @since 1.5.1 |
|
| 107 | + * @uses RGFormsModel::update_lead_property() Modify the entry `created_by` field |
|
| 108 | + * @param int $user_id WordPress User ID |
|
| 109 | + * @param array $config User registration feed configuration |
|
| 110 | + * @param array $entry GF Entry array |
|
| 111 | + * @param string $password User password |
|
| 112 | + * @return void |
|
| 113 | + */ |
|
| 114 | + function assign_new_user_to_lead( $user_id, $config, $entry = array(), $password = '' ) { |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Disable assigning the new user to the entry by returning false. |
|
| 118 | + * @param int $user_id WordPress User ID |
|
| 119 | + * @param array $config User registration feed configuration |
|
| 120 | + * @param array $entry GF Entry array |
|
| 121 | + */ |
|
| 122 | + $assign_to_lead = apply_filters( 'gravityview_assign_new_user_to_entry', true, $user_id, $config, $entry ); |
|
| 123 | + |
|
| 124 | + // If filter returns false, do not process |
|
| 125 | + if( empty( $assign_to_lead ) ) { |
|
| 126 | + return; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // Update the entry. The `false` prevents checking Akismet; `true` disables the user updated hook from firing |
|
| 130 | + $result = RGFormsModel::update_entry_property( (int) $entry['id'], 'created_by', (int) $user_id, false, true ); |
|
| 131 | + |
|
| 132 | + if ( false === $result ) { |
|
| 133 | + $status = __('Error', 'gravityview'); |
|
| 134 | + global $wpdb; |
|
| 135 | + $note = sprintf( '%s: Failed to assign User ID #%d as the entry creator (Last database error: "%s")', $status, $user_id, $wpdb->last_error ); |
|
| 136 | + } else { |
|
| 137 | + $status = __('Success', 'gravityview'); |
|
| 138 | + $note = sprintf( _x('%s: Assigned User ID #%d as the entry creator.', 'First parameter: Success or error of the action. Second: User ID number', 'gravityview'), $status, $user_id ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + gravityview()->log->debug( 'GravityView_Change_Entry_Creator[assign_new_user_to_lead] - {note}', array( 'note' => $note ) ); |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @filter `gravityview_disable_change_entry_creator_note` Disable adding a note when changing the entry creator |
|
| 145 | + * @since 1.21.5 |
|
| 146 | + * @param boolean $disable Disable the Change Entry Creator note. Default: false. |
|
| 147 | + */ |
|
| 148 | + if( apply_filters('gravityview_disable_change_entry_creator_note', false ) ) { |
|
| 149 | + return; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + GravityView_Entry_Notes::add_note( $entry['id'], -1, 'GravityView', $note, 'gravityview' ); |
|
| 153 | + |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Disable previous functionality; use this one as the canonical. |
|
| 158 | + * @return void |
|
| 159 | + */ |
|
| 160 | + function prevent_conflicts() { |
|
| 161 | + |
|
| 162 | + // Plugin that was provided here: |
|
| 163 | + // @link https://gravityview.co/support/documentation/201991205/ |
|
| 164 | + remove_action("gform_entry_info", 'gravityview_change_entry_creator_form', 10 ); |
|
| 165 | + remove_action("gform_after_update_entry", 'gravityview_update_entry_creator', 10 ); |
|
| 166 | + |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @since 3.6.3 |
|
| 171 | + * @return void |
|
| 172 | + */ |
|
| 173 | + function load() { |
|
| 174 | + |
|
| 175 | + // Does GF exist? |
|
| 176 | + if( !class_exists('GFCommon') ) { |
|
| 177 | + return; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // Can the user edit entries? |
|
| 181 | + if( ! GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_entries' ) ) ) { |
|
| 182 | + return; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - // If screen mode isn't set, then we're in the wrong place. |
|
| 186 | - if( empty( $_REQUEST['screen_mode'] ) ) { |
|
| 187 | - return; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // Now, no validation is required in the methods; let's hook in. |
|
| 191 | - add_action('admin_init', array( &$this, 'set_screen_mode' ) ); |
|
| 192 | - |
|
| 193 | - add_action("gform_entry_info", array( &$this, 'add_select' ), 10, 2); |
|
| 194 | - |
|
| 195 | - add_action("gform_after_update_entry", array( &$this, 'update_entry_creator' ), 10, 2); |
|
| 196 | - |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Allows for edit links to work with a link instead of a form (GET instead of POST) |
|
| 201 | - * @return void |
|
| 202 | - */ |
|
| 203 | - function set_screen_mode() { |
|
| 204 | - |
|
| 205 | - if( 'view' === \GV\Utils::_POST( 'screen_mode' ) ) { |
|
| 206 | - return; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // If $_GET['screen_mode'] is set to edit, set $_POST value |
|
| 210 | - if( \GV\Utils::_GET( 'screen_mode' ) === 'edit' ) { |
|
| 211 | - $_POST["screen_mode"] = 'edit'; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - } |
|
| 185 | + // If screen mode isn't set, then we're in the wrong place. |
|
| 186 | + if( empty( $_REQUEST['screen_mode'] ) ) { |
|
| 187 | + return; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // Now, no validation is required in the methods; let's hook in. |
|
| 191 | + add_action('admin_init', array( &$this, 'set_screen_mode' ) ); |
|
| 192 | + |
|
| 193 | + add_action("gform_entry_info", array( &$this, 'add_select' ), 10, 2); |
|
| 194 | + |
|
| 195 | + add_action("gform_after_update_entry", array( &$this, 'update_entry_creator' ), 10, 2); |
|
| 196 | + |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Allows for edit links to work with a link instead of a form (GET instead of POST) |
|
| 201 | + * @return void |
|
| 202 | + */ |
|
| 203 | + function set_screen_mode() { |
|
| 204 | + |
|
| 205 | + if( 'view' === \GV\Utils::_POST( 'screen_mode' ) ) { |
|
| 206 | + return; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // If $_GET['screen_mode'] is set to edit, set $_POST value |
|
| 210 | + if( \GV\Utils::_GET( 'screen_mode' ) === 'edit' ) { |
|
| 211 | + $_POST["screen_mode"] = 'edit'; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - /** |
|
| 217 | - * When the entry creator is changed, add a note to the entry |
|
| 218 | - * @param array $form GF entry array |
|
| 219 | - * @param int $entry_id Entry ID |
|
| 220 | - * @return void |
|
| 221 | - */ |
|
| 222 | - function update_entry_creator($form, $entry_id) { |
|
| 223 | - global $current_user; |
|
| 216 | + /** |
|
| 217 | + * When the entry creator is changed, add a note to the entry |
|
| 218 | + * @param array $form GF entry array |
|
| 219 | + * @param int $entry_id Entry ID |
|
| 220 | + * @return void |
|
| 221 | + */ |
|
| 222 | + function update_entry_creator($form, $entry_id) { |
|
| 223 | + global $current_user; |
|
| 224 | 224 | |
| 225 | - // Update the entry |
|
| 226 | - $created_by = absint( \GV\Utils::_POST( 'created_by') ); |
|
| 225 | + // Update the entry |
|
| 226 | + $created_by = absint( \GV\Utils::_POST( 'created_by') ); |
|
| 227 | 227 | |
| 228 | - RGFormsModel::update_lead_property( $entry_id, 'created_by', $created_by ); |
|
| 228 | + RGFormsModel::update_lead_property( $entry_id, 'created_by', $created_by ); |
|
| 229 | 229 | |
| 230 | - // If the creator has changed, let's add a note about who it used to be. |
|
| 231 | - $originally_created_by = \GV\Utils::_POST( 'originally_created_by' ); |
|
| 230 | + // If the creator has changed, let's add a note about who it used to be. |
|
| 231 | + $originally_created_by = \GV\Utils::_POST( 'originally_created_by' ); |
|
| 232 | 232 | |
| 233 | - // If there's no owner and there didn't used to be, keep going |
|
| 234 | - if( empty( $originally_created_by ) && empty( $created_by ) ) { |
|
| 235 | - return; |
|
| 236 | - } |
|
| 233 | + // If there's no owner and there didn't used to be, keep going |
|
| 234 | + if( empty( $originally_created_by ) && empty( $created_by ) ) { |
|
| 235 | + return; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - // If the values have changed |
|
| 239 | - if( absint( $originally_created_by ) !== absint( $created_by ) ) { |
|
| 238 | + // If the values have changed |
|
| 239 | + if( absint( $originally_created_by ) !== absint( $created_by ) ) { |
|
| 240 | 240 | |
| 241 | - $user_data = get_userdata($current_user->ID); |
|
| 241 | + $user_data = get_userdata($current_user->ID); |
|
| 242 | 242 | |
| 243 | - $user_format = _x('%s (ID #%d)', 'The name and the ID of users who initiated changes to entry ownership', 'gravityview'); |
|
| 243 | + $user_format = _x('%s (ID #%d)', 'The name and the ID of users who initiated changes to entry ownership', 'gravityview'); |
|
| 244 | 244 | |
| 245 | - $original_name = $created_by_name = esc_attr_x( 'No User', 'To show that the entry was unassigned from an actual user to no user.', 'gravityview'); |
|
| 245 | + $original_name = $created_by_name = esc_attr_x( 'No User', 'To show that the entry was unassigned from an actual user to no user.', 'gravityview'); |
|
| 246 | 246 | |
| 247 | - if( !empty( $originally_created_by ) ) { |
|
| 248 | - $originally_created_by_user_data = get_userdata($originally_created_by); |
|
| 249 | - $original_name = sprintf( $user_format, $originally_created_by_user_data->display_name, $originally_created_by_user_data->ID ); |
|
| 250 | - } |
|
| 247 | + if( !empty( $originally_created_by ) ) { |
|
| 248 | + $originally_created_by_user_data = get_userdata($originally_created_by); |
|
| 249 | + $original_name = sprintf( $user_format, $originally_created_by_user_data->display_name, $originally_created_by_user_data->ID ); |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - if( !empty( $created_by ) ) { |
|
| 253 | - $created_by_user_data = get_userdata($created_by); |
|
| 254 | - $created_by_name = sprintf( $user_format, $created_by_user_data->display_name, $created_by_user_data->ID ); |
|
| 255 | - } |
|
| 252 | + if( !empty( $created_by ) ) { |
|
| 253 | + $created_by_user_data = get_userdata($created_by); |
|
| 254 | + $created_by_name = sprintf( $user_format, $created_by_user_data->display_name, $created_by_user_data->ID ); |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __('Changed entry creator from %s to %s', 'gravityview'), $original_name, $created_by_name ), 'note' ); |
|
| 258 | - } |
|
| 257 | + GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __('Changed entry creator from %s to %s', 'gravityview'), $original_name, $created_by_name ), 'note' ); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * Output the select to change the entry creator |
|
| 264 | - * @param int $form_id GF Form ID |
|
| 265 | - * @param array $entry GF entry array |
|
| 266 | - * @return void |
|
| 267 | - */ |
|
| 268 | - function add_select($form_id, $entry ) { |
|
| 262 | + /** |
|
| 263 | + * Output the select to change the entry creator |
|
| 264 | + * @param int $form_id GF Form ID |
|
| 265 | + * @param array $entry GF entry array |
|
| 266 | + * @return void |
|
| 267 | + */ |
|
| 268 | + function add_select($form_id, $entry ) { |
|
| 269 | 269 | |
| 270 | - if( \GV\Utils::_POST( 'screen_mode' ) !== 'edit' ) { |
|
| 271 | - return; |
|
| 272 | - } |
|
| 270 | + if( \GV\Utils::_POST( 'screen_mode' ) !== 'edit' ) { |
|
| 271 | + return; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | 274 | |
| 275 | - $output = '<label for="change_created_by">'; |
|
| 276 | - $output .= esc_html__('Change Entry Creator:', 'gravityview'); |
|
| 277 | - $output .= '</label>'; |
|
| 275 | + $output = '<label for="change_created_by">'; |
|
| 276 | + $output .= esc_html__('Change Entry Creator:', 'gravityview'); |
|
| 277 | + $output .= '</label>'; |
|
| 278 | 278 | |
| 279 | - $output .= '<select name="created_by" id="change_created_by" class="widefat">'; |
|
| 279 | + $output .= '<select name="created_by" id="change_created_by" class="widefat">'; |
|
| 280 | 280 | |
| 281 | - $created_by_id = \GV\Utils::get( $entry, 'created_by' ); |
|
| 282 | - $created_by_user = GVCommon::get_users( 'change_entry_creator', array( 'include' => $created_by_id ) ); |
|
| 283 | - $created_by_user = isset($created_by_user[0]) ? $created_by_user[0] : array(); |
|
| 281 | + $created_by_id = \GV\Utils::get( $entry, 'created_by' ); |
|
| 282 | + $created_by_user = GVCommon::get_users( 'change_entry_creator', array( 'include' => $created_by_id ) ); |
|
| 283 | + $created_by_user = isset($created_by_user[0]) ? $created_by_user[0] : array(); |
|
| 284 | 284 | |
| 285 | - if( empty( $created_by_user ) ) { |
|
| 286 | - $output .= '<option value="0"> — '.esc_attr_x( 'No User', 'No user assigned to the entry', 'gravityview').' — </option>'; |
|
| 287 | - } else { |
|
| 288 | - $output .= '<option value="'. $created_by_user->ID .'" "selected">'.esc_attr( $created_by_user->display_name.' ('.$created_by_user->user_nicename.')' ).'</option>'; |
|
| 289 | - } |
|
| 285 | + if( empty( $created_by_user ) ) { |
|
| 286 | + $output .= '<option value="0"> — '.esc_attr_x( 'No User', 'No user assigned to the entry', 'gravityview').' — </option>'; |
|
| 287 | + } else { |
|
| 288 | + $output .= '<option value="'. $created_by_user->ID .'" "selected">'.esc_attr( $created_by_user->display_name.' ('.$created_by_user->user_nicename.')' ).'</option>'; |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - $output .= '</select>'; |
|
| 292 | - $output .= '<input name="originally_created_by" value="'.esc_attr( $entry['created_by'] ).'" type="hidden" />'; |
|
| 293 | - $output .= wp_nonce_field( 'gv_entry_creator', 'gv_entry_creator_nonce', false, false ); |
|
| 291 | + $output .= '</select>'; |
|
| 292 | + $output .= '<input name="originally_created_by" value="'.esc_attr( $entry['created_by'] ).'" type="hidden" />'; |
|
| 293 | + $output .= wp_nonce_field( 'gv_entry_creator', 'gv_entry_creator_nonce', false, false ); |
|
| 294 | 294 | |
| 295 | - echo $output; |
|
| 296 | - } |
|
| 295 | + echo $output; |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | 298 | } |
| 299 | 299 | |