Ocean Demo Import - Version 1.0.8

Version Description

-Added: Now you will have two steps to import a demo, in the second step, you will be able to import only the XML file and/or the customizer settings and/or the widgets. -Tweak: Much better approch to import a demo, now you just need to click the demo you want to import, install the required plugins and wait for the import.

Download this release

Release Info

Developer oceanwp
Plugin Icon 128x128 Ocean Demo Import
Version 1.0.8
Comparing to
See all releases

Code changes from version 1.0.7 to 1.0.8

assets/css/admin.css DELETED
@@ -1,264 +0,0 @@
1
- #odi-demo-wrap {
2
- display: block;
3
- }
4
- #odi-demo-wrap .odi-important-notice {
5
- margin: 15px 0 0;
6
- padding: 10px 15px;
7
- background: #fff;
8
- }
9
- #odi-demo-wrap .odi-important-notice p {
10
- font-size: 14px;
11
- margin: 0 0 5px;
12
- }
13
- #odi-demo-wrap .odi-important-notice p:last-child {
14
- margin: 0;
15
- }
16
- #odi-demo-wrap .odi-about-description {
17
- margin-top: 30px;
18
- }
19
- #odi-demo-wrap .odi-about-description p {
20
- font-size: 15px;
21
- font-weight: 400;
22
- line-height: 1.8;
23
- margin: 0;
24
- }
25
- #odi-demo-wrap hr {
26
- margin: 32px 0 40px;
27
- }
28
- #odi-demo-wrap .themes {
29
- margin: 0 -15px;
30
- }
31
- #odi-demo-wrap .odi-header-bar {
32
- display: inline-block;
33
- width: -webkit-calc(100% - 40px);
34
- width: calc(100% - 40px);
35
- margin-bottom: 30px;
36
- padding: 0 20px;
37
- background-color: #fff;
38
- }
39
- #odi-demo-wrap .odi-navigation {
40
- font-size: 13px;
41
- float: left;
42
- width: 100%;
43
- }
44
- #odi-demo-wrap .odi-navigation ul {
45
- overflow: hidden;
46
- margin: 0;
47
- padding: 0;
48
- list-style-type: none;
49
- }
50
- #odi-demo-wrap .odi-navigation li {
51
- float: left;
52
- margin: 0 15px;
53
- }
54
- #odi-demo-wrap .odi-navigation li.active a,
55
- #odi-demo-wrap .odi-navigation li.active a:hover {
56
- border-bottom: 4px solid #666;
57
- }
58
- #odi-demo-wrap .odi-navigation li a {
59
- display: block;
60
- padding: 15px 0;
61
- text-align: center;
62
- text-decoration: none;
63
- color: #444;
64
- border-bottom: 4px solid #fff;
65
- outline: 0;
66
- -webkit-box-shadow: none;
67
- box-shadow: none;
68
- }
69
- #odi-demo-wrap .odi-navigation li a:hover {
70
- cursor: pointer;
71
- color: #00a0d2;
72
- border-bottom: 4px solid #fff;
73
- }
74
- #odi-demo-wrap .odi-search-input {
75
- width: 100%;
76
- margin: 10px 0;
77
- -webkit-transition: 50ms border-color ease-in-out;
78
- transition: 50ms border-color ease-in-out;
79
- outline: 0;
80
- -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, .07);
81
- box-shadow: inset 0 1px 2px rgba(0, 0, 0, .07);
82
- }
83
- #odi-demo-wrap .theme-wrap {
84
- float: left;
85
- -webkit-box-sizing: border-box;
86
- box-sizing: border-box;
87
- width: 33.33%;
88
- padding: 0 15px 30px 15px;
89
- }
90
- #odi-demo-wrap .theme {
91
- float: none;
92
- width: 100%;
93
- margin: 0;
94
- }
95
-
96
- .odi-is-fadeout {
97
- -webkit-animation: odi-fade linear 200ms 1 forwards;
98
- animation: odi-fade linear 200ms 1 forwards;
99
- }
100
-
101
- .odi-is-fadein {
102
- -webkit-animation: odi-fade linear 200ms 1 reverse forwards;
103
- animation: odi-fade linear 200ms 1 reverse forwards;
104
- }
105
-
106
- @-webkit-keyframes odi-fade {
107
- from {
108
- opacity: 1;
109
- }
110
- to {
111
- opacity: 0;
112
- }
113
- }
114
-
115
- @keyframes odi-fade {
116
- from {
117
- opacity: 1;
118
- }
119
- to {
120
- opacity: 0;
121
- }
122
- }
123
-
124
- .demo-import-loader {
125
- position: absolute;
126
- top: 0;
127
- display: none;
128
- width: 100%;
129
- height: 100%;
130
- text-align: center;
131
- }
132
- .demo-import-loader.preview-all {
133
- background: rgba(255, 255, 255, .7);
134
- }
135
- .demo-import-loader i {
136
- font-size: 32px;
137
- line-height: 32px;
138
- position: relative;
139
- top: 50%;
140
- display: inline-block;
141
- width: 32px;
142
- height: 32px;
143
- margin: -16px auto 0 auto;
144
- -webkit-animation: spin 2s infinite linear;
145
- animation: spin 2s infinite linear;
146
- text-align: center;
147
- }
148
-
149
- .preview-icon i {
150
- color: #333;
151
- }
152
-
153
- .success-icon i {
154
- font-size: 40px;
155
- width: 40px;
156
- height: 40px;
157
- margin: -20px auto 0 auto;
158
- color: #329e6d;
159
- }
160
-
161
- .warning-icon i {
162
- color: #ff6c6c;
163
- }
164
-
165
- .success-icon i,
166
- .warning-icon i {
167
- -webkit-animation: none;
168
- animation: none;
169
- }
170
-
171
- @-webkit-keyframes spin {
172
- 0% {
173
- -webkit-transform: rotate(0deg);
174
- }
175
- 100% {
176
- -webkit-transform: rotate(359deg);
177
- }
178
- }
179
-
180
- @keyframes spin {
181
- 0% {
182
- -webkit-transform: rotate(0deg);
183
- transform: rotate(0deg);
184
- }
185
- 100% {
186
- -webkit-transform: rotate(359deg);
187
- transform: rotate(359deg);
188
- }
189
- }
190
-
191
- #odi-demo-wrap .theme-browser .theme:focus,
192
- #odi-demo-wrap .theme-browser .theme:hover {
193
- cursor: default;
194
- }
195
-
196
- #odi-demo-wrap .theme-browser .theme .theme-screenshot {
197
- cursor: pointer;
198
- }
199
-
200
- #odi-demo-wrap .theme-browser .theme .theme-name span {
201
- cursor: text;
202
- }
203
-
204
- /* RTL */
205
- .rtl #odi-demo-wrap .theme-wrap,
206
- .rtl #odi-demo-wrap .odi-navigation,
207
- .rtl #odi-demo-wrap .odi-navigation li {
208
- float: right;
209
- }
210
-
211
- /* Responsive */
212
- @media only screen and (min-width: 1640px) {
213
- #odi-demo-wrap .theme-wrap {
214
- width: 25%;
215
- }
216
- }
217
-
218
- @media only screen and (max-width: 1080px) {
219
- #odi-demo-wrap .theme-wrap {
220
- width: 50%;
221
- }
222
- }
223
-
224
- @media only screen and (max-width: 780px) {
225
- #odi-demo-wrap .theme {
226
- text-align: center;
227
- }
228
- #odi-demo-wrap .theme-actions {
229
- position: relative;
230
- display: block;
231
- opacity: 1;
232
- }
233
- #odi-demo-wrap .theme-browser .theme .theme-actions .button-primary {
234
- margin-right: 0 !important;
235
- margin-left: 0 !important;
236
- }
237
- }
238
-
239
- @media only screen and (min-width: 640px) {
240
- #odi-demo-wrap .odi-navigation {
241
- width: -webkit-calc(100% - 180px);
242
- width: calc(100% - 180px);
243
- }
244
- #odi-demo-wrap .odi-navigation li {
245
- margin: 0;
246
- }
247
- #odi-demo-wrap .odi-navigation li a {
248
- padding: 15px;
249
- }
250
- #odi-demo-wrap .odi-search-input {
251
- display: inline-block;
252
- width: 180px;
253
- height: 30px;
254
- margin: 0;
255
- margin-top: 11px;
256
- }
257
- }
258
-
259
- @media only screen and (max-width: 580px) {
260
- #odi-demo-wrap .theme-wrap {
261
- float: none;
262
- width: 100%;
263
- }
264
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/css/admin.min.css DELETED
@@ -1 +0,0 @@
1
- #odi-demo-wrap{display:block}#odi-demo-wrap .odi-important-notice{padding:10px 15px;background:#fff;margin:15px 0 0}#odi-demo-wrap .odi-important-notice p{font-size:14px;margin:0 0 5px}#odi-demo-wrap .odi-important-notice p:last-child{margin:0}#odi-demo-wrap .odi-about-description{margin-top:30px}#odi-demo-wrap .odi-about-description p{font-size:15px;font-weight:400;line-height:1.8;margin:0}#odi-demo-wrap hr{margin:32px 0 40px}#odi-demo-wrap .themes{margin:0 -15px}#odi-demo-wrap .odi-header-bar{display:inline-block;width:-webkit-calc(100% - 40px);width:calc(100% - 40px);background-color:#ffffff;margin-bottom:30px;padding:0 20px}#odi-demo-wrap .odi-navigation{float:left;font-size:13px;width:100%}#odi-demo-wrap .odi-navigation ul{list-style-type:none;margin:0;padding:0;overflow:hidden}#odi-demo-wrap .odi-navigation li{float:left;margin:0 15px}#odi-demo-wrap .odi-navigation li.active a,#odi-demo-wrap .odi-navigation li.active a:hover{border-bottom:4px solid #666666}#odi-demo-wrap .odi-navigation li a{display:block;text-align:center;text-decoration:none;color:#444444;border-bottom:4px solid #ffffff;padding:15px 0;outline:0;-webkit-box-shadow:none;box-shadow:none}#odi-demo-wrap .odi-navigation li a:hover{color:#00a0d2;border-bottom:4px solid #ffffff;cursor:pointer}#odi-demo-wrap .odi-search-input{width:100%;margin:10px 0;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.07);box-shadow:inset 0 1px 2px rgba(0,0,0,0.07);outline:0;-webkit-transition:50ms border-color ease-in-out;transition:50ms border-color ease-in-out}#odi-demo-wrap .theme-wrap{float:left;width:33.33%;padding:0 15px 30px 15px;-webkit-box-sizing:border-box;box-sizing:border-box}#odi-demo-wrap .theme{float:none;width:100%;margin:0}.odi-is-fadeout{-webkit-animation:odi-fade linear 200ms 1 forwards;animation:odi-fade linear 200ms 1 forwards}.odi-is-fadein{-webkit-animation:odi-fade linear 200ms 1 reverse forwards;animation:odi-fade linear 200ms 1 reverse forwards}@-webkit-keyframes odi-fade{from{opacity:1}to{opacity:0}}@keyframes odi-fade{from{opacity:1}to{opacity:0}}.demo-import-loader{display:none;position:absolute;top:0;width:100%;height:100%;text-align:center}.demo-import-loader.preview-all{background:rgba(255,255,255,0.7)}.demo-import-loader i{display:inline-block;margin:-16px auto 0 auto;height:32px;width:32px;top:50%;position:relative;font-size:32px;line-height:32px;text-align:center;-webkit-animation:spin 2s infinite linear;animation:spin 2s infinite linear}.preview-icon i{color:#333}.success-icon i{color:#329e6d;margin:-20px auto 0 auto;height:40px;width:40px;font-size:40px}.warning-icon i{color:#ff6c6c}.success-icon i,.warning-icon i{-webkit-animation:none;animation:none}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg)}100%{-webkit-transform:rotate(359deg)}}@keyframes spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(359deg);transform:rotate(359deg)}}#odi-demo-wrap .theme-browser .theme:focus,#odi-demo-wrap .theme-browser .theme:hover{cursor:default}#odi-demo-wrap .theme-browser .theme .theme-screenshot{cursor:pointer}#odi-demo-wrap .theme-browser .theme .theme-name span{cursor:text}.rtl #odi-demo-wrap .theme-wrap,.rtl #odi-demo-wrap .odi-navigation,.rtl #odi-demo-wrap .odi-navigation li{float:right}@media only screen and (min-width: 1640px){#odi-demo-wrap .theme-wrap{width:25%}}@media only screen and (max-width: 1080px){#odi-demo-wrap .theme-wrap{width:50%}}@media only screen and (max-width: 780px){#odi-demo-wrap .theme{text-align:center}#odi-demo-wrap .theme-actions{display:block;position:relative;opacity:1}#odi-demo-wrap .theme-browser .theme .theme-actions .button-primary{margin-right:0 !important;margin-left:0 !important}}@media only screen and (min-width: 640px){#odi-demo-wrap .odi-navigation{width:-webkit-calc(100% - 180px);width:calc(100% - 180px)}#odi-demo-wrap .odi-navigation li{margin:0}#odi-demo-wrap .odi-navigation li a{padding:15px}#odi-demo-wrap .odi-search-input{display:inline-block;width:180px;height:30px;margin:0;margin-top:11px}}@media only screen and (max-width: 580px){#odi-demo-wrap .theme-wrap{float:none;width:100%}}
 
assets/css/admin.scss DELETED
@@ -1,156 +0,0 @@
1
- #odi-demo-wrap {
2
- display: block;
3
-
4
- .odi-important-notice {
5
- padding: 10px 15px;
6
- background: #fff;
7
- margin: 15px 0 0;
8
-
9
- p {
10
- font-size: 14px;
11
- margin: 0 0 5px;
12
-
13
- &:last-child { margin: 0; }
14
- }
15
- }
16
-
17
- .odi-about-description {
18
- margin-top: 30px;
19
-
20
- p { font-size: 15px; font-weight: 400; line-height: 1.8; margin: 0; }
21
- }
22
-
23
- hr { margin: 32px 0 40px; }
24
-
25
- .themes { margin: 0 -15px; }
26
-
27
- .odi-header-bar { display: inline-block; width: calc(100% - 40px); background-color: #ffffff; margin-bottom: 30px; padding: 0 20px; }
28
-
29
- .odi-navigation {
30
- float: left;
31
- font-size: 13px;
32
- width: 100%;
33
-
34
- ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; }
35
-
36
- li {
37
- float: left;
38
- margin: 0 15px;
39
-
40
- &.active a,
41
- &.active a:hover { border-bottom: 4px solid #666666; }
42
- a {
43
- display: block;
44
- text-align: center;
45
- text-decoration: none;
46
- color: #444444;
47
- border-bottom: 4px solid #ffffff;
48
- padding: 15px 0;
49
- outline: 0;
50
- -webkit-box-shadow: none;
51
- box-shadow: none;
52
-
53
- &:hover { color: #00a0d2; border-bottom: 4px solid #ffffff; cursor:pointer; }
54
- }
55
- }
56
- }
57
-
58
- .odi-search-input {
59
- width: 100%;
60
- margin: 10px 0;
61
- -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,.07);
62
- box-shadow: inset 0 1px 2px rgba(0,0,0,.07);
63
- outline: 0;
64
- -webkit-transition: 50ms border-color ease-in-out;
65
- transition: 50ms border-color ease-in-out;
66
- }
67
-
68
- .theme-wrap { float: left; width: 33.33%; padding: 0 15px 30px 15px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
69
-
70
- .theme { float: none; width: 100%; margin: 0; }
71
- }
72
-
73
- .odi-is-fadeout { animation: odi-fade linear 200ms 1 forwards; }
74
- .odi-is-fadein { animation: odi-fade linear 200ms 1 reverse forwards; }
75
-
76
- @keyframes odi-fade {
77
- from {
78
- opacity: 1;
79
- }
80
-
81
- to {
82
- opacity: 0;
83
- }
84
- }
85
-
86
- .demo-import-loader {
87
- display: none;
88
- position: absolute;
89
- top: 0;
90
- width: 100%;
91
- height: 100%;
92
- text-align: center;
93
-
94
- &.preview-all { background: rgba( 255, 255, 255, 0.7 ); }
95
- i { display: inline-block; margin: -16px auto 0 auto; height: 32px; width: 32px; top: 50%; position: relative; font-size: 32px; line-height: 32px; text-align: center; -moz-animation: spin 2s infinite linear; -o-animation: spin 2s infinite linear; -webkit-animation: spin 2s infinite linear; animation: spin 2s infinite linear; }
96
- }
97
-
98
- .preview-icon i { color: #333; }
99
- .success-icon i { color: #329e6d; margin: -20px auto 0 auto; height: 40px; width: 40px; font-size: 40px; }
100
- .warning-icon i { color: #ff6c6c; }
101
- .success-icon i, .warning-icon i { -moz-animation: none; -o-animation: none; -webkit-animation: none; animation: none; }
102
-
103
- @-webkit-keyframes spin { 0% { -webkit-transform: rotate(0deg); } 100% { -webkit-transform: rotate(359deg); } }
104
- @-moz-keyframes spin { 0% { -moz-transform: rotate(0deg); } 100% { -moz-transform: rotate(359deg); } }
105
- @-o-keyframes spin { 0% { -o-transform: rotate(0deg); } 100% { -o-transform: rotate(359deg); } }
106
- @-ms-keyframes spin { 0% { -ms-transform: rotate(0deg); } 100% { -ms-transform: rotate(359deg); } }
107
- @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(359deg); } }
108
-
109
- #odi-demo-wrap .theme-browser .theme {
110
- &:focus, &:hover { cursor: default; }
111
- .theme-screenshot { cursor: pointer; }
112
- .theme-name span { cursor: text; }
113
- }
114
-
115
- /* RTL */
116
- .rtl #odi-demo-wrap {
117
- .theme-wrap,
118
- .odi-navigation,
119
- .odi-navigation li { float: right; }
120
- }
121
-
122
- /* Responsive */
123
- @media only screen and (min-width: 1640px) {
124
- #odi-demo-wrap .theme-wrap { width: 25%; }
125
- }
126
-
127
- @media only screen and (max-width: 1080px) {
128
- #odi-demo-wrap .theme-wrap { width: 50%; }
129
- }
130
-
131
- @media only screen and (max-width: 780px) {
132
- #odi-demo-wrap {
133
- .theme { text-align: center; }
134
- .theme-actions { display: block; position: relative; opacity: 1; }
135
- .theme-browser .theme .theme-actions .button-primary { margin-right: 0 !important; margin-left: 0 !important; }
136
- }
137
- }
138
-
139
- @media only screen and (min-width: 640px) {
140
- #odi-demo-wrap {
141
- .odi-navigation {
142
- width: calc(100% - 180px);
143
-
144
- li {
145
- margin: 0;
146
-
147
- a { padding: 15px; }
148
- }
149
- }
150
- .odi-search-input { display: inline-block; width: 180px; height: 30px; margin: 0; margin-top: 11px; }
151
- }
152
- }
153
-
154
- @media only screen and (max-width: 580px) {
155
- #odi-demo-wrap .theme-wrap { float: none; width: 100%; }
156
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/js/admin.js DELETED
@@ -1,150 +0,0 @@
1
- var $j = jQuery.noConflict();
2
-
3
- $j(document).ready(function(e) {
4
-
5
- // Categories navigation
6
- (function () {
7
- // Cache selector to all items
8
- var $items = $j( '#odi-demo-wrap .themes' ).find( '.theme-wrap' ),
9
- fadeoutClass = 'odi-is-fadeout',
10
- fadeinClass = 'odi-is-fadein',
11
- animationDuration = 200;
12
-
13
- // Hide all items.
14
- var fadeOut = function () {
15
- var dfd = jQuery.Deferred();
16
-
17
- $items
18
- .addClass( fadeoutClass );
19
-
20
- setTimeout( function() {
21
- $items
22
- .removeClass( fadeoutClass )
23
- .hide();
24
-
25
- dfd.resolve();
26
- }, animationDuration );
27
-
28
- return dfd.promise();
29
- };
30
-
31
- var fadeIn = function ( category, dfd ) {
32
- var filter = category ? '[data-categories*="' + category + '"]' : 'div';
33
-
34
- if ( 'all' === category ) {
35
- filter = 'div';
36
- }
37
-
38
- $items
39
- .filter( filter )
40
- .show()
41
- .addClass( 'odi-is-fadein' );
42
-
43
- setTimeout( function() {
44
- $items
45
- .removeClass( fadeinClass );
46
-
47
- dfd.resolve();
48
- }, animationDuration );
49
- };
50
-
51
- var animate = function ( category ) {
52
- var dfd = jQuery.Deferred();
53
-
54
- var promise = fadeOut();
55
-
56
- promise.done( function () {
57
- fadeIn( category, dfd );
58
- } );
59
-
60
- return dfd;
61
- };
62
-
63
- $j( '.odi-navigation-link' ).on( 'click', function( event ) {
64
- event.preventDefault();
65
-
66
- // Remove 'active' class from the previous nav list items.
67
- $j( this ).parent().siblings().removeClass( 'active' );
68
-
69
- // Add the 'active' class to this nav list item.
70
- $j( this ).parent().addClass( 'active' );
71
-
72
- var category = this.hash.slice(1);
73
-
74
- // show/hide the right items, based on category selected
75
- var $container = $j( '#odi-demo-wrap .themes' );
76
- $container.css( 'min-width', $container.outerHeight() );
77
-
78
- var promise = animate( category );
79
-
80
- promise.done( function () {
81
- $container.removeAttr( 'style' );
82
- } );
83
- } );
84
- }());
85
-
86
- // Search functionality.
87
- $j( '.odi-search-input' ).on( 'keyup', function( event ) {
88
- if ( 0 < $j( this ).val().length ) {
89
- // Hide all items.
90
- $j( '#odi-demo-wrap .themes' ).find( '.theme-wrap' ).hide();
91
-
92
- // Show just the ones that have a match on the import name.
93
- $j( '#odi-demo-wrap .themes' ).find( '.theme-wrap[data-name*="' + $j( this ).val().toLowerCase() + '"]' ).show();
94
- } else {
95
- $j( '#odi-demo-wrap .themes' ).find( '.theme-wrap' ).show();
96
- }
97
- } );
98
-
99
- // if clicked on import data button
100
- $j( '.odi-install' ).live( 'click', function(e) {
101
-
102
- var $selected_demo = $j( this ).data( 'demo-id' ),
103
- $loading_icon = $j( '.preview-' + $selected_demo ),
104
- $success_icon = $j( '.success-' + $selected_demo ),
105
- $warning_icon = $j( '.warning-' + $selected_demo ),
106
- $disable_preview = $j( '.preview-all-' + $selected_demo );
107
-
108
- $loading_icon.show();
109
- $disable_preview.show();
110
-
111
- var data = {
112
- action: 'ocean_import_demo_data',
113
- demo_type: $selected_demo
114
- };
115
-
116
- $j( '.importer-notice' ).hide();
117
-
118
- $j.post( ajaxurl, data, function( $response ) {
119
- if( $response && $response.indexOf( 'imported' ) == -1 ) {
120
- $j( '.importer-notice-1' ).attr( 'style', 'display:block !important' );
121
- $warning_icon.show();
122
- setTimeout( function() {
123
- $warning_icon.hide();
124
- $disable_preview.hide();
125
- }, 4000 );
126
- } else {
127
- $j( '.importer-notice-2' ).attr( 'style', 'display:block !important' );
128
- $success_icon.show();
129
- setTimeout( function() {
130
- $success_icon.hide();
131
- $disable_preview.hide();
132
- }, 4000 );
133
- }
134
- $loading_icon.hide();
135
- } ).fail( function() {
136
- $j( '.importer-notice-3' ).attr( 'style', 'display:block !important' );
137
- $warning_icon.show();
138
- setTimeout( function() {
139
- $warning_icon.hide();
140
- $disable_preview.hide();
141
- }, 4000 );
142
- $loading_icon.hide();
143
-
144
- } );
145
-
146
- e.preventDefault();
147
-
148
- } );
149
-
150
- } );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/js/admin.min.js DELETED
@@ -1 +0,0 @@
1
- var $j=jQuery.noConflict();$j(document).ready(function(a){!function(){var a=$j("#odi-demo-wrap .themes").find(".theme-wrap"),b="odi-is-fadeout",c="odi-is-fadein",d=200,e=function(){var c=jQuery.Deferred();return a.addClass(b),setTimeout(function(){a.removeClass(b).hide(),c.resolve()},d),c.promise()},f=function(b,e){var f=b?'[data-categories*="'+b+'"]':"div";"all"===b&&(f="div"),a.filter(f).show().addClass("odi-is-fadein"),setTimeout(function(){a.removeClass(c),e.resolve()},d)},g=function(a){var b=jQuery.Deferred(),c=e();return c.done(function(){f(a,b)}),b};$j(".odi-navigation-link").on("click",function(a){a.preventDefault(),$j(this).parent().siblings().removeClass("active"),$j(this).parent().addClass("active");var b=this.hash.slice(1),c=$j("#odi-demo-wrap .themes");c.css("min-width",c.outerHeight());var d=g(b);d.done(function(){c.removeAttr("style")})})}(),$j(".odi-search-input").on("keyup",function(a){0<$j(this).val().length?($j("#odi-demo-wrap .themes").find(".theme-wrap").hide(),$j("#odi-demo-wrap .themes").find('.theme-wrap[data-name*="'+$j(this).val().toLowerCase()+'"]').show()):$j("#odi-demo-wrap .themes").find(".theme-wrap").show()}),$j(".odi-install").live("click",function(a){var b=$j(this).data("demo-id"),c=$j(".preview-"+b),d=$j(".success-"+b),e=$j(".warning-"+b),f=$j(".preview-all-"+b);c.show(),f.show();var g={action:"ocean_import_demo_data",demo_type:b};$j(".importer-notice").hide(),$j.post(ajaxurl,g,function(a){a&&-1==a.indexOf("imported")?($j(".importer-notice-1").attr("style","display:block !important"),e.show(),setTimeout(function(){e.hide(),f.hide()},4e3)):($j(".importer-notice-2").attr("style","display:block !important"),d.show(),setTimeout(function(){d.hide(),f.hide()},4e3)),c.hide()}).fail(function(){$j(".importer-notice-3").attr("style","display:block !important"),e.show(),setTimeout(function(){e.hide(),f.hide()},4e3),c.hide()}),a.preventDefault()})});
 
includes/class/class-helpers.php DELETED
@@ -1,113 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Helpers class
5
- */
6
- class ODI_Helpers {
7
-
8
- /**
9
- * Gets and returns url body using wp_remote_get
10
- *
11
- * @since 1.0.0
12
- */
13
- public static function get_remote( $url ) {
14
-
15
- // Get data
16
- $response = wp_remote_get( $url );
17
-
18
- // Check for errors
19
- if ( is_wp_error( $response ) or ( wp_remote_retrieve_response_code( $response ) != 200 ) ) {
20
- return false;
21
- }
22
-
23
- // Get remote body val
24
- $body = wp_remote_retrieve_body( $response );
25
-
26
- // Return data
27
- if ( ! empty( $body ) ) {
28
- return $body;
29
- } else {
30
- return false;
31
- }
32
- }
33
-
34
- /**
35
- * Perform a HTTP HEAD or GET request.
36
- *
37
- * If $file_path is a writable filename, this will do a GET request and write
38
- * the file to that path.
39
- *
40
- * This is a re-implementation of the deprecated wp_get_http() function from WP Core,
41
- * but this time using the recommended WP_Http() class and the WordPress filesystem.
42
- *
43
- * @param string $url URL to fetch.
44
- * @param string|bool $file_path Optional. File path to write request to. Default false.
45
- * @param array $args Optional. Arguments to be passed-on to the request.
46
- * @return bool|string False on failure and string of headers if HEAD request.
47
- */
48
- public static function odi_wp_get_http( $url, $file_path = false, $red = 1 ) {
49
-
50
- // No need to proceed if we don't have a $url or a $file_path.
51
- if ( ! $url || ! $file_path ) {
52
- return false;
53
- }
54
-
55
- $try_file_get_contents = false;
56
-
57
- // Make sure we normalize $file_path.
58
- $file_path = wp_normalize_path( $file_path );
59
-
60
- // Include the WP_Http class if it doesn't already exist.
61
- if ( ! class_exists( 'WP_Http' ) ) {
62
- include_once( wp_normalize_path( ABSPATH . WPINC . '/class-http.php' ) );
63
- }
64
- // Inlude the wp_remote_get function if it doesn't already exist.
65
- if ( ! function_exists( 'wp_remote_get' ) ) {
66
- include_once( wp_normalize_path( ABSPATH . WPINC . '/http.php' ) );
67
- }
68
-
69
- $args = wp_parse_args( $args, array(
70
- 'timeout' => 30,
71
- 'user-agent' => 'avada-user-agent',
72
- ) );
73
- $response = wp_remote_get( esc_url_raw( $url ), $args );
74
- $body = wp_remote_retrieve_body( $response );
75
-
76
- // Try file_get_contents if body is empty.
77
- if ( empty( $body ) ) {
78
- if ( function_exists( 'ini_get' ) && ini_get( 'allow_url_fopen' ) ) {
79
- $body = @file_get_contents( $url );
80
- }
81
- }
82
-
83
- // Initialize the Wordpress filesystem.
84
- global $wp_filesystem;
85
- if ( empty( $wp_filesystem ) ) {
86
- require_once( ABSPATH . '/wp-admin/includes/file.php' );
87
- WP_Filesystem();
88
- }
89
-
90
- // Attempt to write the file.
91
- if ( ! $wp_filesystem->put_contents( $file_path, $body, FS_CHMOD_FILE ) ) {
92
- // If the attempt to write to the file failed, then fallback to fwrite.
93
- @unlink( $file_path );
94
- $fp = fopen( $file_path, 'w' );
95
- $written = fwrite( $fp, $body );
96
- fclose( $fp );
97
- if ( false === $written ) {
98
- return false;
99
- }
100
- }
101
-
102
- // If all went well, then return the headers of the request.
103
- if ( isset( $response['headers'] ) ) {
104
- $response['headers']['response'] = $response['response']['code'];
105
- return $response['headers'];
106
- }
107
-
108
- // If all else fails, then return false.
109
- return false;
110
-
111
- }
112
-
113
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class/class-parsers.php DELETED
@@ -1,691 +0,0 @@
1
- <?php
2
- /**
3
- * WordPress eXtended RSS file parser implementations
4
- *
5
- * @package WordPress
6
- * @subpackage Importer
7
- */
8
-
9
- /**
10
- * WordPress Importer class for managing parsing of WXR files.
11
- */
12
- class WXR_Parser {
13
- function parse( $file ) {
14
- // Attempt to use proper XML parsers first
15
- if ( extension_loaded( 'simplexml' ) ) {
16
- $parser = new WXR_Parser_SimpleXML;
17
- $result = $parser->parse( $file );
18
-
19
- // If SimpleXML succeeds or this is an invalid WXR file then return the results
20
- if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() )
21
- return $result;
22
- } else if ( extension_loaded( 'xml' ) ) {
23
- $parser = new WXR_Parser_XML;
24
- $result = $parser->parse( $file );
25
-
26
- // If XMLParser succeeds or this is an invalid WXR file then return the results
27
- if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() )
28
- return $result;
29
- }
30
-
31
- // We have a malformed XML file, so display the error and fallthrough to regex
32
- if ( isset($result) && defined('IMPORT_DEBUG') && IMPORT_DEBUG ) {
33
- echo '<pre>';
34
- if ( 'SimpleXML_parse_error' == $result->get_error_code() ) {
35
- foreach ( $result->get_error_data() as $error )
36
- echo $error->line . ':' . $error->column . ' ' . esc_html( $error->message ) . "\n";
37
- } else if ( 'XML_parse_error' == $result->get_error_code() ) {
38
- $error = $result->get_error_data();
39
- echo $error[0] . ':' . $error[1] . ' ' . esc_html( $error[2] );
40
- }
41
- echo '</pre>';
42
- echo '<p><strong>' . __( 'There was an error when reading this WXR file', 'wordpress-importer' ) . '</strong><br />';
43
- echo __( 'Details are shown above. The importer will now try again with a different parser...', 'wordpress-importer' ) . '</p>';
44
- }
45
-
46
- // use regular expressions if nothing else available or this is bad XML
47
- $parser = new WXR_Parser_Regex;
48
- return $parser->parse( $file );
49
- }
50
- }
51
-
52
- /**
53
- * WXR Parser that makes use of the SimpleXML PHP extension.
54
- */
55
- class WXR_Parser_SimpleXML {
56
- function parse( $file ) {
57
- $authors = $posts = $categories = $tags = $terms = array();
58
-
59
- $internal_errors = libxml_use_internal_errors(true);
60
-
61
- $dom = new DOMDocument;
62
- $old_value = null;
63
- if ( function_exists( 'libxml_disable_entity_loader' ) ) {
64
- $old_value = libxml_disable_entity_loader( true );
65
- }
66
- $success = $dom->loadXML( file_get_contents( $file ) );
67
- if ( ! is_null( $old_value ) ) {
68
- libxml_disable_entity_loader( $old_value );
69
- }
70
-
71
- if ( ! $success || isset( $dom->doctype ) ) {
72
- return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() );
73
- }
74
-
75
- $xml = simplexml_import_dom( $dom );
76
- unset( $dom );
77
-
78
- // halt if loading produces an error
79
- if ( ! $xml )
80
- return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() );
81
-
82
- $wxr_version = $xml->xpath('/rss/channel/wp:wxr_version');
83
- if ( ! $wxr_version )
84
- return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
85
-
86
- $wxr_version = (string) trim( $wxr_version[0] );
87
- // confirm that we are dealing with the correct file format
88
- if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) )
89
- return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
90
-
91
- $base_url = $xml->xpath('/rss/channel/wp:base_site_url');
92
- $base_url = (string) trim( $base_url[0] );
93
-
94
- $namespaces = $xml->getDocNamespaces();
95
- if ( ! isset( $namespaces['wp'] ) )
96
- $namespaces['wp'] = 'http://wordpress.org/export/1.1/';
97
- if ( ! isset( $namespaces['excerpt'] ) )
98
- $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
99
-
100
- // grab authors
101
- foreach ( $xml->xpath('/rss/channel/wp:author') as $author_arr ) {
102
- $a = $author_arr->children( $namespaces['wp'] );
103
- $login = (string) $a->author_login;
104
- $authors[$login] = array(
105
- 'author_id' => (int) $a->author_id,
106
- 'author_login' => $login,
107
- 'author_email' => (string) $a->author_email,
108
- 'author_display_name' => (string) $a->author_display_name,
109
- 'author_first_name' => (string) $a->author_first_name,
110
- 'author_last_name' => (string) $a->author_last_name
111
- );
112
- }
113
-
114
- // grab cats, tags and terms
115
- foreach ( $xml->xpath('/rss/channel/wp:category') as $term_arr ) {
116
- $t = $term_arr->children( $namespaces['wp'] );
117
- $category = array(
118
- 'term_id' => (int) $t->term_id,
119
- 'category_nicename' => (string) $t->category_nicename,
120
- 'category_parent' => (string) $t->category_parent,
121
- 'cat_name' => (string) $t->cat_name,
122
- 'category_description' => (string) $t->category_description
123
- );
124
-
125
- foreach ( $t->termmeta as $meta ) {
126
- $category['termmeta'][] = array(
127
- 'key' => (string) $meta->meta_key,
128
- 'value' => (string) $meta->meta_value
129
- );
130
- }
131
-
132
- $categories[] = $category;
133
- }
134
-
135
- foreach ( $xml->xpath('/rss/channel/wp:tag') as $term_arr ) {
136
- $t = $term_arr->children( $namespaces['wp'] );
137
- $tag = array(
138
- 'term_id' => (int) $t->term_id,
139
- 'tag_slug' => (string) $t->tag_slug,
140
- 'tag_name' => (string) $t->tag_name,
141
- 'tag_description' => (string) $t->tag_description
142
- );
143
-
144
- foreach ( $t->termmeta as $meta ) {
145
- $tag['termmeta'][] = array(
146
- 'key' => (string) $meta->meta_key,
147
- 'value' => (string) $meta->meta_value
148
- );
149
- }
150
-
151
- $tags[] = $tag;
152
- }
153
-
154
- foreach ( $xml->xpath('/rss/channel/wp:term') as $term_arr ) {
155
- $t = $term_arr->children( $namespaces['wp'] );
156
- $term = array(
157
- 'term_id' => (int) $t->term_id,
158
- 'term_taxonomy' => (string) $t->term_taxonomy,
159
- 'slug' => (string) $t->term_slug,
160
- 'term_parent' => (string) $t->term_parent,
161
- 'term_name' => (string) $t->term_name,
162
- 'term_description' => (string) $t->term_description
163
- );
164
-
165
- foreach ( $t->termmeta as $meta ) {
166
- $term['termmeta'][] = array(
167
- 'key' => (string) $meta->meta_key,
168
- 'value' => (string) $meta->meta_value
169
- );
170
- }
171
-
172
- $terms[] = $term;
173
- }
174
-
175
- // grab posts
176
- foreach ( $xml->channel->item as $item ) {
177
- $post = array(
178
- 'post_title' => (string) $item->title,
179
- 'guid' => (string) $item->guid,
180
- );
181
-
182
- $dc = $item->children( 'http://purl.org/dc/elements/1.1/' );
183
- $post['post_author'] = (string) $dc->creator;
184
-
185
- $content = $item->children( 'http://purl.org/rss/1.0/modules/content/' );
186
- $excerpt = $item->children( $namespaces['excerpt'] );
187
- $post['post_content'] = (string) $content->encoded;
188
- $post['post_excerpt'] = (string) $excerpt->encoded;
189
-
190
- $wp = $item->children( $namespaces['wp'] );
191
- $post['post_id'] = (int) $wp->post_id;
192
- $post['post_date'] = (string) $wp->post_date;
193
- $post['post_date_gmt'] = (string) $wp->post_date_gmt;
194
- $post['comment_status'] = (string) $wp->comment_status;
195
- $post['ping_status'] = (string) $wp->ping_status;
196
- $post['post_name'] = (string) $wp->post_name;
197
- $post['status'] = (string) $wp->status;
198
- $post['post_parent'] = (int) $wp->post_parent;
199
- $post['menu_order'] = (int) $wp->menu_order;
200
- $post['post_type'] = (string) $wp->post_type;
201
- $post['post_password'] = (string) $wp->post_password;
202
- $post['is_sticky'] = (int) $wp->is_sticky;
203
-
204
- if ( isset($wp->attachment_url) )
205
- $post['attachment_url'] = (string) $wp->attachment_url;
206
-
207
- foreach ( $item->category as $c ) {
208
- $att = $c->attributes();
209
- if ( isset( $att['nicename'] ) )
210
- $post['terms'][] = array(
211
- 'name' => (string) $c,
212
- 'slug' => (string) $att['nicename'],
213
- 'domain' => (string) $att['domain']
214
- );
215
- }
216
-
217
- foreach ( $wp->postmeta as $meta ) {
218
- $post['postmeta'][] = array(
219
- 'key' => (string) $meta->meta_key,
220
- 'value' => (string) $meta->meta_value
221
- );
222
- }
223
-
224
- foreach ( $wp->comment as $comment ) {
225
- $meta = array();
226
- if ( isset( $comment->commentmeta ) ) {
227
- foreach ( $comment->commentmeta as $m ) {
228
- $meta[] = array(
229
- 'key' => (string) $m->meta_key,
230
- 'value' => (string) $m->meta_value
231
- );
232
- }
233
- }
234
-
235
- $post['comments'][] = array(
236
- 'comment_id' => (int) $comment->comment_id,
237
- 'comment_author' => (string) $comment->comment_author,
238
- 'comment_author_email' => (string) $comment->comment_author_email,
239
- 'comment_author_IP' => (string) $comment->comment_author_IP,
240
- 'comment_author_url' => (string) $comment->comment_author_url,
241
- 'comment_date' => (string) $comment->comment_date,
242
- 'comment_date_gmt' => (string) $comment->comment_date_gmt,
243
- 'comment_content' => (string) $comment->comment_content,
244
- 'comment_approved' => (string) $comment->comment_approved,
245
- 'comment_type' => (string) $comment->comment_type,
246
- 'comment_parent' => (string) $comment->comment_parent,
247
- 'comment_user_id' => (int) $comment->comment_user_id,
248
- 'commentmeta' => $meta,
249
- );
250
- }
251
-
252
- $posts[] = $post;
253
- }
254
-
255
- return array(
256
- 'authors' => $authors,
257
- 'posts' => $posts,
258
- 'categories' => $categories,
259
- 'tags' => $tags,
260
- 'terms' => $terms,
261
- 'base_url' => $base_url,
262
- 'version' => $wxr_version
263
- );
264
- }
265
- }
266
-
267
- /**
268
- * WXR Parser that makes use of the XML Parser PHP extension.
269
- */
270
- class WXR_Parser_XML {
271
- var $wp_tags = array(
272
- 'wp:post_id', 'wp:post_date', 'wp:post_date_gmt', 'wp:comment_status', 'wp:ping_status', 'wp:attachment_url',
273
- 'wp:status', 'wp:post_name', 'wp:post_parent', 'wp:menu_order', 'wp:post_type', 'wp:post_password',
274
- 'wp:is_sticky', 'wp:term_id', 'wp:category_nicename', 'wp:category_parent', 'wp:cat_name', 'wp:category_description',
275
- 'wp:tag_slug', 'wp:tag_name', 'wp:tag_description', 'wp:term_taxonomy', 'wp:term_parent',
276
- 'wp:term_name', 'wp:term_description', 'wp:author_id', 'wp:author_login', 'wp:author_email', 'wp:author_display_name',
277
- 'wp:author_first_name', 'wp:author_last_name',
278
- );
279
- var $wp_sub_tags = array(
280
- 'wp:comment_id', 'wp:comment_author', 'wp:comment_author_email', 'wp:comment_author_url',
281
- 'wp:comment_author_IP', 'wp:comment_date', 'wp:comment_date_gmt', 'wp:comment_content',
282
- 'wp:comment_approved', 'wp:comment_type', 'wp:comment_parent', 'wp:comment_user_id',
283
- );
284
-
285
- function parse( $file ) {
286
- $this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false;
287
- $this->authors = $this->posts = $this->term = $this->category = $this->tag = array();
288
-
289
- $xml = xml_parser_create( 'UTF-8' );
290
- xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 );
291
- xml_parser_set_option( $xml, XML_OPTION_CASE_FOLDING, 0 );
292
- xml_set_object( $xml, $this );
293
- xml_set_character_data_handler( $xml, 'cdata' );
294
- xml_set_element_handler( $xml, 'tag_open', 'tag_close' );
295
-
296
- if ( ! xml_parse( $xml, file_get_contents( $file ), true ) ) {
297
- $current_line = xml_get_current_line_number( $xml );
298
- $current_column = xml_get_current_column_number( $xml );
299
- $error_code = xml_get_error_code( $xml );
300
- $error_string = xml_error_string( $error_code );
301
- return new WP_Error( 'XML_parse_error', 'There was an error when reading this WXR file', array( $current_line, $current_column, $error_string ) );
302
- }
303
- xml_parser_free( $xml );
304
-
305
- if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) )
306
- return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
307
-
308
- return array(
309
- 'authors' => $this->authors,
310
- 'posts' => $this->posts,
311
- 'categories' => $this->category,
312
- 'tags' => $this->tag,
313
- 'terms' => $this->term,
314
- 'base_url' => $this->base_url,
315
- 'version' => $this->wxr_version
316
- );
317
- }
318
-
319
- function tag_open( $parse, $tag, $attr ) {
320
- if ( in_array( $tag, $this->wp_tags ) ) {
321
- $this->in_tag = substr( $tag, 3 );
322
- return;
323
- }
324
-
325
- if ( in_array( $tag, $this->wp_sub_tags ) ) {
326
- $this->in_sub_tag = substr( $tag, 3 );
327
- return;
328
- }
329
-
330
- switch ( $tag ) {
331
- case 'category':
332
- if ( isset($attr['domain'], $attr['nicename']) ) {
333
- $this->sub_data['domain'] = $attr['domain'];
334
- $this->sub_data['slug'] = $attr['nicename'];
335
- }
336
- break;
337
- case 'item': $this->in_post = true;
338
- case 'title': if ( $this->in_post ) $this->in_tag = 'post_title'; break;
339
- case 'guid': $this->in_tag = 'guid'; break;
340
- case 'dc:creator': $this->in_tag = 'post_author'; break;
341
- case 'content:encoded': $this->in_tag = 'post_content'; break;
342
- case 'excerpt:encoded': $this->in_tag = 'post_excerpt'; break;
343
-
344
- case 'wp:term_slug': $this->in_tag = 'slug'; break;
345
- case 'wp:meta_key': $this->in_sub_tag = 'key'; break;
346
- case 'wp:meta_value': $this->in_sub_tag = 'value'; break;
347
- }
348
- }
349
-
350
- function cdata( $parser, $cdata ) {
351
- if ( ! trim( $cdata ) )
352
- return;
353
-
354
- if ( false !== $this->in_tag || false !== $this->in_sub_tag ) {
355
- $this->cdata .= $cdata;
356
- } else {
357
- $this->cdata .= trim( $cdata );
358
- }
359
- }
360
-
361
- function tag_close( $parser, $tag ) {
362
- switch ( $tag ) {
363
- case 'wp:comment':
364
- unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data
365
- if ( ! empty( $this->sub_data ) )
366
- $this->data['comments'][] = $this->sub_data;
367
- $this->sub_data = false;
368
- break;
369
- case 'wp:commentmeta':
370
- $this->sub_data['commentmeta'][] = array(
371
- 'key' => $this->sub_data['key'],
372
- 'value' => $this->sub_data['value']
373
- );
374
- break;
375
- case 'category':
376
- if ( ! empty( $this->sub_data ) ) {
377
- $this->sub_data['name'] = $this->cdata;
378
- $this->data['terms'][] = $this->sub_data;
379
- }
380
- $this->sub_data = false;
381
- break;
382
- case 'wp:postmeta':
383
- if ( ! empty( $this->sub_data ) )
384
- $this->data['postmeta'][] = $this->sub_data;
385
- $this->sub_data = false;
386
- break;
387
- case 'item':
388
- $this->posts[] = $this->data;
389
- $this->data = false;
390
- break;
391
- case 'wp:category':
392
- case 'wp:tag':
393
- case 'wp:term':
394
- $n = substr( $tag, 3 );
395
- array_push( $this->$n, $this->data );
396
- $this->data = false;
397
- break;
398
- case 'wp:author':
399
- if ( ! empty($this->data['author_login']) )
400
- $this->authors[$this->data['author_login']] = $this->data;
401
- $this->data = false;
402
- break;
403
- case 'wp:base_site_url':
404
- $this->base_url = $this->cdata;
405
- break;
406
- case 'wp:wxr_version':
407
- $this->wxr_version = $this->cdata;
408
- break;
409
-
410
- default:
411
- if ( $this->in_sub_tag ) {
412
- $this->sub_data[$this->in_sub_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
413
- $this->in_sub_tag = false;
414
- } else if ( $this->in_tag ) {
415
- $this->data[$this->in_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
416
- $this->in_tag = false;
417
- }
418
- }
419
-
420
- $this->cdata = false;
421
- }
422
- }
423
-
424
- /**
425
- * WXR Parser that uses regular expressions. Fallback for installs without an XML parser.
426
- */
427
- class WXR_Parser_Regex {
428
- var $authors = array();
429
- var $posts = array();
430
- var $categories = array();
431
- var $tags = array();
432
- var $terms = array();
433
- var $base_url = '';
434
-
435
- function __construct() {
436
- $this->has_gzip = is_callable( 'gzopen' );
437
- }
438
-
439
- function parse( $file ) {
440
- $wxr_version = $in_post = false;
441
-
442
- $fp = $this->fopen( $file, 'r' );
443
- if ( $fp ) {
444
- while ( ! $this->feof( $fp ) ) {
445
- $importline = rtrim( $this->fgets( $fp ) );
446
-
447
- if ( ! $wxr_version && preg_match( '|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version ) )
448
- $wxr_version = $version[1];
449
-
450
- if ( false !== strpos( $importline, '<wp:base_site_url>' ) ) {
451
- preg_match( '|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url );
452
- $this->base_url = $url[1];
453
- continue;
454
- }
455
- if ( false !== strpos( $importline, '<wp:category>' ) ) {
456
- preg_match( '|<wp:category>(.*?)</wp:category>|is', $importline, $category );
457
- $this->categories[] = $this->process_category( $category[1] );
458
- continue;
459
- }
460
- if ( false !== strpos( $importline, '<wp:tag>' ) ) {
461
- preg_match( '|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag );
462
- $this->tags[] = $this->process_tag( $tag[1] );
463
- continue;
464
- }
465
- if ( false !== strpos( $importline, '<wp:term>' ) ) {
466
- preg_match( '|<wp:term>(.*?)</wp:term>|is', $importline, $term );
467
- $this->terms[] = $this->process_term( $term[1] );
468
- continue;
469
- }
470
- if ( false !== strpos( $importline, '<wp:author>' ) ) {
471
- preg_match( '|<wp:author>(.*?)</wp:author>|is', $importline, $author );
472
- $a = $this->process_author( $author[1] );
473
- $this->authors[$a['author_login']] = $a;
474
- continue;
475
- }
476
- if ( false !== strpos( $importline, '<item>' ) ) {
477
- $post = '';
478
- $in_post = true;
479
- continue;
480
- }
481
- if ( false !== strpos( $importline, '</item>' ) ) {
482
- $in_post = false;
483
- $this->posts[] = $this->process_post( $post );
484
- continue;
485
- }
486
- if ( $in_post ) {
487
- $post .= $importline . "\n";
488
- }
489
- }
490
-
491
- $this->fclose($fp);
492
- }
493
-
494
- if ( ! $wxr_version )
495
- return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
496
-
497
- return array(
498
- 'authors' => $this->authors,
499
- 'posts' => $this->posts,
500
- 'categories' => $this->categories,
501
- 'tags' => $this->tags,
502
- 'terms' => $this->terms,
503
- 'base_url' => $this->base_url,
504
- 'version' => $wxr_version
505
- );
506
- }
507
-
508
- function get_tag( $string, $tag ) {
509
- preg_match( "|<$tag.*?>(.*?)</$tag>|is", $string, $return );
510
- if ( isset( $return[1] ) ) {
511
- if ( substr( $return[1], 0, 9 ) == '<![CDATA[' ) {
512
- if ( strpos( $return[1], ']]]]><![CDATA[>' ) !== false ) {
513
- preg_match_all( '|<!\[CDATA\[(.*?)\]\]>|s', $return[1], $matches );
514
- $return = '';
515
- foreach( $matches[1] as $match )
516
- $return .= $match;
517
- } else {
518
- $return = preg_replace( '|^<!\[CDATA\[(.*)\]\]>$|s', '$1', $return[1] );
519
- }
520
- } else {
521
- $return = $return[1];
522
- }
523
- } else {
524
- $return = '';
525
- }
526
- return $return;
527
- }
528
-
529
- function process_category( $c ) {
530
- return array(
531
- 'term_id' => $this->get_tag( $c, 'wp:term_id' ),
532
- 'cat_name' => $this->get_tag( $c, 'wp:cat_name' ),
533
- 'category_nicename' => $this->get_tag( $c, 'wp:category_nicename' ),
534
- 'category_parent' => $this->get_tag( $c, 'wp:category_parent' ),
535
- 'category_description' => $this->get_tag( $c, 'wp:category_description' ),
536
- );
537
- }
538
-
539
- function process_tag( $t ) {
540
- return array(
541
- 'term_id' => $this->get_tag( $t, 'wp:term_id' ),
542
- 'tag_name' => $this->get_tag( $t, 'wp:tag_name' ),
543
- 'tag_slug' => $this->get_tag( $t, 'wp:tag_slug' ),
544
- 'tag_description' => $this->get_tag( $t, 'wp:tag_description' ),
545
- );
546
- }
547
-
548
- function process_term( $t ) {
549
- return array(
550
- 'term_id' => $this->get_tag( $t, 'wp:term_id' ),
551
- 'term_taxonomy' => $this->get_tag( $t, 'wp:term_taxonomy' ),
552
- 'slug' => $this->get_tag( $t, 'wp:term_slug' ),
553
- 'term_parent' => $this->get_tag( $t, 'wp:term_parent' ),
554
- 'term_name' => $this->get_tag( $t, 'wp:term_name' ),
555
- 'term_description' => $this->get_tag( $t, 'wp:term_description' ),
556
- );
557
- }
558
-
559
- function process_author( $a ) {
560
- return array(
561
- 'author_id' => $this->get_tag( $a, 'wp:author_id' ),
562
- 'author_login' => $this->get_tag( $a, 'wp:author_login' ),
563
- 'author_email' => $this->get_tag( $a, 'wp:author_email' ),
564
- 'author_display_name' => $this->get_tag( $a, 'wp:author_display_name' ),
565
- 'author_first_name' => $this->get_tag( $a, 'wp:author_first_name' ),
566
- 'author_last_name' => $this->get_tag( $a, 'wp:author_last_name' ),
567
- );
568
- }
569
-
570
- function process_post( $post ) {
571
- $post_id = $this->get_tag( $post, 'wp:post_id' );
572
- $post_title = $this->get_tag( $post, 'title' );
573
- $post_date = $this->get_tag( $post, 'wp:post_date' );
574
- $post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' );
575
- $comment_status = $this->get_tag( $post, 'wp:comment_status' );
576
- $ping_status = $this->get_tag( $post, 'wp:ping_status' );
577
- $status = $this->get_tag( $post, 'wp:status' );
578
- $post_name = $this->get_tag( $post, 'wp:post_name' );
579
- $post_parent = $this->get_tag( $post, 'wp:post_parent' );
580
- $menu_order = $this->get_tag( $post, 'wp:menu_order' );
581
- $post_type = $this->get_tag( $post, 'wp:post_type' );
582
- $post_password = $this->get_tag( $post, 'wp:post_password' );
583
- $is_sticky = $this->get_tag( $post, 'wp:is_sticky' );
584
- $guid = $this->get_tag( $post, 'guid' );
585
- $post_author = $this->get_tag( $post, 'dc:creator' );
586
-
587
- $post_excerpt = $this->get_tag( $post, 'excerpt:encoded' );
588
- $post_excerpt = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt );
589
- $post_excerpt = str_replace( '<br>', '<br />', $post_excerpt );
590
- $post_excerpt = str_replace( '<hr>', '<hr />', $post_excerpt );
591
-
592
- $post_content = $this->get_tag( $post, 'content:encoded' );
593
- $post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content );
594
- $post_content = str_replace( '<br>', '<br />', $post_content );
595
- $post_content = str_replace( '<hr>', '<hr />', $post_content );
596
-
597
- $postdata = compact( 'post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt',
598
- 'post_title', 'status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent',
599
- 'menu_order', 'post_type', 'post_password', 'is_sticky'
600
- );
601
-
602
- $attachment_url = $this->get_tag( $post, 'wp:attachment_url' );
603
- if ( $attachment_url )
604
- $postdata['attachment_url'] = $attachment_url;
605
-
606
- preg_match_all( '|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER );
607
- foreach ( $terms as $t ) {
608
- $post_terms[] = array(
609
- 'slug' => $t[2],
610
- 'domain' => $t[1],
611
- 'name' => str_replace( array( '<![CDATA[', ']]>' ), '', $t[3] ),
612
- );
613
- }
614
- if ( ! empty( $post_terms ) ) $postdata['terms'] = $post_terms;
615
-
616
- preg_match_all( '|<wp:comment>(.+?)</wp:comment>|is', $post, $comments );
617
- $comments = $comments[1];
618
- if ( $comments ) {
619
- foreach ( $comments as $comment ) {
620
- preg_match_all( '|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta );
621
- $commentmeta = $commentmeta[1];
622
- $c_meta = array();
623
- foreach ( $commentmeta as $m ) {
624
- $c_meta[] = array(
625
- 'key' => $this->get_tag( $m, 'wp:meta_key' ),
626
- 'value' => $this->get_tag( $m, 'wp:meta_value' ),
627
- );
628
- }
629
-
630
- $post_comments[] = array(
631
- 'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ),
632
- 'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ),
633
- 'comment_author_email' => $this->get_tag( $comment, 'wp:comment_author_email' ),
634
- 'comment_author_IP' => $this->get_tag( $comment, 'wp:comment_author_IP' ),
635
- 'comment_author_url' => $this->get_tag( $comment, 'wp:comment_author_url' ),
636
- 'comment_date' => $this->get_tag( $comment, 'wp:comment_date' ),
637
- 'comment_date_gmt' => $this->get_tag( $comment, 'wp:comment_date_gmt' ),
638
- 'comment_content' => $this->get_tag( $comment, 'wp:comment_content' ),
639
- 'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ),
640
- 'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ),
641
- 'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ),
642
- 'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ),
643
- 'commentmeta' => $c_meta,
644
- );
645
- }
646
- }
647
- if ( ! empty( $post_comments ) ) $postdata['comments'] = $post_comments;
648
-
649
- preg_match_all( '|<wp:postmeta>(.+?)</wp:postmeta>|is', $post, $postmeta );
650
- $postmeta = $postmeta[1];
651
- if ( $postmeta ) {
652
- foreach ( $postmeta as $p ) {
653
- $post_postmeta[] = array(
654
- 'key' => $this->get_tag( $p, 'wp:meta_key' ),
655
- 'value' => $this->get_tag( $p, 'wp:meta_value' ),
656
- );
657
- }
658
- }
659
- if ( ! empty( $post_postmeta ) ) $postdata['postmeta'] = $post_postmeta;
660
-
661
- return $postdata;
662
- }
663
-
664
- function _normalize_tag( $matches ) {
665
- return '<' . strtolower( $matches[1] );
666
- }
667
-
668
- function fopen( $filename, $mode = 'r' ) {
669
- if ( $this->has_gzip )
670
- return gzopen( $filename, $mode );
671
- return fopen( $filename, $mode );
672
- }
673
-
674
- function feof( $fp ) {
675
- if ( $this->has_gzip )
676
- return gzeof( $fp );
677
- return feof( $fp );
678
- }
679
-
680
- function fgets( $fp, $len = 8192 ) {
681
- if ( $this->has_gzip )
682
- return gzgets( $fp, $len );
683
- return fgets( $fp, $len );
684
- }
685
-
686
- function fclose( $fp ) {
687
- if ( $this->has_gzip )
688
- return gzclose( $fp );
689
- return fclose( $fp );
690
- }
691
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class/class-settings-importer.php DELETED
@@ -1,56 +0,0 @@
1
- <?php
2
- /**
3
- * Class for the settings importer.
4
- */
5
-
6
- class ODI_Settings_Importer {
7
-
8
- /**
9
- * Process import file - this parses the settings data and returns it.
10
- *
11
- * @param string $file path to json file.
12
- */
13
- public function process_import_file( $file ) {
14
-
15
- // Get file contents.
16
- $data = ODI_Helpers::get_remote( $file );
17
-
18
- // Return from this function if there was an error.
19
- if ( is_wp_error( $data ) ) {
20
- return $data;
21
- }
22
-
23
- // Decode file contents.
24
- $data = json_decode( $data, true );
25
-
26
- // Import the data
27
- return $this->import_data( $data );
28
-
29
- }
30
-
31
- /**
32
- * Import JSON data
33
- *
34
- * @return array $results
35
- */
36
- private function import_data( $file ) {
37
-
38
- // Import the file
39
- if ( ! empty( $file ) ) {
40
-
41
- if ( '0' == json_last_error() ) {
42
-
43
- // Loop through mods and add them
44
- foreach ( $file as $mod => $value ) {
45
- set_theme_mod( $mod, $value );
46
- }
47
-
48
- }
49
-
50
- }
51
-
52
- // Return file
53
- return $file;
54
-
55
- }
56
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class/class-widget-importer.php DELETED
@@ -1,235 +0,0 @@
1
- <?php
2
- /**
3
- * Class for the widget importer.
4
- *
5
- * Code is mostly from the Widget Importer & Exporter plugin.
6
- *
7
- * @see https://wordpress.org/plugins/widget-importer-exporter/
8
- */
9
-
10
- class ODI_Widget_Importer {
11
-
12
- /**
13
- * Process import file - this parses the widget data and returns it.
14
- *
15
- * @param string $file path to json file.
16
- * @global string $widget_import_results
17
- */
18
- public function process_import_file( $file ) {
19
-
20
- // Get file contents.
21
- $data = ODI_Helpers::get_remote( $file );
22
-
23
- // Return from this function if there was an error.
24
- if ( is_wp_error( $data ) ) {
25
- return $data;
26
- }
27
-
28
- // Decode file contents.
29
- $data = json_decode( $data );
30
-
31
- // Import the widget data
32
- return $this->import_data( $data );
33
-
34
- }
35
-
36
- /**
37
- * Import widget JSON data
38
- *
39
- * @global array $wp_registered_sidebars
40
- * @param object $data JSON widget data.
41
- * @return array $results
42
- */
43
- private function import_data( $data ) {
44
-
45
- global $wp_registered_sidebars;
46
-
47
- // Have valid data? If no data or could not decode.
48
- if ( empty( $data ) || ! is_object( $data ) ) {
49
- return;
50
- }
51
-
52
- // Get all available widgets site supports.
53
- $available_widgets = $this->available_widgets();
54
-
55
- // Get all existing widget instances.
56
- $widget_instances = array();
57
-
58
- foreach ( $available_widgets as $widget_data ) {
59
- $widget_instances[ $widget_data['id_base'] ] = get_option( 'widget_' . $widget_data['id_base'] );
60
- }
61
-
62
- // Begin results.
63
- $results = array();
64
-
65
- // Loop import data's sidebars.
66
- foreach ( $data as $sidebar_id => $widgets ) {
67
-
68
- // Skip inactive widgets (should not be in export file).
69
- if ( 'wp_inactive_widgets' == $sidebar_id ) {
70
- continue;
71
- }
72
-
73
- // Check if sidebar is available on this site. Otherwise add widgets to inactive, and say so.
74
- if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) {
75
- $sidebar_available = true;
76
- $use_sidebar_id = $sidebar_id;
77
- $sidebar_message_type = 'success';
78
- $sidebar_message = '';
79
- }
80
- else {
81
- $sidebar_available = false;
82
- $use_sidebar_id = 'wp_inactive_widgets'; // Add to inactive if sidebar does not exist in theme.
83
- $sidebar_message_type = 'error';
84
- $sidebar_message = esc_html__( 'Sidebar does not exist in theme (moving widget to Inactive)', 'ocean-demo-import' );
85
- }
86
-
87
- // Result for sidebar.
88
- $results[ $sidebar_id ]['name'] = ! empty( $wp_registered_sidebars[ $sidebar_id ]['name'] ) ? $wp_registered_sidebars[ $sidebar_id ]['name'] : $sidebar_id; // Sidebar name if theme supports it; otherwise ID.
89
- $results[ $sidebar_id ]['message_type'] = $sidebar_message_type;
90
- $results[ $sidebar_id ]['message'] = $sidebar_message;
91
- $results[ $sidebar_id ]['widgets'] = array();
92
-
93
- // Loop widgets.
94
- foreach ( $widgets as $widget_instance_id => $widget ) {
95
-
96
- $fail = false;
97
-
98
- // Get id_base (remove -# from end) and instance ID number.
99
- $id_base = preg_replace( '/-[0-9]+$/', '', $widget_instance_id );
100
- $instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id );
101
-
102
- // Does site support this widget?
103
- if ( ! $fail && ! isset( $available_widgets[ $id_base ] ) ) {
104
- $fail = true;
105
- $widget_message_type = 'error';
106
- $widget_message = esc_html__( 'Site does not support widget', 'ocean-demo-import' ); // Explain why widget not imported.
107
- }
108
-
109
- // Convert multidimensional objects to multidimensional arrays.
110
- $widget = json_decode( json_encode( $widget ), true );
111
-
112
- // Does widget with identical settings already exist in same sidebar?
113
- if ( ! $fail && isset( $widget_instances[ $id_base ] ) ) {
114
-
115
- // Get existing widgets in this sidebar.
116
- $sidebars_widgets = get_option( 'sidebars_widgets' );
117
- $sidebar_widgets = isset( $sidebars_widgets[ $use_sidebar_id ] ) ? $sidebars_widgets[ $use_sidebar_id ] : array(); // Check Inactive if that's where will go.
118
-
119
- // Loop widgets with ID base.
120
- $single_widget_instances = ! empty( $widget_instances[ $id_base ] ) ? $widget_instances[ $id_base ] : array();
121
- foreach ( $single_widget_instances as $check_id => $check_widget ) {
122
-
123
- // Is widget in same sidebar and has identical settings?
124
- if ( in_array( "$id_base-$check_id", $sidebar_widgets ) && (array) $widget == $check_widget ) {
125
- $fail = true;
126
- $widget_message_type = 'warning';
127
- $widget_message = esc_html__( 'Widget already exists', 'ocean-demo-import' ); // Explain why widget not imported.
128
-
129
- break;
130
- }
131
- }
132
- }
133
-
134
- // No failure.
135
- if ( ! $fail ) {
136
-
137
- // Add widget instance.
138
- $single_widget_instances = get_option( 'widget_' . $id_base ); // All instances for that widget ID base, get fresh every time.
139
- $single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array( '_multiwidget' => 1 ); // Start fresh if have to.
140
- $single_widget_instances[] = $widget; // Add it.
141
-
142
- // Get the key it was given.
143
- end( $single_widget_instances );
144
- $new_instance_id_number = key( $single_widget_instances );
145
-
146
- // If key is 0, make it 1.
147
- // When 0, an issue can occur where adding a widget causes data from other widget to load, and the widget doesn't stick (reload wipes it).
148
- if ( '0' === strval( $new_instance_id_number ) ) {
149
- $new_instance_id_number = 1;
150
- $single_widget_instances[ $new_instance_id_number ] = $single_widget_instances[0];
151
- unset( $single_widget_instances[0] );
152
- }
153
-
154
- // Move _multiwidget to end of array for uniformity.
155
- if ( isset( $single_widget_instances['_multiwidget'] ) ) {
156
- $multiwidget = $single_widget_instances['_multiwidget'];
157
- unset( $single_widget_instances['_multiwidget'] );
158
- $single_widget_instances['_multiwidget'] = $multiwidget;
159
- }
160
-
161
- // Update option with new widget.
162
- update_option( 'widget_' . $id_base, $single_widget_instances );
163
-
164
- // Assign widget instance to sidebar.
165
- $sidebars_widgets = get_option( 'sidebars_widgets' ); // Which sidebars have which widgets, get fresh every time.
166
- $new_instance_id = $id_base . '-' . $new_instance_id_number; // Use ID number from new widget instance.
167
- $sidebars_widgets[ $use_sidebar_id ][] = $new_instance_id; // Add new instance to sidebar.
168
- update_option( 'sidebars_widgets', $sidebars_widgets ); // Save the amended data.
169
-
170
- // After widget import action.
171
- $after_widget_import = array(
172
- 'sidebar' => $use_sidebar_id,
173
- 'sidebar_old' => $sidebar_id,
174
- 'widget' => $widget,
175
- 'widget_type' => $id_base,
176
- 'widget_id' => $new_instance_id,
177
- 'widget_id_old' => $widget_instance_id,
178
- 'widget_id_num' => $new_instance_id_number,
179
- 'widget_id_num_old' => $instance_id_number,
180
- );
181
-
182
- // Success message.
183
- if ( $sidebar_available ) {
184
- $widget_message_type = 'success';
185
- $widget_message = esc_html__( 'Imported', 'ocean-demo-import' );
186
- }
187
- else {
188
- $widget_message_type = 'warning';
189
- $widget_message = esc_html__( 'Imported to Inactive', 'ocean-demo-import' );
190
- }
191
- }
192
-
193
- // Result for widget instance.
194
- $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['name'] = isset( $available_widgets[ $id_base ]['name'] ) ? $available_widgets[ $id_base ]['name'] : $id_base; // Widget name or ID if name not available (not supported by site).
195
- $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['title'] = ! empty( $widget['title'] ) ? $widget['title'] : esc_html__( 'No Title', 'ocean-demo-import' ); // Show "No Title" if widget instance is untitled.
196
- $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message_type'] = $widget_message_type;
197
- $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message'] = $widget_message;
198
-
199
- }
200
- }
201
-
202
- // Return results.
203
- return $results;
204
- }
205
-
206
- /**
207
- * Available widgets.
208
- *
209
- * Gather site's widgets into array with ID base, name, etc.
210
- *
211
- * @global array $wp_registered_widget_controls
212
- * @return array $available_widgets, Widget information
213
- */
214
- private function available_widgets() {
215
-
216
- global $wp_registered_widget_controls;
217
-
218
- $widget_controls = $wp_registered_widget_controls;
219
-
220
- $available_widgets = array();
221
-
222
- foreach ( $widget_controls as $widget ) {
223
-
224
- if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[$widget['id_base']] ) ) { // no dupes
225
-
226
- $available_widgets[$widget['id_base']]['id_base'] = $widget['id_base'];
227
- $available_widgets[$widget['id_base']]['name'] = $widget['name'];
228
-
229
- }
230
-
231
- }
232
-
233
- return $available_widgets;
234
- }
235
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class/class-wordpress-importer.php DELETED
@@ -1,1221 +0,0 @@
1
- <?php
2
- /*
3
- Plugin Name: WordPress Importer
4
- Plugin URI: http://wordpress.org/extend/plugins/wordpress-importer/
5
- Description: Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
6
- Author: wordpressdotorg
7
- Author URI: http://wordpress.org/
8
- Version: 0.6.3
9
- Text Domain: wordpress-importer
10
- License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
- */
12
-
13
- if ( ! defined( 'WP_LOAD_IMPORTERS' ) )
14
- return;
15
-
16
- /** Display verbose errors */
17
- define( 'IMPORT_DEBUG', false );
18
-
19
- // Load Importer API
20
- require_once ABSPATH . 'wp-admin/includes/import.php';
21
-
22
- if ( ! class_exists( 'WP_Importer' ) ) {
23
- $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
24
- if ( file_exists( $class_wp_importer ) )
25
- require $class_wp_importer;
26
- }
27
-
28
- // include WXR file parsers
29
- require ODI_PATH . '/includes/class/class-parsers.php';
30
-
31
- /**
32
- * WordPress Importer class for managing the import process of a WXR file
33
- *
34
- * @package WordPress
35
- * @subpackage Importer
36
- */
37
- if ( class_exists( 'WP_Importer' ) ) {
38
- class WP_Import extends WP_Importer {
39
- var $max_wxr_version = 1.2; // max. supported WXR version
40
-
41
- var $id; // WXR attachment ID
42
-
43
- // information to import from WXR file
44
- var $version;
45
- var $authors = array();
46
- var $posts = array();
47
- var $terms = array();
48
- var $categories = array();
49
- var $tags = array();
50
- var $base_url = '';
51
-
52
- // mappings from old information to new
53
- var $processed_authors = array();
54
- var $author_mapping = array();
55
- var $processed_terms = array();
56
- var $processed_posts = array();
57
- var $post_orphans = array();
58
- var $processed_menu_items = array();
59
- var $menu_item_orphans = array();
60
- var $missing_menu_items = array();
61
-
62
- var $fetch_attachments = false;
63
- var $url_remap = array();
64
- var $featured_images = array();
65
-
66
- /**
67
- * Registered callback function for the WordPress Importer
68
- *
69
- * Manages the three separate stages of the WXR import process
70
- */
71
- function dispatch() {
72
- $this->header();
73
-
74
- $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
75
- switch ( $step ) {
76
- case 0:
77
- $this->greet();
78
- break;
79
- case 1:
80
- check_admin_referer( 'import-upload' );
81
- if ( $this->handle_upload() )
82
- $this->import_options();
83
- break;
84
- case 2:
85
- check_admin_referer( 'import-wordpress' );
86
- $this->fetch_attachments = ( ! empty( $_POST['fetch_attachments'] ) && $this->allow_fetch_attachments() );
87
- $this->id = (int) $_POST['import_id'];
88
- $file = get_attached_file( $this->id );
89
- set_time_limit(0);
90
- $this->import( $file );
91
- break;
92
- }
93
-
94
- $this->footer();
95
- }
96
-
97
- /**
98
- * The main controller for the actual import stage.
99
- *
100
- * @param string $file Path to the WXR file for importing
101
- */
102
- function import( $file ) {
103
- add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
104
- add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
105
-
106
- $this->import_start( $file );
107
-
108
- $this->get_author_mapping();
109
-
110
- wp_suspend_cache_invalidation( true );
111
- $this->process_categories();
112
- $this->process_tags();
113
- $this->process_terms();
114
- $this->process_posts();
115
- wp_suspend_cache_invalidation( false );
116
-
117
- // update incorrect/missing information in the DB
118
- $this->backfill_parents();
119
- $this->backfill_attachment_urls();
120
- $this->remap_featured_images();
121
-
122
- $this->import_end();
123
- }
124
-
125
- /**
126
- * Parses the WXR file and prepares us for the task of processing parsed data
127
- *
128
- * @param string $file Path to the WXR file for importing
129
- */
130
- function import_start( $file ) {
131
- if ( ! is_file($file) ) {
132
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
133
- echo __( 'The file does not exist, please try again.', 'wordpress-importer' ) . '</p>';
134
- $this->footer();
135
- die();
136
- }
137
-
138
- $import_data = $this->parse( $file );
139
-
140
- if ( is_wp_error( $import_data ) ) {
141
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
142
- echo esc_html( $import_data->get_error_message() ) . '</p>';
143
- $this->footer();
144
- die();
145
- }
146
-
147
- $this->version = $import_data['version'];
148
- $this->get_authors_from_import( $import_data );
149
- $this->posts = $import_data['posts'];
150
- $this->terms = $import_data['terms'];
151
- $this->categories = $import_data['categories'];
152
- $this->tags = $import_data['tags'];
153
- $this->base_url = esc_url( $import_data['base_url'] );
154
-
155
- wp_defer_term_counting( true );
156
- wp_defer_comment_counting( true );
157
-
158
- do_action( 'import_start' );
159
- }
160
-
161
- /**
162
- * Performs post-import cleanup of files and the cache
163
- */
164
- function import_end() {
165
- wp_import_cleanup( $this->id );
166
-
167
- wp_cache_flush();
168
- foreach ( get_taxonomies() as $tax ) {
169
- delete_option( "{$tax}_children" );
170
- _get_term_hierarchy( $tax );
171
- }
172
-
173
- wp_defer_term_counting( false );
174
- wp_defer_comment_counting( false );
175
-
176
- echo '<p>' . __( 'All done.', 'wordpress-importer' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!', 'wordpress-importer' ) . '</a>' . '</p>';
177
- echo '<p>' . __( 'Remember to update the passwords and roles of imported users.', 'wordpress-importer' ) . '</p>';
178
-
179
- do_action( 'import_end' );
180
- }
181
-
182
- /**
183
- * Handles the WXR upload and initial parsing of the file to prepare for
184
- * displaying author import options
185
- *
186
- * @return bool False if error uploading or invalid file, true otherwise
187
- */
188
- function handle_upload() {
189
- $file = wp_import_handle_upload();
190
-
191
- if ( isset( $file['error'] ) ) {
192
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
193
- echo esc_html( $file['error'] ) . '</p>';
194
- return false;
195
- } else if ( ! file_exists( $file['file'] ) ) {
196
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
197
- printf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'wordpress-importer' ), esc_html( $file['file'] ) );
198
- echo '</p>';
199
- return false;
200
- }
201
-
202
- $this->id = (int) $file['id'];
203
- $import_data = $this->parse( $file['file'] );
204
- if ( is_wp_error( $import_data ) ) {
205
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
206
- echo esc_html( $import_data->get_error_message() ) . '</p>';
207
- return false;
208
- }
209
-
210
- $this->version = $import_data['version'];
211
- if ( $this->version > $this->max_wxr_version ) {
212
- echo '<div class="error"><p><strong>';
213
- printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'wordpress-importer' ), esc_html($import_data['version']) );
214
- echo '</strong></p></div>';
215
- }
216
-
217
- $this->get_authors_from_import( $import_data );
218
-
219
- return true;
220
- }
221
-
222
- /**
223
- * Retrieve authors from parsed WXR data
224
- *
225
- * Uses the provided author information from WXR 1.1 files
226
- * or extracts info from each post for WXR 1.0 files
227
- *
228
- * @param array $import_data Data returned by a WXR parser
229
- */
230
- function get_authors_from_import( $import_data ) {
231
- if ( ! empty( $import_data['authors'] ) ) {
232
- $this->authors = $import_data['authors'];
233
- // no author information, grab it from the posts
234
- } else {
235
- foreach ( $import_data['posts'] as $post ) {
236
- $login = sanitize_user( $post['post_author'], true );
237
- if ( empty( $login ) ) {
238
- printf( __( 'Failed to import author %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html( $post['post_author'] ) );
239
- echo '<br />';
240
- continue;
241
- }
242
-
243
- if ( ! isset($this->authors[$login]) )
244
- $this->authors[$login] = array(
245
- 'author_login' => $login,
246
- 'author_display_name' => $post['post_author']
247
- );
248
- }
249
- }
250
- }
251
-
252
- /**
253
- * Display pre-import options, author importing/mapping and option to
254
- * fetch attachments
255
- */
256
- function import_options() {
257
- $j = 0;
258
- ?>
259
- <form action="<?php echo admin_url( 'admin.php?import=wordpress&amp;step=2' ); ?>" method="post">
260
- <?php wp_nonce_field( 'import-wordpress' ); ?>
261
- <input type="hidden" name="import_id" value="<?php echo $this->id; ?>" />
262
-
263
- <?php if ( ! empty( $this->authors ) ) : ?>
264
- <h3><?php _e( 'Assign Authors', 'wordpress-importer' ); ?></h3>
265
- <p><?php _e( 'To make it easier for you to edit and save the imported content, you may want to reassign the author of the imported item to an existing user of this site. For example, you may want to import all the entries as <code>admin</code>s entries.', 'wordpress-importer' ); ?></p>
266
- <?php if ( $this->allow_create_users() ) : ?>
267
- <p><?php printf( __( 'If a new user is created by WordPress, a new password will be randomly generated and the new user&#8217;s role will be set as %s. Manually changing the new user&#8217;s details will be necessary.', 'wordpress-importer' ), esc_html( get_option('default_role') ) ); ?></p>
268
- <?php endif; ?>
269
- <ol id="authors">
270
- <?php foreach ( $this->authors as $author ) : ?>
271
- <li><?php $this->author_select( $j++, $author ); ?></li>
272
- <?php endforeach; ?>
273
- </ol>
274
- <?php endif; ?>
275
-
276
- <?php if ( $this->allow_fetch_attachments() ) : ?>
277
- <h3><?php _e( 'Import Attachments', 'wordpress-importer' ); ?></h3>
278
- <p>
279
- <input type="checkbox" value="1" name="fetch_attachments" id="import-attachments" />
280
- <label for="import-attachments"><?php _e( 'Download and import file attachments', 'wordpress-importer' ); ?></label>
281
- </p>
282
- <?php endif; ?>
283
-
284
- <p class="submit"><input type="submit" class="button" value="<?php esc_attr_e( 'Submit', 'wordpress-importer' ); ?>" /></p>
285
- </form>
286
- <?php
287
- }
288
-
289
- /**
290
- * Display import options for an individual author. That is, either create
291
- * a new user based on import info or map to an existing user
292
- *
293
- * @param int $n Index for each author in the form
294
- * @param array $author Author information, e.g. login, display name, email
295
- */
296
- function author_select( $n, $author ) {
297
- _e( 'Import author:', 'wordpress-importer' );
298
- echo ' <strong>' . esc_html( $author['author_display_name'] );
299
- if ( $this->version != '1.0' ) echo ' (' . esc_html( $author['author_login'] ) . ')';
300
- echo '</strong><br />';
301
-
302
- if ( $this->version != '1.0' )
303
- echo '<div style="margin-left:18px">';
304
-
305
- $create_users = $this->allow_create_users();
306
- if ( $create_users ) {
307
- if ( $this->version != '1.0' ) {
308
- _e( 'or create new user with login name:', 'wordpress-importer' );
309
- $value = '';
310
- } else {
311
- _e( 'as a new user:', 'wordpress-importer' );
312
- $value = esc_attr( sanitize_user( $author['author_login'], true ) );
313
- }
314
-
315
- echo ' <input type="text" name="user_new['.$n.']" value="'. $value .'" /><br />';
316
- }
317
-
318
- if ( ! $create_users && $this->version == '1.0' )
319
- _e( 'assign posts to an existing user:', 'wordpress-importer' );
320
- else
321
- _e( 'or assign posts to an existing user:', 'wordpress-importer' );
322
- wp_dropdown_users( array( 'name' => "user_map[$n]", 'multi' => true, 'show_option_all' => __( '- Select -', 'wordpress-importer' ) ) );
323
- echo '<input type="hidden" name="imported_authors['.$n.']" value="' . esc_attr( $author['author_login'] ) . '" />';
324
-
325
- if ( $this->version != '1.0' )
326
- echo '</div>';
327
- }
328
-
329
- /**
330
- * Map old author logins to local user IDs based on decisions made
331
- * in import options form. Can map to an existing user, create a new user
332
- * or falls back to the current user in case of error with either of the previous
333
- */
334
- function get_author_mapping() {
335
- if ( ! isset( $_POST['imported_authors'] ) )
336
- return;
337
-
338
- $create_users = $this->allow_create_users();
339
-
340
- foreach ( (array) $_POST['imported_authors'] as $i => $old_login ) {
341
- // Multisite adds strtolower to sanitize_user. Need to sanitize here to stop breakage in process_posts.
342
- $santized_old_login = sanitize_user( $old_login, true );
343
- $old_id = isset( $this->authors[$old_login]['author_id'] ) ? intval($this->authors[$old_login]['author_id']) : false;
344
-
345
- if ( ! empty( $_POST['user_map'][$i] ) ) {
346
- $user = get_userdata( intval($_POST['user_map'][$i]) );
347
- if ( isset( $user->ID ) ) {
348
- if ( $old_id )
349
- $this->processed_authors[$old_id] = $user->ID;
350
- $this->author_mapping[$santized_old_login] = $user->ID;
351
- }
352
- } else if ( $create_users ) {
353
- if ( ! empty($_POST['user_new'][$i]) ) {
354
- $user_id = wp_create_user( $_POST['user_new'][$i], wp_generate_password() );
355
- } else if ( $this->version != '1.0' ) {
356
- $user_data = array(
357
- 'user_login' => $old_login,
358
- 'user_pass' => wp_generate_password(),
359
- 'user_email' => isset( $this->authors[$old_login]['author_email'] ) ? $this->authors[$old_login]['author_email'] : '',
360
- 'display_name' => $this->authors[$old_login]['author_display_name'],
361
- 'first_name' => isset( $this->authors[$old_login]['author_first_name'] ) ? $this->authors[$old_login]['author_first_name'] : '',
362
- 'last_name' => isset( $this->authors[$old_login]['author_last_name'] ) ? $this->authors[$old_login]['author_last_name'] : '',
363
- );
364
- $user_id = wp_insert_user( $user_data );
365
- }
366
-
367
- if ( ! is_wp_error( $user_id ) ) {
368
- if ( $old_id )
369
- $this->processed_authors[$old_id] = $user_id;
370
- $this->author_mapping[$santized_old_login] = $user_id;
371
- } else {
372
- printf( __( 'Failed to create new user for %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html($this->authors[$old_login]['author_display_name']) );
373
- if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
374
- echo ' ' . $user_id->get_error_message();
375
- echo '<br />';
376
- }
377
- }
378
-
379
- // failsafe: if the user_id was invalid, default to the current user
380
- if ( ! isset( $this->author_mapping[$santized_old_login] ) ) {
381
- if ( $old_id )
382
- $this->processed_authors[$old_id] = (int) get_current_user_id();
383
- $this->author_mapping[$santized_old_login] = (int) get_current_user_id();
384
- }
385
- }
386
- }
387
-
388
- /**
389
- * Create new categories based on import information
390
- *
391
- * Doesn't create a new category if its slug already exists
392
- */
393
- function process_categories() {
394
- $this->categories = apply_filters( 'wp_import_categories', $this->categories );
395
-
396
- if ( empty( $this->categories ) )
397
- return;
398
-
399
- foreach ( $this->categories as $cat ) {
400
- // if the category already exists leave it alone
401
- $term_id = term_exists( $cat['category_nicename'], 'category' );
402
- if ( $term_id ) {
403
- if ( is_array($term_id) ) $term_id = $term_id['term_id'];
404
- if ( isset($cat['term_id']) )
405
- $this->processed_terms[intval($cat['term_id'])] = (int) $term_id;
406
- continue;
407
- }
408
-
409
- $category_parent = empty( $cat['category_parent'] ) ? 0 : category_exists( $cat['category_parent'] );
410
- $category_description = isset( $cat['category_description'] ) ? $cat['category_description'] : '';
411
- $catarr = array(
412
- 'category_nicename' => $cat['category_nicename'],
413
- 'category_parent' => $category_parent,
414
- 'cat_name' => $cat['cat_name'],
415
- 'category_description' => $category_description
416
- );
417
- $catarr = wp_slash( $catarr );
418
-
419
- $id = wp_insert_category( $catarr );
420
- if ( ! is_wp_error( $id ) ) {
421
- if ( isset($cat['term_id']) )
422
- $this->processed_terms[intval($cat['term_id'])] = $id;
423
- } else {
424
- printf( __( 'Failed to import category %s', 'wordpress-importer' ), esc_html($cat['category_nicename']) );
425
- if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
426
- echo ': ' . $id->get_error_message();
427
- echo '<br />';
428
- continue;
429
- }
430
-
431
- $this->process_termmeta( $cat, $id['term_id'] );
432
- }
433
-
434
- unset( $this->categories );
435
- }
436
-
437
- /**
438
- * Create new post tags based on import information
439
- *
440
- * Doesn't create a tag if its slug already exists
441
- */
442
- function process_tags() {
443
- $this->tags = apply_filters( 'wp_import_tags', $this->tags );
444
-
445
- if ( empty( $this->tags ) )
446
- return;
447
-
448
- foreach ( $this->tags as $tag ) {
449
- // if the tag already exists leave it alone
450
- $term_id = term_exists( $tag['tag_slug'], 'post_tag' );
451
- if ( $term_id ) {
452
- if ( is_array($term_id) ) $term_id = $term_id['term_id'];
453
- if ( isset($tag['term_id']) )
454
- $this->processed_terms[intval($tag['term_id'])] = (int) $term_id;
455
- continue;
456
- }
457
-
458
- $tag = wp_slash( $tag );
459
- $tag_desc = isset( $tag['tag_description'] ) ? $tag['tag_description'] : '';
460
- $tagarr = array( 'slug' => $tag['tag_slug'], 'description' => $tag_desc );
461
-
462
- $id = wp_insert_term( $tag['tag_name'], 'post_tag', $tagarr );
463
- if ( ! is_wp_error( $id ) ) {
464
- if ( isset($tag['term_id']) )
465
- $this->processed_terms[intval($tag['term_id'])] = $id['term_id'];
466
- } else {
467
- printf( __( 'Failed to import post tag %s', 'wordpress-importer' ), esc_html($tag['tag_name']) );
468
- if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
469
- echo ': ' . $id->get_error_message();
470
- echo '<br />';
471
- continue;
472
- }
473
-
474
- $this->process_termmeta( $tag, $id['term_id'] );
475
- }
476
-
477
- unset( $this->tags );
478
- }
479
-
480
- /**
481
- * Create new terms based on import information
482
- *
483
- * Doesn't create a term its slug already exists
484
- */
485
- function process_terms() {
486
- $this->terms = apply_filters( 'wp_import_terms', $this->terms );
487
-
488
- if ( empty( $this->terms ) )
489
- return;
490
-
491
- foreach ( $this->terms as $term ) {
492
- // if the term already exists in the correct taxonomy leave it alone
493
- $term_id = term_exists( $term['slug'], $term['term_taxonomy'] );
494
- if ( $term_id ) {
495
- if ( is_array($term_id) ) $term_id = $term_id['term_id'];
496
- if ( isset($term['term_id']) )
497
- $this->processed_terms[intval($term['term_id'])] = (int) $term_id;
498
- continue;
499
- }
500
-
501
- if ( empty( $term['term_parent'] ) ) {
502
- $parent = 0;
503
- } else {
504
- $parent = term_exists( $term['term_parent'], $term['term_taxonomy'] );
505
- if ( is_array( $parent ) ) $parent = $parent['term_id'];
506
- }
507
- $term = wp_slash( $term );
508
- $description = isset( $term['term_description'] ) ? $term['term_description'] : '';
509
- $termarr = array( 'slug' => $term['slug'], 'description' => $description, 'parent' => intval($parent) );
510
-
511
- $id = wp_insert_term( $term['term_name'], $term['term_taxonomy'], $termarr );
512
- if ( ! is_wp_error( $id ) ) {
513
- if ( isset($term['term_id']) )
514
- $this->processed_terms[intval($term['term_id'])] = $id['term_id'];
515
- } else {
516
- printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($term['term_taxonomy']), esc_html($term['term_name']) );
517
- if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
518
- echo ': ' . $id->get_error_message();
519
- echo '<br />';
520
- continue;
521
- }
522
-
523
- $this->process_termmeta( $term, $id['term_id'] );
524
- }
525
-
526
- unset( $this->terms );
527
- }
528
-
529
- /**
530
- * Add metadata to imported term.
531
- *
532
- * @since 0.6.2
533
- *
534
- * @param array $term Term data from WXR import.
535
- * @param int $term_id ID of the newly created term.
536
- */
537
- protected function process_termmeta( $term, $term_id ) {
538
- if ( ! isset( $term['termmeta'] ) ) {
539
- $term['termmeta'] = array();
540
- }
541
-
542
- /**
543
- * Filters the metadata attached to an imported term.
544
- *
545
- * @since 0.6.2
546
- *
547
- * @param array $termmeta Array of term meta.
548
- * @param int $term_id ID of the newly created term.
549
- * @param array $term Term data from the WXR import.
550
- */
551
- $term['termmeta'] = apply_filters( 'wp_import_term_meta', $term['termmeta'], $term_id, $term );
552
-
553
- if ( empty( $term['termmeta'] ) ) {
554
- return;
555
- }
556
-
557
- foreach ( $term['termmeta'] as $meta ) {
558
- /**
559
- * Filters the meta key for an imported piece of term meta.
560
- *
561
- * @since 0.6.2
562
- *
563
- * @param string $meta_key Meta key.
564
- * @param int $term_id ID of the newly created term.
565
- * @param array $term Term data from the WXR import.
566
- */
567
- $key = apply_filters( 'import_term_meta_key', $meta['key'], $term_id, $term );
568
- if ( ! $key ) {
569
- continue;
570
- }
571
-
572
- // Export gets meta straight from the DB so could have a serialized string
573
- $value = maybe_unserialize( $meta['value'] );
574
-
575
- add_term_meta( $term_id, $key, $value );
576
-
577
- /**
578
- * Fires after term meta is imported.
579
- *
580
- * @since 0.6.2
581
- *
582
- * @param int $term_id ID of the newly created term.
583
- * @param string $key Meta key.
584
- * @param mixed $value Meta value.
585
- */
586
- do_action( 'import_term_meta', $term_id, $key, $value );
587
- }
588
- }
589
-
590
- /**
591
- * Create new posts based on import information
592
- *
593
- * Posts marked as having a parent which doesn't exist will become top level items.
594
- * Doesn't create a new post if: the post type doesn't exist, the given post ID
595
- * is already noted as imported or a post with the same title and date already exists.
596
- * Note that new/updated terms, comments and meta are imported for the last of the above.
597
- */
598
- function process_posts() {
599
- $this->posts = apply_filters( 'wp_import_posts', $this->posts );
600
-
601
- foreach ( $this->posts as $post ) {
602
- $post = apply_filters( 'wp_import_post_data_raw', $post );
603
-
604
- if ( ! post_type_exists( $post['post_type'] ) ) {
605
- printf( __( 'Failed to import &#8220;%s&#8221;: Invalid post type %s', 'wordpress-importer' ),
606
- esc_html($post['post_title']), esc_html($post['post_type']) );
607
- echo '<br />';
608
- do_action( 'wp_import_post_exists', $post );
609
- continue;
610
- }
611
-
612
- if ( isset( $this->processed_posts[$post['post_id']] ) && ! empty( $post['post_id'] ) )
613
- continue;
614
-
615
- if ( $post['status'] == 'auto-draft' )
616
- continue;
617
-
618
- if ( 'nav_menu_item' == $post['post_type'] ) {
619
- $this->process_menu_item( $post );
620
- continue;
621
- }
622
-
623
- $post_type_object = get_post_type_object( $post['post_type'] );
624
-
625
- $post_exists = post_exists( $post['post_title'], '', $post['post_date'] );
626
-
627
- /**
628
- * Filter ID of the existing post corresponding to post currently importing.
629
- *
630
- * Return 0 to force the post to be imported. Filter the ID to be something else
631
- * to override which existing post is mapped to the imported post.
632
- *
633
- * @see post_exists()
634
- * @since 0.6.2
635
- *
636
- * @param int $post_exists Post ID, or 0 if post did not exist.
637
- * @param array $post The post array to be inserted.
638
- */
639
- $post_exists = apply_filters( 'wp_import_existing_post', $post_exists, $post );
640
-
641
- if ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] ) {
642
- printf( __('%s &#8220;%s&#8221; already exists.', 'wordpress-importer'), $post_type_object->labels->singular_name, esc_html($post['post_title']) );
643
- echo '<br />';
644
- $comment_post_ID = $post_id = $post_exists;
645
- $this->processed_posts[ intval( $post['post_id'] ) ] = intval( $post_exists );
646
- } else {
647
- $post_parent = (int) $post['post_parent'];
648
- if ( $post_parent ) {
649
- // if we already know the parent, map it to the new local ID
650
- if ( isset( $this->processed_posts[$post_parent] ) ) {
651
- $post_parent = $this->processed_posts[$post_parent];
652
- // otherwise record the parent for later
653
- } else {
654
- $this->post_orphans[intval($post['post_id'])] = $post_parent;
655
- $post_parent = 0;
656
- }
657
- }
658
-
659
- // map the post author
660
- $author = sanitize_user( $post['post_author'], true );
661
- if ( isset( $this->author_mapping[$author] ) )
662
- $author = $this->author_mapping[$author];
663
- else
664
- $author = (int) get_current_user_id();
665
-
666
- $postdata = array(
667
- 'import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'],
668
- 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'],
669
- 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'],
670
- 'post_status' => $post['status'], 'post_name' => $post['post_name'],
671
- 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'],
672
- 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'],
673
- 'post_type' => $post['post_type'], 'post_password' => $post['post_password']
674
- );
675
-
676
- $original_post_ID = $post['post_id'];
677
- $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post );
678
-
679
- $postdata = wp_slash( $postdata );
680
-
681
- if ( 'attachment' == $postdata['post_type'] ) {
682
- $remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
683
-
684
- // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
685
- // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
686
- $postdata['upload_date'] = $post['post_date'];
687
- if ( isset( $post['postmeta'] ) ) {
688
- foreach( $post['postmeta'] as $meta ) {
689
- if ( $meta['key'] == '_wp_attached_file' ) {
690
- if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches ) )
691
- $postdata['upload_date'] = $matches[0];
692
- break;
693
- }
694
- }
695
- }
696
-
697
- $comment_post_ID = $post_id = $this->process_attachment( $postdata, $remote_url );
698
- } else {
699
- $comment_post_ID = $post_id = wp_insert_post( $postdata, true );
700
- do_action( 'wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post );
701
- }
702
-
703
- if ( is_wp_error( $post_id ) ) {
704
- printf( __( 'Failed to import %s &#8220;%s&#8221;', 'wordpress-importer' ),
705
- $post_type_object->labels->singular_name, esc_html($post['post_title']) );
706
- if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
707
- echo ': ' . $post_id->get_error_message();
708
- echo '<br />';
709
- continue;
710
- }
711
-
712
- if ( $post['is_sticky'] == 1 )
713
- stick_post( $post_id );
714
- }
715
-
716
- // map pre-import ID to local ID
717
- $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
718
-
719
- if ( ! isset( $post['terms'] ) )
720
- $post['terms'] = array();
721
-
722
- $post['terms'] = apply_filters( 'wp_import_post_terms', $post['terms'], $post_id, $post );
723
-
724
- // add categories, tags and other terms
725
- if ( ! empty( $post['terms'] ) ) {
726
- $terms_to_set = array();
727
- foreach ( $post['terms'] as $term ) {
728
- // back compat with WXR 1.0 map 'tag' to 'post_tag'
729
- $taxonomy = ( 'tag' == $term['domain'] ) ? 'post_tag' : $term['domain'];
730
- $term_exists = term_exists( $term['slug'], $taxonomy );
731
- $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;
732
- if ( ! $term_id ) {
733
- $t = wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
734
- if ( ! is_wp_error( $t ) ) {
735
- $term_id = $t['term_id'];
736
- do_action( 'wp_import_insert_term', $t, $term, $post_id, $post );
737
- } else {
738
- printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($taxonomy), esc_html($term['name']) );
739
- if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
740
- echo ': ' . $t->get_error_message();
741
- echo '<br />';
742
- do_action( 'wp_import_insert_term_failed', $t, $term, $post_id, $post );
743
- continue;
744
- }
745
- }
746
- $terms_to_set[$taxonomy][] = intval( $term_id );
747
- }
748
-
749
- foreach ( $terms_to_set as $tax => $ids ) {
750
- $tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
751
- do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post );
752
- }
753
- unset( $post['terms'], $terms_to_set );
754
- }
755
-
756
- if ( ! isset( $post['comments'] ) )
757
- $post['comments'] = array();
758
-
759
- $post['comments'] = apply_filters( 'wp_import_post_comments', $post['comments'], $post_id, $post );
760
-
761
- // add/update comments
762
- if ( ! empty( $post['comments'] ) ) {
763
- $num_comments = 0;
764
- $inserted_comments = array();
765
- foreach ( $post['comments'] as $comment ) {
766
- $comment_id = $comment['comment_id'];
767
- $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
768
- $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
769
- $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
770
- $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
771
- $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
772
- $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
773
- $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
774
- $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
775
- $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
776
- $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
777
- $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
778
- $newcomments[$comment_id]['commentmeta'] = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array();
779
- if ( isset( $this->processed_authors[$comment['comment_user_id']] ) )
780
- $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
781
- }
782
- ksort( $newcomments );
783
-
784
- foreach ( $newcomments as $key => $comment ) {
785
- // if this is a new post we can skip the comment_exists() check
786
- if ( ! $post_exists || ! comment_exists( $comment['comment_author'], $comment['comment_date'] ) ) {
787
- if ( isset( $inserted_comments[$comment['comment_parent']] ) )
788
- $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
789
- $comment = wp_filter_comment( $comment );
790
- $inserted_comments[$key] = wp_insert_comment( $comment );
791
- do_action( 'wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post );
792
-
793
- foreach( $comment['commentmeta'] as $meta ) {
794
- $value = maybe_unserialize( $meta['value'] );
795
- add_comment_meta( $inserted_comments[$key], $meta['key'], $value );
796
- }
797
-
798
- $num_comments++;
799
- }
800
- }
801
- unset( $newcomments, $inserted_comments, $post['comments'] );
802
- }
803
-
804
- if ( ! isset( $post['postmeta'] ) )
805
- $post['postmeta'] = array();
806
-
807
- $post['postmeta'] = apply_filters( 'wp_import_post_meta', $post['postmeta'], $post_id, $post );
808
-
809
- // add/update post meta
810
- if ( ! empty( $post['postmeta'] ) ) {
811
- foreach ( $post['postmeta'] as $meta ) {
812
- $key = apply_filters( 'import_post_meta_key', $meta['key'], $post_id, $post );
813
- $value = false;
814
-
815
- if ( '_edit_last' == $key ) {
816
- if ( isset( $this->processed_authors[intval($meta['value'])] ) )
817
- $value = $this->processed_authors[intval($meta['value'])];
818
- else
819
- $key = false;
820
- }
821
-
822
- if ( $key ) {
823
- // export gets meta straight from the DB so could have a serialized string
824
- if ( ! $value )
825
- $value = maybe_unserialize( $meta['value'] );
826
-
827
- add_post_meta( $post_id, $key, $value );
828
- do_action( 'import_post_meta', $post_id, $key, $value );
829
-
830
- // if the post has a featured image, take note of this in case of remap
831
- if ( '_thumbnail_id' == $key )
832
- $this->featured_images[$post_id] = (int) $value;
833
- }
834
- }
835
- }
836
- }
837
-
838
- unset( $this->posts );
839
- }
840
-
841
- /**
842
- * Attempt to create a new menu item from import data
843
- *
844
- * Fails for draft, orphaned menu items and those without an associated nav_menu
845
- * or an invalid nav_menu term. If the post type or term object which the menu item
846
- * represents doesn't exist then the menu item will not be imported (waits until the
847
- * end of the import to retry again before discarding).
848
- *
849
- * @param array $item Menu item details from WXR file
850
- */
851
- function process_menu_item( $item ) {
852
- // skip draft, orphaned menu items
853
- if ( 'draft' == $item['status'] )
854
- return;
855
-
856
- $menu_slug = false;
857
- if ( isset($item['terms']) ) {
858
- // loop through terms, assume first nav_menu term is correct menu
859
- foreach ( $item['terms'] as $term ) {
860
- if ( 'nav_menu' == $term['domain'] ) {
861
- $menu_slug = $term['slug'];
862
- break;
863
- }
864
- }
865
- }
866
-
867
- // no nav_menu term associated with this menu item
868
- if ( ! $menu_slug ) {
869
- _e( 'Menu item skipped due to missing menu slug', 'wordpress-importer' );
870
- echo '<br />';
871
- return;
872
- }
873
-
874
- $menu_id = term_exists( $menu_slug, 'nav_menu' );
875
- if ( ! $menu_id ) {
876
- printf( __( 'Menu item skipped due to invalid menu slug: %s', 'wordpress-importer' ), esc_html( $menu_slug ) );
877
- echo '<br />';
878
- return;
879
- } else {
880
- $menu_id = is_array( $menu_id ) ? $menu_id['term_id'] : $menu_id;
881
- }
882
-
883
- foreach ( $item['postmeta'] as $meta )
884
- ${$meta['key']} = $meta['value'];
885
-
886
- if ( 'taxonomy' == $_menu_item_type && isset( $this->processed_terms[intval($_menu_item_object_id)] ) ) {
887
- $_menu_item_object_id = $this->processed_terms[intval($_menu_item_object_id)];
888
- } else if ( 'post_type' == $_menu_item_type && isset( $this->processed_posts[intval($_menu_item_object_id)] ) ) {
889
- $_menu_item_object_id = $this->processed_posts[intval($_menu_item_object_id)];
890
- } else if ( 'custom' != $_menu_item_type ) {
891
- // associated object is missing or not imported yet, we'll retry later
892
- $this->missing_menu_items[] = $item;
893
- return;
894
- }
895
-
896
- if ( isset( $this->processed_menu_items[intval($_menu_item_menu_item_parent)] ) ) {
897
- $_menu_item_menu_item_parent = $this->processed_menu_items[intval($_menu_item_menu_item_parent)];
898
- } else if ( $_menu_item_menu_item_parent ) {
899
- $this->menu_item_orphans[intval($item['post_id'])] = (int) $_menu_item_menu_item_parent;
900
- $_menu_item_menu_item_parent = 0;
901
- }
902
-
903
- // wp_update_nav_menu_item expects CSS classes as a space separated string
904
- $_menu_item_classes = maybe_unserialize( $_menu_item_classes );
905
- if ( is_array( $_menu_item_classes ) )
906
- $_menu_item_classes = implode( ' ', $_menu_item_classes );
907
-
908
- $args = array(
909
- 'menu-item-object-id' => $_menu_item_object_id,
910
- 'menu-item-object' => $_menu_item_object,
911
- 'menu-item-parent-id' => $_menu_item_menu_item_parent,
912
- 'menu-item-position' => intval( $item['menu_order'] ),
913
- 'menu-item-type' => $_menu_item_type,
914
- 'menu-item-title' => $item['post_title'],
915
- 'menu-item-url' => $_menu_item_url,
916
- 'menu-item-description' => $item['post_content'],
917
- 'menu-item-attr-title' => $item['post_excerpt'],
918
- 'menu-item-target' => $_menu_item_target,
919
- 'menu-item-classes' => $_menu_item_classes,
920
- 'menu-item-xfn' => $_menu_item_xfn,
921
- 'menu-item-status' => $item['status']
922
- );
923
-
924
- $id = wp_update_nav_menu_item( $menu_id, 0, $args );
925
-
926
- // Make sure all custom menu fields are imported correctly
927
- if ( ! $args['menu-item-parent-id'] ) {
928
- $field_name_suffix = array( 'nolink', 'category_post', 'megamenu', 'megamenu_auto_width', 'megamenu_col', 'megamenu_heading', 'icon' );
929
- } else {
930
- $field_name_suffix = array( 'nolink', 'category_post', 'icon', 'megamenu_widgetarea' );
931
- }
932
-
933
- foreach ( $field_name_suffix as $suffix ) {
934
- $key = '_menu_item_' . $suffix;
935
- if ( isset( $$key ) ) {
936
- update_post_meta( $id, '_menu_item_' . $suffix , $$key );
937
- }
938
- }
939
-
940
- if ( $id && ! is_wp_error( $id ) )
941
- $this->processed_menu_items[intval($item['post_id'])] = (int) $id;
942
- }
943
-
944
- /**
945
- * If fetching attachments is enabled then attempt to create a new attachment
946
- *
947
- * @param array $post Attachment post details from WXR
948
- * @param string $url URL to fetch attachment from
949
- * @return int|WP_Error Post ID on success, WP_Error otherwise
950
- */
951
- function process_attachment( $post, $url ) {
952
- if ( ! $this->fetch_attachments )
953
- return new WP_Error( 'attachment_processing_error',
954
- __( 'Fetching attachments is not enabled', 'wordpress-importer' ) );
955
-
956
- // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
957
- if ( preg_match( '|^/[\w\W]+$|', $url ) )
958
- $url = rtrim( $this->base_url, '/' ) . $url;
959
-
960
- $upload = $this->fetch_remote_file( $url, $post );
961
- if ( is_wp_error( $upload ) )
962
- return $upload;
963
-
964
- if ( $info = wp_check_filetype( $upload['file'] ) )
965
- $post['post_mime_type'] = $info['type'];
966
- else
967
- return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') );
968
-
969
- $post['guid'] = $upload['url'];
970
-
971
- // as per wp-admin/includes/upload.php
972
- $post_id = wp_insert_attachment( $post, $upload['file'] );
973
- wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) );
974
-
975
- // remap resized image URLs, works by stripping the extension and remapping the URL stub.
976
- if ( preg_match( '!^image/!', $info['type'] ) ) {
977
- $parts = pathinfo( $url );
978
- $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
979
-
980
- $parts_new = pathinfo( $upload['url'] );
981
- $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
982
-
983
- $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new;
984
- }
985
-
986
- return $post_id;
987
- }
988
-
989
- /**
990
- * Attempt to download a remote file attachment
991
- *
992
- * @param string $url URL of item to fetch
993
- * @param array $post Attachment details
994
- * @return array|WP_Error Local file location details on success, WP_Error otherwise
995
- */
996
- function fetch_remote_file( $url, $post ) {
997
- // extract the file name and extension from the url
998
- $file_name = basename( $url );
999
-
1000
- // get placeholder file in the upload dir with a unique, sanitized filename
1001
- $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
1002
- if ( $upload['error'] )
1003
- return new WP_Error( 'upload_dir_error', $upload['error'] );
1004
-
1005
- // fetch the remote url and write it to the placeholder file
1006
- $headers = ODI_Helpers::odi_wp_get_http( $url, $upload['file'] );
1007
-
1008
- // request failed
1009
- if ( ! $headers ) {
1010
- @unlink( $upload['file'] );
1011
- return new WP_Error( 'import_file_error', __('Remote server did not respond', 'wordpress-importer') );
1012
- }
1013
-
1014
- // make sure the fetch was successful
1015
- if ( $headers['response'] != '200' ) {
1016
- @unlink( $upload['file'] );
1017
- return new WP_Error( 'import_file_error', sprintf( __('Remote server returned error response %1$d %2$s', 'wordpress-importer'), esc_html($headers['response']), get_status_header_desc($headers['response']) ) );
1018
- }
1019
-
1020
- $filesize = filesize( $upload['file'] );
1021
-
1022
- if ( isset( $headers['content-length'] ) && $filesize != $headers['content-length'] ) {
1023
- @unlink( $upload['file'] );
1024
- return new WP_Error( 'import_file_error', __('Remote file is incorrect size', 'wordpress-importer') );
1025
- }
1026
-
1027
- if ( 0 == $filesize ) {
1028
- @unlink( $upload['file'] );
1029
- return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'wordpress-importer') );
1030
- }
1031
-
1032
- $max_size = (int) $this->max_attachment_size();
1033
- if ( ! empty( $max_size ) && $filesize > $max_size ) {
1034
- @unlink( $upload['file'] );
1035
- return new WP_Error( 'import_file_error', sprintf(__('Remote file is too large, limit is %s', 'wordpress-importer'), size_format($max_size) ) );
1036
- }
1037
-
1038
- // keep track of the old and new urls so we can substitute them later
1039
- $this->url_remap[$url] = $upload['url'];
1040
- $this->url_remap[$post['guid']] = $upload['url']; // r13735, really needed?
1041
- // keep track of the destination if the remote url is redirected somewhere else
1042
- if ( isset($headers['x-final-location']) && $headers['x-final-location'] != $url )
1043
- $this->url_remap[$headers['x-final-location']] = $upload['url'];
1044
-
1045
- return $upload;
1046
- }
1047
-
1048
- /**
1049
- * Attempt to associate posts and menu items with previously missing parents
1050
- *
1051
- * An imported post's parent may not have been imported when it was first created
1052
- * so try again. Similarly for child menu items and menu items which were missing
1053
- * the object (e.g. post) they represent in the menu
1054
- */
1055
- function backfill_parents() {
1056
- global $wpdb;
1057
-
1058
- // find parents for post orphans
1059
- foreach ( $this->post_orphans as $child_id => $parent_id ) {
1060
- $local_child_id = $local_parent_id = false;
1061
- if ( isset( $this->processed_posts[$child_id] ) )
1062
- $local_child_id = $this->processed_posts[$child_id];
1063
- if ( isset( $this->processed_posts[$parent_id] ) )
1064
- $local_parent_id = $this->processed_posts[$parent_id];
1065
-
1066
- if ( $local_child_id && $local_parent_id )
1067
- $wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' );
1068
- }
1069
-
1070
- // all other posts/terms are imported, retry menu items with missing associated object
1071
- $missing_menu_items = $this->missing_menu_items;
1072
- foreach ( $missing_menu_items as $item )
1073
- $this->process_menu_item( $item );
1074
-
1075
- // find parents for menu item orphans
1076
- foreach ( $this->menu_item_orphans as $child_id => $parent_id ) {
1077
- $local_child_id = $local_parent_id = 0;
1078
- if ( isset( $this->processed_menu_items[$child_id] ) )
1079
- $local_child_id = $this->processed_menu_items[$child_id];
1080
- if ( isset( $this->processed_menu_items[$parent_id] ) )
1081
- $local_parent_id = $this->processed_menu_items[$parent_id];
1082
-
1083
- if ( $local_child_id && $local_parent_id )
1084
- update_post_meta( $local_child_id, '_menu_item_menu_item_parent', (int) $local_parent_id );
1085
- }
1086
- }
1087
-
1088
- /**
1089
- * Use stored mapping information to update old attachment URLs
1090
- */
1091
- function backfill_attachment_urls() {
1092
- global $wpdb;
1093
- // make sure we do the longest urls first, in case one is a substring of another
1094
- uksort( $this->url_remap, array(&$this, 'cmpr_strlen') );
1095
-
1096
- foreach ( $this->url_remap as $from_url => $to_url ) {
1097
- // remap urls in post_content
1098
- $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url) );
1099
- // remap enclosure urls
1100
- $result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url) );
1101
- }
1102
- }
1103
-
1104
- /**
1105
- * Update _thumbnail_id meta to new, imported attachment IDs
1106
- */
1107
- function remap_featured_images() {
1108
- // cycle through posts that have a featured image
1109
- foreach ( $this->featured_images as $post_id => $value ) {
1110
- if ( isset( $this->processed_posts[$value] ) ) {
1111
- $new_id = $this->processed_posts[$value];
1112
- // only update if there's a difference
1113
- if ( $new_id != $value )
1114
- update_post_meta( $post_id, '_thumbnail_id', $new_id );
1115
- }
1116
- }
1117
- }
1118
-
1119
- /**
1120
- * Parse a WXR file
1121
- *
1122
- * @param string $file Path to WXR file for parsing
1123
- * @return array Information gathered from the WXR file
1124
- */
1125
- function parse( $file ) {
1126
- $parser = new WXR_Parser();
1127
- return $parser->parse( $file );
1128
- }
1129
-
1130
- // Display import page title
1131
- function header() {
1132
- echo '<div class="wrap">';
1133
- screen_icon();
1134
- echo '<h2>' . __( 'Import WordPress', 'wordpress-importer' ) . '</h2>';
1135
-
1136
- $updates = get_plugin_updates();
1137
- $basename = plugin_basename(__FILE__);
1138
- if ( isset( $updates[$basename] ) ) {
1139
- $update = $updates[$basename];
1140
- echo '<div class="error"><p><strong>';
1141
- printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'wordpress-importer' ), $update->update->new_version );
1142
- echo '</strong></p></div>';
1143
- }
1144
- }
1145
-
1146
- // Close div.wrap
1147
- function footer() {
1148
- echo '</div>';
1149
- }
1150
-
1151
- /**
1152
- * Display introductory text and file upload form
1153
- */
1154
- function greet() {
1155
- echo '<div class="narrow">';
1156
- echo '<p>'.__( 'Howdy! Upload your WordPress eXtended RSS (WXR) file and we&#8217;ll import the posts, pages, comments, custom fields, categories, and tags into this site.', 'wordpress-importer' ).'</p>';
1157
- echo '<p>'.__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'wordpress-importer' ).'</p>';
1158
- wp_import_upload_form( 'admin.php?import=wordpress&amp;step=1' );
1159
- echo '</div>';
1160
- }
1161
-
1162
- /**
1163
- * Decide if the given meta key maps to information we will want to import
1164
- *
1165
- * @param string $key The meta key to check
1166
- * @return string|bool The key if we do want to import, false if not
1167
- */
1168
- function is_valid_meta_key( $key ) {
1169
- // skip attachment metadata since we'll regenerate it from scratch
1170
- // skip _edit_lock as not relevant for import
1171
- if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) )
1172
- return false;
1173
- return $key;
1174
- }
1175
-
1176
- /**
1177
- * Decide whether or not the importer is allowed to create users.
1178
- * Default is true, can be filtered via import_allow_create_users
1179
- *
1180
- * @return bool True if creating users is allowed
1181
- */
1182
- function allow_create_users() {
1183
- return apply_filters( 'import_allow_create_users', true );
1184
- }
1185
-
1186
- /**
1187
- * Decide whether or not the importer should attempt to download attachment files.
1188
- * Default is true, can be filtered via import_allow_fetch_attachments. The choice
1189
- * made at the import options screen must also be true, false here hides that checkbox.
1190
- *
1191
- * @return bool True if downloading attachments is allowed
1192
- */
1193
- function allow_fetch_attachments() {
1194
- return apply_filters( 'import_allow_fetch_attachments', true );
1195
- }
1196
-
1197
- /**
1198
- * Decide what the maximum file size for downloaded attachments is.
1199
- * Default is 0 (unlimited), can be filtered via import_attachment_size_limit
1200
- *
1201
- * @return int Maximum attachment file size to import
1202
- */
1203
- function max_attachment_size() {
1204
- return apply_filters( 'import_attachment_size_limit', 0 );
1205
- }
1206
-
1207
- /**
1208
- * Added to http_request_timeout filter to force timeout at 60 seconds during import
1209
- * @return int 60
1210
- */
1211
- function bump_request_timeout( $val ) {
1212
- return 60;
1213
- }
1214
-
1215
- // return the difference in length between two strings
1216
- function cmpr_strlen( $a, $b ) {
1217
- return strlen($b) - strlen($a);
1218
- }
1219
- }
1220
-
1221
- } // class_exists( 'WP_Importer' )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/importer.php DELETED
@@ -1,607 +0,0 @@
1
- <?php
2
- /**
3
- * Importer function
4
- */
5
-
6
- // Exit if accessed directly
7
- if ( ! defined( 'ABSPATH' ) ) {
8
- exit;
9
- }
10
-
11
- /**
12
- * The importer class.
13
- */
14
- class ODI_Importer {
15
-
16
- /**
17
- * Class Constructor
18
- *
19
- * @since 1.0.0
20
- */
21
- public function __construct() {
22
-
23
- // Return if not in admin
24
- if ( ! is_admin() || is_customize_preview() ) {
25
- return;
26
- }
27
-
28
- // Disable Woo Wizard
29
- add_filter( 'woocommerce_enable_setup_wizard', false );
30
-
31
- // Start things
32
- add_action( 'admin_init', array( $this, 'init' ) );
33
-
34
- // Allows xml uploads
35
- add_filter( 'upload_mimes', array( $this, 'allow_xml_uploads' ) );
36
- }
37
-
38
- /**
39
- * Register the AJAX method
40
- *
41
- * @since 1.0.0
42
- */
43
- public function init() {
44
- add_action( 'wp_ajax_ocean_import_demo_data', array( $this, 'ocean_importer' ) );
45
- }
46
-
47
- /**
48
- * Return data
49
- *
50
- * @since 1.0.0
51
- */
52
- public static function get_data() {
53
-
54
- // Demos url
55
- $url = 'https://raw.githubusercontent.com/oceanwp/oceanwp-sample-data/master/';
56
-
57
- $data = array(
58
-
59
- 'architect' => array(
60
- 'categories' => array( 'Business' ),
61
- 'xml_file' => $url . 'architect/sample-data.xml',
62
- 'theme_settings' => $url . 'architect/oceanwp-export.json',
63
- 'widgets_file' => $url . 'architect/widgets.wie',
64
- 'home_title' => 'Home',
65
- 'blog_title' => 'Blog',
66
- 'posts_to_show' => '3',
67
- 'elementor_width' => '1220',
68
- 'is_shop' => false,
69
- ),
70
-
71
- 'blogger' => array(
72
- 'categories' => array( 'Blog' ),
73
- 'xml_file' => $url . 'blogger/sample-data.xml',
74
- 'theme_settings' => $url . 'blogger/oceanwp-export.json',
75
- 'widgets_file' => $url . 'blogger/widgets.wie',
76
- 'home_title' => '',
77
- 'blog_title' => 'Home',
78
- 'posts_to_show' => '12',
79
- 'is_shop' => false,
80
- ),
81
-
82
- 'coach' => array(
83
- 'categories' => array( 'Business', 'Sport', 'One Page' ),
84
- 'xml_file' => $url . 'coach/sample-data.xml',
85
- 'theme_settings' => $url . 'coach/oceanwp-export.json',
86
- 'widgets_file' => $url . 'coach/widgets.wie',
87
- 'home_title' => 'Home',
88
- 'blog_title' => 'Blog',
89
- 'posts_to_show' => '3',
90
- 'is_shop' => false,
91
- ),
92
-
93
- 'gym' => array(
94
- 'categories' => array( 'Business', 'Sport' ),
95
- 'xml_file' => $url . 'gym/sample-data.xml',
96
- 'theme_settings' => $url . 'gym/oceanwp-export.json',
97
- 'widgets_file' => $url . 'gym/widgets.wie',
98
- 'home_title' => 'Home',
99
- 'blog_title' => 'News',
100
- 'posts_to_show' => '3',
101
- 'elementor_width' => '1100',
102
- 'is_shop' => false,
103
- ),
104
-
105
- 'lawyer' => array(
106
- 'categories' => array( 'Business' ),
107
- 'xml_file' => $url . 'lawyer/sample-data.xml',
108
- 'theme_settings' => $url . 'lawyer/oceanwp-export.json',
109
- 'widgets_file' => $url . 'lawyer/widgets.wie',
110
- 'home_title' => 'Home',
111
- 'blog_title' => 'Blog',
112
- 'posts_to_show' => '3',
113
- 'elementor_width' => '1220',
114
- 'is_shop' => false,
115
- ),
116
-
117
- 'megagym' => array(
118
- 'categories' => array( 'Business', 'Sport', 'One Page' ),
119
- 'xml_file' => $url . 'megagym/sample-data.xml',
120
- 'theme_settings' => $url . 'megagym/oceanwp-export.json',
121
- 'widgets_file' => $url . 'megagym/widgets.wie',
122
- 'home_title' => 'Home',
123
- 'blog_title' => 'Blog',
124
- 'posts_to_show' => '3',
125
- 'is_shop' => false,
126
- ),
127
-
128
- 'personal' => array(
129
- 'categories' => array( 'Blog' ),
130
- 'xml_file' => $url . 'personal/sample-data.xml',
131
- 'theme_settings' => $url . 'personal/oceanwp-export.json',
132
- 'widgets_file' => $url . 'personal/widgets.wie',
133
- 'home_title' => '',
134
- 'blog_title' => 'Home',
135
- 'posts_to_show' => '3',
136
- 'is_shop' => false,
137
- ),
138
-
139
- 'simple' => array(
140
- 'categories' => array( 'eCommerce' ),
141
- 'xml_file' => $url . 'simple/sample-data.xml',
142
- 'theme_settings' => $url . 'simple/oceanwp-export.json',
143
- 'widgets_file' => $url . 'simple/widgets.wie',
144
- 'home_title' => 'Home',
145
- 'blog_title' => 'Blog',
146
- 'posts_to_show' => '3',
147
- 'elementor_width' => '1100',
148
- 'is_shop' => true,
149
- 'catalog_img' => array(
150
- 'width' => '348',
151
- 'height' => '464',
152
- ),
153
- 'single_img' => array(
154
- 'width' => '454',
155
- 'height' => '608',
156
- ),
157
- 'thumbnails_img' => array(
158
- 'width' => '90',
159
- 'height' => '120',
160
- ),
161
- ),
162
-
163
- 'store' => array(
164
- 'categories' => array( 'eCommerce' ),
165
- 'xml_file' => $url . 'store/sample-data.xml',
166
- 'theme_settings' => $url . 'store/oceanwp-export.json',
167
- 'widgets_file' => $url . 'store/widgets.wie',
168
- 'home_title' => 'Home',
169
- 'blog_title' => 'Blog',
170
- 'posts_to_show' => '3',
171
- 'elementor_width' => '1220',
172
- 'is_shop' => true,
173
- 'catalog_img' => array(
174
- 'width' => '265',
175
- 'height' => '354',
176
- ),
177
- 'single_img' => array(
178
- 'width' => '504',
179
- 'height' => '674',
180
- ),
181
- 'thumbnails_img' => array(
182
- 'width' => '93',
183
- 'height' => '120',
184
- ),
185
- ),
186
-
187
- 'stylish' => array(
188
- 'categories' => array( 'Business' ),
189
- 'xml_file' => $url . 'stylish/sample-data.xml',
190
- 'theme_settings' => $url . 'stylish/oceanwp-export.json',
191
- 'home_title' => 'Home',
192
- 'blog_title' => 'Blog',
193
- 'posts_to_show' => '12',
194
- 'elementor_width' => '1420',
195
- 'is_shop' => false,
196
- ),
197
-
198
- 'travel' => array(
199
- 'categories' => array( 'Blog' ),
200
- 'xml_file' => $url . 'travel/sample-data.xml',
201
- 'theme_settings' => $url . 'travel/oceanwp-export.json',
202
- 'widgets_file' => $url . 'travel/widgets.wie',
203
- 'home_title' => 'Home',
204
- 'blog_title' => 'Blog',
205
- 'posts_to_show' => '4',
206
- 'elementor_width' => '1220',
207
- 'is_shop' => false,
208
- ),
209
-
210
- 'lingerie' => array(
211
- 'categories' => array( 'eCommerce' ),
212
- 'xml_file' => $url . 'lingerie/sample-data.xml',
213
- 'theme_settings' => $url . 'lingerie/oceanwp-export.json',
214
- 'widgets_file' => $url . 'lingerie/widgets.wie',
215
- 'home_title' => 'Home',
216
- 'blog_title' => 'Blog',
217
- 'posts_to_show' => '3',
218
- 'elementor_width' => '1220',
219
- 'is_shop' => true,
220
- 'catalog_img' => array(
221
- 'width' => '265',
222
- 'height' => '352',
223
- ),
224
- 'single_img' => array(
225
- 'width' => '433',
226
- 'height' => '578',
227
- ),
228
- 'thumbnails_img' => array(
229
- 'width' => '90',
230
- 'height' => '120',
231
- ),
232
- ),
233
-
234
- 'yoga' => array(
235
- 'categories' => array( 'Business', 'Sport' ),
236
- 'xml_file' => $url . 'yoga/sample-data.xml',
237
- 'theme_settings' => $url . 'yoga/oceanwp-export.json',
238
- 'widgets_file' => $url . 'yoga/widgets.wie',
239
- 'home_title' => 'Home',
240
- 'blog_title' => 'Blog',
241
- 'posts_to_show' => '3',
242
- 'is_shop' => false,
243
- ),
244
-
245
- );
246
-
247
- // Return
248
- return $data;
249
-
250
- }
251
-
252
- /**
253
- * Get the category list of all categories used in the predefined demo imports array.
254
- *
255
- * @since 1.0.2
256
- */
257
- public static function get_all_categories( $demo_imports ) {
258
- $categories = array();
259
-
260
- foreach ( $demo_imports as $item ) {
261
- if ( ! empty( $item['categories'] ) && is_array( $item['categories'] ) ) {
262
- foreach ( $item['categories'] as $category ) {
263
- $categories[ sanitize_key( $category ) ] = $category;
264
- }
265
- }
266
- }
267
-
268
- if ( empty( $categories ) ) {
269
- return false;
270
- }
271
-
272
- return $categories;
273
- }
274
-
275
- /**
276
- * Return the concatenated string of demo import item categories.
277
- * These should be separated by comma and sanitized properly.
278
- *
279
- * @since 1.0.2
280
- */
281
- public static function get_item_categories( $item ) {
282
- $sanitized_categories = array();
283
-
284
- if ( isset( $item['categories'] ) ) {
285
- foreach ( $item['categories'] as $category ) {
286
- $sanitized_categories[] = sanitize_key( $category );
287
- }
288
- }
289
-
290
- if ( ! empty( $sanitized_categories ) ) {
291
- return implode( ',', $sanitized_categories );
292
- }
293
-
294
- return false;
295
- }
296
-
297
- /**
298
- * Allows xml uploads so we can import from github
299
- *
300
- * @since 1.0.0
301
- */
302
- public function allow_xml_uploads( $mimes ) {
303
- $mimes = array_merge( $mimes, array(
304
- 'xml' => 'application/xml'
305
- ) );
306
- return $mimes;
307
- }
308
-
309
- /**
310
- * Importer
311
- *
312
- * @since 1.0.0
313
- */
314
- public function ocean_importer() {
315
-
316
- // Include settings importer
317
- include ODI_PATH . 'includes/class/class-settings-importer.php';
318
-
319
- // Include widgets importer
320
- include ODI_PATH . 'includes/class/class-widget-importer.php';
321
-
322
- if ( current_user_can( 'manage_options' ) ) {
323
-
324
- if ( ! isset( $_POST['demo_type'] ) || '' == trim( $_POST['demo_type'] ) ) {
325
- $demo_type = 'architect';
326
- } else {
327
- $demo_type = $_POST['demo_type'];
328
- }
329
-
330
- // Get demo data
331
- $demo = self::get_data()[ $demo_type ];
332
-
333
- // Content file
334
- $xml_file = isset ( $demo['xml_file'] ) ? $demo['xml_file'] : '';
335
-
336
- // Settings file
337
- $theme_settings = isset ( $demo['theme_settings'] ) ? $demo['theme_settings'] : '';
338
-
339
- // Widgets file
340
- $widgets_file = isset ( $demo['widgets_file'] ) ? $demo['widgets_file'] : '';
341
-
342
- // Elementor width setting
343
- if ( $demo['elementor_width'] ) {
344
- $elementor_width = isset ( $demo['elementor_width'] ) ? $demo['elementor_width'] : '';
345
- }
346
-
347
- // Reading settings
348
- $homepage_title = isset ( $demo['home_title'] ) ? $demo['home_title'] : 'Home';
349
- $blog_title = isset ( $demo['blog_title'] ) ? $demo['blog_title'] : 'Blog';
350
-
351
- // Posts to show on the blog page
352
- $posts_to_show = isset ( $demo['posts_to_show'] ) ? $demo['posts_to_show'] : '';
353
-
354
- // If shop demo
355
- $shop_demo = isset ( $demo['is_shop'] ) ? $demo['is_shop'] : false;
356
-
357
- // Woo catalog images sizes
358
- $catalog_img = isset ( $demo['catalog_img'] ) ? $demo['catalog_img'] : '';
359
- $c_width = isset ( $catalog_img['width'] ) ? $catalog_img['width'] : '';
360
- $c_height = isset ( $catalog_img['height'] ) ? $catalog_img['height'] : '';
361
-
362
- // Woo single product image sizes
363
- $single_img = isset ( $demo['single_img'] ) ? $demo['single_img'] : '';
364
- $s_width = isset ( $single_img['width'] ) ? $single_img['width'] : '';
365
- $s_height = isset ( $single_img['height'] ) ? $single_img['height'] : '';
366
-
367
- // Woo product thumbnails images sizes
368
- $thumbnails_img = isset ( $demo['thumbnails_img'] ) ? $demo['thumbnails_img'] : '';
369
- $t_width = isset ( $thumbnails_img['width'] ) ? $thumbnails_img['width'] : '';
370
- $t_height = isset ( $thumbnails_img['height'] ) ? $thumbnails_img['height'] : '';
371
-
372
- // Import Posts, Pages, Images, Menus.
373
- $this->process_xml( $xml_file );
374
-
375
- // Assign WooCommerce pages if WooCommerce Exists
376
- if ( class_exists( 'WooCommerce' ) && $shop_demo ) {
377
-
378
- $woopages = array(
379
- 'woocommerce_shop_page_id' => 'Shop',
380
- 'woocommerce_cart_page_id' => 'Cart',
381
- 'woocommerce_checkout_page_id' => 'Checkout',
382
- 'woocommerce_pay_page_id' => 'Checkout &#8594; Pay',
383
- 'woocommerce_thanks_page_id' => 'Order Received',
384
- 'woocommerce_myaccount_page_id' => 'My Account',
385
- 'woocommerce_edit_address_page_id' => 'Edit My Address',
386
- 'woocommerce_view_order_page_id' => 'View Order',
387
- 'woocommerce_change_password_page_id' => 'Change Password',
388
- 'woocommerce_logout_page_id' => 'Logout',
389
- 'woocommerce_lost_password_page_id' => 'Lost Password'
390
- );
391
-
392
- foreach ( $woopages as $woo_page_name => $woo_page_title ) {
393
-
394
- $woopage = get_page_by_title( $woo_page_title );
395
- if ( isset( $woopage ) && $woopage->ID ) {
396
- update_option( $woo_page_name, $woopage->ID );
397
- }
398
-
399
- }
400
-
401
- // Catalog images sizes
402
- if ( $catalog_img ) {
403
- $catalog = array(
404
- 'width' => $c_width,
405
- 'height' => $c_height,
406
- 'crop' => 1
407
- );
408
- update_option( 'shop_catalog_image_size', $catalog );
409
- }
410
-
411
- // Single product image sizes
412
- if ( $single_img ) {
413
- $single = array(
414
- 'width' => $s_width,
415
- 'height' => $s_height,
416
- 'crop' => 1
417
- );
418
- update_option( 'shop_single_image_size', $single );
419
- }
420
-
421
- // Product thumbnails image sizes
422
- if ( $thumbnails_img ) {
423
- $thumbnail = array(
424
- 'width' => $t_width,
425
- 'height' => $t_height,
426
- 'crop' => 1
427
- );
428
- update_option( 'shop_thumbnail_image_size', $thumbnail );
429
- }
430
-
431
- // We no longer need to install pages
432
- delete_option( '_wc_needs_pages' );
433
- delete_transient( '_wc_activation_redirect' );
434
-
435
- }
436
-
437
- // Import settings
438
- if ( $theme_settings ) {
439
- $settings_importer = new ODI_Settings_Importer();
440
- $settings_importer->process_import_file( $theme_settings );
441
- }
442
-
443
- // Import widgets
444
- if ( $widgets_file ) {
445
- $widgets_importer = new ODI_Widget_Importer();
446
- $widgets_importer->process_import_file( $widgets_file );
447
- }
448
-
449
- // Set imported menus to registered theme locations
450
- $locations = get_theme_mod( 'nav_menu_locations' );
451
- $menus = wp_get_nav_menus();
452
-
453
- if ( $menus ) {
454
-
455
- foreach ( $menus as $menu ) {
456
-
457
- if ( $menu->name == 'Main Menu' ) {
458
- $locations['main_menu'] = $menu->term_id;
459
- } else if ( $menu->name == 'Top Menu' ) {
460
- $locations['topbar_menu'] = $menu->term_id;
461
- } else if ( $menu->name == 'Footer Menu' ) {
462
- $locations['footer_menu'] = $menu->term_id;
463
- } else if ( $menu->name == 'Sticky Footer' ) {
464
- $locations['sticky_footer_menu'] = $menu->term_id;
465
- }
466
-
467
- }
468
-
469
- }
470
-
471
- // Set menus to locations
472
- set_theme_mod( 'nav_menu_locations', $locations );
473
-
474
- // Disable Elementor default settings
475
- update_option( 'elementor_disable_color_schemes', 'yes' );
476
- update_option( 'elementor_disable_typography_schemes', 'yes' );
477
- if ( $elementor_width ) {
478
- update_option( 'elementor_container_width', $elementor_width );
479
- }
480
-
481
- // Assign front page and posts page (blog page).
482
- $home_page = get_page_by_title( $homepage_title );
483
- $blog_page = get_page_by_title( $blog_title );
484
-
485
- update_option( 'show_on_front', 'page' );
486
-
487
- if ( isset( $home_page ) && $home_page->ID ) {
488
- update_option( 'page_on_front', $home_page->ID );
489
- }
490
-
491
- if ( isset( $blog_page ) && $blog_page->ID ) {
492
- update_option( 'page_for_posts', $blog_page->ID );
493
- }
494
-
495
- // Posts to show on the blog page
496
- if ( $posts_to_show ) {
497
- update_option( 'posts_per_page', $posts_to_show );
498
- }
499
-
500
- echo 'imported';
501
-
502
- exit;
503
-
504
- }
505
-
506
- }
507
-
508
- /**
509
- * Import XML data
510
- *
511
- * @since 1.0.0
512
- */
513
- public function process_xml( $file ) {
514
-
515
- $response = ODI_Helpers::get_remote( $file );
516
-
517
- // No sample data found
518
- if ( $response === false ) {
519
- return new WP_Error( 'xml_import_error', __( 'Can not retrieve sample data xml file. Github may be down at the momment please try again later. If you still have issues contact the theme developer for assistance.', 'ocean-demo-import' ) );
520
- }
521
-
522
- // Write sample data content to temp xml file
523
- $temp_xml = ODI_PATH .'includes/temp.xml';
524
- file_put_contents( $temp_xml, $response );
525
-
526
- // Set temp xml to attachment url for use
527
- $attachment_url = $temp_xml;
528
-
529
- // If file exists lets import it
530
- if ( file_exists( $attachment_url ) ) {
531
- $this->import_xml( $attachment_url );
532
- } else {
533
- // Import file can't be imported - we should die here since this is core for most people.
534
- return new WP_Error( 'xml_import_error', __( 'The xml import file could not be accessed. Please try again or contact the theme developer.', 'ocean-demo-import' ) );
535
- }
536
-
537
- }
538
-
539
- /**
540
- * Import XML file
541
- *
542
- * @since 1.0.0
543
- */
544
- private function import_xml( $file ) {
545
-
546
- // Make sure importers constant is defined
547
- if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
548
- define( 'WP_LOAD_IMPORTERS', true );
549
- }
550
-
551
- // Import file location
552
- $import_file = ABSPATH . 'wp-admin/includes/import.php';
553
-
554
- // Include import file
555
- if ( ! file_exists( $import_file ) ) {
556
- return;
557
- }
558
-
559
- // Include import file
560
- require_once( $import_file );
561
-
562
- // Define error var
563
- $importer_error = false;
564
-
565
- if ( ! class_exists( 'WP_Importer' ) ) {
566
- $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
567
-
568
- if ( file_exists( $class_wp_importer ) ) {
569
- require_once $class_wp_importer;
570
- } else {
571
- $importer_error = __( 'Can not retrieve class-wp-importer.php', 'ocean-demo-import' );
572
- }
573
- }
574
-
575
- if ( ! class_exists( 'WP_Import' ) ) {
576
- $class_wp_import = ODI_PATH . 'includes/class/class-wordpress-importer.php';
577
-
578
- if ( file_exists( $class_wp_import ) ) {
579
- require_once $class_wp_import;
580
- } else {
581
- $importer_error = __( 'Can not retrieve wordpress-importer.php', 'ocean-demo-import' );
582
- }
583
- }
584
-
585
- // Display error
586
- if ( $importer_error ) {
587
- return new WP_Error( 'xml_import_error', $importer_error );
588
- } else {
589
-
590
- // No error, lets import things...
591
- if ( ! is_file( $file ) ) {
592
- $importer_error = __( 'Sample data file appears corrupt or can not be accessed.', 'ocean-demo-import' );
593
- return new WP_Error( 'xml_import_error', $importer_error );
594
- } else {
595
- $importer = new WP_Import();
596
- $importer->fetch_attachments = true;
597
- $importer->import( $file );
598
-
599
- // Clear sample data content from temp xml file
600
- $temp_xml = ODI_PATH .'includes/temp.xml';
601
- file_put_contents( $temp_xml, '' );
602
- }
603
- }
604
- }
605
-
606
- }
607
- new ODI_Importer();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/install-demos.php DELETED
@@ -1,160 +0,0 @@
1
- <?php
2
- /**
3
- * Install demos page
4
- */
5
-
6
- // Exit if accessed directly
7
- if ( ! defined( 'ABSPATH' ) ) {
8
- exit;
9
- }
10
-
11
- // Start Class
12
- class ODI_Install_Demos {
13
-
14
- /**
15
- * Start things up
16
- */
17
- public function __construct() {
18
- add_action( 'admin_menu', array( $this, 'add_page' ), 11 );
19
- }
20
-
21
- /**
22
- * Add sub menu page for the custom CSS input
23
- *
24
- * @since 1.0.0
25
- */
26
- public function add_page() {
27
- add_submenu_page(
28
- 'oceanwp-panel',
29
- esc_html__( 'Install Demos', 'ocean-demo-import' ),
30
- esc_html__( 'Install Demos', 'ocean-demo-import' ),
31
- 'manage_options',
32
- 'oceanwp-panel-install-demos',
33
- array( $this, 'create_admin_page' )
34
- );
35
- }
36
-
37
- /**
38
- * Settings page output
39
- *
40
- * @since 1.0.0
41
- */
42
- public function create_admin_page() {
43
-
44
- // Vars
45
- $ocean_url = 'https://oceanwp.org/';
46
- $demos = ODI_Importer::get_data();
47
- $brand = oceanwp_theme_branding(); ?>
48
-
49
- <div id="odi-demo-wrap" class="wrap">
50
-
51
- <h2><?php echo esc_attr( $brand ); ?> - <?php esc_attr_e( 'Install Demos', 'ocean-demo-import' ); ?></h2>
52
-
53
- <div class="updated error importer-notice importer-notice-1" style="display: none;">
54
-
55
- <p><?php esc_attr_e( 'We&rsquo;re sorry but the demo data could not be imported. It is most likely due to low PHP configurations on your server. You need to import the demo manually, look the second method from this article of the documentation:', 'ocean-demo-import' ); ?> <a href="http://docs.oceanwp.org/article/52-importing-the-sample-data/#manual-installation" target="_blank"><?php esc_attr_e( 'Importing the sample data', 'ocean-demo-import' ); ?></a></p>
56
-
57
- </div>
58
-
59
- <div class="updated importer-notice importer-notice-2" style="display: none;">
60
-
61
- <p><?php echo sprintf( esc_html__( 'Demo data successfully imported. Please check your page and make sure that everything has imported correctly. If it did, you can deactivate the %1$sOcean Demo Import%2$s plugin, because it has done its job.', 'ocean-demo-import' ), '<strong>', '</strong>' ); ?></p>
62
-
63
- </div>
64
-
65
- <div class="updated error importer-notice importer-notice-3" style="display: none;">
66
-
67
- <p><?php esc_attr_e( 'We&rsquo;re sorry but the demo data could not be imported. It is most likely due to low PHP configurations on your server. You need to import the demo manually, look the second method from this article of the documentation:', 'ocean-demo-import' ); ?> <a href="http://docs.oceanwp.org/article/52-importing-the-sample-data/#manual-installation" target="_blank"><?php esc_attr_e( 'Importing the sample data', 'ocean-demo-import' ); ?></a></p>
68
-
69
- </div>
70
-
71
- <div class="odi-important-notice notice notice-warning">
72
-
73
- <p><?php echo sprintf( esc_html__( 'Before you begin, make sure all the required plugins are activated. %1$sSee this article%2$s.', 'ocean-demo-import' ), '<a href="http://docs.oceanwp.org/article/52-importing-the-sample-data#plugins" target="_blank">', '</a>' ); ?></p>
74
-
75
- </div>
76
-
77
- <div class="odi-about-description">
78
-
79
- <?php
80
- if ( is_plugin_active( 'wordpress-database-reset/wp-reset.php' ) ) {
81
- $plugin_link = admin_url( 'tools.php?page=database-reset' );
82
- } else {
83
- $plugin_link = admin_url( 'plugin-install.php?s=Wordpress+Database+Reset&tab=search' );
84
- } ?>
85
-
86
- <p><?php echo sprintf( esc_html__( 'Importing demo data ( post, pages, images, customizer settings, ... ) is the easiest way to setup your theme. It will allow you to quickly edit everything instead of creating content from scratch. We recommend uploading sample data on a clean installation to prevent conflicts with your current content. You can use this plugin to reset your site if needed: %1$sWordpress Database Reset%2$s.', 'ocean-demo-import' ), '<a href="'. $plugin_link .'" target="_blank">', '</a>' ); ?></p>
87
-
88
- </div>
89
-
90
- <hr>
91
-
92
- <div class="theme-browser rendered">
93
-
94
- <?php
95
- // Categories
96
- $categories = ODI_Importer::get_all_categories( $demos ); ?>
97
-
98
- <?php if ( ! empty( $categories ) ) : ?>
99
- <div class="odi-header-bar">
100
- <nav class="odi-navigation">
101
- <ul>
102
- <li class="active"><a href="#all" class="odi-navigation-link"><?php esc_html_e( 'All', 'ocean-demo-import' ); ?></a></li>
103
- <?php foreach ( $categories as $key => $name ) : ?>
104
- <li><a href="#<?php echo esc_attr( $key ); ?>" class="odi-navigation-link"><?php echo esc_html( $name ); ?></a></li>
105
- <?php endforeach; ?>
106
- </ul>
107
- </nav>
108
- <div clas="odi-search">
109
- <input type="text" class="odi-search-input" name="odi-search" value="" placeholder="<?php esc_html_e( 'Search demos...', 'ocean-demo-import' ); ?>">
110
- </div>
111
- </div>
112
- <?php endif; ?>
113
-
114
- <div class="themes wp-clearfix">
115
-
116
- <?php
117
- // Loop through all demos
118
- foreach ( $demos as $demo => $key ) { ?>
119
-
120
- <div class="theme-wrap" data-categories="<?php echo esc_attr( ODI_Importer::get_item_categories( $key ) ); ?>" data-name="<?php echo esc_attr( strtolower( $demo ) ); ?>">
121
-
122
- <div class="theme">
123
-
124
- <div class="theme-screenshot odi-install" data-demo-id="<?php echo esc_attr( $demo ); ?>">
125
- <img src="https://raw.githubusercontent.com/oceanwp/oceanwp-sample-data/master/<?php echo esc_attr( $demo ); ?>/preview.jpg" />
126
-
127
- <div class="demo-import-loader preview-all preview-all-<?php echo esc_attr( $demo ); ?>"></div>
128
-
129
- <div class="demo-import-loader preview-icon preview-<?php echo esc_attr( $demo ); ?>"><i class="dashicons dashicons-update"></i></div>
130
-
131
- <div class="demo-import-loader success-icon success-<?php echo esc_attr( $demo ); ?>"><i class="dashicons dashicons-yes"></i></div>
132
-
133
- <div class="demo-import-loader warning-icon warning-<?php echo esc_attr( $demo ); ?>"><i class="dashicons dashicons-warning"></i></div>
134
- </div>
135
-
136
- <div class="theme-id-container">
137
-
138
- <h2 class="theme-name" id="<?php echo esc_attr( $demo ); ?>"><span><?php echo ucwords( $demo ); ?></span></h2>
139
-
140
- <div class="theme-actions">
141
- <a class="button button-secondary odi-install" data-demo-id="<?php echo esc_attr( $demo ); ?>" href="#"><?php _e( 'Install', 'ocean-demo-import' ); ?></a>
142
- <a class="button button-primary" href="https://<?php echo esc_attr( $demo ); ?>.oceanwp.org/" target="_blank"><?php _e( 'Preview', 'ocean-demo-import' ); ?></a>
143
- </div>
144
- </div>
145
-
146
- </div>
147
-
148
- </div>
149
-
150
- <?php } ?>
151
-
152
- </div>
153
-
154
- </div>
155
-
156
- </div>
157
-
158
- <?php }
159
- }
160
- new ODI_Install_Demos();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/temp.xml DELETED
File without changes
ocean-demo-import.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Ocean Demo Import
4
  * Plugin URI: https://oceanwp.org/extension/ocean-demo-import/
5
  * Description: Import the OceanWP demo content, widgets and customizer settings with one click.
6
- * Version: 1.0.7
7
  * Author: OceanWP
8
  * Author URI: https://oceanwp.org/
9
  * Requires at least: 4.0.0
@@ -87,16 +87,14 @@ final class Ocean_Demo_Import {
87
  $this->token = 'ocean-demo-import';
88
  $this->plugin_url = plugin_dir_url( __FILE__ );
89
  $this->plugin_path = plugin_dir_path( __FILE__ );
90
- $this->version = '1.0.7';
91
 
92
  define( 'ODI_PATH', $this->plugin_path );
93
  define( 'ODI_URL', $this->plugin_url );
94
 
95
  register_activation_hook( __FILE__, array( $this, 'install' ) );
96
 
97
- add_action( 'init', array( $this, 'odi_load_plugin_textdomain' ) );
98
-
99
- add_action( 'init', array( $this, 'odi_setup' ) );
100
  }
101
 
102
  /**
@@ -121,7 +119,7 @@ final class Ocean_Demo_Import {
121
  * @since 1.0.0
122
  * @return void
123
  */
124
- public function odi_load_plugin_textdomain() {
125
  load_plugin_textdomain( 'ocean-demo-import', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
126
  }
127
 
@@ -165,42 +163,4 @@ final class Ocean_Demo_Import {
165
  update_option( $this->token . '-version', $this->version );
166
  }
167
 
168
- /**
169
- * Setup all the things.
170
- * Only executes if OceanWP or a child theme using OceanWP as a parent is active and the extension specific filter returns true.
171
- * @return void
172
- */
173
- public function odi_setup() {
174
- $theme = wp_get_theme();
175
-
176
- if ( 'OceanWP' == $theme->name || 'oceanwp' == $theme->template ) {
177
- if ( is_admin()
178
- && version_compare( PHP_VERSION, '5.4', '>=' ) ) {
179
- require_once( ODI_PATH .'/includes/class/class-helpers.php' );
180
- require_once( ODI_PATH .'/includes/importer.php' );
181
- require_once( ODI_PATH .'/includes/install-demos.php' );
182
- }
183
- add_action( 'admin_enqueue_scripts', array( $this, 'odi_scripts' ) );
184
- }
185
- }
186
-
187
- /**
188
- * Load scripts
189
- *
190
- * @since 1.0.0
191
- */
192
- public static function odi_scripts( $hook_suffix ) {
193
-
194
- if ( 'theme-panel_page_oceanwp-panel-install-demos' == $hook_suffix ) {
195
-
196
- // CSS
197
- wp_enqueue_style( 'odi-style', plugins_url( '/assets/css/admin.min.css', __FILE__ ) );
198
-
199
- // JS
200
- wp_enqueue_script( 'odi-js', plugins_url( '/assets/js/admin.min.js', __FILE__ ) );
201
-
202
- }
203
-
204
- }
205
-
206
  } // End Class
3
  * Plugin Name: Ocean Demo Import
4
  * Plugin URI: https://oceanwp.org/extension/ocean-demo-import/
5
  * Description: Import the OceanWP demo content, widgets and customizer settings with one click.
6
+ * Version: 1.0.8
7
  * Author: OceanWP
8
  * Author URI: https://oceanwp.org/
9
  * Requires at least: 4.0.0
87
  $this->token = 'ocean-demo-import';
88
  $this->plugin_url = plugin_dir_url( __FILE__ );
89
  $this->plugin_path = plugin_dir_path( __FILE__ );
90
+ $this->version = '1.0.8';
91
 
92
  define( 'ODI_PATH', $this->plugin_path );
93
  define( 'ODI_URL', $this->plugin_url );
94
 
95
  register_activation_hook( __FILE__, array( $this, 'install' ) );
96
 
97
+ add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
 
 
98
  }
99
 
100
  /**
119
  * @since 1.0.0
120
  * @return void
121
  */
122
+ public function load_plugin_textdomain() {
123
  load_plugin_textdomain( 'ocean-demo-import', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
124
  }
125
 
163
  update_option( $this->token . '-version', $this->version );
164
  }
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  } // End Class
readme.txt CHANGED
@@ -2,15 +2,15 @@
2
  Contributors: oceanwp
