2

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?

5

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.

3

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);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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