Support » Plugins » Hacks » Problem of use of add_filter within a class plugin

  • I made simple class plugin to test upload capacity in a personnalized directory. After a search i came to this : But as you can see if i call add_filter from within the class :

    add_filter('upload_dir', array(&$this, 'myplug_upload_dir_inside'));
    add_filter('upload_dir', 'myplug_upload_dir_outside');
    my upload is done to the standard directory

    But if i use the add_filter from outside the class, the upload is correctly directed to where i expected. The problem here is this filter is then available to all pages : when i then upload from the Library, the file is set to the new directory too.

    How to make this filter have a limited action to this plugin / page using my code structure ?


Viewing 3 replies - 1 through 3 (of 3 total)
  • I usually set all of my WP actions in a static method and call them like this in my constructor or other setup method

    add_filter('upload_dir', array(__CLASS__, 'static_method_name'));

    You’re right. But this won’t do.
    Sorry for thos who looked at my paste , it was the wrong one (for a topic closed).
    The real paste for this problem is

    I must add that the upload part is directly taken from the wp-admin/media-upload.php page

    I tried to add a
    if (isset($_GET[“page”]) && $_GET[“page”] == “myplug_menu”)
    add_filter(‘upload_dir’, ‘myplug_upload_dir_outside’);
    but this doesn’t work since i use the media-upload page code

    olivier did you ever figure out how to use add_filter inside an class?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem of use of add_filter within a class plugin’ is closed to new replies.