Skip to content

Commit

Permalink
Initiate Jetpack listening.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Lannoy committed Sep 13, 2019
1 parent 85c6c23 commit f08d7ed
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
71 changes: 71 additions & 0 deletions includes/listeners/class-jetpacklistener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Jetpack listener for DecaLog.
*
* Defines class for Jetpack listener.
*
* @package Listeners
* @author Pierre Lannoy <https://pierre.lannoy.fr/>.
* @since 1.4.0
*/

namespace Decalog\Listener;

/**
* Jetpack listener for DecaLog.
*
* Defines methods and properties for User Switching listener class.
*
* @package Listeners
* @author Pierre Lannoy <https://pierre.lannoy.fr/>.
* @since 1.4.0
*/
class JetpackListener extends AbstractListener {

/**
* Sets the listener properties.
*
* @since 1.0.0
*/
protected function init() {
$this->id = 'jetpack';
$this->class = 'plugin';
$this->product = 'Jetpack';
$this->name = 'Jetpack';
if ( defined( 'JETPACK__VERSION' ) ) {
$this->version = JETPACK__VERSION;
} else {
$this->version = 'x';
}
}

/**
* Verify if this listener is needed, mainly by verifying if the listen plugin/theme is loaded.
*
* @return boolean True if listener is needed, false otherwise.
* @since 1.4.0
*/
protected function is_available() {
return class_exists( 'Jetpack' );
}

/**
* "Launch" the listener.
*
* @return boolean True if listener was launched, false otherwise.
* @since 1.4.0
*/
protected function launch() {
add_action( 'jetpack_log_entry', [ $this, 'jetpack_log_entry' ], 10, 1 );
return true;
}

/**
* "jetpack_log_entry" event.
*
* @since 1.4.0
*/
public function jetpack_log_entry( $log_entry) {
$this->logger->emergency( print_r($log_entry, true) );
}
}
1 change: 1 addition & 0 deletions includes/listeners/class-listenerfactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ListenerFactory {
'.',
'index.php',
'class-abstractlistener.php',
'class-jetpacklistener.php',
'class-listenerfactory.php',
];

Expand Down

0 comments on commit f08d7ed

Please sign in to comment.