<?php

if (! defined('ABSPATH')) exit;

function docuchat_get_file_from_nameOrId($imageNameOrId)
{ 
  if (!null == get_option(DOCUCHAT_IMAGES_IDS)) {

    if (gettype($imageNameOrId) == 'integer') { 
      
        return explode('/uploads/', get_attached_file($imageNameOrId))[1];
    }
    if (gettype($imageNameOrId) == 'string') {
      $imagesIds = unserialize(get_option(DOCUCHAT_IMAGES_IDS));
      foreach ($imagesIds as $imageId) {
        if (explode('.',  explode('/docuchat_', wp_get_attachment_metadata($imageId)['file'])[1])[0] == $imageNameOrId) {
          return $imageId;
        }
      }
    }
  } else {
    return null;
  }
}
