$endpoint['name'], 'url' => $endpoint['url'], 'events' => $endpoint['events'], 'format' => $endpoint['format'], 'headers' => (object) $endpoint['headers'], 'conditions' => $endpoint['conditions'], 'options' => (object) $endpoint['options'], 'active' => $endpoint['active'], ); if ( $include_secrets ) { $item['secret'] = $endpoint['secret']; } $endpoints[] = $item; } return array( 'plugin' => 'hookbird', 'version' => HOOKBIRD_VERSION, 'exported_at' => gmdate( 'c' ), 'settings' => Settings::all(), 'endpoints' => $endpoints, ); } /** * Import data. * * @param array $data Decoded export. * @param bool $import_settings Also replace settings. * @return array|\WP_Error { created: int, errors: string[] } */ public static function import( array $data, $import_settings = true ) { if ( ! isset( $data['plugin'] ) || 'hookbird' !== $data['plugin'] || ! isset( $data['endpoints'] ) || ! is_array( $data['endpoints'] ) ) { return new \WP_Error( 'hookbird_bad_import', __( 'This file is not a Hookbird export.', 'hookbird' ) ); } if ( $import_settings && isset( $data['settings'] ) && is_array( $data['settings'] ) ) { update_option( Settings::OPTION, Settings::sanitize( $data['settings'] ), false ); } $created = 0; $errors = array(); foreach ( array_slice( $data['endpoints'], 0, 200 ) as $index => $item ) { if ( ! is_array( $item ) ) { continue; } $item['headers'] = isset( $item['headers'] ) ? (array) $item['headers'] : array(); $item['options'] = isset( $item['options'] ) ? (array) $item['options'] : array(); $secret = isset( $item['secret'] ) ? (string) $item['secret'] : ''; $result = Endpoints::create( $item, $secret ); if ( is_wp_error( $result ) ) { /* translators: 1: position in file, 2: error message. */ $errors[] = sprintf( __( 'Endpoint %1$d: %2$s', 'hookbird' ), $index + 1, $result->get_error_message() ); } else { ++$created; } } return array( 'created' => $created, 'errors' => $errors, ); } }