本文整理汇总了PHP中update_metadata_by_mid函数的典型用法代码示例。如果您正苦于以下问题:PHP update_metadata_by_mid函数的具体用法?PHP update_metadata_by_mid怎么用?PHP update_metadata_by_mid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_metadata_by_mid函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: test_update_metadata_by_mid
function test_update_metadata_by_mid()
{
// Setup
$meta = get_metadata_by_mid('user', $this->meta_id);
// Update the meta value
$this->assertTrue(update_metadata_by_mid('user', $this->meta_id, 'meta_new_value'));
$meta = get_metadata_by_mid('user', $this->meta_id);
$this->assertEquals('meta_new_value', $meta->meta_value);
// Update the meta value
$this->assertTrue(update_metadata_by_mid('user', $this->meta_id, 'meta_new_value', 'meta_new_key'));
$meta = get_metadata_by_mid('user', $this->meta_id);
$this->assertEquals('meta_new_key', $meta->meta_key);
// Update the key and value
$this->assertTrue(update_metadata_by_mid('user', $this->meta_id, 'meta_value', 'meta_key'));
$meta = get_metadata_by_mid('user', $this->meta_id);
$this->assertEquals('meta_key', $meta->meta_key);
$this->assertEquals('meta_value', $meta->meta_value);
// Update the value that has to be serialized
$this->assertTrue(update_metadata_by_mid('user', $this->meta_id, array('first', 'second')));
$meta = get_metadata_by_mid('user', $this->meta_id);
$this->assertEquals(array('first', 'second'), $meta->meta_value);
// Let's try some invalid meta data
$this->assertFalse(update_metadata_by_mid('user', 0, 'meta_value'));
$this->assertFalse(update_metadata_by_mid('user', $this->meta_id, 'meta_value', array('invalid', 'key')));
// Let's see if caches get cleared after updates.
$meta = get_metadata_by_mid('user', $this->meta_id);
$first = get_user_meta($meta->user_id, $meta->meta_key);
$this->assertTrue(update_metadata_by_mid('user', $this->meta_id, 'other_meta_value'));
$second = get_user_meta($meta->user_id, $meta->meta_key);
$this->assertFalse($first === $second);
}
开发者ID:rmccue,项目名称:wordpress-unit-tests,代码行数:31,代码来源:meta.php
示例2: write_post
//.........这里部分代码省略.........
}
}
$post_id = wp_insert_post(add_magic_quotes($insert), true);
if ($has_media) {
$this->api->trap_wp_die('upload_error');
foreach ($input['media'] as $media_item) {
$_FILES['.api.media.item.'] = $media_item;
// check for WP_Error if we ever actually need $media_id
$media_id = media_handle_upload('.api.media.item.', $post_id);
}
$this->api->trap_wp_die(null);
unset($_FILES['.api.media.item.']);
}
} else {
$insert['ID'] = $post->ID;
$post_id = wp_update_post((object) $insert);
}
if (!$post_id || is_wp_error($post_id)) {
return $post_id;
}
if ($publicize === false) {
foreach ($GLOBALS['publicize_ui']->publicize->get_services('all') as $name => $service) {
update_post_meta($post_id, $GLOBALS['publicize_ui']->publicize->POST_SKIP . $name, 1);
}
} else {
if (is_array($publicize) && count($publicize) > 0) {
foreach ($GLOBALS['publicize_ui']->publicize->get_services('all') as $name => $service) {
if (!in_array($name, $publicize)) {
update_post_meta($post_id, $GLOBALS['publicize_ui']->publicize->POST_SKIP . $name, 1);
}
}
}
}
if (!empty($publicize_custom_message)) {
update_post_meta($post_id, $GLOBALS['publicize_ui']->publicize->POST_MESS, trim($publicize_custom_message));
}
set_post_format($post_id, $insert['post_format']);
if (!empty($metadata)) {
foreach ((array) $metadata as $meta) {
$meta = (object) $meta;
$existing_meta_item = new stdClass();
if (empty($meta->operation)) {
$meta->operation = 'update';
}
if (!empty($meta->value)) {
if ('true' == $meta->value) {
$meta->value = true;
}
if ('false' == $meta->value) {
$meta->value = false;
}
}
if (!empty($meta->id)) {
$meta->id = absint($meta->id);
$existing_meta_item = get_metadata_by_mid('post', $meta->id);
}
$unslashed_meta_key = wp_unslash($meta->key);
// should match what the final key will be
$meta->key = wp_slash($meta->key);
$unslashed_existing_meta_key = wp_unslash($existing_meta_item->meta_key);
$existing_meta_item->meta_key = wp_slash($existing_meta_item->meta_key);
switch ($meta->operation) {
case 'delete':
if (!empty($meta->id) && !empty($existing_meta_item->meta_key) && current_user_can('delete_post_meta', $post_id, $unslashed_existing_meta_key)) {
delete_metadata_by_mid('post', $meta->id);
} elseif (!empty($meta->key) && !empty($meta->previous_value) && current_user_can('delete_post_meta', $post_id, $unslashed_meta_key)) {
delete_post_meta($post_id, $meta->key, $meta->previous_value);
} elseif (!empty($meta->key) && current_user_can('delete_post_meta', $post_id, $unslashed_meta_key)) {
delete_post_meta($post_id, $meta->key);
}
break;
case 'add':
if (!empty($meta->id) || !empty($meta->previous_value)) {
continue;
} elseif (!empty($meta->key) && !empty($meta->value) && current_user_can('add_post_meta', $post_id, $unslashed_meta_key)) {
add_post_meta($post_id, $meta->key, $meta->value);
}
break;
case 'update':
if (empty($meta->value)) {
continue;
} elseif (!empty($meta->id) && !empty($existing_meta_item->meta_key) && current_user_can('edit_post_meta', $post_id, $unslashed_existing_meta_key)) {
update_metadata_by_mid('post', $meta->id, $meta->value);
} elseif (!empty($meta->key) && !empty($meta->previous_value) && current_user_can('edit_post_meta', $post_id, $unslashed_meta_key)) {
update_post_meta($post_id, $meta->key, $meta->value, $meta->previous_value);
} elseif (!empty($meta->key) && current_user_can('edit_post_meta', $post_id, $unslashed_meta_key)) {
update_post_meta($post_id, $meta->key, $meta->value);
}
break;
}
}
}
do_action('rest_api_inserted_post', $post_id, $insert, $new);
$return = $this->get_post_by('ID', $post_id, $args['context']);
if (!$return || is_wp_error($return)) {
return $return;
}
do_action('wpcom_json_api_objects', 'posts');
return $return;
}
开发者ID:vsalx,项目名称:rattieinfo,代码行数:101,代码来源:class.json-api-endpoints.php
示例3: update_item
/**
* Add meta to an object.
*
* @param WP_REST_Request $request
* @return WP_REST_Response|WP_Error
*/
public function update_item($request)
{
$parent_id = (int) $request['parent_id'];
$mid = (int) $request['id'];
$parent_column = $this->get_parent_column();
$current = get_metadata_by_mid($this->parent_type, $mid);
if (empty($current)) {
return new WP_Error('rest_meta_invalid_id', __('Invalid meta id.'), array('status' => 404));
}
if (absint($current->{$parent_column}) !== $parent_id) {
return new WP_Error('rest_meta_' . $this->parent_type . '_mismatch', __('Meta does not belong to this object'), array('status' => 400));
}
if (!isset($request['key']) && !isset($request['value'])) {
return new WP_Error('rest_meta_data_invalid', __('Invalid meta parameters.'), array('status' => 400));
}
if (isset($request['key'])) {
$key = $request['key'];
} else {
$key = $current->meta_key;
}
if (isset($request['value'])) {
$value = $request['value'];
} else {
$value = $current->meta_value;
}
if (!$key) {
return new WP_Error('rest_meta_invalid_key', __('Invalid meta key.'), array('status' => 400));
}
// for now let's not allow updating of arrays, objects or serialized values.
if (!$this->is_valid_meta_data($current->meta_value)) {
$code = $this->parent_type === 'post' ? 'rest_post_invalid_action' : 'rest_meta_invalid_action';
return new WP_Error($code, __('Invalid existing meta data for action.'), array('status' => 400));
}
if (!$this->is_valid_meta_data($value)) {
$code = $this->parent_type === 'post' ? 'rest_post_invalid_action' : 'rest_meta_invalid_action';
return new WP_Error($code, __('Invalid provided meta data for action.'), array('status' => 400));
}
if (is_protected_meta($current->meta_key)) {
return new WP_Error('rest_meta_protected', sprintf(__('%s is marked as a protected field.'), $current->meta_key), array('status' => 403));
}
if (is_protected_meta($key)) {
return new WP_Error('rest_meta_protected', sprintf(__('%s is marked as a protected field.'), $key), array('status' => 403));
}
// update_metadata_by_mid will return false if these are equal, so check
// first and pass through
if ((string) $value === $current->meta_value && (string) $key === $current->meta_key) {
return $this->get_item($request);
}
if (!update_metadata_by_mid($this->parent_type, $mid, $value, $key)) {
return new WP_Error('rest_meta_could_not_update', __('Could not update meta.'), array('status' => 500));
}
$request = new WP_REST_Request('GET');
$request->set_query_params(array('context' => 'edit', 'parent_id' => $parent_id, 'id' => $mid));
$response = $this->get_item($request);
/**
* Fires after meta is added to an object or updated via the REST API.
*
* @param array $value The inserted meta data.
* @param WP_REST_Request $request The request sent to the API.
* @param bool $creating True when adding meta, false when updating.
*/
do_action('rest_insert_meta', $value, $request, false);
return rest_ensure_response($response);
}
开发者ID:walkthenight,项目名称:walkthenight-wordpress,代码行数:70,代码来源:class-wp-rest-meta-controller.php
示例4: stripslashes
$value = stripslashes($_POST['meta'][$mid]['value']);
if ('' == trim($key)) {
die(__('Please provide a custom field name.'));
}
if ('' == trim($value)) {
die(__('Please provide a custom field value.'));
}
if (!($meta = get_metadata_by_mid('post', $mid))) {
die('0');
}
// if meta doesn't exist
if (is_protected_meta($meta->meta_key, 'post') || is_protected_meta($key, 'post') || !current_user_can('edit_post_meta', $meta->post_id, $meta->meta_key) || !current_user_can('edit_post_meta', $meta->post_id, $key)) {
die('-1');
}
if ($meta->meta_value != $value || $meta->meta_key != $key) {
if (!($u = update_metadata_by_mid('post', $mid, $value, $key))) {
die('0');
}
// We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
}
$x = new WP_Ajax_Response(array('what' => 'meta', 'id' => $mid, 'old_id' => $mid, 'data' => _list_meta_row(array('meta_key' => $key, 'meta_value' => $value, 'meta_id' => $mid), $c), 'position' => 0, 'supplemental' => array('postid' => $meta->post_id)));
}
$x->send();
break;
case 'add-user':
check_ajax_referer($action);
if (!current_user_can('create_users')) {
die('-1');
}
if (!($user_id = add_user())) {
die('0');
开发者ID:vivekkodira1,项目名称:wordpress,代码行数:31,代码来源:admin-ajax.php
示例5: update_drop
/**
* Update a drop
*
* @todo delegate to Drop classes
* @param [type] $payload [description]
* @return [type] [description]
*/
function update_drop($payload)
{
$drop = Drop_It_Drop::payload($payload);
update_metadata_by_mid('post', $payload->drop_id, $drop, $meta_key = false);
}
开发者ID:foo123,项目名称:drop-it,代码行数:12,代码来源:drop-it.php
示例6: wp_ajax_add_meta
/**
* Ajax handler for adding meta.
*
* @since 3.1.0
*/
function wp_ajax_add_meta()
{
check_ajax_referer('add-meta', '_ajax_nonce-add-meta');
$c = 0;
$pid = (int) $_POST['post_id'];
$post = get_post($pid);
if (isset($_POST['metakeyselect']) || isset($_POST['metakeyinput'])) {
if (!current_user_can('edit_post', $pid)) {
wp_die(-1);
}
if (isset($_POST['metakeyselect']) && '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput'])) {
wp_die(1);
}
// If the post is an autodraft, save the post as a draft and then attempt to save the meta.
if ($post->post_status == 'auto-draft') {
$post_data = array();
$post_data['action'] = 'draft';
// Warning fix
$post_data['post_ID'] = $pid;
$post_data['post_type'] = $post->post_type;
$post_data['post_status'] = 'draft';
$now = current_time('timestamp', 1);
$post_data['post_title'] = sprintf(__('Draft created on %1$s at %2$s'), date(get_option('date_format'), $now), date(get_option('time_format'), $now));
$pid = edit_post($post_data);
if ($pid) {
if (is_wp_error($pid)) {
$x = new WP_Ajax_Response(array('what' => 'meta', 'data' => $pid));
$x->send();
}
if (!($mid = add_meta($pid))) {
wp_die(__('Please provide a custom field value.'));
}
} else {
wp_die(0);
}
} elseif (!($mid = add_meta($pid))) {
wp_die(__('Please provide a custom field value.'));
}
$meta = get_metadata_by_mid('post', $mid);
$pid = (int) $meta->post_id;
$meta = get_object_vars($meta);
$x = new WP_Ajax_Response(array('what' => 'meta', 'id' => $mid, 'data' => _list_meta_row($meta, $c), 'position' => 1, 'supplemental' => array('postid' => $pid)));
} else {
// Update?
$mid = (int) key($_POST['meta']);
$key = wp_unslash($_POST['meta'][$mid]['key']);
$value = wp_unslash($_POST['meta'][$mid]['value']);
if ('' == trim($key)) {
wp_die(__('Please provide a custom field name.'));
}
if ('' == trim($value)) {
wp_die(__('Please provide a custom field value.'));
}
if (!($meta = get_metadata_by_mid('post', $mid))) {
wp_die(0);
}
// if meta doesn't exist
if (is_protected_meta($meta->meta_key, 'post') || is_protected_meta($key, 'post') || !current_user_can('edit_post_meta', $meta->post_id, $meta->meta_key) || !current_user_can('edit_post_meta', $meta->post_id, $key)) {
wp_die(-1);
}
if ($meta->meta_value != $value || $meta->meta_key != $key) {
if (!($u = update_metadata_by_mid('post', $mid, $value, $key))) {
wp_die(0);
}
// We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
}
$x = new WP_Ajax_Response(array('what' => 'meta', 'id' => $mid, 'old_id' => $mid, 'data' => _list_meta_row(array('meta_key' => $key, 'meta_value' => $value, 'meta_id' => $mid), $c), 'position' => 0, 'supplemental' => array('postid' => $meta->post_id)));
}
$x->send();
}
开发者ID:hughnet,项目名称:WordPress,代码行数:75,代码来源:ajax-actions.php
示例7: update_meta
/**
* Update post meta data by meta ID.
*
* @since 1.2.0
*
* @param int $meta_id
* @param string $meta_key Expect Slashed
* @param string $meta_value Expect Slashed
* @return bool
*/
function update_meta($meta_id, $meta_key, $meta_value)
{
$meta_key = wp_unslash($meta_key);
$meta_value = wp_unslash($meta_value);
return update_metadata_by_mid('post', $meta_id, $meta_value, $meta_key);
}
开发者ID:nicholasgriffintn,项目名称:WordPress,代码行数:16,代码来源:post.php
示例8: update_meta
/**
* {@internal Missing Short Description}}
*
* @since 1.2.0
*
* @param unknown_type $meta_id
* @param unknown_type $meta_key Expect Slashed
* @param unknown_type $meta_value Expect Slashed
* @return unknown
*/
function update_meta($meta_id, $meta_key, $meta_value)
{
$meta_key = stripslashes($meta_key);
$meta_value = stripslashes_deep($meta_value);
return update_metadata_by_mid('post', $meta_id, $meta_value, $meta_key);
}
开发者ID:adisonc,项目名称:MaineLearning,代码行数:16,代码来源:post.php
示例9: write_post
//.........这里部分代码省略.........
* EG: array( 'twitter', 'facebook') will only publicize to those, ignoring the other available services
* Form data: publicize[]=twitter&publicize[]=facebook
* EG: array( 'twitter' => '(int) $pub_conn_id_0, (int) $pub_conn_id_3', 'facebook' => (int) $pub_conn_id_7 ) will publicize to two Twitter accounts, and one Facebook connection, of potentially many.
* Form data: publicize[twitter]=$pub_conn_id_0,$pub_conn_id_3&publicize[facebook]=$pub_conn_id_7
* EG: array( 'twitter', 'facebook' => '(int) $pub_conn_id_0, (int) $pub_conn_id_3' ) will publicize to all available Twitter accounts, but only 2 of potentially many Facebook connections
* Form data: publicize[]=twitter&publicize[facebook]=$pub_conn_id_0,$pub_conn_id_3
*/
if (!in_array($name, $publicize) && !array_key_exists($name, $publicize)) {
// Skip the whole service
update_post_meta($post_id, $GLOBALS['publicize_ui']->publicize->POST_SKIP . $name, 1);
} else {
if (!empty($publicize[$name])) {
// Seems we're being asked to only push to [a] specific connection[s].
// Explode the list on commas, which will also support a single passed ID
$requested_connections = explode(',', preg_replace('/[\\s]*/', '', $publicize[$name]));
// Get the user's connections and flag the ones we can't match with the requested list to be skipped.
$service_connections = $GLOBALS['publicize_ui']->publicize->get_connections($name);
foreach ($service_connections as $service_connection) {
if (!in_array($service_connection->meta['connection_data']->id, $requested_connections)) {
update_post_meta($post_id, $GLOBALS['publicize_ui']->publicize->POST_SKIP . $service_connection->unique_id, 1);
}
}
}
}
}
}
}
if (!empty($publicize_custom_message)) {
update_post_meta($post_id, $GLOBALS['publicize_ui']->publicize->POST_MESS, trim($publicize_custom_message));
}
set_post_format($post_id, $insert['post_format']);
if (!empty($featured_image)) {
$this->parse_and_set_featured_image($post_id, $delete_featured_image, $featured_image);
}
if (!empty($metadata)) {
foreach ((array) $metadata as $meta) {
$meta = (object) $meta;
$existing_meta_item = new stdClass();
if (empty($meta->operation)) {
$meta->operation = 'update';
}
if (!empty($meta->value)) {
if ('true' == $meta->value) {
$meta->value = true;
}
if ('false' == $meta->value) {
$meta->value = false;
}
}
if (!empty($meta->id)) {
$meta->id = absint($meta->id);
$existing_meta_item = get_metadata_by_mid('post', $meta->id);
}
$unslashed_meta_key = wp_unslash($meta->key);
// should match what the final key will be
$meta->key = wp_slash($meta->key);
$unslashed_existing_meta_key = wp_unslash($existing_meta_item->meta_key);
$existing_meta_item->meta_key = wp_slash($existing_meta_item->meta_key);
switch ($meta->operation) {
case 'delete':
if (!empty($meta->id) && !empty($existing_meta_item->meta_key) && current_user_can('delete_post_meta', $post_id, $unslashed_existing_meta_key)) {
delete_metadata_by_mid('post', $meta->id);
} elseif (!empty($meta->key) && !empty($meta->previous_value) && current_user_can('delete_post_meta', $post_id, $unslashed_meta_key)) {
delete_post_meta($post_id, $meta->key, $meta->previous_value);
} elseif (!empty($meta->key) && current_user_can('delete_post_meta', $post_id, $unslashed_meta_key)) {
delete_post_meta($post_id, $meta->key);
}
break;
case 'add':
if (!empty($meta->id) || !empty($meta->previous_value)) {
continue;
} elseif (!empty($meta->key) && !empty($meta->value) && current_user_can('add_post_meta', $post_id, $unslashed_meta_key) || $this->is_metadata_public($meta->key)) {
add_post_meta($post_id, $meta->key, $meta->value);
}
break;
case 'update':
if (!isset($meta->value)) {
continue;
} elseif (!empty($meta->id) && !empty($existing_meta_item->meta_key) && (current_user_can('edit_post_meta', $post_id, $unslashed_existing_meta_key) || $this->is_metadata_public($meta->key))) {
update_metadata_by_mid('post', $meta->id, $meta->value);
} elseif (!empty($meta->key) && !empty($meta->previous_value) && (current_user_can('edit_post_meta', $post_id, $unslashed_meta_key) || $this->is_metadata_public($meta->key))) {
update_post_meta($post_id, $meta->key, $meta->value, $meta->previous_value);
} elseif (!empty($meta->key) && (current_user_can('edit_post_meta', $post_id, $unslashed_meta_key) || $this->is_metadata_public($meta->key))) {
update_post_meta($post_id, $meta->key, $meta->value);
}
break;
}
}
}
do_action('rest_api_inserted_post', $post_id, $insert, $new);
$return = $this->get_post_by('ID', $post_id, $args['context']);
if (!$return || is_wp_error($return)) {
return $return;
}
if ('revision' === $input['type']) {
$return['preview_nonce'] = wp_create_nonce('post_preview_' . $input['parent']);
}
do_action('wpcom_json_api_objects', 'posts');
return $return;
}
开发者ID:lokenxo,项目名称:familygenerator,代码行数:101,代码来源:class.wpcom-json-api-update-post-endpoint.php
示例10: powerpress_admin_migrate_request
//.........这里部分代码省略.........
}
if (empty($GLOBALS['g_powerpress_update_errors'])) {
$GLOBALS['g_powerpress_update_errors'] = 0;
}
$QueuedEpisodes = get_option('powerpress_migrate_queued');
// Array of key meta_id => URL value pairs
$FoundCount = 0;
if (!empty($QueuedEpisodes)) {
while (list($index, $row) = each($URLs['results'])) {
if ($row['status'] != 'completed') {
// Not migrated
continue;
}
$source_url = $row['source_url'];
$new_url = $row['new_url'];
$found = array_keys($QueuedEpisodes, $source_url);
if (empty($found)) {
continue;
// Nothing found here
}
$FoundCount++;
$GLOBALS['g_powerpress_total_files_found']++;
while (list($null, $meta_id) = each($found)) {
// Get the post meta
$meta_object = get_metadata_by_mid('post', $meta_id);
if (!is_object($meta_object)) {
continue;
}
// Weird
$meta_data = $meta_object->meta_value;
$parts = explode("\n", $meta_data, 2);
$other_meta_data = false;
if (count($parts) == 2) {
list($current_url, $other_meta_data) = $parts;
} else {
$current_url = trim($meta_data);
}
$current_url = trim($current_url);
// We already migrated this one, or it was modified anyway
if ($source_url != $current_url) {
//echo "$source_url != $current_url ";
$GLOBALS['g_powerpress_already_migrated']++;
continue;
}
// Verify the URL:
if (!empty($_POST['PowerPressVerifyURLs'])) {
$verified = powerpress_admin_verify_url($new_url);
if (!empty($verified['error'])) {
// TODO: Handle the error here...
$GLOBALS['g_powerprss_verify_failed_count']++;
continue;
}
}
$new_meta_data = $new_url;
if ($other_meta_data) {
$new_meta_data .= "\n" . $other_meta_data;
}
// save the new URL
if (update_metadata_by_mid('post', $meta_id, $new_meta_data)) {
$CompletedResults['completed_count']++;
$CompletedResults['results'][$meta_id] = $new_url;
} else {
$CompletedResults['error_count']++;
$GLOBALS['g_powerpress_update_errors']++;
}
}
}
if ($CompletedResults['completed_count'] > 0) {
if ($update_option) {
update_option('powerpress_migrate_completed', $CompletedResults);
} else {
add_option('powerpress_migrate_completed', $CompletedResults, '', 'no');
}
// Make sure we are not preloading
powerpress_page_message_add_notice(sprintf(__('Episodes updated successfully.', 'powerpress')));
return;
}
powerpress_page_message_add_notice(sprintf(__('No Episodes updated. Please see results.', 'powerpress')));
return;
}
} else {
powerpress_page_message_add_notice(sprintf(__('No episodes updated.', 'powerpress')));
}
}
break;
}
}
if (!empty($_GET['migrate_action'])) {
check_admin_referer('powerpress-migrate-media');
switch ($_GET['migrate_action']) {
case 'reset_migrate_media':
delete_option('powerpress_migrate_completed');
delete_option('powerpress_migrate_queued');
delete_option('powerpress_migrate_status');
delete_option('powerpress_migrate_results');
powerpress_page_message_add_notice(sprintf(__('Media migration reset successfully.', 'powerpress')));
break;
}
}
}
开发者ID:mattsims,项目名称:powerpress,代码行数:101,代码来源:powerpressadmin-migrate.php
示例11: update_meta
/**
* Add meta to an object.
*
* @param int $id Object ID
* @param array $data {
* @type string|null $key Meta key
* @type string|null $key Meta value
* }
* @return bool|WP_Error
*/
public function update_meta($id, $mid, $data)
{
$id = (int) $id;
$mid = (int) $mid;
$check = $this->check_object($id);
if (is_wp_error($check)) {
return $check;
}
$parent_column = $this->get_parent_column();
$current = get_metadata_by_mid($this->type, $mid);
if (empty($current)) {
return new WP_Error('json_meta_invalid_id', __('Invalid meta ID.'), array('status' => 404));
}
if (absint($current->{$parent_column}) !== $id) {
return new WP_Error('json_meta_' . $this->type . '_mismatch', __('Meta does not belong to this object'), array('status' => 400));
}
if (!array_key_exists('key', $data)) {
$data['key'] = $current->meta_key;
}
if (!array_key_exists('value', $data)) {
$data['value'] = $current->meta_value;
}
if (empty($data['key'])) {
return new WP_Error('json_meta_invalid_key', __('Invalid meta key.'), array('status' => 400));
}
// for now let's not allow updating of arrays, objects or serialized values.
if (!$this->is_valid_meta_data($current->meta_value)) {
$code = $this->type === 'post' ? 'json_post_invalid_action' : 'json_meta_invalid_action';
return new WP_Error($code, __('Invalid existing meta data for action.'), array('status' => 400));
}
if (!$this->is_valid_meta_data($data['value'])) {
$code = $this->type === 'post' ? 'json_post_invalid_action' : 'json_meta_invalid_action';
return new WP_Error($code, __('Invalid provided meta data for action.'), array('status' => 400));
}
if (is_protected_meta($current->meta_key)) {
return new WP_Error('json_meta_protected', sprintf(__('%s is marked as a protected field.'), $current->meta_key), array('status' => 403));
}
if (is_protected_meta($data['key'])) {
return new WP_Error('json_meta_protected', sprintf(__('%s is marked as a protected field.'), $data['key']), array('status' => 403));
}
// update_metadata_by_mid will return false if these are equal, so check
// first and pass through
if ($data['value'] === $current->meta_value && $data['key'] === $current->meta_key) {
return $this->get_meta($id, $mid);
}
$key = wp_slash($data['key']);
$value = wp_slash($data['value']);
if (!update_metadata_by_mid($this->type, $mid, $value, $key)) {
return new WP_Error('json_meta_could_not_update', __('Could not update meta.'), array('status' => 500));
}
return $this->get_meta($id, $mid);
}
开发者ID:dani-ocean,项目名称:wp_angular_api,代码行数:62,代码来源:class-wp-json-meta.php
示例12: save_meta_data
/**
* Update Meta Data in the database.
* @since 2.6.0
*/
protected function save_meta_data()
{
foreach ($this->_meta_data as $array_key => $meta) {
if (is_null($meta->value)) {
if (!empty($meta->id)) {
delete_metadata_by_mid($this->_meta_type, $meta->id);
}
} elseif (empty($meta->id)) {
$new_meta_id = add_metadata($this->_meta_type, $this->get_id(), $meta->key, $meta->value, false);
$this->_meta_data[$array_key]->id = $new_meta_id;
} else {
update_metadata_by_mid($this->_meta_type, $meta->id, $meta->value, $meta->key);
}
}
if (!empty($this->_cache_group)) {
WC_Cache_Helper::incr_cache_prefix($this->_cache_group);
}
$this->read_meta_data();
}
开发者ID:WPprodigy,项目名称:woocommerce,代码行数:23,代码来源:abstract-wc-data.php
示例13: test_string_point_zero_meta_id
/**
* @ticket 37746
*/
function test_string_point_zero_meta_id()
{
$meta_id = add_metadata('user', $this->author->ID, 'meta_key', 'meta_value_2');
$string_mid = "{$meta_id}.0";
$this->assertTrue(floor($string_mid) == $string_mid);
$this->assertNotEquals(false, get_metadata_by_mid('user', $string_mid));
$this->assertNotEquals(false, update_metadata_by_mid('user', $string_mid, 'meta_new_value_2'));
$this->assertNotEquals(false, delete_metadata_by_mid('user', $string_mid));
}
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:12,代码来源:meta.php
示例14: save
//.........这里部分代码省略.........
if (strstr($id, 'insert-')) {
foreach ($fields as &$field) {
if ($field['object_id']) {
$field['object_id'] = is_array($field['object_id']) ? $field['object_id'] : array($field['object_id']);
array_push($field['object_id'], $result_id);
} else {
$field['object_id'] = $result_id;
}
}
}
if (!isset($object_ids[$scope])) {
$object_ids[$scope] = $result_id;
}
}
} elseif (in_array($scope, array('post_meta', 'term_meta', 'user_meta', 'comment_meta'))) {
$meta_type = substr($scope, 0, strpos($scope, '_'));
$meta = piklist_meta::get_meta_properties($meta_type);
foreach ($fields as &$field) {
$field['object_id'] = $field['object_id'] ? $field['object_id'] : $object_ids[$meta_type];
if ($field['object_id'] && !$field['display'] && !strstr($field['field'], ':')) {
$save_as = is_string($field['save_as']) ? $field['save_as'] : $field['field'];
$grouped = in_array($field['type'], self::$field_list_types['multiple_value']);
$current_meta_ids = $wpdb->get_col($wpdb->prepare("SELECT {$meta->id} FROM {$meta->table} WHERE {$meta->object_id} = %d AND meta_key = %s", $field['object_id'], $save_as));
if ($grouped) {
$current_group_meta_ids = $wpdb->get_col($wpdb->prepare("SELECT {$meta->id} FROM {$meta->table} WHERE {$meta->object_id} = %d AND meta_key = %s", $field['object_id'], '_' . piklist::$prefix . $save_as));
}
if (is_array($field['request_value']) && $field['type'] != 'group') {
foreach ($field['request_value'] as $values) {
if (is_array($values)) {
$meta_ids = array();
foreach ($values as $value) {
if (!empty($current_meta_ids)) {
$meta_id = array_shift($current_meta_ids);
update_metadata_by_mid($meta_type, $meta_id, $value);
} else {
$meta_id = add_metadata($meta_type, $field['object_id'], $save_as, $value);
}
if ($meta_id) {
array_push($meta_ids, $meta_id);
}
}
if ($grouped) {
if (!empty($current_group_meta_ids)) {
$group_meta_id = array_shift($current_group_meta_ids);
update_metadata_by_mid($meta_type, $group_meta_id, $meta_ids);
} else {
add_metadata($meta_type, $field['object_id'], '_' . piklist::$prefix . $save_as, $meta_ids);
}
}
} else {
if (is_array($values) && count($values) == 1) {
$values = current($values);
}
if (!empty($current_meta_ids)) {
$meta_id = array_shift($current_meta_ids);
update_metadata_by_mid($meta_type, $meta_id, $values);
} else {
add_metadata($meta_type, $field['object_id'], $save_as, $values);
}
}
}
if (!empty($current_group_meta_ids)) {
foreach ($current_group_meta_ids as $current_group_meta_id) {
delete_metadata_by_mid($meta_type, $current_group_meta_id);
}
}
开发者ID:a42,项目名称:piklist,代码行数:67,代码来源:class-piklist-form.php
示例15: test_non_numeric_meta_id
/**
* @ticket 28315
*/
function test_non_numeric_meta_id()
{
$this->assertFalse(get_metadata_by_mid('user', array(1)));
$this->assertFalse(update_metadata_by_mid('user', array(1), 'meta_new_value'));
$this->assertFalse(delete_metadata_by_mid('user', array(1)));
}
开发者ID:boonebgorges,项目名称:wp,代码行数:9,代码来源:meta.php
示例16: update_meta
/**
* Update meta.
*
* @since 2.7.0
* @param WC_Data
* @param stdClass (containing ->id, ->key and ->value)
*/
public function update_meta(&$object, $meta)
{
update_metadata_by_mid($this->meta_type, $meta->id, $meta->value, $meta->key);
}
开发者ID:woocommerce,项目名称:woocommerce,代码行数:11,代码来源:class-wc-data-store-wp.php
示例17: write_post
//.........这里部分代码省略.........
}
}
if (!empty($insert['post_format'])) {
if ('default' !== strtolower($insert['post_format'])) {
set_post_format($post_id, $insert['post_format']);
} else {
set_post_format($post_id, get_option('default_post_format'));
}
}
if (isset($featured_image)) {
$this->parse_and_set_featured_image($post_id, $delete_featured_image, $featured_image);
}
if (!empty($metadata)) {
foreach ((array) $metadata as $meta) {
$meta = (object) $meta;
$existing_meta_item = new stdClass();
if (empty($meta->operation)) {
$meta->operation = 'update';
}
if (!empty($meta->value)) {
if ('true' == $meta->value) {
$meta->value = true;
}
if ('false' == $meta->value) {
$meta->value = false;
}
}
if (!empty($meta->id)) {
$meta->id = absint($meta->id);
$existing_meta_item = get_metadata_by_mid('post', $meta->id);
}
$unslashed_meta_key = wp_unslash($meta->key);
// should match what the final key will be
$meta->key = wp_slash($meta->key);
$unslashed_existing_meta_key = wp_unslash($existing_meta_item->meta_key);
$existing_meta_item->meta_key = wp_slash($ex
|
请发表评论