$value ) {
$withstyle = $value . '. ' . $style_text . ', ' . $tone_text . '.';
// if avoid is not empty add it to the prompt
if ( !empty( $qc_wpbotpro_article_label_word_to_avoid ) ) {
$withstyle = $value . '. ' . $style_text . ', ' . $tone_text . ', ' . $avoid_text . '.';
}
$gptkeyword = [];
if( $ai_engines == 'gpt-3.5-turbo' || $ai_engines == 'gpt-4' || $ai_engines == 'gpt-4o' || $ai_engines == 'gpt-4o-mini'){
// phpcs:ignore WordPress.WP.AlternativeFunctions
$ch = curl_init();
$url = 'https://api.openai.com/v1/chat/completions';
array_push($gptkeyword, array(
"role" => "user",
"content" => $myprompt
));
$post_fields = array(
"model" => $ai_engines,
"messages" => $gptkeyword,
"max_tokens" => (int)$max_token,
"temperature" => ( float ) $temperature
);
$header = [
'Content-Type: application/json',
'Authorization: Bearer ' . $OPENAI_API_KEY
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo esc_html('Error: ') . esc_html(curl_error($ch));
}
curl_close($ch);
$complete = json_decode( $result );
$complete = isset($complete->choices[0]->message->content) ? $complete->choices[0]->message->content : '';
}else{
$request_body = [
"prompt" => $myprompt,
"model" => $ai_engines,
"max_tokens" => (int)$max_token,
"temperature" => (float)$temperature,
"presence_penalty" => (float)$ppenalty,
"frequency_penalty" => (float)$fpenalty,
"top_p" => 1,
"best_of" => 1,
];
$data = json_encode($request_body);
$url = "https://api.openai.com/v1/completions";
$apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_init
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/json",
$apt_key ,
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
curl_close($curl);
$complete = json_decode( $result );
$complete = isset($complete->choices[0]->text) ? $complete->choices[0]->text : '';
}
// trim the text
$complete = !empty($complete) ? trim( $complete ) : '';
$value = str_replace( '\\/', '', $value );
$value = str_replace( '\\', '', $value );
// trim value
$value = trim( $value );
// we will add h tag if the user wants to
if ( $qc_wpbotpro_article_heading_tag == "h1" ) {
$result = "\n"."
" . $value . "
" ."\n". $complete;
} elseif ( $qc_wpbotpro_article_heading_tag == "h2" ) {
$result = "\n"."" . $value . "
" ."\n". $complete;
} elseif ( $qc_wpbotpro_article_heading_tag == "h3" ) {
$result = "\n"."" . $value . "
" ."\n". $complete;
} elseif ( $qc_wpbotpro_article_heading_tag == "h4" ) {
$result = "\n"."" . $value . "
" ."\n". $complete;
} elseif ( $qc_wpbotpro_article_heading_tag == "h5" ) {
$result = "\n"."" . $value . "
" ."\n". $complete;
} elseif ( $qc_wpbotpro_article_heading_tag == "h6" ) {
$result = "\n"."" . $value . "
" ."\n". $complete;
} else {
$result = "\n"."" . $value . "
" ."\n". $complete;
}
$result = preg_replace('/[\*]+/', '', $result);
$Qcld_Parsedown = new Qcld_Parsedown();
$allresults = $allresults . $Qcld_Parsedown->text($result);
}
}
return $allresults;
}
}
add_filter('qc_wpbotpro_floating_openai_article_heading_intro', 'qc_wpbotpro_floating_openai_article_heading_intro_callback', 10, 3 );
if ( ! function_exists( 'qc_wpbotpro_floating_openai_article_heading_intro_callback' ) ) {
function qc_wpbotpro_floating_openai_article_heading_intro_callback( $allresults, $myintro, $introduction ){
$OPENAI_API_KEY = get_option('open_ai_api_key');
$ai_engines = get_option('openai_engines');
$max_token = get_option('openai_max_tokens') ? get_option('openai_max_tokens') : 4000;
$temperature = get_option('openai_temperature') ? get_option('openai_temperature') : 0;
$ppenalty = get_option('presence_penalty');
$fpenalty = get_option('frequency_penalty');
$gptkeyword = [];
if( $ai_engines == 'gpt-3.5-turbo' || $ai_engines == 'gpt-4' || $ai_engines == 'gpt-4o' || $ai_engines == 'gpt-4o-mini'){
// phpcs:ignore WordPress.WP.AlternativeFunctions
$ch = curl_init();
$url = 'https://api.openai.com/v1/chat/completions';
array_push($gptkeyword, array(
"role" => "user",
"content" => $myintro
));
$post_fields = array(
"model" => $ai_engines,
"messages" => $gptkeyword,
"max_tokens" => (int)$max_token,
"temperature" => ( float ) $temperature
);
$header = [
'Content-Type: application/json',
'Authorization: Bearer ' . $OPENAI_API_KEY
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo esc_html('Error: ') . esc_html(curl_error($ch));
}
curl_close($ch);
$completeintro = json_decode( $result );
if ( isset( $completeintro->error ) ) {
$completeintro = $completeintro->error->message;
// exit
echo esc_html( $completeintro ) ;
exit;
} else {
$completeintro = isset( $completeintro->choices[0]->message->content ) ? trim($completeintro->choices[0]->message->content) : '';
// trim the text
$Qcld_Parsedown = new Qcld_Parsedown();
$completeintro = !empty( $completeintro ) ? $Qcld_Parsedown->text( $completeintro ) : '';
// add Introuction
to the beginning of the text
$completeintro = "\n"."" . $introduction . "
" ."\n". $completeintro;
// add intro to the beginning of the text
$allresults = $Qcld_Parsedown->text($completeintro) . $allresults;
}
}else{
$request_body = [
"prompt" => $myintro,
"model" => $ai_engines,
"max_tokens" => (int)$max_token,
"temperature" => (float)$temperature,
"presence_penalty" => (float)$ppenalty,
"frequency_penalty" => (float)$fpenalty,
"top_p" => 1,
"best_of" => 1,
];
$data = json_encode($request_body);
$url = "https://api.openai.com/v1/completions";
$apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_init
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/json",
$apt_key ,
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
curl_close($curl);
$completeintro = json_decode( $result );
if ( isset( $completeintro->error ) ) {
$completeintro = $completeintro->error->message;
// exit
echo esc_html( $completeintro ) ;
exit;
} else {
$completeintro = isset( $completeintro->choices[0]->text ) ? trim( $completeintro->choices[0]->text ) : '';
// trim the text
$Qcld_Parsedown = new Qcld_Parsedown();
$completeintro = !empty( $completeintro ) ? $Qcld_Parsedown->text( $completeintro ) : '';
// add Introuction
to the beginning of the text
$completeintro = "\n"."" . $introduction . "
" ."\n". $completeintro;
// add intro to the beginning of the text
$allresults = $Qcld_Parsedown->text($completeintro) . $allresults;
}
}
return $allresults;
}
}
add_filter('qc_wpbotpro_floating_openai_article_heading_faq', 'qc_wpbotpro_floating_openai_article_heading_faq_callback', 10, 3 );
if ( ! function_exists( 'qc_wpbotpro_floating_openai_article_heading_faq_callback' ) ) {
function qc_wpbotpro_floating_openai_article_heading_faq_callback( $allresults, $faq_text, $faq_heading ){
$OPENAI_API_KEY = get_option('open_ai_api_key');
$ai_engines = get_option('openai_engines');
$max_token = get_option('openai_max_tokens') ? get_option('openai_max_tokens') : 4000;
$temperature = get_option('openai_temperature') ? get_option('openai_temperature') : 0;
$ppenalty = get_option('presence_penalty');
$fpenalty = get_option('frequency_penalty');
$gptkeyword = [];
if( $ai_engines == 'gpt-3.5-turbo' || $ai_engines == 'gpt-4' || $ai_engines == 'gpt-4o' || $ai_engines == 'gpt-4o-mini'){
// phpcs:ignore WordPress.WP.AlternativeFunctions
$ch = curl_init();
$url = 'https://api.openai.com/v1/chat/completions';
array_push($gptkeyword, array(
"role" => "user",
"content" => $faq_text
));
$post_fields = array(
"model" => $ai_engines,
"messages" => $gptkeyword,
"max_tokens" => (int)$max_token,
"temperature" => ( float ) $temperature
);
$header = [
'Content-Type: application/json',
'Authorization: Bearer ' . $OPENAI_API_KEY
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo esc_html('Error: ') . esc_html(curl_error($ch));
}
curl_close($ch);
$completeintro = json_decode( $result );
if ( isset( $completefaq->error ) ) {
$completefaq = $completefaq->error->message;
// exit
echo esc_html( $completefaq ) ;
exit;
} else {
//$completefaq = $complete->choices[0]->message->content;
$completefaq = isset( $complete->choices[0]->message->content ) ? trim( $complete->choices[0]->message->content ) : '';
// trim the text
$completefaq = !empty( $completefaq ) ? trim( $completefaq ) : '';
// add FAQ
to the beginning of the text
$completefaq = "\n"."" . $faq_heading . "
" ."\n". $completefaq;
// add intro to the beginning of the text
$allresults = $allresults . $completefaq;
}
}else{
$request_body = [
"prompt" => $faq_text,
"model" => $ai_engines,
"max_tokens" => (int)$max_token,
"temperature" => (float)$temperature,
"presence_penalty" => (float)$ppenalty,
"frequency_penalty" => (float)$fpenalty,
"top_p" => 1,
"best_of" => 1,
];
$data = json_encode($request_body);
$url = "https://api.openai.com/v1/completions";
$apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_init
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/json",
$apt_key ,
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
curl_close($curl);
$completefaq = json_decode( $result );
if ( isset( $completefaq->error ) ) {
$completefaq = $completefaq->error->message;
// exit
echo esc_html( $completefaq ) ;
exit;
} else {
//$completefaq = $completefaq->choices[0]->text;
$completefaq = isset( $completefaq->choices[0]->text ) ? trim( $completefaq->choices[0]->text ) : '';
// trim the text
$Qcld_Parsedown = new Qcld_Parsedown();
$completefaq = !empty( $completefaq ) ? $Qcld_Parsedown->text( $completefaq ) : '';
// add FAQ
to the beginning of the text
$completefaq = "\n"."" . $faq_heading . "
" ."\n". $completefaq;
// add intro to the beginning of the text
$allresults = $allresults . $completefaq;
}
}
return $allresults;
}
}
add_filter('qc_wpbotpro_floating_openai_article_heading_conclusion', 'qc_wpbotpro_floating_openai_article_heading_conclusion_callback', 10, 3 );
if ( ! function_exists( 'qc_wpbotpro_floating_openai_article_heading_conclusion_callback' ) ) {
function qc_wpbotpro_floating_openai_article_heading_conclusion_callback( $allresults, $myconclusion, $conclusion ){
$OPENAI_API_KEY = get_option('open_ai_api_key');
$ai_engines = get_option('openai_engines');
$max_token = get_option('openai_max_tokens') ? get_option('openai_max_tokens') : 4000;
$temperature = get_option('openai_temperature') ? get_option('openai_temperature') : 0;
$ppenalty = get_option('presence_penalty');
$fpenalty = get_option('frequency_penalty');
$gptkeyword = [];
if( $ai_engines == 'gpt-3.5-turbo' || $ai_engines == 'gpt-4' || $ai_engines == 'gpt-4o' || $ai_engines == 'gpt-4o-mini'){
// phpcs:ignore WordPress.WP.AlternativeFunctions
$ch = curl_init();
$url = 'https://api.openai.com/v1/chat/completions';
array_push($gptkeyword, array(
"role" => "user",
"content" => $myconclusion
));
$post_fields = array(
"model" => $ai_engines,
"messages" => $gptkeyword,
"max_tokens" => (int)$max_token,
"temperature" => ( float ) $temperature
);
$header = [
'Content-Type: application/json',
'Authorization: Bearer ' . $OPENAI_API_KEY
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo esc_html('Error: ') . esc_html(curl_error($ch));
}
curl_close($ch);
//$complete = json_decode( $result );
// $complete = isset($complete->choices[0]->message->content) ? $complete->choices[0]->message->content : '';
$completeconclusion = json_decode( $result );
if ( isset( $completeconclusion->error ) ) {
$completeconclusion = $completeconclusion->error->message;
// exit
echo esc_html( $completeconclusion ) ;
exit;
} else {
//$completeconclusion = $complete->choices[0]->message->content;
$completeconclusion = isset( $completeconclusion->choices[0]->message->content ) ? trim( $completeconclusion->choices[0]->message->content ) : '';
// trim the text
$Qcld_Parsedown = new Qcld_Parsedown();
$completeconclusion = !empty( $completeconclusion ) ? $Qcld_Parsedown->text( $completeconclusion ) : '';
// add Conclusion
to the beginning of the text
$completeconclusion = "\n"."" . $conclusion . "
" ."\n". $completeconclusion;
// add intro to the beginning of the text
$allresults = $allresults . $completeconclusion;
}
}else{
// we need to catch the error here
$request_body = [
"prompt" => $myconclusion,
"model" => $ai_engines,
"max_tokens" => (int)$max_token,
"temperature" => (float)$temperature,
"presence_penalty" => (float)$ppenalty,
"frequency_penalty" => (float)$fpenalty,
"top_p" => 1,
"best_of" => 1,
];
$data = json_encode($request_body);
$url = "https://api.openai.com/v1/completions";
$apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_init
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/json",
$apt_key ,
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
curl_close($curl);
$completeconclusion = json_decode( $result );
if ( isset( $completeconclusion->error ) ) {
$completeconclusion = $completeconclusion->error->message;
// exit
echo esc_html( $completeconclusion ) ;
exit;
} else {
//$completeconclusion = $completeconclusion->choices[0]->text;
$completeconclusion = isset( $completeconclusion->choices[0]->text ) ? trim( $completeconclusion->choices[0]->text ) : '';
// trim the text
$Qcld_Parsedown = new Qcld_Parsedown();
$completeconclusion = !empty( $completeconclusion ) ? $Qcld_Parsedown->text( $completeconclusion ) : '';
// add Conclusion
to the beginning of the text
$completeconclusion = "\n"."" . $conclusion . "
" ."\n". $completeconclusion;
// add intro to the beginning of the text
$allresults = $allresults . $completeconclusion;
}
}
return $allresults;
}
}
add_filter('qcld_wpbotpro_floating_openai_article_heading_tagline', 'qcld_wpbotpro_floating_openai_article_heading_tagline_callback', 10, 3 );
if ( ! function_exists( 'qcld_wpbotpro_floating_openai_article_heading_tagline_callback' ) ) {
function qcld_wpbotpro_floating_openai_article_heading_tagline_callback( $allresults, $mytagline, $conclusion ){
$OPENAI_API_KEY = get_option('open_ai_api_key');
$ai_engines = get_option('openai_engines');
$max_token = get_option('openai_max_tokens') ? get_option('openai_max_tokens') : 4000;
$temperature = get_option('openai_temperature') ? get_option('openai_temperature') : 0;
$ppenalty = get_option('presence_penalty');
$fpenalty = get_option('frequency_penalty');
$gptkeyword = [];
if( $ai_engines == 'gpt-3.5-turbo' || $ai_engines == 'gpt-4' || $ai_engines == 'gpt-4o' || $ai_engines == 'gpt-4o-mini'){
// phpcs:ignore WordPress.WP.AlternativeFunctions
$ch = curl_init();
$url = 'https://api.openai.com/v1/chat/completions';
array_push($gptkeyword, array(
"role" => "user",
"content" => $mytagline
));
$post_fields = array(
"model" => $ai_engines,
"messages" => $gptkeyword,
"max_tokens" => (int)$max_token,
"temperature" => ( float ) $temperature
);
$header = [
'Content-Type: application/json',
'Authorization: Bearer ' . $OPENAI_API_KEY
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo esc_html('Error: ') . esc_html(curl_error($ch));
}
curl_close($ch);
//$complete = json_decode( $result );
// $complete = isset($complete->choices[0]->message->content) ? $complete->choices[0]->message->content : '';
$completetagline = json_decode( $result );
if ( isset( $completetagline->error ) ) {
$completetagline = $completetagline->error->message;
// exit
echo esc_html( $completetagline ) ;
exit;
} else {
$completetagline = isset( $completetagline->choices[0]->message->content ) ? trim( $completetagline->choices[0]->message->content ) : '';
// trim the text
$Qcld_Parsedown = new Qcld_Parsedown();
$completetagline = !empty($completetagline) ? $Qcld_Parsedown->text( $completetagline ) : '';
// add to the beginning of the text
$completetagline = "\n"."
" . $completetagline . "
"."\n";
// add intro to the beginning of the text
$allresults = $completetagline . $allresults;
}
}else{
// we need to catch the error here
$request_body = [
"prompt" => $mytagline,
"model" => $ai_engines,
"max_tokens" => (int)$max_token,
"temperature" => (float)$temperature,
"presence_penalty" => (float)$ppenalty,
"frequency_penalty" => (float)$fpenalty,
"top_p" => 1,
"best_of" => 1,
];
$data = json_encode($request_body);
$url = "https://api.openai.com/v1/completions";
$apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_init
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/json",
$apt_key ,
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
curl_close($curl);
$completetagline = json_decode( $result );
if ( isset( $completetagline->error ) ) {
$completetagline = $completetagline->error->message;
// exit
echo esc_html( $completetagline ) ;
exit;
} else {
//$completetagline = $completetagline->choices[0]->text;
$completetagline = isset( $completetagline->choices[0]->text ) ? trim( $completetagline->choices[0]->text ) : '';
// trim the text
$Qcld_Parsedown = new Qcld_Parsedown();
$completetagline = !empty($completetagline) ? $Qcld_Parsedown->text( $completetagline ) : '';
// add to the beginning of the text
$completetagline = "\n"."
" . $completetagline . "
"."\n";
// add intro to the beginning of the text
$allresults = $completetagline . $allresults;
}
}
return $allresults;
}
}
add_filter('qc_wpbotpro_floating_openai_article_heading_img', 'qc_wpbotpro_floating_openai_article_heading_img_callback', 10, 2 );
if ( ! function_exists( 'qc_wpbotpro_floating_openai_article_heading_img_callback' ) ) {
function qc_wpbotpro_floating_openai_article_heading_img_callback( $qc_wpbotpro_article_text, $img_size ){
$OPENAI_API_KEY = get_option('open_ai_api_key');
$ai_engines = get_option('openai_engines');
$max_token = get_option('openai_max_tokens') ? get_option('openai_max_tokens') : 4000;
$temperature = get_option('openai_temperature') ? get_option('openai_temperature') : 0;
$ppenalty = get_option('presence_penalty');
$fpenalty = get_option('frequency_penalty');
$imgresult = '';
$request_body = [
"prompt" => $qc_wpbotpro_article_text,
"model" => 'dall-e-3',
"n" => 1,
"size" => $img_size,
"response_format" => "url",
];
$data = json_encode($request_body);
$url = "https://api.openai.com/v1/images/generations";
$apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_init
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/json",
$apt_key,
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
curl_close($curl);
// we need to catch the error here
$imgresult = json_decode( $result );
$imgresult = isset($imgresult->data[0]->url) ? $imgresult->data[0]->url : '';
if( !empty($imgresult)){
$array = explode('/', getimagesize($imgresult)['mime']);
$imagetype = end($array);
$uniq_name = md5($imgresult);
$filename = $uniq_name . '.' . $imagetype;
$uploaddir = wp_upload_dir();
$target_file_name = $uploaddir['path'] . '/' . $filename;
$contents = file_get_contents( $imgresult );
global $wp_filesystem;
if ( empty( $wp_filesystem ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
}
if ( $wp_filesystem ) {
$wp_filesystem->put_contents( $target_file_name, $contents, FS_CHMOD_FILE );
}
/* add the image title */
$image_title = ucwords( $uniq_name );
$qc_wpbotpro_floating_openai_images_attribution = 'gpt openai';
/* add the caption */
$attachment_caption = '';
if (! isset($qc_wpbotpro_floating_openai_images_attribution['attribution']) | isset($qc_wpbotpro_floating_openai_images_attribution['attribution']) == 'true')
$attachment_caption = '' . esc_attr( $filename ) . '';
unset($imgresult);
/* insert the attachment */
$wp_filetype = wp_check_filetype(basename($target_file_name), null);
$attachment = array(
'guid' => $uploaddir['url'] . '/' . basename($target_file_name),
'post_mime_type' => $wp_filetype['type'],
'post_title' => $image_title,
'post_status' => 'inherit'
);
$post_id = isset($_REQUEST['post_id']) ? absint($_REQUEST['post_id']): '';
$attach_id = wp_insert_attachment($attachment, $target_file_name, $post_id);
if ($attach_id == 0)
die('Error: File attachment error');
$attach_data = wp_generate_attachment_metadata($attach_id, $target_file_name);
$result = wp_update_attachment_metadata($attach_id, $attach_data);
$image_data = array();
$image_data['ID'] = $attach_id;
$image_data['post_excerpt'] = $attachment_caption;
wp_update_post($image_data);
$parsed = wp_get_attachment_image_src( $attach_id, 'full' )[0];
if(!empty($parsed)){
$attach_id = $parsed;
}
$imgresult = "\n"."
"."\n";
}
return $imgresult;
}
// phpcs:enable WordPress.WP.AlternativeFunctions.curl_curl_init, WordPress.WP.AlternativeFunctions.curl_curl_setopt, WordPress.WP.AlternativeFunctions.curl_curl_exec, WordPress.WP.AlternativeFunctions.curl_curl_errno, WordPress.WP.AlternativeFunctions.curl_curl_error, WordPress.WP.AlternativeFunctions.curl_curl_close
}