Completed
Push — master ( 0cb291...9bc524 )
by J.D.
14s queued 10s
created
src/admin/screens/importing.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( true !== current_user_can( 'manage_options' ) ) {
11
-	wp_die();
11
+    wp_die();
12 12
 }
13 13
 
14 14
 check_admin_referer( 'wordpoints_import' );
Please login to merge, or discard this patch.
tests/phpunit/includes/activate-cubepoints-components.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
  */
9 9
 
10 10
 foreach ( $data as $module_slug ) {
11
-	cp_module_activation_set( $module_slug, 'active' );
11
+    cp_module_activation_set( $module_slug, 'active' );
12 12
 }
13 13
 
14 14
 // EOF
Please login to merge, or discard this patch.
tests/codeception/_support/AcceptanceTester.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
  * @since 1.0.0
14 14
  */
15 15
 class AcceptanceTester extends \WordPoints\Tests\Codeception\AcceptanceTester {
16
-	// Add any methods here that you want.
16
+    // Add any methods here that you want.
17 17
 }
18 18
 
19 19
 // EOF
Please login to merge, or discard this patch.
src/importer.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
  */
28 28
 
29 29
 wordpoints_register_extension(
30
-	'
30
+    '
31 31
 		Extension Name: Importer
32 32
 		Author:         J.D. Grimes
33 33
 		Author URI:     https://codesymphony.co/
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 		ID:             430
42 42
 		Namespace:      Importer
43 43
 	'
44
-	, __FILE__
44
+    , __FILE__
45 45
 );
46 46
 
47 47
 WordPoints_Class_Autoloader::register_dir( dirname( __FILE__ ) . '/includes' );
@@ -55,12 +55,12 @@  discard block
 block discarded – undo
55 55
 
56 56
 if ( is_admin() ) {
57 57
 
58
-	/**
59
-	 * The extension's admin-side code.
60
-	 *
61
-	 * @since 1.0.0
62
-	 */
63
-	require_once dirname( __FILE__ ) . '/admin/admin.php';
58
+    /**
59
+     * The extension's admin-side code.
60
+     *
61
+     * @since 1.0.0
62
+     */
63
+    require_once dirname( __FILE__ ) . '/admin/admin.php';
64 64
 }
65 65
 
66 66
 // EOF
Please login to merge, or discard this patch.
src/admin/admin.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -14,23 +14,23 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wordpoints_importer_admin_menu() {
16 16
 
17
-	add_submenu_page(
18
-		wordpoints_get_main_admin_menu()
19
-		,__( 'WordPoints — Import', 'wordpoints-importer' )
20
-		,__( 'Import', 'wordpoints-importer' )
21
-		,'manage_options'
22
-		,'wordpoints_import'
23
-		,'wordpoints_import_admin_screen'
24
-	);
25
-
26
-	add_submenu_page(
27
-		'_wordpoints_import' // Fake.
28
-		,__( 'WordPoints — Importing', 'wordpoints-importer' )
29
-		,__( 'Importing', 'wordpoints-importer' )
30
-		,'manage_options'
31
-		,'wordpoints_importing'
32
-		,'wordpoints_importing_admin_screen'
33
-	);
17
+    add_submenu_page(
18
+        wordpoints_get_main_admin_menu()
19
+        ,__( 'WordPoints — Import', 'wordpoints-importer' )
20
+        ,__( 'Import', 'wordpoints-importer' )
21
+        ,'manage_options'
22
+        ,'wordpoints_import'
23
+        ,'wordpoints_import_admin_screen'
24
+    );
25
+
26
+    add_submenu_page(
27
+        '_wordpoints_import' // Fake.
28
+        ,__( 'WordPoints — Importing', 'wordpoints-importer' )
29
+        ,__( 'Importing', 'wordpoints-importer' )
30
+        ,'manage_options'
31
+        ,'wordpoints_importing'
32
+        ,'wordpoints_importing_admin_screen'
33
+    );
34 34
 }
35 35
 add_action( 'admin_menu', 'wordpoints_importer_admin_menu' );
36 36
 add_action( 'network_admin_menu', 'wordpoints_importer_admin_menu' );
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
  */
43 43
 function wordpoints_import_admin_screen() {
44 44
 
45
-	/**
46
-	 * The importer admin screen.
47
-	 *
48
-	 * @since 1.0.0
49
-	 */
50
-	require dirname( __FILE__ ) . '/screens/import.php';
45
+    /**
46
+     * The importer admin screen.
47
+     *
48
+     * @since 1.0.0
49
+     */
50
+    require dirname( __FILE__ ) . '/screens/import.php';
51 51
 }
52 52
 
53 53
 /**
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
  */
58 58
 function wordpoints_importing_admin_screen() {
59 59
 
60
-	/**
61
-	 * The importer admin screen.
62
-	 *
63
-	 * @since 1.0.0
64
-	 */
65
-	require dirname( __FILE__ ) . '/screens/importing.php';
60
+    /**
61
+     * The importer admin screen.
62
+     *
63
+     * @since 1.0.0
64
+     */
65
+    require dirname( __FILE__ ) . '/screens/importing.php';
66 66
 }
67 67
 
68 68
 /**
@@ -72,17 +72,17 @@  discard block
 block discarded – undo
72 72
  */
73 73
 function wordpoints_importer_register_admin_scripts() {
74 74
 
75
-	$assets_url = wordpoints_extensions_url(
76
-		'admin/assets'
77
-		, dirname( dirname( __FILE__ ) ) . '/importer.php'
78
-	);
75
+    $assets_url = wordpoints_extensions_url(
76
+        'admin/assets'
77
+        , dirname( dirname( __FILE__ ) ) . '/importer.php'
78
+    );
79 79
 
80
-	$suffix = SCRIPT_DEBUG ? '' : '.min';
80
+    $suffix = SCRIPT_DEBUG ? '' : '.min';
81 81
 
82
-	wp_register_style(
83
-		'wordpoints-importer-feedback'
84
-		, "{$assets_url}/css/feedback{$suffix}.css"
85
-	);
82
+    wp_register_style(
83
+        'wordpoints-importer-feedback'
84
+        , "{$assets_url}/css/feedback{$suffix}.css"
85
+    );
86 86
 }
87 87
 add_action( 'init', 'wordpoints_importer_register_admin_scripts' );
88 88
 
@@ -93,41 +93,41 @@  discard block
 block discarded – undo
93 93
  */
94 94
 function wordpoints_importer_do_import() {
95 95
 
96
-	if ( ! defined( 'IFRAME_REQUEST' ) ) {
97
-		define( 'IFRAME_REQUEST', true );
98
-	}
96
+    if ( ! defined( 'IFRAME_REQUEST' ) ) {
97
+        define( 'IFRAME_REQUEST', true );
98
+    }
99 99
 
100
-	if ( ! current_user_can( 'manage_options' ) ) {
101
-		wp_die( esc_html__( 'Sorry, you are not allowed to import to WordPoints.', 'wordpoints-importer' ) );
102
-	}
100
+    if ( ! current_user_can( 'manage_options' ) ) {
101
+        wp_die( esc_html__( 'Sorry, you are not allowed to import to WordPoints.', 'wordpoints-importer' ) );
102
+    }
103 103
 
104
-	check_admin_referer( 'wordpoints_import' );
104
+    check_admin_referer( 'wordpoints_import' );
105 105
 
106
-	if ( ! isset( $_GET['importer'] ) ) {
107
-		wp_die( esc_html__( 'No importer selected.', 'wordpoints-importer' ) );
108
-	}
106
+    if ( ! isset( $_GET['importer'] ) ) {
107
+        wp_die( esc_html__( 'No importer selected.', 'wordpoints-importer' ) );
108
+    }
109 109
 
110
-	$importer = WordPoints_Importers::get_importer(
111
-		sanitize_key( $_GET['importer'] )
112
-	);
110
+    $importer = WordPoints_Importers::get_importer(
111
+        sanitize_key( $_GET['importer'] )
112
+    );
113 113
 
114
-	if ( ! ( $importer instanceof WordPoints_Importer ) ) {
115
-		wp_die( esc_html__( 'Importer not installed.', 'wordpoints-importer' ) );
116
-	}
114
+    if ( ! ( $importer instanceof WordPoints_Importer ) ) {
115
+        wp_die( esc_html__( 'Importer not installed.', 'wordpoints-importer' ) );
116
+    }
117 117
 
118
-	wp_enqueue_style( 'wordpoints-importer-feedback' );
118
+    wp_enqueue_style( 'wordpoints-importer-feedback' );
119 119
 
120
-	$args = array();
120
+    $args = array();
121 121
 
122
-	if ( isset( $_GET['wordpoints_import'] ) && is_array( $_GET['wordpoints_import'] ) ) {
123
-		$args = wp_unslash( $_GET['wordpoints_import'] ); // WPCS: sanitization OK.
124
-	}
122
+    if ( isset( $_GET['wordpoints_import'] ) && is_array( $_GET['wordpoints_import'] ) ) {
123
+        $args = wp_unslash( $_GET['wordpoints_import'] ); // WPCS: sanitization OK.
124
+    }
125 125
 
126
-	iframe_header();
126
+    iframe_header();
127 127
 
128
-	$importer->do_import( $args );
128
+    $importer->do_import( $args );
129 129
 
130
-	iframe_footer();
130
+    iframe_footer();
131 131
 }
132 132
 add_action( 'update-custom_wordpoints_import', 'wordpoints_importer_do_import' );
133 133
 
@@ -138,9 +138,9 @@  discard block
 block discarded – undo
138 138
  */
139 139
 function wordpoints_importer_admin_screen_points_type_select() {
140 140
 
141
-	$args = array( 'name' => 'wordpoints_import[points][_data][points_type]' );
141
+    $args = array( 'name' => 'wordpoints_import[points][_data][points_type]' );
142 142
 
143
-	?>
143
+    ?>
144 144
 
145 145
 	<p>
146 146
 		<label for="wordpoints_import[points][_data][points_type]">
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
 	<?php
153 153
 }
154 154
 add_action(
155
-	'wordpoints_importer_before_component_options-points'
156
-	, 'wordpoints_importer_admin_screen_points_type_select'
155
+    'wordpoints_importer_before_component_options-points'
156
+    , 'wordpoints_importer_admin_screen_points_type_select'
157 157
 );
158 158
 
159 159
 /**
@@ -169,24 +169,24 @@  discard block
 block discarded – undo
169 169
  */
170 170
 function wordpoints_importer_validate_points_type_setting( $valid, $settings, $feedback ) {
171 171
 
172
-	if ( $valid ) {
172
+    if ( $valid ) {
173 173
 
174
-		if ( ! isset( $settings['points_type'] ) ) {
175
-			$feedback->warning( __( 'Skipping Points component—no points type specified.', 'wordpoints-importer' ) );
176
-			$valid = false;
177
-		} elseif ( ! wordpoints_is_points_type( $settings['points_type'] ) ) {
178
-			$feedback->warning( __( 'Skipping Points component—invalid points type selected.', 'wordpoints-importer' ) );
179
-			$valid = false;
180
-		}
181
-	}
174
+        if ( ! isset( $settings['points_type'] ) ) {
175
+            $feedback->warning( __( 'Skipping Points component—no points type specified.', 'wordpoints-importer' ) );
176
+            $valid = false;
177
+        } elseif ( ! wordpoints_is_points_type( $settings['points_type'] ) ) {
178
+            $feedback->warning( __( 'Skipping Points component—invalid points type selected.', 'wordpoints-importer' ) );
179
+            $valid = false;
180
+        }
181
+    }
182 182
 
183
-	return $valid;
183
+    return $valid;
184 184
 }
185 185
 add_action(
186
-	'wordpoints_import_settings_valid-points'
187
-	, 'wordpoints_importer_validate_points_type_setting'
188
-	, 10
189
-	, 3
186
+    'wordpoints_import_settings_valid-points'
187
+    , 'wordpoints_importer_validate_points_type_setting'
188
+    , 10
189
+    , 3
190 190
 );
191 191
 
192 192
 /**
@@ -196,20 +196,20 @@  discard block
 block discarded – undo
196 196
  */
197 197
 function wordpoints_importer_admin_screen_rank_group_select() {
198 198
 
199
-	$rank_groups = WordPoints_Rank_Groups::get();
199
+    $rank_groups = WordPoints_Rank_Groups::get();
200 200
 
201
-	// See https://github.com/WordPoints/wordpoints/issues/310.
202
-	$options = array();
203
-	foreach ( $rank_groups as $rank_group ) {
204
-		$options[ $rank_group->slug ] = $rank_group->name;
205
-	}
201
+    // See https://github.com/WordPoints/wordpoints/issues/310.
202
+    $options = array();
203
+    foreach ( $rank_groups as $rank_group ) {
204
+        $options[ $rank_group->slug ] = $rank_group->name;
205
+    }
206 206
 
207
-	$dropdown = new WordPoints_Dropdown_Builder(
208
-		$options
209
-		, array( 'name' => 'wordpoints_import[ranks][_data][rank_group]' )
210
-	);
207
+    $dropdown = new WordPoints_Dropdown_Builder(
208
+        $options
209
+        , array( 'name' => 'wordpoints_import[ranks][_data][rank_group]' )
210
+    );
211 211
 
212
-	?>
212
+    ?>
213 213
 
214 214
 	<p>
215 215
 		<label for="wordpoints_import[ranks][_data][rank_group]">
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
 <?php
222 222
 }
223 223
 add_action(
224
-	'wordpoints_importer_before_component_options-ranks'
225
-	, 'wordpoints_importer_admin_screen_rank_group_select'
224
+    'wordpoints_importer_before_component_options-ranks'
225
+    , 'wordpoints_importer_admin_screen_rank_group_select'
226 226
 );
227 227
 
228 228
 /**
@@ -238,24 +238,24 @@  discard block
 block discarded – undo
238 238
  */
239 239
 function wordpoints_importer_validate_rank_group_setting( $valid, $settings, $feedback ) {
240 240
 
241
-	if ( $valid ) {
241
+    if ( $valid ) {
242 242
 
243
-		if ( ! isset( $settings['rank_group'] ) ) {
244
-			$feedback->warning( __( 'Skipping Ranks component—no rank group specified.', 'wordpoints-importer' ) );
245
-			$valid = false;
246
-		} elseif ( ! WordPoints_Rank_Groups::is_group_registered( $settings['rank_group'] ) ) {
247
-			$feedback->warning( __( 'Skipping Ranks component—invalid rank group selected.', 'wordpoints-importer' ) );
248
-			$valid = false;
249
-		}
250
-	}
243
+        if ( ! isset( $settings['rank_group'] ) ) {
244
+            $feedback->warning( __( 'Skipping Ranks component—no rank group specified.', 'wordpoints-importer' ) );
245
+            $valid = false;
246
+        } elseif ( ! WordPoints_Rank_Groups::is_group_registered( $settings['rank_group'] ) ) {
247
+            $feedback->warning( __( 'Skipping Ranks component—invalid rank group selected.', 'wordpoints-importer' ) );
248
+            $valid = false;
249
+        }
250
+    }
251 251
 
252
-	return $valid;
252
+    return $valid;
253 253
 }
254 254
 add_action(
255
-	'wordpoints_import_settings_valid-ranks'
256
-	, 'wordpoints_importer_validate_rank_group_setting'
257
-	, 10
258
-	, 3
255
+    'wordpoints_import_settings_valid-ranks'
256
+    , 'wordpoints_importer_validate_rank_group_setting'
257
+    , 10
258
+    , 3
259 259
 );
260 260
 
261 261
 // EOF
Please login to merge, or discard this patch.
src/admin/screens/import.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( true !== current_user_can( 'manage_options' ) ) {
11
-	wp_die();
11
+    wp_die();
12 12
 }
13 13
 
14 14
 $tabs = array( 'unavailable' => __( 'Unavailable', 'wordpoints-importer' ) );
@@ -16,19 +16,19 @@  discard block
 block discarded – undo
16 16
 
17 17
 foreach ( WordPoints_Importers::get() as $slug => $args ) {
18 18
 
19
-	$importer = WordPoints_Importers::get_importer( $slug );
19
+    $importer = WordPoints_Importers::get_importer( $slug );
20 20
 
21
-	$is_available = $importer->is_available();
21
+    $is_available = $importer->is_available();
22 22
 
23
-	if ( is_wp_error( $is_available ) ) {
24
-		$unavailable[ $args['name'] ] = $is_available;
25
-	} else {
26
-		$tabs[ $slug ] = $args['name'];
27
-	}
23
+    if ( is_wp_error( $is_available ) ) {
24
+        $unavailable[ $args['name'] ] = $is_available;
25
+    } else {
26
+        $tabs[ $slug ] = $args['name'];
27
+    }
28 28
 }
29 29
 
30 30
 if ( empty( $unavailable ) ) {
31
-	unset( $tabs['unavailable'] );
31
+    unset( $tabs['unavailable'] );
32 32
 }
33 33
 
34 34
 $current_tab = wordpoints_admin_get_current_tab( $tabs );
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
 				<li>
52 52
 					<?php
53 53
 
54
-					printf(
55
-						/* translators: 1 is an importer name, 2 is the reason that it is unavailable. */
56
-						esc_html__( '%1$s — %2$s', 'wordpoints-importer' )
57
-						, '<strong>' . esc_html( $name ) . '</strong>'
58
-						, esc_html( $error->get_error_message() )
59
-					);
54
+                    printf(
55
+                        /* translators: 1 is an importer name, 2 is the reason that it is unavailable. */
56
+                        esc_html__( '%1$s — %2$s', 'wordpoints-importer' )
57
+                        , '<strong>' . esc_html( $name ) . '</strong>'
58
+                        , esc_html( $error->get_error_message() )
59
+                    );
60 60
 
61
-					?>
61
+                    ?>
62 62
 				</li>
63 63
 			<?php endforeach; ?>
64 64
 		</ul>
@@ -74,39 +74,39 @@  discard block
 block discarded – undo
74 74
 
75 75
 				<?php
76 76
 
77
-				if ( ! $importer->supports_component( $slug ) ) {
78
-					continue;
79
-				}
77
+                if ( ! $importer->supports_component( $slug ) ) {
78
+                    continue;
79
+                }
80 80
 
81
-				$supported = true;
81
+                $supported = true;
82 82
 
83
-				?>
83
+                ?>
84 84
 
85 85
 				<h3><?php echo esc_html( $component['name'] ); ?></h3>
86 86
 
87 87
 				<?php
88 88
 
89
-				/**
90
-				 * Before the import option fields for a component.
91
-				 *
92
-				 * @since 1.0.0
93
-				 */
94
-				do_action( "wordpoints_importer_before_component_options-{$slug}" );
89
+                /**
90
+                 * Before the import option fields for a component.
91
+                 *
92
+                 * @since 1.0.0
93
+                 */
94
+                do_action( "wordpoints_importer_before_component_options-{$slug}" );
95 95
 
96
-				?>
96
+                ?>
97 97
 
98 98
 				<?php foreach ( $importer->get_options_for_component( $slug ) as $name => $option ) : ?>
99 99
 
100 100
 					<?php
101 101
 
102
-					$can_import = true;
102
+                    $can_import = true;
103 103
 
104
-					// Check if this option is available.
105
-					if ( isset( $option['can_import'] ) ) {
106
-						$can_import = call_user_func( $option['can_import'], array() );
107
-					}
104
+                    // Check if this option is available.
105
+                    if ( isset( $option['can_import'] ) ) {
106
+                        $can_import = call_user_func( $option['can_import'], array() );
107
+                    }
108 108
 
109
-					?>
109
+                    ?>
110 110
 
111 111
 					<label for="wordpoints_import[<?php echo esc_attr( $slug ); ?>][<?php echo esc_attr( $name ); ?>]">
112 112
 						<input type="checkbox" value="1" id="wordpoints_import[<?php echo esc_attr( $slug ); ?>][<?php echo esc_attr( $name ); ?>]" name="wordpoints_import[<?php echo esc_attr( $slug ); ?>][<?php echo esc_attr( $name ); ?>]" <?php disabled( is_wp_error( $can_import ), true ); ?> />
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
 							<em>
117 117
 								<?php
118 118
 
119
-								// translators: Error message explaining the reason why the importer is disabled.
120
-								printf( esc_html__( 'Disabled (%s)', 'wordpoints-importer' ), esc_html( $can_import->get_error_message() ) );
119
+                                // translators: Error message explaining the reason why the importer is disabled.
120
+                                printf( esc_html__( 'Disabled (%s)', 'wordpoints-importer' ), esc_html( $can_import->get_error_message() ) );
121 121
 
122
-								?>
122
+                                ?>
123 123
 							</em>
124 124
 						<?php endif; ?>
125 125
 					</label>
@@ -140,20 +140,20 @@  discard block
 block discarded – undo
140 140
 
141 141
 			<?php
142 142
 
143
-			if ( ! isset( $supported ) ) {
143
+            if ( ! isset( $supported ) ) {
144 144
 
145
-				esc_html_e(
146
-					'This importer does not support any of the installed components.'
147
-					, 'wordpoints-importer'
148
-				);
145
+                esc_html_e(
146
+                    'This importer does not support any of the installed components.'
147
+                    , 'wordpoints-importer'
148
+                );
149 149
 
150
-			} else {
150
+            } else {
151 151
 
152
-				wp_nonce_field( 'wordpoints_import' );
153
-				submit_button( __( 'Import', 'wordpoints-importer' ) );
154
-			}
152
+                wp_nonce_field( 'wordpoints_import' );
153
+                submit_button( __( 'Import', 'wordpoints-importer' ) );
154
+            }
155 155
 
156
-			?>
156
+            ?>
157 157
 		</form>
158 158
 	<?php endif; ?>
159 159
 </div>
Please login to merge, or discard this patch.
src/includes/class-importer.php 1 patch
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -14,237 +14,237 @@
 block discarded – undo
14 14
  */
15 15
 abstract class WordPoints_Importer {
16 16
 
17
-	/**
18
-	 * The name of the importer.
19
-	 *
20
-	 * @since 1.0.0
21
-	 *
22
-	 * @type string $name
23
-	 */
24
-	protected $name;
25
-
26
-	/**
27
-	 * The components supported by this importer.
28
-	 *
29
-	 * The keys are the component slugs, the values arrays of options for importing
30
-	 * to that component.
31
-	 *
32
-	 * @since 1.0.0
33
-	 *
34
-	 * @type array[] $components
35
-	 */
36
-	protected $components = array();
37
-
38
-	/**
39
-	 * The feedback provider object.
40
-	 *
41
-	 * This is only set by self::do_import().
42
-	 *
43
-	 * @since 1.0.0
44
-	 *
45
-	 * @type WordPoints_Importer_Feedback $feedback
46
-	 */
47
-	protected $feedback;
48
-
49
-	/**
50
-	 * Check if this importer is available.
51
-	 *
52
-	 * @since 1.0.0
53
-	 *
54
-	 * @return true|WP_Error A WP_Error if the importer is not available.
55
-	 */
56
-	abstract public function is_available();
57
-
58
-	/**
59
-	 * Construct the importer.
60
-	 *
61
-	 * @since 1.0.0
62
-	 *
63
-	 * @param string $name The name of the importer.
64
-	 */
65
-	public function __construct( $name ) {
66
-
67
-		$this->name = $name;
68
-	}
69
-
70
-	/**
71
-	 * Check if this importer supports a specific component.
72
-	 *
73
-	 * @since 1.0.0
74
-	 *
75
-	 * @param string $component The slug of a component.
76
-	 *
77
-	 * @return bool True if the component is supported, otherwise false.
78
-	 */
79
-	public function supports_component( $component ) {
80
-
81
-		return isset( $this->components[ $component ] );
82
-	}
83
-
84
-	/**
85
-	 * Get the import options for a component.
86
-	 *
87
-	 * @since 1.0.0
88
-	 *
89
-	 * @param string $component The slug of a component.
90
-	 *
91
-	 * @return array[] The options for this component.
92
-	 */
93
-	public function get_options_for_component( $component ) {
94
-
95
-		if ( ! $this->supports_component( $component ) ) {
96
-			return array();
97
-		}
98
-
99
-		return $this->components[ $component ];
100
-	}
101
-
102
-	/**
103
-	 * Run the import.
104
-	 *
105
-	 * @since 1.0.0
106
-	 *
107
-	 * @param array                        $args     The settings for the import.
108
-	 * @param WordPoints_Importer_Feedback $feedback The feedback object.
109
-	 */
110
-	public function do_import( array $args, $feedback = null ) {
111
-
112
-		if ( ! ( $feedback instanceof WordPoints_Importer_Feedback ) ) {
113
-			$feedback = new WordPoints_Importer_Feedback();
114
-		}
115
-
116
-		$this->feedback = $feedback;
117
-
118
-		// translators: Plugin name.
119
-		$this->feedback->info( sprintf( __( 'Importing from %s&hellip;', 'wordpoints-importer' ), $this->name ) );
120
-
121
-		$this->no_interruptions();
122
-
123
-		foreach ( $args as $component => $options ) {
124
-			$this->do_import_for_component( $component, $options );
125
-		}
126
-
127
-		$this->feedback->info( __( 'Import complete.', 'wordpoints-importer' ) );
128
-	}
129
-
130
-	/**
131
-	 * Prevent any interruptions from occurring during the import.
132
-	 *
133
-	 * @since 1.2.1
134
-	 */
135
-	protected function no_interruptions() {
136
-
137
-		wordpoints_prevent_interruptions();
138
-	}
139
-
140
-	/**
141
-	 * Validate the import settings for a component.
142
-	 *
143
-	 * @since 1.0.0
144
-	 *
145
-	 * @param string $component The slug of the component.
146
-	 * @param array  $settings  The settings supplied for this component.
147
-	 *
148
-	 * @return bool Whether the settings are valid.
149
-	 */
150
-	protected function validate_import_settings( $component, $settings ) {
151
-
152
-		/**
153
-		 * Filter whether the settings are valid before importing.
154
-		 *
155
-		 * @since 1.0.0
156
-		 *
157
-		 * @param bool  $valid    Whether the settings are valid.
158
-		 * @param array $settings The settings for this component.
159
-		 * @param WordPoints_Importer_Feedback $feedback The feedback object.
160
-		 */
161
-		return apply_filters( "wordpoints_import_settings_valid-{$component}", true, $settings, $this->feedback );
162
-	}
163
-
164
-	/**
165
-	 * Run the import for a component.
166
-	 *
167
-	 * @since 1.0.0
168
-	 *
169
-	 * @param string $component The component to run the import for.
170
-	 * @param array  $options   The selected options of what to import.
171
-	 */
172
-	protected function do_import_for_component( $component, $options ) {
173
-
174
-		$component_data = WordPoints_Components::instance()->get_component(
175
-			$component
176
-		);
177
-
178
-		if ( false === $component_data ) {
179
-			// translators: Component name.
180
-			$this->feedback->warning( sprintf( __( 'Skipping %s component—not installed.', 'wordpoints-importer' ), esc_html( $component ) ) );
181
-			return;
182
-		}
183
-
184
-		if ( true !== $this->supports_component( $component ) ) {
185
-			// translators: Component name.
186
-			$this->feedback->warning( sprintf( __( 'Skipping the %s component—not supported.', 'wordpoints-importer' ), $component_data['name'] ) );
187
-			return;
188
-		}
189
-
190
-		$settings = array();
191
-
192
-		if ( isset( $options['_data'] ) ) {
193
-			$settings = $options['_data'];
194
-			unset( $options['_data'] );
195
-		}
196
-
197
-		if ( empty( $options ) || ! $this->validate_import_settings( $component, $settings ) ) {
198
-			return;
199
-		}
200
-
201
-		// translators: Component name.
202
-		$this->feedback->info( sprintf( __( 'Importing data to the %s component&hellip;', 'wordpoints-importer' ), $component_data['name'] ) );
203
-
204
-		foreach ( $options as $option => $unused ) {
205
-			$this->do_import_for_option( $option, $component, $settings );
206
-		}
207
-	}
208
-
209
-	/**
210
-	 * Run the import for an option.
211
-	 *
212
-	 * The import is split up into different options which the user can select (these
213
-	 * are displayed to the user as checkboxes in the form). This handles the import
214
-	 * for each of the individual things the user has selected to import. These are
215
-	 * all optional, so each is just termed an import "option" here.
216
-	 *
217
-	 * @since 1.0.0
218
-	 *
219
-	 * @param string $option    An import option that has been selected.
220
-	 * @param string $component The component this option is for.
221
-	 * @param array  $settings  Other settings for this component.
222
-	 */
223
-	protected function do_import_for_option( $option, $component, $settings ) {
224
-
225
-		if ( ! isset( $this->components[ $component ][ $option ] ) ) {
226
-			// translators: Option name.
227
-			$this->feedback->warning( sprintf( __( 'Skipping unrecognized import option &#8220;%s&#8221;&hellip;', 'wordpoints-importer' ), $option ) );
228
-			return;
229
-		}
230
-
231
-		$option_data = $this->components[ $component ][ $option ];
232
-
233
-		// Check if we can actually run this option.
234
-		if ( isset( $option_data['can_import'] ) ) {
235
-
236
-			$cant_import = call_user_func( $option_data['can_import'], $settings );
237
-
238
-			if ( is_wp_error( $cant_import ) ) {
239
-				// translators: 1. Option name; 2. Reason the import was skipped.
240
-				$this->feedback->warning( sprintf( __( 'Skipping importing %1$s. Reason: %2$s', 'wordpoints-importer' ), $option_data['label'], $cant_import->get_error_message() ) );
241
-				return;
242
-			}
243
-		}
244
-
245
-		// OK, we can run the import method for this option.
246
-		call_user_func( $option_data['function'], $settings );
247
-	}
17
+    /**
18
+     * The name of the importer.
19
+     *
20
+     * @since 1.0.0
21
+     *
22
+     * @type string $name
23
+     */
24
+    protected $name;
25
+
26
+    /**
27
+     * The components supported by this importer.
28
+     *
29
+     * The keys are the component slugs, the values arrays of options for importing
30
+     * to that component.
31
+     *
32
+     * @since 1.0.0
33
+     *
34
+     * @type array[] $components
35
+     */
36
+    protected $components = array();
37
+
38
+    /**
39
+     * The feedback provider object.
40
+     *
41
+     * This is only set by self::do_import().
42
+     *
43
+     * @since 1.0.0
44
+     *
45
+     * @type WordPoints_Importer_Feedback $feedback
46
+     */
47
+    protected $feedback;
48
+
49
+    /**
50
+     * Check if this importer is available.
51
+     *
52
+     * @since 1.0.0
53
+     *
54
+     * @return true|WP_Error A WP_Error if the importer is not available.
55
+     */
56
+    abstract public function is_available();
57
+
58
+    /**
59
+     * Construct the importer.
60
+     *
61
+     * @since 1.0.0
62
+     *
63
+     * @param string $name The name of the importer.
64
+     */
65
+    public function __construct( $name ) {
66
+
67
+        $this->name = $name;
68
+    }
69
+
70
+    /**
71
+     * Check if this importer supports a specific component.
72
+     *
73
+     * @since 1.0.0
74
+     *
75
+     * @param string $component The slug of a component.
76
+     *
77
+     * @return bool True if the component is supported, otherwise false.
78
+     */
79
+    public function supports_component( $component ) {
80
+
81
+        return isset( $this->components[ $component ] );
82
+    }
83
+
84
+    /**
85
+     * Get the import options for a component.
86
+     *
87
+     * @since 1.0.0
88
+     *
89
+     * @param string $component The slug of a component.
90
+     *
91
+     * @return array[] The options for this component.
92
+     */
93
+    public function get_options_for_component( $component ) {
94
+
95
+        if ( ! $this->supports_component( $component ) ) {
96
+            return array();
97
+        }
98
+
99
+        return $this->components[ $component ];
100
+    }
101
+
102
+    /**
103
+     * Run the import.
104
+     *
105
+     * @since 1.0.0
106
+     *
107
+     * @param array                        $args     The settings for the import.
108
+     * @param WordPoints_Importer_Feedback $feedback The feedback object.
109
+     */
110
+    public function do_import( array $args, $feedback = null ) {
111
+
112
+        if ( ! ( $feedback instanceof WordPoints_Importer_Feedback ) ) {
113
+            $feedback = new WordPoints_Importer_Feedback();
114
+        }
115
+
116
+        $this->feedback = $feedback;
117
+
118
+        // translators: Plugin name.
119
+        $this->feedback->info( sprintf( __( 'Importing from %s&hellip;', 'wordpoints-importer' ), $this->name ) );
120
+
121
+        $this->no_interruptions();
122
+
123
+        foreach ( $args as $component => $options ) {
124
+            $this->do_import_for_component( $component, $options );
125
+        }
126
+
127
+        $this->feedback->info( __( 'Import complete.', 'wordpoints-importer' ) );
128
+    }
129
+
130
+    /**
131
+     * Prevent any interruptions from occurring during the import.
132
+     *
133
+     * @since 1.2.1
134
+     */
135
+    protected function no_interruptions() {
136
+
137
+        wordpoints_prevent_interruptions();
138
+    }
139
+
140
+    /**
141
+     * Validate the import settings for a component.
142
+     *
143
+     * @since 1.0.0
144
+     *
145
+     * @param string $component The slug of the component.
146
+     * @param array  $settings  The settings supplied for this component.
147
+     *
148
+     * @return bool Whether the settings are valid.
149
+     */
150
+    protected function validate_import_settings( $component, $settings ) {
151
+
152
+        /**
153
+         * Filter whether the settings are valid before importing.
154
+         *
155
+         * @since 1.0.0
156
+         *
157
+         * @param bool  $valid    Whether the settings are valid.
158
+         * @param array $settings The settings for this component.
159
+         * @param WordPoints_Importer_Feedback $feedback The feedback object.
160
+         */
161
+        return apply_filters( "wordpoints_import_settings_valid-{$component}", true, $settings, $this->feedback );
162
+    }
163
+
164
+    /**
165
+     * Run the import for a component.
166
+     *
167
+     * @since 1.0.0
168
+     *
169
+     * @param string $component The component to run the import for.
170
+     * @param array  $options   The selected options of what to import.
171
+     */
172
+    protected function do_import_for_component( $component, $options ) {
173
+
174
+        $component_data = WordPoints_Components::instance()->get_component(
175
+            $component
176
+        );
177
+
178
+        if ( false === $component_data ) {
179
+            // translators: Component name.
180
+            $this->feedback->warning( sprintf( __( 'Skipping %s component—not installed.', 'wordpoints-importer' ), esc_html( $component ) ) );
181
+            return;
182
+        }
183
+
184
+        if ( true !== $this->supports_component( $component ) ) {
185
+            // translators: Component name.
186
+            $this->feedback->warning( sprintf( __( 'Skipping the %s component—not supported.', 'wordpoints-importer' ), $component_data['name'] ) );
187
+            return;
188
+        }
189
+
190
+        $settings = array();
191
+
192
+        if ( isset( $options['_data'] ) ) {
193
+            $settings = $options['_data'];
194
+            unset( $options['_data'] );
195
+        }
196
+
197
+        if ( empty( $options ) || ! $this->validate_import_settings( $component, $settings ) ) {
198
+            return;
199
+        }
200
+
201
+        // translators: Component name.
202
+        $this->feedback->info( sprintf( __( 'Importing data to the %s component&hellip;', 'wordpoints-importer' ), $component_data['name'] ) );
203
+
204
+        foreach ( $options as $option => $unused ) {
205
+            $this->do_import_for_option( $option, $component, $settings );
206
+        }
207
+    }
208
+
209
+    /**
210
+     * Run the import for an option.
211
+     *
212
+     * The import is split up into different options which the user can select (these
213
+     * are displayed to the user as checkboxes in the form). This handles the import
214
+     * for each of the individual things the user has selected to import. These are
215
+     * all optional, so each is just termed an import "option" here.
216
+     *
217
+     * @since 1.0.0
218
+     *
219
+     * @param string $option    An import option that has been selected.
220
+     * @param string $component The component this option is for.
221
+     * @param array  $settings  Other settings for this component.
222
+     */
223
+    protected function do_import_for_option( $option, $component, $settings ) {
224
+
225
+        if ( ! isset( $this->components[ $component ][ $option ] ) ) {
226
+            // translators: Option name.
227
+            $this->feedback->warning( sprintf( __( 'Skipping unrecognized import option &#8220;%s&#8221;&hellip;', 'wordpoints-importer' ), $option ) );
228
+            return;
229
+        }
230
+
231
+        $option_data = $this->components[ $component ][ $option ];
232
+
233
+        // Check if we can actually run this option.
234
+        if ( isset( $option_data['can_import'] ) ) {
235
+
236
+            $cant_import = call_user_func( $option_data['can_import'], $settings );
237
+
238
+            if ( is_wp_error( $cant_import ) ) {
239
+                // translators: 1. Option name; 2. Reason the import was skipped.
240
+                $this->feedback->warning( sprintf( __( 'Skipping importing %1$s. Reason: %2$s', 'wordpoints-importer' ), $option_data['label'], $cant_import->get_error_message() ) );
241
+                return;
242
+            }
243
+        }
244
+
245
+        // OK, we can run the import method for this option.
246
+        call_user_func( $option_data['function'], $settings );
247
+    }
248 248
 }
