Skip to content

Commit 8b693fa

Browse files
committed
Tightened down a few more screws
1 parent c11a041 commit 8b693fa

File tree

4 files changed

+59
-17
lines changed

4 files changed

+59
-17
lines changed

admin/class-pods-export-code.php

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ class Pods_Export_Code_Admin {
77
/**
88
* Instance of this class.
99
*
10-
* @since 1.0.0
11-
*
1210
* @var object
1311
*/
1412
protected static $instance = null;
1513

1614
/**
1715
* Slug of the plugin screen.
1816
*
19-
* @since 1.0.0
20-
*
2117
* @var string
2218
*/
2319
protected $plugin_screen_hook_suffix = null;
2420

21+
/**
22+
* @var array
23+
*/
24+
protected $exportable_pods = array();
25+
2526
/**
2627
* Initialize the plugin by loading admin scripts & styles and adding a
2728
* settings page and menu.
@@ -147,7 +148,22 @@ public function add_plugin_admin_menu ( $admin_menus ) {
147148
* @since 1.0.0
148149
*/
149150
public function display_plugin_admin_page () {
150-
include_once( 'views/admin.php' );
151+
152+
$this->set_exportable_pods();
153+
if ( count( $this->exportable_pods() ) > 0 ) {
154+
include_once( 'views/admin.php' );
155+
}
156+
else {
157+
include_once( 'views/admin-no-pods.php' );
158+
}
159+
160+
}
161+
162+
/**
163+
* @return array|null
164+
*/
165+
public function exportable_pods() {
166+
return $this->exportable_pods;
151167
}
152168

153169
/**
@@ -171,4 +187,25 @@ public function pods_export_code () {
171187

172188
die();
173189
}
190+
191+
/**
192+
*
193+
*/
194+
private function set_exportable_pods() {
195+
196+
$this->exportable_pods = array();
197+
198+
$pods = pods_api()->load_pods( array( 'fields' => false ) );
199+
foreach ( $pods as $this_pod ) {
200+
201+
// We only support meta-based Pods
202+
if ( 'table' == $this_pod[ 'storage' ] ) {
203+
continue;
204+
}
205+
206+
$this->exportable_pods[] = $this_pod;
207+
}
208+
209+
}
210+
174211
}

admin/classes/pods-export-code-api.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ public function export_pod ( $pod_name ) {
2626

2727
$output = '';
2828

29-
// Attempt to load the pod
30-
// ToDo: test with bad pod names
29+
// Attempt to load the pod, don't throw an exception on error
3130
$params = array(
3231
'name' => $pod_name,
3332
'fields' => true,
3433
);
35-
$pod = $this->api->load_pod( $params );
34+
$pod = $this->api->load_pod( $params, false );
3635

37-
// We only support meta-based Pods
38-
if ( 'table' == $pod[ 'storage' ] ) {
36+
// Exit if the pod wasn't found or is table based (not supported)
37+
if ( false === $pod || !isset( $pod[ 'storage' ] ) || 'table' == $pod[ 'storage' ] ) {
3938
return '';
4039
}
4140

admin/views/admin-no-pods.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="wrap">
2+
3+
<?php screen_icon( 'options-general' ); ?>
4+
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
5+
6+
<div class="updated">
7+
<p>
8+
There are no Pods to export.
9+
</p>
10+
</div>
11+
</div>

admin/views/admin.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?php /** @global Pods_Export_Code_Admin $this */ ?>
12
<div class="wrap">
23

34
<?php screen_icon( 'options-general' ); ?>
@@ -16,14 +17,8 @@
1617
<div class="pods-pick-values pods-pick-checkbox pods-zebra">
1718
<ul>
1819
<?php
19-
$pods = pods_api()->load_pods( array( 'fields' => false ) );
2020
$zebra = false;
21-
foreach ( $pods as $this_pod ) {
22-
23-
// We only support meta-based Pods
24-
if ( 'table' == $this_pod[ 'storage' ] ) {
25-
continue;
26-
}
21+
foreach ( $this->exportable_pods() as $this_pod ) {
2722

2823
$class = ( $zebra ? 'even' : 'odd' );
2924
$zebra = ( !$zebra );

0 commit comments

Comments
 (0)