array( $this, 'block_render' ), ) ); } } /** * Get twitter 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_twitter_feed' ); $request->set_query_params( $data ); $response = rest_do_request( $request ); $server = rest_get_server(); $data = $server->response_to_data( $response, false ); return isset( $data['response'] ) && isset( $data['success'] ) && $data['success'] ? $data['response'] : false; } /** * Get twitter 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_twitter_profile' ); $request->set_query_params( $data ); $response = rest_do_request( $request ); $server = rest_get_server(); $data = $server->response_to_data( $response, false ); return isset( $data['response'] ) && isset( $data['success'] ) && $data['success'] ? $data['response'] : 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', 'consumerKey' => '', 'consumerSecret' => '', 'accessToken' => '', 'accessTokenSecret' => '', 'userName' => 'nkdevv', 'count' => 3, 'showReplies' => false, 'showRetweets' => true, 'showFeedAvatar' => true, 'feedAvatarSize' => 48, 'showFeedName' => true, 'showFeedDate' => true, 'feedTextMode' => '', 'feedTextConvertLinks' => 'links_media', 'showFeedActions' => true, 'showProfile' => true, 'showProfileAvatar' => true, 'profileAvatarSize' => 70, 'showProfileName' => true, 'showProfileStats' => true, 'showProfileDescription' => true, 'showProfileWebsite' => true, 'showProfileLocation' => true, 'className' => '', ), $attributes ); $api_data_ready = $attributes['consumerKey'] && $attributes['consumerSecret'] && $attributes['accessToken'] && $attributes['accessTokenSecret']; $attributes['showProfile'] = $attributes['showProfile'] && ( $attributes['showProfileAvatar'] || $attributes['showProfileName'] || $attributes['showProfileDescription'] || $attributes['showProfileWebsite'] || $attributes['showProfileStats'] || $attributes['showProfileLocation'] ); $class = 'ghostkit-twitter'; // variant classname. if ( 'default' !== $attributes['variant'] ) { $class .= ' ghostkit-twitter-variant-' . $attributes['variant']; } if ( $attributes['className'] ) { $class .= ' ' . $attributes['className']; } if ( $api_data_ready && $attributes['userName'] ) { $profile = $this->get_profile( array( 'consumer_key' => $attributes['consumerKey'], 'consumer_secret' => $attributes['consumerSecret'], 'access_token' => $attributes['accessToken'], 'access_token_secret' => $attributes['accessTokenSecret'], 'screen_name' => $attributes['userName'], ) ); $feed = $this->get_feed( array( 'consumer_key' => $attributes['consumerKey'], 'consumer_secret' => $attributes['consumerSecret'], 'access_token' => $attributes['accessToken'], 'access_token_secret' => $attributes['accessTokenSecret'], 'count' => $attributes['count'], 'exclude_replies' => $attributes['showReplies'] ? 'false' : 'true', 'include_rts' => $attributes['showRetweets'] ? 'true' : 'false', 'tweet_mode_extended' => 'full' === $attributes['feedTextMode'] ? 'true' : 'false', 'screen_name' => $attributes['userName'], ) ); if ( $feed || $profile ) { ?>
<?php echo esc_attr( $profile['name'] ); ?>

@