【发布时间】:2014-03-15 14:09:32
【问题描述】:
我希望我的插件设置页面包含所有当前管理的文件的列表,并允许它们添加新的文件路径。像这样:
浏览器中的虚构布局
Files Managed:
* /wp-content/plugins/myplugin/files/file1
* /wp-content/plugins/myplugin/files/file1
* /wp-content/plugins/myplugin/files/file1
Add New File:
[File_Name]
[submit]
我将如何实现这一目标?以前,我只是将页面提交给options.php(Wordpress 内置选项处理程序),但这完全替换了该选项,并且不允许添加另一个选项。
我能够想出的唯一“解决方案”(这似乎很老套)就是自己处理并做到这一点:
/* They've submitted the new file to manage, so we're in a POST situation */
//Get the existing options
$existing = get_option( "managed_files" );
//First time (doesn't exist yet)
if ( $existing === false ) add_option( "managed_files", array( $_POST[ "filename" ] ) );
//Already exists
else
{
//Add to current values
array_push( $existing, $_POST[ "filename" ] );
//Update Option
update_option( "managed_files", $existing );
}
这是唯一的方法吗?
【问题讨论】: