Skip to content

Commit

Permalink
adding custom hook for generated xml properties (#177)
Browse files Browse the repository at this point in the history
* adding custom hook for generated xml properties

* removing custom hook and appending xml and url count to existing
  • Loading branch information
elysium001 authored Dec 1, 2023
1 parent 57c779c commit b23cf6a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions msm-sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,23 +519,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

0 comments on commit b23cf6a

Please sign in to comment.