Skip to content

Instantly share code, notes, and snippets.

@sibaberpollo
Last active April 6, 2016 15:46
Show Gist options
  • Save sibaberpollo/00850e9eb26af9f6aa751061ac1b43c3 to your computer and use it in GitHub Desktop.
Save sibaberpollo/00850e9eb26af9f6aa751061ac1b43c3 to your computer and use it in GitHub Desktop.
en la función save de wordpress, mueve la imagen destacada a un directorio y agrega un texto
<?php
function save_id_to_file($post_id){
//use your file creation/save function here
header ("Content-type: image/jpeg");
$path = "C:\TEMP";
$imageName = $path."\\meme-".$post_id.".png";
$imageNameFeat = $path."\\meme-".$post_id."-feat.png";
$elTitulo = get_field('conduccion');
$urlFeaturred = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') );
$myFile = $path."\\testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "$elTitulo --- $post_id ---- $urlFeaturred\n";
fwrite($fh, $stringData);
fclose($fh);
$content = file_get_contents($urlFeaturred) or die ("Problemas");
file_put_contents($imageName, $content) or die ("problemas copiando");
$imgPath = $imageName;
$image = imagecreatefrompng($imgPath);
$color = imagecolorallocate($image, 255, 255, 255);
$string = "$elTitulo";
$fontSize = 3;
$x = 0;
$y = 0;
imagestring($image, $fontSize, $x, $y, $string, $color);
imagepng($image, $imageNameFeat);
?>
return $post_id;
}
add_action('save_post','save_id_to_file');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment