Plugin Directory

Changeset 3444728


Ignore:
Timestamp:
01/22/2026 11:03:54 AM (4 weeks ago)
Author:
pfefferle
Message:

Update to version 4.0.0 from GitHub

Location:
pubsubhubbub
Files:
16 added
10 deleted
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • pubsubhubbub/tags/4.0.0/includes/class-pubsubhubbub.php

    r3065416 r3444728  
    11<?php
    22/**
    3  * The WebSub/PubSubHubbub class
     3 * Pubsubhubbub Class
     4 *
     5 * @package Pubsubhubbub
     6 */
     7
     8namespace Pubsubhubbub;
     9
     10use Pubsubhubbub\WP_Admin\Admin;
     11use Pubsubhubbub\Rest\Subscriber_Controller;
     12
     13/**
     14 * Pubsubhubbub Class
     15 *
     16 * @package Pubsubhubbub
    417 */
    518class Pubsubhubbub {
     19
     20    /**
     21     * Instance of the class.
     22     *
     23     * @var Pubsubhubbub
     24     */
     25    private static $instance;
     26
     27    /**
     28     * Default hub URLs.
     29     *
     30     * @var array
     31     */
    632    const DEFAULT_HUBS = array(
    733        'https://pubsubhubbub.appspot.com',
     
    1137
    1238    /**
    13      * Load the plugin textdomain.
     39     * Whether the class has been initialized.
     40     *
     41     * @var boolean
    1442     */
    15     public static function load_textdomain() {
    16         load_plugin_textdomain( 'pubsubhubbub', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
     43    private $initialized = false;
     44
     45    /**
     46     * Get the instance of the class.
     47     *
     48     * @return Pubsubhubbub
     49     */
     50    public static function get_instance() {
     51        if ( null === self::$instance ) {
     52            self::$instance = new self();
     53        }
     54
     55        return self::$instance;
     56    }
     57
     58    /**
     59     * Do not allow multiple instances of the class.
     60     */
     61    private function __construct() {
     62        // Do nothing.
     63    }
     64
     65    /**
     66     * Initialize the plugin.
     67     */
     68    public function init() {
     69        if ( $this->initialized ) {
     70            return;
     71        }
     72
     73        $this->register_hooks();
     74        $this->register_admin_hooks();
     75        $this->register_rest_hooks();
     76        $this->register_subscriber_hooks();
     77
     78        $this->initialized = true;
     79    }
     80
     81    /**
     82     * Get the plugin version.
     83     *
     84     * @return string
     85     */
     86    public function get_version() {
     87        return PUBSUBHUBBUB_VERSION;
     88    }
     89
     90    /**
     91     * Register hooks.
     92     */
     93    public function register_hooks() {
     94        // Publisher integration.
     95        \add_action( 'publish_post', array( Publisher::class, 'publish_post' ) );
     96        // phpcs:ignore Squiz.Commenting.InlineComment.InvalidEndChar
     97        // Uncomment to enable comment publishing: \add_action( 'comment_post', array( Publisher::class, 'publish_comment' ) );
     98
     99        // Feed integrations.
     100        \add_action( 'atom_head', array( Discovery::class, 'add_atom_link_tag' ) );
     101        \add_action( 'rdf_header', array( Discovery::class, 'add_rss_link_tag' ) );
     102        \add_action( 'rss2_head', array( Discovery::class, 'add_rss_link_tag' ) );
     103
     104        \add_action( 'comments_atom_head', array( Discovery::class, 'add_atom_link_tag' ) );
     105        \add_action( 'commentsrss2_head', array( Discovery::class, 'add_rss_link_tag' ) );
     106
     107        \add_action( 'rdf_ns', array( Discovery::class, 'add_rss_ns_link' ) );
     108
     109        \add_action( 'template_redirect', array( Discovery::class, 'template_redirect' ) );
     110    }
     111
     112    /**
     113     * Register admin hooks.
     114     */
     115    public function register_admin_hooks() {
     116        \add_action( 'admin_init', array( Admin::class, 'register_settings' ) );
     117        \add_action( 'admin_menu', array( Admin::class, 'add_plugin_menu' ) );
     118    }
     119
     120    /**
     121     * Register REST API hooks.
     122     */
     123    public function register_rest_hooks() {
     124        \add_action( 'rest_api_init', array( Subscriber_Controller::class, 'register_routes' ) );
     125    }
     126
     127    /**
     128     * Register subscriber action hooks.
     129     *
     130     * These hooks allow other plugins to trigger subscriptions via do_action().
     131     */
     132    public function register_subscriber_hooks() {
     133        \add_action( 'websub_subscribe', array( Subscriber::class, 'subscribe' ), 10, 3 );
     134        \add_action( 'websub_unsubscribe', array( Subscriber::class, 'unsubscribe' ), 10, 3 );
    17135    }
    18136}
  • pubsubhubbub/tags/4.0.0/includes/deprecated.php

    r2666072 r3444728  
    11<?php
    22/**
    3  * Beeing backwards compatible
    4  * based on a fix by Stephen Paul Weber (http://singpolyma.net)
     3 * Deprecated functions for backward compatibility.
    54 *
    6  * @deprecated
     5 * @package Pubsubhubbub
     6 */
     7
     8use Pubsubhubbub\Publisher;
     9
     10/**
     11 * Being backwards compatible.
     12 * Based on a fix by Stephen Paul Weber (http://singpolyma.net)
     13 *
     14 * @deprecated 3.0.0 Use pubsubhubbub_publish_to_hub() instead.
     15 *
     16 * @param mixed $deprecated Deprecated parameter.
     17 * @param array $feed_urls  A list of feed urls you want to publish.
     18 *
     19 * @return void
    720 */
    821function publish_to_hub( $deprecated, $feed_urls ) {
    922    _deprecated_function( __FUNCTION__, '3.0.0', 'pubsubhubbub_publish_to_hub()' );
    1023
    11     PubSubHubbub_Publisher::publish_to_hub( $feed_urls );
     24    Publisher::publish_to_hub( $feed_urls );
    1225}
    1326
    1427/**
    15  * The ability for other plugins to hook into the PuSH code
     28 * The ability for other plugins to hook into the PuSH code.
    1629 *
    17  * @param array $feed_urls a list of feed urls you want to publish
     30 * @deprecated 3.0.0 Use pubsubhubbub_publish_to_hub() instead.
    1831 *
    19  * @deprecated
     32 * @param array $feed_urls A list of feed urls you want to publish.
     33 *
     34 * @return void
    2035 */
    2136function pshb_publish_to_hub( $feed_urls ) {
    2237    _deprecated_function( __FUNCTION__, '3.0.0', 'pubsubhubbub_publish_to_hub()' );
    2338
    24     PubSubHubbub_Publisher::publish_to_hub( $feed_urls );
     39    Publisher::publish_to_hub( $feed_urls );
    2540}
    2641
    2742/**
    28  * Map old filter to new filter
     43 * The ability for other plugins to hook into the PuSH code.
    2944 *
    30  * @param array $feed_urls the list of feed urls
     45 * This function maintains backward compatibility with the old naming convention.
    3146 *
    32  * @return array filtered list
     47 * @param array $feed_urls A list of feed urls you want to publish.
    3348 *
    34  * @deprecated
     49 * @return void
     50 */
     51function pubsubhubbub_publish_to_hub( $feed_urls ) {
     52    Publisher::publish_to_hub( $feed_urls );
     53}
     54
     55/**
     56 * Get the endpoints from the WordPress options table.
     57 *
     58 * This function maintains backward compatibility with the old naming convention.
     59 *
     60 * @uses apply_filters() Calls 'websub_hub_urls' filter.
     61 *
     62 * @return array The hub URLs.
     63 */
     64function pubsubhubbub_get_hubs() {
     65    return Publisher::get_hubs();
     66}
     67
     68/**
     69 * Check if link supports PubSubHubbub or WebSub.
     70 *
     71 * This function maintains backward compatibility with the old naming convention.
     72 *
     73 * @return boolean
     74 */
     75function pubsubhubbub_show_discovery() {
     76    return \Pubsubhubbub\show_discovery();
     77}
     78
     79/**
     80 * Get the correct self URL.
     81 *
     82 * This function maintains backward compatibility with the old naming convention.
     83 *
     84 * @return string The self link URL.
     85 */
     86function pubsubhubbub_get_self_link() {
     87    return \Pubsubhubbub\get_self_link();
     88}
     89
     90/**
     91 * Return the list of feed types that are supported by PubSubHubbub.
     92 *
     93 * This function maintains backward compatibility with the old naming convention.
     94 *
     95 * @return array List of supported feed types.
     96 */
     97function pubsubhubbub_get_supported_feed_types() {
     98    return \Pubsubhubbub\get_supported_feed_types();
     99}
     100
     101/**
     102 * Return the list of comment feed types that are supported by PubSubHubbub.
     103 *
     104 * This function maintains backward compatibility with the old naming convention.
     105 *
     106 * @return array List of supported comment feed types.
     107 */
     108function pubsubhubbub_get_supported_comment_feed_types() {
     109    return \Pubsubhubbub\get_supported_comment_feed_types();
     110}
     111
     112/**
     113 * Map old filter to new filter.
     114 *
     115 * @deprecated 3.0.0
     116 *
     117 * @param array $feed_urls The list of feed urls.
     118 *
     119 * @return array Filtered list.
    35120 */
    36121function pshb_feed_urls( $feed_urls ) {
    37     //_deprecated_function( __FUNCTION__, '3.0.0', 'get_feed_urls_by_post_id()' );
    38 
    39122    return apply_filters( 'pshb_feed_urls', $feed_urls );
    40123}
    41 add_filter( 'pubsubhubbub_feed_urls', 'pshb_feed_urls' );
     124add_filter( 'websub_feed_urls', 'pshb_feed_urls' );
  • pubsubhubbub/tags/4.0.0/includes/functions.php

    r2618981 r3444728  
    11<?php
    22/**
    3  * The ability for other plugins to hook into the PuSH code
     3 * Helper functions for Pubsubhubbub.
    44 *
    5  * @param array $feed_urls a list of feed urls you want to publish
     5 * @package Pubsubhubbub
    66 */
    7 function pubsubhubbub_publish_to_hub( $feed_urls ) {
    8     PubSubHubbub_Publisher::publish_to_hub( $feed_urls );
     7
     8namespace Pubsubhubbub;
     9
     10/**
     11 * The ability for other plugins to hook into the PuSH code.
     12 *
     13 * @param array $feed_urls A list of feed urls you want to publish.
     14 *
     15 * @return void
     16 */
     17function publish_to_hub( $feed_urls ) {
     18    Publisher::publish_to_hub( $feed_urls );
    919}
    1020
    1121/**
    12  * Get the endpoints from the WordPress options table
    13  * valid parameters are "publish" or "subscribe"
     22 * Get the endpoints from the WordPress options table.
    1423 *
    15  * @uses apply_filters() Calls 'pubsubhubbub_hub_urls' filter
     24 * @uses apply_filters() Calls 'websub_hub_urls' filter.
     25 *
     26 * @return array The hub URLs.
    1627 */
    17 function pubsubhubbub_get_hubs() {
    18     return PubSubHubbub_Publisher::get_hubs();
     28function get_hubs() {
     29    return Publisher::get_hubs();
    1930}
    2031
    2132/**
    22  * Check if link supports PubSubHubbub or WebSub
     33 * Check if link supports WebSub.
    2334 *
    2435 * @return boolean
    2536 */
    26 function pubsubhubbub_show_discovery() {
     37function show_discovery() {
    2738    $show_discovery = false;
    2839
    29     $supported_feed_types = apply_filters( 'pubsubhubbub_show_discovery_for_feed_types', pubsubhubbub_get_supported_feed_types() );
    30     $supported_comment_feed_types = apply_filters( 'pubsubhubbub_show_discovery_for_comment_feed_types', pubsubhubbub_get_supported_comment_feed_types() );
     40    /**
     41     * Filter the list of feed types that show WebSub discovery.
     42     *
     43     * @since 4.0.0
     44     *
     45     * @param array $feed_types List of feed types (e.g., 'atom', 'rss2').
     46     */
     47    $supported_feed_types = \apply_filters_deprecated( 'pubsubhubbub_show_discovery_for_feed_types', array( get_supported_feed_types() ), '4.0.0', 'websub_show_discovery_for_feed_types' );
     48    $supported_feed_types = \apply_filters( 'websub_show_discovery_for_feed_types', $supported_feed_types );
     49
     50    /**
     51     * Filter the list of comment feed types that show WebSub discovery.
     52     *
     53     * @since 4.0.0
     54     *
     55     * @param array $feed_types List of comment feed types (e.g., 'atom', 'rss2').
     56     */
     57    $supported_comment_feed_types = \apply_filters_deprecated( 'pubsubhubbub_show_discovery_for_comment_feed_types', array( get_supported_comment_feed_types() ), '4.0.0', 'websub_show_discovery_for_comment_feed_types' );
     58    $supported_comment_feed_types = \apply_filters( 'websub_show_discovery_for_comment_feed_types', $supported_comment_feed_types );
    3159
    3260    if (
    33         ( is_feed( $supported_feed_types ) && ! is_date() && ! is_post_type_archive() && ! is_singular() ) ||
    34         ( is_feed( $supported_comment_feed_types ) && is_singular() ) ||
    35         ( is_home() && current_theme_supports( 'microformats2' ) )
     61        ( \is_feed( $supported_feed_types ) && ! \is_date() && ! \is_post_type_archive() && ! \is_singular() ) ||
     62        ( \is_feed( $supported_comment_feed_types ) && \is_singular() ) ||
     63        ( \is_home() && \current_theme_supports( 'microformats2' ) )
    3664    ) {
    3765        $show_discovery = true;
    3866    }
    3967
    40     return apply_filters( 'pubsubhubbub_show_discovery', $show_discovery );
     68    /**
     69     * Filter whether to show WebSub discovery links.
     70     *
     71     * @since 4.0.0
     72     *
     73     * @param bool $show_discovery Whether to show discovery links.
     74     */
     75    $show_discovery = \apply_filters_deprecated( 'pubsubhubbub_show_discovery', array( $show_discovery ), '4.0.0', 'websub_show_discovery' );
     76    $show_discovery = \apply_filters( 'websub_show_discovery', $show_discovery );
     77
     78    return $show_discovery;
    4179}
    4280
    4381/**
    44  * Get the correct self URL
     82 * Get the correct self URL.
    4583 *
    46  * @return boolean
     84 * @return string The self link URL.
    4785 */
    48 function pubsubhubbub_get_self_link() {
    49     $host = wp_parse_url( home_url() );
     86function get_self_link() {
     87    $host = \wp_parse_url( \home_url() );
     88    // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
     89    $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? \wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
    5090
    51     return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) );
     91    return \esc_url( \apply_filters( 'self_link', \set_url_scheme( 'http://' . $host['host'] . $request_uri ) ) );
    5292}
    5393
    5494/**
    55  * Return the list of feed types that are supported by PubSubHubbub
     95 * Return the list of feed types that are supported by PubSubHubbub.
    5696 *
    57  * @return array List of supported feed types
     97 * @return array List of supported feed types.
    5898 */
    59 function pubsubhubbub_get_supported_feed_types() {
    60     return apply_filters( 'pubsubhubbub_supported_feed_types', array( 'atom', 'rss2' ) );
     99function get_supported_feed_types() {
     100    /**
     101     * Filter the list of supported feed types for WebSub.
     102     *
     103     * @since 4.0.0
     104     *
     105     * @param array $feed_types List of supported feed types. Default: array( 'atom', 'rss2' ).
     106     */
     107    $feed_types = \apply_filters_deprecated( 'pubsubhubbub_supported_feed_types', array( array( 'atom', 'rss2' ) ), '4.0.0', 'websub_supported_feed_types' );
     108    $feed_types = \apply_filters( 'websub_supported_feed_types', $feed_types );
     109
     110    return $feed_types;
    61111}
    62112
    63113/**
    64  * Return the list of comment feed types that are supported by PubSubHubbub
     114 * Return the list of comment feed types that are supported by PubSubHubbub.
    65115 *
    66  * @return array List of supported comment feed types
     116 * @return array List of supported comment feed types.
    67117 */
    68 function pubsubhubbub_get_supported_comment_feed_types() {
    69     return apply_filters( 'pubsubhubbub_supported_comment_feed_types', array( 'atom', 'rss2' ) );
     118function get_supported_comment_feed_types() {
     119    /**
     120     * Filter the list of supported comment feed types for WebSub.
     121     *
     122     * @since 4.0.0
     123     *
     124     * @param array $feed_types List of supported comment feed types. Default: array( 'atom', 'rss2' ).
     125     */
     126    $feed_types = \apply_filters_deprecated( 'pubsubhubbub_supported_comment_feed_types', array( array( 'atom', 'rss2' ) ), '4.0.0', 'websub_supported_comment_feed_types' );
     127    $feed_types = \apply_filters( 'websub_supported_comment_feed_types', $feed_types );
     128
     129    return $feed_types;
    70130}
  • pubsubhubbub/tags/4.0.0/pubsubhubbub.php

    r3065416 r3444728  
    44 * Plugin URI: https://github.com/pubsubhubbub/wordpress-pubsubhubbub/
    55 * Description: A better way to tell the world when your blog is updated.
    6  * Version: 3.2.1
     6 * Version: 4.0.0
    77 * Author: PubSubHubbub Team
    88 * Author URI: https://github.com/pubsubhubbub/wordpress-pubsubhubbub
     
    1010 * License URI: http://opensource.org/licenses/MIT
    1111 * Text Domain: pubsubhubbub
    12  * Domain Path: /languages
     12 * Requires PHP: 7.2
     13 *
     14 * @package Pubsubhubbub
    1315 */
    1416
    15 /**
    16  * Initialize plugin
    17  */
    18 function pubsubhubbub_init() {
    19     require_once( dirname( __FILE__ ) . '/includes/functions.php' );
     17namespace Pubsubhubbub;
    2018
    21     /**
    22      * Publisher integration
    23      */
    24     require_once( dirname( __FILE__ ) . '/includes/class-pubsubhubbub-publisher.php' );
     19\defined( 'ABSPATH' ) || exit;
    2520
    26     add_action( 'publish_post', array( 'PubSubHubbub_Publisher', 'publish_post' ) );
    27     //add_action( 'comment_post', array( 'PubSubHubbub_Publisher', 'publish_comment' ) );
     21\define( 'PUBSUBHUBBUB_VERSION', '4.0.0' );
     22\define( 'PUBSUBHUBBUB_PLUGIN_DIR', \plugin_dir_path( __FILE__ ) );
     23\define( 'PUBSUBHUBBUB_PLUGIN_BASENAME', \plugin_basename( __FILE__ ) );
     24\define( 'PUBSUBHUBBUB_PLUGIN_FILE', __FILE__ );
     25\define( 'PUBSUBHUBBUB_PLUGIN_URL', \plugin_dir_url( __FILE__ ) );
    2826
    29     /**
    30      * Admin panel
    31      */
    32     require_once( dirname( __FILE__ ) . '/includes/class-pubsubhubbub-admin.php' );
     27// Load the autoloader.
     28require_once PUBSUBHUBBUB_PLUGIN_DIR . 'includes/class-autoloader.php';
    3329
    34     add_action( 'init', array( 'PubSubHubbub_Admin', 'register_settings' ) );
    35     add_action( 'admin_menu', array( 'Pubsubhubbub_Admin', 'add_plugin_menu' ) );
     30// Load helper functions.
     31require_once PUBSUBHUBBUB_PLUGIN_DIR . 'includes/functions.php';
    3632
    37     /**
    38      * Feed integrations
    39      */
    40     require_once( dirname( __FILE__ ) . '/includes/class-pubsubhubbub-topics.php' );
     33// Load deprecated functions for backward compatibility.
     34require_once PUBSUBHUBBUB_PLUGIN_DIR . 'includes/deprecated.php';
    4135
    42     add_action( 'atom_head', array( 'Pubsubhubbub_Topics', 'add_atom_link_tag' ) );
    43     add_action( 'rdf_header', array( 'Pubsubhubbub_Topics', 'add_rss_link_tag' ) );
    44     add_action( 'rss2_head', array( 'Pubsubhubbub_Topics', 'add_rss_link_tag' ) );
     36// Register the autoloader.
     37Autoloader::register_path( __NAMESPACE__, PUBSUBHUBBUB_PLUGIN_DIR . 'includes' );
    4538
    46     add_action( 'comments_atom_head', array( 'Pubsubhubbub_Topics', 'add_atom_link_tag' ) );
    47     add_action( 'commentsrss2_head', array( 'Pubsubhubbub_Topics', 'add_rss_link_tag' ) );
    48 
    49     add_action( 'rdf_ns', array( 'Pubsubhubbub_Topics', 'add_rss_ns_link' ) );
    50 
    51     add_action( 'template_redirect', array( 'Pubsubhubbub_Topics', 'template_redirect' ) );
    52 
    53     /**
    54      * Main class
    55      */
    56     require_once( dirname( __FILE__ ) . '/includes/class-pubsubhubbub.php' );
    57 
    58     add_action( 'init', array( 'PubSubHubbub', 'load_textdomain' ) );
    59 
    60     /**
    61      * Deprecated functions
    62      */
    63     require_once( dirname( __FILE__ ) . '/includes/deprecated.php' );
    64 }
    65 
    66 add_action( 'plugins_loaded', 'pubsubhubbub_init' );
     39// Initialize the plugin.
     40$pubsubhubbub = Pubsubhubbub::get_instance();
     41$pubsubhubbub->init();
  • pubsubhubbub/trunk/includes/class-pubsubhubbub.php

    r3065416 r3444728  
    11<?php
    22/**
    3  * The WebSub/PubSubHubbub class
     3 * Pubsubhubbub Class
     4 *
     5 * @package Pubsubhubbub
     6 */
     7
     8namespace Pubsubhubbub;
     9
     10use Pubsubhubbub\WP_Admin\Admin;
     11use Pubsubhubbub\Rest\Subscriber_Controller;
     12
     13/**
     14 * Pubsubhubbub Class
     15 *
     16 * @package Pubsubhubbub
    417 */
    518class Pubsubhubbub {
     19
     20    /**
     21     * Instance of the class.
     22     *
     23     * @var Pubsubhubbub
     24     */
     25    private static $instance;
     26
     27    /**
     28     * Default hub URLs.
     29     *
     30     * @var array
     31     */
    632    const DEFAULT_HUBS = array(
    733        'https://pubsubhubbub.appspot.com',
     
    1137
    1238    /**
    13      * Load the plugin textdomain.
     39     * Whether the class has been initialized.
     40     *
     41     * @var boolean
    1442     */
    15     public static function load_textdomain() {
    16         load_plugin_textdomain( 'pubsubhubbub', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
     43    private $initialized = false;
     44
     45    /**
     46     * Get the instance of the class.
     47     *
     48     * @return Pubsubhubbub
     49     */
     50    public static function get_instance() {
     51        if ( null === self::$instance ) {
     52            self::$instance = new self();
     53        }
     54
     55        return self::$instance;
     56    }
     57
     58    /**
     59     * Do not allow multiple instances of the class.
     60     */
     61    private function __construct() {
     62        // Do nothing.
     63    }
     64
     65    /**
     66     * Initialize the plugin.
     67     */
     68    public function init() {
     69        if ( $this->initialized ) {
     70            return;
     71        }
     72
     73        $this->register_hooks();
     74        $this->register_admin_hooks();
     75        $this->register_rest_hooks();
     76        $this->register_subscriber_hooks();
     77
     78        $this->initialized = true;
     79    }
     80
     81    /**
     82     * Get the plugin version.
     83     *
     84     * @return string
     85     */
     86    public function get_version() {
     87        return PUBSUBHUBBUB_VERSION;
     88    }
     89
     90    /**
     91     * Register hooks.
     92     */
     93    public function register_hooks() {
     94        // Publisher integration.
     95        \add_action( 'publish_post', array( Publisher::class, 'publish_post' ) );
     96        // phpcs:ignore Squiz.Commenting.InlineComment.InvalidEndChar
     97        // Uncomment to enable comment publishing: \add_action( 'comment_post', array( Publisher::class, 'publish_comment' ) );
     98
     99        // Feed integrations.
     100        \add_action( 'atom_head', array( Discovery::class, 'add_atom_link_tag' ) );
     101        \add_action( 'rdf_header', array( Discovery::class, 'add_rss_link_tag' ) );
     102        \add_action( 'rss2_head', array( Discovery::class, 'add_rss_link_tag' ) );
     103
     104        \add_action( 'comments_atom_head', array( Discovery::class, 'add_atom_link_tag' ) );
     105        \add_action( 'commentsrss2_head', array( Discovery::class, 'add_rss_link_tag' ) );
     106
     107        \add_action( 'rdf_ns', array( Discovery::class, 'add_rss_ns_link' ) );
     108
     109        \add_action( 'template_redirect', array( Discovery::class, 'template_redirect' ) );
     110    }
     111
     112    /**
     113     * Register admin hooks.
     114     */
     115    public function register_admin_hooks() {
     116        \add_action( 'admin_init', array( Admin::class, 'register_settings' ) );
     117        \add_action( 'admin_menu', array( Admin::class, 'add_plugin_menu' ) );
     118    }
     119
     120    /**
     121     * Register REST API hooks.
     122     */
     123    public function register_rest_hooks() {
     124        \add_action( 'rest_api_init', array( Subscriber_Controller::class, 'register_routes' ) );
     125    }
     126
     127    /**
     128     * Register subscriber action hooks.
     129     *
     130     * These hooks allow other plugins to trigger subscriptions via do_action().
     131     */
     132    public function register_subscriber_hooks() {
     133        \add_action( 'websub_subscribe', array( Subscriber::class, 'subscribe' ), 10, 3 );
     134        \add_action( 'websub_unsubscribe', array( Subscriber::class, 'unsubscribe' ), 10, 3 );
    17135    }
    18136}
  • pubsubhubbub/trunk/includes/deprecated.php

    r2666072 r3444728  
    11<?php
    22/**
    3  * Beeing backwards compatible
    4  * based on a fix by Stephen Paul Weber (http://singpolyma.net)
     3 * Deprecated functions for backward compatibility.
    54 *
    6  * @deprecated
     5 * @package Pubsubhubbub
     6 */
     7
     8use Pubsubhubbub\Publisher;
     9
     10/**
     11 * Being backwards compatible.
     12 * Based on a fix by Stephen Paul Weber (http://singpolyma.net)
     13 *
     14 * @deprecated 3.0.0 Use pubsubhubbub_publish_to_hub() instead.
     15 *
     16 * @param mixed $deprecated Deprecated parameter.
     17 * @param array $feed_urls  A list of feed urls you want to publish.
     18 *
     19 * @return void
    720 */
    821function publish_to_hub( $deprecated, $feed_urls ) {
    922    _deprecated_function( __FUNCTION__, '3.0.0', 'pubsubhubbub_publish_to_hub()' );
    1023
    11     PubSubHubbub_Publisher::publish_to_hub( $feed_urls );
     24    Publisher::publish_to_hub( $feed_urls );
    1225}
    1326
    1427/**
    15  * The ability for other plugins to hook into the PuSH code
     28 * The ability for other plugins to hook into the PuSH code.
    1629 *
    17  * @param array $feed_urls a list of feed urls you want to publish
     30 * @deprecated 3.0.0 Use pubsubhubbub_publish_to_hub() instead.
    1831 *
    19  * @deprecated
     32 * @param array $feed_urls A list of feed urls you want to publish.
     33 *
     34 * @return void
    2035 */
    2136function pshb_publish_to_hub( $feed_urls ) {
    2237    _deprecated_function( __FUNCTION__, '3.0.0', 'pubsubhubbub_publish_to_hub()' );
    2338
    24     PubSubHubbub_Publisher::publish_to_hub( $feed_urls );
     39    Publisher::publish_to_hub( $feed_urls );
    2540}
    2641
    2742/**
    28  * Map old filter to new filter
     43 * The ability for other plugins to hook into the PuSH code.
    2944 *
    30  * @param array $feed_urls the list of feed urls
     45 * This function maintains backward compatibility with the old naming convention.
    3146 *
    32  * @return array filtered list
     47 * @param array $feed_urls A list of feed urls you want to publish.
    3348 *
    34  * @deprecated
     49 * @return void
     50 */
     51function pubsubhubbub_publish_to_hub( $feed_urls ) {
     52    Publisher::publish_to_hub( $feed_urls );
     53}
     54
     55/**
     56 * Get the endpoints from the WordPress options table.
     57 *
     58 * This function maintains backward compatibility with the old naming convention.
     59 *
     60 * @uses apply_filters() Calls 'websub_hub_urls' filter.
     61 *
     62 * @return array The hub URLs.
     63 */
     64function pubsubhubbub_get_hubs() {
     65    return Publisher::get_hubs();
     66}
     67
     68/**
     69 * Check if link supports PubSubHubbub or WebSub.
     70 *
     71 * This function maintains backward compatibility with the old naming convention.
     72 *
     73 * @return boolean
     74 */
     75function pubsubhubbub_show_discovery() {
     76    return \Pubsubhubbub\show_discovery();
     77}
     78
     79/**
     80 * Get the correct self URL.
     81 *
     82 * This function maintains backward compatibility with the old naming convention.
     83 *
     84 * @return string The self link URL.
     85 */
     86function pubsubhubbub_get_self_link() {
     87    return \Pubsubhubbub\get_self_link();
     88}
     89
     90/**
     91 * Return the list of feed types that are supported by PubSubHubbub.
     92 *
     93 * This function maintains backward compatibility with the old naming convention.
     94 *
     95 * @return array List of supported feed types.
     96 */
     97function pubsubhubbub_get_supported_feed_types() {
     98    return \Pubsubhubbub\get_supported_feed_types();
     99}
     100
     101/**
     102 * Return the list of comment feed types that are supported by PubSubHubbub.
     103 *
     104 * This function maintains backward compatibility with the old naming convention.
     105 *
     106 * @return array List of supported comment feed types.
     107 */
     108function pubsubhubbub_get_supported_comment_feed_types() {
     109    return \Pubsubhubbub\get_supported_comment_feed_types();
     110}
     111
     112/**
     113 * Map old filter to new filter.
     114 *
     115 * @deprecated 3.0.0
     116 *
     117 * @param array $feed_urls The list of feed urls.
     118 *
     119 * @return array Filtered list.
    35120 */
    36121function pshb_feed_urls( $feed_urls ) {
    37     //_deprecated_function( __FUNCTION__, '3.0.0', 'get_feed_urls_by_post_id()' );
    38 
    39122    return apply_filters( 'pshb_feed_urls', $feed_urls );
    40123}
    41 add_filter( 'pubsubhubbub_feed_urls', 'pshb_feed_urls' );
     124add_filter( 'websub_feed_urls', 'pshb_feed_urls' );
  • pubsubhubbub/trunk/includes/functions.php

    r2618981 r3444728  
    11<?php
    22/**
    3  * The ability for other plugins to hook into the PuSH code
     3 * Helper functions for Pubsubhubbub.
    44 *
    5  * @param array $feed_urls a list of feed urls you want to publish
     5 * @package Pubsubhubbub
    66 */
    7 function pubsubhubbub_publish_to_hub( $feed_urls ) {
    8     PubSubHubbub_Publisher::publish_to_hub( $feed_urls );
     7
     8namespace Pubsubhubbub;
     9
     10/**
     11 * The ability for other plugins to hook into the PuSH code.
     12 *
     13 * @param array $feed_urls A list of feed urls you want to publish.
     14 *
     15 * @return void
     16 */
     17function publish_to_hub( $feed_urls ) {
     18    Publisher::publish_to_hub( $feed_urls );
    919}
    1020
    1121/**
    12  * Get the endpoints from the WordPress options table
    13  * valid parameters are "publish" or "subscribe"
     22 * Get the endpoints from the WordPress options table.
    1423 *
    15  * @uses apply_filters() Calls 'pubsubhubbub_hub_urls' filter
     24 * @uses apply_filters() Calls 'websub_hub_urls' filter.
     25 *
     26 * @return array The hub URLs.
    1627 */
    17 function pubsubhubbub_get_hubs() {
    18     return PubSubHubbub_Publisher::get_hubs();
     28function get_hubs() {
     29    return Publisher::get_hubs();
    1930}
    2031
    2132/**
    22  * Check if link supports PubSubHubbub or WebSub
     33 * Check if link supports WebSub.
    2334 *
    2435 * @return boolean
    2536 */
    26 function pubsubhubbub_show_discovery() {
     37function show_discovery() {
    2738    $show_discovery = false;
    2839
    29     $supported_feed_types = apply_filters( 'pubsubhubbub_show_discovery_for_feed_types', pubsubhubbub_get_supported_feed_types() );
    30     $supported_comment_feed_types = apply_filters( 'pubsubhubbub_show_discovery_for_comment_feed_types', pubsubhubbub_get_supported_comment_feed_types() );
     40    /**
     41     * Filter the list of feed types that show WebSub discovery.
     42     *
     43     * @since 4.0.0
     44     *
     45     * @param array $feed_types List of feed types (e.g., 'atom', 'rss2').
     46     */
     47    $supported_feed_types = \apply_filters_deprecated( 'pubsubhubbub_show_discovery_for_feed_types', array( get_supported_feed_types() ), '4.0.0', 'websub_show_discovery_for_feed_types' );
     48    $supported_feed_types = \apply_filters( 'websub_show_discovery_for_feed_types', $supported_feed_types );
     49
     50    /**
     51     * Filter the list of comment feed types that show WebSub discovery.
     52     *
     53     * @since 4.0.0
     54     *
     55     * @param array $feed_types List of comment feed types (e.g., 'atom', 'rss2').
     56     */
     57    $supported_comment_feed_types = \apply_filters_deprecated( 'pubsubhubbub_show_discovery_for_comment_feed_types', array( get_supported_comment_feed_types() ), '4.0.0', 'websub_show_discovery_for_comment_feed_types' );
     58    $supported_comment_feed_types = \apply_filters( 'websub_show_discovery_for_comment_feed_types', $supported_comment_feed_types );
    3159
    3260    if (
    33         ( is_feed( $supported_feed_types ) && ! is_date() && ! is_post_type_archive() && ! is_singular() ) ||
    34         ( is_feed( $supported_comment_feed_types ) && is_singular() ) ||
    35         ( is_home() && current_theme_supports( 'microformats2' ) )
     61        ( \is_feed( $supported_feed_types ) && ! \is_date() && ! \is_post_type_archive() && ! \is_singular() ) ||
     62        ( \is_feed( $supported_comment_feed_types ) && \is_singular() ) ||
     63        ( \is_home() && \current_theme_supports( 'microformats2' ) )
    3664    ) {
    3765        $show_discovery = true;
    3866    }
    3967
    40     return apply_filters( 'pubsubhubbub_show_discovery', $show_discovery );
     68    /**
     69     * Filter whether to show WebSub discovery links.
     70     *
     71     * @since 4.0.0
     72     *
     73     * @param bool $show_discovery Whether to show discovery links.
     74     */
     75    $show_discovery = \apply_filters_deprecated( 'pubsubhubbub_show_discovery', array( $show_discovery ), '4.0.0', 'websub_show_discovery' );
     76    $show_discovery = \apply_filters( 'websub_show_discovery', $show_discovery );
     77
     78    return $show_discovery;
    4179}
    4280
    4381/**
    44  * Get the correct self URL
     82 * Get the correct self URL.
    4583 *
    46  * @return boolean
     84 * @return string The self link URL.
    4785 */
    48 function pubsubhubbub_get_self_link() {
    49     $host = wp_parse_url( home_url() );
     86function get_self_link() {
     87    $host = \wp_parse_url( \home_url() );
     88    // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
     89    $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? \wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
    5090
    51     return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) );
     91    return \esc_url( \apply_filters( 'self_link', \set_url_scheme( 'http://' . $host['host'] . $request_uri ) ) );
    5292}
    5393
    5494/**
    55  * Return the list of feed types that are supported by PubSubHubbub
     95 * Return the list of feed types that are supported by PubSubHubbub.
    5696 *
    57  * @return array List of supported feed types
     97 * @return array List of supported feed types.
    5898 */
    59 function pubsubhubbub_get_supported_feed_types() {
    60     return apply_filters( 'pubsubhubbub_supported_feed_types', array( 'atom', 'rss2' ) );
     99function get_supported_feed_types() {
     100    /**
     101     * Filter the list of supported feed types for WebSub.
     102     *
     103     * @since 4.0.0
     104     *
     105     * @param array $feed_types List of supported feed types. Default: array( 'atom', 'rss2' ).
     106     */
     107    $feed_types = \apply_filters_deprecated( 'pubsubhubbub_supported_feed_types', array( array( 'atom', 'rss2' ) ), '4.0.0', 'websub_supported_feed_types' );
     108    $feed_types = \apply_filters( 'websub_supported_feed_types', $feed_types );
     109
     110    return $feed_types;
    61111}
    62112
    63113/**
    64  * Return the list of comment feed types that are supported by PubSubHubbub
     114 * Return the list of comment feed types that are supported by PubSubHubbub.
    65115 *
    66  * @return array List of supported comment feed types
     116 * @return array List of supported comment feed types.
    67117 */
    68 function pubsubhubbub_get_supported_comment_feed_types() {
    69     return apply_filters( 'pubsubhubbub_supported_comment_feed_types', array( 'atom', 'rss2' ) );
     118function get_supported_comment_feed_types() {
     119    /**
     120     * Filter the list of supported comment feed types for WebSub.
     121     *
     122     * @since 4.0.0
     123     *
     124     * @param array $feed_types List of supported comment feed types. Default: array( 'atom', 'rss2' ).
     125     */
     126    $feed_types = \apply_filters_deprecated( 'pubsubhubbub_supported_comment_feed_types', array( array( 'atom', 'rss2' ) ), '4.0.0', 'websub_supported_comment_feed_types' );
     127    $feed_types = \apply_filters( 'websub_supported_comment_feed_types', $feed_types );
     128
     129    return $feed_types;
    70130}
  • pubsubhubbub/trunk/pubsubhubbub.php

    r3065416 r3444728  
    44 * Plugin URI: https://github.com/pubsubhubbub/wordpress-pubsubhubbub/
    55 * Description: A better way to tell the world when your blog is updated.
    6  * Version: 3.2.1
     6 * Version: 4.0.0
    77 * Author: PubSubHubbub Team
    88 * Author URI: https://github.com/pubsubhubbub/wordpress-pubsubhubbub
     
    1010 * License URI: http://opensource.org/licenses/MIT
    1111 * Text Domain: pubsubhubbub
    12  * Domain Path: /languages
     12 * Requires PHP: 7.2
     13 *
     14 * @package Pubsubhubbub
    1315 */
    1416
    15 /**
    16  * Initialize plugin
    17  */
    18 function pubsubhubbub_init() {
    19     require_once( dirname( __FILE__ ) . '/includes/functions.php' );
     17namespace Pubsubhubbub;
    2018
    21     /**
    22      * Publisher integration
    23      */
    24     require_once( dirname( __FILE__ ) . '/includes/class-pubsubhubbub-publisher.php' );
     19\defined( 'ABSPATH' ) || exit;
    2520
    26     add_action( 'publish_post', array( 'PubSubHubbub_Publisher', 'publish_post' ) );
    27     //add_action( 'comment_post', array( 'PubSubHubbub_Publisher', 'publish_comment' ) );
     21\define( 'PUBSUBHUBBUB_VERSION', '4.0.0' );
     22\define( 'PUBSUBHUBBUB_PLUGIN_DIR', \plugin_dir_path( __FILE__ ) );
     23\define( 'PUBSUBHUBBUB_PLUGIN_BASENAME', \plugin_basename( __FILE__ ) );
     24\define( 'PUBSUBHUBBUB_PLUGIN_FILE', __FILE__ );
     25\define( 'PUBSUBHUBBUB_PLUGIN_URL', \plugin_dir_url( __FILE__ ) );
    2826
    29     /**
    30      * Admin panel
    31      */
    32     require_once( dirname( __FILE__ ) . '/includes/class-pubsubhubbub-admin.php' );
     27// Load the autoloader.
     28require_once PUBSUBHUBBUB_PLUGIN_DIR . 'includes/class-autoloader.php';
    3329
    34     add_action( 'init', array( 'PubSubHubbub_Admin', 'register_settings' ) );
    35     add_action( 'admin_menu', array( 'Pubsubhubbub_Admin', 'add_plugin_menu' ) );
     30// Load helper functions.
     31require_once PUBSUBHUBBUB_PLUGIN_DIR . 'includes/functions.php';
    3632
    37     /**
    38      * Feed integrations
    39      */
    40     require_once( dirname( __FILE__ ) . '/includes/class-pubsubhubbub-topics.php' );
     33// Load deprecated functions for backward compatibility.
     34require_once PUBSUBHUBBUB_PLUGIN_DIR . 'includes/deprecated.php';
    4135
    42     add_action( 'atom_head', array( 'Pubsubhubbub_Topics', 'add_atom_link_tag' ) );
    43     add_action( 'rdf_header', array( 'Pubsubhubbub_Topics', 'add_rss_link_tag' ) );
    44     add_action( 'rss2_head', array( 'Pubsubhubbub_Topics', 'add_rss_link_tag' ) );
     36// Register the autoloader.
     37Autoloader::register_path( __NAMESPACE__, PUBSUBHUBBUB_PLUGIN_DIR . 'includes' );
    4538
    46     add_action( 'comments_atom_head', array( 'Pubsubhubbub_Topics', 'add_atom_link_tag' ) );
    47     add_action( 'commentsrss2_head', array( 'Pubsubhubbub_Topics', 'add_rss_link_tag' ) );
    48 
    49     add_action( 'rdf_ns', array( 'Pubsubhubbub_Topics', 'add_rss_ns_link' ) );
    50 
    51     add_action( 'template_redirect', array( 'Pubsubhubbub_Topics', 'template_redirect' ) );
    52 
    53     /**
    54      * Main class
    55      */
    56     require_once( dirname( __FILE__ ) . '/includes/class-pubsubhubbub.php' );
    57 
    58     add_action( 'init', array( 'PubSubHubbub', 'load_textdomain' ) );
    59 
    60     /**
    61      * Deprecated functions
    62      */
    63     require_once( dirname( __FILE__ ) . '/includes/deprecated.php' );
    64 }
    65 
    66 add_action( 'plugins_loaded', 'pubsubhubbub_init' );
     39// Initialize the plugin.
     40$pubsubhubbub = Pubsubhubbub::get_instance();
     41$pubsubhubbub->init();
Note: See TracChangeset for help on using the changeset viewer.