@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | // If the functions have already been autoloaded, don't reload. |
| 14 | 14 | // This fixes function duplication during unit testing. |
| 15 | -if ( defined( 'WRITING_ON_GITHUB_TEST' ) && WRITING_ON_GITHUB_TEST ) { |
|
| 16 | - $path = dirname( __FILE__ ) . '/vendor/autoload.php'; |
|
| 15 | +if (defined('WRITING_ON_GITHUB_TEST') && WRITING_ON_GITHUB_TEST) { |
|
| 16 | + $path = dirname(__FILE__) . '/vendor/autoload.php'; |
|
| 17 | 17 | include_once $path; |
| 18 | 18 | } |
| 19 | 19 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | // require_once(dirname(__FILE__) . '/views/options.php'); |
| 41 | 41 | // require_once(dirname(__FILE__) . '/views/user-setting-field.php'); |
| 42 | 42 | |
| 43 | -add_action( 'plugins_loaded', array( new Writing_On_GitHub, 'boot' ) ); |
|
| 43 | +add_action('plugins_loaded', array(new Writing_On_GitHub, 'boot')); |
|
| 44 | 44 | |
| 45 | 45 | class Writing_On_GitHub { |
| 46 | 46 | |
@@ -130,14 +130,14 @@ discard block |
||
| 130 | 130 | public function __construct() { |
| 131 | 131 | self::$instance = $this; |
| 132 | 132 | |
| 133 | - if ( is_admin() ) { |
|
| 133 | + if (is_admin()) { |
|
| 134 | 134 | $this->admin = new Writing_On_GitHub_Admin; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $this->controller = new Writing_On_GitHub_Controller( $this ); |
|
| 137 | + $this->controller = new Writing_On_GitHub_Controller($this); |
|
| 138 | 138 | |
| 139 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 140 | - WP_CLI::add_command( 'wogh', $this->cli() ); |
|
| 139 | + if (defined('WP_CLI') && WP_CLI) { |
|
| 140 | + WP_CLI::add_command('wogh', $this->cli()); |
|
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | |
@@ -145,30 +145,30 @@ discard block |
||
| 145 | 145 | * Attaches the plugin's hooks into WordPress. |
| 146 | 146 | */ |
| 147 | 147 | public function boot() { |
| 148 | - register_activation_hook( __FILE__, array( $this, 'activate' ) ); |
|
| 149 | - add_action( 'admin_notices', array( $this, 'activation_notice' ) ); |
|
| 148 | + register_activation_hook(__FILE__, array($this, 'activate')); |
|
| 149 | + add_action('admin_notices', array($this, 'activation_notice')); |
|
| 150 | 150 | |
| 151 | - add_action( 'init', array( $this, 'l10n' ) ); |
|
| 151 | + add_action('init', array($this, 'l10n')); |
|
| 152 | 152 | |
| 153 | 153 | // Controller actions. |
| 154 | - add_action( 'save_post', array( $this->controller, 'export_post' ) ); |
|
| 155 | - add_action( 'delete_post', array( $this->controller, 'delete_post' ) ); |
|
| 156 | - add_action( 'wp_ajax_nopriv_wogh_push_request', array( $this->controller, 'pull_posts' ) ); |
|
| 157 | - add_action( 'wogh_export', array( $this->controller, 'export_all' ), 10, 2 ); |
|
| 158 | - add_action( 'wogh_import', array( $this->controller, 'import_master' ), 10, 1 ); |
|
| 159 | - add_filter( 'get_edit_post_link', array( $this, 'edit_post_link' ), 10, 3 ); |
|
| 154 | + add_action('save_post', array($this->controller, 'export_post')); |
|
| 155 | + add_action('delete_post', array($this->controller, 'delete_post')); |
|
| 156 | + add_action('wp_ajax_nopriv_wogh_push_request', array($this->controller, 'pull_posts')); |
|
| 157 | + add_action('wogh_export', array($this->controller, 'export_all'), 10, 2); |
|
| 158 | + add_action('wogh_import', array($this->controller, 'import_master'), 10, 1); |
|
| 159 | + add_filter('get_edit_post_link', array($this, 'edit_post_link'), 10, 3); |
|
| 160 | 160 | |
| 161 | 161 | // add_filter( 'wogh_post_meta', array( $this, 'ignore_post_meta' ), 10, 1 ); |
| 162 | 162 | // add_filter( 'wogh_pre_import_meta', array( $this, 'ignore_post_meta' ), 10, 1 ); |
| 163 | - add_filter( 'the_content', array( $this, 'the_content' ) ); |
|
| 163 | + add_filter('the_content', array($this, 'the_content')); |
|
| 164 | 164 | |
| 165 | - do_action( 'wogh_boot', $this ); |
|
| 165 | + do_action('wogh_boot', $this); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | public function edit_post_link($link, $postID, $context) { |
| 169 | - if ( ! wp_is_post_revision( $postID ) ) { |
|
| 170 | - $post = new Writing_On_GitHub_Post( $postID, Writing_On_GitHub::$instance->api() ); |
|
| 171 | - if ( $post->is_on_github() ) { |
|
| 169 | + if ( ! wp_is_post_revision($postID)) { |
|
| 170 | + $post = new Writing_On_GitHub_Post($postID, Writing_On_GitHub::$instance->api()); |
|
| 171 | + if ($post->is_on_github()) { |
|
| 172 | 172 | return $post->github_edit_url(); |
| 173 | 173 | } |
| 174 | 174 | } |
@@ -227,29 +227,29 @@ discard block |
||
| 227 | 227 | * Init i18n files |
| 228 | 228 | */ |
| 229 | 229 | public function l10n() { |
| 230 | - load_plugin_textdomain( self::$text_domain ); |
|
| 230 | + load_plugin_textdomain(self::$text_domain); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | 234 | * Sets and kicks off the export cronjob |
| 235 | 235 | */ |
| 236 | - public function start_export( $force = false ) { |
|
| 237 | - $this->start_cron( 'export', $force ); |
|
| 236 | + public function start_export($force = false) { |
|
| 237 | + $this->start_cron('export', $force); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
| 241 | 241 | * Sets and kicks off the import cronjob |
| 242 | 242 | */ |
| 243 | 243 | public function start_import() { |
| 244 | - $this->start_cron( 'import' ); |
|
| 244 | + $this->start_cron('import'); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
| 248 | 248 | * Enables the admin notice on initial activation |
| 249 | 249 | */ |
| 250 | 250 | public function activate() { |
| 251 | - if ( 'yes' !== get_option( '_wogh_fully_exported' ) ) { |
|
| 252 | - set_transient( '_wogh_activated', 'yes' ); |
|
| 251 | + if ('yes' !== get_option('_wogh_fully_exported')) { |
|
| 252 | + set_transient('_wogh_activated', 'yes'); |
|
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
@@ -257,18 +257,18 @@ discard block |
||
| 257 | 257 | * Displays the activation admin notice |
| 258 | 258 | */ |
| 259 | 259 | public function activation_notice() { |
| 260 | - if ( ! get_transient( '_wogh_activated' ) ) { |
|
| 260 | + if ( ! get_transient('_wogh_activated')) { |
|
| 261 | 261 | return; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - delete_transient( '_wogh_activated' ); |
|
| 264 | + delete_transient('_wogh_activated'); |
|
| 265 | 265 | |
| 266 | 266 | ?><div class="updated"> |
| 267 | 267 | <p> |
| 268 | 268 | <?php |
| 269 | 269 | printf( |
| 270 | - __( 'To set up your site to sync with GitHub, update your <a href="%s">settings</a> and click "Export to GitHub."', 'writing-on-github' ), |
|
| 271 | - admin_url( 'options-general.php?page=' . static::$text_domain) |
|
| 270 | + __('To set up your site to sync with GitHub, update your <a href="%s">settings</a> and click "Export to GitHub."', 'writing-on-github'), |
|
| 271 | + admin_url('options-general.php?page=' . static::$text_domain) |
|
| 272 | 272 | ); |
| 273 | 273 | ?> |
| 274 | 274 | </p> |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @return Writing_On_GitHub_CLI |
| 291 | 291 | */ |
| 292 | 292 | public function cli() { |
| 293 | - if ( ! $this->cli ) { |
|
| 293 | + if ( ! $this->cli) { |
|
| 294 | 294 | $this->cli = new Writing_On_GitHub_CLI; |
| 295 | 295 | } |
| 296 | 296 | |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | * @return Writing_On_GitHub_Request |
| 304 | 304 | */ |
| 305 | 305 | public function request() { |
| 306 | - if ( ! $this->request ) { |
|
| 307 | - $this->request = new Writing_On_GitHub_Request( $this ); |
|
| 306 | + if ( ! $this->request) { |
|
| 307 | + $this->request = new Writing_On_GitHub_Request($this); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | return $this->request; |
@@ -316,8 +316,8 @@ discard block |
||
| 316 | 316 | * @return Writing_On_GitHub_Response |
| 317 | 317 | */ |
| 318 | 318 | public function response() { |
| 319 | - if ( ! $this->response ) { |
|
| 320 | - $this->response = new Writing_On_GitHub_Response( $this ); |
|
| 319 | + if ( ! $this->response) { |
|
| 320 | + $this->response = new Writing_On_GitHub_Response($this); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | return $this->response; |
@@ -329,8 +329,8 @@ discard block |
||
| 329 | 329 | * @return Writing_On_GitHub_Api |
| 330 | 330 | */ |
| 331 | 331 | public function api() { |
| 332 | - if ( ! $this->api ) { |
|
| 333 | - $this->api = new Writing_On_GitHub_Api( $this ); |
|
| 332 | + if ( ! $this->api) { |
|
| 333 | + $this->api = new Writing_On_GitHub_Api($this); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | return $this->api; |
@@ -342,8 +342,8 @@ discard block |
||
| 342 | 342 | * @return Writing_On_GitHub_Import |
| 343 | 343 | */ |
| 344 | 344 | public function import() { |
| 345 | - if ( ! $this->import ) { |
|
| 346 | - $this->import = new Writing_On_GitHub_Import( $this ); |
|
| 345 | + if ( ! $this->import) { |
|
| 346 | + $this->import = new Writing_On_GitHub_Import($this); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | return $this->import; |
@@ -355,8 +355,8 @@ discard block |
||
| 355 | 355 | * @return Writing_On_GitHub_Export |
| 356 | 356 | */ |
| 357 | 357 | public function export() { |
| 358 | - if ( ! $this->export ) { |
|
| 359 | - $this->export = new Writing_On_GitHub_Export( $this ); |
|
| 358 | + if ( ! $this->export) { |
|
| 359 | + $this->export = new Writing_On_GitHub_Export($this); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | return $this->export; |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @return Writing_On_GitHub_Semaphore |
| 369 | 369 | */ |
| 370 | 370 | public function semaphore() { |
| 371 | - if ( ! $this->semaphore ) { |
|
| 371 | + if ( ! $this->semaphore) { |
|
| 372 | 372 | $this->semaphore = new Writing_On_GitHub_Semaphore; |
| 373 | 373 | } |
| 374 | 374 | |
@@ -381,8 +381,8 @@ discard block |
||
| 381 | 381 | * @return Writing_On_GitHub_Database |
| 382 | 382 | */ |
| 383 | 383 | public function database() { |
| 384 | - if ( ! $this->database ) { |
|
| 385 | - $this->database = new Writing_On_GitHub_Database( $this ); |
|
| 384 | + if ( ! $this->database) { |
|
| 385 | + $this->database = new Writing_On_GitHub_Database($this); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | return $this->database; |
@@ -396,18 +396,18 @@ discard block |
||
| 396 | 396 | * @param mixed $msg |
| 397 | 397 | * @param string $write |
| 398 | 398 | */ |
| 399 | - public static function write_log( $msg, $write = 'line' ) { |
|
| 400 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 401 | - if ( is_array( $msg ) || is_object( $msg ) ) { |
|
| 402 | - WP_CLI::print_value( $msg ); |
|
| 399 | + public static function write_log($msg, $write = 'line') { |
|
| 400 | + if (defined('WP_CLI') && WP_CLI) { |
|
| 401 | + if (is_array($msg) || is_object($msg)) { |
|
| 402 | + WP_CLI::print_value($msg); |
|
| 403 | 403 | } else { |
| 404 | - WP_CLI::$write( $msg ); |
|
| 404 | + WP_CLI::$write($msg); |
|
| 405 | 405 | } |
| 406 | - } elseif ( true === WP_DEBUG ) { |
|
| 407 | - if ( is_array( $msg ) || is_object( $msg ) ) { |
|
| 408 | - error_log( print_r( $msg, true ) ); |
|
| 406 | + } elseif (true === WP_DEBUG) { |
|
| 407 | + if (is_array($msg) || is_object($msg)) { |
|
| 408 | + error_log(print_r($msg, true)); |
|
| 409 | 409 | } else { |
| 410 | - error_log( $msg ); |
|
| 410 | + error_log($msg); |
|
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | 413 | } |
@@ -418,10 +418,10 @@ discard block |
||
| 418 | 418 | * @param bool $force |
| 419 | 419 | * @param string $type |
| 420 | 420 | */ |
| 421 | - protected function start_cron( $type, $force = false ) { |
|
| 422 | - update_option( '_wogh_' . $type . '_started', 'yes' ); |
|
| 421 | + protected function start_cron($type, $force = false) { |
|
| 422 | + update_option('_wogh_' . $type . '_started', 'yes'); |
|
| 423 | 423 | $user_id = get_current_user_id(); |
| 424 | - wp_schedule_single_event( time(), 'wogh_' . $type . '', array( $user_id, $force ) ); |
|
| 424 | + wp_schedule_single_event(time(), 'wogh_' . $type . '', array($user_id, $force)); |
|
| 425 | 425 | spawn_cron(); |
| 426 | 426 | } |
| 427 | 427 | } |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return array[Writing_On_GitHub_File_Info]|WP_Error |
| 18 | 18 | */ |
| 19 | - public function compare( $sha ) { |
|
| 19 | + public function compare($sha) { |
|
| 20 | 20 | // https://api.github.com/repos/litefeel/testwpsync/compare/861f87e8851b8debb78db548269d29f8da4d94ac...master |
| 21 | 21 | $endpoint = $this->compare_endpoint(); |
| 22 | 22 | $branch = $this->branch(); |
| 23 | - $data = $this->call( 'GET', "$endpoint/$sha...$branch" ); |
|
| 23 | + $data = $this->call('GET', "$endpoint/$sha...$branch"); |
|
| 24 | 24 | |
| 25 | - if ( is_wp_error( $data ) ) { |
|
| 25 | + if (is_wp_error($data)) { |
|
| 26 | 26 | return $data; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @return mixed |
| 46 | 46 | */ |
| 47 | - public function remote_contents( $post ) { |
|
| 48 | - return $this->call( 'GET', $this->content_endpoint( $post->github_path() ) ); |
|
| 47 | + public function remote_contents($post) { |
|
| 48 | + return $this->call('GET', $this->content_endpoint($post->github_path())); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public function exists( $path ) { |
|
| 52 | - $result = $this->call( 'GET', $this->content_endpoint( $path ) ); |
|
| 53 | - if ( is_wp_error( $result ) ) { |
|
| 51 | + public function exists($path) { |
|
| 52 | + $result = $this->call('GET', $this->content_endpoint($path)); |
|
| 53 | + if (is_wp_error($result)) { |
|
| 54 | 54 | return false; |
| 55 | 55 | } |
| 56 | 56 | return true; |
@@ -63,27 +63,27 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @return Writing_On_GitHub_Tree|WP_Error |
| 65 | 65 | */ |
| 66 | - public function tree_recursive( $sha = '_default' ) { |
|
| 66 | + public function tree_recursive($sha = '_default') { |
|
| 67 | 67 | |
| 68 | - if ( '_default' === $sha ) { |
|
| 68 | + if ('_default' === $sha) { |
|
| 69 | 69 | $sha = $this->branch(); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $data = $this->call( 'GET', $this->tree_endpoint() . '/' . $sha . '?recursive=1' ); |
|
| 72 | + $data = $this->call('GET', $this->tree_endpoint() . '/' . $sha . '?recursive=1'); |
|
| 73 | 73 | |
| 74 | - if ( is_wp_error( $data ) ) { |
|
| 74 | + if (is_wp_error($data)) { |
|
| 75 | 75 | return $data; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $files = array(); |
| 79 | 79 | |
| 80 | - foreach ( $data->tree as $index => $thing ) { |
|
| 80 | + foreach ($data->tree as $index => $thing) { |
|
| 81 | 81 | // We need to remove the trees because |
| 82 | 82 | // the recursive tree includes both |
| 83 | 83 | // the subtrees as well the subtrees' blobs. |
| 84 | - if ( 'blob' === $thing->type ) { |
|
| 84 | + if ('blob' === $thing->type) { |
|
| 85 | 85 | $thing->status = ''; |
| 86 | - $files[] = new Writing_On_GitHub_File_Info( $thing ); |
|
| 86 | + $files[] = new Writing_On_GitHub_File_Info($thing); |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @return Writing_On_GitHub_Blob|WP_Error |
| 99 | 99 | */ |
| 100 | - public function blob( $blob ) { |
|
| 101 | - $data = $this->call( 'GET', $this->blob_endpoint() . '/' . $blob->sha ); |
|
| 100 | + public function blob($blob) { |
|
| 101 | + $data = $this->call('GET', $this->blob_endpoint() . '/' . $blob->sha); |
|
| 102 | 102 | |
| 103 | - if ( is_wp_error( $data ) ) { |
|
| 103 | + if (is_wp_error($data)) { |
|
| 104 | 104 | return $data; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $data->path = $blob->path; |
| 108 | - $obj = new Writing_On_GitHub_Blob( $data ); |
|
| 108 | + $obj = new Writing_On_GitHub_Blob($data); |
|
| 109 | 109 | |
| 110 | 110 | return $obj; |
| 111 | 111 | } |