Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugins/ai-album-finder/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
vendor
build
37 changes: 37 additions & 0 deletions plugins/ai-album-finder/ai-album-finder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Plugin Name: AI Album Finder
* Description: A WordPress plugin that uses AI to help users find music albums based on their preferences.
* Version: 1.0.0
* Author: The WordPress Contributors
* License: GPL-2.0-or-later
*
* @package ai-album-finder
*/

define( "PLUGIN_DIR", plugin_dir_path( __FILE__ ) );
define( "PLUGIN_URL", plugins_url( '', __FILE__ ) );

use Developer_Showcase\AI_Album_Finder\Plugin_Main;
use Developer_Showcase\AI_Album_Finder\Chatbot_Assets;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( file_exists( dirname( __FILE__ ) . '/vendor/autoload.php' ) ) {
require_once dirname( __FILE__ ) . '/vendor/autoload.php';
}

function devshow_ai_album_finder_load(){
// Load the plugin.
$plugin_main = new Plugin_Main();
$plugin_main->add_hooks();

$chatbot_assets = new Chatbot_Assets( PLUGIN_DIR, PLUGIN_URL );
$chatbot_assets->add_hooks();

}

devshow_ai_album_finder_load();
29 changes: 29 additions & 0 deletions plugins/ai-album-finder/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "wptrainingteam/ai-album-finder",
"description": "AI powered album search",
"type": "wordpress-plugin",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "WordPress Contributors"
}
],
"minimum-stability": "stable",
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"php-http/discovery": true
}
},
"autoload": {
"psr-4": {
"Developer_Showcase\\": "includes/"
}
},
"require-dev": {
"wp-coding-standards/wpcs": "^3.0"
},
"require": {
"wordpress/wp-ai-client": "^0.2.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Chatbot Assets Handler
*
* Handles enqueuing of chatbot scripts and styles
*
* @package ai-album-finder
*/

namespace Developer_Showcase\AI_Album_Finder;

class Chatbot_Assets {

/**
* Plugin directory path.
*
* @var string
*/
private string $plugin_dir;

/**
* Plugin URL.
*
* @var string
*/
private string $plugin_url;

/**
* Constructor.
*
* @param string $plugin_dir Plugin directory path.
* @param string $plugin_url Plugin URL.
*/
public function __construct( string $plugin_dir, string $plugin_url ) {
$this->plugin_dir = $plugin_dir;
$this->plugin_url = $plugin_url;
}

/**
* Add hooks.
*/
public function add_hooks(): void {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) );
add_action( 'wp_footer', array( $this, 'render_chatbot_container' ) );
}

/**
* Enqueue chatbot assets.
*/
public function enqueue_assets(): void {
wp_enqueue_script( 'wp-ai-client' );

$asset_file = $this->plugin_dir . '/build/index.asset.php';

if ( ! file_exists( $asset_file ) ) {
return;
}

$asset = require $asset_file;

// Enqueue the main chatbot script.
wp_enqueue_script(
'ai-album-finder-chatbot',
$this->plugin_url . '/build/index.js',
$asset['dependencies'],
$asset['version'],
true
);

// Enqueue the chatbot styles.
wp_enqueue_style(
'ai-album-finder-chatbot',
$this->plugin_url . '/build/style-index.css',
array( 'wp-components' ),
$asset['version']
);

// Set up translations.
wp_set_script_translations(
'ai-album-finder-chatbot',
'ai-album-finder',
$this->plugin_dir . '/languages'
);
}

/**
* Render the chatbot container in the footer.
*/
public function render_chatbot_container(): void {
echo '<div id="ai-album-finder-chatbot"></div>';
}
}
22 changes: 22 additions & 0 deletions plugins/ai-album-finder/includes/AI_Album_Finder/Plugin_Main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Developer_Showcase\AI_Album_Finder;

use WordPress\AI_Client\AI_Client;

class Plugin_Main {

public function __construct() {
// Initialize chatbot assets handler.
}

public function add_hooks() {
add_action( 'init', array( $this, 'init' ) );
}

public function init(): void {
if ( class_exists( 'WordPress\AI_Client\AI_Client' ) ) {
AI_Client::init();
}
}
}
Loading