Читать книгу Professional WordPress Plugin Development - Brad Williams - Страница 84
Segregating Plugin Options
ОглавлениеA function to initiate your plugin options, run on plugin activation as covered in Chapter 2, could then look like the following:
<?php function pdev_plugin_create_options() { // front-end options: autoloaded add_option( 'pdev_plugin_options', array( 'color' => 'red', 'fontsize' => '120%', 'border' => '2px solid red' ) ); // back-end options: loaded only if explicitly needed add_option( 'pdev_plugin_admin_options', array( 'version' => '1.0', 'donate_url' => 'https://example.com/', 'advanced_options' => '1' ), '', 'no' ); } ?>
Again, don't forget the empty third parameter before the autoload
value. This might seem a bit convoluted, and actually it is for so few options set. This professional technique makes sense if your plugin features dozens of options, or options containing long text strings.
NOTE As a rule of thumb, if your options are needed by the public part of the blog, save them with autoload
. If they are needed only in the admin area, save them without autoload
.