Passed
Push — master ( cdcc0c...410349 )
by litefeel
22:03 queued 03:07
created
lib/admin.php 1 patch
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -9,235 +9,235 @@
 block discarded – undo
9 9
  */
10 10
 class Writing_On_GitHub_Admin {
11 11
 
12
-    /**
13
-     * Hook into GitHub API
14
-     */
15
-    public function __construct() {
16
-        add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
17
-        add_action( 'admin_init', array( $this, 'register_settings' ) );
18
-        add_action( 'current_screen', array( $this, 'trigger_cron' ) );
19
-    }
20
-
21
-    /**
22
-     * Callback to render the settings page view
23
-     */
24
-    public function settings_page() {
25
-        include dirname( dirname( __FILE__ ) ) . '/views/options.php';
26
-    }
27
-
28
-    /**
29
-     * Callback to register the plugin's options
30
-     */
31
-    public function register_settings() {
32
-        add_settings_section(
33
-            'general',
34
-            'General Settings',
35
-            array( $this, 'section_callback' ),
36
-            Writing_On_GitHub::$text_domain
37
-        );
38
-
39
-        register_setting( Writing_On_GitHub::$text_domain, 'wogh_host' );
40
-        add_settings_field( 'wogh_host', __( 'GitHub hostname', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
41
-                'default'   => 'https://api.github.com',
42
-                'name'      => 'wogh_host',
43
-                'help_text' => __( 'The GitHub host to use. This only needs to be changed to support a GitHub Enterprise installation.', 'writing-on-github' ),
44
-            )
45
-        );
46
-
47
-        register_setting( Writing_On_GitHub::$text_domain, 'wogh_repository' );
48
-        add_settings_field( 'wogh_repository', __( 'Repository', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
49
-                'default'   => '',
50
-                'name'      => 'wogh_repository',
51
-                'help_text' => __( 'The GitHub repository to commit to, with owner (<code>[OWNER]/[REPOSITORY]</code>), e.g., <code>github/hubot.github.com</code>. The repository should contain an initial commit, which is satisfied by including a README when you create the repository on GitHub.', 'writing-on-github' ),
52
-            )
53
-        );
54
-
55
-        register_setting( Writing_On_GitHub::$text_domain, 'wogh_branch' );
56
-        add_settings_field( 'wogh_branch', __( 'Branch', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
57
-                'default'   => 'master',
58
-                'name'      => 'wogh_branch',
59
-                'help_text' => __( 'The GitHub branch to commit to, default is master.', 'writing-on-github' ),
60
-            )
61
-        );
62
-
63
-        register_setting( Writing_On_GitHub::$text_domain, 'wogh_oauth_token' );
64
-        add_settings_field( 'wogh_oauth_token', __( 'Oauth Token', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
65
-                'default'   => '',
66
-                'name'      => 'wogh_oauth_token',
67
-                'help_text' => __( "A <a href='https://github.com/settings/tokens/new'>personal oauth token</a> with <code>public_repo</code> scope.", 'writing-on-github' ),
68
-            )
69
-        );
70
-
71
-        register_setting( Writing_On_GitHub::$text_domain, 'wogh_secret' );
72
-        add_settings_field( 'wogh_secret', __( 'Webhook Secret', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
73
-                'default'   => '',
74
-                'name'      => 'wogh_secret',
75
-                'help_text' => __( "The webhook's secret phrase. This should be password strength, as it is used to verify the webhook's payload.", 'writing-on-github' ),
76
-            )
77
-        );
78
-
79
-        register_setting( Writing_On_GitHub::$text_domain, 'wogh_default_user' );
80
-        add_settings_field( 'wogh_default_user', __( 'Default Import User', 'writing-on-github' ), array( &$this, 'user_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
81
-                'default'   => '',
82
-                'name'      => 'wogh_default_user',
83
-                'help_text' => __( 'The fallback user for import, in case Writing On GitHub cannot find the committer in the database.', 'writing-on-github' ),
84
-            )
85
-        );
86
-
87
-        register_setting( Writing_On_GitHub::$text_domain, 'wogh_ignore_author' );
88
-        add_settings_field( 'wogh_ignore_author', __( 'Ignore author', 'writing-on-github' ), array( &$this, 'checkbox_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
89
-                'default'   => '',
90
-                'name'      => 'wogh_ignore_author',
91
-                'help_text' => __( 'Do not export author and do not use author info from GitHub.', 'writing-on-github' ),
92
-            )
93
-        );
94
-
95
-        register_setting( Writing_On_GitHub::$text_domain, 'wogh_dont_export_content' );
96
-        add_settings_field( 'wogh_dont_export_content', __( 'Don\'t export content', 'writing-on-github' ), array( &$this, 'checkbox_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
97
-                'default'   => '',
98
-                'name'      => 'wogh_dont_export_content',
99
-                'help_text' => __( 'Do not export post content to github, only export meta.', 'writing-on-github' ),
100
-            )
101
-        );
102
-
103
-        // register_setting( Writing_On_GitHub::$text_domain, 'wogh_ignore_metas' );
104
-        // add_settings_field( 'wogh_ignore_metas', __( 'Ignore post metas', 'writing-on-github' ), array( &$this, 'textarea_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
105
-        //      'default'   => '',
106
-        //      'name'      => 'wogh_ignore_metas',
107
-        //      'help_text' => __( 'These meta keys will be ignored and cannot be imported and exported. One meta key per line.', 'writing-on-github' ),
108
-        //  )
109
-        // );
110
-    }
111
-
112
-    /**
113
-     * Callback to render an individual options field
114
-     *
115
-     * @param array $args Field arguments.
116
-     */
117
-    public function field_callback( $args ) {
118
-        include dirname( dirname( __FILE__ ) ) . '/views/setting-field.php';
119
-    }
120
-
121
-    /**
122
-     * Callback to render the default import user field.
123
-     *
124
-     * @param array $args Field arguments.
125
-     */
126
-    public function user_field_callback( $args ) {
127
-        include dirname( dirname( __FILE__ ) ) . '/views/user-setting-field.php';
128
-    }
129
-
130
-    /**
131
-     * Callback to render the textarea field.
132
-     *
133
-     * @param array $args Field arguments.
134
-     */
135
-    public function textarea_field_callback( $args ) {
136
-        include dirname( dirname( __FILE__ ) ) . '/views/textarea-setting-field.php';
137
-    }
138
-
139
-    /**
140
-     * Callback to render the checkbox field.
141
-     *
142
-     * @param array $args Field arguments.
143
-     */
144
-    public function checkbox_field_callback( $args ) {
145
-        include dirname( dirname( __FILE__ ) ) . '/views/checkbox-setting-field.php';
146
-    }
147
-
148
-    /**
149
-     * Displays settings messages from background processes
150
-     */
151
-    public function section_callback() {
152
-        if ( get_current_screen()->id !== 'settings_page_' . Writing_On_GitHub::$text_domain ) {
153
-            return;
154
-        }
155
-
156
-        if ( 'yes' === get_option( '_wogh_export_started' ) ) { ?>
12
+	/**
13
+	 * Hook into GitHub API
14
+	 */
15
+	public function __construct() {
16
+		add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
17
+		add_action( 'admin_init', array( $this, 'register_settings' ) );
18
+		add_action( 'current_screen', array( $this, 'trigger_cron' ) );
19
+	}
20
+
21
+	/**
22
+	 * Callback to render the settings page view
23
+	 */
24
+	public function settings_page() {
25
+		include dirname( dirname( __FILE__ ) ) . '/views/options.php';
26
+	}
27
+
28
+	/**
29
+	 * Callback to register the plugin's options
30
+	 */
31
+	public function register_settings() {
32
+		add_settings_section(
33
+			'general',
34
+			'General Settings',
35
+			array( $this, 'section_callback' ),
36
+			Writing_On_GitHub::$text_domain
37
+		);
38
+
39
+		register_setting( Writing_On_GitHub::$text_domain, 'wogh_host' );
40
+		add_settings_field( 'wogh_host', __( 'GitHub hostname', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
41
+				'default'   => 'https://api.github.com',
42
+				'name'      => 'wogh_host',
43
+				'help_text' => __( 'The GitHub host to use. This only needs to be changed to support a GitHub Enterprise installation.', 'writing-on-github' ),
44
+			)
45
+		);
46
+
47
+		register_setting( Writing_On_GitHub::$text_domain, 'wogh_repository' );
48
+		add_settings_field( 'wogh_repository', __( 'Repository', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
49
+				'default'   => '',
50
+				'name'      => 'wogh_repository',
51
+				'help_text' => __( 'The GitHub repository to commit to, with owner (<code>[OWNER]/[REPOSITORY]</code>), e.g., <code>github/hubot.github.com</code>. The repository should contain an initial commit, which is satisfied by including a README when you create the repository on GitHub.', 'writing-on-github' ),
52
+			)
53
+		);
54
+
55
+		register_setting( Writing_On_GitHub::$text_domain, 'wogh_branch' );
56
+		add_settings_field( 'wogh_branch', __( 'Branch', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
57
+				'default'   => 'master',
58
+				'name'      => 'wogh_branch',
59
+				'help_text' => __( 'The GitHub branch to commit to, default is master.', 'writing-on-github' ),
60
+			)
61
+		);
62
+
63
+		register_setting( Writing_On_GitHub::$text_domain, 'wogh_oauth_token' );
64
+		add_settings_field( 'wogh_oauth_token', __( 'Oauth Token', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
65
+				'default'   => '',
66
+				'name'      => 'wogh_oauth_token',
67
+				'help_text' => __( "A <a href='https://github.com/settings/tokens/new'>personal oauth token</a> with <code>public_repo</code> scope.", 'writing-on-github' ),
68
+			)
69
+		);
70
+
71
+		register_setting( Writing_On_GitHub::$text_domain, 'wogh_secret' );
72
+		add_settings_field( 'wogh_secret', __( 'Webhook Secret', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
73
+				'default'   => '',
74
+				'name'      => 'wogh_secret',
75
+				'help_text' => __( "The webhook's secret phrase. This should be password strength, as it is used to verify the webhook's payload.", 'writing-on-github' ),
76
+			)
77
+		);
78
+
79
+		register_setting( Writing_On_GitHub::$text_domain, 'wogh_default_user' );
80
+		add_settings_field( 'wogh_default_user', __( 'Default Import User', 'writing-on-github' ), array( &$this, 'user_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
81
+				'default'   => '',
82
+				'name'      => 'wogh_default_user',
83
+				'help_text' => __( 'The fallback user for import, in case Writing On GitHub cannot find the committer in the database.', 'writing-on-github' ),
84
+			)
85
+		);
86
+
87
+		register_setting( Writing_On_GitHub::$text_domain, 'wogh_ignore_author' );
88
+		add_settings_field( 'wogh_ignore_author', __( 'Ignore author', 'writing-on-github' ), array( &$this, 'checkbox_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
89
+				'default'   => '',
90
+				'name'      => 'wogh_ignore_author',
91
+				'help_text' => __( 'Do not export author and do not use author info from GitHub.', 'writing-on-github' ),
92
+			)
93
+		);
94
+
95
+		register_setting( Writing_On_GitHub::$text_domain, 'wogh_dont_export_content' );
96
+		add_settings_field( 'wogh_dont_export_content', __( 'Don\'t export content', 'writing-on-github' ), array( &$this, 'checkbox_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
97
+				'default'   => '',
98
+				'name'      => 'wogh_dont_export_content',
99
+				'help_text' => __( 'Do not export post content to github, only export meta.', 'writing-on-github' ),
100
+			)
101
+		);
102
+
103
+		// register_setting( Writing_On_GitHub::$text_domain, 'wogh_ignore_metas' );
104
+		// add_settings_field( 'wogh_ignore_metas', __( 'Ignore post metas', 'writing-on-github' ), array( &$this, 'textarea_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array(
105
+		//      'default'   => '',
106
+		//      'name'      => 'wogh_ignore_metas',
107
+		//      'help_text' => __( 'These meta keys will be ignored and cannot be imported and exported. One meta key per line.', 'writing-on-github' ),
108
+		//  )
109
+		// );
110
+	}
111
+
112
+	/**
113
+	 * Callback to render an individual options field
114
+	 *
115
+	 * @param array $args Field arguments.
116
+	 */
117
+	public function field_callback( $args ) {
118
+		include dirname( dirname( __FILE__ ) ) . '/views/setting-field.php';
119
+	}
120
+
121
+	/**
122
+	 * Callback to render the default import user field.
123
+	 *
124
+	 * @param array $args Field arguments.
125
+	 */
126
+	public function user_field_callback( $args ) {
127
+		include dirname( dirname( __FILE__ ) ) . '/views/user-setting-field.php';
128
+	}
129
+
130
+	/**
131
+	 * Callback to render the textarea field.
132
+	 *
133
+	 * @param array $args Field arguments.
134
+	 */
135
+	public function textarea_field_callback( $args ) {
136
+		include dirname( dirname( __FILE__ ) ) . '/views/textarea-setting-field.php';
137
+	}
138
+
139
+	/**
140
+	 * Callback to render the checkbox field.
141
+	 *
142
+	 * @param array $args Field arguments.
143
+	 */
144
+	public function checkbox_field_callback( $args ) {
145
+		include dirname( dirname( __FILE__ ) ) . '/views/checkbox-setting-field.php';
146
+	}
147
+
148
+	/**
149
+	 * Displays settings messages from background processes
150
+	 */
151
+	public function section_callback() {
152
+		if ( get_current_screen()->id !== 'settings_page_' . Writing_On_GitHub::$text_domain ) {
153
+			return;
154
+		}
155
+
156
+		if ( 'yes' === get_option( '_wogh_export_started' ) ) { ?>
157 157
             <div class="updated">
158 158
                 <p><?php esc_html_e( 'Export to GitHub started.', 'writing-on-github' ); ?></p>
159 159
             </div><?php
160
-            delete_option( '_wogh_export_started' );
161
-        }
160
+			delete_option( '_wogh_export_started' );
161
+		}
162 162
 
163
-        if ( $message = get_option( '_wogh_export_error' ) ) { ?>
163
+		if ( $message = get_option( '_wogh_export_error' ) ) { ?>
164 164
             <div class="error">
165 165
                 <p><?php esc_html_e( 'Export to GitHub failed with error:', 'writing-on-github' ); ?> <?php echo esc_html( $message );?></p>
166 166
             </div><?php
167
-            delete_option( '_wogh_export_error' );
168
-        }
167
+			delete_option( '_wogh_export_error' );
168
+		}
169 169
 
170
-        if ( 'yes' === get_option( '_wogh_export_complete' ) ) { ?>
170
+		if ( 'yes' === get_option( '_wogh_export_complete' ) ) { ?>
171 171
             <div class="updated">
172 172
                 <p><?php esc_html_e( 'Export to GitHub completed successfully.', 'writing-on-github' );?></p>
173 173
             </div><?php
174
-            delete_option( '_wogh_export_complete' );
175
-        }
174
+			delete_option( '_wogh_export_complete' );
175
+		}
176 176
 
177
-        if ( 'yes' === get_option( '_wogh_import_started' ) ) { ?>
177
+		if ( 'yes' === get_option( '_wogh_import_started' ) ) { ?>
178 178
             <div class="updated">
179 179
             <p><?php esc_html_e( 'Import from GitHub started.', 'writing-on-github' ); ?></p>
180 180
             </div><?php
181
-            delete_option( '_wogh_import_started' );
182
-        }
181
+			delete_option( '_wogh_import_started' );
182
+		}
183 183
 
184
-        if ( $message = get_option( '_wogh_import_error' ) ) { ?>
184
+		if ( $message = get_option( '_wogh_import_error' ) ) { ?>
185 185
             <div class="error">
186 186
             <p><?php esc_html_e( 'Import from GitHub failed with error:', 'writing-on-github' ); ?> <?php echo esc_html( $message );?></p>
187 187
             </div><?php
188
-            delete_option( '_wogh_import_error' );
189
-        }
188
+			delete_option( '_wogh_import_error' );
189
+		}
190 190
 
191
-        if ( 'yes' === get_option( '_wogh_import_complete' ) ) { ?>
191
+		if ( 'yes' === get_option( '_wogh_import_complete' ) ) { ?>
192 192
             <div class="updated">
193 193
             <p><?php esc_html_e( 'Import from GitHub completed successfully.', 'writing-on-github' );?></p>
194 194
             </div><?php
195
-            delete_option( '_wogh_import_complete' );
196
-        }
197
-    }
198
-
199
-    /**
200
-     * Add options menu to admin navbar
201
-     */
202
-    public function add_admin_menu() {
203
-        add_options_page(
204
-            __( 'Writing On GitHub', 'writing-on-github' ),
205
-            __( 'Writing On GitHub', 'writing-on-github' ),
206
-            'manage_options',
207
-            Writing_On_GitHub::$text_domain,
208
-            array( $this, 'settings_page' )
209
-        );
210
-    }
211
-
212
-    /**
213
-     * Admin callback to trigger import/export because WordPress admin routing lol
214
-     */
215
-    public function trigger_cron() {
216
-        if ( ! current_user_can( 'manage_options' ) ) {
217
-            return;
218
-        }
219
-
220
-        if ( get_current_screen()->id !== 'settings_page_' . Writing_On_GitHub::$text_domain ) {
221
-            return;
222
-        }
223
-
224
-        if ( ! isset( $_GET['action'] ) ) {
225
-            return;
226
-        }
227
-
228
-        if ( 'export' === $_GET['action'] ) {
229
-            Writing_On_GitHub::$instance->start_export();
230
-        }
231
-
232
-        if ( 'force_export' === $_GET['action'] ) {
233
-            Writing_On_GitHub::$instance->start_export(true);
234
-        }
235
-
236
-        if ( 'import' === $_GET['action'] ) {
237
-            Writing_On_GitHub::$instance->start_import();
238
-        }
239
-
240
-        wp_redirect( admin_url( 'options-general.php?page=writing-on-github' ) );
241
-        die;
242
-    }
195
+			delete_option( '_wogh_import_complete' );
196
+		}
197
+	}
198
+
199
+	/**
200
+	 * Add options menu to admin navbar
201
+	 */
202
+	public function add_admin_menu() {
203
+		add_options_page(
204
+			__( 'Writing On GitHub', 'writing-on-github' ),
205
+			__( 'Writing On GitHub', 'writing-on-github' ),
206
+			'manage_options',
207
+			Writing_On_GitHub::$text_domain,
208
+			array( $this, 'settings_page' )
209
+		);
210
+	}
211
+
212
+	/**
213
+	 * Admin callback to trigger import/export because WordPress admin routing lol
214
+	 */
215
+	public function trigger_cron() {
216
+		if ( ! current_user_can( 'manage_options' ) ) {
217
+			return;
218
+		}
219
+
220
+		if ( get_current_screen()->id !== 'settings_page_' . Writing_On_GitHub::$text_domain ) {
221
+			return;
222
+		}
223
+
224
+		if ( ! isset( $_GET['action'] ) ) {
225
+			return;
226
+		}
227
+
228
+		if ( 'export' === $_GET['action'] ) {
229
+			Writing_On_GitHub::$instance->start_export();
230
+		}
231
+
232
+		if ( 'force_export' === $_GET['action'] ) {
233
+			Writing_On_GitHub::$instance->start_export(true);
234
+		}
235
+
236
+		if ( 'import' === $_GET['action'] ) {
237
+			Writing_On_GitHub::$instance->start_import();
238
+		}
239
+
240
+		wp_redirect( admin_url( 'options-general.php?page=writing-on-github' ) );
241
+		die;
242
+	}
243 243
 }
Please login to merge, or discard this patch.