Scott Bressler
Forum Replies Created
-
Forum: Plugins
In reply to: Check user role is something or aboveThanks for your help and advice, Andrew. I decided to go with creating my own capability. I’ve now added this to the settings page for the plugin, but the logic for adding or removing the capability from the roles based on the checkboxes obviously isn’t handled by the Settings API and my settings group. How and where should that be handled?
Here is the code I have for displaying the checkboxes:
<p> <strong>Roles that can view calendar</strong><br /> <?php foreach($wp_roles->get_names() as $role => $role_name) : if ( $wp_roles->is_role( $role ) ) : $target_role =& get_role( $role ); $role_has_cap = $target_role->has_cap( 'view_calendar' ); ?> <label for="calendar_view_<?php echo $role; ?>"> <input type="checkbox" id="calendar_view_<?php echo $role; ?>" value="<?php echo $role; ?>" <?php echo ($role_has_cap ? 'checked="yes"' : '');?> style="margin-bottom: 5px;" /> <?php _e($role_name, 'edit-flow') ?> </label> <br /> <?php endif; ?> <?php endforeach; ?> <span class="description"><?php _e('Select above which roles may view the Edit Flow Calendar.', 'edit-flow') ?></span> </p>
All this code is in the callback for add_submenu_page which echos all the settings.
Thanks in advance!
-Scott
Forum: Plugins
In reply to: Effective way to give media credit?My Media Credit plugin should make this easy. I made it for exactly the same reason you guys want it – we moved from CP to WP and needed to display credit in a nice way.
Let me know if this works out for you or if you need help using it.
-Scott
Forum: Plugins
In reply to: [Plugin: Column Inches] What…Hey f1mkstol,
There are is no new column on the far right when you click Edit under Posts nor a column inch count next to the word count below the post text when editing a post, as in the screenshots?
Also, what appears when you go to the Column Inches settings? Are there any errors there?
Thanks,
ScottForum: Themes and Templates
In reply to: Get current page number for paginated postsThanks for the quick response! Nice catch – didn’t notice those variables.
Forum: Plugins
In reply to: Working With Columns On Pages/PostsWow, might have just asked the same question. Are you looking for something for post display on the front-end or an admin modification (I’m looking for an admin hack)?
I think this can be marked as resolved now.
Forum: Fixing WordPress
In reply to: Change author in RSSPosted fix I found here: https://www.ads-software.com/support/topic/382593?replies=2#post-1465901
Forum: Plugins
In reply to: Change author that appears in RSSFound this, which is pretty much exactly what I needed.
For anyone that might find this, my code ended up being:
/** * Filters the_author. * If Other Author is the author of a post, changes the author to whatever is in the 'Other Author' custom field for the post, if one exists. * Code taken mainly from https://www.wpbeginner.com/wp-tutorials/how-to-rewrite-guest-author-name-with-custom-fields-in-wordpress/ */ function fix_other_author( $name ) { global $post; if ( $name == "Other Author") { $author = get_metadata( 'post', $post->ID, 'Other Author', true ); if ( $author != '' ) $name = $author; } return $name; } add_filter( 'the_author', 'fix_other_author' ); add_filter( 'get_the_author_display_name', 'fix_other_author' );
Forum: Fixing WordPress
In reply to: Error displayed during automatic plugin upgradeThanks, esmi. As I said in my original message, however, I had tried doing what other people suggested, as on that page, with this error, albeit to no avail.
Just to check, I downloaded a fresh copy of WP MU and diff’ed admin-header.php with the currently installed copy and there were no changes. Line 17, as you can see here, is where HTML output starts from that page (intentionally!) – this is not a simple PHP-end-closing-mark missing. Or if it is, it’s not from admin-header.php. Any other thoughts?
Forum: Fixing WordPress
In reply to: Custom author queryIs there a way to create a WP_Query from SQL code rather than using an args array?
Forum: Plugins
In reply to: Major overhaul coming to Co-Authors PlusHey batmoo, just curious about your re-architecture in v2.0: how do you take advantage of taxonomies in and display all the authors on the edit.php page since there is no filter in core for that page.
Forum: Fixing WordPress
In reply to: Custom author queryUnfortunately, it’s not exactly the most optimal query, as you suspected. The much more verbose code that follows is slightly better because it’s more specific about which rows in postmeta to look at. In my veryyyy informal speed tests, the following runs about 30% faster:
/** * Joins fields from an array of objects, returning a string with the fields separated by the given separator. */ function joinKeys($toJoin, $key, $separator) { for ($i = 0; $i < count($toJoin); ++$i) $ids .= $toJoin[$i]->$key . ($i < count($toJoin) - 1 ? $separator : ''); return $ids; } // media inline with posts $all_attachments = $wpdb->get_results( $wpdb->prepare( " SELECT ID FROM $wpdb->posts WHERE post_author = %d AND (post_type = 'attachment' OR (post_type = 'post' AND post_parent = '0' AND post_status = 'publish') ) ORDER BY post_date DESC", $curauth->ID )); $all_ids = joinKeys($all_attachments, 'ID', ','); $freeform = $wpdb->get_results( " SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'media-credit' AND post_id IN ($all_ids)" ); $freeform_ids = joinKeys($freeform, 'post_id', ','); $attachments = $wpdb->get_results( " SELECT * FROM $wpdb->posts WHERE ID IN ($all_ids) AND ID NOT IN ($freeform_ids) ORDER BY post_date DESC" );
I then use this to display it:
<?php if ($attachments) : ?> <div id="posts-and-media"> <h3>Posts and images by <?php echo $curauth->display_name; ?></h3> <ul> <?php foreach ($attachments as $post) : ?> <li> <?php setup_postdata($post); if ( $post->post_type == 'attachment' ) echo wp_get_attachment_link($post->ID, 'thumbnail'); else echo the_title(); ?> </li> <?php endforeach; ?> </ul> </div> <?php endif; ?>
A) Any suggested optimizations to the above?
B) Is there a way to take advantage of the Loop instead of my custom looping? I’m not that familiar with how the Loop is made, or thus how to make one myself…Forum: Fixing WordPress
In reply to: Custom author queryWow, thank you – that’s almost exactly it. Whew, this is a doozy! Here’s your query above touched up a bit and simplified to work seemingly perfectly for my purposes:
$attachments = $wpdb->get_results( $wpdb->prepare( " SELECT * FROM $wpdb->posts WHERE post_author = %d AND ID NOT IN ( SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = 'media-credit') AND post_type = 'attachment' OR (post_type = 'post' AND post_parent = '0' AND post_status = 'publish') GROUP BY ID ORDER BY post_date DESC" , $curauth->ID ));
Forum: Fixing WordPress
In reply to: Custom author queryPerhaps I’m missing something, and I’ve never really done pagination before (at the query level, at least), but how would that work/not work with regards to pagination? I tried digging through core earlier to understand how it really does pagination, but I quickly got lost in wp-db.php…
Also, the downside to that approach is that I’ll be hitting the
database constantly, right?I’m going to try my multi-step approach above, though that might very well fail with pagination as well. Will report back here when I’ve got something.
Forum: Fixing WordPress
In reply to: Custom author queryThanks for your help, Michael. Unfortunately that doesn’t quite work I don’t think, because I’m looking for all posts by say, user 1, but not the posts that even have a meta_key of ‘cf1’. So if there are three posts by user 1, one of which has a meta_key of ‘cf1’ (regardless of meta_value), then only two posts should be returned.
Perhaps there is a good way to do this in one post, but I’m thinking that I might need to get all the posts by user 1, then join the result separating IDs with commas, then get all the posts that have a meta_key of ‘cf1’ in the ID list that I just created. Then do an array_diff of IDs for the ones without the ‘cf1’ meta_key.
Easier way?