I am new to wordpress and I am trying to create a simple delivery settings plugin, adding it to the general section. As soon as I click on activate I see a white screen. I am not sure what I am doing wrong. Any help would be really appreciated. Thanks!!
function delInfoSec()
{
add_settings_section("delivery_info", "Delivery Info", "delInfoHtml", "general");
}
add_settings_field("min_del","Minimum Delivery","minDelCallBack","general","delivery_info");
register_setting("general","min_del");
add_action("admin_init","delInfoSec");
function minDelCallBack(){
echo "<h3>Enter minimum delivery</h3>";
}
function delInfoHtml(){
echo "<input type='text'>";
}
Two problems. This first tip will help you troubleshoot moving forward:
To get useful debugging information while you are developing, you should modify your
wp-config.php
file. Find the line that saysdefine('WP_DEBUG', FALSE);
and change it todefine('WP_DEBUG', TRUE);
– this will cause WordPress and PHP to output the errors so you can see exactly what is happening.Your code problem is that you cannot call some of these functions outside of the appropriate hooks. They aren’t available unless you are in “admin”, so you need to call them inside of
admin_init
.Here’s an article that covers ALL of what you are trying to do in a complete tutorial: http://code.tutsplus.com/tutorials/the-complete-guide-to-the-wordpress-settings-api-part-2-sections-fields-and-settings–wp-24619
Your code should be modified as follows:
The white page means there are some error on your plugin. Please check log file which will tell you the exact error on page with line number. If every thing looks fine please also check the php version supported by plugin and the php version on which server is running. Some time php version mismatch also gives you white page.
BR