Use WP_Filesystem to list files in directory

Unfortunately the documentation about the Filesystem API is very basic. What you are looking for is the dirlist method/function of the WP_Filesystem_$method class(es). The only documentation about it is the docblock out of the WP_Filesystem_Base class: /** * Get details for files in a directory or a specific file. * * @since 2.5.0 * * … Read more

View content from uploaded file in editor

Okay.. I’m really losing it here. I’m just gonna extract it all so it might be more clear. In my functions.php: function jj_readcsv($filename, $header=false) { $handle = fopen($filename, “r”); echo ‘<table style=”width:100%;”>’; //display header row if true if ($header) { $csvcontents = fgetcsv($handle); echo ‘<tr>’; foreach ($csvcontents as $headercolumn) { echo “<th>$headercolumn</th>”; } echo ‘</tr>’; … Read more

Setting the uploads directory

You can use the ‘upload_dir’ filter add_filter(‘upload_dir’, ‘set_upload_folder’, 999); function set_upload_folder( $upload_data ) { // absolute dir path, must be writable by wordpress $upload_data[‘basedir’] = trailingslashit(ABSPATH). ‘/files’; $upload_data[‘baseurl’] = ‘http://subdomain.wptest.com/files’; $subdir = $upload_data[‘subdir’]; $upload_data[‘path’] = $upload_data[‘basedir’] . $subdir; $upload_data[‘url’] = $upload_data[‘baseurl’] . $subdir; return wp_parse_args($upload_data, $upload_data); } This code will works no matter if year/month … Read more

How to change the image size in new Media Uploader (ie use medium vs thumbnail)

Supposing that I’m interpreting your Question correctly… The thumbnails displayed in the new Media Uploader are already the medium sized ones, being constrained on the fly. So, it’s a matter of applying some CSS styling to increase their size. Maybe other style adjustments are necessary, this is just a proof of concept. add_action( ‘admin_head-post-new.php’, ‘style_thumbnails_wpse_81677’ … Read more

Issue on Running Image upload on WP Metabox Custom Image Loader

I had the same error because I forgot to add: wp_enqueue_media(); Then I found this how to and solved the problem like this: 1: You have to enqueue WP JavaScript library for media and your own JS file: public function enqueue_scripts() { //WP library wp_enqueue_media(); //Your JS file wp_register_script(‘name-of-your-script’, plugin_dir_url( __FILE__ ) . ‘js/path-to-your.js’, array( … Read more