@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * @action `gravityview_search_widget_field_before` Before each search input is rendered (other than the submit button) |
| 33 | 33 | * @param GravityView_Widget_Search $this GravityView Widget instance |
| 34 | - * @param array $search_field |
|
| 34 | + * @param array $search_field |
|
| 35 | 35 | */ |
| 36 | 36 | do_action( 'gravityview_search_widget_field_before', $this, $search_field ); |
| 37 | 37 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * @action `gravityview_search_widget_field_after` After each search input is rendered (other than the submit button) |
| 48 | 48 | * @param GravityView_Widget_Search $this GravityView Widget instance |
| 49 | - * @param array $search_field |
|
| 49 | + * @param array $search_field |
|
| 50 | 50 | */ |
| 51 | 51 | do_action( 'gravityview_search_widget_field_after', $this, $search_field ); |
| 52 | 52 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | do_action( 'gravityview_search_widget_fields_after', $this ); |
| 59 | 59 | |
| 60 | 60 | if( $has_inputs ) { |
| 61 | - $this->render( 'search-field', 'submit', false ); |
|
| 62 | - } |
|
| 61 | + $this->render( 'search-field', 'submit', false ); |
|
| 62 | + } |
|
| 63 | 63 | ?> |
| 64 | 64 | </form> |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | 'payment_id' => '', |
| 105 | 105 | 'customer_name' => '', |
| 106 | 106 | 'customer_email' => '', |
| 107 | - 'price_id' => '0', |
|
| 107 | + 'price_id' => '0', |
|
| 108 | 108 | ) ); |
| 109 | 109 | |
| 110 | 110 | // This is just HTML we don't need. |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | case 3: |
| 122 | 122 | $package = 'Galactic'; |
| 123 | 123 | break; |
| 124 | - case 4: |
|
| 125 | - $package = 'Lifetime'; |
|
| 126 | - break; |
|
| 124 | + case 4: |
|
| 125 | + $package = 'Lifetime'; |
|
| 126 | + break; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | $data = array( |
@@ -152,18 +152,18 @@ discard block |
||
| 152 | 152 | 'contactEnabled' => (int)GVCommon::has_cap( 'gravityview_contact_support' ), |
| 153 | 153 | 'data' => $data, |
| 154 | 154 | 'translation' => $translation, |
| 155 | - 'suggest' => array(), |
|
| 155 | + 'suggest' => array(), |
|
| 156 | 156 | ); |
| 157 | 157 | |
| 158 | 158 | /** |
| 159 | - * @filter `gravityview/support_port/localization_data` Filter data passed to the Support Port, before localize_script is run |
|
| 159 | + * @filter `gravityview/support_port/localization_data` Filter data passed to the Support Port, before localize_script is run |
|
| 160 | 160 | * @since 2.0 |
| 161 | - * @param array $localization_data { |
|
| 162 | - * @type int $contactEnabled Can the user contact support? |
|
| 163 | - * @type array $data Support/license info |
|
| 164 | - * @type array $translation i18n strings |
|
| 165 | - * @type array $suggest Article IDs to recommend to the user (per page in the admin |
|
| 166 | - * } |
|
| 161 | + * @param array $localization_data { |
|
| 162 | + * @type int $contactEnabled Can the user contact support? |
|
| 163 | + * @type array $data Support/license info |
|
| 164 | + * @type array $translation i18n strings |
|
| 165 | + * @type array $suggest Article IDs to recommend to the user (per page in the admin |
|
| 166 | + * } |
|
| 167 | 167 | */ |
| 168 | 168 | $localization_data = apply_filters( 'gravityview/support_port/localization_data', $localization_data ); |
| 169 | 169 | |
@@ -177,11 +177,11 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * If the user doesn't have the `gravityview_support_port` capability, returns false; then |
| 179 | 179 | * If global setting is "hide", returns false; then |
| 180 | - * If user preference is not set, return global setting; then |
|
| 181 | - * If user preference is set, return that setting. |
|
| 180 | + * If user preference is not set, return global setting; then |
|
| 181 | + * If user preference is set, return that setting. |
|
| 182 | 182 | * |
| 183 | 183 | * @since 1.15 |
| 184 | - * @since 1.17.5 Changed behavior to respect global setting |
|
| 184 | + * @since 1.17.5 Changed behavior to respect global setting |
|
| 185 | 185 | * |
| 186 | 186 | * @param int $user Optional. ID of the user to check, defaults to 0 for current user. |
| 187 | 187 | * |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $global_setting = gravityview()->plugin->settings->get( 'support_port' ); |
| 197 | 197 | |
| 198 | 198 | if ( empty( $global_setting ) ) { |
| 199 | - return false; |
|
| 199 | + return false; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // Get the per-user Support Port setting |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * Modifies the output of profile.php to add GravityView Support preference |
| 233 | 233 | * |
| 234 | 234 | * @since 1.15 |
| 235 | - * @since 1.17.5 Only show if global setting is active |
|
| 235 | + * @since 1.17.5 Only show if global setting is active |
|
| 236 | 236 | * |
| 237 | 237 | * @param WP_User $user Current user info |
| 238 | 238 | * |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | $global_setting = gravityview()->plugin->settings->get( 'support_port' ); |
| 244 | 244 | |
| 245 | 245 | if ( empty( $global_setting ) ) { |
| 246 | - return; |
|
| 246 | + return; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -28,13 +28,13 @@ |
||
| 28 | 28 | |
| 29 | 29 | $show_mt = $this->show_merge_tags(); |
| 30 | 30 | |
| 31 | - if( $show_mt && $this->field['merge_tags'] !== false || $this->field['merge_tags'] === 'force' ) { |
|
| 32 | - $class .= ' merge-tag-support mt-position-right '; |
|
| 31 | + if( $show_mt && $this->field['merge_tags'] !== false || $this->field['merge_tags'] === 'force' ) { |
|
| 32 | + $class .= ' merge-tag-support mt-position-right '; |
|
| 33 | 33 | |
| 34 | - if( empty( $this->field['show_all_fields'] ) ) { |
|
| 35 | - $class .= ' mt-hide_all_fields '; |
|
| 36 | - } |
|
| 37 | - } |
|
| 34 | + if( empty( $this->field['show_all_fields'] ) ) { |
|
| 35 | + $class .= ' mt-hide_all_fields '; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | $class .= \GV\Utils::get( $this->field, 'class' ); |
| 39 | 39 | $placeholder = \GV\Utils::get( $this->field, 'placeholder' ); |
| 40 | 40 | $rows = \GV\Utils::get( $this->field, 'rows', 5 ); |
@@ -28,11 +28,11 @@ |
||
| 28 | 28 | |
| 29 | 29 | $show_mt = $this->show_merge_tags(); |
| 30 | 30 | |
| 31 | - if( $show_mt && $this->field['merge_tags'] !== false || $this->field['merge_tags'] === 'force' ) { |
|
| 32 | - $class = 'merge-tag-support mt-position-right mt-hide_all_fields '; |
|
| 33 | - } |
|
| 34 | - $class .= \GV\Utils::get( $this->field, 'class', 'widefat' ); |
|
| 35 | - $placeholder = \GV\Utils::get( $this->field, 'placeholder' ); |
|
| 31 | + if( $show_mt && $this->field['merge_tags'] !== false || $this->field['merge_tags'] === 'force' ) { |
|
| 32 | + $class = 'merge-tag-support mt-position-right mt-hide_all_fields '; |
|
| 33 | + } |
|
| 34 | + $class .= \GV\Utils::get( $this->field, 'class', 'widefat' ); |
|
| 35 | + $placeholder = \GV\Utils::get( $this->field, 'placeholder' ); |
|
| 36 | 36 | ?> |
| 37 | 37 | <input name="<?php echo esc_attr( $this->name ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" id="<?php echo $this->get_field_id(); ?>" type="text" value="<?php echo esc_attr( $this->value ); ?>" class="<?php echo esc_attr( $class ); ?>"> |
| 38 | 38 | <?php |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | self::getInstance()->set_entry( $entry ); |
| 241 | 241 | |
| 242 | - $base = GravityView_API::directory_link( $post_id ? : $view_id, true ); |
|
| 242 | + $base = GravityView_API::directory_link( $post_id ? : $view_id, true ); |
|
| 243 | 243 | |
| 244 | 244 | if ( empty( $base ) ) { |
| 245 | 245 | gravityview()->log->error( 'Post ID does not exist: {post_id}', array( 'post_id' => $post_id ) ); |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | 'action' => 'delete', |
| 254 | 254 | 'entry_id' => $entry_slug, |
| 255 | 255 | 'gvid' => $view_id, |
| 256 | - 'view_id' => $view_id, |
|
| 256 | + 'view_id' => $view_id, |
|
| 257 | 257 | ), $base ); |
| 258 | 258 | |
| 259 | 259 | $url = wp_nonce_url( $actionurl, 'delete_'.$entry_slug, 'delete' ); |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | * @since 1.16.4 |
| 428 | 428 | * @param int $entry_id ID of the Gravity Forms entry |
| 429 | 429 | * @param array $entry Deleted entry array |
| 430 | - */ |
|
| 430 | + */ |
|
| 431 | 431 | do_action( 'gravityview/delete-entry/deleted', $entry_id, $entry ); |
| 432 | 432 | } |
| 433 | 433 | |
@@ -18,80 +18,80 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | class GravityView_Edit_Entry { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | 24 | static $file; |
| 25 | 25 | |
| 26 | 26 | static $instance; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Component instances. |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - public $instances = array(); |
|
| 28 | + /** |
|
| 29 | + * Component instances. |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + public $instances = array(); |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | function __construct() { |
| 36 | 36 | |
| 37 | - self::$file = plugin_dir_path( __FILE__ ); |
|
| 37 | + self::$file = plugin_dir_path( __FILE__ ); |
|
| 38 | 38 | |
| 39 | - if( is_admin() ) { |
|
| 40 | - $this->load_components( 'admin' ); |
|
| 41 | - } |
|
| 39 | + if( is_admin() ) { |
|
| 40 | + $this->load_components( 'admin' ); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - $this->load_components( 'render' ); |
|
| 44 | + $this->load_components( 'render' ); |
|
| 45 | 45 | |
| 46 | - // If GF User Registration Add-on exists |
|
| 47 | - $this->load_components( 'user-registration' ); |
|
| 46 | + // If GF User Registration Add-on exists |
|
| 47 | + $this->load_components( 'user-registration' ); |
|
| 48 | 48 | |
| 49 | - $this->add_hooks(); |
|
| 49 | + $this->add_hooks(); |
|
| 50 | 50 | |
| 51 | 51 | // Process hooks for addons that may or may not be present |
| 52 | 52 | $this->addon_specific_hooks(); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | |
| 56 | - static function getInstance() { |
|
| 56 | + static function getInstance() { |
|
| 57 | 57 | |
| 58 | - if( empty( self::$instance ) ) { |
|
| 59 | - self::$instance = new GravityView_Edit_Entry; |
|
| 60 | - } |
|
| 58 | + if( empty( self::$instance ) ) { |
|
| 59 | + self::$instance = new GravityView_Edit_Entry; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return self::$instance; |
|
| 63 | - } |
|
| 62 | + return self::$instance; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - private function load_components( $component ) { |
|
| 66 | + private function load_components( $component ) { |
|
| 67 | 67 | |
| 68 | - $dir = trailingslashit( self::$file ); |
|
| 68 | + $dir = trailingslashit( self::$file ); |
|
| 69 | 69 | |
| 70 | - $filename = $dir . 'class-edit-entry-' . $component . '.php'; |
|
| 71 | - $classname = 'GravityView_Edit_Entry_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $component ) ) ); |
|
| 70 | + $filename = $dir . 'class-edit-entry-' . $component . '.php'; |
|
| 71 | + $classname = 'GravityView_Edit_Entry_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $component ) ) ); |
|
| 72 | 72 | |
| 73 | - // Loads component and pass extension's instance so that component can |
|
| 74 | - // talk each other. |
|
| 75 | - require_once $filename; |
|
| 76 | - $this->instances[ $component ] = new $classname( $this ); |
|
| 77 | - $this->instances[ $component ]->load(); |
|
| 73 | + // Loads component and pass extension's instance so that component can |
|
| 74 | + // talk each other. |
|
| 75 | + require_once $filename; |
|
| 76 | + $this->instances[ $component ] = new $classname( $this ); |
|
| 77 | + $this->instances[ $component ]->load(); |
|
| 78 | 78 | |
| 79 | - } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - private function add_hooks() { |
|
| 81 | + private function add_hooks() { |
|
| 82 | 82 | |
| 83 | - // Add front-end access to Gravity Forms delete file action |
|
| 84 | - add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 83 | + // Add front-end access to Gravity Forms delete file action |
|
| 84 | + add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 85 | 85 | |
| 86 | - // Make sure this hook is run for non-admins |
|
| 87 | - add_action( 'wp_ajax_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 86 | + // Make sure this hook is run for non-admins |
|
| 87 | + add_action( 'wp_ajax_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 88 | 88 | |
| 89 | - add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 ); |
|
| 89 | + add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 ); |
|
| 90 | 90 | |
| 91 | - // add template path to check for field |
|
| 92 | - add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
|
| 91 | + // add template path to check for field |
|
| 92 | + add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
|
| 93 | 93 | |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | 97 | * Trigger hooks that are normally run in the admin for Addons, but need to be triggered manually because we're not in the admin |
@@ -105,73 +105,73 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Include this extension templates path |
|
| 110 | - * @param array $file_paths List of template paths ordered |
|
| 111 | - */ |
|
| 112 | - public function add_template_path( $file_paths ) { |
|
| 113 | - |
|
| 114 | - // Index 100 is the default GravityView template path. |
|
| 115 | - $file_paths[ 110 ] = self::$file; |
|
| 116 | - |
|
| 117 | - return $file_paths; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * |
|
| 122 | - * Return a well formatted nonce key according to GravityView Edit Entry protocol |
|
| 123 | - * |
|
| 124 | - * @param $view_id int GravityView view id |
|
| 125 | - * @param $form_id int Gravity Forms form id |
|
| 126 | - * @param $entry_id int Gravity Forms entry id |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - public static function get_nonce_key( $view_id, $form_id, $entry_id ) { |
|
| 130 | - return sprintf( 'edit_%d_%d_%d', $view_id, $form_id, $entry_id ); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * The edit entry link creates a secure link with a nonce |
|
| 136 | - * |
|
| 137 | - * It also mimics the URL structure Gravity Forms expects to have so that |
|
| 138 | - * it formats the display of the edit form like it does in the backend, like |
|
| 139 | - * "You can edit this post from the post page" fields, for example. |
|
| 140 | - * |
|
| 141 | - * @param $entry array Gravity Forms entry object |
|
| 142 | - * @param $view_id int GravityView view id |
|
| 143 | - * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2} |
|
| 144 | - * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } |
|
| 145 | - * @return string |
|
| 146 | - */ |
|
| 147 | - public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { |
|
| 148 | - |
|
| 149 | - $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id'] ); |
|
| 150 | - |
|
| 151 | - $base = gv_entry_link( $entry, $post_id ? : $view_id ); |
|
| 152 | - |
|
| 153 | - $url = add_query_arg( array( |
|
| 154 | - 'edit' => wp_create_nonce( $nonce_key ) |
|
| 155 | - ), $base ); |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Allow passing params to dynamically populate entry with values |
|
| 159 | - * @since 1.9.2 |
|
| 160 | - */ |
|
| 161 | - if( !empty( $field_values ) ) { |
|
| 162 | - |
|
| 163 | - if( is_array( $field_values ) ) { |
|
| 164 | - // If already an array, no parse_str() needed |
|
| 165 | - $params = $field_values; |
|
| 166 | - } else { |
|
| 167 | - parse_str( $field_values, $params ); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $url = add_query_arg( $params, $url ); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return $url; |
|
| 174 | - } |
|
| 108 | + /** |
|
| 109 | + * Include this extension templates path |
|
| 110 | + * @param array $file_paths List of template paths ordered |
|
| 111 | + */ |
|
| 112 | + public function add_template_path( $file_paths ) { |
|
| 113 | + |
|
| 114 | + // Index 100 is the default GravityView template path. |
|
| 115 | + $file_paths[ 110 ] = self::$file; |
|
| 116 | + |
|
| 117 | + return $file_paths; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * |
|
| 122 | + * Return a well formatted nonce key according to GravityView Edit Entry protocol |
|
| 123 | + * |
|
| 124 | + * @param $view_id int GravityView view id |
|
| 125 | + * @param $form_id int Gravity Forms form id |
|
| 126 | + * @param $entry_id int Gravity Forms entry id |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + public static function get_nonce_key( $view_id, $form_id, $entry_id ) { |
|
| 130 | + return sprintf( 'edit_%d_%d_%d', $view_id, $form_id, $entry_id ); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * The edit entry link creates a secure link with a nonce |
|
| 136 | + * |
|
| 137 | + * It also mimics the URL structure Gravity Forms expects to have so that |
|
| 138 | + * it formats the display of the edit form like it does in the backend, like |
|
| 139 | + * "You can edit this post from the post page" fields, for example. |
|
| 140 | + * |
|
| 141 | + * @param $entry array Gravity Forms entry object |
|
| 142 | + * @param $view_id int GravityView view id |
|
| 143 | + * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2} |
|
| 144 | + * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } |
|
| 145 | + * @return string |
|
| 146 | + */ |
|
| 147 | + public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { |
|
| 148 | + |
|
| 149 | + $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id'] ); |
|
| 150 | + |
|
| 151 | + $base = gv_entry_link( $entry, $post_id ? : $view_id ); |
|
| 152 | + |
|
| 153 | + $url = add_query_arg( array( |
|
| 154 | + 'edit' => wp_create_nonce( $nonce_key ) |
|
| 155 | + ), $base ); |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Allow passing params to dynamically populate entry with values |
|
| 159 | + * @since 1.9.2 |
|
| 160 | + */ |
|
| 161 | + if( !empty( $field_values ) ) { |
|
| 162 | + |
|
| 163 | + if( is_array( $field_values ) ) { |
|
| 164 | + // If already an array, no parse_str() needed |
|
| 165 | + $params = $field_values; |
|
| 166 | + } else { |
|
| 167 | + parse_str( $field_values, $params ); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $url = add_query_arg( $params, $url ); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return $url; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | /** |
| 177 | 177 | * Edit mode doesn't allow certain field types. |
@@ -225,82 +225,82 @@ discard block |
||
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * checks if user has permissions to edit a specific entry |
|
| 230 | - * |
|
| 231 | - * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! |
|
| 232 | - * |
|
| 233 | - * @param array $entry Gravity Forms entry array |
|
| 234 | - * @param int $view_id ID of the view you want to check visibility against {@since 1.9.2}. Required since 2.0 |
|
| 235 | - * @return bool |
|
| 236 | - */ |
|
| 237 | - public static function check_user_cap_edit_entry( $entry, $view_id = 0 ) { |
|
| 228 | + /** |
|
| 229 | + * checks if user has permissions to edit a specific entry |
|
| 230 | + * |
|
| 231 | + * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! |
|
| 232 | + * |
|
| 233 | + * @param array $entry Gravity Forms entry array |
|
| 234 | + * @param int $view_id ID of the view you want to check visibility against {@since 1.9.2}. Required since 2.0 |
|
| 235 | + * @return bool |
|
| 236 | + */ |
|
| 237 | + public static function check_user_cap_edit_entry( $entry, $view_id = 0 ) { |
|
| 238 | 238 | |
| 239 | - // No permission by default |
|
| 240 | - $user_can_edit = false; |
|
| 239 | + // No permission by default |
|
| 240 | + $user_can_edit = false; |
|
| 241 | 241 | |
| 242 | - // If they can edit any entries (as defined in Gravity Forms) |
|
| 243 | - // Or if they can edit other people's entries |
|
| 244 | - // Then we're good. |
|
| 245 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { |
|
| 242 | + // If they can edit any entries (as defined in Gravity Forms) |
|
| 243 | + // Or if they can edit other people's entries |
|
| 244 | + // Then we're good. |
|
| 245 | + if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { |
|
| 246 | 246 | |
| 247 | - gravityview()->log->debug( 'User has ability to edit all entries.' ); |
|
| 247 | + gravityview()->log->debug( 'User has ability to edit all entries.' ); |
|
| 248 | 248 | |
| 249 | - $user_can_edit = true; |
|
| 249 | + $user_can_edit = true; |
|
| 250 | 250 | |
| 251 | - } else if( !isset( $entry['created_by'] ) ) { |
|
| 251 | + } else if( !isset( $entry['created_by'] ) ) { |
|
| 252 | 252 | |
| 253 | - gravityview()->log->error( 'Entry `created_by` doesn\'t exist.'); |
|
| 253 | + gravityview()->log->error( 'Entry `created_by` doesn\'t exist.'); |
|
| 254 | 254 | |
| 255 | - $user_can_edit = false; |
|
| 255 | + $user_can_edit = false; |
|
| 256 | 256 | |
| 257 | - } else { |
|
| 257 | + } else { |
|
| 258 | 258 | |
| 259 | - // get user_edit setting |
|
| 260 | - if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) { |
|
| 261 | - // if View ID not specified or is the current view |
|
| 259 | + // get user_edit setting |
|
| 260 | + if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) { |
|
| 261 | + // if View ID not specified or is the current view |
|
| 262 | 262 | // @deprecated path |
| 263 | - $user_edit = GravityView_View::getInstance()->getAtts('user_edit'); |
|
| 264 | - } else { |
|
| 265 | - // in case is specified and not the current view |
|
| 266 | - $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' ); |
|
| 267 | - } |
|
| 263 | + $user_edit = GravityView_View::getInstance()->getAtts('user_edit'); |
|
| 264 | + } else { |
|
| 265 | + // in case is specified and not the current view |
|
| 266 | + $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' ); |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - $current_user = wp_get_current_user(); |
|
| 269 | + $current_user = wp_get_current_user(); |
|
| 270 | 270 | |
| 271 | - // User edit is disabled |
|
| 272 | - if( empty( $user_edit ) ) { |
|
| 271 | + // User edit is disabled |
|
| 272 | + if( empty( $user_edit ) ) { |
|
| 273 | 273 | |
| 274 | - gravityview()->log->debug( 'User Edit is disabled. Returning false.' ); |
|
| 274 | + gravityview()->log->debug( 'User Edit is disabled. Returning false.' ); |
|
| 275 | 275 | |
| 276 | - $user_can_edit = false; |
|
| 277 | - } |
|
| 276 | + $user_can_edit = false; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. |
|
| 280 | - else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
| 279 | + // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. |
|
| 280 | + else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
| 281 | 281 | |
| 282 | - gravityview()->log->debug( 'User {user_id} created the entry.', array( 'user_id', $current_user->ID ) ); |
|
| 282 | + gravityview()->log->debug( 'User {user_id} created the entry.', array( 'user_id', $current_user->ID ) ); |
|
| 283 | 283 | |
| 284 | - $user_can_edit = true; |
|
| 284 | + $user_can_edit = true; |
|
| 285 | 285 | |
| 286 | - } else if( ! is_user_logged_in() ) { |
|
| 286 | + } else if( ! is_user_logged_in() ) { |
|
| 287 | 287 | |
| 288 | - gravityview()->log->debug( 'No user defined; edit entry requires logged in user' ); |
|
| 289 | - } |
|
| 288 | + gravityview()->log->debug( 'No user defined; edit entry requires logged in user' ); |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - } |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. |
|
| 295 | - * @since 1.15 Added `$entry` and `$view_id` parameters |
|
| 296 | - * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false) |
|
| 297 | - * @param[in] array $entry Gravity Forms entry array {@since 1.15} |
|
| 298 | - * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15} |
|
| 299 | - */ |
|
| 300 | - $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id ); |
|
| 293 | + /** |
|
| 294 | + * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. |
|
| 295 | + * @since 1.15 Added `$entry` and `$view_id` parameters |
|
| 296 | + * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false) |
|
| 297 | + * @param[in] array $entry Gravity Forms entry array {@since 1.15} |
|
| 298 | + * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15} |
|
| 299 | + */ |
|
| 300 | + $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id ); |
|
| 301 | 301 | |
| 302 | - return (bool)$user_can_edit; |
|
| 303 | - } |
|
| 302 | + return (bool)$user_can_edit; |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | 305 | |
| 306 | 306 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | if ( ! defined( 'WPINC' ) ) { |
| 14 | - die; |
|
| 14 | + die; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -22,104 +22,104 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * @var GravityView_Edit_Entry |
| 24 | 24 | */ |
| 25 | - protected $loader; |
|
| 25 | + protected $loader; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var WP_User|null Temporary storage used by restore_user_details() |
|
| 29 | - */ |
|
| 30 | - private $_user_before_update = null; |
|
| 27 | + /** |
|
| 28 | + * @var WP_User|null Temporary storage used by restore_user_details() |
|
| 29 | + */ |
|
| 30 | + private $_user_before_update = null; |
|
| 31 | 31 | |
| 32 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
| 33 | - $this->loader = $loader; |
|
| 34 | - } |
|
| 32 | + function __construct( GravityView_Edit_Entry $loader ) { |
|
| 33 | + $this->loader = $loader; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * @since 1.11 |
| 38 | 38 | */ |
| 39 | 39 | public function load() { |
| 40 | 40 | add_action( 'wp', array( $this, 'add_hooks' ), 10 ); |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Add hooks to trigger updating the user |
| 45 | 45 | * |
| 46 | 46 | * @since 1.18 |
| 47 | 47 | */ |
| 48 | - public function add_hooks() { |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated? |
|
| 52 | - * @since 1.11 |
|
| 53 | - * @param boolean $boolean Whether to trigger update on user registration (default: true) |
|
| 54 | - */ |
|
| 55 | - if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
| 56 | - |
|
| 57 | - add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
| 58 | - |
|
| 59 | - // last resort in case the current user display name don't match any of the defaults |
|
| 60 | - add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Update the WordPress user profile based on the GF User Registration create feed |
|
| 66 | - * |
|
| 67 | - * @since 1.11 |
|
| 68 | - * |
|
| 69 | - * @param array $form Gravity Forms form array |
|
| 70 | - * @param string $entry_id Gravity Forms entry ID |
|
| 71 | - * @return void |
|
| 72 | - */ |
|
| 73 | - public function update_user( $form = array(), $entry_id = 0 ) { |
|
| 74 | - |
|
| 75 | - if( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) ) { |
|
| 76 | - gravityview()->log->error( 'GFAPI or User Registration class not found; not updating the user' ); |
|
| 77 | - return; |
|
| 78 | - } elseif( empty( $entry_id ) ) { |
|
| 79 | - gravityview()->log->error( 'Entry ID is empty [{entry_id}]; not updating the user', array( 'entry_id' => $entry_id ) ); |
|
| 80 | - return; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** @var GF_User_Registration $gf_user_registration */ |
|
| 84 | - $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 85 | - |
|
| 86 | - $entry = GFAPI::get_entry( $entry_id ); |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
| 90 | - * @since 1.11 |
|
| 91 | - * @param array $entry Gravity Forms entry |
|
| 92 | - * @param array $form Gravity Forms form |
|
| 93 | - */ |
|
| 94 | - $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
| 95 | - |
|
| 96 | - $config = $this->get_feed_configuration( $entry, $form ); |
|
| 97 | - |
|
| 98 | - // Make sure the feed is active |
|
| 99 | - if ( ! \GV\Utils::get( $config, 'is_active', false ) ) { |
|
| 48 | + public function add_hooks() { |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated? |
|
| 52 | + * @since 1.11 |
|
| 53 | + * @param boolean $boolean Whether to trigger update on user registration (default: true) |
|
| 54 | + */ |
|
| 55 | + if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
| 56 | + |
|
| 57 | + add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
| 58 | + |
|
| 59 | + // last resort in case the current user display name don't match any of the defaults |
|
| 60 | + add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Update the WordPress user profile based on the GF User Registration create feed |
|
| 66 | + * |
|
| 67 | + * @since 1.11 |
|
| 68 | + * |
|
| 69 | + * @param array $form Gravity Forms form array |
|
| 70 | + * @param string $entry_id Gravity Forms entry ID |
|
| 71 | + * @return void |
|
| 72 | + */ |
|
| 73 | + public function update_user( $form = array(), $entry_id = 0 ) { |
|
| 74 | + |
|
| 75 | + if( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) ) { |
|
| 76 | + gravityview()->log->error( 'GFAPI or User Registration class not found; not updating the user' ); |
|
| 100 | 77 | return; |
| 101 | - } |
|
| 78 | + } elseif( empty( $entry_id ) ) { |
|
| 79 | + gravityview()->log->error( 'Entry ID is empty [{entry_id}]; not updating the user', array( 'entry_id' => $entry_id ) ); |
|
| 80 | + return; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** @var GF_User_Registration $gf_user_registration */ |
|
| 84 | + $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 85 | + |
|
| 86 | + $entry = GFAPI::get_entry( $entry_id ); |
|
| 102 | 87 | |
| 103 | - // If an Update feed, make sure the conditions are met. |
|
| 104 | - if ( \GV\Utils::get( $config, 'meta/feedType' ) === 'update' ) { |
|
| 105 | - if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 106 | - return; |
|
| 107 | - } |
|
| 108 | - } |
|
| 88 | + /** |
|
| 89 | + * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
| 90 | + * @since 1.11 |
|
| 91 | + * @param array $entry Gravity Forms entry |
|
| 92 | + * @param array $form Gravity Forms form |
|
| 93 | + */ |
|
| 94 | + $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
| 95 | + |
|
| 96 | + $config = $this->get_feed_configuration( $entry, $form ); |
|
| 97 | + |
|
| 98 | + // Make sure the feed is active |
|
| 99 | + if ( ! \GV\Utils::get( $config, 'is_active', false ) ) { |
|
| 100 | + return; |
|
| 101 | + } |
|
| 109 | 102 | |
| 110 | - // The priority is set to 3 so that default priority (10) will still override it |
|
| 111 | - add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 112 | - add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 103 | + // If an Update feed, make sure the conditions are met. |
|
| 104 | + if ( \GV\Utils::get( $config, 'meta/feedType' ) === 'update' ) { |
|
| 105 | + if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 108 | + } |
|
| 113 | 109 | |
| 114 | - // Trigger the User Registration update user method |
|
| 115 | - $gf_user_registration->update_user( $entry, $form, $config ); |
|
| 110 | + // The priority is set to 3 so that default priority (10) will still override it |
|
| 111 | + add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 112 | + add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 116 | 113 | |
| 117 | - remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 118 | - remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 114 | + // Trigger the User Registration update user method |
|
| 115 | + $gf_user_registration->update_user( $entry, $form, $config ); |
|
| 119 | 116 | |
| 120 | - // Prevent double-triggering by removing the hook |
|
| 121 | - remove_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10 ); |
|
| 122 | - } |
|
| 117 | + remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 118 | + remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 119 | + |
|
| 120 | + // Prevent double-triggering by removing the hook |
|
| 121 | + remove_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10 ); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * Get the User Registration feed configuration for the entry & form |
@@ -134,185 +134,185 @@ discard block |
||
| 134 | 134 | * |
| 135 | 135 | * @return array |
| 136 | 136 | */ |
| 137 | - public function get_feed_configuration( $entry, $form ) { |
|
| 138 | - |
|
| 139 | - /** @var GF_User_Registration $gf_user_registration */ |
|
| 140 | - $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 141 | - |
|
| 142 | - $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
| 146 | - * @since 1.15 |
|
| 147 | - * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
| 148 | - * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
| 149 | - * @param[in] array $form Gravity Forms form array |
|
| 150 | - * @param[in] array $entry Gravity Forms entry being edited |
|
| 151 | - */ |
|
| 152 | - $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
| 153 | - |
|
| 154 | - if( $preserve_role ) { |
|
| 155 | - $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Make sure the current display name is not changed with the update user method. |
|
| 162 | - * @since 1.15 |
|
| 163 | - */ |
|
| 164 | - $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
| 168 | - * @since 1.14 |
|
| 169 | - * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
| 170 | - * @param[in] array $form Gravity Forms form array |
|
| 171 | - * @param[in] array $entry Gravity Forms entry being edited |
|
| 172 | - */ |
|
| 173 | - $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
| 174 | - |
|
| 175 | - return $config; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Calculate the user display name format |
|
| 180 | - * |
|
| 181 | - * @since 1.15 |
|
| 182 | - * @since 1.20 Returns false if user not found at $user_id |
|
| 183 | - * |
|
| 184 | - * @param int $user_id WP User ID |
|
| 185 | - * @return false|string Display name format as used inside Gravity Forms User Registration. Returns false if user not found. |
|
| 186 | - */ |
|
| 187 | - public function match_current_display_name( $user_id ) { |
|
| 188 | - |
|
| 189 | - $user = get_userdata( $user_id ); |
|
| 190 | - |
|
| 191 | - if( ! $user ) { |
|
| 192 | - return false; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - $names = $this->generate_display_names( $user ); |
|
| 196 | - |
|
| 197 | - $format = array_search( $user->display_name, $names, true ); |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
|
| 201 | - * @see restore_display_name |
|
| 202 | - */ |
|
| 203 | - if( false === $format ) { |
|
| 204 | - $this->_user_before_update = $user; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - return $format; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Generate an array of all the user display names possibilities |
|
| 212 | - * |
|
| 213 | - * @since 1.15 |
|
| 214 | - * |
|
| 215 | - * @param object $profileuser WP_User object |
|
| 216 | - * @return array List all the possible display names for a certain User object |
|
| 217 | - */ |
|
| 218 | - public function generate_display_names( $profileuser ) { |
|
| 219 | - |
|
| 220 | - $public_display = array(); |
|
| 221 | - $public_display['nickname'] = $profileuser->nickname; |
|
| 222 | - $public_display['username'] = $profileuser->user_login; |
|
| 223 | - |
|
| 224 | - if ( !empty($profileuser->first_name) ) { |
|
| 225 | - $public_display['firstname'] = $profileuser->first_name; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - if ( !empty($profileuser->last_name) ) { |
|
| 229 | - $public_display['lastname'] = $profileuser->last_name; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
| 233 | - $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
| 234 | - $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - $public_display = array_map( 'trim', $public_display ); |
|
| 238 | - $public_display = array_unique( $public_display ); |
|
| 239 | - |
|
| 240 | - return $public_display; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
| 246 | - * |
|
| 247 | - * @see GFUser::update_user() |
|
| 248 | - * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
| 249 | - * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
| 250 | - * @param array $entry The Gravity Forms entry that was just updated |
|
| 251 | - * @param string $password User password |
|
| 252 | - * @return int|false|WP_Error|null True: User updated; False: $user_id not a valid User ID; WP_Error: User update error; Null: Method didn't process |
|
| 253 | - */ |
|
| 254 | - public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
| 258 | - * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
| 259 | - * @since 1.14.4 |
|
| 260 | - * @param boolean $restore_display_name Restore Display Name? Default: true |
|
| 261 | - */ |
|
| 262 | - $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
| 263 | - |
|
| 264 | - $is_update_feed = ( $config && \GV\Utils::get( $config, 'meta/feed_type' ) === 'update' ); |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Don't restore display name: |
|
| 268 | - * - either disabled, |
|
| 269 | - * - or it is an Update feed (we only care about Create feed) |
|
| 270 | - * - or we don't need as we found the correct format before updating user. |
|
| 271 | - * @since 1.14.4 |
|
| 272 | - */ |
|
| 273 | - if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 274 | - return null; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - $user_after_update = get_userdata( $user_id ); |
|
| 278 | - |
|
| 279 | - // User not found |
|
| 280 | - if ( ! $user_after_update ) { |
|
| 281 | - gravityview()->log->error( 'User not found at $user_id #{user_id}', array( 'user_id' => $user_id ) ); |
|
| 282 | - return false; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $restored_user = $user_after_update; |
|
| 286 | - |
|
| 287 | - // Restore previous display_name |
|
| 288 | - $restored_user->display_name = $this->_user_before_update->display_name; |
|
| 289 | - |
|
| 290 | - // Don't have WP update the password. |
|
| 291 | - unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
| 295 | - * @since 1.14 |
|
| 296 | - * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
| 297 | - * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
| 298 | - * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
| 299 | - * @param array $entry The Gravity Forms entry that was just updated |
|
| 300 | - */ |
|
| 301 | - $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
| 302 | - |
|
| 303 | - $updated = wp_update_user( $restored_user ); |
|
| 304 | - |
|
| 305 | - if( is_wp_error( $updated ) ) { |
|
| 306 | - gravityview()->log->error( 'There was an error updating user #{user_id} details', array( 'user_id' => $user_id, 'data' => $updated ) ); |
|
| 307 | - } else { |
|
| 308 | - gravityview()->log->debug( 'User #{user_id} details restored', array( 'user_id' => $user_id ) ); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - $this->_user_before_update = null; |
|
| 312 | - |
|
| 313 | - unset( $restored_user, $user_after_update ); |
|
| 314 | - |
|
| 315 | - return $updated; |
|
| 316 | - } |
|
| 137 | + public function get_feed_configuration( $entry, $form ) { |
|
| 138 | + |
|
| 139 | + /** @var GF_User_Registration $gf_user_registration */ |
|
| 140 | + $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 141 | + |
|
| 142 | + $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
| 146 | + * @since 1.15 |
|
| 147 | + * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
| 148 | + * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
| 149 | + * @param[in] array $form Gravity Forms form array |
|
| 150 | + * @param[in] array $entry Gravity Forms entry being edited |
|
| 151 | + */ |
|
| 152 | + $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
| 153 | + |
|
| 154 | + if( $preserve_role ) { |
|
| 155 | + $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Make sure the current display name is not changed with the update user method. |
|
| 162 | + * @since 1.15 |
|
| 163 | + */ |
|
| 164 | + $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
| 168 | + * @since 1.14 |
|
| 169 | + * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
| 170 | + * @param[in] array $form Gravity Forms form array |
|
| 171 | + * @param[in] array $entry Gravity Forms entry being edited |
|
| 172 | + */ |
|
| 173 | + $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
| 174 | + |
|
| 175 | + return $config; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Calculate the user display name format |
|
| 180 | + * |
|
| 181 | + * @since 1.15 |
|
| 182 | + * @since 1.20 Returns false if user not found at $user_id |
|
| 183 | + * |
|
| 184 | + * @param int $user_id WP User ID |
|
| 185 | + * @return false|string Display name format as used inside Gravity Forms User Registration. Returns false if user not found. |
|
| 186 | + */ |
|
| 187 | + public function match_current_display_name( $user_id ) { |
|
| 188 | + |
|
| 189 | + $user = get_userdata( $user_id ); |
|
| 190 | + |
|
| 191 | + if( ! $user ) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + $names = $this->generate_display_names( $user ); |
|
| 196 | + |
|
| 197 | + $format = array_search( $user->display_name, $names, true ); |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
|
| 201 | + * @see restore_display_name |
|
| 202 | + */ |
|
| 203 | + if( false === $format ) { |
|
| 204 | + $this->_user_before_update = $user; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + return $format; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Generate an array of all the user display names possibilities |
|
| 212 | + * |
|
| 213 | + * @since 1.15 |
|
| 214 | + * |
|
| 215 | + * @param object $profileuser WP_User object |
|
| 216 | + * @return array List all the possible display names for a certain User object |
|
| 217 | + */ |
|
| 218 | + public function generate_display_names( $profileuser ) { |
|
| 219 | + |
|
| 220 | + $public_display = array(); |
|
| 221 | + $public_display['nickname'] = $profileuser->nickname; |
|
| 222 | + $public_display['username'] = $profileuser->user_login; |
|
| 223 | + |
|
| 224 | + if ( !empty($profileuser->first_name) ) { |
|
| 225 | + $public_display['firstname'] = $profileuser->first_name; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + if ( !empty($profileuser->last_name) ) { |
|
| 229 | + $public_display['lastname'] = $profileuser->last_name; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
| 233 | + $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
| 234 | + $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + $public_display = array_map( 'trim', $public_display ); |
|
| 238 | + $public_display = array_unique( $public_display ); |
|
| 239 | + |
|
| 240 | + return $public_display; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
| 246 | + * |
|
| 247 | + * @see GFUser::update_user() |
|
| 248 | + * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
| 249 | + * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
| 250 | + * @param array $entry The Gravity Forms entry that was just updated |
|
| 251 | + * @param string $password User password |
|
| 252 | + * @return int|false|WP_Error|null True: User updated; False: $user_id not a valid User ID; WP_Error: User update error; Null: Method didn't process |
|
| 253 | + */ |
|
| 254 | + public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
| 258 | + * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
| 259 | + * @since 1.14.4 |
|
| 260 | + * @param boolean $restore_display_name Restore Display Name? Default: true |
|
| 261 | + */ |
|
| 262 | + $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
| 263 | + |
|
| 264 | + $is_update_feed = ( $config && \GV\Utils::get( $config, 'meta/feed_type' ) === 'update' ); |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Don't restore display name: |
|
| 268 | + * - either disabled, |
|
| 269 | + * - or it is an Update feed (we only care about Create feed) |
|
| 270 | + * - or we don't need as we found the correct format before updating user. |
|
| 271 | + * @since 1.14.4 |
|
| 272 | + */ |
|
| 273 | + if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 274 | + return null; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + $user_after_update = get_userdata( $user_id ); |
|
| 278 | + |
|
| 279 | + // User not found |
|
| 280 | + if ( ! $user_after_update ) { |
|
| 281 | + gravityview()->log->error( 'User not found at $user_id #{user_id}', array( 'user_id' => $user_id ) ); |
|
| 282 | + return false; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $restored_user = $user_after_update; |
|
| 286 | + |
|
| 287 | + // Restore previous display_name |
|
| 288 | + $restored_user->display_name = $this->_user_before_update->display_name; |
|
| 289 | + |
|
| 290 | + // Don't have WP update the password. |
|
| 291 | + unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
| 295 | + * @since 1.14 |
|
| 296 | + * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
| 297 | + * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
| 298 | + * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
| 299 | + * @param array $entry The Gravity Forms entry that was just updated |
|
| 300 | + */ |
|
| 301 | + $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
| 302 | + |
|
| 303 | + $updated = wp_update_user( $restored_user ); |
|
| 304 | + |
|
| 305 | + if( is_wp_error( $updated ) ) { |
|
| 306 | + gravityview()->log->error( 'There was an error updating user #{user_id} details', array( 'user_id' => $user_id, 'data' => $updated ) ); |
|
| 307 | + } else { |
|
| 308 | + gravityview()->log->debug( 'User #{user_id} details restored', array( 'user_id' => $user_id ) ); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + $this->_user_before_update = null; |
|
| 312 | + |
|
| 313 | + unset( $restored_user, $user_after_update ); |
|
| 314 | + |
|
| 315 | + return $updated; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | 318 | } //end class |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | public function prevent_maybe_process_form() { |
| 161 | 161 | |
| 162 | 162 | if( ! empty( $_POST ) ) { |
| 163 | - gravityview()->log->debug( 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', array( 'data' => esc_html( print_r( $_POST, true ) ) ) ); |
|
| 163 | + gravityview()->log->debug( 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', array( 'data' => esc_html( print_r( $_POST, true ) ) ) ); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | if( $this->is_edit_entry_submission() ) { |
| 167 | 167 | remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
| 168 | - remove_action( 'wp', array( 'GFForms', 'maybe_process_form'), 9 ); |
|
| 168 | + remove_action( 'wp', array( 'GFForms', 'maybe_process_form'), 9 ); |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
@@ -197,8 +197,8 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | |
| 199 | 199 | $entries = $gravityview_view->getEntries(); |
| 200 | - self::$original_entry = $entries[0]; |
|
| 201 | - $this->entry = $entries[0]; |
|
| 200 | + self::$original_entry = $entries[0]; |
|
| 201 | + $this->entry = $entries[0]; |
|
| 202 | 202 | |
| 203 | 203 | self::$original_form = $gravityview_view->getForm(); |
| 204 | 204 | $this->form = $gravityview_view->getForm(); |
@@ -322,8 +322,8 @@ discard block |
||
| 322 | 322 | |
| 323 | 323 | GFFormsModel::save_lead( $form, $this->entry ); |
| 324 | 324 | |
| 325 | - // Delete the values for hidden inputs |
|
| 326 | - $this->unset_hidden_field_values(); |
|
| 325 | + // Delete the values for hidden inputs |
|
| 326 | + $this->unset_hidden_field_values(); |
|
| 327 | 327 | |
| 328 | 328 | $this->entry['date_created'] = $date_created; |
| 329 | 329 | |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | // Perform actions normally performed after updating a lead |
| 334 | 334 | $this->after_update(); |
| 335 | 335 | |
| 336 | - /** |
|
| 336 | + /** |
|
| 337 | 337 | * Must be AFTER after_update()! |
| 338 | 338 | * @see https://github.com/gravityview/GravityView/issues/764 |
| 339 | 339 | */ |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | * @return void |
| 364 | 364 | */ |
| 365 | 365 | private function unset_hidden_field_values() { |
| 366 | - global $wpdb; |
|
| 366 | + global $wpdb; |
|
| 367 | 367 | |
| 368 | 368 | /** |
| 369 | 369 | * @filter `gravityview/edit_entry/unset_hidden_field_values` Whether to delete values of fields hidden by conditional logic |
@@ -385,27 +385,27 @@ discard block |
||
| 385 | 385 | $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $this->entry['id'] ) ); |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - foreach ( $this->entry as $input_id => $field_value ) { |
|
| 388 | + foreach ( $this->entry as $input_id => $field_value ) { |
|
| 389 | 389 | |
| 390 | - $field = RGFormsModel::get_field( $this->form, $input_id ); |
|
| 390 | + $field = RGFormsModel::get_field( $this->form, $input_id ); |
|
| 391 | 391 | |
| 392 | - // Reset fields that are hidden |
|
| 393 | - // Don't pass $entry as fourth parameter; force using $_POST values to calculate conditional logic |
|
| 394 | - if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), NULL ) ) { |
|
| 392 | + // Reset fields that are hidden |
|
| 393 | + // Don't pass $entry as fourth parameter; force using $_POST values to calculate conditional logic |
|
| 394 | + if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), NULL ) ) { |
|
| 395 | 395 | |
| 396 | - // List fields are stored as empty arrays when empty |
|
| 397 | - $empty_value = $this->is_field_json_encoded( $field ) ? '[]' : ''; |
|
| 396 | + // List fields are stored as empty arrays when empty |
|
| 397 | + $empty_value = $this->is_field_json_encoded( $field ) ? '[]' : ''; |
|
| 398 | 398 | |
| 399 | - $lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id ); |
|
| 399 | + $lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id ); |
|
| 400 | 400 | |
| 401 | - GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value ); |
|
| 401 | + GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value ); |
|
| 402 | 402 | |
| 403 | - // Prevent the $_POST values of hidden fields from being used as default values when rendering the form |
|
| 403 | + // Prevent the $_POST values of hidden fields from being used as default values when rendering the form |
|
| 404 | 404 | // after submission |
| 405 | - $post_input_id = 'input_' . str_replace( '.', '_', $input_id ); |
|
| 406 | - $_POST[ $post_input_id ] = ''; |
|
| 407 | - } |
|
| 408 | - } |
|
| 405 | + $post_input_id = 'input_' . str_replace( '.', '_', $input_id ); |
|
| 406 | + $_POST[ $post_input_id ] = ''; |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | |
| 500 | 500 | $form = $this->form; |
| 501 | 501 | |
| 502 | - /** @var GF_Field $field */ |
|
| 502 | + /** @var GF_Field $field */ |
|
| 503 | 503 | foreach( $form['fields'] as $k => &$field ) { |
| 504 | 504 | |
| 505 | 505 | /** |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | |
| 516 | 516 | if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
| 517 | 517 | foreach( $field->inputs as $key => $input ) { |
| 518 | - $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 518 | + $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 519 | 519 | } |
| 520 | 520 | } |
| 521 | 521 | } |
@@ -536,13 +536,13 @@ discard block |
||
| 536 | 536 | foreach ( $this->fields_with_calculation as $calc_field ) { |
| 537 | 537 | $inputs = $calc_field->get_entry_inputs(); |
| 538 | 538 | if ( is_array( $inputs ) ) { |
| 539 | - foreach ( $inputs as $input ) { |
|
| 540 | - $input_name = 'input_' . str_replace( '.', '_', $input['id'] ); |
|
| 541 | - $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 542 | - } |
|
| 539 | + foreach ( $inputs as $input ) { |
|
| 540 | + $input_name = 'input_' . str_replace( '.', '_', $input['id'] ); |
|
| 541 | + $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 542 | + } |
|
| 543 | 543 | } else { |
| 544 | - $input_name = 'input_' . str_replace( '.', '_', $calc_field->id); |
|
| 545 | - $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 544 | + $input_name = 'input_' . str_replace( '.', '_', $calc_field->id); |
|
| 545 | + $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 546 | 546 | } |
| 547 | 547 | } |
| 548 | 548 | |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] ); |
| 591 | 591 | |
| 592 | 592 | $ary = ! empty( $value ) ? explode( '|:|', $value ) : array(); |
| 593 | - $ary = stripslashes_deep( $ary ); |
|
| 593 | + $ary = stripslashes_deep( $ary ); |
|
| 594 | 594 | $img_url = \GV\Utils::get( $ary, 0 ); |
| 595 | 595 | |
| 596 | 596 | $img_title = count( $ary ) > 1 ? $ary[1] : ''; |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | private function maybe_update_post_fields( $form ) { |
| 664 | 664 | |
| 665 | 665 | if( empty( $this->entry['post_id'] ) ) { |
| 666 | - gravityview()->log->debug( 'This entry has no post fields. Continuing...' ); |
|
| 666 | + gravityview()->log->debug( 'This entry has no post fields. Continuing...' ); |
|
| 667 | 667 | return; |
| 668 | 668 | } |
| 669 | 669 | |
@@ -698,51 +698,51 @@ discard block |
||
| 698 | 698 | |
| 699 | 699 | switch( $field->type ) { |
| 700 | 700 | |
| 701 | - case 'post_title': |
|
| 702 | - $post_title = $value; |
|
| 703 | - if ( \GV\Utils::get( $form, 'postTitleTemplateEnabled' ) ) { |
|
| 704 | - $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp ); |
|
| 705 | - } |
|
| 706 | - $updated_post->post_title = $post_title; |
|
| 707 | - $updated_post->post_name = $post_title; |
|
| 708 | - unset( $post_title ); |
|
| 709 | - break; |
|
| 710 | - |
|
| 711 | - case 'post_content': |
|
| 712 | - $post_content = $value; |
|
| 713 | - if ( \GV\Utils::get( $form, 'postContentTemplateEnabled' ) ) { |
|
| 714 | - $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true ); |
|
| 715 | - } |
|
| 716 | - $updated_post->post_content = $post_content; |
|
| 717 | - unset( $post_content ); |
|
| 718 | - break; |
|
| 719 | - case 'post_excerpt': |
|
| 720 | - $updated_post->post_excerpt = $value; |
|
| 721 | - break; |
|
| 722 | - case 'post_tags': |
|
| 723 | - wp_set_post_tags( $post_id, $value, false ); |
|
| 724 | - break; |
|
| 725 | - case 'post_category': |
|
| 726 | - break; |
|
| 727 | - case 'post_custom_field': |
|
| 701 | + case 'post_title': |
|
| 702 | + $post_title = $value; |
|
| 703 | + if ( \GV\Utils::get( $form, 'postTitleTemplateEnabled' ) ) { |
|
| 704 | + $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp ); |
|
| 705 | + } |
|
| 706 | + $updated_post->post_title = $post_title; |
|
| 707 | + $updated_post->post_name = $post_title; |
|
| 708 | + unset( $post_title ); |
|
| 709 | + break; |
|
| 710 | + |
|
| 711 | + case 'post_content': |
|
| 712 | + $post_content = $value; |
|
| 713 | + if ( \GV\Utils::get( $form, 'postContentTemplateEnabled' ) ) { |
|
| 714 | + $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true ); |
|
| 715 | + } |
|
| 716 | + $updated_post->post_content = $post_content; |
|
| 717 | + unset( $post_content ); |
|
| 718 | + break; |
|
| 719 | + case 'post_excerpt': |
|
| 720 | + $updated_post->post_excerpt = $value; |
|
| 721 | + break; |
|
| 722 | + case 'post_tags': |
|
| 723 | + wp_set_post_tags( $post_id, $value, false ); |
|
| 724 | + break; |
|
| 725 | + case 'post_category': |
|
| 726 | + break; |
|
| 727 | + case 'post_custom_field': |
|
| 728 | 728 | if ( is_array( $value ) && ( floatval( $field_id ) !== floatval( $field->id ) ) ) { |
| 729 | 729 | $value = $value[ $field_id ]; |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | - if( ! empty( $field->customFieldTemplateEnabled ) ) { |
|
| 733 | - $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true ); |
|
| 734 | - } |
|
| 732 | + if( ! empty( $field->customFieldTemplateEnabled ) ) { |
|
| 733 | + $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true ); |
|
| 734 | + } |
|
| 735 | 735 | |
| 736 | - if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) { |
|
| 737 | - $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); |
|
| 738 | - } |
|
| 736 | + if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) { |
|
| 737 | + $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); |
|
| 738 | + } |
|
| 739 | 739 | |
| 740 | - update_post_meta( $post_id, $field->postCustomFieldName, $value ); |
|
| 741 | - break; |
|
| 740 | + update_post_meta( $post_id, $field->postCustomFieldName, $value ); |
|
| 741 | + break; |
|
| 742 | 742 | |
| 743 | - case 'post_image': |
|
| 744 | - $value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id ); |
|
| 745 | - break; |
|
| 743 | + case 'post_image': |
|
| 744 | + $value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id ); |
|
| 745 | + break; |
|
| 746 | 746 | |
| 747 | 747 | } |
| 748 | 748 | |
@@ -787,20 +787,20 @@ discard block |
||
| 787 | 787 | */ |
| 788 | 788 | private function is_field_json_encoded( $field ) { |
| 789 | 789 | |
| 790 | - $json_encoded = false; |
|
| 790 | + $json_encoded = false; |
|
| 791 | 791 | |
| 792 | 792 | $input_type = RGFormsModel::get_input_type( $field ); |
| 793 | 793 | |
| 794 | - // Only certain custom field types are supported |
|
| 795 | - switch( $input_type ) { |
|
| 796 | - case 'fileupload': |
|
| 797 | - case 'list': |
|
| 798 | - case 'multiselect': |
|
| 799 | - $json_encoded = true; |
|
| 800 | - break; |
|
| 801 | - } |
|
| 794 | + // Only certain custom field types are supported |
|
| 795 | + switch( $input_type ) { |
|
| 796 | + case 'fileupload': |
|
| 797 | + case 'list': |
|
| 798 | + case 'multiselect': |
|
| 799 | + $json_encoded = true; |
|
| 800 | + break; |
|
| 801 | + } |
|
| 802 | 802 | |
| 803 | - return $json_encoded; |
|
| 803 | + return $json_encoded; |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /** |
@@ -890,14 +890,14 @@ discard block |
||
| 890 | 890 | ?><h2 class="gv-edit-entry-title"> |
| 891 | 891 | <span><?php |
| 892 | 892 | |
| 893 | - /** |
|
| 894 | - * @filter `gravityview_edit_entry_title` Modify the edit entry title |
|
| 895 | - * @param string $edit_entry_title Modify the "Edit Entry" title |
|
| 896 | - * @param GravityView_Edit_Entry_Render $this This object |
|
| 897 | - */ |
|
| 898 | - $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 893 | + /** |
|
| 894 | + * @filter `gravityview_edit_entry_title` Modify the edit entry title |
|
| 895 | + * @param string $edit_entry_title Modify the "Edit Entry" title |
|
| 896 | + * @param GravityView_Edit_Entry_Render $this This object |
|
| 897 | + */ |
|
| 898 | + $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 899 | 899 | |
| 900 | - echo esc_attr( $edit_entry_title ); |
|
| 900 | + echo esc_attr( $edit_entry_title ); |
|
| 901 | 901 | ?></span> |
| 902 | 902 | </h2> |
| 903 | 903 | |
@@ -1006,7 +1006,7 @@ discard block |
||
| 1006 | 1006 | |
| 1007 | 1007 | ob_get_clean(); |
| 1008 | 1008 | |
| 1009 | - remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
| 1009 | + remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
| 1010 | 1010 | remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
| 1011 | 1011 | remove_filter( 'gform_disable_view_counter', '__return_true' ); |
| 1012 | 1012 | remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 ); |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | |
| 1061 | 1061 | // for now we don't support Save and Continue feature. |
| 1062 | 1062 | if( ! self::$supports_save_and_continue ) { |
| 1063 | - unset( $form['save'] ); |
|
| 1063 | + unset( $form['save'] ); |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | return $form; |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | || ! empty( $field_content ) |
| 1136 | 1136 | || in_array( $field->type, array( 'honeypot' ) ) |
| 1137 | 1137 | ) { |
| 1138 | - return $field_content; |
|
| 1138 | + return $field_content; |
|
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
@@ -1143,24 +1143,24 @@ discard block |
||
| 1143 | 1143 | |
| 1144 | 1144 | $field_value = $this->get_field_value( $field ); |
| 1145 | 1145 | |
| 1146 | - // Prevent any PHP warnings, like undefined index |
|
| 1147 | - ob_start(); |
|
| 1146 | + // Prevent any PHP warnings, like undefined index |
|
| 1147 | + ob_start(); |
|
| 1148 | 1148 | |
| 1149 | - $return = null; |
|
| 1149 | + $return = null; |
|
| 1150 | 1150 | |
| 1151 | 1151 | /** @var GravityView_Field $gv_field */ |
| 1152 | 1152 | if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { |
| 1153 | 1153 | $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field ); |
| 1154 | 1154 | } else { |
| 1155 | - $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
| 1156 | - } |
|
| 1155 | + $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
| 1156 | + } |
|
| 1157 | 1157 | |
| 1158 | - // If there was output, it's an error |
|
| 1159 | - $warnings = ob_get_clean(); |
|
| 1158 | + // If there was output, it's an error |
|
| 1159 | + $warnings = ob_get_clean(); |
|
| 1160 | 1160 | |
| 1161 | - if( !empty( $warnings ) ) { |
|
| 1162 | - gravityview()->log->error( '{warning}', array( 'warning' => $warnings, 'data' => $field_value ) ); |
|
| 1163 | - } |
|
| 1161 | + if( !empty( $warnings ) ) { |
|
| 1162 | + gravityview()->log->error( '{warning}', array( 'warning' => $warnings, 'data' => $field_value ) ); |
|
| 1163 | + } |
|
| 1164 | 1164 | |
| 1165 | 1165 | return $return; |
| 1166 | 1166 | } |
@@ -1195,8 +1195,8 @@ discard block |
||
| 1195 | 1195 | $input_id = strval( $input['id'] ); |
| 1196 | 1196 | |
| 1197 | 1197 | if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) { |
| 1198 | - $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 1199 | - $allow_pre_populated = false; |
|
| 1198 | + $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 1199 | + $allow_pre_populated = false; |
|
| 1200 | 1200 | } |
| 1201 | 1201 | |
| 1202 | 1202 | } |
@@ -1220,7 +1220,7 @@ discard block |
||
| 1220 | 1220 | if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) { |
| 1221 | 1221 | $categories = array(); |
| 1222 | 1222 | foreach ( explode( ',', $field_value ) as $cat_string ) { |
| 1223 | - $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 1223 | + $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 1224 | 1224 | } |
| 1225 | 1225 | $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
| 1226 | 1226 | } |
@@ -1230,25 +1230,25 @@ discard block |
||
| 1230 | 1230 | // if value is empty get the default value if defined |
| 1231 | 1231 | $field_value = $field->get_value_default_if_empty( $field_value ); |
| 1232 | 1232 | |
| 1233 | - /** |
|
| 1234 | - * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
|
| 1235 | - * @since 1.11 |
|
| 1236 | - * @since 1.20 Added third param |
|
| 1237 | - * @param mixed $field_value field value used to populate the input |
|
| 1238 | - * @param object $field Gravity Forms field object ( Class GF_Field ) |
|
| 1239 | - * @param GravityView_Edit_Entry_Render $this Current object |
|
| 1240 | - */ |
|
| 1241 | - $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field, $this ); |
|
| 1242 | - |
|
| 1243 | - /** |
|
| 1244 | - * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type |
|
| 1245 | - * @since 1.17 |
|
| 1246 | - * @since 1.20 Added third param |
|
| 1247 | - * @param mixed $field_value field value used to populate the input |
|
| 1248 | - * @param GF_Field $field Gravity Forms field object |
|
| 1249 | - * @param GravityView_Edit_Entry_Render $this Current object |
|
| 1250 | - */ |
|
| 1251 | - $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field, $this ); |
|
| 1233 | + /** |
|
| 1234 | + * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
|
| 1235 | + * @since 1.11 |
|
| 1236 | + * @since 1.20 Added third param |
|
| 1237 | + * @param mixed $field_value field value used to populate the input |
|
| 1238 | + * @param object $field Gravity Forms field object ( Class GF_Field ) |
|
| 1239 | + * @param GravityView_Edit_Entry_Render $this Current object |
|
| 1240 | + */ |
|
| 1241 | + $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field, $this ); |
|
| 1242 | + |
|
| 1243 | + /** |
|
| 1244 | + * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type |
|
| 1245 | + * @since 1.17 |
|
| 1246 | + * @since 1.20 Added third param |
|
| 1247 | + * @param mixed $field_value field value used to populate the input |
|
| 1248 | + * @param GF_Field $field Gravity Forms field object |
|
| 1249 | + * @param GravityView_Edit_Entry_Render $this Current object |
|
| 1250 | + */ |
|
| 1251 | + $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field, $this ); |
|
| 1252 | 1252 | |
| 1253 | 1253 | return $field_value; |
| 1254 | 1254 | } |
@@ -1275,7 +1275,7 @@ discard block |
||
| 1275 | 1275 | // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
| 1276 | 1276 | // expects certain field array items to be set. |
| 1277 | 1277 | foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { |
| 1278 | - $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
| 1278 | + $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
| 1279 | 1279 | } |
| 1280 | 1280 | |
| 1281 | 1281 | switch( RGFormsModel::get_input_type( $field ) ) { |
@@ -1289,61 +1289,61 @@ discard block |
||
| 1289 | 1289 | */ |
| 1290 | 1290 | case 'fileupload': |
| 1291 | 1291 | |
| 1292 | - // Set the previous value |
|
| 1293 | - $entry = $this->get_entry(); |
|
| 1292 | + // Set the previous value |
|
| 1293 | + $entry = $this->get_entry(); |
|
| 1294 | 1294 | |
| 1295 | - $input_name = 'input_'.$field->id; |
|
| 1296 | - $form_id = $form['id']; |
|
| 1295 | + $input_name = 'input_'.$field->id; |
|
| 1296 | + $form_id = $form['id']; |
|
| 1297 | 1297 | |
| 1298 | - $value = NULL; |
|
| 1298 | + $value = NULL; |
|
| 1299 | 1299 | |
| 1300 | - // Use the previous entry value as the default. |
|
| 1301 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1302 | - $value = $entry[ $field->id ]; |
|
| 1303 | - } |
|
| 1300 | + // Use the previous entry value as the default. |
|
| 1301 | + if( isset( $entry[ $field->id ] ) ) { |
|
| 1302 | + $value = $entry[ $field->id ]; |
|
| 1303 | + } |
|
| 1304 | 1304 | |
| 1305 | - // If this is a single upload file |
|
| 1306 | - if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 1307 | - $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 1308 | - $value = $file_path['url']; |
|
| 1305 | + // If this is a single upload file |
|
| 1306 | + if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 1307 | + $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 1308 | + $value = $file_path['url']; |
|
| 1309 | 1309 | |
| 1310 | - } else { |
|
| 1310 | + } else { |
|
| 1311 | 1311 | |
| 1312 | - // Fix PHP warning on line 1498 of form_display.php for post_image fields |
|
| 1313 | - // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
|
| 1314 | - $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 1312 | + // Fix PHP warning on line 1498 of form_display.php for post_image fields |
|
| 1313 | + // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
|
| 1314 | + $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 1315 | 1315 | |
| 1316 | - } |
|
| 1316 | + } |
|
| 1317 | 1317 | |
| 1318 | - if ( \GV\Utils::get( $field, "multipleFiles" ) ) { |
|
| 1318 | + if ( \GV\Utils::get( $field, "multipleFiles" ) ) { |
|
| 1319 | 1319 | |
| 1320 | - // If there are fresh uploads, process and merge them. |
|
| 1321 | - // Otherwise, use the passed values, which should be json-encoded array of URLs |
|
| 1322 | - if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 1323 | - $value = empty( $value ) ? '[]' : $value; |
|
| 1324 | - $value = stripslashes_deep( $value ); |
|
| 1325 | - $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 1326 | - } |
|
| 1320 | + // If there are fresh uploads, process and merge them. |
|
| 1321 | + // Otherwise, use the passed values, which should be json-encoded array of URLs |
|
| 1322 | + if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 1323 | + $value = empty( $value ) ? '[]' : $value; |
|
| 1324 | + $value = stripslashes_deep( $value ); |
|
| 1325 | + $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 1326 | + } |
|
| 1327 | 1327 | |
| 1328 | - } else { |
|
| 1328 | + } else { |
|
| 1329 | 1329 | |
| 1330 | - // A file already exists when editing an entry |
|
| 1331 | - // We set this to solve issue when file upload fields are required. |
|
| 1332 | - GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
| 1330 | + // A file already exists when editing an entry |
|
| 1331 | + // We set this to solve issue when file upload fields are required. |
|
| 1332 | + GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
| 1333 | 1333 | |
| 1334 | - } |
|
| 1334 | + } |
|
| 1335 | 1335 | |
| 1336 | - $this->entry[ $input_name ] = $value; |
|
| 1337 | - $_POST[ $input_name ] = $value; |
|
| 1336 | + $this->entry[ $input_name ] = $value; |
|
| 1337 | + $_POST[ $input_name ] = $value; |
|
| 1338 | 1338 | |
| 1339 | - break; |
|
| 1339 | + break; |
|
| 1340 | 1340 | |
| 1341 | 1341 | case 'number': |
| 1342 | - // Fix "undefined index" issue at line 1286 in form_display.php |
|
| 1343 | - if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 1344 | - $_POST['input_'.$field->id ] = NULL; |
|
| 1345 | - } |
|
| 1346 | - break; |
|
| 1342 | + // Fix "undefined index" issue at line 1286 in form_display.php |
|
| 1343 | + if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 1344 | + $_POST['input_'.$field->id ] = NULL; |
|
| 1345 | + } |
|
| 1346 | + break; |
|
| 1347 | 1347 | } |
| 1348 | 1348 | |
| 1349 | 1349 | } |
@@ -1428,42 +1428,42 @@ discard block |
||
| 1428 | 1428 | case 'fileupload' : |
| 1429 | 1429 | case 'post_image': |
| 1430 | 1430 | |
| 1431 | - // in case nothing is uploaded but there are already files saved |
|
| 1432 | - if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1433 | - $field->failed_validation = false; |
|
| 1434 | - unset( $field->validation_message ); |
|
| 1435 | - } |
|
| 1431 | + // in case nothing is uploaded but there are already files saved |
|
| 1432 | + if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1433 | + $field->failed_validation = false; |
|
| 1434 | + unset( $field->validation_message ); |
|
| 1435 | + } |
|
| 1436 | 1436 | |
| 1437 | - // validate if multi file upload reached max number of files [maxFiles] => 2 |
|
| 1438 | - if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { |
|
| 1437 | + // validate if multi file upload reached max number of files [maxFiles] => 2 |
|
| 1438 | + if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { |
|
| 1439 | 1439 | |
| 1440 | - $input_name = 'input_' . $field->id; |
|
| 1441 | - //uploaded |
|
| 1442 | - $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1440 | + $input_name = 'input_' . $field->id; |
|
| 1441 | + //uploaded |
|
| 1442 | + $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1443 | 1443 | |
| 1444 | - //existent |
|
| 1445 | - $entry = $this->get_entry(); |
|
| 1446 | - $value = NULL; |
|
| 1447 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1448 | - $value = json_decode( $entry[ $field->id ], true ); |
|
| 1449 | - } |
|
| 1444 | + //existent |
|
| 1445 | + $entry = $this->get_entry(); |
|
| 1446 | + $value = NULL; |
|
| 1447 | + if( isset( $entry[ $field->id ] ) ) { |
|
| 1448 | + $value = json_decode( $entry[ $field->id ], true ); |
|
| 1449 | + } |
|
| 1450 | 1450 | |
| 1451 | - // count uploaded files and existent entry files |
|
| 1452 | - $count_files = count( $file_names ) + count( $value ); |
|
| 1451 | + // count uploaded files and existent entry files |
|
| 1452 | + $count_files = count( $file_names ) + count( $value ); |
|
| 1453 | 1453 | |
| 1454 | - if( $count_files > $field->maxFiles ) { |
|
| 1455 | - $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
| 1456 | - $field->failed_validation = 1; |
|
| 1457 | - $gv_valid = false; |
|
| 1454 | + if( $count_files > $field->maxFiles ) { |
|
| 1455 | + $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
| 1456 | + $field->failed_validation = 1; |
|
| 1457 | + $gv_valid = false; |
|
| 1458 | 1458 | |
| 1459 | - // in case of error make sure the newest upload files are removed from the upload input |
|
| 1460 | - GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1461 | - } |
|
| 1459 | + // in case of error make sure the newest upload files are removed from the upload input |
|
| 1460 | + GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1461 | + } |
|
| 1462 | 1462 | |
| 1463 | - } |
|
| 1463 | + } |
|
| 1464 | 1464 | |
| 1465 | 1465 | |
| 1466 | - break; |
|
| 1466 | + break; |
|
| 1467 | 1467 | |
| 1468 | 1468 | } |
| 1469 | 1469 | |
@@ -1474,47 +1474,47 @@ discard block |
||
| 1474 | 1474 | |
| 1475 | 1475 | switch ( $field_type ) { |
| 1476 | 1476 | |
| 1477 | - // Captchas don't need to be re-entered. |
|
| 1478 | - case 'captcha': |
|
| 1477 | + // Captchas don't need to be re-entered. |
|
| 1478 | + case 'captcha': |
|
| 1479 | 1479 | |
| 1480 | - // Post Image fields aren't editable, so we un-fail them. |
|
| 1481 | - case 'post_image': |
|
| 1482 | - $field->failed_validation = false; |
|
| 1483 | - unset( $field->validation_message ); |
|
| 1484 | - break; |
|
| 1480 | + // Post Image fields aren't editable, so we un-fail them. |
|
| 1481 | + case 'post_image': |
|
| 1482 | + $field->failed_validation = false; |
|
| 1483 | + unset( $field->validation_message ); |
|
| 1484 | + break; |
|
| 1485 | 1485 | |
| 1486 | 1486 | } |
| 1487 | 1487 | |
| 1488 | 1488 | // You can't continue inside a switch, so we do it after. |
| 1489 | 1489 | if( empty( $field->failed_validation ) ) { |
| 1490 | - continue; |
|
| 1490 | + continue; |
|
| 1491 | 1491 | } |
| 1492 | 1492 | |
| 1493 | 1493 | // checks if the No Duplicates option is not validating entry against itself, since |
| 1494 | 1494 | // we're editing a stored entry, it would also assume it's a duplicate. |
| 1495 | 1495 | if( !empty( $field->noDuplicates ) ) { |
| 1496 | 1496 | |
| 1497 | - $entry = $this->get_entry(); |
|
| 1497 | + $entry = $this->get_entry(); |
|
| 1498 | 1498 | |
| 1499 | - // If the value of the entry is the same as the stored value |
|
| 1500 | - // Then we can assume it's not a duplicate, it's the same. |
|
| 1501 | - if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1502 | - //if value submitted was not changed, then don't validate |
|
| 1503 | - $field->failed_validation = false; |
|
| 1499 | + // If the value of the entry is the same as the stored value |
|
| 1500 | + // Then we can assume it's not a duplicate, it's the same. |
|
| 1501 | + if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1502 | + //if value submitted was not changed, then don't validate |
|
| 1503 | + $field->failed_validation = false; |
|
| 1504 | 1504 | |
| 1505 | - unset( $field->validation_message ); |
|
| 1505 | + unset( $field->validation_message ); |
|
| 1506 | 1506 | |
| 1507 | - gravityview()->log->debug( 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', array( 'data' => $entry ) ); |
|
| 1507 | + gravityview()->log->debug( 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', array( 'data' => $entry ) ); |
|
| 1508 | 1508 | |
| 1509 | - continue; |
|
| 1510 | - } |
|
| 1509 | + continue; |
|
| 1510 | + } |
|
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | // if here then probably we are facing the validation 'At least one field must be filled out' |
| 1514 | 1514 | if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
| 1515 | - unset( $field->validation_message ); |
|
| 1516 | - $field->validation_message = false; |
|
| 1517 | - continue; |
|
| 1515 | + unset( $field->validation_message ); |
|
| 1516 | + $field->validation_message = false; |
|
| 1517 | + continue; |
|
| 1518 | 1518 | } |
| 1519 | 1519 | |
| 1520 | 1520 | $gv_valid = false; |
@@ -1578,8 +1578,8 @@ discard block |
||
| 1578 | 1578 | // Hide fields depending on admin settings |
| 1579 | 1579 | $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
| 1580 | 1580 | |
| 1581 | - // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
|
| 1582 | - $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
| 1581 | + // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
|
| 1582 | + $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
| 1583 | 1583 | |
| 1584 | 1584 | /** |
| 1585 | 1585 | * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form |
@@ -1639,12 +1639,12 @@ discard block |
||
| 1639 | 1639 | // The edit tab has been configured, so we loop through to configured settings |
| 1640 | 1640 | foreach ( $configured_fields as $configured_field ) { |
| 1641 | 1641 | |
| 1642 | - /** @var GF_Field $field */ |
|
| 1643 | - foreach ( $fields as $field ) { |
|
| 1642 | + /** @var GF_Field $field */ |
|
| 1643 | + foreach ( $fields as $field ) { |
|
| 1644 | 1644 | |
| 1645 | 1645 | if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
| 1646 | - $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1647 | - break; |
|
| 1646 | + $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1647 | + break; |
|
| 1648 | 1648 | } |
| 1649 | 1649 | |
| 1650 | 1650 | } |
@@ -1700,28 +1700,28 @@ discard block |
||
| 1700 | 1700 | */ |
| 1701 | 1701 | private function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { |
| 1702 | 1702 | |
| 1703 | - /** |
|
| 1703 | + /** |
|
| 1704 | 1704 | * @filter `gravityview/edit_entry/use_gf_admin_only_setting` When Edit tab isn't configured, should the Gravity Forms "Admin Only" field settings be used to control field display to non-admins? Default: true |
| 1705 | - * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. |
|
| 1706 | - * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions |
|
| 1707 | - * @since 1.9.1 |
|
| 1708 | - * @param boolean $use_gf_adminonly_setting True: Hide field if set to Admin Only in GF and the user is not an admin. False: show field based on GV permissions, ignoring GF permissions. |
|
| 1709 | - * @param array $form GF Form array |
|
| 1710 | - * @param int $view_id View ID |
|
| 1711 | - */ |
|
| 1712 | - $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
| 1713 | - |
|
| 1714 | - if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1705 | + * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. |
|
| 1706 | + * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions |
|
| 1707 | + * @since 1.9.1 |
|
| 1708 | + * @param boolean $use_gf_adminonly_setting True: Hide field if set to Admin Only in GF and the user is not an admin. False: show field based on GV permissions, ignoring GF permissions. |
|
| 1709 | + * @param array $form GF Form array |
|
| 1710 | + * @param int $view_id View ID |
|
| 1711 | + */ |
|
| 1712 | + $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
| 1713 | + |
|
| 1714 | + if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1715 | 1715 | foreach( $fields as $k => $field ) { |
| 1716 | 1716 | if( $field->adminOnly ) { |
| 1717 | - unset( $fields[ $k ] ); |
|
| 1717 | + unset( $fields[ $k ] ); |
|
| 1718 | 1718 | } |
| 1719 | 1719 | } |
| 1720 | 1720 | return $fields; |
| 1721 | 1721 | } |
| 1722 | 1722 | |
| 1723 | - foreach( $fields as &$field ) { |
|
| 1724 | - $field->adminOnly = false; |
|
| 1723 | + foreach( $fields as &$field ) { |
|
| 1724 | + $field->adminOnly = false; |
|
| 1725 | 1725 | } |
| 1726 | 1726 | |
| 1727 | 1727 | return $fields; |
@@ -1754,36 +1754,36 @@ discard block |
||
| 1754 | 1754 | |
| 1755 | 1755 | if( 'checkbox' === $field->type ) { |
| 1756 | 1756 | foreach ( $field->get_entry_inputs() as $key => $input ) { |
| 1757 | - $input_id = $input['id']; |
|
| 1758 | - $choice = $field->choices[ $key ]; |
|
| 1759 | - $value = \GV\Utils::get( $this->entry, $input_id ); |
|
| 1760 | - $match = RGFormsModel::choice_value_match( $field, $choice, $value ); |
|
| 1761 | - if( $match ) { |
|
| 1762 | - $field->choices[ $key ]['isSelected'] = true; |
|
| 1763 | - } |
|
| 1757 | + $input_id = $input['id']; |
|
| 1758 | + $choice = $field->choices[ $key ]; |
|
| 1759 | + $value = \GV\Utils::get( $this->entry, $input_id ); |
|
| 1760 | + $match = RGFormsModel::choice_value_match( $field, $choice, $value ); |
|
| 1761 | + if( $match ) { |
|
| 1762 | + $field->choices[ $key ]['isSelected'] = true; |
|
| 1763 | + } |
|
| 1764 | 1764 | } |
| 1765 | 1765 | } else { |
| 1766 | 1766 | |
| 1767 | 1767 | // We need to run through each field to set the default values |
| 1768 | 1768 | foreach ( $this->entry as $field_id => $field_value ) { |
| 1769 | 1769 | |
| 1770 | - if( floatval( $field_id ) === floatval( $field->id ) ) { |
|
| 1770 | + if( floatval( $field_id ) === floatval( $field->id ) ) { |
|
| 1771 | 1771 | |
| 1772 | - if( 'list' === $field->type ) { |
|
| 1773 | - $list_rows = maybe_unserialize( $field_value ); |
|
| 1772 | + if( 'list' === $field->type ) { |
|
| 1773 | + $list_rows = maybe_unserialize( $field_value ); |
|
| 1774 | 1774 | |
| 1775 | - $list_field_value = array(); |
|
| 1776 | - foreach ( (array) $list_rows as $row ) { |
|
| 1777 | - foreach ( (array) $row as $column ) { |
|
| 1778 | - $list_field_value[] = $column; |
|
| 1779 | - } |
|
| 1780 | - } |
|
| 1775 | + $list_field_value = array(); |
|
| 1776 | + foreach ( (array) $list_rows as $row ) { |
|
| 1777 | + foreach ( (array) $row as $column ) { |
|
| 1778 | + $list_field_value[] = $column; |
|
| 1779 | + } |
|
| 1780 | + } |
|
| 1781 | 1781 | |
| 1782 | - $field->defaultValue = serialize( $list_field_value ); |
|
| 1783 | - } else { |
|
| 1784 | - $field->defaultValue = $field_value; |
|
| 1785 | - } |
|
| 1786 | - } |
|
| 1782 | + $field->defaultValue = serialize( $list_field_value ); |
|
| 1783 | + } else { |
|
| 1784 | + $field->defaultValue = $field_value; |
|
| 1785 | + } |
|
| 1786 | + } |
|
| 1787 | 1787 | } |
| 1788 | 1788 | } |
| 1789 | 1789 | } |
@@ -1840,7 +1840,7 @@ discard block |
||
| 1840 | 1840 | return $has_conditional_logic; |
| 1841 | 1841 | } |
| 1842 | 1842 | |
| 1843 | - /** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */ |
|
| 1843 | + /** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */ |
|
| 1844 | 1844 | return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); |
| 1845 | 1845 | } |
| 1846 | 1846 | |
@@ -1907,14 +1907,14 @@ discard block |
||
| 1907 | 1907 | |
| 1908 | 1908 | if( $echo && $error !== true ) { |
| 1909 | 1909 | |
| 1910 | - $error = esc_html( $error ); |
|
| 1910 | + $error = esc_html( $error ); |
|
| 1911 | 1911 | |
| 1912 | - /** |
|
| 1913 | - * @since 1.9 |
|
| 1914 | - */ |
|
| 1915 | - if ( ! empty( $this->entry ) ) { |
|
| 1916 | - $error .= ' ' . gravityview_get_link( '#', _x('Go back.', 'Link shown when invalid Edit Entry link is clicked', 'gravityview' ), array( 'onclick' => "window.history.go(-1); return false;" ) ); |
|
| 1917 | - } |
|
| 1912 | + /** |
|
| 1913 | + * @since 1.9 |
|
| 1914 | + */ |
|
| 1915 | + if ( ! empty( $this->entry ) ) { |
|
| 1916 | + $error .= ' ' . gravityview_get_link( '#', _x('Go back.', 'Link shown when invalid Edit Entry link is clicked', 'gravityview' ), array( 'onclick' => "window.history.go(-1); return false;" ) ); |
|
| 1917 | + } |
|
| 1918 | 1918 | |
| 1919 | 1919 | echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
| 1920 | 1920 | } |
@@ -10,175 +10,175 @@ |
||
| 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() { |
|
| 26 | - |
|
| 27 | - if( !is_admin() ) { |
|
| 28 | - return; |
|
| 29 | - } |
|
| 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 ); |
|
| 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 ); |
|
| 25 | + function load() { |
|
| 26 | + |
|
| 27 | + if( !is_admin() ) { |
|
| 28 | + return; |
|
| 29 | + } |
|
| 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 ); |
|
| 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 ); |
|
| 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') ); |
|
| 42 | - |
|
| 43 | - // custom fields' options for zone EDIT |
|
| 44 | - add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 5 ); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Add Edit Link as a default field, outside those set in the Gravity Form form |
|
| 49 | - * @param array $entry_default_fields Existing fields |
|
| 50 | - * @param string|array $form form_ID or form object |
|
| 51 | - * @param string $zone Either 'single', 'directory', 'header', 'footer' |
|
| 52 | - */ |
|
| 53 | - function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
| 54 | - |
|
| 55 | - if( $zone !== 'edit' ) { |
|
| 56 | - |
|
| 57 | - $entry_default_fields['edit_link'] = array( |
|
| 58 | - 'label' => __('Edit Entry', 'gravityview'), |
|
| 59 | - 'type' => 'edit_link', |
|
| 60 | - 'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
| 61 | - ); |
|
| 62 | - |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return $entry_default_fields; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Change wording for the Edit context to read Entry Creator |
|
| 70 | - * |
|
| 71 | - * @param array $visibility_caps Array of capabilities to display in field dropdown. |
|
| 72 | - * @param string $field_type Type of field options to render (`field` or `widget`) |
|
| 73 | - * @param string $template_id Table slug |
|
| 74 | - * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
|
| 75 | - * @param string $context What context are we in? Example: `single` or `directory` |
|
| 76 | - * @param string $input_type (textarea, list, select, etc.) |
|
| 77 | - * @return array Array of field options with `label`, `value`, `type`, `default` keys |
|
| 78 | - */ |
|
| 79 | - function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
| 80 | - |
|
| 81 | - $caps = $visibility_caps; |
|
| 82 | - |
|
| 83 | - // If we're configuring fields in the edit context, we want a limited selection |
|
| 84 | - if( $context === 'edit' ) { |
|
| 85 | - |
|
| 86 | - // Remove other built-in caps. |
|
| 87 | - unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
| 88 | - |
|
| 89 | - $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - return $caps; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Add "Edit Link Text" setting to the edit_link field settings |
|
| 97 | - * @param [type] $field_options [description] |
|
| 98 | - * @param [type] $template_id [description] |
|
| 99 | - * @param [type] $field_id [description] |
|
| 100 | - * @param [type] $context [description] |
|
| 101 | - * @param [type] $input_type [description] |
|
| 102 | - * @return [type] [description] |
|
| 103 | - */ |
|
| 104 | - function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 105 | - |
|
| 106 | - // Always a link, never a filter |
|
| 107 | - unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
| 108 | - |
|
| 109 | - // Edit Entry link should only appear to visitors capable of editing entries |
|
| 110 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 111 | - |
|
| 112 | - $add_option['edit_link'] = array( |
|
| 113 | - 'type' => 'text', |
|
| 114 | - 'label' => __( 'Edit Link Text', 'gravityview' ), |
|
| 115 | - 'desc' => NULL, |
|
| 116 | - 'value' => __('Edit Entry', 'gravityview'), |
|
| 117 | - 'merge_tags' => true, |
|
| 118 | - ); |
|
| 119 | - |
|
| 120 | - return array_merge( $add_option, $field_options ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Add tooltips |
|
| 125 | - * @param array $tooltips Existing tooltips |
|
| 126 | - * @return array Modified tooltips |
|
| 127 | - */ |
|
| 128 | - function tooltips( $tooltips ) { |
|
| 129 | - |
|
| 130 | - $return = $tooltips; |
|
| 131 | - |
|
| 132 | - $return['allow_edit_cap'] = array( |
|
| 133 | - 'title' => __('Limiting Edit Access', 'gravityview'), |
|
| 134 | - 'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
| 135 | - ); |
|
| 136 | - |
|
| 137 | - return $return; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Manipulate the fields' options for the EDIT ENTRY screen |
|
| 142 | - * @param [type] $field_options [description] |
|
| 143 | - * @param [type] $template_id [description] |
|
| 144 | - * @param [type] $field_id [description] |
|
| 145 | - * @param [type] $context [description] |
|
| 146 | - * @param [type] $input_type [description] |
|
| 147 | - * @return [type] [description] |
|
| 148 | - */ |
|
| 149 | - function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 150 | - |
|
| 151 | - // We only want to modify the settings for the edit context |
|
| 152 | - if( 'edit' !== $context ) { |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @since 1.8.4 |
|
| 156 | - */ |
|
| 157 | - $field_options['new_window'] = array( |
|
| 158 | - 'type' => 'checkbox', |
|
| 159 | - 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
| 160 | - 'value' => false, |
|
| 161 | - ); |
|
| 162 | - |
|
| 163 | - return $field_options; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // Entry field is only for logged in users |
|
| 167 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 168 | - |
|
| 169 | - $add_options = array( |
|
| 170 | - 'allow_edit_cap' => array( |
|
| 171 | - 'type' => 'select', |
|
| 172 | - 'label' => __( 'Make field editable to:', 'gravityview' ), |
|
| 173 | - 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
| 174 | - 'tooltip' => 'allow_edit_cap', |
|
| 175 | - 'class' => 'widefat', |
|
| 176 | - 'value' => 'read', // Default: entry creator |
|
| 177 | - ), |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - return array_merge( $field_options, $add_options ); |
|
| 181 | - } |
|
| 40 | + // add tooltips |
|
| 41 | + add_filter( 'gravityview/metaboxes/tooltips', array( $this, 'tooltips') ); |
|
| 42 | + |
|
| 43 | + // custom fields' options for zone EDIT |
|
| 44 | + add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 5 ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Add Edit Link as a default field, outside those set in the Gravity Form form |
|
| 49 | + * @param array $entry_default_fields Existing fields |
|
| 50 | + * @param string|array $form form_ID or form object |
|
| 51 | + * @param string $zone Either 'single', 'directory', 'header', 'footer' |
|
| 52 | + */ |
|
| 53 | + function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
| 54 | + |
|
| 55 | + if( $zone !== 'edit' ) { |
|
| 56 | + |
|
| 57 | + $entry_default_fields['edit_link'] = array( |
|
| 58 | + 'label' => __('Edit Entry', 'gravityview'), |
|
| 59 | + 'type' => 'edit_link', |
|
| 60 | + 'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
| 61 | + ); |
|
| 62 | + |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return $entry_default_fields; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Change wording for the Edit context to read Entry Creator |
|
| 70 | + * |
|
| 71 | + * @param array $visibility_caps Array of capabilities to display in field dropdown. |
|
| 72 | + * @param string $field_type Type of field options to render (`field` or `widget`) |
|
| 73 | + * @param string $template_id Table slug |
|
| 74 | + * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
|
| 75 | + * @param string $context What context are we in? Example: `single` or `directory` |
|
| 76 | + * @param string $input_type (textarea, list, select, etc.) |
|
| 77 | + * @return array Array of field options with `label`, `value`, `type`, `default` keys |
|
| 78 | + */ |
|
| 79 | + function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
| 80 | + |
|
| 81 | + $caps = $visibility_caps; |
|
| 82 | + |
|
| 83 | + // If we're configuring fields in the edit context, we want a limited selection |
|
| 84 | + if( $context === 'edit' ) { |
|
| 85 | + |
|
| 86 | + // Remove other built-in caps. |
|
| 87 | + unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
| 88 | + |
|
| 89 | + $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + return $caps; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Add "Edit Link Text" setting to the edit_link field settings |
|
| 97 | + * @param [type] $field_options [description] |
|
| 98 | + * @param [type] $template_id [description] |
|
| 99 | + * @param [type] $field_id [description] |
|
| 100 | + * @param [type] $context [description] |
|
| 101 | + * @param [type] $input_type [description] |
|
| 102 | + * @return [type] [description] |
|
| 103 | + */ |
|
| 104 | + function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 105 | + |
|
| 106 | + // Always a link, never a filter |
|
| 107 | + unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
| 108 | + |
|
| 109 | + // Edit Entry link should only appear to visitors capable of editing entries |
|
| 110 | + unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 111 | + |
|
| 112 | + $add_option['edit_link'] = array( |
|
| 113 | + 'type' => 'text', |
|
| 114 | + 'label' => __( 'Edit Link Text', 'gravityview' ), |
|
| 115 | + 'desc' => NULL, |
|
| 116 | + 'value' => __('Edit Entry', 'gravityview'), |
|
| 117 | + 'merge_tags' => true, |
|
| 118 | + ); |
|
| 119 | + |
|
| 120 | + return array_merge( $add_option, $field_options ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Add tooltips |
|
| 125 | + * @param array $tooltips Existing tooltips |
|
| 126 | + * @return array Modified tooltips |
|
| 127 | + */ |
|
| 128 | + function tooltips( $tooltips ) { |
|
| 129 | + |
|
| 130 | + $return = $tooltips; |
|
| 131 | + |
|
| 132 | + $return['allow_edit_cap'] = array( |
|
| 133 | + 'title' => __('Limiting Edit Access', 'gravityview'), |
|
| 134 | + 'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
| 135 | + ); |
|
| 136 | + |
|
| 137 | + return $return; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Manipulate the fields' options for the EDIT ENTRY screen |
|
| 142 | + * @param [type] $field_options [description] |
|
| 143 | + * @param [type] $template_id [description] |
|
| 144 | + * @param [type] $field_id [description] |
|
| 145 | + * @param [type] $context [description] |
|
| 146 | + * @param [type] $input_type [description] |
|
| 147 | + * @return [type] [description] |
|
| 148 | + */ |
|
| 149 | + function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 150 | + |
|
| 151 | + // We only want to modify the settings for the edit context |
|
| 152 | + if( 'edit' !== $context ) { |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @since 1.8.4 |
|
| 156 | + */ |
|
| 157 | + $field_options['new_window'] = array( |
|
| 158 | + 'type' => 'checkbox', |
|
| 159 | + 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
| 160 | + 'value' => false, |
|
| 161 | + ); |
|
| 162 | + |
|
| 163 | + return $field_options; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // Entry field is only for logged in users |
|
| 167 | + unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 168 | + |
|
| 169 | + $add_options = array( |
|
| 170 | + 'allow_edit_cap' => array( |
|
| 171 | + 'type' => 'select', |
|
| 172 | + 'label' => __( 'Make field editable to:', 'gravityview' ), |
|
| 173 | + 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
| 174 | + 'tooltip' => 'allow_edit_cap', |
|
| 175 | + 'class' => 'widefat', |
|
| 176 | + 'value' => 'read', // Default: entry creator |
|
| 177 | + ), |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + return array_merge( $field_options, $add_options ); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | 183 | |
| 184 | 184 | } // end class |
| 185 | 185 | \ No newline at end of file |