Adding compatibility with WPUF
-
Hi,
right now there’s a problem when using WordPress User Frontend plugin, which is that they create the post on the front-end, so the global $post_id doesn’t belong to the post being created, but to their page from which to create the post (where shortcode [wpuf_addpost] goes)
So then I fixed this issue: if creating a post in the frontend, the $post_id is different
Maybe if this solution is not justified, it would be nice to add a filter in that place, so we can add a hook without having to hack the code
Can this be added to the main code? Thanks!
file: template-tags.php
function get_coauthors( $post_id = 0 ) { global $post, $post_ID, $coauthors_plus, $wpdb; $coauthors = array(); $post_id = (int)$post_id; if ( !$post_id && $post_ID ) $post_id = $post_ID; if ( !$post_id && $post ) $post_id = $post->ID; if ( $post_id ) { $coauthor_terms = get_the_terms( $post_id, $coauthors_plus->coauthor_taxonomy ); if ( is_array( $coauthor_terms ) && !empty( $coauthor_terms ) ) { foreach( $coauthor_terms as $coauthor ) { $coauthor_slug = preg_replace( '#^cap\-#', '', $coauthor->slug ); $post_author = $coauthors_plus->get_coauthor_by( 'user_nicename', $coauthor_slug ); // In case the user has been deleted while plugin was deactivated if ( !empty( $post_author ) ) $coauthors[] = $post_author; } } else if ( !$coauthors_plus->force_guest_authors ) { // Hack: for old posts, the plugin didn't save the Author in the terms, so it's missing // This creates a bug: for WPUF frontend, global $post is the page to edit the post, and not the post, so it takes that one // Ask before if there's a $post_id, since this one is the right one for the post if ( !is_admin()) { $post_from_post_id = get_post($post_id); $post_author = get_userdata( $post_from_post_id->post_author ); } elseif ( $post ) { $post_author = get_userdata( $post->post_author ); } else { $post_author = get_userdata( $wpdb->get_var( $wpdb->prepare("SELECT post_author FROM $wpdb->posts WHERE ID = %d", $post_id ) ) ); } if ( !empty( $post_author ) ) $coauthors[] = $post_author; } // the empty else case is because if we force guest authors, we don't ever care what value wp_posts.post_author has. } return $coauthors; }
- The topic ‘Adding compatibility with WPUF’ is closed to new replies.