Advertisement
creacom

call to add_filter used with wordpress class

Dec 21st, 2011
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.63 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package myplug
  4. */
  5. /*
  6. Plugin Name: myplug
  7. Plugin URI: myplug
  8. Description: myplug
  9. Domain Path: /lang
  10. Version: 0.1
  11. Author: myplug
  12. Author URI: myplug
  13. License: GPLv2 or later
  14. */
  15. if ( ! class_exists('myplug') )
  16. {
  17.     class myplug
  18.     {
  19.         public function __construct()
  20.         {
  21.             add_action('admin_menu', array(&$this, 'myplug_adminmenu'));
  22.         }
  23.        
  24.         public function myplug_upload_dir_inside()
  25.         {
  26.             return array(
  27.                 'path' =>plugin_dir_path( __FILE__ ).'uploadtmp',
  28.                 'url' => plugin_dir_url( __FILE__ ).'uploadtmp',
  29.                 'subdir' => '',
  30.                 'basedir' =>plugin_dir_path( __FILE__ ).'uploadtmp',
  31.                 'baseurl' => plugin_dir_url( __FILE__ ).'uploadtmp',
  32.                 'error' => false
  33.             );
  34.         }
  35.  
  36.         public function myplug_menu()
  37.         {
  38. //Neither this call works
  39. // add_filter('upload_dir', array(&$this, 'myplug_upload_dir_inside'));
  40. //Nor this call either works !
  41. // add_filter('upload_dir', 'myplug_upload_dir_outside');
  42.             echo '<pre>'; print_r(wp_upload_dir()); echo '</pre>';
  43.             wp_enqueue_script('plupload-handlers');
  44.             $form_class = 'media-upload-form type-form validate';
  45.             echo '<form enctype="multipart/form-data" method="post" action="'.admin_url("media-upload.php?inline=&amp;upload-page-form=").'" class="'.$form_class.'" id="file-form">';
  46.             media_upload_form();
  47.             echo '
  48.             <script type="text/javascript">
  49.             jQuery(function($){
  50.                 var preloaded = $(".media-item.preloaded");
  51.                 if ( preloaded.length > 0 ) {
  52.                     preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, "")},"");});
  53.                 }
  54.                 updateMediaForm();
  55.                 post_id = 0;
  56.                 shortform = 1;
  57.             });
  58.             </script>
  59.             <input type="hidden" name="post_id" id="post_id" value="0" />';
  60.             wp_nonce_field("media-form");
  61.             echo '<div id="media-items" class="hide-if-no-js"></div>';
  62.             submit_button( __( "Save all changes" ), "button savebutton hidden", "save" );
  63.             echo '</form>';
  64.             // remove_filter('upload_dir', 'manuland_upload_dir');
  65.         }
  66.        
  67.         public function myplug_adminmenu()
  68.         {
  69.             add_menu_page('Myplugin', 'Myplugin', 'manage_options', 'myplug_menu', array(&$this, 'myplug_menu'));
  70.         }
  71.     }
  72. }
  73. $myplug = new myplug();
  74. function myplug_upload_dir_outside()
  75. {
  76.     return array(
  77.         'path' =>plugin_dir_path( __FILE__ ).'uploadtmp',
  78.         'url' => plugin_dir_url( __FILE__ ).'uploadtmp',
  79.         'subdir' => '',
  80.         'basedir' =>plugin_dir_path( __FILE__ ).'uploadtmp',
  81.         'baseurl' => plugin_dir_url( __FILE__ ).'uploadtmp',
  82.         'error' => false
  83.     );
  84. }
  85. //This call works though !
  86. //add_filter('upload_dir', 'myplug_upload_dir_outside');
  87. //BUT this filter can't be limited to this plugin : when i upload from library the upload dir is also filtered
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement