diff --git a/class-export-one-post.php b/class-export-one-post.php
index 5d2be07..4f56eda 100644
--- a/class-export-one-post.php
+++ b/class-export-one-post.php
@@ -28,6 +28,8 @@ function init() {
add_action( 'post_submitbox_misc_actions', array( $this, 'post_submitbox_misc_actions' ) );
add_filter( 'export_args', array( $this, 'export_args' ) );
add_filter( 'query', array( $this, 'query' ) );
+ add_filter( 'post_row_actions', array( $this, 'post_row_export_link'), 10, 2);
+ add_filter( 'page_row_actions', array( $this, 'post_row_export_link'), 10, 2);
}
}
/**
@@ -50,16 +52,43 @@ function post_submitbox_misc_actions() {
}
- '',
- 'export_single' => get_the_ID(),
- ), admin_url( 'export.php' ) );
- ?>
-
+
+
+
get_export_url($post->ID) . '">' . esc_html__( 'Export XML', 'export-one-post' ) . '';
+ }
+
+ return $actions;
+ }
+
+ /**
+ * Generate export url
+ *
+ */
+ function get_export_url( $post_id = null ) {
+
+ if ( $post_id === null ) {
+ $post_id = get_the_ID();
+ }
+
+ $export_url = add_query_arg( array(
+ 'download' => '',
+ 'export_single' => $post_id,
+ '_wpnonce' => wp_create_nonce( 'export_single' ),
+ ), admin_url( 'export.php' ) );
+
+ return $export_url;
+ }
+
/**
* Modify export arguments
* except if normal export
@@ -69,14 +98,14 @@ function post_submitbox_misc_actions() {
*/
function export_args( $args ) {
// if no export_single var, it's a normal export - don't interfere
- if ( ! isset( $_GET['export_single'] ) ) {
- return $args;
- }
+ if ( isset( $_GET['export_single'] ) ) {
+ check_admin_referer('export_single');
- // use our fake date so the query is easy to find (because we don't have a good hook to use)
- $args['content'] = 'post';
- $args['start_date'] = $this->fake_date;
- $args['end_date'] = $this->fake_date;
+ // use our fake date so the query is easy to find (because we don't have a good hook to use)
+ $args['content'] = 'post';
+ $args['start_date'] = $this->fake_date;
+ $args['end_date'] = $this->fake_date;
+ }
return $args;
}
@@ -89,32 +118,32 @@ function export_args( $args ) {
* @return string Modified SQL query
*/
function query( $query ) {
- if ( ! isset( $_GET['export_single'] ) ) {
- return $query;
- }
+ if (isset($_GET['export_single'])) {
+ check_admin_referer('export_single');
- global $wpdb;
+ global $wpdb;
- // This is the query WP will build (given our arg filtering above)
- // Since the current_filter isn't narrow, we'll check each query
- // to see if it matches, then if it is we replace it
- // @see https://github.com/wordpress/wordpress/blob/5.4.1/wp-admin/includes/export.php#L144
- $test = $wpdb->prepare(
- "SELECT ID FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_type = 'post' AND {$wpdb->posts}.post_status != 'auto-draft' AND {$wpdb->posts}.post_date >= %s AND {$wpdb->posts}.post_date < %s",
- date( 'Y-m-d', strtotime( $this->fake_date ) ),
- date( 'Y-m-d', strtotime( '+1 month', strtotime( $this->fake_date ) ) )
- );
+ // This is the query WP will build (given our arg filtering above)
+ // Since the current_filter isn't narrow, we'll check each query
+ // to see if it matches, then if it is we replace it
+ // @see https://github.com/wordpress/wordpress/blob/5.4.1/wp-admin/includes/export.php#L144
+ $test = $wpdb->prepare(
+ "SELECT ID FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_type = 'post' AND {$wpdb->posts}.post_status != 'auto-draft' AND {$wpdb->posts}.post_date >= %s AND {$wpdb->posts}.post_date < %s",
+ date('Y-m-d', strtotime($this->fake_date)),
+ date('Y-m-d', strtotime('+1 month', strtotime($this->fake_date)))
+ );
- if ( $test !== $query ) {
- return $query;
- }
+ if ($test !== $query) {
+ return $query;
+ }
- // divide query
- $split = explode( 'WHERE', $query );
- // replace WHERE clause
- $split[1] = $wpdb->prepare( " {$wpdb->posts}.ID = %d", intval( $_GET['export_single'] ) );
- // put query back together
- $query = implode( 'WHERE', $split );
+ // divide query
+ $split = explode('WHERE', $query);
+ // replace WHERE clause
+ $split[1] = $wpdb->prepare(" {$wpdb->posts}.ID = %d", intval($_GET['export_single']));
+ // put query back together
+ $query = implode('WHERE', $split);
+ }
return $query;
}
diff --git a/export-one-post.php b/export-one-post.php
index faa8e34..19161ed 100644
--- a/export-one-post.php
+++ b/export-one-post.php
@@ -1,11 +1,11 @@