SIS_Admin_Main::thumbnail_rebuild PHP Method

thumbnail_rebuild() public static method

Rebuild the given attribute with the given thumbnails
Author: Nicolas Juen
public static thumbnail_rebuild ( $att_id, $thumbnails = null ) : array
$att_id
$thumbnails
return array
    public static function thumbnail_rebuild($att_id, $thumbnails = null)
    {
        // Time a the begining
        timer_start();
        // Check Id
        if ((int) $att_id <= 0) {
            return array('time' => timer_stop(false, 4), 'error' => __('No id given in POST datas.', 'simple-image-sizes'));
        }
        // Get the path
        $fullsizepath = get_attached_file($att_id);
        // Regen the attachment
        if (false !== $fullsizepath && file_exists($fullsizepath)) {
            if (false == wp_update_attachment_metadata($att_id, self::wp_generate_attachment_metadata_custom($att_id, $fullsizepath, $thumbnails))) {
                return array('src' => wp_get_attachment_thumb_url($att_id), 'time' => timer_stop(false, 4), 'message' => sprintf(__('This file already exists in this size and have not been regenerated :<br/><a target="_blank" href="%1$s" >%2$s</a>', 'simple-image-sizes'), get_edit_post_link($att_id), get_the_title($att_id)));
            }
        } else {
            return array('src' => wp_get_attachment_thumb_url($att_id), 'time' => timer_stop(false, 4), 'error' => sprintf(__('This file does not exists and have not been regenerated :<br/><a target="_blank" href="%1$s" >%2$s</a>', 'simple-image-sizes'), get_edit_post_link($att_id), get_the_title($att_id)));
        }
        // Display the attachment url for feedback
        return array('time' => timer_stop(false, 4), 'src' => wp_get_attachment_thumb_url($att_id), 'title' => get_the_title($att_id));
    }

Usage Example

コード例 #1
0
ファイル: post.php プロジェクト: yarylo/cerkva.pp.ua
 /**
  * Rebuild the image
  *
  * @access public
  * @return void
  * @author Nicolas Juen
  */
 public static function a_thumbnail_rebuild()
 {
     // Get the nonce
     $nonce = isset($_POST['nonce']) ? $_POST['nonce'] : '';
     // Get the thumbnails
     $thumbnails = isset($_POST['thumbnails']) ? $_POST['thumbnails'] : null;
     // Check the nonce
     if (!wp_verify_nonce($nonce, 'regen')) {
         SIS_Admin_Main::display_json(array('error' => __('Trying to cheat ?', 'simple-image-sizes')));
     }
     // Get the id
     $id = isset($_POST['id']) ? $_POST['id'] : 0;
     SIS_Admin_Main::display_json(SIS_Admin_Main::thumbnail_rebuild($id, $thumbnails));
 }
All Usage Examples Of SIS_Admin_Main::thumbnail_rebuild