• I’ve come across a couple of errors from Polylang in combination with another plugin, in my case Profile Builder Pro v.2.1.9.

    Warning: Missing argument 2 for PLL_Admin_Sync::add_meta_boxes() in [MY_SERVER_PATH]\wp-content\plugins\polylang\admin\admin-sync.php on line 46
    Warning: Missing argument 2 for PLL_Plugins_Compat::cft_copy() in [MY_SERVER_PATH]\wp-content\plugins\polylang\include\plugins-compat.php on line 226

    After googling for these errors I found that they were more common and not limited to my specific case/plugin. I looked at the code and found that both mentioned functions need the same parameters.

    @param string $post_type unused
    @param object $post current post object

    What strikes me is that the first parameter $post_type is stated as ‘unused’. Is this because of legacy? I’d think an unused parameter could be removed completely, or if it’s a optional parameter, moved to the end of the argument list with a default value.
    My guess is that these other plugins send the $post parameter, but it gets handled as the $post_type parameter while post is still missing.

    The following edit in both functions made the errors go away, but is this an actual fix or am I likely to break stuff?
    – giving the second parameter a default value of false
    – using $post_type as $post when only one parameter is given

    function [FUNCTION_NAME]($post_type, $post=false) {
      if ( !$post ) $post = $post_type;
      [...]

    https://wordpress.org/plugins/polylang/

Viewing 1 replies (of 1 total)
  • Plugin Author Chouby

    (@chouby)

    Hi!

    These two functions are hooking to the add_meta_boxes action. As you can see in the doc, this action has two arguments. Polylang doesn’t use the first (as stated in comment) but only the second.

    It’s not the first time the warning is reported. My guess is that it comes from themes/plugins wrongly firing the action add_meta_boxes with only one argument instead of 2 as in WP. You should report this bug to conflicting plugins/themes authors.

Viewing 1 replies (of 1 total)

The topic ‘Polylang possible fix for 'Missing argument 2' error’ is closed to new replies.