public static function insertMedia($mediaFiles, $postID, $postTypeSlug, $languages, $notTranslatableFiles, $filesToBeIgnored = [])
    {
        $imagesArr = array();
        foreach($mediaFiles as $fileKey => $files){
            // feature image is treated as a default column
            if($fileKey == 'featuredImage'
                || $fileKey == 'featuredVideo'
                || in_array($fileKey, $filesToBeIgnored)
                || substr($fileKey, 0, 6) == 'plugin'
            ) {
                continue;
            }
            //if not translatable
            if(in_array($fileKey, $notTranslatableFiles)) {
                foreach ($files as $file){
                    $image = array();
                    $image['field'] = $fileKey;
                    $image['mediaID'] = $file['mediaID'];
                    $image['postID'] = $postID;

                    $languageAvailability = array();
                    foreach ($languages as $lang){
                        $languageAvailability[$lang['slug']] = true;
                    }
                    $image['language'] = json_encode($languageAvailability);
                    array_push($imagesArr, $image);
                }
            }else{ // if translatable
                $explodedFileKey = explode("__lang__", $fileKey);  // remove the "__lang__" part
                $fieldName = $explodedFileKey[0]; // The input name
                $langSlug = $explodedFileKey[1];  // The lang slug
                foreach ($files as $file){
                    $image['field'] = $fieldName;
                    $image['mediaID'] = $file['mediaID'];
                    $image['postID'] = $postID;

                    //store only the language which the input belongs to
                    $languageAvailability = array();
                    foreach ($languages as $lang){
                        if($lang['slug'] == $langSlug) {
                            $languageAvailability[$lang['slug']] = true;
                        }else{
                            $languageAvailability[$lang['slug']] = false;
                        }
                    }
                    $image['language'] = json_encode($languageAvailability);
                    array_push($imagesArr, $image);
                }
            }
        }

        $mediaSaved = (new MediaRelation())->setTable($postTypeSlug.'_media')->insert($imagesArr);
        if($mediaSaved) {
            return $imagesArr;
        }
        return [];
    }
public static function insertMedia($mediaFiles, $postID, $postTypeSlug, $languages, $notTranslatableFiles, $filesToBeIgnored = [])
    {
        $imagesArr = array();
        foreach($mediaFiles as $fileKey => $files){
            // feature image is treated as a default column
            if($fileKey == 'featuredImage'
                || $fileKey == 'featuredVideo'
                || in_array($fileKey, $filesToBeIgnored)
                || substr($fileKey, 0, 6) == 'plugin'
            ) {
                continue;
            }
            //if not translatable
            if(in_array($fileKey, $notTranslatableFiles)) {
                foreach ($files as $file){
                    $image = array();
                    $image['field'] = $fileKey;
                    $image['mediaID'] = $file['mediaID'];
                    $image['postID'] = $postID;

                    $languageAvailability = array();
                    foreach ($languages as $lang){
                        $languageAvailability[$lang['slug']] = true;
                    }
                    $image['language'] = json_encode($languageAvailability);
                    array_push($imagesArr, $image);
                }
            }else{ // if translatable
                $explodedFileKey = explode("__lang__", $fileKey);  // remove the "__lang__" part
                $fieldName = $explodedFileKey[0]; // The input name
                $langSlug = $explodedFileKey[1];  // The lang slug
                foreach ($files as $file){
                    $image['field'] = $fieldName;
                    $image['mediaID'] = $file['mediaID'];
                    $image['postID'] = $postID;

                    //store only the language which the input belongs to
                    $languageAvailability = array();
                    foreach ($languages as $lang){
                        if($lang['slug'] == $langSlug) {
                            $languageAvailability[$lang['slug']] = true;
                        }else{
                            $languageAvailability[$lang['slug']] = false;
                        }
                    }
                    $image['language'] = json_encode($languageAvailability);
                    array_push($imagesArr, $image);
                }
            }
        }

        $mediaSaved = (new MediaRelation())->setTable($postTypeSlug.'_media')->insert($imagesArr);
        if($mediaSaved) {
            return $imagesArr;
        }
        return [];
    }
public static function insertMedia ( $ mediaFiles , $ postID , $ postTypeSlug , $ languages , $ notTranslatableFiles , $ filesToBeIgnored = [ ] ) { $ imagesArr = array ( ) ; foreach ( $ mediaFiles as $ fileKey => $ files ) { // feature image is treated as a default column if ( $ fileKey == 'featuredImage' || $ fileKey == 'featuredVideo' || in_array ( $ fileKey , $ filesToBeIgnored ) || substr ( $ fileKey , 0 , 6 ) == 'plugin' ) { continue ; } //if not translatable if ( in_array ( $ fileKey , $ notTranslatableFiles ) ) { foreach ( $ files as $ file ) { $ image = array ( ) ; $ image [ 'field' ] = $ fileKey ; $ image [ 'mediaID' ] = $ file [ 'mediaID' ] ; $ image [ 'postID' ] = $ postID ; $ languageAvailability = array ( ) ; foreach ( $ languages as $ lang ) { $ languageAvailability [ $ lang [ 'slug' ] ] = true ; } $ image [ 'language' ] = json_encode ( $ languageAvailability ) ; array_push ( $ imagesArr , $ image ) ; } } else { // if translatable $ explodedFileKey = explode ( "__lang__" , $ fileKey ) ; // remove the "__lang__" part $ fieldName = $ explodedFileKey [ 0 ] ; // The input name $ langSlug = $ explodedFileKey [ 1 ] ; // The lang slug foreach ( $ files as $ file ) { $ image [ 'field' ] = $ fieldName ; $ image [ 'mediaID' ] = $ file [ 'mediaID' ] ; $ image [ 'postID' ] = $ postID ; //store only the language which the input belongs to $ languageAvailability = array ( ) ; foreach ( $ languages as $ lang ) { if ( $ lang [ 'slug' ] == $ langSlug ) { $ languageAvailability [ $ lang [ 'slug' ] ] = true ; } else { $ languageAvailability [ $ lang [ 'slug' ] ] = false ; } } $ image [ 'language' ] = json_encode ( $ languageAvailability ) ; array_push ( $ imagesArr , $ image ) ; } } } $ mediaSaved = ( new MediaRelation ( ) ) -> setTable ( $ postTypeSlug . '_media' ) -> insert ( $ imagesArr ) ; if ( $ mediaSaved ) { return $ imagesArr ; } return [ ] ; }
Insert Post media files.

@param array  $mediaFiles           The list of media files from Post Request
@param int    $postID               ID of the Post
@param string $postTypeSlug         The slug of post type
@param array  $languages            The list of languages to add media files
@param array  $notTranslatableFiles Slugs of all selected files. Used to identify media files that are not translatable

@return array  List of inserted media files
Insert Post media files .