0

Problems with a plugin I am developing, and the 'Are you sure you want to do this?' message.

Not my first plugin, and it is following the general guidelines for development. The plugins' function is to perform a database query on a button press on the plugin settings screen. That all functions properly.

The function for the button press (in a form) displays the form/button on the Settings page. The form's action is to itself, so the plugin settings page is displayed on the button press/form submit (after performing the desired function for the button/submit).

I have noticed the following

  • The plugin cannot be deactivated on the plugin screen - the screen is redrawn, but no deactivation message and the plugin is still active. Plugin deactivation code is standard and per Codex; nothing fancy,
    just deactivate.
  • The 'Are you sure..' error message is displayed on a post
    save/publish attempt. Post is not saved.
  • This error message is in the wp-admin error log:

"PHP Warning: array_merge(): Argument #2 is not an array in /[specific file location redacted]/wp-includes/load.php on line 664'

  • There is no nonce checking in the form on the settings page (used to be, but removed that during testing to no avail) (And yes, I know the risk; it's not there while I debug things, and Post values from the form are already sanitized elsewhere.)

  • There is no check_admin_referer() code in my plugin

  • I have verified the plugin causing the error by removing the plugin folder
    manually

  • It is not a permissions error.
  • It is not a memory error (the plugin increases the memory_limit to 256M)

  • Have asked the googles; nothing helpful there.

What should I be looking for in my plugin code (too long to reproduce here)? Where should the form for the button be displayed optimially (or is that even related to the error)?

0

It appears that the issue is related to my uses of this code:

$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING) ;
$_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING) ;

I had placed this at the top of the plugin (outside of the plugin's class); I used it to sanitize any GET and POST values.

When you do any action (like a Post or Page Publish, or a plugin deactivate) that results in a $_POST, the wp_magic_quotes() function in load.php gets called (via the check_admin_referer() function, called on all $_POSTs on all pages, including a Publish and a plugin deactivate POST):

// code fragment from wp_magic_quote() in load.php
// Force REQUEST to be GET + POST.
$_REQUEST = array_merge( $_GET, $_POST );

My filter_input_array code (which I use to sanitize $_GETs and $_POSTs) was causing the second parameter in the array_merge() to not be an array, which caused this error to show up in the wp-admin folder error log:

    "PHP Warning: array_merge(): Argument #2 is not an array 
in /[specific file location redacted]/wp-includes/load.php 
on line 664'

By moving the filter_input_array statements (first code block above) inside the check for the Submit button on the plugin settings form, the error went away. Apparently, my filter_input_array statements conflicted with the wp_magic_quotes use of the $_POST parameters.

Moving my filter_input_array statements inside the 'check for the plugin settings page button submit' appears to have fixed the problem.

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.