Git Product home page Git Product logo

betterexport's Introduction

betterexport

This adds import/export functionality to WordPress, implemented the way we think it should be implemented.

Still under heavy development. Not production ready.

Some general principles

  • Plugins and themes can add their own options/data into the export files, registering export and import functions.
  • The export is in JSON format.
  • We are sorting the keys and pretty printing the JSON, to get as readable diffs as possible between exports. (To make it easier to see what has happened on your site.)
  • Support for WP-Cli.

How to add your own data to export files

Adding your own data to export files is simple and follow normal WordPress patterns.

Example:

function my_theme_options_export() {
	$data = array( 'background_color' => get_option( 'my_background' ) );
	return $data;
}

function my_theme_options_import($data) {
	update_option( 'my_background', $data[ 'background_color' ] );
}

if (function_exists( 'add_export_import' )) { // Only if plugin is active...
	add_export_import( 'my_theme_stuff', 'my_theme_options_export', 'my_theme_options_import' );
}

WP-Cli Commands

Exporting

To save the export JSON in a timestamped file:

wp betterexport export

To save the export JSON in a timestamped file (and overwrite if it already exists):

wp betterexport export --overwrite

To output the export JSON to stdout:

wp betterexport export --stdout

Importing

Pipe JSON into WP-Cli this way:

cat exportfile.json | wp betterexport import --stdin

HTTP/AJAX Exports

To make it easier to export from remote, i.e. automatic exports from your production environment, you can make exports with just a simple HTTP request. However, to enable this, you will have to add a BETTEREXPORT_HTTP_SECRET constant, and pass the same value in your request.

How to add BETTEREXPORT_HTTP_SECRET to your wp-config.php (before the "That's all, stop editing! Happy blogging." string):

define ( 'BETTEREXPORT_HTTP_SECRET', 'th15isAs3cr3t' );

Example, using command line HTTP client cURL, outputing an export JSON:

curl 'http://example.org/wp-admin/admin-ajax.php?action=export&secret=th15isAs3cr3t'

Generic filters

  • betterexport_export_filename - Filter for the export filename.

Users import/export

Filters (users)

  • betterexports_users_logins_to_export - An array of user logins to export into export file. Use this filter to restrict which users to be exported.
  • betterexports_users_logins_to_import - An array of user logins to import from an export file. Use this filter to restrict which users to be imported.

betterexport's People

Watchers

 avatar James Cloos avatar Alexander Berthelsen avatar Jesper Nilsson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.