Skip to content

Commit 16654bc

Browse files
committed
Cleanup plugin a bit
1 parent 594c6b1 commit 16654bc

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

cmb2-attached-posts-field.php

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,36 @@
33
Plugin Name: CMB2 Field Type: Attached Posts
44
Plugin URI: https://github.com/WebDevStudios/cmb2-attached-posts
55
Description: Attached posts field type for CMB2.
6-
Version: 1.0.0
7-
Author: Web Dev Studios
6+
Version: 1.2.0
7+
Author: WebDevStudios
88
Author URI: http://webdevstudios.com
99
License: GPLv2+
1010
*/
1111

1212
/**
13-
* Class WDS_CMB2_Field_Attached_Posts
13+
* Class WDS_CMB2_Attached_Posts_Field
1414
*/
15-
class WDS_CMB2_Field_Attached_Posts {
16-
15+
class WDS_CMB2_Attached_Posts_Field {
16+
1717
/**
1818
* Current version number
1919
*/
20-
const VERSION = '2.1.1';
20+
const VERSION = '1.2.0';
2121

2222
/**
2323
* Initialize the plugin by hooking into CMB2
2424
*/
2525
public function __construct() {
26-
add_action( 'cmb2_render_custom_attached_posts', array( $this, 'cmb2_attached_posts_fields_render' ), 10, 5 );
27-
add_action( 'cmb2_sanitize_custom_attached_posts', array( $this, 'cmb2_attached_posts_fields_sanitize' ), 10, 2 );
26+
add_action( 'cmb2_render_custom_attached_posts', array( $this, 'render' ), 10, 5 );
27+
add_action( 'cmb2_sanitize_custom_attached_posts', array( $this, 'sanitize' ), 10, 2 );
2828
}
2929

3030
/**
3131
* Add a CMB custom field to allow for the selection of multiple posts
3232
* attached to a single page
3333
*/
34-
public function cmb2_attached_posts_fields_render( $field, $escaped_value, $object_id, $object_type, $field_type ) {
34+
public function render( $field, $escaped_value, $object_id, $object_type, $field_type ) {
35+
3536
$this->setup_admin_scripts();
3637

3738
// Setup our args
@@ -102,7 +103,7 @@ public function cmb2_attached_posts_fields_render( $field, $escaped_value, $obje
102103
echo '<ul class="attached connected', $has_thumbnail ,'">';
103104

104105
// If we have any posts saved already, display them
105-
$post_ids = $this->cmb2_attached_posts_fields_display_attached( $field, $attached );
106+
$post_ids = $this->display_attached( $field, $attached );
106107

107108
$value = ! empty( $post_ids ) ? implode( ',', $post_ids ) : '';
108109

@@ -123,20 +124,11 @@ public function cmb2_attached_posts_fields_render( $field, $escaped_value, $obje
123124
$field_type->_desc( true, true );
124125

125126
}
126-
127-
128-
public function cmb2_attached_posts_fields_sanitize( $sanitized_val, $val ) {
129-
if ( ! empty( $val ) ) {
130-
return explode( ',', $val );
131-
}
132-
return $sanitized_val;
133-
}
134-
135127

136128
/**
137129
* Helper function to grab and filter our post meta
138130
*/
139-
private function cmb2_attached_posts_fields_display_attached( $field, $attached ) {
131+
protected function display_attached( $field, $attached ) {
140132

141133
// Start with nothing
142134
$output = '';
@@ -178,11 +170,18 @@ private function cmb2_attached_posts_fields_display_attached( $field, $attached
178170

179171
return $post_ids;
180172
}
181-
173+
174+
public function sanitize( $sanitized_val, $val ) {
175+
if ( ! empty( $val ) ) {
176+
return explode( ',', $val );
177+
}
178+
return $sanitized_val;
179+
}
180+
182181
/**
183182
* Enqueue admin scripts for our attached posts field
184183
*/
185-
private function setup_admin_scripts() {
184+
protected function setup_admin_scripts() {
186185
$dir = trailingslashit( dirname( __FILE__ ) );
187186

188187
if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ) {
@@ -215,4 +214,4 @@ private function setup_admin_scripts() {
215214

216215
}
217216
}
218-
$wds_cmb2_field_attached_posts = new WDS_CMB2_Field_Attached_Posts();
217+
$cmb2_attached_posts_field = new WDS_CMB2_Attached_Posts_Field();

0 commit comments

Comments
 (0)