edit/remove featuremedia

This commit is contained in:
Filip Penkava
2017-02-17 14:42:51 +01:00
parent 449e3d2e88
commit d5e3b3be6b
2 changed files with 51 additions and 29 deletions

24
mvp.php
View File

@@ -26,6 +26,7 @@ define('MVP_PLUGIN_URL', untrailingslashit(plugins_url('', MVP_PLUGIN)));
define('MVP_DATABASE_VERSION', '2');
define('DB_TABLE_SYNC_POST', 'sync_posts');
define('DB_TABLE_POSTMETA', 'postmeta');
define('DB_TABLE_USERS', 'users');
@@ -81,5 +82,28 @@ function generatePassword() {
return $password;
}
function saveAttachment($picture, $post_ID) {
$filenameQ = explode("/", $picture['renditions']['original']['media']);
$filename = $filenameQ[1];
saveFile($picture['renditions']['original']['href'], wp_upload_dir()['path'] . "/" . $filename);
$attachment = array(
'guid' => wp_upload_dir()['url'] . '/' . basename($filename),
'post_mime_type' => $picture['mimetype'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename($picture['headline'])),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment($attachment, date("Y") . "/" . date("m") . "/" . $filename, $post_ID);
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$attach_data = wp_generate_attachment_metadata($attach_id, wp_upload_dir()['path'] . "/" . $filename);
wp_update_attachment_metadata($attach_id, $attach_data);
set_post_thumbnail($post_ID, $attach_id);
}
register_activation_hook(__FILE__, 'mvp_database_install');
add_action('plugins_loaded', 'mvp_database_update');