See More

admin = new WordPress_GitHub_Sync_Admin; } $this->controller = new WordPress_GitHub_Sync_Controller; register_activation_hook( __FILE__, array( $this, 'activate' ) ); add_action( 'admin_notices', array( $this, 'activation_notice' ) ); add_action( 'init', array( &$this, 'l10n' ) ); add_action( 'save_post', array( &$this, 'save_post_callback' ) ); add_action( 'delete_post', array( &$this, 'delete_post_callback' ) ); add_action( 'wp_ajax_nopriv_wpghs_sync_request', array( &$this, 'pull_posts' ) ); add_action( 'wpghs_export', array( &$this->controller, 'export_all' ) ); add_action( 'wpghs_import', array( &$this->controller, 'import_master' ) ); if ( defined( 'WP_CLI' ) && WP_CLI ) { WP_CLI::add_command( 'wpghs', 'WordPress_GitHub_Sync_CLI' ); } } /** * Init i18n files */ public function l10n() { load_plugin_textdomain( self::$text_domain, false, plugin_basename( dirname( __FILE__ ) ) . '/languages/' ); } /** * Returns the Webhook secret */ public function secret() { return get_option( 'wpghs_secret' ); } /** * Callback triggered on post save, used to initiate an outbound sync * * $post_id - (int) the post to sync */ public function save_post_callback( $post_id ) { if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) { return; } $this->controller->export_post( $post_id ); } /** * Callback triggered on post delete, used to initiate an outbound sync * * $post_id - (int) the post to delete */ public function delete_post_callback( $post_id ) { if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) { return; } $this->controller->delete_post( $post_id ); } /** * Webhook callback as trigered from GitHub push */ public function pull_posts() { # Prevent pushes on update $this->push_lock = true; $raw_data = file_get_contents( 'php://input' ); $headers = $this->headers(); // validate secret $hash = hash_hmac( 'sha1', $raw_data, $this->secret() ); if ( 'sha1=' . $hash !== $headers['X-Hub-Signature'] ) { $msg = __( 'Failed to validate secret.', 'wordpress-github-sync' ); self::write_log( $msg ); wp_send_json( array( 'result' => 'error', 'message' => $msg, ) ); } $result = $this->controller->pull( json_decode( $raw_data ) ); wp_send_json( $result ); } /** * Cross-server header support * Returns an array of the request's headers */ public function headers() { if ( function_exists( 'getallheaders' ) ) { return getallheaders(); } // Nginx and pre 5.4 workaround // http://www.php.net/manual/en/function.getallheaders.php $headers = array(); foreach ( $_SERVER as $name => $value ) { if ( 'HTTP_' === substr( $name, 0, 5 ) ) { $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; } } return $headers; } /** * Sets and kicks off the export cronjob */ public function start_export() { update_option( '_wpghs_export_user_id', get_current_user_id() ); update_option( '_wpghs_export_started', 'yes' ); WordPress_GitHub_Sync::write_log( __( 'Starting full export to GitHub.', 'wordpress-github-sync' ) ); wp_schedule_single_event( time(), 'wpghs_export' ); spawn_cron(); } /** * Sets and kicks off the import cronjob */ public function start_import() { update_option( '_wpghs_import_started', 'yes' ); WordPress_GitHub_Sync::write_log( __( 'Starting import from GitHub.', 'wordpress-github-sync' ) ); wp_schedule_single_event( time(), 'wpghs_import' ); spawn_cron(); } /** * Enables the admin notice on initial activation */ public function activate() { if ( 'yes' !== get_option( '_wpghs_fully_exported' ) ) { set_transient( '_wpghs_activated', 'yes' ); } } /** * Displays the activation admin notice */ public function activation_notice() { if ( ! get_transient( '_wpghs_activated' ) ) { return; } delete_transient( '_wpghs_activated' ); ?>

settings and click "Export to GitHub."', 'wordpress-github-sync' ), admin_url( 'options-general.php?page=wordpress-github-sync' ) ); ?>