Skip to content

Instantly share code, notes, and snippets.

@patrickposner
Last active December 23, 2022 10:25
Show Gist options
  • Save patrickposner/d7b5a6e38da8035ec29d3a764de048bd to your computer and use it in GitHub Desktop.
Save patrickposner/d7b5a6e38da8035ec29d3a764de048bd to your computer and use it in GitHub Desktop.
Simply Static Pro: Single Export after save_post
<?php
add_action( 'save_post', 'ssp_auto_export', 10, 3 );
/**
* Automatically run a static export after post is saved.
*
* @param int $post_id given post id.
* @param object $post given post object.
* @param bool $update if it's updated or not.
* @return void
*/
function ssp_auto_export( $post_id, $post, $update ) {
$options = get_option( 'simply-static' );
$single = simply_static_pro\Single::get_instance();
$additional_urls = apply_filters( 'ssp_single_export_additional_urls', array_merge( $single->get_related_urls( $post_id ), $single->get_related_attachements( $post_id ) ) );
// Update option for using a single post.
update_option( 'simply-static-use-single', $post_id );
// Clear records before run the export.
Simply_Static\Page::query()->delete_all();
// Add URls for static export.
$single->add_url( $post_id );
$single->add_additional_urls( $additional_urls, $post_id );
do_action( 'ssp_before_run_single' );
// Start static export.
$ss = Simply_Static\Plugin::instance();
$ss->run_static_export();
}
@codehunter85
Copy link

Hello, I use same function in my site but when the function is hit on save_post its coping all things, but didn't copy post featured image can you please look out this,
I used Pro Version here is my function

add_action( 'save_post', 'ssp_auto_export', 10, 3 );

/**

  • Automatically run a static export after post is saved.

  • @param int $post_id given post id.

  • @param object $post given post object.

  • @param bool $update if it's updated or not.

  • @return void
    */
    function ssp_auto_export( $post_id, $post, $update ) {
    $options = get_option( 'simply-static' );
    $single = simply_static_pro\Single::get_instance();

    // $additional_urls = apply_filters( 'ssp_single_export_additional_urls', array_merge( $single->get_related_urls( $post_id ), $single->get_related_attachements( $post_id ) ) );
    $additional_urls = apply_filters( 'ssp_single_export_additional_urls', array_merge( $single->get_related_urls( $post_id ), $single->get_related_attachements( $post_id ) ) );

    // Update option for using a single post.
    update_option( 'simply-static-use-single', $post_id );
    // // Add URls for static export.
    $single->add_url( $post_id );
    $single->add_additional_urls( $additional_urls, $post_id );
    do_action( 'ssp_before_run_single' );

    // Start static export.
    $ss = Simply_Static\Plugin::instance();
    $ss->run_static_export();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment