Ocean Extra - Version 1.0.5

Version Description

  • New import/export tab to easily import or export your settings.
Download this release

Release Info

Developer oceanwp
Plugin Icon 128x128 Ocean Extra
Version 1.0.5
Comparing to
See all releases

Code changes from version 1.0.4 to 1.0.5

includes/metabox/assets/ocean-metabox.css CHANGED
@@ -23,13 +23,6 @@
23
 
24
  #ocean-metabox .inside .ocean-wrap .ocean-mb-desc p.ocean-mb-description { font-size: 12px; font-weight: normal; margin: 8px 0 0; padding: 0; color: #939393; }
25
 
26
- #ocean-metabox .inside .ocean-wrap .ocean-multiple-links .ocean-custom-links { margin-top: 14px; }
27
- #ocean-metabox .inside .ocean-wrap .ocean-multiple-links .ocean-custom-links:first-child { margin-top: 0; }
28
- #ocean-metabox .inside .ocean-wrap .ocean-multiple-links .first,
29
- #ocean-metabox .inside .ocean-wrap .ocean-multiple-links .last { width: 48%; }
30
- #ocean-metabox .inside .ocean-wrap .ocean-multiple-links .first { float: left; }
31
- #ocean-metabox .inside .ocean-wrap .ocean-multiple-links .last { float: right; }
32
-
33
  #ocean-metabox .inside .ocean-wrap .uploader input[type="text"] { width: 78%; }
34
  #ocean-metabox .inside .ocean-wrap .uploader .ocean-mb-uploader { float: right; width: 18%; height: 35px; margin: 1px; border-radius: 0; outline: 0; -webkit-box-shadow: none; box-shadow: none; vertical-align: middle; }
35
  #ocean-metabox .inside .ocean-wrap .uploader .ocean-mb-uploader:hover { border-color: #bbb; }
23
 
24
  #ocean-metabox .inside .ocean-wrap .ocean-mb-desc p.ocean-mb-description { font-size: 12px; font-weight: normal; margin: 8px 0 0; padding: 0; color: #939393; }
25
 
 
 
 
 
 
 
 
26
  #ocean-metabox .inside .ocean-wrap .uploader input[type="text"] { width: 78%; }
27
  #ocean-metabox .inside .ocean-wrap .uploader .ocean-mb-uploader { float: right; width: 18%; height: 35px; margin: 1px; border-radius: 0; outline: 0; -webkit-box-shadow: none; box-shadow: none; vertical-align: middle; }
28
  #ocean-metabox .inside .ocean-wrap .uploader .ocean-mb-uploader:hover { border-color: #bbb; }