249 249
 
250 250
 // EOF
Please login to merge, or discard this patch.
src/includes/class-feedback.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -16,84 +16,84 @@
 block discarded – undo
16 16
  */
17 17
 class WordPoints_Importer_Feedback {
18 18
 
19
-	/**
20
-	 * Send an info message.
21
-	 *
22
-	 * Use this to give the user any info that wouldn't be handles by the other
23
-	 * methods.
24
-	 *
25
-	 * @since 1.0.0
26
-	 *
27
-	 * @param string $message The info message.
28
-	 */
29
-	public function info( $message ) {
30
-		$this->_send( $message, 'info' );
31
-	}
19
+    /**
20
+     * Send an info message.
21
+     *
22
+     * Use this to give the user any info that wouldn't be handles by the other
23
+     * methods.
24
+     *
25
+     * @since 1.0.0
26
+     *
27
+     * @param string $message The info message.
28
+     */
29
+    public function info( $message ) {
30
+        $this->_send( $message, 'info' );
31
+    }
32 32
 
33
-	/**
34
-	 * Send a success message.
35
-	 *
36
-	 * Use this when you want to let the user know that something was a success.
37
-	 *
38
-	 * @since 1.0.0
39
-	 *
40
-	 * @param string $message The success message.
41
-	 */
42
-	public function success( $message ) {
43
-		$this->_send( $message, 'success' );
44
-	}
33
+    /**
34
+     * Send a success message.
35
+     *
36
+     * Use this when you want to let the user know that something was a success.
37
+     *
38
+     * @since 1.0.0
39
+     *
40
+     * @param string $message The success message.
41
+     */
42
+    public function success( $message ) {
43
+        $this->_send( $message, 'success' );
44
+    }
45 45
 
46
-	/**
47
-	 * Send an error message.
48
-	 *
49
-	 * Use this when you want to let the user know that there was an error.
50
-	 *
51
-	 * @since 1.0.0
52
-	 *
53
-	 * @param string $message The error message.
54
-	 */
55
-	public function error( $message ) {
56
-		$this->_send( $message, 'error' );
57
-	}
46
+    /**
47
+     * Send an error message.
48
+     *
49
+     * Use this when you want to let the user know that there was an error.
50
+     *
51
+     * @since 1.0.0
52
+     *
53
+     * @param string $message The error message.
54
+     */
55
+    public function error( $message ) {
56
+        $this->_send( $message, 'error' );
57
+    }
58 58
 
59
-	/**
60
-	 * Send a warning message.
61
-	 *
62
-	 * Use this to warn the user about something. A warning doesn't necessarily imply
63
-	 * an error, but that something unexpected has occured that the user might need
64
-	 * to know.
65
-	 *
66
-	 * @since 1.0.0
67
-	 *
68
-	 * @param string $message The warning message.
69
-	 */
70
-	public function warning( $message ) {
71
-		$this->_send( $message, 'warning' );
72
-	}
59
+    /**
60
+     * Send a warning message.
61
+     *
62
+     * Use this to warn the user about something. A warning doesn't necessarily imply
63
+     * an error, but that something unexpected has occured that the user might need
64
+     * to know.
65
+     *
66
+     * @since 1.0.0
67
+     *
68
+     * @param string $message The warning message.
69
+     */
70
+    public function warning( $message ) {
71
+        $this->_send( $message, 'warning' );
72
+    }
73 73
 
74
-	//
75
-	// Protected Methods.
76
-	//
74
+    //
75
+    // Protected Methods.
76
+    //
77 77
 
78
-	/**
79
-	 * Send a message to the user.
80
-	 *
81
-	 * @since 1.0.0
82
-	 *
83
-	 * @param string $message The feedback message.
84
-	 * @param string $type    The type of message: 'info' (defuault), 'sucess',
85
-	 *                        'error', 'warning'.
86
-	 */
87
-	protected function _send( $message, $type = 'info' ) { // @codingStandardsIgnoreLine
78
+    /**
79
+     * Send a message to the user.
80
+     *
81
+     * @since 1.0.0
82
+     *
83
+     * @param string $message The feedback message.
84
+     * @param string $type    The type of message: 'info' (defuault), 'sucess',
85
+     *                        'error', 'warning'.
86
+     */
87
+    protected function _send( $message, $type = 'info' ) { // @codingStandardsIgnoreLine
88 88
 
89
-		?>
89
+        ?>
90 90
 
91 91
 		<p class="wordpoints-feedback wordpoints-feedback-<?php echo esc_attr( $type ); ?>">
92 92
 			<?php echo wp_kses( $message, 'wordpoints_importer_feedback' ); ?>
93 93
 		</p>
94 94
 
95 95
 		<?php
96
-	}
96
+    }
97 97
 }
