Skip to content

Instantly share code, notes, and snippets.

@gamaup
Created November 9, 2018 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gamaup/fe0c00b284f8b7267c8677fbe2dbaf32 to your computer and use it in GitHub Desktop.
Save gamaup/fe0c00b284f8b7267c8677fbe2dbaf32 to your computer and use it in GitHub Desktop.
<?php
add_action( 'admin_menu', 'tair_admin_menu' );
function tair_admin_menu() {
add_menu_page( 'Tes airtable', 'Tes airtable', 'manage_options', 'tair', 'tair_admin' );
}
function tair_admin() {
global $wp_version;
$records = wp_remote_get( 'https://api.airtable.com/v0/appOc1ESRgBBFWbW9/Places?view=High%20priority', array(
'timeout' => 30,
'redirection' => 5,
'httpversion' => '1.0',
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ),
'blocking' => true,
'headers' => array(
'Authorization' => 'Bearer keygMxu1j2xIY8C7B'
),
'cookies' => array(),
'body' => null,
'compress' => false,
'decompress' => true,
'sslverify' => true,
'stream' => false,
'filename' => null,
) );
$records = json_decode($records['body']);
?>
<div class="wrap">
<h1 class="title">Tes Airtable</h1>
</div>
<table class="widefat striped">
<thead>
<tr>
<th>City</th>
<th>Pic</th>
<th>Priority</th>
<th>Highlights</th>
<th>Weekend Trip</th>
<th>International</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<?php foreach ( $records->records as $record ) : ?>
<tr>
<td><?php echo $record->fields->City; ?></td>
<td>
<?php foreach ( $record->fields->Pic as $pic ) : ?>
<img src="<?php echo $pic->thumbnails->small->url ?>">
<?php endforeach; ?>
</td>
<td><?php echo $record->fields->Priority; ?></td>
<td><?php echo implode(', ', $record->fields->Highlights); ?></td>
<td><?php echo isset( $record->fields->{'Weekend Trip'}) && $record->fields->{'Weekend Trip'} ? 'Yes' : 'No'; ?></td>
<td><?php echo isset( $record->fields->International) && $record->fields->International ? 'Yes' : 'No'; ?></td>
<td><?php echo isset( $record->fields->Notes ) ? $record->fields->Notes : ''; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
}
@gamaup
Copy link
Author

gamaup commented Nov 9, 2018

cara generate api:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment