Your SlideShare is downloading. ×
0
Plugins debugging and developing
Plugins debugging and developing
Plugins debugging and developing
Plugins debugging and developing
Plugins debugging and developing
Plugins debugging and developing
Plugins debugging and developing
Plugins debugging and developing
Plugins debugging and developing
Plugins debugging and developing
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Plugins debugging and developing

321

Published on

Published in: Technology, Art & Photos
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
321
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • With this header in place, your plugin will be listed on the Plugins admin screen.You will have to click the Activate link for the plugin to actually be enabled.
  • If my_awesome_function() is part of a plugin, this function will be called on every page load.The bad part is the array_map of stripslashes on the $_POST array.This is what happens when I code without caffeine! Anytime the $_POST array is present, each element of that array will be stripped of slashes.Why is this bad? If the $_POST array contained a nested array, that array would be trashed and converted to a string == ‘Array’. Oopse...
  • This only fixes part of the problem.Lets say that your plugin has an admin screen with a simple form. When the user clicks the submit button, you want to take that POST data and save it to the database. You need to make sure that your plugin’s form processor only executes when the $_POST array comes from it’s admin screen.
  • There are a couple of ways to do this. Most admin screens will have a page slug associated with them. For example, if you have a settings screen for your plugin, the URL to it should be something like:
  • Transcript

    • 1. Plugins: Debugging and Developing<br />
    • 2. Plugins are tools to extend the functionality of WordPress.<br />Q: Has anyone here ever developed a WordPress plugin?<br />
    • 3. Are you wishing that WordPress had some new or modified feature?<br />Always check the WordPress Plugin Repository first!<br />No one wants to re-invent the wheel.<br />Chances are that someone else has already created a plugin that would suite your needs.<br />
    • 4. Plugins live in /wp-content/plugins/<br />The plugin header lets WordPress know that this file is a plugin.<br /><?php<br />/*<br />Plugin Name: Vox Importer<br />Plugin URI: http://wordpress.org/extend/plugins/vox-importer/<br />Description: Import posts, comments, tags, and attachments from a Vox.com blog.<br />Author: Automattic, Brian Colinger<br />Author URI: http://automattic.com/<br />Version: 0.6<br />License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html<br />*/<br />?><br />
    • 5. Potential Gotcha’s<br />(How to break 10 million blogs with one line of code)<br />
    • 6. <?php<br />function my_awesome_function() {<br />$_POST = array_map( 'stripslashes', $_POST );<br />// ...Insert something into the database<br />}<br />my_awesome_function();<br />?><br />What’s wrong with this code?<br />
    • 7. The proper way of doing this is to wrap this line with a conditional statement:<br /> $_POST = array_map( 'stripslashes_deep', $_POST );<br />stripslashes_deep() is a WordPress function that can properly handle multi-dimensional arrays.<br />
    • 8. /wp-admin/options-general.php?page=my-awesome-plugin<br />
    • 9. You could wrap the array_map code in a conditional check to make sure that you only run this code on this page.<br />if ( 'my-awesome-plugin' == $_GET['page'] ) {<br />$_POST = array_map( 'stripslashes_deep', $_POST );<br />}<br />
    • 10. Another way would be to create a nonce field in the submission form and check for it before processing the POST data.<br />Add this to your form:<br /><input name="update_settings" type="hidden"<br />value="<?phpecho wp_create_nonce('update_settings'); ?>" /><br />In your plugin form handler function add this:<br />if ( !wp_verify_nonce( $_POST['update_settings'], 'update_settings' ) )<br />return;<br />Or you could check the referrer:check_admin_referer( $_GET['action'],'update_settings');<br />

    ×