includes/metabox/gallery-metabox/gallery-metabox.php CHANGED
@@ -49,7 +49,7 @@ if ( ! class_exists( 'Ocean_Gallery_Metabox' ) ) {
49
  *
50
  * @since 1.0.0
51
  */
52
- function add_meta( $post ) {
53
  add_meta_box(
54
  'ocean-gallery-metabox',
55
  __( 'Image Gallery', 'ocean-extra' ),
@@ -66,10 +66,7 @@ if ( ! class_exists( 'Ocean_Gallery_Metabox' ) ) {
66
  * @since 1.0.0
67
  */
68
  public function render() {
69
- global $post;
70
-
71
- wp_nonce_field( 'gallery_meta_nonce', 'gallery_meta_nonce' );
72
- $ids = get_post_meta( $post->ID, 'ocean_gallery_id', true ); ?>
73
 
74
 
75
  <p class="add-ocean-gallery-images hide-if-no-js">
49
  *
50
  * @since 1.0.0
51
  */
52
+ public function add_meta( $post ) {
53
  add_meta_box(
54
  'ocean-gallery-metabox',
55
  __( 'Image Gallery', 'ocean-extra' ),
66
  * @since 1.0.0
67
  */
68
  public function render() {
69
+ global $post; ?>
 
 
 
70
 
71
 
72
  <p class="add-ocean-gallery-images hide-if-no-js">
includes/metabox/metabox.php CHANGED
@@ -162,7 +162,6 @@ class Ocean_Post_Metaboxes {
162
  $input_min = isset ( $setting['input_attrs']['min'] ) ? $setting['input_attrs']['min'] : '0';
163
  $input_max = isset ( $setting['input_attrs']['max'] ) ? $setting['input_attrs']['max'] : '10';
164
  $input_step = isset ( $setting['input_attrs']['step'] ) ? $setting['input_attrs']['step'] : '1';
165
- $links_count = isset ( $setting['links_count'] ) ? $setting['links_count'] : '4';
166
  $meta_value = get_post_meta( $post_id, $meta_id, true );
167
  $meta_value = $meta_value ? $meta_value : $default; ?>
168
 
162
  $input_min = isset ( $setting['input_attrs']['min'] ) ? $setting['input_attrs']['min'] : '0';
163
  $input_max = isset ( $setting['input_attrs']['max'] ) ? $setting['input_attrs']['max'] : '10';
164
  $input_step = isset ( $setting['input_attrs']['step'] ) ? $setting['input_attrs']['step'] : '1';
 
165
  $meta_value = get_post_meta( $post_id, $meta_id, true );
166
  $meta_value = $meta_value ? $meta_value : $default; ?>
167
 
includes/panel/extensions.php CHANGED
@@ -24,7 +24,7 @@ class Ocean_Extensions {
24
  }
25
 
26
  /**
27
- * Add sub menu page for the custom CSS input
28
  *
29
  * @since 1.0.0
30
  */
24
  }
25
 
26
  /**
27
+ * Add sub menu page
28
  *
29
  * @since 1.0.0
30
  */
includes/panel/import-export.php ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Import/Export
4
+ *
5
+ * @package Ocean_Extra
6
+ * @category Core
7
+ * @author OceanWP
8
+ */
9
+
10
+ // Exit if accessed directly
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ // Start Class
16
+ class Ocean_Import_Export {
17
+
18
+ /**
19
+ * Start things up
20
+ */
21
+ public function __construct() {
22
+ add_action( 'admin_menu', array( $this, 'add_page' ), 999 );
23
+ add_filter( 'upload_mimes', array( $this, 'add_mime_types' ) );
24
+ add_action( 'admin_init', array( $this, 'register_settings' ) );
25
+ add_action( 'admin_notices', array( $this, 'register_notices' ) );
26
+ add_action( 'load-theme-panel_page_ocean-panel-import-export', array( $this, 'send_export_file' ) );
27
+ add_action( 'load-theme-panel_page_ocean-panel-import-export', array( $this, 'upload_import_file' ) );
28
+ }
29
+
30
+ /**
31
+ * Add sub menu page
32
+ *
33
+ * @since 1.0.5
34
+ */
35
+ public function add_page() {
36
+ add_submenu_page(
37
+ 'ocean-panel',
38
+ esc_html__( 'Import/Export', 'ocean-extra' ),
39
+ esc_html__( 'Import/Export', 'ocean-extra' ),
40
+ 'manage_options',
41
+ 'ocean-panel-import-export',
42
+ array( $this, 'create_admin_page' )
43
+ );
44
+ }
45
+
46
+ /**
47
+ * Add mime type for upload
48
+ *
49
+ * @since 1.0.5
50
+ */
51
+ public static function add_mime_types( $mime_types ) {
52
+ $mime_types['json'] = 'application/json';
53
+
54
+ return $mime_types;
55
+ }
56
+
57
+ /**
58
+ * Register setting
59
+ *
60
+ * @since 1.0.5
61
+ */
62
+ public static function register_settings() {
63
+ register_setting( 'ocean_import_setting', 'ocean_import_setting', array( 'Ocean_Import_Export', 'import_data' ) );
64
+ }
65
+
66
+ /**
67
+ * Register all messages
68
+ *
69
+ * @since 1.0.5
70
+ */
71
+ public static function register_notices() {
72
+ settings_errors( 'ocean-import-notices' );
73
+ }
74
+
75
+ /**
76
+ * Send export file to user
77
+ *
78
+ * @since 1.0.5
79
+ */
80
+ public static function send_export_file() {
81
+
82
+ // Export requested
83
+ if ( ! empty( $_GET['export'] ) ) {
84
+
85
+ // Get an array of all the theme mods
86
+ $mods = get_theme_mods();
87
+
88
+ if ( $mods ) {
89
+
90
+ $get_mods = array();
91
+
92
+ foreach ( $mods as $mod => $value ) {
93
+ $get_mods[$mod] = maybe_unserialize( $value );
94
+ }
95
+
96
+ $json = json_encode( $get_mods );
97
+
98
+ } else {
99
+
100
+ $json = esc_attr__( 'No Settings Found', 'ocean-extra' );
101
+
102
+ }
103
+
104
+ // Get file size
105
+ $filesize = strlen( $json );
106
+
107
+ // Headers to prompt "Save As"
108
+ header( 'Content-Type: application/octet-stream' );
109
+ header( 'Content-Disposition: attachment; filename=ocean-export.json' );
110
+ header( 'Expires: 0' );
111
+ header( 'Cache-Control: must-revalidate' );
112
+ header( 'Pragma: public' );
113
+ header( 'Content-Length: ' . $filesize );
114
+
115
+ // Clear buffering just in case
116
+ @ob_end_clean();
117
+ flush();
118
+
119
+ // Output file contents
120
+ echo $json;
121
+
122
+ // Stop execution
123
+ exit;
124
+
125
+ }
126
+
127
+ }
128
+
129
+ /**
130
+ * Upload import file
131
+ *
132
+ * @since 1.0.5
133
+ */
134
+ public static function upload_import_file() {
135
+
136
+ // Check nonce for security since form was posted
137
+ if ( ! empty( $_POST ) && ! empty( $_FILES['ocean_import_file'] )
138
+ && check_admin_referer( 'ocean_import', 'ocean_import_nonce' ) ) { // check_admin_referer prints fail page and dies
139
+
140
+ // Uploaded file
141
+ $uploaded_file = $_FILES['ocean_import_file'];
142
+
143
+ // Check file type
144
+ // This will also fire if no file uploaded
145
+ $wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'], false );
146
+ if ( 'json' != $wp_filetype['ext'] && ! wp_match_mime_types( 'json', $wp_filetype['type'] ) ) {
147
+ wp_die(
148
+ wp_kses(
149
+ __( 'You must upload a <b>.json</b> file generated by the export button.', 'ocean-extra' ),
150
+ array(
151
+ 'b' => array()
152
+ )
153
+ ),
154
+ '',
155
+ array( 'back_link' => true )
156
+ );
157
+ }
158
+
159
+ // Check and move file to uploads dir, get file data
160
+ // Will show die with WP errors if necessary (file too large, quota exceeded, etc.)
161
+ $overrides = array( 'test_form' => false );
162
+ $file_data = wp_handle_upload( $uploaded_file, $overrides );
163
+ if ( isset( $file_data['error'] ) ) {
164
+ wp_die(
165
+ $file_data['error'],
166
+ '',
167
+ array( 'back_link' => true )
168
+ );
169
+ }
170
+
171
+ // Process import file
172
+ self::process_import_file( $file_data['file'] );
173
+
174
+ }
175
+
176
+ }
177
+
178
+ /**
179
+ * Process import file
180
+ *
181
+ * @since 1.0.5
182
+ */
183
+ public static function process_import_file( $file ) {
184
+
185
+ // File exists?
186
+ if ( ! file_exists( $file ) ) {
187
+ wp_die(
188
+ esc_html__( 'Import file could not be found. Please try again.', 'ocean-extra' ),
189
+ '',
190
+ array( 'back_link' => true )
191
+ );
192
+ }
193
+
194
+ // Get file contents and decode
195
+ $data = file_get_contents( $file );
196
+ $data = json_decode( $data, true );
197
+
198
+ // Delete import file
199
+ unlink( $file );
200
+
201
+ // Import data
202
+ self::import_data( $data );
203
+
204
+ }
205
+
206
+ /**
207
+ * Sanitization callback
208
+ *
209
+ * @since 1.0.5
210
+ */
211
+ public static function import_data( $file ) {
212
+
213
+ $msg = null;
214
+ $type = null;
215
+
216
+ // Import the file
217
+ if ( ! empty( $file ) ) {
218
+
219
+ if ( '0' == json_last_error() ) {
220
+
221
+ // Loop through mods and add them
222
+ foreach ( $file as $mod => $value ) {
223
+ set_theme_mod( $mod, $value );
224
+ }
225
+
226
+ // Success message
227
+ $msg = esc_attr__( 'Settings imported successfully.', 'ocean-extra' );
228
+ $type = 'updated';
229
+
230
+ }
231
+
232
+ // Display invalid json data error
233
+ else {
234
+
235
+ $msg = esc_attr__( 'Invalid Import Data.', 'ocean-extra' );
236
+ $type = 'error';
237
+
238
+ }
239
+
240
+ }
241
+
242
+ // No json data entered
243
+ else {
244
+ $error_msg = esc_attr__( 'No import data found.', 'total' );
245
+ $error_type = 'error';
246
+ }
247
+
248
+ // Display notice
249
+ add_settings_error( 'ocean-import-notices', esc_attr( 'settings_updated' ), $msg, $type );
250
+
251
+ // Return file
252
+ return $file;
253
+
254
+ }
255
+
256
+ /**
257
+ * Settings page output
258
+ *
259
+ * @since 1.0.5
260
+ */
261
+ public static function create_admin_page() { ?>
262
+
263
+ <div class="wrap">
264
+
265
+ <h2><?php esc_html_e( 'Ocean Importer & Exporter', 'ocean-extra' ); ?></h2>
266
+
267
+ <p><?php esc_html_e( 'This will import/export all theme_mods that means if other plugins are adding settings in the Customizer it will import/export those as well.', 'ocean-extra' ); ?></p>
268
+
269
+ <?php
270
+ // Display notices
271
+ settings_fields( 'ocean_import_setting' ); ?>
272
+
273
+ <h3 class="title"><?php esc_html_e( 'Import Settings', 'ocean-extra' ); ?></h3>
274
+
275
+ <p><?php echo wp_kses( __( 'Please select a <b>.json</b> file generated by the export button.', 'ocean-extra' ), array( 'b' => array() ) ); ?></p>
276
+
277
+ <form method="post" enctype="multipart/form-data">
278
+
279
+ <?php wp_nonce_field( 'ocean_import', 'ocean_import_nonce' ); ?>
280
+
281
+ <input type="file" name="ocean_import_file" id="ocean-import-file" />
282
+
283
+ <p class="submit">
284
+ <input type="submit" class="button button-primary" value="<?php esc_attr_e( 'Import Settings', 'ocean-extra' ) ?>" />
285
+ </p>
286
+
287
+ </form>
288
+
289
+ <h3 class="title"><?php echo esc_html_x( 'Export Settings', 'heading', 'ocean-extra' ); ?></h3>
290
+
291
+ <p><?php echo wp_kses( __( 'Click below to generate a <b>.json</b> file for all settings.', 'ocean-extra' ), array( 'b' => array() ) ); ?></p>
292
+
293
+ <p class="submit">
294
+ <a href="<?php echo esc_url( admin_url( basename( $_SERVER['PHP_SELF'] ) . '?page=' . $_GET['page'] . '&export=1' ) ); ?>" id="ocean-export-button" class="button button-primary"><?php echo esc_html_x( 'Export Settings', 'button', 'ocean-extra' ); ?></a>
295
+ </p>
296
+
297
+ </div>
298
+
299
+ <?php }
300
+
301
+ }
302
+ new Ocean_Import_Export();
includes/panel/theme-panel.php CHANGED
@@ -372,8 +372,13 @@ if ( ! class_exists( 'Ocean_Theme_Panel' ) ) {
372
  $dir = OE_ROOT .'/includes/panel/';
373
 
374
  // Custom CSS
375
- if ( get_theme_mod( 'custom_css_enable', true ) ) {
376
- require_once( $dir .'custom-css.php' );
 
 
 
 
 
377
  }
378
 
379
  // Links
372
  $dir = OE_ROOT .'/includes/panel/';
373
 
374
  // Custom CSS
375
+ require_once( $dir .'custom-css.php' );
376
+
377
+ if ( is_admin() ) {
378
+
379
+ // Import/Export
380
+ require_once( $dir .'import-export.php' );
381
+
382
  }
383
 
384
  // Links
ocean-extra.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Ocean Extra
4
  * Plugin URI: https://oceanwp.org/extension/ocean-extra/
5
  * Description: Add extra features like metaboxes, custom CSS and a panel to activate the premium extensions.
6
- * Version: 1.0.4
7
  * Author: OceanWP
8
  * Author URI: https://oceanwp.org/
9
  * Requires at least: 4.0.0
@@ -86,7 +86,7 @@ final class Ocean_Extra {
86
  $this->token = 'ocean-extra';
87
  $this->plugin_url = plugin_dir_url( __FILE__ );
88
  $this->plugin_path = plugin_dir_path( __FILE__ );
89
- $this->version = '1.0.4';
90
 
91
  define( 'OE_ROOT', dirname( __FILE__ ) );
92
  define( 'OE_ADMIN_PANEL_HOOK_PREFIX', 'theme-panel_page_ocean-panel' );
3
  * Plugin Name: Ocean Extra
4
  * Plugin URI: https://oceanwp.org/extension/ocean-extra/
5
  * Description: Add extra features like metaboxes, custom CSS and a panel to activate the premium extensions.
6
+ * Version: 1.0.5
7
  * Author: OceanWP
8
  * Author URI: https://oceanwp.org/
9
  * Requires at least: 4.0.0
86
  $this->token = 'ocean-extra';
87
  $this->plugin_url = plugin_dir_url( __FILE__ );
88
  $this->plugin_path = plugin_dir_path( __FILE__ );
89
+ $this->version = '1.0.5';
90
 
91
  define( 'OE_ROOT', dirname( __FILE__ ) );
92
  define( 'OE_ADMIN_PANEL_HOOK_PREFIX', 'theme-panel_page_ocean-panel' );
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: oceanwp
3
  Tags: meta boxes, meta box, metaboxes, metabox, social sharing, ocean
4
  Requires at least: 3.5
5
  Tested up to: 4.6.1
6
- Stable tag: 1.0.4
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -33,6 +33,9 @@ This plugin will only work with the [Ocean](https://oceanwp.org/) theme.
33
 
34
  == Changelog ==
35
 
 
 
 
36
  = 1.0.4 =
37
  - Modified capability to manage options for the Custom CSS tab.
38
 
3
  Tags: meta boxes, meta box, metaboxes, metabox, social sharing, ocean
4
  Requires at least: 3.5
5
  Tested up to: 4.6.1
6
+ Stable tag: 1.0.5
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
33
 
34
  == Changelog ==
35
 
36
+ = 1.0.5 =
37
+ - New import/export tab to easily import or export your settings.
38
+
39
  = 1.0.4 =
40
  - Modified capability to manage options for the Custom CSS tab.
41