How to change upload dir for custom plugin?

I like to change the media upload directory for my custom plugin. Now i am testing with this in functions.php

 function custom_upload_directory( $args ) {
    // Check for our plugin pages
    if (($_GET['page']=="contender_add") || ($_GET['page']=="contender_edit")){
        $args['path'] = plugin_dir_path(__FILE__) . "uploads/test";
        $args['url']  = plugin_dir_url(__FILE__) . "uploads/test";
        $args['basedir'] = plugin_dir_path(__FILE__) . "uploads/test";
        $args['baseurl'] = plugin_dir_url(__FILE__) . "uploads/test";
    }
    return $args;
}

add_filter( 'upload_dir', 'custom_upload_directory' );

Also how do add my custom upload folder to the media uploader library tab?

Read More

Regards

Related posts

1 comment

  1. IN YOUR wp-config.php

       define('MY_', '/');
    define('MY_DIR','ui'); 
    define('MY_DIR_PLUGINS', 'plugins');
    define('MY_DIR_CONTENT', 'resource');
    define('MY_DIR_MEDIA', 'media');
    define('MY_PAGE_TYPE', 'http://');
    
    if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__)  . MY_. MY_DIR);  
    define('WP_HOME',MY_PAGE_TYPE.$_SERVER['HTTP_HOST']);
    define('WP_SITEURL',WP_HOME. MY_.MY_DIR);
    
    //URL DE CONTENIDO:
    define('WP_CONTENT_URL',WP_SITEURL.MY_.MY_DIR_CONTENT);
    define('WP_CONTENT_DIR',realpath(ABSPATH.MY_.MY_DIR_CONTENT)); 
    
    //CAMBAIR RUTA DE PLIGINS:
    define( 'WP_PLUGIN_URL',WP_SITEURL.MY_.MY_DIR_PLUGINS);
    define( 'WP_PLUGIN_DIR',realpath(ABSPATH.MY_DIR_PLUGINS));
    
    //CAMBIAR RUTA DE SUBIDA
    define('UPLOADS', ''.MY_DIR_CONTENT.MY_.MY_DIR_MEDIA);   
    
    /** Sets up WordPress vars and included files. */
    require_once(ABSPATH . 'wp-settings.php');
    

    And change values for this vars :

       define('MY_DIR','ui'); 
    define('MY_DIR_PLUGINS', 'plugins');
    define('MY_DIR_CONTENT', 'resource');
    define('MY_DIR_MEDIA', 'media');
    define('MY_PAGE_TYPE', 'http://');
    

Comments are closed.