@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @subpackage Test Content |
11 | 11 | * @author Old Town Media |
12 | 12 | */ |
13 | -abstract class Type{ |
|
13 | +abstract class Type { |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * type |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | protected $type; |
23 | 23 | |
24 | 24 | |
25 | - public function register_type(){ |
|
25 | + public function register_type() { |
|
26 | 26 | |
27 | - add_action( 'tc_types', 'set_type' ); |
|
27 | + add_action('tc_types', 'set_type'); |
|
28 | 28 | |
29 | 29 | } |
30 | 30 | |
31 | - public function set_type( $types ){ |
|
31 | + public function set_type($types) { |
|
32 | 32 | |
33 | 33 | $types[] = $this->type; |
34 | 34 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @subpackage Evans |
9 | 9 | * @author Old Town Media |
10 | 10 | */ |
11 | -class AdminPage{ |
|
11 | +class AdminPage { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * plugin |
@@ -45,16 +45,16 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @see admin_menu, wp_ajax actions |
47 | 47 | */ |
48 | - public function hooks(){ |
|
48 | + public function hooks() { |
|
49 | 49 | |
50 | 50 | $connection = new ConnectionTest; |
51 | - $this->definitions = $this->plugin->get_definitions(); |
|
52 | - $this->connected = $connection->test(); |
|
51 | + $this->definitions = $this->plugin->get_definitions(); |
|
52 | + $this->connected = $connection->test(); |
|
53 | 53 | |
54 | - add_action( 'admin_menu' , array( $this, 'add_menu_item' ) ); |
|
55 | - add_action( 'wp_ajax_handle_test_data', array( $this, 'handle_test_data_callback' ) ); |
|
56 | - add_filter( 'plugin_action_links_' . $this->definitions->basename , array( $this, 'add_settings_link' ) ); |
|
57 | - add_action( 'admin_notices', array( $this, 'internet_connected_admin_notice' ) ); |
|
54 | + add_action('admin_menu', array($this, 'add_menu_item')); |
|
55 | + add_action('wp_ajax_handle_test_data', array($this, 'handle_test_data_callback')); |
|
56 | + add_filter('plugin_action_links_'.$this->definitions->basename, array($this, 'add_settings_link')); |
|
57 | + add_action('admin_notices', array($this, 'internet_connected_admin_notice')); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @param Plugin $plugin Main plugin instance. |
66 | 66 | */ |
67 | - public function set_plugin( $plugin ) { |
|
67 | + public function set_plugin($plugin) { |
|
68 | 68 | |
69 | 69 | $this->plugin = $plugin; |
70 | 70 | return $this; |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | |
82 | 82 | $page = add_submenu_page( |
83 | 83 | 'tools.php', |
84 | - __( 'Create Test Content', 'otm-test-content' ), |
|
85 | - __( 'Test Content', 'otm-test-content' ), |
|
84 | + __('Create Test Content', 'otm-test-content'), |
|
85 | + __('Test Content', 'otm-test-content'), |
|
86 | 86 | 'manage_options', |
87 | 87 | 'create-test-data', |
88 | - array( $this, 'admin_page' ) |
|
88 | + array($this, 'admin_page') |
|
89 | 89 | ); |
90 | 90 | |
91 | - add_action( 'admin_print_styles-' . $page, array( $this, 'load_scripts' ) ); |
|
91 | + add_action('admin_print_styles-'.$page, array($this, 'load_scripts')); |
|
92 | 92 | |
93 | 93 | } |
94 | 94 | |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | * @param array $links Existing links |
99 | 99 | * @return array Modified links |
100 | 100 | */ |
101 | - public function add_settings_link( $links ) { |
|
101 | + public function add_settings_link($links) { |
|
102 | 102 | |
103 | - $settings_link = '<a href="tools.php?page=create-test-data">' . __( 'Build Test Content', 'otm-test-content' ) . '</a>'; |
|
104 | - array_push( $links, $settings_link ); |
|
103 | + $settings_link = '<a href="tools.php?page=create-test-data">'.__('Build Test Content', 'otm-test-content').'</a>'; |
|
104 | + array_push($links, $settings_link); |
|
105 | 105 | return $links; |
106 | 106 | |
107 | 107 | } |
@@ -114,24 +114,24 @@ discard block |
||
114 | 114 | * Internet, and the test fails displays a notice informing the user that |
115 | 115 | * images will not pull into test data. |
116 | 116 | */ |
117 | - public function internet_connected_admin_notice(){ |
|
117 | + public function internet_connected_admin_notice() { |
|
118 | 118 | |
119 | 119 | // Get the current admin screen & verify that we're on the right one |
120 | 120 | // before continuing. |
121 | 121 | $screen = get_current_screen(); |
122 | 122 | |
123 | - if ( $screen->base != 'tools_page_create-test-data' ){ |
|
123 | + if ($screen->base != 'tools_page_create-test-data') { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | 127 | // Check the response |
128 | - if ( $this->connected ) { |
|
128 | + if ($this->connected) { |
|
129 | 129 | // We got a response so early return |
130 | 130 | return; |
131 | 131 | } else { |
132 | 132 | // We didn't get a reponse so print the notice out |
133 | 133 | echo '<div class="notice notice-error">'; |
134 | - echo '<p>'.__( 'WordPress could not connect to Splashbase and therefore images will not pull into metaboxes/thumbnails. Turn Airplane Mode off or reconnect to the Internet to get images when creating test data.', 'otm-test-content' ).'</p>'; |
|
134 | + echo '<p>'.__('WordPress could not connect to Splashbase and therefore images will not pull into metaboxes/thumbnails. Turn Airplane Mode off or reconnect to the Internet to get images when creating test data.', 'otm-test-content').'</p>'; |
|
135 | 135 | echo '</div>'; |
136 | 136 | } |
137 | 137 | |
@@ -141,19 +141,19 @@ discard block |
||
141 | 141 | /** |
142 | 142 | * Load our script in the admin section and serve in data. |
143 | 143 | */ |
144 | - public function load_scripts(){ |
|
144 | + public function load_scripts() { |
|
145 | 145 | |
146 | - wp_enqueue_script( 'test-content-js', plugins_url( 'assets/admin.js' , dirname( __FILE__ ) ) ); |
|
147 | - wp_enqueue_style( 'test-content-css', plugins_url( 'assets/admin.css' , dirname( __FILE__ ) ) ); |
|
146 | + wp_enqueue_script('test-content-js', plugins_url('assets/admin.js', dirname(__FILE__))); |
|
147 | + wp_enqueue_style('test-content-css', plugins_url('assets/admin.css', dirname(__FILE__))); |
|
148 | 148 | |
149 | 149 | $data = array( |
150 | - 'nonce' => wp_create_nonce( 'handle-test-data' ), |
|
151 | - 'createdStr' => __( 'Created', 'otm-test-content' ), |
|
152 | - 'deletedStr' => __( 'Deleting', 'otm-test-content' ), |
|
153 | - 'creatingStr' => __( 'Creating', 'otm-test-content' ), |
|
150 | + 'nonce' => wp_create_nonce('handle-test-data'), |
|
151 | + 'createdStr' => __('Created', 'otm-test-content'), |
|
152 | + 'deletedStr' => __('Deleting', 'otm-test-content'), |
|
153 | + 'creatingStr' => __('Creating', 'otm-test-content'), |
|
154 | 154 | ); |
155 | 155 | |
156 | - wp_localize_script( 'test-content-js', 'test_content', $data ); |
|
156 | + wp_localize_script('test-content-js', 'test_content', $data); |
|
157 | 157 | |
158 | 158 | } |
159 | 159 | |
@@ -165,21 +165,21 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function handle_test_data_callback() { |
167 | 167 | |
168 | - $action = $_REQUEST['todo']; |
|
169 | - $nonce = $_REQUEST['nonce']; |
|
168 | + $action = $_REQUEST['todo']; |
|
169 | + $nonce = $_REQUEST['nonce']; |
|
170 | 170 | |
171 | 171 | // Verify that we have a proper logged in user and it's the right person |
172 | - if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'handle-test-data' ) ){ |
|
172 | + if (empty($nonce) || !wp_verify_nonce($nonce, 'handle-test-data')) { |
|
173 | 173 | return; |
174 | 174 | } |
175 | 175 | |
176 | - if ( $action == 'delete' ){ |
|
176 | + if ($action == 'delete') { |
|
177 | 177 | |
178 | - $this->deletion_routing( $_REQUEST ); |
|
178 | + $this->deletion_routing($_REQUEST); |
|
179 | 179 | |
180 | - } elseif ( $action == 'create' ){ |
|
180 | + } elseif ($action == 'create') { |
|
181 | 181 | |
182 | - $this->creation_routing( $_REQUEST ); |
|
182 | + $this->creation_routing($_REQUEST); |
|
183 | 183 | |
184 | 184 | } |
185 | 185 | |
@@ -192,11 +192,11 @@ discard block |
||
192 | 192 | * Choose which type of creation needs to be accomplished and route through |
193 | 193 | * the correct class. |
194 | 194 | */ |
195 | - private function creation_routing( $data ){ |
|
195 | + private function creation_routing($data) { |
|
196 | 196 | |
197 | - $type = 'testContent\Types\\' . ucwords( $data['type'] ); |
|
197 | + $type = 'testContent\Types\\'.ucwords($data['type']); |
|
198 | 198 | $object = new $type(); |
199 | - $object->create_objects( $data['slug'], $data['connection'], true, 1 ); |
|
199 | + $object->create_objects($data['slug'], $data['connection'], true, 1); |
|
200 | 200 | |
201 | 201 | } |
202 | 202 | |
@@ -205,17 +205,17 @@ discard block |
||
205 | 205 | * Choose which type of deletion needs to be accomplished and route through |
206 | 206 | * the correct method of Delete. |
207 | 207 | */ |
208 | - private function deletion_routing( $data ){ |
|
208 | + private function deletion_routing($data) { |
|
209 | 209 | |
210 | 210 | $delete_content = new Delete; |
211 | 211 | |
212 | - if ( $data['type'] == 'all' ){ |
|
212 | + if ($data['type'] == 'all') { |
|
213 | 213 | |
214 | - $delete_content->delete_all_test_data( true ); |
|
214 | + $delete_content->delete_all_test_data(true); |
|
215 | 215 | |
216 | 216 | } else { |
217 | 217 | |
218 | - $delete_content->delete_objects( true, $data ); |
|
218 | + $delete_content->delete_objects(true, $data); |
|
219 | 219 | |
220 | 220 | } |
221 | 221 | |
@@ -225,20 +225,20 @@ discard block |
||
225 | 225 | /** |
226 | 226 | * Print out our admin page to control test data. |
227 | 227 | */ |
228 | - public function admin_page(){ |
|
229 | - echo '<div class="wrap" id="options_editor">' . "\n"; |
|
228 | + public function admin_page() { |
|
229 | + echo '<div class="wrap" id="options_editor">'."\n"; |
|
230 | 230 | |
231 | - echo '<h2>' . __( 'Create Test Data' , 'otm-test-content' ) . '</h2>' . "\n"; |
|
231 | + echo '<h2>'.__('Create Test Data', 'otm-test-content').'</h2>'."\n"; |
|
232 | 232 | |
233 | 233 | echo "<div class='nav-tab-wrapper'>"; |
234 | 234 | |
235 | - do_action( 'tc-admin-tabs', '' ); |
|
235 | + do_action('tc-admin-tabs', ''); |
|
236 | 236 | |
237 | 237 | echo "</div>"; |
238 | 238 | |
239 | 239 | echo ""; |
240 | 240 | |
241 | - do_action( 'tc-admin-sections', '' ); |
|
241 | + do_action('tc-admin-sections', ''); |
|
242 | 242 | |
243 | 243 | echo ""; |
244 | 244 |
@@ -8,32 +8,32 @@ discard block |
||
8 | 8 | * @subpackage Evans |
9 | 9 | * @author Old Town Media |
10 | 10 | */ |
11 | -class Delete{ |
|
11 | +class Delete { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Delete all test content created ever. |
15 | 15 | * |
16 | 16 | * @access private |
17 | 17 | */ |
18 | - public function delete_all_test_data( $echo = false ){ |
|
18 | + public function delete_all_test_data($echo = false) { |
|
19 | 19 | |
20 | - if ( !$this->user_can_delete() ){ |
|
20 | + if (!$this->user_can_delete()) { |
|
21 | 21 | return; |
22 | 22 | } |
23 | 23 | |
24 | 24 | // Loop through all post types and remove any test data |
25 | - $post_types = get_post_types( array( 'public' => true ), 'objects' ); |
|
26 | - foreach ( $post_types as $post_type ) : |
|
25 | + $post_types = get_post_types(array('public' => true), 'objects'); |
|
26 | + foreach ($post_types as $post_type) : |
|
27 | 27 | |
28 | - $this->delete_posts( $post_type->name, $echo ); |
|
28 | + $this->delete_posts($post_type->name, $echo); |
|
29 | 29 | |
30 | 30 | endforeach; |
31 | 31 | |
32 | 32 | // Loop through all taxonomies and remove any data |
33 | 33 | $taxonomies = get_taxonomies(); |
34 | - foreach ( $taxonomies as $tax ) : |
|
34 | + foreach ($taxonomies as $tax) : |
|
35 | 35 | |
36 | - $this->delete_terms( $tax, $echo ); |
|
36 | + $this->delete_terms($tax, $echo); |
|
37 | 37 | |
38 | 38 | endforeach; |
39 | 39 | |
@@ -51,22 +51,22 @@ discard block |
||
51 | 51 | * @param string $slug a custom post type ID. |
52 | 52 | * @param boolean $echo Whether or not to echo the result |
53 | 53 | */ |
54 | - public function delete_objects( $echo = false, $data ){ |
|
54 | + public function delete_objects($echo = false, $data) { |
|
55 | 55 | |
56 | 56 | // Make sure that the current user is logged in & has full permissions. |
57 | - if ( !$this->user_can_delete() ){ |
|
57 | + if (!$this->user_can_delete()) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | 60 | |
61 | - if ( empty( $data ) ){ |
|
61 | + if (empty($data)) { |
|
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
65 | - $type = 'testContent\Types\\' . ucwords( $data['type'] ); |
|
65 | + $type = 'testContent\Types\\'.ucwords($data['type']); |
|
66 | 66 | $slug = $data['slug']; |
67 | 67 | |
68 | 68 | $object = new $type(); |
69 | - $object->delete( $slug, $echo ); |
|
69 | + $object->delete($slug, $echo); |
|
70 | 70 | |
71 | 71 | } |
72 | 72 | |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @see is_user_logged_in, current_user_can |
78 | 78 | */ |
79 | - public function user_can_delete(){ |
|
79 | + public function user_can_delete() { |
|
80 | 80 | |
81 | 81 | // User must be logged in |
82 | - if ( !is_user_logged_in() ){ |
|
82 | + if (!is_user_logged_in()) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // User must have editor priveledges, at a minimum |
87 | - if ( !current_user_can( 'delete_others_posts' ) ){ |
|
87 | + if (!current_user_can('delete_others_posts')) { |
|
88 | 88 | return false; |
89 | 89 | } |
90 | 90 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @subpackage Evans |
9 | 9 | * @author Old Town Media |
10 | 10 | */ |
11 | -class Metaboxes{ |
|
11 | +class Metaboxes { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Decide which cmb library to try and loop to get our metaboxes. |
@@ -22,31 +22,31 @@ discard block |
||
22 | 22 | * @param string $slug Post Type slug ID. |
23 | 23 | * @return array Fields to fill in for our post object. |
24 | 24 | */ |
25 | - public function get_metaboxes( $slug ){ |
|
25 | + public function get_metaboxes($slug) { |
|
26 | 26 | $cmb2_fields = $cmb_fields = $acf_fields = array(); |
27 | 27 | |
28 | 28 | // CMB2 |
29 | - if ( class_exists( 'CMB2', false ) ) { |
|
30 | - $cmb2_fields = $this->get_cmb2_metaboxes( $slug ); |
|
29 | + if (class_exists('CMB2', false)) { |
|
30 | + $cmb2_fields = $this->get_cmb2_metaboxes($slug); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | // Custom Metaboxes and Fields (CMB1) |
34 | - if ( class_exists( 'cmb_Meta_Box', false ) ) { |
|
35 | - $cmb_fields = $this->get_cmb1_metaboxes( $slug ); |
|
34 | + if (class_exists('cmb_Meta_Box', false)) { |
|
35 | + $cmb_fields = $this->get_cmb1_metaboxes($slug); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | // Advanced Custom Fields (ACF Free) |
39 | - if ( class_exists( 'acf', false ) ) { |
|
40 | - $acf_fields = $this->get_acf_free_metaboxes( $slug ); |
|
39 | + if (class_exists('acf', false)) { |
|
40 | + $acf_fields = $this->get_acf_free_metaboxes($slug); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | // Return our array |
44 | - return array_merge( $cmb2_fields, $cmb_fields, $acf_fields ); |
|
44 | + return array_merge($cmb2_fields, $cmb_fields, $acf_fields); |
|
45 | 45 | |
46 | 46 | } |
47 | 47 | |
48 | 48 | |
49 | - private function get_acf_free_metaboxes( $slug ){ |
|
49 | + private function get_acf_free_metaboxes($slug) { |
|
50 | 50 | |
51 | 51 | $fields = array(); |
52 | 52 | |
@@ -54,21 +54,21 @@ discard block |
||
54 | 54 | $fieldsets = $this->get_all_acf_field_groups(); |
55 | 55 | |
56 | 56 | // Return empty array if there are no fieldsets at all |
57 | - if ( empty( $fieldsets ) ){ |
|
57 | + if (empty($fieldsets)) { |
|
58 | 58 | return $fields; |
59 | 59 | } |
60 | 60 | |
61 | 61 | // Loop through each fieldset for possible matches |
62 | - foreach ( $fieldsets as $fieldset ){ |
|
62 | + foreach ($fieldsets as $fieldset) { |
|
63 | 63 | |
64 | - if ( $this->is_acf_field_in_post_type( $slug, $fieldset ) ){ |
|
64 | + if ($this->is_acf_field_in_post_type($slug, $fieldset)) { |
|
65 | 65 | |
66 | 66 | // If this is the first group of fields, simply set the value |
67 | 67 | // Else, merge this group with the previous one |
68 | - if ( empty( $fields ) ){ |
|
68 | + if (empty($fields)) { |
|
69 | 69 | $fields = $fieldset->fields; |
70 | 70 | } else { |
71 | - $fields = array_merge( $fields, $fieldset->fields ); |
|
71 | + $fields = array_merge($fields, $fieldset->fields); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | } |
@@ -80,16 +80,16 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | |
83 | - private function is_acf_field_in_post_type( $slug, $fieldset ){ |
|
83 | + private function is_acf_field_in_post_type($slug, $fieldset) { |
|
84 | 84 | |
85 | 85 | // Make sure we have something to parse |
86 | - if ( empty( $fieldset ) ){ |
|
86 | + if (empty($fieldset)) { |
|
87 | 87 | return false; |
88 | 88 | } |
89 | 89 | |
90 | 90 | // Loop through the rules to check for post type matches |
91 | - foreach ( $fieldset->rules as $rule ){ |
|
92 | - if ( $rule['param'] === 'post_type' && $rule['value'] === $slug ){ |
|
91 | + foreach ($fieldset->rules as $rule) { |
|
92 | + if ($rule['param'] === 'post_type' && $rule['value'] === $slug) { |
|
93 | 93 | return true; |
94 | 94 | } |
95 | 95 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | |
103 | - private function get_all_acf_field_groups(){ |
|
103 | + private function get_all_acf_field_groups() { |
|
104 | 104 | $info = $rules = $fields = array(); |
105 | 105 | |
106 | 106 | $args = array( |
@@ -108,20 +108,20 @@ discard block |
||
108 | 108 | 'posts_per_page'=> 500 |
109 | 109 | ); |
110 | 110 | |
111 | - $objects = new \WP_Query( $args ); |
|
111 | + $objects = new \WP_Query($args); |
|
112 | 112 | |
113 | - if ( $objects->have_posts() ) : |
|
114 | - while ( $objects->have_posts() ) : $objects->the_post(); |
|
113 | + if ($objects->have_posts()) : |
|
114 | + while ($objects->have_posts()) : $objects->the_post(); |
|
115 | 115 | |
116 | - $data = get_metadata( 'post', get_the_id() ); |
|
116 | + $data = get_metadata('post', get_the_id()); |
|
117 | 117 | |
118 | - foreach ( $data['rule'] as $rule ){ |
|
119 | - $rules[] = unserialize( $rule ); |
|
118 | + foreach ($data['rule'] as $rule) { |
|
119 | + $rules[] = unserialize($rule); |
|
120 | 120 | } |
121 | 121 | |
122 | - foreach ( $data as $key => $value ){ |
|
123 | - if ( substr( $key, 0, 6 ) == 'field_' ) : |
|
124 | - $field_detail = unserialize( $value[0] ); |
|
122 | + foreach ($data as $key => $value) { |
|
123 | + if (substr($key, 0, 6) == 'field_') : |
|
124 | + $field_detail = unserialize($value[0]); |
|
125 | 125 | $fields[] = array( |
126 | 126 | 'key' => $field_detail['key'], |
127 | 127 | 'type' => $field_detail['type'], |
@@ -159,55 +159,55 @@ discard block |
||
159 | 159 | * @param string $slug a custom post type ID. |
160 | 160 | * @return array Array of fields. |
161 | 161 | */ |
162 | - private function get_cmb2_metaboxes( $slug ){ |
|
162 | + private function get_cmb2_metaboxes($slug) { |
|
163 | 163 | |
164 | 164 | $fields = array(); |
165 | 165 | |
166 | 166 | // Get all metaboxes from CMB2 library |
167 | - $all_metaboxes = apply_filters( 'cmb2_meta_boxes', array() ); |
|
167 | + $all_metaboxes = apply_filters('cmb2_meta_boxes', array()); |
|
168 | 168 | |
169 | 169 | // Loop through all possible sets of metaboxes added the old way |
170 | - foreach ( $all_metaboxes as $metabox_array ){ |
|
170 | + foreach ($all_metaboxes as $metabox_array) { |
|
171 | 171 | |
172 | 172 | // If the custom post type ID matches this set of fields, set & stop |
173 | - if ( in_array( $slug, $metabox_array['object_types'] ) ) { |
|
173 | + if (in_array($slug, $metabox_array['object_types'])) { |
|
174 | 174 | |
175 | 175 | // If this is the first group of fields, simply set the value |
176 | 176 | // Else, merge this group with the previous one |
177 | - if ( empty( $fields ) ){ |
|
177 | + if (empty($fields)) { |
|
178 | 178 | $fields = $metabox_array['fields']; |
179 | 179 | } else { |
180 | - $fields = array_merge( $fields, $metabox_array['fields'] ); |
|
180 | + $fields = array_merge($fields, $metabox_array['fields']); |
|
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | 184 | } |
185 | 185 | |
186 | 186 | // Loop through all metaboxes added the new way |
187 | - foreach ( \CMB2_Boxes::get_all() as $cmb ) { |
|
187 | + foreach (\CMB2_Boxes::get_all() as $cmb) { |
|
188 | 188 | |
189 | 189 | // Create the default |
190 | 190 | $match = false; |
191 | 191 | |
192 | 192 | // Establish correct cmb types |
193 | - if ( is_string( $cmb->meta_box['object_types'] ) ){ |
|
194 | - if ( $cmb->meta_box['object_types'] == $slug ){ |
|
193 | + if (is_string($cmb->meta_box['object_types'])) { |
|
194 | + if ($cmb->meta_box['object_types'] == $slug) { |
|
195 | 195 | $match = true; |
196 | 196 | } |
197 | 197 | } else { |
198 | - if ( in_array( $slug, $cmb->meta_box['object_types'] ) ){ |
|
198 | + if (in_array($slug, $cmb->meta_box['object_types'])) { |
|
199 | 199 | $match = true; |
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
203 | - if ( $match !== true ){ |
|
203 | + if ($match !== true) { |
|
204 | 204 | continue; |
205 | 205 | } |
206 | 206 | |
207 | - if ( empty( $fields ) ){ |
|
207 | + if (empty($fields)) { |
|
208 | 208 | $fields = $cmb->meta_box['fields']; |
209 | 209 | } else { |
210 | - $fields = array_merge( $fields, $cmb->meta_box['fields'] ); |
|
210 | + $fields = array_merge($fields, $cmb->meta_box['fields']); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | } |
@@ -231,25 +231,25 @@ discard block |
||
231 | 231 | * @param string $slug a custom post type ID. |
232 | 232 | * @return array Array of fields. |
233 | 233 | */ |
234 | - private function get_cmb1_metaboxes( $slug ){ |
|
234 | + private function get_cmb1_metaboxes($slug) { |
|
235 | 235 | |
236 | 236 | $fields = array(); |
237 | 237 | |
238 | 238 | // Get all metaboxes from CMB2 library |
239 | - $all_metaboxes = apply_filters( 'cmb_meta_boxes', array() ); |
|
239 | + $all_metaboxes = apply_filters('cmb_meta_boxes', array()); |
|
240 | 240 | |
241 | 241 | // Loop through all possible sets of metaboxes |
242 | - foreach ( $all_metaboxes as $metabox_array ){ |
|
242 | + foreach ($all_metaboxes as $metabox_array) { |
|
243 | 243 | |
244 | 244 | // If the custom post type ID matches this set of fields, set & stop |
245 | - if ( in_array( $slug, $metabox_array['pages'] ) ) { |
|
245 | + if (in_array($slug, $metabox_array['pages'])) { |
|
246 | 246 | |
247 | 247 | // If this is the first group of fields, simply set the value |
248 | 248 | // Else, merge this group with the previous one |
249 | - if ( empty( $fields ) ){ |
|
249 | + if (empty($fields)) { |
|
250 | 250 | $fields = $metabox_array['fields']; |
251 | 251 | } else { |
252 | - $fields = array_merge( $fields, $metabox_array['fields'] ); |
|
252 | + $fields = array_merge($fields, $metabox_array['fields']); |
|
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
@@ -272,36 +272,36 @@ discard block |
||
272 | 272 | * @param int $post_id Single post ID. |
273 | 273 | * @param array $cmb custom metabox array from CMB2. |
274 | 274 | */ |
275 | - public function random_metabox_content( $post_id, $cmb, $connected ){ |
|
275 | + public function random_metabox_content($post_id, $cmb, $connected) { |
|
276 | 276 | $value = ''; |
277 | 277 | |
278 | 278 | // First check that our post ID & cmb array aren't empty |
279 | - if ( empty( $cmb ) || empty( $post_id ) ){ |
|
279 | + if (empty($cmb) || empty($post_id)) { |
|
280 | 280 | return; |
281 | 281 | } |
282 | 282 | |
283 | 283 | // Fetch the appropriate type of data and return |
284 | - switch( $cmb['type'] ){ |
|
284 | + switch ($cmb['type']) { |
|
285 | 285 | |
286 | 286 | case 'text': |
287 | 287 | case 'text_small': |
288 | 288 | case 'text_medium': |
289 | 289 | |
290 | 290 | // If phone is in the id, fetch a phone # |
291 | - if ( stripos( $cmb['id'], 'phone' ) ){ |
|
291 | + if (stripos($cmb['id'], 'phone')) { |
|
292 | 292 | $value = TestContent::phone(); |
293 | 293 | |
294 | 294 | // If email is in the id, fetch an email address |
295 | - } elseif ( stripos( $cmb['id'], 'email' ) ){ |
|
295 | + } elseif (stripos($cmb['id'], 'email')) { |
|
296 | 296 | $value = TestContent::email(); |
297 | 297 | |
298 | 298 | // If time is in the id, fetch a time string |
299 | - } elseif ( stripos( $cmb['id'], 'time' ) ){ |
|
299 | + } elseif (stripos($cmb['id'], 'time')) { |
|
300 | 300 | $value = TestContent::time(); |
301 | 301 | |
302 | 302 | // Otherwise, just a random text string |
303 | 303 | } else { |
304 | - $value = TestContent::title( rand( 10, 50 ) ); |
|
304 | + $value = TestContent::title(rand(10, 50)); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | break; |
@@ -332,14 +332,14 @@ discard block |
||
332 | 332 | |
333 | 333 | case 'text_date': |
334 | 334 | |
335 | - $value = TestContent::date( 'm/d/Y' ); |
|
335 | + $value = TestContent::date('m/d/Y'); |
|
336 | 336 | |
337 | 337 | break; |
338 | 338 | |
339 | 339 | case 'text_date_timestamp': |
340 | 340 | case 'text_datetime_timestamp': |
341 | 341 | |
342 | - $value = TestContent::date( 'U' ); |
|
342 | + $value = TestContent::date('U'); |
|
343 | 343 | |
344 | 344 | break; |
345 | 345 | |
@@ -347,13 +347,13 @@ discard block |
||
347 | 347 | |
348 | 348 | case 'text_money': |
349 | 349 | |
350 | - $value = rand( 0, 100000 ); |
|
350 | + $value = rand(0, 100000); |
|
351 | 351 | |
352 | 352 | break; |
353 | 353 | |
354 | 354 | case 'test_colorpicker': |
355 | 355 | |
356 | - $value = '#' . str_pad( dechex( mt_rand( 0, 0xFFFFFF ) ), 6, '0', STR_PAD_LEFT ); |
|
356 | + $value = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
357 | 357 | |
358 | 358 | break; |
359 | 359 | |
@@ -370,8 +370,8 @@ discard block |
||
370 | 370 | case 'radio': |
371 | 371 | |
372 | 372 | // Grab a random item out of the array and return the key |
373 | - $new_val = array_slice( $cmb['options'], rand( 0, count( $cmb['options'] ) ), 1 ); |
|
374 | - $value = key( $new_val ); |
|
373 | + $new_val = array_slice($cmb['options'], rand(0, count($cmb['options'])), 1); |
|
374 | + $value = key($new_val); |
|
375 | 375 | |
376 | 376 | break; |
377 | 377 | |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | case 'checkbox': |
383 | 383 | |
384 | 384 | // 50/50 odds of being turned on |
385 | - if ( rand( 0, 1 ) == 1 ){ |
|
385 | + if (rand(0, 1) == 1) { |
|
386 | 386 | $value = 'on'; |
387 | 387 | } |
388 | 388 | |
@@ -393,10 +393,10 @@ discard block |
||
393 | 393 | $new_option = array(); |
394 | 394 | |
395 | 395 | // Loop through each of our options |
396 | - foreach ( $cmb['options'] as $key => $value ){ |
|
396 | + foreach ($cmb['options'] as $key => $value) { |
|
397 | 397 | |
398 | 398 | // 50/50 chance of being included |
399 | - if ( rand( 0, 1 ) ){ |
|
399 | + if (rand(0, 1)) { |
|
400 | 400 | $new_option[] = $key; |
401 | 401 | } |
402 | 402 | |
@@ -414,8 +414,8 @@ discard block |
||
414 | 414 | |
415 | 415 | case 'file': |
416 | 416 | |
417 | - if ( true == $connected ){ |
|
418 | - $value = TestContent::image( $post_id ); |
|
417 | + if (true == $connected) { |
|
418 | + $value = TestContent::image($post_id); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | break; |
@@ -431,38 +431,38 @@ discard block |
||
431 | 431 | } |
432 | 432 | |
433 | 433 | // Value must exist to attempt to insert |
434 | - if ( ! empty( $value ) && ! is_wp_error( $value ) ){ |
|
434 | + if (!empty($value) && !is_wp_error($value)) { |
|
435 | 435 | |
436 | - $this->update_meta( $post_id, $value, $cmb ); |
|
436 | + $this->update_meta($post_id, $value, $cmb); |
|
437 | 437 | |
438 | 438 | // If we're dealing with a WP Error object, just return the message for debugging |
439 | - } elseif ( is_wp_error( $value ) ){ |
|
440 | - error_log( $value->get_error_message() ); |
|
439 | + } elseif (is_wp_error($value)) { |
|
440 | + error_log($value->get_error_message()); |
|
441 | 441 | return $value->get_error_message(); |
442 | 442 | } |
443 | 443 | |
444 | 444 | } // end random_metabox_content |
445 | 445 | |
446 | 446 | |
447 | - private function update_meta( $post_id, $value, $cmb ){ |
|
447 | + private function update_meta($post_id, $value, $cmb) { |
|
448 | 448 | |
449 | 449 | $type = $cmb['type']; |
450 | - $id = $cmb['id']; |
|
451 | - $value = apply_filters( "tc_{$type}_metabox", $value ); // Filter by metabox type |
|
452 | - $value = apply_filters( "tc_{$id}_metabox", $value ); // Filter by metabox ID |
|
450 | + $id = $cmb['id']; |
|
451 | + $value = apply_filters("tc_{$type}_metabox", $value); // Filter by metabox type |
|
452 | + $value = apply_filters("tc_{$id}_metabox", $value); // Filter by metabox ID |
|
453 | 453 | |
454 | 454 | // Files must be treated separately - they use the attachment ID |
455 | 455 | // & url of media for separate cmb values. |
456 | - if ( $cmb['type'] != 'file' ){ |
|
457 | - add_post_meta( $post_id, $cmb['id'], $value, true ); |
|
456 | + if ($cmb['type'] != 'file') { |
|
457 | + add_post_meta($post_id, $cmb['id'], $value, true); |
|
458 | 458 | } else { |
459 | - add_post_meta( $post_id, $cmb['id'].'_id', $value, true ); |
|
460 | - add_post_meta( $post_id, $cmb['id'], wp_get_attachment_url( $value ), true ); |
|
459 | + add_post_meta($post_id, $cmb['id'].'_id', $value, true); |
|
460 | + add_post_meta($post_id, $cmb['id'], wp_get_attachment_url($value), true); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | // Add extra, redundant meta. Because, why not have rows for the price of one? |
464 | - if ( $cmb['source'] === 'acf' ){ |
|
465 | - add_post_meta( $post_id, '_' . $cmb['id'], $cmb['key'], true ); |
|
464 | + if ($cmb['source'] === 'acf') { |
|
465 | + add_post_meta($post_id, '_'.$cmb['id'], $cmb['key'], true); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @subpackage Test Content |
11 | 11 | * @author Old Town Media |
12 | 12 | */ |
13 | -abstract class View{ |
|
13 | +abstract class View { |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * title |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @see tab, view |
46 | 46 | */ |
47 | - public function register_view(){ |
|
47 | + public function register_view() { |
|
48 | 48 | |
49 | - add_action( 'tc-admin-tabs', array( $this, 'tab' ), $this->priority ); |
|
50 | - add_action( 'tc-admin-sections', array( $this, 'view' ), $this->priority ); |
|
49 | + add_action('tc-admin-tabs', array($this, 'tab'), $this->priority); |
|
50 | + add_action('tc-admin-sections', array($this, 'view'), $this->priority); |
|
51 | 51 | |
52 | 52 | } |
53 | 53 | |
@@ -58,10 +58,10 @@ discard block |
||
58 | 58 | * Each view has a tab and tab navigation - this function compiles our |
59 | 59 | * navigation tab. Rarely extended. |
60 | 60 | */ |
61 | - public function tab(){ |
|
61 | + public function tab() { |
|
62 | 62 | $html = ""; |
63 | 63 | |
64 | - $html .= "<a class='nav-tab' data-type='".sanitize_title( $this->title )."' href='javascript:void(0)'>"; |
|
64 | + $html .= "<a class='nav-tab' data-type='".sanitize_title($this->title)."' href='javascript:void(0)'>"; |
|
65 | 65 | $html .= $this->title; |
66 | 66 | $html .= "</a>"; |
67 | 67 | |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @see actions_section, options_section |
80 | 80 | */ |
81 | - public function view(){ |
|
81 | + public function view() { |
|
82 | 82 | $html = ''; |
83 | 83 | |
84 | - $html .= "<section class='test-content-tab' data-type='".sanitize_title( $this->title )."'>"; |
|
84 | + $html .= "<section class='test-content-tab' data-type='".sanitize_title($this->title)."'>"; |
|
85 | 85 | $html .= $this->actions_section(); |
86 | 86 | $html .= $this->options_section(); |
87 | 87 | $html .= "</section>"; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * |
99 | 99 | * @return string HTML content. |
100 | 100 | */ |
101 | - protected function actions_section(){ |
|
101 | + protected function actions_section() { |
|
102 | 102 | $html = ''; |
103 | 103 | return $html; |
104 | 104 | } |
@@ -115,13 +115,13 @@ discard block |
||
115 | 115 | * @param string $html Existing HTML content. |
116 | 116 | * @return string HTML section content. |
117 | 117 | */ |
118 | - protected function options_section( $html = '' ){ |
|
118 | + protected function options_section($html = '') { |
|
119 | 119 | $html .= "<hr>"; |
120 | 120 | |
121 | 121 | $html .= "<div class='test-data-cpt'>"; |
122 | 122 | $html .= "<h3>"; |
123 | - $html .= "<span class='label'>".__( 'Quantity', 'otm-test-content' )."</span>"; |
|
124 | - $html .= "<input type='number' value='0' class='quantity-adjustment' for='".$this->type."' placeholder='".__( '', 'otm-test-content' )."'> "; |
|
123 | + $html .= "<span class='label'>".__('Quantity', 'otm-test-content')."</span>"; |
|
124 | + $html .= "<input type='number' value='0' class='quantity-adjustment' for='".$this->type."' placeholder='".__('', 'otm-test-content')."'> "; |
|
125 | 125 | $html .= "</h3>"; |
126 | 126 | $html .= "</div>"; |
127 | 127 | |
@@ -139,22 +139,22 @@ discard block |
||
139 | 139 | * @param string $text Text to display in the button. |
140 | 140 | * @return string HTML. |
141 | 141 | */ |
142 | - protected function build_button( $action, $slug, $text ){ |
|
142 | + protected function build_button($action, $slug, $text) { |
|
143 | 143 | $html = $dashicon = ''; |
144 | 144 | |
145 | - if ( $action == 'create' ){ |
|
145 | + if ($action == 'create') { |
|
146 | 146 | $dashicon = 'dashicons-plus'; |
147 | - } elseif ( $action == 'delete' ){ |
|
147 | + } elseif ($action == 'delete') { |
|
148 | 148 | $dashicon = 'dashicons-trash'; |
149 | 149 | } |
150 | 150 | |
151 | 151 | $html .= "<a href='javascript:void(0);' "; |
152 | - $html .= " data-type='" . $this->type . "'"; |
|
153 | - $html .= " data-slug='" . $slug . "'"; |
|
154 | - $html .= " data-todo='" . $action . "'"; |
|
152 | + $html .= " data-type='".$this->type."'"; |
|
153 | + $html .= " data-slug='".$slug."'"; |
|
154 | + $html .= " data-todo='".$action."'"; |
|
155 | 155 | $html .= " class='button-primary handle-test-data'"; |
156 | 156 | $html .= "/>"; |
157 | - $html .= "<span class='dashicons " . $dashicon . "'></span>"; |
|
157 | + $html .= "<span class='dashicons ".$dashicon."'></span>"; |
|
158 | 158 | $html .= $text; |
159 | 159 | $html .= "</a>"; |
160 | 160 |