edtiley
Forum Replies Created
-
Forum: Plugins
In reply to: [External Media] Is this plugin Multisite compatible?Sorry for not replying sooner. I’m not getting email notices of replies.
Just plain old WordPress.
Say for example, if I had a Multisite fishing site that contained several blogs by various fishermen, charter captains, etc. I’d like for each one of them to be able to set their individual sites up so Google Drive could be used as their media library for pictures and videos instead of using server storage bandwidth.
Forum: Developing with WordPress
In reply to: wp_handle_upload() works, but image not in media libraryCatacaustic – bcworks
The section of the example below
if( ! is_null( $post ))
is what lead me astray. The resolution is a simple passing of the right info to the attachment functions. (as it usually is!) This is the code that works:require_once( ABSPATH . 'wp-admin/includes/image.php' ); require_once( ABSPATH . 'wp-admin/includes/file.php' ); $uploadedfile = $_FILES['file']; $upload_overrides = array( 'test_form' => false ); $movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); $wp_upload_dir = wp_upload_dir(); $attachment = array( "guid" => $movefile['file'], "post_mime_type" => $movefile['type'], "post_title" => $_POST['who'], "post_content" => "", "post_status" => "draft", "post_author" => 1 ); $id = wp_insert_attachment( $attachment, $movefile['file'],0); $attach_data = wp_generate_attachment_metadata( $id, $movefile['file'] ); wp_update_attachment_metadata( $id, $attach_data );
Thanks for steering me in the right direction!
Forum: Developing with WordPress
In reply to: wp_handle_upload() works, but image not in media librarycatacaustic – In your example, where does $post variable come from?
Forum: Developing with WordPress
In reply to: wp_handle_upload() works, but image not in media librarybcworkz –
No. there are no thumbnails or other image sizes generated. The file is sent from an android device via cordova file transfer. If I click on the icon in the media library, I get a link to view the attachment page, and when I clik on that link, the image displays just fine. I would assume that means it is just a plain old jpg file.
There has to be some parameter my code is not passing correctly.
The site is Multisite, but the file is showing up in the proper sites folder and everything.
Forum: Developing with WordPress
In reply to: wp_handle_upload() works, but image not in media libraryWell I had to do a little tweaking, and they show up in the media library, but only as icons. They are apparently not being processed to create thumbnails, etc. I’ve looked into the posts and post_meta tables and things look to be “normal,” but these days who can say what is normal?
Here’s my amended code”
function get_file() { if ( ! function_exists( 'wp_handle_upload' ) ) require_once( ABSPATH . 'wp-admin/includes/file.php' ); if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) require_once( ABSPATH . 'wp-admin/includes/image.php' ); $uploadedfile = $_FILES['file']; $upload_overrides = array( 'test_form' => false ); $movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); if( isset( $movefile["file"] )) { $file_name_and_location = $movefile["file"]; $file_title_for_media_library = $_POST['who']; $wp_upload_dir = wp_upload_dir(); $filetype = wp_check_filetype( $uploadedfile ); $attachment = array( "guid" => $movefile['file'], "post_mime_type" => $filetype['type'], "post_title" => addslashes( $file_title_for_media_library ), "post_content" => "", "post_status" => "inherit", "post_author" => 1 ); if( ! is_null( $post )) { if ( ! is_numeric( $post )) { $post = $post->ID; } // if () $attachment ['post_parent'] = $post; } // if () require_once( ABSPATH."wp-admin/includes/image.php" ); $id = wp_insert_attachment( $attachment, $file_name_and_location ); $attach_data = wp_generate_attachment_metadata( $id, $file_name_and_location ); wp_update_attachment_metadata( $id, $attach_data ); } }
BTW, when uploading from the Cordoba File Transfer plugin, the params show up in $_POST
Forum: Developing with WordPress
In reply to: wp_handle_upload() works, but image not in media libraryOh!!! Excellent, I’ve added the code to my file and will check it out in the AM. Thank you.
Now all I have to do is figure out how to capture the params (an array of key/value pairs embeded in $_FILES) from from the Cordova File Transfer plugin, and I’ll have this thing worked out.
When I get it, I’ll post the code here.
Thanks again.
Forum: Networking WordPress
In reply to: Domain Mapping and 301 RedirectsThe one word I didn’t see in the blurb for that plugin was MultiSite, but decided I was overthinking it.
I have no other sites at the moment upgrading to my network from straight html sites, so I just did the redirect without worrying if there were two boards.htm. There aren’t, and by the time there might be, the search engines will have already re-indexed the site.
Thanks, though! I’ll keep that one in mind.
Ed
Forum: Plugins
In reply to: [WooCommerce Advanced Free Shipping] How to charge shipping for other itemsJeroen,
On that point we must agree to disagree. And please understand I’m not criticizing your plugin or you. It seems all the avilable plugins have the same problem.
The WooCommerce cart seemingly can’t deal with charging shipping and having another item that ships free. I’ve seen articles and forum posts that suggest breaking transactions into two purchases, one with shipping charges, and one for the items that ship free. And that was one of the least convoluted recommendations!
You should be able to check a field in the product form just as easily as you do to put it on sale. After all, it really is just another form of a sale.
But you can’t, and I’d argue that’s a structural weakness of the cart.
Ed
Forum: Plugins
In reply to: [WooCommerce Advanced Free Shipping] How to charge shipping for other itemsIs this a weakness in the WooCommerce architecture? It just seems like this is way too hard.
Forum: Hacks
In reply to: Adding widgets to sidebar programmaticallysite and the integrity of the data needs to be protected to the extent possible.
There we must agree to disagree. If security is the issue, then the function should be declared as PRIVATE and you couldn’t get to it outside the Widget_Factory class.
Just telling programmers not to use something is an open invitation to get on it. Sort of like the current trend to use WP_List despite the documentation telling you not to.
Anyhow, thanks again for your encouragement. Onward to building Dashboard Widgets! YeeHaw!
Forum: Hacks
In reply to: Adding widgets to sidebar programmaticallyWhoa, whoa, whoa! It’s not off topic at all. I mentioned this a couple of days ago when you sent me the AJAX link. See my message that starts: “Yes, there are globals…”
I’m not talking about scopes of funtions inside or outside of classes. I’m talking about the codex says not to use wp_get_sidebars_widgets and wp_set_sidebar_widgets because they are “private” functions to be used by core. See: https://codex.www.ads-software.com/Function_Reference/wp_set_sidebars_widgets
In fact, these functions ARE in the WP_Widget_Factory class (/wp-includes/widgets.php) and both are technically PUBLIC functions since they aren’t declared PRIVATE in the source code. They are marked in commenting as /* Internal Functions */
The source code (around line 1392) is pretty simple and clear, doesn’t involve voodoo internals or anything like that.
I’d like an answer to why they are taboo as they potentially could have made by job a lot easier.
Forum: Hacks
In reply to: Adding widgets to sidebar programmaticallyWell, it was one and a half hurdles.
Remember a couple days ago and Ross Mitchell asked when I was hooking the action and I said after_setup_theme? Well at that point the globals aren’t populated yet.
It’s a good lesson in “Don’t hook an action too early either.”
The foreach was bellyaching because on a fresh theme change it is possible for malformed array data to be returned by
get_option($sidebars_widgets)
Sidebars_widgets is an array of arrays, and for some reason the orphaned_widgets array is sometimes left unterminated, but it can happen to inactive_widgets as well.So, I moved the action hook to wp_loaded. By that time the sidebars have all been rendered properly and the newly activated theme has populated sidebars_widgets with a properly formed array. Thus the foreach in my plugin always gets a “good” array and the error warnings are banished.
Bwaaa Ha Haa! As long as my plugin knows the sidebar_id of the target sidebar in network enabled themes, my widget is added to the sidebar on the second page served up after any theme change.
The only thing unresolved is that I’m really REALLY curious as to why wp_get_sidebars_widgets and wp_set_sidebar_widgets are marked in the codex as private core funtions that shouldn’t be used by developers.
That’s probably a new & different thread.
Forum: Hacks
In reply to: Adding widgets to sidebar programmaticallybcworkz,
I wrote a reply late last night, but I guess I was so tired I failed to hit the post button. The first part of the answer lay not in the AJAX module you cited, but in this article:
https://www.wpcustoms.net/snippets/programmatically-add-widgets-to-sidebars/
About the sixth or seventh readthrough I finally noticed that he was doing an update_option on the widget_example_name. A widget specified in sidebars_widgets, that hasn’t got matching instantiation in its own option gets ignored. So:
if ($has_widget == 'N'){ // match the widget name instance // number (my_neaux_widget-2) to // the array index of the // widget_ option (e.g. 2) array_unshift($widget_sets[$sb],'my_neaux_widget-2'); $widg['2' ] = array ('text' => 'Inserted Widget'); update_option( 'widget_my_neaux_widget', $widg ); update_option('sidebars_widgets', $widget_sets); }
Seemingly there is one last hurdle. (Isn’t there always?) In testing, I’m finding that changing themes somehow changes sidebars_widgets
such that I’m getting an error in the foreach expression on some transitions. Gotta track that down.I won’t mark this resolved till I figure it out.
Forum: Hacks
In reply to: Adding widgets to sidebar programmaticallyYes, there are globals, specifically:
global $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
$sidebars_widgets is empty at the time my code calls get_option for the settings.
I need to study that link you cite, but a quick look raises a can of Pandora’s Box style worms, in that it calls wp_set_sidebars_widgets.
Both wp_get_sidebars_widgets and wp_set_sidebar_widgets are maked in the codex as private core funtions that shouldn’t be used by developers.Looking at their source code shows they mostly format the array written to sidebars_widgets in wp_options. They don’t make any magical calls at that I noticed.
I’ve got to dig deeper I guess. I’m finding the retrieve_widgets funtion interesting, but it could be a dead end.
Sigh…
Forum: Hacks
In reply to: Adding widgets to sidebar programmaticallyI thought of that which is why I moved it back to after_setup_theme which is before init or get_sidebar.
I’m not so sure that’s it though, because I’ve gone so far as to reboot and come back to the site, and it still doesn’t show up.