Skip to content

Commit

Permalink
Merge pull request #22 from anatolinicolae/patch-1
Browse files Browse the repository at this point in the history
fix: empty option on fresh install leads to broken feed links
  • Loading branch information
pfefferle committed Apr 5, 2024
2 parents b239f8a + 9eb1ff4 commit 0bcd628
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion includes/class-pubsubhubbub-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function register_settings() {
'type' => 'string',
'description' => __( 'The WebSub/PubSubHubbub endpoints', 'pubsubhubbub' ),
'show_in_rest' => true,
'default' => "https://pubsubhubbub.appspot.com\nhttps://pubsubhubbub.superfeedr.com\nhttps://websubhub.com/hub",
'default' => implode( PHP_EOL, Pubsubhubbub::DEFAULT_HUBS ),
'sanitize_callback' => function ( $value ) {
$value = explode( PHP_EOL, $value );
$value = array_filter( array_map( 'trim', $value ) );
Expand Down
8 changes: 7 additions & 1 deletion includes/class-pubsubhubbub-publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ public static function publish_to_hub( $feed_urls ) {
*/
public static function get_hubs() {
$endpoints = get_option( 'pubsubhubbub_endpoints' );
$hub_urls = explode( PHP_EOL, $endpoints );

// Fail with an empty array when option retrieval fails
if ( ! $endpoints ) {
$hub_urls = Pubsubhubbub::DEFAULT_HUBS;
} else {
$hub_urls = explode( PHP_EOL, $endpoints );
}

return apply_filters( 'pubsubhubbub_hub_urls', $hub_urls );
}
Expand Down
6 changes: 6 additions & 0 deletions includes/class-pubsubhubbub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
* The WebSub/PubSubHubbub class
*/
class Pubsubhubbub {
const DEFAULT_HUBS = array(
'https://pubsubhubbub.appspot.com',
'https://pubsubhubbub.superfeedr.com',
'https://websubhub.com/hub',
);

/**
* Load the plugin textdomain.
*/
Expand Down
2 changes: 1 addition & 1 deletion pubsubhubbub.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function pubsubhubbub_init() {
*/
require_once( dirname( __FILE__ ) . '/includes/class-pubsubhubbub-admin.php' );

add_action( 'admin_init', array( 'PubSubHubbub_Admin', 'register_settings' ) );
add_action( 'init', array( 'PubSubHubbub_Admin', 'register_settings' ) );
add_action( 'admin_menu', array( 'Pubsubhubbub_Admin', 'add_plugin_menu' ) );

/**
Expand Down

0 comments on commit 0bcd628

Please sign in to comment.