Skip to content

Commit

Permalink
Merge pull request #82 from alleyinteractive/meta-box-helpers
Browse files Browse the repository at this point in the history
Meta box helper methods
  • Loading branch information
srtfisher authored Dec 19, 2022
2 parents 71dc39e + 953e5f7 commit 117b6a9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
25 changes: 24 additions & 1 deletion ai-logger.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Plugin Name: AI Logger
* Plugin Name: Alley Logger
* Plugin URI: https://github.com/alleyinteractive/logger
* Description: A Monolog-based logging tool for WordPress. Supports storing log message in a custom post type or in individual posts and terms.
* Version: 2.3.0
Expand Down Expand Up @@ -95,3 +95,26 @@ function ai_logger_to_post( int $post_id, string $meta_key = 'log', string $leve
function ai_logger_to_term( int $term_id, string $meta_key = 'log', string $level = Logger::DEBUG ): \AI_Logger\AI_Logger {
return ai_logger()->to_term( $meta_key, $term_id, $level );
}

/**
* Create a new post meta box to display logs stored in post meta.
*
* @param string $meta_key Meta key for the logs.
* @param string $title Title for the meta box.
* @return \AI_Logger\Meta_Box\Post_Meta_Box
*/
function ai_logger_post_meta_box( string $meta_key, string $title ): \AI_Logger\Meta_Box\Post_Meta_Box {
return new \AI_Logger\Meta_Box\Post_Meta_Box( $meta_key, $title );
}

/**
* Create a new term meta box to display logs stored in term meta.
*
* @param string $meta_key Meta key for the logs.
* @param string $title Title for the meta box.
* @param array $taxonomies Taxonomies to display the meta box on.
* @return \AI_Logger\Meta_Box\Term_Meta_Box
*/
function ai_logger_term_meta_box( string $meta_key, string $title, array $taxonomies ): \AI_Logger\Meta_Box\Term_Meta_Box {
return new \AI_Logger\Meta_Box\Term_Meta_Box( $meta_key, $title, $taxonomies );
}
19 changes: 19 additions & 0 deletions inc/class-ai-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ public function with_handlers( array $handlers ) {
return $logger;
}

/**
* Retrieve a logger instance with specific processors attached.
*
* @param \Monolog\Processor\ProcessorInterface[] $processors Processors to attach to the logger.
* @return static
*/
public function with_processors( array $processors ) {
$logger = clone $this;

// Clear all processors with popProcessor().
while ( $logger->logger->popProcessor() ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedWhile
// Do nothing.
}

$logger->logger->pushProcessor( $processors );

return $logger;
}

/**
* Retrieve a logger instance with default context attached.
*
Expand Down

0 comments on commit 117b6a9

Please sign in to comment.