Skip to content

Commit fd615ae

Browse files
committed
Pods Export to Code 0.9.1
1 parent 10fbfa5 commit fd615ae

File tree

7 files changed

+123
-409
lines changed

7 files changed

+123
-409
lines changed

admin/assets/css/admin.css

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
clear: both;
1616
}
1717

18+
.stuffbox.pods-export-code .pods-field-option-group {
19+
display: block;
20+
}
21+
1822
.pods-export-code div.pods-manage-field .pods-field-option-group {
1923
padding-top: 0;
2024
}

admin/class-pods-export-code.php

+34-48
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Class Pods_Export_Code_Admin
45
*/
@@ -21,31 +22,30 @@ class Pods_Export_Code_Admin {
2122
/**
2223
* @var array
2324
*/
24-
protected $exportable_pods = array();
25+
protected $exportable_pods = [];
2526

2627
/**
2728
* Initialize the plugin by loading admin scripts & styles and adding a
2829
* settings page and menu.
2930
*
3031
* @since 1.0.0
3132
*/
32-
private function __construct () {
33-
33+
private function __construct() {
3434
/*
3535
* Call $plugin_slug from public plugin class.
3636
*/
37-
$plugin = Pods_Export_Code::get_instance();
37+
$plugin = Pods_Export_Code::get_instance();
3838
$this->plugin_slug = $plugin->get_plugin_slug();
3939

4040
// Load admin style sheet and JavaScript.
41-
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
42-
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
41+
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_styles' ] );
42+
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] );
4343

4444
// Hook into the pods admin menu
45-
add_filter( 'pods_admin_menu', array( $this, 'add_plugin_admin_menu' ) );
45+
add_filter( 'pods_admin_menu', [ $this, 'add_plugin_admin_menu' ] );
4646

4747
// Ajax handler
48-
add_action( 'wp_ajax_pods_export_code', array( $this, 'pods_export_code' ) );
48+
add_action( 'wp_ajax_pods_export_code', [ $this, 'pods_export_code' ] );
4949
}
5050

5151
/**
@@ -55,8 +55,7 @@ private function __construct () {
5555
*
5656
* @return object A single instance of this class.
5757
*/
58-
public static function get_instance () {
59-
58+
public static function get_instance() {
6059
// If the single instance hasn't been set, set it now.
6160
if ( null == self::$instance ) {
6261
self::$instance = new self;
@@ -72,17 +71,15 @@ public static function get_instance () {
7271
*
7372
* @return null Return early if no settings page is registered.
7473
*/
75-
public function enqueue_admin_styles () {
76-
77-
if ( !isset( $this->plugin_screen_hook_suffix ) ) {
74+
public function enqueue_admin_styles() {
75+
if ( ! isset( $this->plugin_screen_hook_suffix ) ) {
7876
return;
7977
}
8078

8179
$screen = get_current_screen();
8280
if ( $this->plugin_screen_hook_suffix == $screen->id ) {
83-
wp_enqueue_style( $this->plugin_slug . '-admin-styles', plugins_url( 'assets/css/admin.css', __FILE__ ), array(), Pods_Export_Code::VERSION );
81+
wp_enqueue_style( $this->plugin_slug . '-admin-styles', plugins_url( 'assets/css/admin.css', __FILE__ ), [], Pods_Export_Code::VERSION );
8482
}
85-
8683
}
8784

8885
/**
@@ -92,17 +89,15 @@ public function enqueue_admin_styles () {
9289
*
9390
* @return null Return early if no settings page is registered.
9491
*/
95-
public function enqueue_admin_scripts () {
96-
97-
if ( !isset( $this->plugin_screen_hook_suffix ) ) {
92+
public function enqueue_admin_scripts() {
93+
if ( ! isset( $this->plugin_screen_hook_suffix ) ) {
9894
return;
9995
}
10096

10197
$screen = get_current_screen();
10298
if ( $this->plugin_screen_hook_suffix == $screen->id ) {
103-
wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.js', __FILE__ ), array( 'jquery' ), Pods_Export_Code::VERSION );
99+
wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.js', __FILE__ ), [ 'jquery' ], Pods_Export_Code::VERSION );
104100
}
105-
106101
}
107102

108103
/**
@@ -112,26 +107,24 @@ public function enqueue_admin_scripts () {
112107
*
113108
* @return array
114109
*/
115-
public function add_plugin_admin_menu ( $admin_menus ) {
116-
110+
public function add_plugin_admin_menu( $admin_menus ) {
117111
// Fresh array to insert our new menu item
118-
$new_menus = array();
112+
$new_menus = [];
119113

120114
// New menu item to insert
121-
$plugin_menu = array(
115+
$plugin_menu = [
122116
'label' => 'Export to Code',
123-
'function' => array( $this, 'display_plugin_admin_page' ),
124-
'access' => $this->plugin_slug
125-
);
117+
'function' => [ $this, 'display_plugin_admin_page' ],
118+
'access' => $this->plugin_slug,
119+
];
126120

127121
// Loop through the Pods menu items looking for the target to insert after
128122
foreach ( $admin_menus as $key => $this_menu_item ) {
129-
130123
// Copy all the menu items
131124
$new_menus[ $key ] = $this_menu_item;
132125

133126
// Insert our menu item after pods components
134-
if ( isset( $this_menu_item[ 'access' ] ) && 'pods_components' == $this_menu_item[ 'access' ] ) {
127+
if ( isset( $this_menu_item['access'] ) && 'pods_components' == $this_menu_item['access'] ) {
135128
$new_menus[ $this->plugin_slug ] = $plugin_menu;
136129

137130
// ToDo: Proper way to do this?
@@ -147,56 +140,49 @@ public function add_plugin_admin_menu ( $admin_menus ) {
147140
*
148141
* @since 1.0.0
149142
*/
150-
public function display_plugin_admin_page () {
151-
143+
public function display_plugin_admin_page() {
152144
$this->set_exportable_pods();
153145
if ( count( $this->exportable_pods() ) > 0 ) {
154146
include_once( 'views/admin.php' );
155-
}
156-
else {
147+
} else {
157148
include_once( 'views/admin-no-pods.php' );
158149
}
159-
160150
}
161151

162152
/**
163153
*
164154
*/
165-
private function set_exportable_pods () {
155+
private function set_exportable_pods() {
156+
$this->exportable_pods = [];
166157

167-
$this->exportable_pods = array();
168-
169-
$pods = pods_api()->load_pods( array( 'fields' => false ) );
158+
$pods = pods_api()->load_pods( [ 'fields' => false ] );
170159
foreach ( $pods as $this_pod ) {
171-
172160
// We do no support table-based Pods
173-
if ( 'table' == $this_pod[ 'storage' ] ) {
161+
if ( 'table' == $this_pod['storage'] ) {
174162
continue;
175163
}
176164

177-
$this->exportable_pods[ ] = $this_pod;
165+
$this->exportable_pods[] = $this_pod;
178166
}
179-
180167
}
181168

182169
/**
183170
* @return array
184171
*/
185-
public function exportable_pods () {
172+
public function exportable_pods() {
186173
return $this->exportable_pods;
187174
}
188175

189176
/**
190177
* AJAX handler
191178
*/
192-
public function pods_export_code () {
193-
194-
if ( !isset( $_POST[ 'pod_names' ] ) ) {
179+
public function pods_export_code() {
180+
if ( ! isset( $_POST['pod_names'] ) ) {
195181
die();
196182
}
197-
$pod_names = $_POST[ 'pod_names' ];
183+
$pod_names = $_POST['pod_names'];
198184

199-
if ( !is_array( $pod_names ) ) {
185+
if ( ! is_array( $pod_names ) ) {
200186
die();
201187
}
202188

0 commit comments

Comments
 (0)