Make WordPress Core

Changeset 10711


Ignore:
Timestamp:
03/04/2009 10:59:16 PM (15 years ago)
Author:
ryan
Message:

Check for empty meta keys. Props Denis-de-Bernardy, markedwards. fixes #7953

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r10693 r10711  
    511511 */
    512512function add_post_meta($post_id, $meta_key, $meta_value, $unique = false) {
     513    if ( !$meta_key )
     514        return false;
     515   
    513516    global $wpdb;
    514517
     
    559562    $meta_value = maybe_serialize( stripslashes_deep($meta_value) );
    560563
     564    if ( !$meta_key )
     565        return false;
     566   
    561567    if ( empty( $meta_value ) )
    562568        $meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta_key ) );
     
    590596 */
    591597function get_post_meta($post_id, $key, $single = false) {
     598    if ( !$key )
     599        return '';
     600   
    592601    $post_id = (int) $post_id;
    593602
     
    638647    $meta_key = stripslashes($meta_key);
    639648
     649    if ( !$meta_key )
     650        return false;
     651   
    640652    if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = %s AND post_id = %d", $meta_key, $post_id ) ) ) {
    641653        return add_post_meta($post_id, $meta_key, $meta_value);
     
    667679 */
    668680function delete_post_meta_by_key($post_meta_key) {
     681    if ( !$post_meta_key )
     682        return false;
     683   
    669684    global $wpdb;
    670685    if ( $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key)) ) {
     
    740755 */
    741756function get_post_custom_values( $key = '', $post_id = 0 ) {
     757    if ( !$key )
     758        return null;
     759   
    742760    $custom = get_post_custom($post_id);
    743761
Note: See TracChangeset for help on using the changeset viewer.