Hallo,
ich habe folgendes Problem, die Url für das Beitragsbild wird von einem Plugin erstellt, welche dann über ein Shortcode abgerufen werden kann, soweit alles gut...
Das Problem ist, dass der Shortcode noch nicht ausgeführt wurden ist, und deshalb nicht die Url verwendet wird, sondern der Shortcode an sich.
Gibt es eine möglichkeit den Shortcode erst auszuführen, und die Ausgabe
dann in eine Variable zu Packen um diese dann als Bild Url zu verwenden ?
Hier der gekürzte Code aus der functions.php:
Code
function wpcf7_to_post($cfdata) {
// Daten aus der Anfrage auslesen
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$formdata = $submission->get_posted_data();
}
// Post ID des Formulares angeben, welches "abgefangen" werden soll
if ( $cfdata->id() == '118738') {
$imdb = do_shortcode( '[imdb:id(' . $formdata['imdb_id'] . ')]' );
$imdb_title = do_shortcode( '[imdb:title_nolink]' );
$imdb_picture = do_shortcode( '[imdb:poster]' );
$post_content = 'Test';
$imageurl = $imdb . $imdb_picture;
$newpublish = array(
'post_title' => $imdb . $imdb_title,
'post_content' => $post_content,
'tags_input' => 'Test',
'post_status' => 'publish',
'post_type' => 'post',
);
$newpostid = wp_insert_post($newpublish);
// Add Featured Image to Post
$image_url = $imageurl;
$upload_dir = wp_upload_dir();
$image_data = file_get_contents($image_url);
$filename = basename($image_url);
if( wp_mkdir_p( $upload_dir['path'] ) ) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
file_put_contents( $file, $image_data );
$wp_filetype = wp_check_filetype( $filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $filename ),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
wp_update_attachment_metadata( $attach_id, $attach_data );
set_post_thumbnail( $newpostid, $attach_id );
}
}
add_action('wpcf7_before_send_mail', 'wpcf7_to_post',1);
Alles anzeigen
Habe schon mein bestes versucht, bin jetzt langsam am verzweifeln..
Hoffe das mir da jemand helfen kann, wäre echt super.
LG