$target ) { SPE_Queue::add( $path, $target['url'], $target['kind'] ); } } public static function on_delete( $post_id, $post = null ) { $post = $post ? $post : get_post( $post_id ); if ( ! $post || ! self::should_export( $post ) || 'publish' !== $post->post_status ) { return; } $path = SPE_Mapper::path_for_post( $post ); if ( '' !== $path ) { self::unpublish( $path ); } foreach ( SPE_Mapper::affected_by_post( $post ) as $affected => $target ) { if ( $affected !== $path ) { SPE_Queue::add( $affected, $target['url'], $target['kind'] ); } } } /** Renaming a category changes its archive URL and every page linking to it. */ public static function on_term_edited( $term_id, $tt_id, $taxonomy ) { if ( ! SP_Settings::auto_publish() ) { return; } $tax = get_taxonomy( $taxonomy ); if ( ! $tax || ! $tax->public ) { return; } $link = get_term_link( (int) $term_id, $taxonomy ); if ( is_wp_error( $link ) ) { return; } $path = SPE_Mapper::path_for_url_path( (string) wp_parse_url( $link, PHP_URL_PATH ) ); if ( '' !== $path ) { SPE_Queue::add( $path, $link, 'archive' ); } } private static function should_export( $post ) { if ( ! SP_Settings::auto_publish() || ! SP_Settings::is_configured() ) { return false; } if ( ! $post instanceof WP_Post ) { return false; } if ( wp_is_post_revision( $post ) || wp_is_post_autosave( $post ) ) { return false; } $type = get_post_type_object( $post->post_type ); if ( ! $type || ! $type->public ) { return false; } // A password-protected post renders as a password form to the // exporter, and publishing that form to permanent public storage // would be worse than not publishing at all. if ( '' !== $post->post_password ) { return false; } /** * Filters whether a post is exported at all. * * @param bool $export * @param WP_Post $post */ return (bool) apply_filters( 'sirius_press_should_export_post', true, $post ); } /** * Remove a path from the bucket. * * In manual mode there is no key to sign a delete with, so the operator is * told rather than left with a stale page they think is gone. */ private static function unpublish( $path ) { if ( SP_Settings::MODE_SERVER !== SP_Settings::mode() ) { SP_Inbox::add( 0, __( 'A removed page is still published to your name', 'sirius-press' ), sprintf( /* translators: 1: bucket path, 2: export screen URL. */ wp_kses_post( __( '%1$s is no longer public on this site, but this server holds no key to delete it from the name\'s storage. Remove it from the export screen.', 'sirius-press' ) ), esc_html( $path ), esc_url( admin_url( 'admin.php?page=sirius-press-export' ) ) ), 'export' ); return; } $result = SP_Gateway::delete( $path ); if ( empty( $result['ok'] ) ) { SP_Inbox::add( 0, __( 'A removed page could not be unpublished', 'sirius-press' ), sprintf( /* translators: 1: bucket path, 2: error message. */ wp_kses_post( __( '%1$s could not be deleted from the name\'s storage: %2$s', 'sirius-press' ) ), esc_html( $path ), esc_html( $result['error'] ) ), 'export' ); } } }