本文整理汇总了PHP中get_metadata_by_mid函数的典型用法代码示例。如果您正苦于以下问题:PHP get_metadata_by_mid函数的具体用法?PHP get_metadata_by_mid怎么用?PHP get_metadata_by_mid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_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: see_also_page_template
function see_also_page_template()
{
$parent_post_id = array_key_exists('parent', $_GET) ? $_GET['parent'] : 0;
if (array_key_exists('meta', $_GET)) {
$meta_id = $_GET['meta'];
} else {
if (is_page('video')) {
$meta_id = get_meta_id_by_key($parent_post_id, 'external_video_url');
}
}
if (empty($meta_id)) {
show_error_message('missing_meta_param', $parent_post_id);
}
$external_url_meta = get_metadata_by_mid('post', $meta_id);
if (!empty($external_url_meta->meta_value)) {
echo do_shortcode('[iframe src="' . $external_url_meta->meta_value . '" width="100% height="100%]');
} else {
show_error_message('missing_url', $parent_post_id);
}
}
开发者ID:rjkrath,项目名称:see-also-shortcode,代码行数:20,代码来源:see-also-shortcode.php
示例3: get_metadata_by_mid
$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 = stripslashes($_POST['meta'][$mid]['key']);
$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();
开发者ID:vivekkodira1,项目名称:wordpress,代码行数:31,代码来源:admin-ajax.php
示例4: ajax_add_bbpmeta
static function ajax_add_bbpmeta()
{
check_ajax_referer('add-bbpmeta', '_ajax_nonce-add-bbpmeta');
$c = 0;
$pid = (int) $_POST['post_id'];
$post = get_post($pid);
if (isset($_POST['bbpmeta_key'])) {
if (!current_user_can('edit_post', $pid)) {
wp_die(-1);
}
if (empty($_POST['bbpmeta_key'])) {
wp_die(1);
}
if ($post->post_status == 'auto-draft') {
$save_POST = $_POST;
// Backup $_POST
$_POST = array();
// Make it empty for edit_post()
$_POST['action'] = 'draft';
// Warning fix
$_POST['post_ID'] = $pid;
$_POST['post_type'] = $post->post_type;
$_POST['post_status'] = 'draft';
$now = current_time('timestamp', 1);
$_POST['post_title'] = sprintf(__('Draft created on %1$s at %2$s'), date(get_option('date_format'), $now), date(get_option('time_format'), $now));
if ($pid = edit_post()) {
if (is_wp_error($pid)) {
$x = new WP_Ajax_Response(array('what' => 'bbpmeta', 'data' => $pid));
$x->send();
}
$_POST = $save_POST;
// Now we can restore original $_POST again
if (!($mid = self::add_meta($pid))) {
wp_die(__('Please provide a valid key and value set.', 'bbpresskr'));
} elseif (!is_numeric($mid)) {
wp_die($mid);
}
} else {
wp_die(0);
}
} elseif (!($mid = self::add_meta($pid))) {
wp_die(__('Please provide a valid key and value set.', 'bbpresskr'));
} elseif (!is_numeric($mid)) {
wp_die($mid);
}
$meta = get_metadata_by_mid('post', $mid);
$pid = (int) $meta->post_id;
$meta = $meta->meta_value;
$x = new WP_Ajax_Response(array('what' => 'meta', 'id' => $mid, 'data' => self::_list_meta_row(array_merge($meta, array('meta_id' => $mid)), $c), 'position' => 1, 'supplemental' => array('postid' => $pid)));
} else {
// Update?
$mid = (int) key($_POST['bbpmeta']);
$new = array_map('wp_unslash', $_POST['bbpmeta'][$mid]);
foreach (array('list') as $what) {
$new[$what] = isset($new[$what]);
}
extract($new, EXTR_SKIP);
// var_dump( $_POST['bbpmeta'], $key, $label);
if (true !== ($validate = self::validate_meta($new))) {
wp_die($validate);
}
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);
}
$meta_value = maybe_unserialize($meta->meta_value);
if ($meta_value != $new) {
if ($meta_value['key'] != $new['key']) {
$current = \bbPressKR\Meta::meta_params($pid);
foreach ($current as $param) {
if ($param['key'] == $new['key']) {
wp_die('Provided key is already in use.', 'bbpresskr');
}
}
}
if (!($u = update_metadata_by_mid('post', $mid, $new))) {
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' => self::_list_meta_row(array_merge($new, array('meta_id' => $mid)), $c), 'position' => 0, 'supplemental' => array('postid' => $meta->post_id)));
}
$x->send();
}
开发者ID:082net,项目名称:bbpresskr,代码行数:87,代码来源:meta.php
示例5: set_custom_fields
/**
* Set custom fields for post.
*
* @since 2.5.0
*
* @param int $post_id Post ID.
* @param array $fields Custom fields.
*/
public function set_custom_fields($post_id, $fields)
{
$post_id = (int) $post_id;
foreach ((array) $fields as $meta) {
if (isset($meta['id'])) {
$meta['id'] = (int) $meta['id'];
$pmeta = get_metadata_by_mid('post', $meta['id']);
if (isset($meta['key'])) {
$meta['key'] = wp_unslash($meta['key']);
if ($meta['key'] !== $pmeta->meta_key) {
continue;
}
$meta['value'] = wp_unslash($meta['value']);
if (current_user_can('edit_post_meta', $post_id, $meta['key'])) {
update_metadata_by_mid('post', $meta['id'], $meta['value']);
}
} elseif (current_user_can('delete_post_meta', $post_id, $pmeta->meta_key)) {
delete_metadata_by_mid('post', $meta['id']);
}
} elseif (current_user_can('add_post_meta', $post_id, wp_unslash($meta['key']))) {
add_post_meta($post_id, $meta['key'], $meta['value']);
}
}
}
开发者ID:sb-xs,项目名称:que-pour-elle,代码行数:32,代码来源:class-wp-xmlrpc-server.php
示例6: test_update_meta
function test_update_meta()
{
// Add a unique post meta item
$this->assertInternalType('integer', $mid1 = add_post_meta($this->post_id, 'unique_update', 'value', true));
// Add two non unique post meta item
$this->assertInternalType('integer', $mid2 = add_post_meta($this->post_id, 'nonunique_update', 'value'));
$this->assertInternalType('integer', $mid3 = add_post_meta($this->post_id, 'nonunique_update', 'another value'));
//Check they exist
$this->assertEquals('value', get_post_meta($this->post_id, 'unique_update', true));
$this->assertEquals(array('value'), get_post_meta($this->post_id, 'unique_update', false));
$this->assertEquals('value', get_post_meta($this->post_id, 'nonunique_update', true));
$this->assertEquals(array('value', 'another value'), get_post_meta($this->post_id, 'nonunique_update', false));
// Update them
$this->assertTrue(update_meta($mid1, 'unique_update', 'new'));
$this->assertTrue(update_meta($mid2, 'nonunique_update', 'new'));
$this->assertTrue(update_meta($mid3, 'nonunique_update', 'another new'));
//Check they updated
$this->assertEquals('new', get_post_meta($this->post_id, 'unique_update', true));
$this->assertEquals(array('new'), get_post_meta($this->post_id, 'unique_update', false));
$this->assertEquals('new', get_post_meta($this->post_id, 'nonunique_update', true));
$this->assertEquals(array('new', 'another new'), get_post_meta($this->post_id, 'nonunique_update', false));
// Slashed update
$data = "'quote and \\slash";
$this->assertTrue(update_meta($mid1, 'unique_update', addslashes($data)));
$meta = get_metadata_by_mid('post', $mid1);
$this->assertEquals($data, $meta->meta_value);
}
开发者ID:boonebgorges,项目名称:wp,代码行数:27,代码来源:meta.php
示例7: write_post
//.........这里部分代码省略.........
} else {
delete_post_meta($post_id, $GLOBALS['publicize_ui']->publicize->POST_SKIP . $service_connection->unique_id);
}
}
} else {
// delete all SKIP values; it's okay to publish to all connected IDs for this service
foreach ($service_connections as $service_connection) {
delete_post_meta($post_id, $GLOBALS['publicize_ui']->publicize->POST_SKIP . $service_connection->unique_id);
}
}
}
}
}
}
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 (isset($featured_image)) {
parent::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);
// make sure that the meta id passed matches the existing meta key
if (!empty($meta->id) && !empty($meta->key)) {
$meta_by_id = get_metadata_by_mid('post', $meta->id);
if ($meta_by_id->meta_key !== $meta->key) {
continue;
// skip this meta
}
}
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 (isset($input['type']) && 'revision' === $input['type']) {
$return['preview_nonce'] = wp_create_nonce('post_preview_' . $input['parent']);
}
// workaround for sticky test occasionally failing, maybe a race condition with stick_post() above
$return['sticky'] = true === $sticky;
if (!empty($media_results['errors'])) {
$return['media_errors'] = $media_results['errors'];
}
do_action('wpcom_json_api_objects', 'posts');
return $return;
}
开发者ID:brooklyntri,项目名称:btc-plugins,代码行数:101,代码来源:class.wpcom-json-api-update-post-v1-2-endpoint.php
示例8: write_post
//.........这里部分代码省略.........
if (empty($publicize_custom_message)) {
delete_post_meta($post_id, $GLOBALS['publicize_ui']->publicize->POST_MESS);
} else {
update_post_meta($post_id, $GLOBALS['publicize_ui']->publicize->POST_MESS, trim($publicize_custom_message));
}
}
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($existing_meta_item->meta_key);
// make sure that the meta id passed matches the existing meta key
if (!empty($meta->id) && !empty($meta->key)) {
$meta_by_id = get_metadata_by_mid('post', $meta->id);
if ($meta_by_id->meta_key !== $meta->key) {
continue;
// skip this meta
}
}
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':
开发者ID:Nihilivin,项目名称:jetpack,代码行数:67,代码来源:class.wpcom-json-api-update-post-endpoint.php
示例9: test_edit_custom_fields
function test_edit_custom_fields() {
$contributor_id = $this->make_user_by_role( 'contributor' );
$post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
$post_id = wp_insert_post( $post );
$mid_edit = add_post_meta( $post_id, 'custom_field_key', '12345678' );
$mid_delete = add_post_meta( $post_id, 'custom_field_to_delete', '12345678' );
$new_title = 'Post test (updated)';
$post2 = array(
'post_title' => $new_title,
'custom_fields' =>
array(
array( 'id' => $mid_delete ),
array( 'id' => $mid_edit, 'key' => 'custom_field_key', 'value' => '87654321' ),
array( 'key' => 'custom_field_to_create', 'value' => '12345678' )
)
);
$result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) );
$this->assertNotInstanceOf( 'IXR_Error', $result );
$this->assertTrue($result);
$out = get_post( $post_id );
$this->assertEquals( $new_title, $out->post_title );
$edited_object = get_metadata_by_mid( 'post', $mid_edit );
$this->assertEquals( '87654321', $edited_object->meta_value );
$this->assertFalse( get_metadata_by_mid( 'post', $mid_delete ) );
$created_object = get_post_meta( $post_id, 'custom_field_to_create', true );
$this->assertEquals( $created_object, '12345678' );
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:33,代码来源:editPost.php
示例10: 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
示例11: powerpress_admin_migrate_request
function powerpress_admin_migrate_request()
{
if (!empty($_GET['migrate_step'])) {
switch ($_GET['migrate_step']) {
case 1:
$GLOBALS['powerpress_migrate_stats'] = powerpress_admin_extension_counts();
break;
}
}
if (!empty($_POST['migrate_action'])) {
check_admin_referer('powerpress-migrate-media');
switch ($_POST['migrate_action']) {
case 'queue_episodes':
if (!empty($_POST['Migrate'])) {
powerpress_admin_queue_files($_POST['Migrate']);
// Else error message handled in functoin called above
}
break;
case 'update_episodes':
// <input type="hidden" name="migrate_action" value="update_episodes" />
$MigrateResultsPrevious = get_option('powerpress_migrate_results');
$add_option = false;
if ($MigrateResultsPrevious == false) {
$add_option = true;
}
unset($MigrateResultsPrevious);
// Free up the memory
//$URLs = powerpress_admin_migrate_get_migrated_by_status('completed');
$URLs = powerpress_admin_migrate_get_migrated_by_status('all');
if (!empty($URLs)) {
$URLs['updated_timestamp'] = current_time('timestamp');
if ($add_option) {
add_option('powerpress_migrate_results', $URLs, '', 'no');
} else {
update_option('powerpress_migrate_results', $URLs);
}
if (!empty($URLs['results'])) {
$update_option = true;
$CompletedResults = get_option('powerpress_migrate_completed');
if ($CompletedResults == false) {
$update_option = false;
}
if (empty($CompletedResults['completed_count'])) {
$CompletedResults['completed_count'] = 0;
}
if (empty($CompletedResults['error_count'])) {
$CompletedResults['error_count'] = 0;
}
if (empty($GLOBALS['g_powerprss_verify_failed_count'])) {
$GLOBALS['g_powerprss_verify_failed_count'] = 0;
}
if (empty($GLOBALS['g_powerpress_already_migrated'])) {
$GLOBALS['g_powerpress_already_migrated'] = 0;
}
if (empty($GLOBALS['g_powerpress_total_files_found'])) {
$GLOBALS['g_powerpress_total_files_found'] = 0;
}
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;
}
//.........这里部分代码省略.........
开发者ID:mattsims,项目名称:powerpress,代码行数:101,代码来源:powerpressadmin-migrate.php
示例12: delete_meta
/**
* Delete meta from an object.
*
* @param int $id Object ID
* @param int $mid Metadata ID
* @return array|WP_Error Message on success, WP_Error otherwise
*/
public function delete_meta($id, $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));
}
// 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 (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 (!delete_metadata_by_mid($this->type, $mid)) {
return new WP_Error('json_meta_could_not_delete', __('Could not delete meta.'), array('status' => 500));
}
return array('message' => __('Deleted meta'));
}
开发者ID:dani-ocean,项目名称:wp_angular_api,代码行数:34,代码来源:class-wp-json-meta.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: ajax_revet_file
/**
* revert File version
* @author Ohad Raz
* @since 2.0
* @access public
*/
public function ajax_revet_file()
{
check_ajax_referer('revert_file');
$meta = get_metadata_by_mid('file', intval($_GET['mid']));
if (!$meta) {
echo json_encode(array('error' => __('Error restoring file version', 'ace')));
die;
}
$meta = $meta->meta_value;
$m = __('Make sure to save changes if you want the restore to take place.', 'ace');
echo json_encode(array('version' => stripslashes($meta['version']), 'm' => $m));
die;
}
开发者ID:juandanceswild,项目名称:aomp-backup,代码行数:19,代码来源:advanced-code-editor.php
示例15: delete_item
/**
* Delete meta from an object.
*
* @param WP_REST_Request $request
* @return WP_REST_Response|WP_Error Message on success, WP_Error otherwise
*/
public function delete_item($request)
{
$parent_id = (int) $request['parent_id'];
$mid = (int) $request['id'];
$force = isset($request['force']) ? (bool) $request['force'] : false;
// We don't support trashing for this type, error out
if (!$force) {
return new WP_Error('rest_trash_not_supported', __('Meta does not support trashing.'), array('status' => 501));
}
$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}) !== (int) $parent_id) {
return new WP_Error('rest_meta_' . $this->parent_type . '_mismatch', __('Meta does not belong to this object'), 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 (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 (!delete_metadata_by_mid($this->parent_type, $mid)) {
return new WP_Error('rest_meta_could_not_delete', __('Could not delete meta.'), array('status' => 500));
}
/**
* Fires after a meta value is deleted via the REST API.
*
* @param WP_REST_Request $request The request sent to the API.
*/
do_action('rest_delete_meta', $request);
return rest_ensure_response(array('message' => __('Deleted meta')));
}
开发者ID:walkthenight,项目名称:walkthenight-wordpress,代码行数:42,代码来源:class-wp-rest-meta-controller.php
示例16: test_delete_item_no_trash
public function test_delete_item_no_trash()
{
wp_set_current_user($this->user);
$this->allow_user_to_manage_multisite();
$meta_id = add_user_meta($this->user, 'testkey', 'testvalue');
$request = new WP_REST_Request('DELETE', sprintf('/wp/v2/users/%d/meta/%d', $this->user, $meta_id));
$response = $this->server->dispatch($request);
$this->assertErrorResponse('rest_trash_not_supported', $response, 501);
// Ensure the meta still exists
$meta = get_metadata_by_mid('user', $meta_id);
$this->assertNotEmpty($meta);
}
开发者ID:WP-API,项目名称:wp-api-meta-endpoints,代码行数:12,代码来源:test-rest-meta-users-controller.php
示例17: write_post
//.........这里部分代码省略.........
}
}
$post_id = wp_insert_post(add_magic_quotes($insert), true);
if ($has_media) {
$this->api->trap_wp_die('upload_er
|
请发表评论