'wp-export', 'parent' => 'top-secondary', 'title' => ''. __( 'Export', 'wp-exporter' ), 'href' => $this->export_url(), 'meta' => array( 'class' => 'wp-export', 'target' => '_blank', ) ); $wp_admin_bar->add_node( $args ); return $wp_admin_bar; } /** * Create admin bar export menu, before user profile menu * * @param $wp_admin_bar (object) WP_Admin_Bar * @since 0.0.5 */ public static function export_url() { global $post; $params = array( 'download' => 'true', 'content' => 'advanced', 'content' => 'advanced', 'query' => $post->post_type, 'post_ids[]' => $post->ID, ); return admin_url( "export.php?" ) . http_build_query($params); } /** * Custom styles for export admin bar menu * * @param $hook (string) current admin file name * @since 0.0.5 */ function admin_enqueue( $hook ) { if ( ! in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) return; echo ''; } /** * Export action using custom query * Modify post object while 'get_post' inside 'setup_postdata' * Put define('WP_EXPORTER_POST_STATUS', 'draft'); in wp-config.php or theme functions.php * * @param $post (array) The array of retrieved post. * @param $wp_query The current Query object (passed by reference). * @since 0.0.5 */ function the_post( $post, $wp_query ) { if ( isset( $wp_query->wp_exporter ) && $wp_query->wp_exporter && defined('WP_EXPORTER_POST_STATUS') && isset( $GLOBALS['post'] ) ) { $GLOBALS['post']->post_status = WP_EXPORTER_POST_STATUS; return $GLOBALS['post']; } } } new WP_Export_Utility(); /** * Debugging purpose * @params $arr array() * @since 0.0.5 */ function _wp_exporter_debugr( $arr ) { echo '
'. print_r( $arr, true ) . '
'; }