Created
November 9, 2018 10:13
-
-
Save gamaup/fe0c00b284f8b7267c8677fbe2dbaf32 to your computer and use it in GitHub Desktop.
Get airtable records https://airtable.com/shroE7aeG3Q79zfBP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cara generate api: