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

Adding hook for custom post status with tests #176

Merged

Conversation

elysium001
Copy link
Contributor

Pull Request: Add msm_sitemap_post_status WordPress Hook

Description: This pull request introduces a new WordPress hook, msm_sitemap_post_status, to facilitate customization of post statuses for inclusion in the sitemap. This feature was specifically requested by a customer to enhance the flexibility of handling custom post statuses in the sitemap functionality.

Changes Introduced:

  • Added msm_sitemap_post_status hook in msm-sitemap.php.
  • Documented usage of the new hook in the codebase and readme
  • Added unit tests to make sure other query and helper functions still work accordingly.

Background: A customer expressed the need for a way to use a post status other than 'published' to build the sitemap, prompting the development of this feature. The introduction of the msm_sitemap_post_status hook allows developers to extend the sitemap functionality easily and integrate their custom post statuses.

Related Issues:

  • internal customer discussion and P2

Reviewers: TBD

msm-sitemap.php Outdated Show resolved Hide resolved
msm-sitemap.php Outdated
*
* @return string
*/
public static function get_post_status() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static function get_post_status() {
public static function get_post_status(): string {

I'd suggest adding a type declaration on this, so that any effort to return a non-string is caught earlier before trying to pass it to the SQL query.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this method need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while it's not required, it does make it much easier to test such as the get_post_stati values mechanism.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't mould the API for a class just to make testing either. Non-public methods can be tested via Reflection if necessary.

msm-sitemap.php Outdated Show resolved Hide resolved
tests/test-sitemap-functions.php Outdated Show resolved Hide resolved
tests/test-sitemap-functions.php Outdated Show resolved Hide resolved
tests/test-sitemap-functions.php Outdated Show resolved Hide resolved
tests/test-sitemap-functions.php Outdated Show resolved Hide resolved
tests/test-sitemap-functions.php Outdated Show resolved Hide resolved
tests/test-sitemap-functions.php Outdated Show resolved Hide resolved
@elysium001 elysium001 merged commit 57c779c into main Dec 1, 2023
2 of 40 checks passed
@elysium001 elysium001 deleted the add/proposal-hook-generate-xml-for-nonpublish-post-status branch December 1, 2023 17:37
@GaryJones GaryJones added this to the 1.5.0 milestone Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants