Skip to content

Commit

Permalink
Merge pull request #90 from alleyinteractive/dont-require-autoloader
Browse files Browse the repository at this point in the history
Allow plugin to be loaded as a Composer dependency
  • Loading branch information
srtfisher authored Mar 20, 2023
2 parents 117b6a9 + e3c1d66 commit 0ebc5ee
Show file tree
Hide file tree
Showing 8 changed files with 812 additions and 740 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/dependabot-auto-approve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: dependabot-auto-approve
on:
pull_request:

permissions:
pull-requests: write
contents: write

jobs:
dependabot:
uses: alleyinteractive/.github/.github/workflows/dependabot-auto-approve.yml@main
10 changes: 10 additions & 0 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: dependabot-auto-merge
on: pull_request_target

permissions:
pull-requests: write
contents: write

jobs:
dependabot:
uses: alleyinteractive/.github/.github/workflows/dependabot-auto-merge.yml@main
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a
CHANGELOG](https://keepachangelog.com/en/1.0.0/).

## 2.4.0

- Renamed the main plugin file from `ai-logger.php` to `logger.php`.

## 2.3.0

- Dependency bumps.
Expand Down
116 changes: 2 additions & 114 deletions ai-logger.php
Original file line number Diff line number Diff line change
@@ -1,120 +1,8 @@
<?php
/**
* 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
* Author: Alley Interactive
* Author URI: https://alley.com/
* Requires at least: 5.9
* Tested up to: 5.9
*
* Text Domain: ai-logger
* Domain Path: /languages/
* Alias to the renamed plugin file.
*
* @package AI_Logger
*/

use Monolog\Logger;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

define( 'AI_LOGGER_PATH', __DIR__ );
define( 'AI_LOGGER_URL', trailingslashit( plugins_url( '/', __FILE__ ) ) );

// Check if Composer is installed.
if ( ! file_exists( __DIR__ . '/vendor/wordpress-autoload.php' ) ) {
\add_action(
'admin_notices',
function() {
?>
<div class="notice notice-error">
<p><?php esc_html_e( 'AI Logger: Composer is not installed and the plugin cannot load. Try using the `develop-built` branch or a `*-built` tag.', 'ai-logger' ); ?></p>
</div>
<?php
}
);

return;
}

// Include core dependencies.
require_once __DIR__ . '/vendor/wordpress-autoload.php';
require_once __DIR__ . '/inc/bootstrap.php';

/**
* Retrieve the core logger instance.
*
* @param array|string|null $context Default context to apply to the logger, optional.
* @return \AI_Logger\AI_Logger
*/
function ai_logger( array|string|null $context = null ): \AI_Logger\AI_Logger {
if ( $context ) {
return \AI_Logger\AI_Logger::instance()->with_context( $context );
}

return \AI_Logger\AI_Logger::instance();
}

/**
* Create a Query Monitor Logger instance.
*
* @param string $level The log level to use.
* @return \AI_Logger\AI_Logger
*/
function ai_logger_to_qm( string $level = Logger::DEBUG ): \AI_Logger\AI_Logger {
return ai_logger()->with_handlers(
[
new \AI_Logger\Handler\Query_Monitor_Handler( $level ),
]
);
}

/**
* Create a post logger instance.
*
* @param int $post_id Post ID.
* @param string $meta_key Meta key to log to.
* @param string $level The log level to use.
* @return \AI_Logger\AI_Logger
*/
function ai_logger_to_post( int $post_id, string $meta_key = 'log', string $level = Logger::DEBUG ): \AI_Logger\AI_Logger {
return ai_logger()->to_post( $meta_key, $post_id, $level );
}

/**
* Create a term logger instance.
*
* @param int $term_id Term ID.
* @param string $meta_key Meta key to log to.
* @param string $level The log level to use.
* @return \AI_Logger\AI_Logger
*/
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 );
}
require_once __DIR__ . '/logger.php';
11 changes: 4 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"authors": [
{
"name": "Alley Interactive",
"email": "info@alley.co"
"email": "info@alley.com"
}
],
"require": {
Expand All @@ -17,8 +17,8 @@
"psr/log": "^1.0|^2.0|^3.0"
},
"require-dev": {
"alleyinteractive/alley-coding-standards": "dev-feature/dependencies",
"mantle-framework/testkit": "^0.9.1",
"alleyinteractive/alley-coding-standards": "^1.0",
"mantle-framework/testkit": "^0.10",
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^9.3.3"
},
Expand All @@ -28,10 +28,7 @@
"dealerdirect/phpcodesniffer-composer-installer": true
},
"apcu-autoloader": true,
"optimize-autoloader": true,
"platform": {
"php": "8.0"
}
"optimize-autoloader": true
},
"extra": {
"wordpress-autoloader": {
Expand Down
Loading

0 comments on commit 0ebc5ee

Please sign in to comment.