v1.0.0
This commit is contained in:
commit
a157afe625
21 changed files with 4623 additions and 0 deletions
147
robotstxt-ai-translator.php
Normal file
147
robotstxt-ai-translator.php
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin Name: AI Translator (by ROBOTSTXT)
|
||||
* Plugin URI: https://git.robotstxt.es/ROBOTSTXT/robotstxt-ai-translator
|
||||
* Gitea Plugin URI: ROBOTSTXT/robotstxt-ai-translator
|
||||
* Description: Translate post titles and content from the editor using the native WordPress AI plugin as backend. Multisite-ready with global or per-site configuration.
|
||||
* Version: 1.0.0
|
||||
* Author: ROBOTSTXT
|
||||
* Author URI: https://www.robotstxt.es/
|
||||
* License: GPL-3.0-or-later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
* Text Domain: robotstxt-ai-translator
|
||||
* Domain Path: /languages
|
||||
* Requires at least: 7.0
|
||||
* Requires PHP: 7.4
|
||||
* Requires Plugins: ai
|
||||
* Network: true
|
||||
*
|
||||
* @package ROBOTSTXT\AI_Translator
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin version.
|
||||
*/
|
||||
define( 'AI_TRANSLATOR_VERSION', '1.0.0' );
|
||||
|
||||
/**
|
||||
* Main plugin file path.
|
||||
*/
|
||||
define( 'AI_TRANSLATOR_FILE', __FILE__ );
|
||||
|
||||
/**
|
||||
* Plugin directory path (with trailing slash).
|
||||
*/
|
||||
define( 'AI_TRANSLATOR_DIR', plugin_dir_path( __FILE__ ) );
|
||||
|
||||
/**
|
||||
* Plugin URL (with trailing slash).
|
||||
*/
|
||||
define( 'AI_TRANSLATOR_URL', plugin_dir_url( __FILE__ ) );
|
||||
|
||||
/**
|
||||
* Plugin basename (e.g. robotstxt-ai-translator/robotstxt-ai-translator.php).
|
||||
*/
|
||||
define( 'AI_TRANSLATOR_BASENAME', plugin_basename( __FILE__ ) );
|
||||
|
||||
/**
|
||||
* REST API namespace.
|
||||
*/
|
||||
define( 'AI_TRANSLATOR_REST_NAMESPACE', 'ai-translator/v1' );
|
||||
|
||||
require_once AI_TRANSLATOR_DIR . 'includes/class-ai-translator-settings.php';
|
||||
require_once AI_TRANSLATOR_DIR . 'includes/class-ai-translator-translator.php';
|
||||
require_once AI_TRANSLATOR_DIR . 'includes/class-ai-translator-admin.php';
|
||||
require_once AI_TRANSLATOR_DIR . 'includes/class-ai-translator-editor-ui.php';
|
||||
require_once AI_TRANSLATOR_DIR . 'robotstxt-updater.php';
|
||||
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
require_once AI_TRANSLATOR_DIR . 'includes/class-ai-translator-cli.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the plugin text domain.
|
||||
*
|
||||
* Hooked on `init` per WordPress 6.7+ guidance (loading earlier triggers a
|
||||
* `_load_textdomain_just_in_time` deprecation notice).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function ai_translator_load_textdomain() {
|
||||
load_plugin_textdomain(
|
||||
'robotstxt-ai-translator',
|
||||
false,
|
||||
dirname( AI_TRANSLATOR_BASENAME ) . '/languages'
|
||||
);
|
||||
}
|
||||
add_action( 'init', 'ai_translator_load_textdomain' );
|
||||
|
||||
/**
|
||||
* Bootstraps the plugin once all plugins are loaded.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function ai_translator_bootstrap() {
|
||||
$settings = new AI_Translator_Settings();
|
||||
$translator = new AI_Translator_Translator();
|
||||
$admin = new AI_Translator_Admin( $settings );
|
||||
$editor_ui = new AI_Translator_Editor_UI( $settings, $translator );
|
||||
|
||||
$admin->register();
|
||||
$editor_ui->register();
|
||||
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
$cli = new AI_Translator_CLI( $settings, $translator );
|
||||
$cli->register();
|
||||
}
|
||||
|
||||
Robotstxt_Updater::init( AI_TRANSLATOR_FILE );
|
||||
}
|
||||
add_action( 'plugins_loaded', 'ai_translator_bootstrap' );
|
||||
|
||||
/**
|
||||
* Renders an admin notice when the WordPress AI plugin is not active.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function ai_translator_dependency_notice() {
|
||||
if ( function_exists( 'wp_ai_client_prompt' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'activate_plugins' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
/* translators: %s: WordPress AI plugin link. */
|
||||
esc_html__( 'AI Translator (by ROBOTSTXT) requires the %s plugin to be active. Translation features will be disabled until it is installed and configured.', 'robotstxt-ai-translator' ),
|
||||
'<a href="https://wordpress.org/plugins/ai/" target="_blank" rel="noopener noreferrer">' . esc_html__( 'WordPress AI', 'robotstxt-ai-translator' ) . '</a>'
|
||||
);
|
||||
|
||||
printf(
|
||||
'<div class="notice notice-warning"><p>%s</p></div>',
|
||||
wp_kses(
|
||||
$message,
|
||||
array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'target' => array(),
|
||||
'rel' => array(),
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'admin_notices', 'ai_translator_dependency_notice' );
|
||||
add_action( 'network_admin_notices', 'ai_translator_dependency_notice' );
|
||||
Loading…
Reference in a new issue