98 98
 
99 99
 // EOF
Please login to merge, or discard this patch.
src/includes/functions.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@  discard block
 block discarded – undo
15 15
  */
16 16
 function wordpoints_importer_load_textdomain() {
17 17
 
18
-	_deprecated_function( __FUNCTION__, '1.3.0' );
18
+    _deprecated_function( __FUNCTION__, '1.3.0' );
19 19
 
20
-	wordpoints_load_module_textdomain(
21
-		'wordpoints-importer'
22
-		, wordpoints_module_basename( dirname( dirname( __FILE__ ) ) ) . '/languages'
23
-	);
20
+    wordpoints_load_module_textdomain(
21
+        'wordpoints-importer'
22
+        , wordpoints_module_basename( dirname( dirname( __FILE__ ) ) ) . '/languages'
23
+    );
24 24
 }
25 25
 
26 26
 /**
@@ -30,12 +30,12 @@  discard block
 block discarded – undo
30 30
  */
31 31
 function wordpoints_importer_register_importers() {
32 32
 
33
-	$args = array(
34
-		'class' => 'WordPoints_CubePoints_Importer',
35
-		'name'  => __( 'CubePoints', 'wordpoints-importer' ),
36
-	);
33
+    $args = array(
34
+        'class' => 'WordPoints_CubePoints_Importer',
35
+        'name'  => __( 'CubePoints', 'wordpoints-importer' ),
36
+    );
37 37
 
38
-	WordPoints_Importers::register( 'cubepoints', $args );
38
+    WordPoints_Importers::register( 'cubepoints', $args );
39 39
 }
40 40
 add_action( 'wordpoints_register_importers', 'wordpoints_importer_register_importers' );
41 41
 
Please login to merge, or discard this patch.