Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality of Life / Modernization #72

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Ipstenu
Copy link

@Ipstenu Ipstenu commented Jul 20, 2023

This pull is basically bringing a LOT of the existing pulls up to modern speed, slapping it around with PHPCS and formatting, and adding in things I needed if I didn't want to hardcode in everything.

It runs live on lezwatchtv.com and is what powers our connections of characters to actors/shows.

Overview

  1. Bring (most of) the code to modern standards per PHPCS
  2. Improve inline documentation (spelling etc)
  3. Added new filters
  4. cmb2_attached_posts_objects filter (from add filter to give us more control over get_all_objects() #58 - props @njeffers )
  5. Change lightbox 'title' based on post-types (i.e. 'Search Custom Post Named Bob' vs 'Find Posts and Pages')
  6. Display errors instead of failing silently if no posts are found
  7. support for limiting the amount of posts that can be selected (based on Adding support for limiting the amount of posts that can be sele… #52 - props @d79 )
  8. Fix for deleted posts borking meta (from Fix an issue when a post is deleted but still present in the meta. #49 - props @jrmd )
  9. Allow multiple metaboxes on one page (from fixed bug where multiple metaboxes caused search modal to send posts … #41 - props @cggit )
  10. Change enqueue URLs to be flexible for weirdos who put the library inside a massive plugin/theme instead of as a separate plugin

New Filters

cmb2_attached_posts_title_filter - allows the display title of the post to be altered

example:

add_filter( 'cmb2_attached_posts_title_filter', 'YOURPREFIX_cmb_filter_title_attached_posts', 10, 2 );

function YOURPREFIX_cmb_filter_title_attached_posts( $post_title, $post_id ) {
	$additional = array();
	$status     = get_post_status( $post_id );
	$has_meta   = get_post_meta( $post_id, 'EXAMPLE_META', true );
	if ( ! empty( $has_meta ) && $has_meta ) {
		$additional[] = 'This is extra stuff I want to show at the end of the title';
	}
	if ( ! empty( $additional ) ) {
		$post_title .= ' (' . implode( ', ', $additional ) . ')';
	}

	return $post_title;
}

cmb2_attached_posts_status_filter - changes the post types allowed.

example:

add_filter( 'cmb2_attached_posts_status_filter', 'YOURPREFIX_cmb_filter_post_status_attached_posts', 10, 2 );

function YOURPREFIX_cmb_filter_post_status_attached_posts( $post_status ) {
	$post_status = array( 'publish', 'pending', 'draft', 'future', 'private', 'inherit' );
	return $post_status;
}

cmb2_attached_posts_per_page_filter - changes how many pages to search (important to me as we have a couple thousand ;)

example:

add_filter( 'cmb2_attached_posts_per_page_filter', 'YOURPREFIX_cmb_filter_post_statue_attached_posts', 10, 2 );

function YOURPREFIX_cmb_filter_post_statue_attached_posts( $post_status ) {
	$post_status = array( 'publish', 'pending', 'draft', 'future', 'private', 'inherit' );
	return $post_status;
}

@Ipstenu Ipstenu marked this pull request as ready for review July 20, 2023 20:20
@Ipstenu Ipstenu changed the title Draft: Quality of Life Quality of Life / Modernization Jul 20, 2023
@tw2113
Copy link

tw2113 commented Jul 20, 2023

Will do what I can to get some feedback and review your way ASAP. Appreciate all the help here and hopefully we can get things merged in pretty soon.

Thanks Mika.

@njeffers
Copy link

njeffers commented Jul 20, 2023

@Ipstenu First off, thank you for the mention, as well as all you do for the WP community.

I haven't gotten a chance to check anything here, so please excuse me if I'm wrong, but I think the args order on the cmb2_attached_posts_title_filter should have $post_id and $post_title reversed. As is, I think it'll show the $post_id if a callback function via add_filter() isn't in play.

@jtsternberg
Copy link
Member

I'm curious, have you had a chance to check out this WIP for bringing this lib into CMB2 Core? CMB2/CMB2#1056

@Ipstenu
Copy link
Author

Ipstenu commented Jul 21, 2023

@jtsternberg Yes, but seeing as it was untouched for 5+ years, I assumed it was an abandoned idea.

@njeffers Since I use it for all posts (to flag the status) I didn't notice :D Flipped it. Weirdly that way makes my check run multiple times, but I fixed my own code.

@tw2113
Copy link

tw2113 commented Sep 29, 2023

Discussing internally about merging this one in for the time being. I've looked over everything and all looks good to me. Not managing to find any compatibility issues, but I am probably not using as extensively as you are, to create logged items.

@Ipstenu
Copy link
Author

Ipstenu commented Sep 29, 2023

TBH, I was recently wrestling with some issues on the search and that led to what is a WAY more significant divergence.

  1. Removed all the stuff about users (it doesn't work, I never use it)
  2. Changed the query to order by relevance unless the title is under 4 characters, then use exact by title

I may be the only use case where post titles can be 2-characters though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants