Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to set certain settings from the theme functions file for example the setting Enable threaded (nested) comments ca I set it to allow 2 as the answer without having the user go into the admin panel and setting it for there wordpress comment settings?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

I am satisfied with Nikolay Yordanov's answer. Just generalizing the solution.

Yes, we can update WordPress options programmatically. WordPress saves options in wp_options table. wp_options holds two rows option_name and option_value to store key and value respectively. We need right option_name and a way to save value in wp_options table.

As we know, we can update threaded comments option by going to wp-admin/options-discussion.php. By opening the page options-discussion.php in a code editor, you can easily found the required option_name to update.

WordPress Options-Discussion

Now, if one can get an option, also one can update it. What you need is WordPress function update_option.

Final PHP Snippet


function update_thread_comments_depth($depth){
    //Validation check
    if(is_int($depth) && 0 < $depth){

        update_option('thread_comments_depth', $width);

        return true; //success
    }

    return false; //failure
}

Hope, it will help to update other options as well, just open right file in code editor and find the required option name.

Ref: http://www.thebinary.in/blog/change-wordpress-options-programmatically/

share|improve this answer
add comment

Well, you can do something like this which will always reset the option to 2:

add_action('init', 'update_comment_depth');
function update_comment_depth() {
  update_option('thread_comments_depth', 2);
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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