HEX
Server: Apache
System: Linux WWW 6.1.0-40-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.153-1 (2025-09-20) x86_64
User: web11 (1011)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/ideasforum.kaunokolegija.lt/wp-content/plugins/robo-gallery/app/class.restapi.php
<?php 
/* 
*      Robo Gallery     
*      Version: 3.2.1 - 52888
*      By Robosoft
*
*      Contact: https://robogallery.co/ 
*      Created: 2021
*      Licensed under the GPLv2 license - http://opensource.org/licenses/gpl-2.0.php

 */

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

class RoboGalleryRestAPI {

	public function __construct(){}


    public static function init(){
    	add_action( 'rest_api_init', array( 'RoboGalleryRestAPI', 'add_restapi_meta_field' ) );
    }

 
	public static function add_restapi_meta_field() {
	    // register_rest_field ( 'name-of-post-type', 'name-of-field-to-return', array-of-callbacks-and-schema() )
	    register_rest_field( ROBO_GALLERY_TYPE_POST, 'meta-fields', array(
	           'get_callback'    => array( 'RoboGalleryRestAPI', 'get_post_meta_for_api'),
	           'schema'          => null,
	        )
	    );
	}

 
	public static function get_post_meta_for_api( $object ){

	    $post_id = $object['id'];
	    $metaData = get_post_meta( $post_id );
	     
	    if(!empty( $metaData['rsg_shadow-options'][0] )){
	    	$metaData['rsg_shadow-options'][0] = unserialize( $metaData['rsg_shadow-options'][0] );
	    }

	    if( !empty($metaData['rsg_galleryImages'][0]) ){

	    	function toInt($n){ return (int) $n; }		

	    	$imagesArray = unserialize( $metaData['rsg_galleryImages'][0] );
	    	$imagesArray = array_map('toInt', $imagesArray);
	    	$metaData['rsg_galleryImages'] = array( 'count' => count($imagesArray), 'items' => $imagesArray );
	    }

	    if(!empty($metaData['rsg_width-size'])){
	    	$metaData['rsg_width-size'] = unserialize( $metaData['rsg_width-size'][0] );
	    }

	    return $metaData;
	}
	
}

RoboGalleryRestAPI::init();