Created
June 24, 2023 22:55
-
-
Save felipeelia/9570cac412f42b6768b8d8ecb650c3c6 to your computer and use it in GitHub Desktop.
Compatibility layer between the ClassifAI plugin and Polylang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: ClassifAI and Polylang | |
* Description: Compatibility layer between the ClassifAI plugin and Polylang | |
* Version: 1.0.0 | |
* Author: Felipe Elia | |
* Author URI: https://felipeelia.dev/ | |
* Text Domain: felipeelia-classifai | |
* Domain Path: /languages | |
* | |
* @package FelipeEliaClassifAi | |
*/ | |
namespace FelipeEliaClassifAi; | |
defined( 'ABSPATH' ) || exit; | |
/** | |
* Add the language to ClassifAI excerpt prompt | |
* | |
* @param string $prompt Prompt sent to ChatGPT | |
* @param int $post_id Post ID | |
* @return string | |
*/ | |
function add_language_to_prompt( $prompt, $post_id ) { | |
if ( ! function_exists( 'pll_get_post_language' ) ) { | |
return $prompt; | |
} | |
$language = pll_get_post_language( $post_id, 'locale' ); | |
if ( in_array( $language, [ 'en', 'en_US', 'en_UK' ], true ) ) { | |
return $prompt; | |
} | |
$prompt .= " in {$language}"; | |
return $prompt; | |
} | |
add_filter( 'classifai_chatgpt_excerpt_prompt', __NAMESPACE__ . '\add_language_to_prompt', 10, 2 ); | |
add_filter( 'classifai_chatgpt_title_prompt', __NAMESPACE__ . '\add_language_to_prompt', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment