| @@ -21,103 +21,23 @@ | ||
| 21 | 21 | /** |
| 22 | 22 | * @param int $library_id |
| 23 | 23 | * @return array |
| 24 | 24 | */ |
| 25 | - public function export_to_cloud( $library_id, $subtype, $options ) { | |
| 25 | + public function export_to_cloud( $library_id ) { | |
| 26 | 26 | $client = new CloudClient; |
| 27 | + $data = $this->export_settings(); | |
| 28 | + $theme = wp_get_theme(); | |
| 27 | 29 | |
| 28 | - if ( $subtype === 'theme_settings' ) { | |
| 29 | - $theme = wp_get_theme(); | |
| 30 | - $data = $this->export_theme_settings(); | |
| 31 | - $name = sprintf( _x( '%s Settings', '%s theme name', 'assistant' ), $theme->Name ); | |
| 32 | - } elseif ( $subtype === 'bb_settings' ) { | |
| 33 | - if ( ! class_exists( '\FLBuilderModel') ) { | |
| 34 | - return rest_ensure_response( [ 'error' => __( 'Unable to load BeaverBuilder settings exporter.' ) ] ); | |
| 35 | - } | |
| 36 | - | |
| 37 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 38 | - return rest_ensure_response( [ 'error' => __( 'You do not have permission to export BeaverBuilder settings.' ) ] ); | |
| 39 | - } | |
| 40 | - | |
| 41 | - $possible_options = [ | |
| 42 | - 'admin_settings', | |
| 43 | - 'global_settings', | |
| 44 | - 'global_styles', | |
| 45 | - 'global_colors', | |
| 46 | - ]; | |
| 47 | - $settings = []; | |
| 48 | - $settings['builder_global_settings'] = \FLBuilderModel::get_global_settings(); | |
| 49 | - $settings['admin_settings'] = []; | |
| 50 | - $all_settings = true; | |
| 51 | - $selected_settings = []; | |
| 52 | - | |
| 53 | - foreach ( \FLBuilderAdminSettings::registered_settings() as $setting ) { | |
| 54 | - $settings['admin_settings'][ $setting ] = get_option( $setting ); | |
| 55 | - } | |
| 56 | - | |
| 57 | - if ( class_exists( 'FLBuilderGlobalStyles' ) ) { | |
| 58 | - $globals = \FLBuilderGlobalStyles::get_settings( false ); | |
| 59 | - $settings['global_colors'] = $globals->colors; | |
| 60 | - unset( $globals->colors ); | |
| 61 | - $settings['global_styles'] = $globals; | |
| 62 | - } | |
| 63 | - | |
| 64 | - foreach ( $possible_options as $option ) { | |
| 65 | - if ( ! in_array( $option, $options ) ) { | |
| 66 | - $all_settings = false; | |
| 67 | - } | |
| 68 | - } | |
| 69 | - | |
| 70 | - if ( in_array( 'admin_settings', $options ) ) { | |
| 71 | - $selected_settings[] = 'Admin'; | |
| 72 | - } else { | |
| 73 | - unset( $settings['admin_settings'] ); | |
| 74 | - } | |
| 75 | - | |
| 76 | - if ( in_array( 'global_settings', $options ) ) { | |
| 77 | - $selected_settings[] = 'Global Settings'; | |
| 78 | - } else { | |
| 79 | - unset( $settings['builder_global_settings'] ); | |
| 80 | - } | |
| 81 | - | |
| 82 | - if ( in_array( 'global_styles', $options ) ) { | |
| 83 | - $selected_settings[] = 'Styles'; | |
| 84 | - } else { | |
| 85 | - unset( $settings['global_styles'] ); | |
| 86 | - } | |
| 87 | - | |
| 88 | - if ( in_array( 'global_colors', $options ) ) { | |
| 89 | - $selected_settings[] = 'Colors'; | |
| 90 | - } else { | |
| 91 | - unset( $settings['global_colors'] ); | |
| 92 | - } | |
| 93 | - | |
| 94 | - if ( isset( $settings['global_colors'] ) && isset ( $globals->prefix ) ) { | |
| 95 | - $settings['global_colors_prefix'] = $globals->prefix; | |
| 96 | - } | |
| 97 | - | |
| 98 | - if ( $all_settings ) { | |
| 99 | - $name = 'All Settings'; | |
| 100 | - } else { | |
| 101 | - $name = implode( ', ', $selected_settings ); | |
| 102 | - } | |
| 103 | - | |
| 104 | - $data = json_encode( $settings ); | |
| 105 | - } | |
| 106 | - | |
| 107 | - $screenshot = isset( $_POST['screenshot'] ) ? ScreenShotHelper::get_for_post_request( home_url(), false ) : null; | |
| 108 | - | |
| 109 | 30 | return $client->libraries->create_item( |
| 110 | 31 | $library_id, |
| 111 | 32 | [ |
| 112 | - 'name' => $name, | |
| 113 | - 'type' => 'settings', | |
| 114 | - 'subtype' => $subtype, | |
| 33 | + 'name' => sprintf( _x( '%s Settings', '%s theme name', 'assistant' ), $theme->Name ), | |
| 34 | + 'type' => 'theme_settings', | |
| 115 | 35 | 'data' => $data, |
| 116 | 36 | 'media' => [ |
| 117 | - 'attachments' => is_array( $data ) ? MediaPathHelper::get_image_paths_from_data( $data ) : MediaPathHelper::get_image_paths_from_string( $data ) | |
| 37 | + 'attachments' => MediaPathHelper::get_image_paths_from_data( $data ) | |
| 118 | 38 | ], |
| 119 | - 'screenshot' => $screenshot, | |
| 39 | + 'screenshot' => ScreenshotHelper::get_for_post_request( home_url(), false ), | |
| 120 | 40 | ] |
| 121 | 41 | ); |
| 122 | 42 | } |
| 123 | 43 | |
| @@ -123,9 +43,9 @@ | ||
| 123 | 43 | |
| 124 | 44 | /** |
| 125 | 45 | * @return array |
| 126 | 46 | */ |
| 127 | - public function export_theme_settings() { | |
| 47 | + public function export_settings() { | |
| 128 | 48 | global $wp_customize; |
| 129 | 49 | |
| 130 | 50 | $theme_service = new ThemeService(); |
| 131 | 51 | $theme = $theme_service->get_current_theme_data(); |
| @@ -192,20 +112,8 @@ | ||
| 192 | 112 | public function import_from_cloud( $item_id ) { |
| 193 | 113 | $client = new CloudClient; |
| 194 | 114 | $item = $client->libraries->get_item( $item_id ); |
| 195 | 115 | |
| 196 | - if ($item->subtype === 'theme_settings') { | |
| 197 | - return $this->import_theme_settings_from_cloud( $item ); | |
| 198 | - } elseif ( $item->subtype === 'bb_settings' ) { | |
| 199 | - // Convert settings back into array | |
| 200 | - $item->data = json_decode(json_encode($item->data), true); | |
| 201 | - return $this->import_bb_settings( $item ); | |
| 202 | - } else { | |
| 203 | - return rest_ensure_response( [ 'error' => __( 'Unsupported settings type.' ) ] ); | |
| 204 | - } | |
| 205 | - } | |
| 206 | - | |
| 207 | - public function import_theme_settings_from_cloud( $item ) { | |
| 208 | 116 | if ( ! is_object( $item ) || empty( $item->data ) ) { |
| 209 | 117 | return rest_ensure_response( [ 'error' => __( 'Missing item data.' ) ] ); |
| 210 | 118 | } |
| 211 | 119 | |
| @@ -217,9 +125,9 @@ | ||
| 217 | 125 | ] ); |
| 218 | 126 | } |
| 219 | 127 | |
| 220 | 128 | $data = $this->import_media_from_library( $item ); |
| 221 | - $this->import_theme_settings( $data ); | |
| 129 | + $this->import_settings( $data ); | |
| 222 | 130 | |
| 223 | 131 | return rest_ensure_response( [ |
| 224 | 132 | 'success' => true |
| 225 | 133 | ] ); |
| @@ -224,77 +132,8 @@ | ||
| 224 | 132 | 'success' => true |
| 225 | 133 | ] ); |
| 226 | 134 | } |
| 227 | 135 | |
| 228 | - public function import_bb_settings( $item ) { | |
| 229 | - $data = $item->data; | |
| 230 | - | |
| 231 | - if ( !class_exists( '\FLBuilderModel') ) { | |
| 232 | - return rest_ensure_response( [ 'error' => __( 'Unable to load BeaverBuilder settings importer.' ) ] ); | |
| 233 | - } | |
| 234 | - | |
| 235 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 236 | - return rest_ensure_response( [ 'error' => __( 'You do not have permission to export BeaverBuilder settings.' ) ] ); | |
| 237 | - } | |
| 238 | - | |
| 239 | - if ( isset( $data['builder_global_settings'] ) ) { | |
| 240 | - update_option( '_fl_builder_settings', $data['builder_global_settings'], true ); | |
| 241 | - } | |
| 242 | - | |
| 243 | - // loop through admin settings | |
| 244 | - if ( isset( $data['admin_settings'] ) ) { | |
| 245 | - $settings = $data['admin_settings']; | |
| 246 | - | |
| 247 | - foreach ( $settings as $key => $setting ) { | |
| 248 | - update_option( $key, $setting, true ); | |
| 249 | - } | |
| 250 | - } | |
| 251 | - | |
| 252 | - $globals = get_option( '_fl_builder_styles' ); | |
| 253 | - if ( isset( $data['global_styles'] ) ) { | |
| 254 | - $backup_colors = isset( $globals->colors ) ? $globals->colors : array(); | |
| 255 | - $new_settings = (object) $data['global_styles']; | |
| 256 | - $new_settings->colors = $backup_colors; | |
| 257 | - $globals = $new_settings; | |
| 258 | - \FLBuilderUtils::update_option( '_fl_builder_styles', $globals, true ); | |
| 259 | - } | |
| 260 | - | |
| 261 | - // global styles/colors... | |
| 262 | - if ( isset( $data['global_colors'] ) ) { | |
| 263 | - // get current settings and swap out colours | |
| 264 | - $globals = $globals ? $globals : \FLBuilderGlobalStyles::get_settings( false ); | |
| 265 | - $current = $globals->colors; | |
| 266 | - | |
| 267 | - $new = array_merge( (array) $current, (array) $data['global_colors'] ); | |
| 268 | - | |
| 269 | - // filter out duplicates | |
| 270 | - $serialized = array_map( 'serialize', $new ); | |
| 271 | - $unique = array_unique( $serialized ); | |
| 272 | - $globals->colors = array_intersect_key( $new, $unique ); | |
| 273 | - | |
| 274 | - foreach ( $globals->colors as $k => $color ) { | |
| 275 | - if ( empty( $color ) || ! $color['color'] ) { | |
| 276 | - unset( $globals->colors[ $k ] ); | |
| 277 | - } | |
| 278 | - } | |
| 279 | - | |
| 280 | - if ( isset( $data->global_colors_prefix ) ) { | |
| 281 | - $globals->prefix = $data->global_colors_prefix; | |
| 282 | - } | |
| 283 | - | |
| 284 | - // Fixes global colors not starting with 0 key | |
| 285 | - $globals->colors = array_values( $globals->colors ); | |
| 286 | - | |
| 287 | - \FLBuilderUtils::update_option( '_fl_builder_styles', $globals, true ); | |
| 288 | - } | |
| 289 | - | |
| 290 | - \FLBuilderModel::delete_asset_cache_for_all_posts(); | |
| 291 | - | |
| 292 | - return rest_ensure_response( [ | |
| 293 | - 'success' => true | |
| 294 | - ] ); | |
| 295 | - } | |
| 296 | - | |
| 297 | 136 | public function import_media_from_library( $item ) { |
| 298 | 137 | $service = new MediaLibraryService(); |
| 299 | 138 | $data = $item->data; |
| 300 | 139 | $media = $item->media; |
| @@ -332,9 +171,9 @@ | ||
| 332 | 171 | /** |
| 333 | 172 | * @param array $data |
| 334 | 173 | * @return bool|WP_Error |
| 335 | 174 | */ |
| 336 | - public function import_theme_settings( $data ) { | |
| 175 | + public function import_settings( $data ) { | |
| 337 | 176 | global $wp_customize; |
| 338 | 177 | |
| 339 | 178 | $template = get_template(); |
| 340 | 179 | $can_import = $this->can_import_settings( $data ); |