• Resolved David Lingren

    (@dglingren)


    I am responding to a topic in my plugin’s support forum:

    Cannot save categories

    I installed and tested Cannonical Attachments and discovered this problem on lines 80-88 of canonical-attachments.php:

    // This processes the post back from the media pages
    function can_attach_update_media_canonical($post, $attachment){
        if( isset( $attachment['canonical-url'] ) ) {
            $canonical = $attachment['canonical-url'];
            $id = $post['ID'];
            can_attach_update_single_canonical($id, $canonical);
        }
    }
    add_filter( 'attachment_fields_to_save', 'can_attach_update_media_canonical', 10, 2 );
    

    All WordPress filters must return a value corresponding to their first input parameter, in this case, $post. Failure to do so causes all sorts of problems. In this case failure to return $post makes it impossible to make any updates on the Media/Edit Media screen.

    It looks like there are a number of filters in this file that do not return the proper values.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Jake Bohall

    (@jblifestyles)

    Hi David,

    Thanks for the comment and helpful insight.

    Are you saying the function added to the filter should have a return value of $post?

    In reviewing the documentation, I’m wondering if I should add return true; if successful…

    Would appreciate if you could add a little insight, and then I’ll go through and update the plugin!

    Thread Starter David Lingren

    (@dglingren)

    Thanks for your good words and the clarification question.

    All WordPress filters are expected to “filter” the value of their first argument. They must return either a new value of that argument or the original value.

    For the function given in my earlier post (can_attach_update_media_canonical) the last line of the function must be:

    return $post;

    Do NOT return true – that would overwrite the content of the $post and
    cause problems.

    The filter return value problems I found in the plugin you’re using would make me wary of using the plugin. Be very thorough in your inspection and testing of the code. Good luck with your plugin.

    Plugin Contributor Jake Bohall

    (@jblifestyles)

    Thanks again David (@dglingren), I have updated the plugin and believe this issue should be resolved. Please let me know if you continue to have any problems.

    Best,

    Jake

    Thread Starter David Lingren

    (@dglingren)

    I have done a quick re-test of the problem I originally reported. It looks like the new plugin version has resolved the “Cannot save categories” issue and changes made on the Media/Edit Media admin submenu are now successful.

    I did notice one other problem with the new version. On the Media/Canonical Attachments admin submenu “All Attachments” view I get this PHP Notice:

    PHP Notice:  Undefined index: filter in \wp-content\plugins\canonical-attachments\tools\bulk-editor.php on line 184
    PHP Stack trace:
    PHP   1. {main}() \wp-admin\upload.php:0
    PHP   2. require_once() \wp-admin\upload.php:10
    PHP   3. do_action() \wp-admin\admin.php:224
    PHP   4. WP_Hook->do_action() \wp-includes\plugin.php:453
    PHP   5. WP_Hook->apply_filters() \wp-includes\class-wp-hook.php:310
    PHP   6. canonical_attachments_plugin() \wp-includes\class-wp-hook.php:286
    PHP   7. include() \wp-content\plugins\canonical-attachments\canonical-attachments.php:182
    PHP   8. Can_Attach_Attachment_List_Table->prepare_items() \wp-content\plugins\canonical-attachments\tools\bulk-editor.php:333
    PHP   9. Can_Attach_Attachment_List_Table->can_attach_get_all_attachments() \wp-content\plugins\canonical-attachments\tools\bulk-editor.php:249
    

    You can find this kind of problem by testing with the WP_DEBUG mode enabled, as explained in:

    Debugging in WordPress

    Good luck with your plugin!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Plugin Prevents Updating Media’ is closed to new replies.