From a080b272b6f335c1433e62fc39ecf63901d05ab1 Mon Sep 17 00:00:00 2001 From: Ben Leivian Date: Wed, 27 May 2020 13:51:11 -0700 Subject: [PATCH 1/5] Add description. --- export-one-post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/export-one-post.php b/export-one-post.php index faa8e34..4b61882 100644 --- a/export-one-post.php +++ b/export-one-post.php @@ -2,7 +2,7 @@ /* * Plugin Name: Export One Post * Plugin URI: https://github.com/trepmal/export-one-post - * Description: + * Description: Export single posts and pages from the edit screen. * Version: 1.0 * Author: Kailey Lampert * Author URI: kaileylampert.com From 2bbfdf2c9488e044e37090cc6b6ad674e7834b24 Mon Sep 17 00:00:00 2001 From: Ben Leivian Date: Wed, 27 May 2020 14:14:27 -0700 Subject: [PATCH 2/5] Update plugin info. --- export-one-post.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/export-one-post.php b/export-one-post.php index 4b61882..19161ed 100644 --- a/export-one-post.php +++ b/export-one-post.php @@ -1,11 +1,11 @@ Date: Wed, 27 May 2020 14:14:30 -0700 Subject: [PATCH 3/5] Update readme.md --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 0ca68c1..f351db4 100644 --- a/readme.md +++ b/readme.md @@ -1,10 +1,11 @@ +Fork of: https://github.com/trepmal/export-one-post + # Export One Post Works on pages and custom post types! ![screenshot](screenshot.png) - Confirmed working on WordPress 5.4.1, single and multisite. Gutenberg not (yet...?) supported. ## WP-CLI From 450207964d2b420945444474fd524e8afb63919f Mon Sep 17 00:00:00 2001 From: Ben Leivian Date: Wed, 27 May 2020 14:14:44 -0700 Subject: [PATCH 4/5] Add wpnonce. --- class-export-one-post.php | 63 ++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/class-export-one-post.php b/class-export-one-post.php index 5d2be07..75226c3 100644 --- a/class-export-one-post.php +++ b/class-export-one-post.php @@ -54,9 +54,12 @@ function post_submitbox_misc_actions() { $export_url = add_query_arg( array( 'download' => '', 'export_single' => get_the_ID(), + '_wpnonce' => wp_create_nonce( 'export_single' ), ), admin_url( 'export.php' ) ); ?> - + + + 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 +92,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; } From c027f66104f9d4f4101282b7f32596356c05b349 Mon Sep 17 00:00:00 2001 From: Ben Leivian Date: Wed, 27 May 2020 14:42:24 -0700 Subject: [PATCH 5/5] Add export link to post/page rows. --- class-export-one-post.php | 42 +++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/class-export-one-post.php b/class-export-one-post.php index 75226c3..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,19 +52,43 @@ function post_submitbox_misc_actions() { }
- '', - 'export_single' => get_the_ID(), - '_wpnonce' => wp_create_nonce( 'export_single' ), - ), 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