array( $this, 'block_render' ), ) ); } /** * Get instagram feed from REST * * @param Array $data - data to get feed. * @return array */ public function get_feed( $data ) { $request = new WP_REST_Request( 'GET', '/ghostkit/v1/get_instagram_feed' ); $request->set_query_params( $data ); $response = rest_do_request( $request ); $server = rest_get_server(); $data = $server->response_to_data( $response, false ); $data = isset( $data['response'] ) ? $data['response'] : false; return isset( $data['data'] ) ? $data['data'] : false; } /** * Get instagram profile from REST * * @param Array $data - data to get profile. * @return array */ public function get_profile( $data ) { $request = new WP_REST_Request( 'GET', '/ghostkit/v1/get_instagram_profile' ); $request->set_query_params( $data ); $response = rest_do_request( $request ); $server = rest_get_server(); $data = $server->response_to_data( $response, false ); $data = isset( $data['response'] ) ? $data['response'] : false; return isset( $data['data'] ) ? $data['data'] : false; } /** * Register gutenberg block output * * @param array $attributes - block attributes. * * @return string */ public function block_render( $attributes ) { ob_start(); $attributes = array_merge( array( 'variant' => 'default', 'accessToken' => '', 'count' => 8, 'columns' => 4, 'gap' => 'sm', 'showProfile' => true, 'showProfileAvatar' => true, 'profileAvatarSize' => 70, 'showProfileName' => true, 'showProfileBio' => true, 'showProfileWebsite' => true, 'showProfileStats' => true, 'className' => '', ), $attributes ); $attributes['showProfile'] = $attributes['showProfile'] && ( $attributes['showProfileAvatar'] || $attributes['showProfileName'] || $attributes['showProfileBio'] || $attributes['showProfileWebsite'] || $attributes['showProfileStats'] ); $class = 'ghostkit-instagram'; // variant classname. if ( 'default' !== $attributes['variant'] ) { $class .= ' ghostkit-instagram-variant-' . $attributes['variant']; } if ( $attributes['gap'] ) { $class .= ' ghostkit-instagram-gap-' . $attributes['gap']; } if ( $attributes['columns'] ) { $class .= ' ghostkit-instagram-columns-' . $attributes['columns']; } if ( $attributes['className'] ) { $class .= ' ' . $attributes['className']; } if ( $attributes['accessToken'] ) { $feed = $this->get_feed( array( 'access_token' => $attributes['accessToken'], 'count' => $attributes['count'], ) ); $profile = $this->get_profile( array( 'access_token' => $attributes['accessToken'], ) ); if ( $feed || $profile ) { ?>