-1
function asec_get_link_color() {
        global $wpdp;
    $query = "SELECT value FROM wp_theme_options WHERE property = 'link-color'";
    $result = $wpdb->get_results($sql);
    return $result;
}

It doesn't return any value.

1
  • global $wpdp won't get you very far. Commented Jul 10, 2013 at 17:27

1 Answer 1

2

You've made no attempt to check for errors, e.g. $result may be false, also your code would fail if there was more than one result returned.

So instead of using a custom table, and reinventing the wheel, use the provided APIs:

get_theme_mod and set_theme_mod

So your code now becomes:

function asec_get_link_color( $default_color='blue') {
    return get_theme_mod( 'link-color', $default_color );
}

Using set_theme_mod also handles all your SQL escaping and security code for you.

Also keep in mind that you use wp_theme_options as your table name, but you're not the only person building themes. At the very least, add an identifier unique to your theme and yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.