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 custom hook for generated xml properties #177

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions msm-sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,23 +495,25 @@ public static function generate_sitemap_for_date( $sitemap_date ) {
// TODO: add images to sitemap via <image:image> tag
}

// Save the sitemap
$generated_xml_string = $xml->asXML();

// Save the sitemap
if ( $sitemap_exists ) {
// Get the previous post count
$previous_url_count = intval( get_post_meta( $sitemap_id, 'msm_indexed_url_count', true ) );

// Update the total post count with the difference
$total_url_count += $url_count - $previous_url_count;

update_post_meta( $sitemap_id, 'msm_sitemap_xml', $xml->asXML() );
update_post_meta( $sitemap_id, 'msm_sitemap_xml', $generated_xml_string );
update_post_meta( $sitemap_id, 'msm_indexed_url_count', $url_count );
do_action( 'msm_update_sitemap_post', $sitemap_id, $year, $month, $day );
do_action( 'msm_update_sitemap_post', $sitemap_id, $year, $month, $day, $generated_xml_string, $url_count );
} else {
/* Should no longer hit this */
$sitemap_id = wp_insert_post( $sitemap_data );
add_post_meta( $sitemap_id, 'msm_sitemap_xml', $xml->asXML() );
add_post_meta( $sitemap_id, 'msm_sitemap_xml', $generated_xml_string );
add_post_meta( $sitemap_id, 'msm_indexed_url_count', $url_count );
do_action( 'msm_insert_sitemap_post', $sitemap_id, $year, $month, $day );
do_action( 'msm_insert_sitemap_post', $sitemap_id, $year, $month, $day, $generated_xml_string, $url_count );

// Update the total url count
$total_url_count += $url_count;
Expand Down
Loading