bbpress-api-server/bbpress-api-server.php

89 lines
2.5 KiB
PHP
Raw Normal View History

2025-03-04 14:55:39 +08:00
<?php
/**
* Plugin Name: bbPress API Server
2025-03-16 15:57:16 +08:00
* Plugin URI: https://wptopic.com/document/bbpress-api-server
* Description: Provides comprehensive API endpoints for bbPress forums, topics, and replies with creation capabilities
* Version: 2.0.0
* Author: WPTopic.com
* Author URI: https://wptopic.com
2025-03-04 14:55:39 +08:00
* Text Domain: bbpress-api-server
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
2025-03-16 15:57:16 +08:00
* Requires Plugins: bbpress
2025-03-04 14:55:39 +08:00
*/
if (!defined('ABSPATH')) {
exit;
}
// Define plugin constants
2025-03-16 15:57:16 +08:00
define('BBPAS_VERSION', '2.0.0');
2025-03-04 14:55:39 +08:00
define('BBPAS_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('BBPAS_PLUGIN_URL', plugin_dir_url(__FILE__));
2025-03-16 15:57:16 +08:00
define('BBPAS_API_NAMESPACE', 'bbpas/v2');
2025-03-04 14:55:39 +08:00
2025-03-16 15:57:16 +08:00
// Load dependent files
require_once BBPAS_PLUGIN_DIR . 'includes/endpoints.php';
require_once BBPAS_PLUGIN_DIR . 'includes/helpers.php';
require_once BBPAS_PLUGIN_DIR . 'includes/admin.php';
2025-03-04 14:55:39 +08:00
// Check if bbPress is active
function bbpas_check_required_plugins() {
if (!class_exists('bbPress')) {
add_action('admin_notices', 'bbpas_admin_notice');
return false;
}
return true;
}
2025-03-16 15:57:16 +08:00
// Display admin notice if bbPress is not active
2025-03-04 14:55:39 +08:00
function bbpas_admin_notice() {
2025-03-16 15:57:16 +08:00
echo '<div class="notice notice-error"><p>' . __('bbPress API Server requires bbPress to be installed and activated.', 'bbpress-api-server') . '</p></div>';
2025-03-04 14:55:39 +08:00
}
2025-03-16 15:57:16 +08:00
// Load plugin text domain for translations
function bbpas_load_textdomain() {
load_plugin_textdomain(
'bbpress-api-server',
false,
dirname(plugin_basename(__FILE__)) . '/languages'
2025-03-04 14:55:39 +08:00
);
}
2025-03-16 15:57:16 +08:00
add_action('plugins_loaded', 'bbpas_load_textdomain');
2025-03-04 14:55:39 +08:00
2025-03-16 15:57:16 +08:00
// Initialize plugin
2025-03-04 14:55:39 +08:00
add_action('plugins_loaded', function() {
if (bbpas_check_required_plugins()) {
add_action('rest_api_init', 'bbpas_register_routes');
}
});
2025-03-16 15:57:16 +08:00
// Activation hook
register_activation_hook(__FILE__, function() {
if (!class_exists('bbPress')) {
deactivate_plugins(plugin_basename(__FILE__));
wp_die(__('bbPress API Server requires bbPress to be installed and activated.', 'bbpress-api-server'));
}
flush_rewrite_rules();
});
// Deactivation hook
register_deactivation_hook(__FILE__, function() {
flush_rewrite_rules();
});
2025-03-04 14:55:39 +08:00
// Add admin menu
add_action('admin_menu', function() {
if (!bbpas_check_required_plugins()) {
return;
}
add_submenu_page(
'options-general.php',
__('bbPress API Server', 'bbpress-api-server'),
__('bbPress API', 'bbpress-api-server'),
'manage_options',
'bbpress-api-server',
'bbpas_admin_page'
);
});