professor99
Forum Replies Created
-
Ok I can definitely confirm it is a problem with 3.5.1 with the official Frontend version 1.1. Its due to a bug in the checkSubmit function in wpuf.js. I rewrote this in the development version some time back due to similar bugs and this seems to solve the problem. Simply update wpuf.js with the updated version of checkSubmit below
checkSubmit: function () { var form = $(this); //Save tinymce iframe to textarea if (typeof(tinyMCE) != "undefined") { tinyMCE.triggerSave(); } $('#wpuf-info-msg').html(' '); $('*',this).each(function() { if( $(this).hasClass('wpuf-invalid') ) { $(this).removeClass('wpuf-invalid'); } }); var hasError = false; $(this).find('.requiredField').each(function() { var el = $(this); if(jQuery.trim(el.val()) == '') { //Highlights closest visible container. //Still slight bug in tinyMCE editor when submitted when display tab is "HTML" //In this case the "Visible" tab won't be highlighted but this is very insignificant. el.closest(':visible').addClass('wpuf-invalid'); hasError = true; } else if(el.hasClass('email')) { var emailReg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if(!emailReg.test($.trim(el.val()))) { el.closest(':visible').addClass('wpuf-invalid'); hasError = true; } } else if(el.hasClass('cat')) { if( el.val() == '-1' ) { el.closest(':visible').addClass('wpuf-invalid'); hasError = true; } } }); if( ! hasError ) { $(this).find('input[type=submit]').attr({ 'value': wpuf.postingMsg, 'disabled': true }); return true; } $('#wpuf-info-msg').html('<div class="wpuf-error">Required field(s) empty.</div>'); $('#wpuf-info-msg').fadeTo(0,1); return false; },Hi Jonga,
Haven’t had this problem myself. I’m about to release the 4.3 version of the development release within a day once I’ve finished a few more tests. I will get you to try it just in case it solves your problems.
Hi jonga1306.
Forgot to mention that all the changes above were for the official FrontEnd version but will work for both (except for this one).
For Fix 1 for the development version change featured_image.php:attach_file_to_post() as follows
/** * Attach a featured image to a post * * @since 1.1-fork-2RRR-3.0 */ static function attach_file_to_post( $post_id ) { //get featured image attach id $attach_id = isset( $_POST['wpuf_featured_img'] ) ? intval( $_POST['wpuf_featured_img'] ) : 0; //set post thumbnail to featured image attach id if ( $attach_id ) { $attachment = get_post( $attach_id ); // If this attachment is unattached, attach it. if ( $attachment->post_parent == 0 ) wp_update_post( array( 'ID' => $attach_id, 'post_parent' => $post_id ) ); set_post_thumbnail( $post_id, $attach_id ); } }Fix2 is the same for both official and development versions
For those of you that find all these changes to much to bear I will be releasing a new development version in a day or two with all these changes
Ok some more fixes related to the above.
Fix 1
——Featured Images uploaded via Frontend are not linked to the post and are listed as unattached in the Media Library.
The following fix needs to be applied to wpuf-edit-post.php:submit_post().
Change
//set post thumbnail if has any if ( $attach_id ) { set_post_thumbnail( $post_id, $attach_id ); }to
//set post thumbnail to featured image attach id if ( $attach_id ) { $attachment = get_post( $attach_id ); // If this attachment is unattached, attach it. if ( $attachment->post_parent == 0 ) wp_update_post( array( 'ID' => $attach_id, 'post_parent' => $post_id ) ); set_post_thumbnail( $post_id, $attach_id ); }Fix2
—–Given the above fixes and normal use of the backend editor the attachment section will list thumbnails and attachments in the content of the posts.
The following fix limits that just to attachments that are not the featured image or in the content.
Note if the attachments are deleted from the content or removed as the thumbnail they may then appear in the attachment section as their parent still remains the original post.
Change wpuf-functions.php:wpfu_get_attachments to this.
/** * Get the attachments of a post * * @param int $post_id * @return array attachment list */ function wpfu_get_attachments( $post_id ) { $att_list = array(); $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post_id, 'order' => 'ASC', 'orderby' => 'menu_order' ); $post = get_post( $post_id ); $content = $post->post_content; $attachments = get_posts( $args ); foreach ($attachments as $attachment) { $id = $attachment->ID; $url = wp_get_attachment_url( $attachment->ID ); //exclude thumbnails if ( $id == get_post_thumbnail_id( $post_id ) ) continue; //exclude attachments in content if ( strpos( $content, $url ) !== false ) continue; $att_list[] = array( 'id' => $id, 'title' => $attachment->post_title, 'url' => $url, 'mime' => $attachment->post_mime_type ); } return $att_list; }Had a look on WordPress 3.5.1 with my development version which definitely doesn’t have this problem. My try again later with the official release as I need to test the upgrade from that to the new development release
Theres a frontend option to substitute WordPress’s edit link with a link to frontend’s edit page.
If you want to suppress the edit link on the Frontend pages see the code for suppress_edit_post_link (about to be renamed wpuf_suppress_edit_post_link) in my development version.
The issues you bring up with the Media Library are definitely worth exploring as I have had concerns along the same lines.
I actually consider the fact that it allows you to delete files that are actually in use to be a bug.
Hi gpspake,
Your wish list is a lot to wish for
I don’t want users to be able to see other peoples pictures in the library and I don’t want to let them delete images from posts that have been published (This would probably involve ‘the attachments to link to the new or edited post’.
That probably requires a Media Library replacement or some clever use of wp media’s actions and filters.
There are some Media Library type plugins that already exist that may do what you need. Worth a search.
Can confirm auto-drafts seems to be the best solution.
Modify my earlier code given above as follows
/** * Fix insert media bug * * @since version 1.1-fork-2RRR-4.3 */ function wpuf_insert_media_fix( $post_id ) { global $wpuf_post_id; global $post_ID; /* WordPress 3.4.2 fix */ $post_ID = $post_id; /* WordPress 3.5.1 fix */ $wpuf_post_id = $post_id; add_filter( 'media_view_settings', 'wpuf_insert_media_fix_filter', 10, 2 ); } /** * Fix insert media editor button filter * * Fixes bug with WordPress 3.5.1 * * @since version 1.1-fork-2RRR-4.3 */ function wpuf_insert_media_fix_filter( $settings, $post ) { global $wpuf_post_id; $settings['post']['id'] = $wpuf_post_id; $settings['post']['nonce'] = wp_create_nonce( 'update-post_' . $wpuf_post_id ); return $settings; }Insert it into wpuf-functions.php.
For wpuf-edit-post.php add the following the beginning of edit_form( $curpost ) as follows:
//Fix Insert Media Bug wpuf_insert_media_fix( $curpost->ID );For wpuf-add-post.php there are a number of things to do.
First add the following line to the beginning of the file.
require_once(ABSPATH . '/wp-admin/includes/post.php');Then change the beginning of function post_form( $post_type ) as follows:
function post_form( $post_type ) { global $userdata; $curpost = get_default_post_to_edit( $post_type, true ); //Fix Insert Media Bug wpuf_insert_media_fix( $curpost->ID );Later on in the same function add the following line after the line starting with ‘<input class=”wpuf_submit” type=”submit” name=”wpuf_new_post_submit”‘ ….
<input type="hidden" name="post_id" value="<?php echo $curpost->ID; ?>">Change the beginning of submit_post as follows
function submit_post() { global $userdata; $post_id = trim( $_POST['post_id'] );Finally in submit_post() add the following line to the $my_post array:
'ID' => $post_id,Presto!!!
Had a look for a solution to the unattached files in the Media Library bug mentioned above.
Looked firstly at filtering the content on post save. Images do include the attachment id but other attachments did not hence this is not a solution.
Looking now at the solution mentioned earlier using either the edited post’s id or for new posts using auto-drafts.
To Jonga1306
Don’t know if the above fix will solve your Featured Image problem. I recall there was another problem there I fixed with my development version. It should be mentioned somewhere in the forums
First the good news.
The following code works.
/** * Fix insert media editor button * * Fixes bug with WordPress 3.5.1 * * @since version 1.1-fork-2RRR-4.3 */ function wpuf_insert_media_fix() { add_filter( 'media_view_settings', 'wpuf_insert_media_fix_filter', 10, 2 ); } /** * Fix insert media editor button filter * * Fixes bug with WordPress 3.5.1 * * @since version 1.1-fork-2RRR-4.3 */ function wpuf_insert_media_fix_filter( $settings, $post ) { unset( $settings['post']['id'] ); unset( $settings['post']['nonce'] ); return $settings; }Insert it into wpuf-functions.php and call it at the beginning of wpuf-add-post:post_form() and wpuf-edit-post.php:edit_form() as follows
//Fix WordPress 3.5.1 Insert Media Bug wpuf_insert_media_fix();Now the not so bad news. I was mistaken about WordPress 3.4.2 updating the attachments to link to the new or edited post (post_parent in the database). The new fix doesn’t change this behavior on either WordPress 3.4.2 or 3.5.1. As a result the attachments will display in the Media Library as unattached which is a bit dangerous if somebody decides to remove the unattached files from the Media Library. Therefore we should fix this bug too.
So far my checking with the media_view_settings fix hasn’t reveal any problems.
After the post is uploaded the “insert post” button should update the editor. Attachments would have to be updated after the content is saved which is already the case.
One other solution I didn’t mention for edit posts was to update the post id to the id of the post being edited. For new posts we could create an auto-draft post and use this id. This also would allow a preview for new posts which I was already thinking about. Both these still require the use of the media_view_settings filter.
Anyway I’m about to see if my first solution works so wish me luck.
Hi gpspake,
Yes this is what I’m thinking with a few mods.
We do need to account for both WordPress 3.4.2 and 3.5.1 but this can be easily done by simply looking at the WordPress version.
The post_id needs to be omitted altogether due to wp-admin/includes/ajax-actions.php:wp_ajax_upload_attachment() which requires a valid post_id (0 isn’t valid) or none at all.
I think the (‘update-post_’ . $post->ID) nonce isn’t used so can be left out.
The ‘media-form’ nonce used in wp-admin/includes/ajax-actions.php:wp_ajax_upload_attachment() is set in wp-includes/media.php:wp_plupload_default_settings() which also sets ‘action’ => ‘upload-attachment’, and a lot of the other parameters
Yet to try it as making sure there are no other potential conflicts.