Skip to content

Commit

Permalink
Add publish_to_discourse utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmcleod committed Jan 15, 2024
1 parent 3b22094 commit ea2b41a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ wpcs/*
*.sublime-project

node_modules
.phpunit.result.cache
2 changes: 1 addition & 1 deletion .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":1,"defects":{"WPDiscourse\\Test\\DiscourseCommentTest::test_sync_comments_handle_error_response":6,"WPDiscourse\\Test\\DiscourseCommentTest::test_get_comment_type_for_post_display_public_comments_only_when_connection_fails":6,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_response_error":6,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_response_error_legacy":6,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_scopes_invalid":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_embed_error":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_category_error":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_response_body_error":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_enqueued_post":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_updating_with_deleted_topic":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_forbidden":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_unprocessable":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_failed_to_connect":6,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_invalid_signature":6,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_invalid_nonce":6,"WPDiscourse\\Test\\DiscourseSSOTest::test_logout_from_discourse_failed_to_get_discourse_user":6,"WPDiscourse\\Test\\DiscourseSSOTest::test_logout_from_discourse_failed_to_logout":6,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_write":6,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_date_rotation":6,"WPDiscourse\\Test\\FileManagerTest::test_validation_uploads_creation":6,"WPDiscourse\\Test\\FileManagerTest::test_validation_logs_creation":6,"WPDiscourse\\Test\\LogViewerTest::test_log_retrieval":4,"WPDiscourse\\Test\\SSOClientTest::test_parse_request_invalid_signature":4,"WPDiscourse\\Test\\SSOClientTest::test_parse_request_get_user_failed":4,"WPDiscourse\\Test\\SSOClientTest::test_parse_request_update_user_failed":4,"WPDiscourse\\Test\\SyncDiscourseUserTest::test_update_user_unable_to_find_user":6,"WPDiscourse\\Test\\SSOClientTest::test_parse_request":4},"times":{"WPDiscourse\\Test\\DiscourseCommentFormatterTest::test_format":0.013,"WPDiscourse\\Test\\DiscourseCommentFormatterTest::test_comment_cache":0.01,"WPDiscourse\\Test\\DiscourseCommentFormatterTest::test_missing_post_meta":0.01,"WPDiscourse\\Test\\DiscourseCommentTest::test_comments_disabled":0.008,"WPDiscourse\\Test\\DiscourseCommentTest::test_sync_comments":0.012,"WPDiscourse\\Test\\DiscourseCommentTest::test_sync_comments_handle_error_response":0.015,"WPDiscourse\\Test\\DiscourseCommentTest::test_get_comment_type_for_post_display_public_comments_only":0.019,"WPDiscourse\\Test\\DiscourseCommentTest::test_get_comment_type_for_post_display_public_comments_only_when_connection_fails":0.022,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status":0.001,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_legacy":0.001,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_response_error":0.003,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_response_error_legacy":0.003,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_scopes_invalid":0.006,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating":0.011,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_embed_error":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_category_error":0.012,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_response_body_error":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_enqueued_post":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_direct_db_publication_flags":0.012,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_pin_topic":0.012,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_discourse_username":0.021,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_discourse_username_with_single_user_api_key":0.019,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_updating":0.012,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_updating_with_deleted_topic":0.015,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_updating_with_featured_link":0.012,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_updating_with_direct_db_publication_flags":0.012,"WPDiscourse\\Test\\DiscoursePublishTest::test_exclude_tags_with_exclusionary_tag":0.014,"WPDiscourse\\Test\\DiscoursePublishTest::test_exclude_tags_with_non_exclusionary_tag":0.015,"WPDiscourse\\Test\\DiscoursePublishTest::test_wpdc_publish_options":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_force_publish_allowed_property":0.014,"WPDiscourse\\Test\\DiscoursePublishTest::test_force_publish_option":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_force_publish_max_age_prevents_older_posts_from_being_published":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_wp_discourse_before_xmlrpc_publish_filter":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_xmlrpc_publish_failure_notification":0.012,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_success":0,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_forbidden":0.004,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_unprocessable":0.004,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_failed_to_connect":0.003,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_no_user":0.009,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_user":0.007,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_logout":0.007,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_invalid_signature":0.01,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_invalid_nonce":0.011,"WPDiscourse\\Test\\DiscourseSSOTest::test_logout_from_discourse":0.009,"WPDiscourse\\Test\\DiscourseSSOTest::test_logout_from_discourse_failed_to_get_discourse_user":0.011,"WPDiscourse\\Test\\DiscourseSSOTest::test_logout_from_discourse_failed_to_logout":0.011,"WPDiscourse\\Test\\FileHandlerTest::test_construct":0,"WPDiscourse\\Test\\FileHandlerTest::test_enabled":0,"WPDiscourse\\Test\\FileHandlerTest::test_not_enabled":0.001,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_create":0.001,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_write":0.003,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_multiple":0.001,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_date_rotation":0.001,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_size_limit_rotation":0.01,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_number":0.001,"WPDiscourse\\Test\\FileHandlerTest::test_log_max_files":0.003,"WPDiscourse\\Test\\FileManagerTest::test_validation_uploads_creation":0.001,"WPDiscourse\\Test\\FileManagerTest::test_validation_logs_creation":0,"WPDiscourse\\Test\\FileManagerTest::test_validation_ready":0,"WPDiscourse\\Test\\FileManagerTest::test_validation_not_ready":0,"WPDiscourse\\Test\\FileManagerTest::test_validation_when_wp_uploads_not_writable":0,"WPDiscourse\\Test\\FileManagerTest::test_validation_when_folders_partially_restricted":0,"WPDiscourse\\Test\\LogViewerTest::test_file_handler_not_enabled":0.002,"WPDiscourse\\Test\\LogViewerTest::test_logs_not_enabled":0,"WPDiscourse\\Test\\LogViewerTest::test_log_retrieval":0.001,"WPDiscourse\\Test\\LoggerTest::test_create":0,"WPDiscourse\\Test\\LoggerTest::test_create_handler":0,"WPDiscourse\\Test\\LoggerTest::test_create_handler_formatter":0,"WPDiscourse\\Test\\LoggerTest::test_create_file_handler_not_enabled":0.001,"WPDiscourse\\Test\\LoggerTest::test_create_logs_not_enabled":0,"WPDiscourse\\Test\\SSOClientTest::test_parse_request":0.014,"WPDiscourse\\Test\\SSOClientTest::test_parse_request_invalid_signature":0.01,"WPDiscourse\\Test\\SSOClientTest::test_parse_request_get_user_failed":0.011,"WPDiscourse\\Test\\SSOClientTest::test_parse_request_update_user_failed":0.018,"WPDiscourse\\Test\\SyncDiscourseTopicTest::test_update_topic_content":0.01,"WPDiscourse\\Test\\SyncDiscourseTopicTest::test_update_topic_content_invalid_signature":0.009,"WPDiscourse\\Test\\SyncDiscourseUserTest::test_update_user":0.002,"WPDiscourse\\Test\\SyncDiscourseUserTest::test_update_user_using_discourse_sso_user_id":0.008,"WPDiscourse\\Test\\SyncDiscourseUserTest::test_update_user_using_email":0.008,"WPDiscourse\\Test\\SyncDiscourseUserTest::test_update_user_unable_to_find_user":0.01,"WPDiscourse\\Test\\UtilitiesTest::test_get_options":0.007,"WPDiscourse\\Test\\UtilitiesTest::test_validate":0.007,"WPDiscourse\\Test\\UtilitiesTest::test_get_discourse_categories":0.008,"WPDiscourse\\Test\\UtilitiesTest::test_get_discourse_user":0.008,"WPDiscourse\\Test\\UtilitiesTest::test_get_discourse_user_by_email":0.007,"WPDiscourse\\Test\\UtilitiesTest::test_sync_sso_record":0.008,"WPDiscourse\\Test\\UtilitiesTest::test_get_sso_params":0.005,"WPDiscourse\\Test\\UtilitiesTest::test_verify_discourse_webhook_request":0.007,"WPDiscourse\\Test\\UtilitiesTest::test_get_discourse_groups":0.007,"WPDiscourse\\Test\\UtilitiesTest::test_create_discourse_user":0.005,"WPDiscourse\\Test\\UtilitiesTest::test_add_user_to_discourse_group":0.006,"WPDiscourse\\Test\\UtilitiesTest::test_remove_user_from_discourse_group":0.006}}
{"version":1,"defects":{"WPDiscourse\\Test\\DiscourseCommentTest::test_sync_comments_handle_error_response":6,"WPDiscourse\\Test\\DiscourseCommentTest::test_get_comment_type_for_post_display_public_comments_only_when_connection_fails":6,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_response_error":6,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_response_error_legacy":6,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_scopes_invalid":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_embed_error":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_category_error":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_response_body_error":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_enqueued_post":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_updating_with_deleted_topic":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_forbidden":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_unprocessable":6,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_failed_to_connect":6,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_invalid_signature":6,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_invalid_nonce":6,"WPDiscourse\\Test\\DiscourseSSOTest::test_logout_from_discourse_failed_to_get_discourse_user":6,"WPDiscourse\\Test\\DiscourseSSOTest::test_logout_from_discourse_failed_to_logout":6,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_write":6,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_date_rotation":6,"WPDiscourse\\Test\\FileManagerTest::test_validation_uploads_creation":6,"WPDiscourse\\Test\\FileManagerTest::test_validation_logs_creation":6,"WPDiscourse\\Test\\LogViewerTest::test_log_retrieval":4,"WPDiscourse\\Test\\SSOClientTest::test_parse_request_invalid_signature":4,"WPDiscourse\\Test\\SSOClientTest::test_parse_request_get_user_failed":4,"WPDiscourse\\Test\\SSOClientTest::test_parse_request_update_user_failed":4,"WPDiscourse\\Test\\SyncDiscourseUserTest::test_update_user_unable_to_find_user":6,"WPDiscourse\\Test\\SSOClientTest::test_parse_request":4},"times":{"WPDiscourse\\Test\\DiscourseCommentFormatterTest::test_format":0.029,"WPDiscourse\\Test\\DiscourseCommentFormatterTest::test_comment_cache":0.02,"WPDiscourse\\Test\\DiscourseCommentFormatterTest::test_missing_post_meta":0.014,"WPDiscourse\\Test\\DiscourseCommentTest::test_comments_disabled":0.01,"WPDiscourse\\Test\\DiscourseCommentTest::test_sync_comments":0.013,"WPDiscourse\\Test\\DiscourseCommentTest::test_sync_comments_handle_error_response":0.016,"WPDiscourse\\Test\\DiscourseCommentTest::test_get_comment_type_for_post_display_public_comments_only":0.019,"WPDiscourse\\Test\\DiscourseCommentTest::test_get_comment_type_for_post_display_public_comments_only_when_connection_fails":0.022,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status":0.002,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_legacy":0.001,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_response_error":0.003,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_response_error_legacy":0.003,"WPDiscourse\\Test\\DiscourseConnectionTest::test_check_connection_status_scopes_invalid":0.006,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating":0.016,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_embed_error":0.011,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_category_error":0.025,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_response_body_error":0.015,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_enqueued_post":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_creating_with_direct_db_publication_flags":0.01,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_pin_topic":0.011,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_discourse_username":0.019,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_discourse_username_with_single_user_api_key":0.017,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_updating":0.009,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_updating_with_deleted_topic":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_updating_with_featured_link":0.011,"WPDiscourse\\Test\\DiscoursePublishTest::test_sync_to_discourse_when_updating_with_direct_db_publication_flags":0.011,"WPDiscourse\\Test\\DiscoursePublishTest::test_exclude_tags_with_exclusionary_tag":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_exclude_tags_with_non_exclusionary_tag":0.015,"WPDiscourse\\Test\\DiscoursePublishTest::test_wpdc_publish_options":0.014,"WPDiscourse\\Test\\DiscoursePublishTest::test_force_publish_allowed_property":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_force_publish_option":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_force_publish_max_age_prevents_older_posts_from_being_published":0.013,"WPDiscourse\\Test\\DiscoursePublishTest::test_wp_discourse_before_xmlrpc_publish_filter":0.014,"WPDiscourse\\Test\\DiscoursePublishTest::test_xmlrpc_publish_failure_notification":0.014,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_success":0,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_forbidden":0.004,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_unprocessable":0.004,"WPDiscourse\\Test\\DiscoursePublishTest::test_remote_post_failed_to_connect":0.004,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_no_user":0.008,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_user":0.007,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_logout":0.007,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_invalid_signature":0.01,"WPDiscourse\\Test\\DiscourseSSOTest::test_sso_parse_request_invalid_nonce":0.009,"WPDiscourse\\Test\\DiscourseSSOTest::test_logout_from_discourse":0.008,"WPDiscourse\\Test\\DiscourseSSOTest::test_logout_from_discourse_failed_to_get_discourse_user":0.01,"WPDiscourse\\Test\\DiscourseSSOTest::test_logout_from_discourse_failed_to_logout":0.011,"WPDiscourse\\Test\\FileHandlerTest::test_construct":0,"WPDiscourse\\Test\\FileHandlerTest::test_enabled":0,"WPDiscourse\\Test\\FileHandlerTest::test_not_enabled":0.001,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_create":0.001,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_write":0.003,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_multiple":0.001,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_date_rotation":0.001,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_size_limit_rotation":0.041,"WPDiscourse\\Test\\FileHandlerTest::test_log_file_number":0.001,"WPDiscourse\\Test\\FileHandlerTest::test_log_max_files":0.003,"WPDiscourse\\Test\\FileManagerTest::test_validation_uploads_creation":0.003,"WPDiscourse\\Test\\FileManagerTest::test_validation_logs_creation":0,"WPDiscourse\\Test\\FileManagerTest::test_validation_ready":0,"WPDiscourse\\Test\\FileManagerTest::test_validation_not_ready":0,"WPDiscourse\\Test\\FileManagerTest::test_validation_when_wp_uploads_not_writable":0,"WPDiscourse\\Test\\FileManagerTest::test_validation_when_folders_partially_restricted":0,"WPDiscourse\\Test\\LogViewerTest::test_file_handler_not_enabled":0.002,"WPDiscourse\\Test\\LogViewerTest::test_logs_not_enabled":0,"WPDiscourse\\Test\\LogViewerTest::test_log_retrieval":0.001,"WPDiscourse\\Test\\LoggerTest::test_create":0,"WPDiscourse\\Test\\LoggerTest::test_create_handler":0,"WPDiscourse\\Test\\LoggerTest::test_create_handler_formatter":0,"WPDiscourse\\Test\\LoggerTest::test_create_file_handler_not_enabled":0.001,"WPDiscourse\\Test\\LoggerTest::test_create_logs_not_enabled":0,"WPDiscourse\\Test\\SSOClientTest::test_parse_request":0.016,"WPDiscourse\\Test\\SSOClientTest::test_parse_request_invalid_signature":0.014,"WPDiscourse\\Test\\SSOClientTest::test_parse_request_get_user_failed":0.01,"WPDiscourse\\Test\\SSOClientTest::test_parse_request_update_user_failed":0.017,"WPDiscourse\\Test\\SyncDiscourseTopicTest::test_update_topic_content":0.01,"WPDiscourse\\Test\\SyncDiscourseTopicTest::test_update_topic_content_invalid_signature":0.009,"WPDiscourse\\Test\\SyncDiscourseUserTest::test_update_user":0.003,"WPDiscourse\\Test\\SyncDiscourseUserTest::test_update_user_using_discourse_sso_user_id":0.007,"WPDiscourse\\Test\\SyncDiscourseUserTest::test_update_user_using_email":0.008,"WPDiscourse\\Test\\SyncDiscourseUserTest::test_update_user_unable_to_find_user":0.01,"WPDiscourse\\Test\\UtilitiesTest::test_get_options":0.007,"WPDiscourse\\Test\\UtilitiesTest::test_validate":0.006,"WPDiscourse\\Test\\UtilitiesTest::test_get_discourse_categories":0.008,"WPDiscourse\\Test\\UtilitiesTest::test_get_discourse_user":0.007,"WPDiscourse\\Test\\UtilitiesTest::test_get_discourse_user_by_email":0.007,"WPDiscourse\\Test\\UtilitiesTest::test_sync_sso_record":0.008,"WPDiscourse\\Test\\UtilitiesTest::test_get_sso_params":0.005,"WPDiscourse\\Test\\UtilitiesTest::test_verify_discourse_webhook_request":0.006,"WPDiscourse\\Test\\UtilitiesTest::test_get_discourse_groups":0.007,"WPDiscourse\\Test\\UtilitiesTest::test_create_discourse_user":0.005,"WPDiscourse\\Test\\UtilitiesTest::test_add_user_to_discourse_group":0.005,"WPDiscourse\\Test\\UtilitiesTest::test_remove_user_from_discourse_group":0.006,"WPDiscourse\\Test\\UtilitiesTest::test_publish_to_discourse":0.016}}
22 changes: 22 additions & 0 deletions lib/utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,26 @@ public static function discourse_munge( $data, $schema ) {

return $result;
}

/**
* Publishes a post to a Discourse.
*
* @param string $post_id ID of the post to publish.
*
* @return void;
*/
public static function publish_to_discourse( $post_id ) {
$post = get_post( $post_id );

if ( !$post ) {
return new \WP_Error( 'wpdc_param_error', 'There is no WordPress post with the supplied id.' );
}

$email_notifier = new \WPDiscourse\EmailNotification\EmailNotification();
$publish = new \WPDiscourse\DiscoursePublish\DiscoursePublish( $email_notifier, false );
$publish->setup_options();
$publish->setup_logger();

return $publish->sync_to_discourse( $post_id, $post->post_title, $post->post_content );;
}
}
Loading

0 comments on commit ea2b41a

Please sign in to comment.