function acf_update_metadata($post_id = 0, $name = '', $value = '', $hidden = false) { // vars $return = false; $prefix = $hidden ? '_' : ''; // get post_id info $info = acf_get_post_id_info($post_id); // bail early if no $post_id (acf_form - new_post) if (!$info['id']) { return $return; } // option if ($info['type'] === 'option') { $name = $prefix . $post_id . '_' . $name; $return = acf_update_option($name, $value); // meta } else { $name = $prefix . $name; $return = update_metadata($info['type'], $info['id'], $name, $value); } // return return $return; }
function acf_update_metadata($post_id = 0, $name = '', $value = '', $hidden = false) { // vars $return = false; // add prefix for hidden meta if ($hidden) { $name = '_' . $name; } // postmeta if (is_numeric($post_id)) { $return = update_metadata('post', $post_id, $name, $value); // usermeta } elseif (substr($post_id, 0, 5) == 'user_') { $user_id = (int) substr($post_id, 5); $return = update_metadata('user', $user_id, $name, $value); // commentmeta } elseif (substr($post_id, 0, 8) == 'comment_') { $comment_id = (int) substr($post_id, 8); $return = update_metadata('comment', $comment_id, $name, $value); // options } else { // modify prefix for hidden meta if ($hidden) { $post_id = '_' . $post_id; $name = substr($name, 1); } $return = acf_update_option($post_id . '_' . $name, $value); } // return return (bool) $return; }
function acf_update_metadata($post_id, $name, $value) { // vars $return = false; // postmeta if (is_numeric($post_id)) { $return = update_metadata('post', $post_id, $name, $value); // usermeta } elseif (strpos($post_id, 'user_') !== false) { $user_id = str_replace('user_', '', $post_id); $return = update_metadata('user', $user_id, $name, $value); // commentmeta } elseif (strpos($post_id, 'comment_') !== false) { $comment_id = str_replace('comment_', '', $post_id); $return = update_metadata('comment', $comment_id, $name, $value); // options } else { // for some reason, update_option does not use stripslashes_deep. // update_metadata -> http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/meta.php#L82: line 101 (does use stripslashes_deep) // update_option -> http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/option.php#L0: line 215 (does not use stripslashes_deep) $value = stripslashes_deep($value); $return = acf_update_option($post_id . '_' . $name, $value); } // return return $return; }
function acf_update_value($value = null, $post_id = 0, $field) { // vars $return = false; // strip slashes // allow 3rd party customisation if (acf_get_setting('stripslashes')) { $value = stripslashes_deep($value); } // filter for 3rd party customization $value = apply_filters("acf/update_value", $value, $post_id, $field); $value = apply_filters("acf/update_value/type={$field['type']}", $value, $post_id, $field); $value = apply_filters("acf/update_value/name={$field['name']}", $value, $post_id, $field); $value = apply_filters("acf/update_value/key={$field['key']}", $value, $post_id, $field); // note: // attempted to save values as individual rows for better WP_Query compatibility. Issues are clear that order would not work. if (is_numeric($post_id)) { // allow ACF to save to revision! $return = update_metadata('post', $post_id, $field['name'], $value); update_metadata('post', $post_id, '_' . $field['name'], $field['key']); } elseif (strpos($post_id, 'user_') !== false) { $user_id = str_replace('user_', '', $post_id); $return = update_metadata('user', $user_id, $field['name'], $value); update_metadata('user', $user_id, '_' . $field['name'], $field['key']); } elseif (strpos($post_id, 'comment_') !== false) { $comment_id = str_replace('comment_', '', $post_id); $return = update_metadata('comment', $comment_id, $field['name'], $value); update_metadata('comment', $comment_id, '_' . $field['name'], $field['key']); } else { // for some reason, update_option does not use stripslashes_deep. // update_metadata -> http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/meta.php#L82: line 101 (does use stripslashes_deep) // update_option -> http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/option.php#L0: line 215 (does not use stripslashes_deep) $value = stripslashes_deep($value); $return = acf_update_option($post_id . '_' . $field['name'], $value); acf_update_option('_' . $post_id . '_' . $field['name'], $field['key']); } // clear cache wp_cache_delete("load_value/post_id={$post_id}/name={$field['name']}", 'acf'); // return return $return; }