0

I want to write a plugin for wordpress that in some cases will show some content as if it were a post or page as an end result of a form processing.

My idea is to add a hook that checks for and intercepts a GET or POST request from a form, and when processed, shows some message as a post/page.

As I wish to be anble to change the text, I would like to have a plugin page that has the text editor and store the result from this in the database for when needed.

My question is then: should such a message, which is in the end a post/page be written to wp_options, or is there a better aproach?

1

Answering short: it's legit and proper solution.

Answering in details:

1. About the table capacity

Considering _options table structure

option_id    | bigint(20)
option_name  | varchar(64)
option_value | longtext
autoload     | varchar(20)

and the fact that option_value (which is going to contain your HTML), is longtext - it can store L + 4 bytes, where L < 2^32 (4 Gigabytes of info).

I'd like to say more: serialized array, which can contain options stored as a text, is much more effective THAN key-value pairs in terms of db optimization (understand as storing a short strings under meta/option_name - meta/option_value, is less effective).

2. About storing the HTML

Dont forget about charaters escaping there.

<?php echo stripslashes( get_option( 'your_option' ) ); ?>, in order to output the content.

More advanced solution may be a serialized array. But it's more suitable if you want to store some key-value "option" pairs additionally to your HTML.

3. The API.

_options table can be accessed via user-friendly API

  1. get_option()
  2. add_option()
  3. update_option()

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.