3
  Tags: import, content, demo, data, widgets, settings, oceanwp
4
  Requires at least: 4.0
5
- Tested up to: 4.9.1
6
- Stable tag: 1.0.7
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
  == Description ==
11
 
12
  Import the OceanWP demo content, widgets and customizer settings with one click.
13
- This plugin requires the [OceanWP](https://oceanwp.org) theme to be installed.
14
 
15
  == Installation ==
16
 
@@ -30,6 +30,10 @@ This plugin will only work with the [OceanWP](https://oceanwp.org/) theme.
30
 
31
  == Changelog ==
32
 
 
 
 
 
33
  = 1.0.7 =
34
  - Fixed: Install buttons style.
35
  - Added: Spanish language, thank you to Angel Julian Mena.
2
  Contributors: oceanwp
3
  Tags: import, content, demo, data, widgets, settings, oceanwp
4
  Requires at least: 4.0
5
+ Tested up to: 4.9.4
6
+ Stable tag: 1.0.8
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
  == Description ==
11
 
12
  Import the OceanWP demo content, widgets and customizer settings with one click.
13
+ This plugin requires the [OceanWP](https://oceanwp.org/) theme to be installed.
14
 
15
  == Installation ==
16
 
30
 
31
  == Changelog ==
32
 
33
+ = 1.0.8 =
34
+ -Added: Now you will have two steps to import a demo, in the second step, you will be able to import only the XML file and/or the customizer settings and/or the widgets.
35
+ -Tweak: Much better approch to import a demo, now you just need to click the demo you want to import, install the required plugins and wait for the import.
36
+
37
  = 1.0.7 =
38
  - Fixed: Install buttons style.
39
  - Added: Spanish language, thank you to Angel Julian Mena.