/** * Update the post categories based on all post category fields * * @since 1.17 * * @param array $form Gravity Forms form array * @param int $entry_id Numeric ID of the entry that was updated * * @return array|false|WP_Error Array of term taxonomy IDs of affected categories. WP_Error or false on failure. false if there are no post category fields or connected post. */ public function set_post_categories($form = array(), $entry_id = 0) { $entry = GFAPI::get_entry($entry_id); $post_id = rgar($entry, 'post_id'); if (empty($post_id)) { return false; } $return = false; $post_category_fields = GFAPI::get_fields_by_type($form, 'post_category'); if ($post_category_fields) { $updated_categories = array(); foreach ($post_category_fields as $field) { // Get the value of the field, including $_POSTed value $field_cats = RGFormsModel::get_field_value($field); $field_cats = is_array($field_cats) ? array_values($field_cats) : (array) $field_cats; $field_cats = gv_map_deep($field_cats, 'intval'); $updated_categories = array_merge($updated_categories, array_values($field_cats)); } // Remove `0` values from intval() $updated_categories = array_filter($updated_categories); /** * @filter `gravityview/edit_entry/post_categories/append` Should post categories be added to or replaced? * @since 1.17 * @param bool $append If `true`, don't delete existing categories, just add on. If `false`, replace the categories with the submitted categories. Default: `false` */ $append = apply_filters('gravityview/edit_entry/post_categories/append', false); $return = wp_set_post_categories($post_id, $updated_categories, $append); } return $return; }
/** * Based on the search method, fetch the value for a specific key * * @since 1.16.4 * * @param string $name Name of the request key to fetch the value for * * @return mixed|string Value of request at $name key. Empty string if empty. */ private function rgget_or_rgpost($name) { $value = 'get' === $this->search_method ? rgget($name) : rgpost($name); $value = stripslashes_deep($value); $value = gv_map_deep($value, 'rawurldecode'); $value = gv_map_deep($value, '_wp_specialchars'); return $value; }
/** * Get strings used by the Entry Notes field * * Use `gravityview/field/notes/strings` filter to modify the strings * * @since 1.17 * * @param string $key If set, return the string with the key of $key * * @return array|string Array of strings with keys and values. If $key is set, returns string. If missing $strings[ $key ], empty string. */ public static function strings($key = '') { $strings = array('add-note' => __('Add Note', 'gravityview'), 'added-note' => __('Note added.', 'gravityview'), 'content-label' => __('Note Content', 'gravityview'), 'delete' => __('Delete', 'gravityview'), 'delete-confirm' => __('Are you sure you want to delete the selected notes?', 'gravityview'), 'caption' => __('Notes for this entry', 'gravityview'), 'toggle-notes' => __('Toggle all notes', 'gravityview'), 'no-notes' => __('There are no notes.', 'gravityview'), 'processing' => __('Processing…', 'gravityview'), 'other-email' => __('Other email address', 'gravityview'), 'email-label' => __('Email address', 'gravityview'), 'email-placeholder' => _x('*****@*****.**', 'Example email address used as a placeholder', 'gravityview'), 'subject-label' => __('Subject', 'gravityview'), 'subject' => __('Email subject', 'gravityview'), 'default-email-subject' => __('New entry note', 'gravityview'), 'also-email' => __('Also email this note to', 'gravityview'), 'error-add-note' => __('There was an error adding the note.', 'gravityview'), 'error-invalid' => __('The request was invalid. Refresh the page and try again.', 'gravityview'), 'error-empty-note' => _x('Note cannot be blank.', 'Message to display when submitting a note without content.', 'gravityview'), 'error-cap-delete' => __('You don\'t have the ability to delete notes.', 'gravityview'), 'error-cap-add' => __('You don\'t have the ability to add notes.', 'gravityview')); /** * @filter `gravityview/field/notes/strings` Modify the text used in the Entry Notes field. Sanitized by `esc_html` after return. * @since 1.17 * @param array $strings Text in key => value pairs */ $strings = gv_map_deep(apply_filters('gravityview/field/notes/strings', $strings), 'esc_html'); if ($key) { return isset($strings[$key]) ? $strings[$key] : ''; } return $strings; }
/** * Maps a function to all non-iterable elements of an array or an object. * * @see map_deep() This is an alias of the WP core function `map_deep()`, added in 4.4. Here for legacy purposes. * @since 1.16.3 * * @param mixed $value The array, object, or scalar. * @param callable $callback The function to map onto $value. * * @return mixed The value with the callback applied to all non-arrays and non-objects inside it. */ function gv_map_deep($value, $callback) { // Use the original function, if exists. // Requires WP 4.4+ if (function_exists('map_deep')) { return map_deep($value, $callback); } // Exact copy of map_deep() code below: if (is_array($value)) { foreach ($value as $index => $item) { $value[$index] = gv_map_deep($item, $callback); } } elseif (is_object($value)) { $object_vars = get_object_vars($value); foreach ($object_vars as $property_name => $property_value) { $value->{$property_name} = gv_map_deep($property_value, $callback); } } else { $value = call_user_func($callback, $value); } return $value; }