See More

admin = new WordPress_GitHub_Sync_Admin; } $this->controller = new WordPress_GitHub_Sync_Controller( $this ); if ( defined( 'WP_CLI' ) && WP_CLI ) { WP_CLI::add_command( 'wpghs', $this->cli() ); } } /** * Attaches the plugin's hooks into WordPress. */ public function boot() { register_activation_hook( __FILE__, array( $this, 'activate' ) ); add_action( 'admin_notices', array( $this, 'activation_notice' ) ); add_action( 'init', array( $this, 'l10n' ) ); // Controller actions. add_action( 'save_post', array( $this->controller, 'export_post' ) ); add_action( 'delete_post', array( $this->controller, 'delete_post' ) ); add_action( 'wp_ajax_nopriv_wpghs_sync_request', array( $this->controller, 'pull_posts' ) ); add_action( 'wpghs_export', array( $this->controller, 'export_all' ) ); add_action( 'wpghs_import', array( $this->controller, 'import_master' ) ); add_shortcode( 'wpghs', 'write_wpghs_link' ); do_action( 'wpghs_boot', $this ); } /** * Init i18n files */ public function l10n() { load_plugin_textdomain( self::$text_domain, false, plugin_basename( dirname( __FILE__ ) ) . '/languages/' ); } /** * Sets and kicks off the export cronjob */ public function start_export() { $this->export()->set_user( get_current_user_id() ); $this->start_cron( 'export' ); } /** * Sets and kicks off the import cronjob */ public function start_import() { $this->start_cron( 'import' ); } /** * 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."', 'wp-github-sync' ), admin_url( 'options-general.php?page=' . static::$text_domain) ); ?>

controller; } /** * Lazy-load the CLI object. * * @return WordPress_GitHub_Sync_CLI */ public function cli() { if ( ! $this->cli ) { $this->cli = new WordPress_GitHub_Sync_CLI; } return $this->cli; } /** * Lazy-load the Request object. * * @return WordPress_GitHub_Sync_Request */ public function request() { if ( ! $this->request ) { $this->request = new WordPress_GitHub_Sync_Request( $this ); } return $this->request; } /** * Lazy-load the Response object. * * @return WordPress_GitHub_Sync_Response */ public function response() { if ( ! $this->response ) { $this->response = new WordPress_GitHub_Sync_Response( $this ); } return $this->response; } /** * Lazy-load the Api object. * * @return WordPress_GitHub_Sync_Api */ public function api() { if ( ! $this->api ) { $this->api = new WordPress_GitHub_Sync_Api( $this ); } return $this->api; } /** * Lazy-load the Import object. * * @return WordPress_GitHub_Sync_Import */ public function import() { if ( ! $this->import ) { $this->import = new WordPress_GitHub_Sync_Import( $this ); } return $this->import; } /** * Lazy-load the Export object. * * @return WordPress_GitHub_Sync_Export */ public function export() { if ( ! $this->export ) { $this->export = new WordPress_GitHub_Sync_Export( $this ); } return $this->export; } /** * Lazy-load the Semaphore object. * * @return WordPress_GitHub_Sync_Semaphore */ public function semaphore() { if ( ! $this->semaphore ) { $this->semaphore = new WordPress_GitHub_Sync_Semaphore; } return $this->semaphore; } /** * Lazy-load the Database object. * * @return WordPress_GitHub_Sync_Database */ public function database() { if ( ! $this->database ) { $this->database = new WordPress_GitHub_Sync_Database( $this ); } return $this->database; } /** * Lazy-load the Cache object. * * @return WordPress_GitHub_Sync_Cache */ public function cache() { if ( ! $this->cache ) { $this->cache = new WordPress_GitHub_Sync_Cache; } return $this->cache; } /** * Print to WP_CLI if in CLI environment or * write to debug.log if WP_DEBUG is enabled * * @source http://www.stumiller.me/sending-output-to-the-wordpress-debug-log/ * * @param mixed $msg Message text. * @param string $write How to write the message, if CLI. */ public static function write_log( $msg, $write = 'line' ) { if ( defined( 'WP_CLI' ) && WP_CLI ) { if ( is_array( $msg ) || is_object( $msg ) ) { WP_CLI::print_value( $msg ); } else { WP_CLI::$write( $msg ); } } elseif ( true === WP_DEBUG ) { if ( is_array( $msg ) || is_object( $msg ) ) { error_log( print_r( $msg, true ) ); } else { error_log( $msg ); } } } /** * Kicks of an import or export cronjob. * * @param string $type Cron to kick off. */ protected function start_cron( $type ) { update_option( '_wpghs_' . $type . '_started', 'yes' ); wp_schedule_single_event( time(), 'wpghs_' . $type . '' ); spawn_cron(); } }