/** * Survey fields inject their output using `gform_field_input` filter, but in Edit Entry, the values were empty. * We filter the values here because it was the easiest access point: tell the survey field the correct value, GF outputs it. * * @since 1.16.4 * @since 1.17 Moved to GravityView_Plugin_Hooks_Gravity_Forms_Survey class * * @param string $value Existing value * @param GF_Field $field * @param string $name Field custom parameter name, normally blank. * * @return mixed */ public function fix_survey_field_value($value, $field, $name) { if ('survey' === $field->type) { $entry = GravityView_Edit_Entry::getInstance()->instances['render']->get_entry(); // We need to run through each survey row until we find a match for expected values foreach ($entry as $field_id => $field_value) { if (floor($field_id) !== floor($field->id)) { continue; } if (rgar($field, 'gsurveyLikertEnableMultipleRows')) { list($row_val, $col_val) = explode(':', $field_value, 2); // If the $name matches the $row_val, we are processing the correct row if ($row_val === $name) { $value = $field_value; break; } } else { // When not processing multiple rows, the value is the $entry[ $field_id ] value. $value = $field_value; break; } } } return $value; }
/** * @covers GravityView_Edit_Entry::add_template_path */ public function test_add_template_path() { $template_paths = GravityView_Edit_Entry::getInstance()->add_template_path(array()); $expected = array(110 => GravityView_Edit_Entry::$file); $this->assertEquals($expected, $template_paths); }
/** * Always show the live Category values * * By default, Gravity Forms would show unchecked/default choices. We want to show the live Post categories * * @since 1.17 * * @param $choices * @param $field * @param $form_id * * @return mixed */ function edit_entry_post_category_choices($choices, $field, $form_id) { $entry = GravityView_Edit_Entry::getInstance()->instances['render']->get_entry(); // $entry['post_id'] should always be set, but we check to make sure. if ($entry && isset($entry['post_id']) && ($post_id = $entry['post_id'])) { $post_categories = wp_get_post_categories($post_id, array('fields' => 'ids')); // Always use the live value foreach ($choices as &$choice) { $choice['isSelected'] = in_array($choice['value'], array_values($post_categories)); } } return $choices; }
// User edit is disabled if (empty($user_edit)) { do_action('gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.'); $user_can_edit = false; } else { if (is_user_logged_in() && intval($current_user->ID) === intval($entry['created_by'])) { do_action('gravityview_log_debug', sprintf('GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID)); $user_can_edit = true; } else { if (!is_user_logged_in()) { do_action('gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user'); } } } } } /** * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. * @since 1.15 Added `$entry` and `$view_id` parameters * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false) * @param[in] array $entry Gravity Forms entry array {@since 1.15} * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15} */ $user_can_edit = apply_filters('gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id); return (bool) $user_can_edit; } } // end class //add_action( 'plugins_loaded', array('GravityView_Edit_Entry', 'getInstance'), 6 ); GravityView_Edit_Entry::getInstance();