diff --git a/includes/class-webmention.php b/includes/class-webmention.php index f988547..167d7cb 100644 --- a/includes/class-webmention.php +++ b/includes/class-webmention.php @@ -34,6 +34,13 @@ class Webmention { */ private $default_post_types = array( 'post', 'page' ); + /** + * Whether the class has been initialized. + * + * @var boolean + */ + private $initialized = false; + /** * Get the instance of the class. * @@ -58,6 +65,10 @@ private function __construct() { * Initialize the plugin. */ public function init() { + if ( $this->initialized ) { + return; + } + $this->register_constants(); $this->register_hooks(); @@ -67,6 +78,8 @@ public function init() { // Load language files. load_plugin_textdomain( self::TEXT_DOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); + + $this->initialized = true; } /** diff --git a/tests/test-webmention.php b/tests/test-webmention.php index 378a06a..afdc05a 100644 --- a/tests/test-webmention.php +++ b/tests/test-webmention.php @@ -1,4 +1,21 @@ init(); + + $this->assertEquals( WEBMENTION_ALWAYS_SHOW_HEADERS, 0 ); + $this->assertEquals( WEBMENTION_COMMENT_APPROVE, 0 ); + $this->assertEquals( WEBMENTION_COMMENT_TYPE, 'webmention' ); + $this->assertEquals( WEBMENTION_GRAVATAR_CACHE_TIME, WEEK_IN_SECONDS ); + } + + public function test_register_hooks() { + \Webmention\Webmention::get_instance()->init(); + + // test if some hooks are registered + $this->assertEquals( has_action( 'init', array( \Webmention\Comment::class, 'init' ) ), 10 ); + $this->assertEquals( has_action( 'admin_menu', array( \Webmention\Admin::class, 'admin_menu' ) ), 10 ); + $this->assertEquals( has_action( 'admin_init', array( \Webmention\Admin::class, 'admin_init' ) ), 10 ); + } }