@@ -133,14 +133,14 @@ |
||
133 | 133 | |
134 | 134 | // Query for our terms |
135 | 135 | $args = array( |
136 | - 'hide_empty' => false, |
|
137 | - 'meta_query' => array( |
|
138 | - array( |
|
139 | - 'key' => 'evans_test_content', |
|
140 | - 'value' => '__test__', |
|
141 | - 'compare' => '=' |
|
142 | - ) |
|
143 | - ) |
|
136 | + 'hide_empty' => false, |
|
137 | + 'meta_query' => array( |
|
138 | + array( |
|
139 | + 'key' => 'evans_test_content', |
|
140 | + 'value' => '__test__', |
|
141 | + 'compare' => '=' |
|
142 | + ) |
|
143 | + ) |
|
144 | 144 | ); |
145 | 145 | |
146 | 146 | $terms = get_terms( $slug, $args ); |
@@ -8,7 +8,7 @@ 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 test data posts. |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param string $slug a custom post type ID. |
25 | 25 | */ |
26 | - public function delete_posts( $slug, $echo = false ){ |
|
26 | + public function delete_posts($slug, $echo = false) { |
|
27 | 27 | |
28 | 28 | // Check that $cptslg has a string. |
29 | 29 | // Also make sure that the current user is logged in & has full permissions. |
30 | - if ( empty( $slug ) || !is_user_logged_in() || !current_user_can( 'delete_posts' ) ){ |
|
30 | + if (empty($slug) || !is_user_logged_in() || !current_user_can('delete_posts')) { |
|
31 | 31 | return; |
32 | 32 | } |
33 | 33 | |
@@ -44,39 +44,39 @@ discard block |
||
44 | 44 | ), |
45 | 45 | ); |
46 | 46 | |
47 | - $objects = new \WP_Query( $query ); |
|
47 | + $objects = new \WP_Query($query); |
|
48 | 48 | |
49 | - if ( $objects->have_posts() ){ |
|
49 | + if ($objects->have_posts()) { |
|
50 | 50 | |
51 | 51 | $events = array(); |
52 | 52 | |
53 | - while ( $objects->have_posts() ) : $objects->the_post(); |
|
53 | + while ($objects->have_posts()) : $objects->the_post(); |
|
54 | 54 | |
55 | 55 | // Find any media associated with the test post and delete it as well |
56 | - $this->delete_associated_media( get_the_id() ); |
|
56 | + $this->delete_associated_media(get_the_id()); |
|
57 | 57 | |
58 | - if ( $echo === true ){ |
|
58 | + if ($echo === true) { |
|
59 | 59 | $events[] = array( |
60 | 60 | 'type' => 'deleted', |
61 | 61 | 'pid' => get_the_id(), |
62 | - 'post_type' => get_post_type( get_the_id() ), |
|
62 | + 'post_type' => get_post_type(get_the_id()), |
|
63 | 63 | 'link' => '' |
64 | 64 | ); |
65 | 65 | } |
66 | 66 | |
67 | 67 | // Force delete the post |
68 | - wp_delete_post( get_the_id(), true ); |
|
68 | + wp_delete_post(get_the_id(), true); |
|
69 | 69 | |
70 | 70 | endwhile; |
71 | 71 | |
72 | - $obj = get_post_type_object( $slug ); |
|
72 | + $obj = get_post_type_object($slug); |
|
73 | 73 | |
74 | 74 | $events[] = array( |
75 | 75 | 'type' => 'general', |
76 | 76 | 'message' => 'Deleted ' . $obj->labels->all_items |
77 | 77 | ); |
78 | 78 | |
79 | - echo \json_encode( $events ); |
|
79 | + echo \json_encode($events); |
|
80 | 80 | |
81 | 81 | } |
82 | 82 | |
@@ -96,20 +96,20 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @param int $pid a custom post type ID. |
98 | 98 | */ |
99 | - private function delete_associated_media( $pid ){ |
|
99 | + private function delete_associated_media($pid) { |
|
100 | 100 | |
101 | - if ( !is_int( $pid ) ){ |
|
101 | + if (!is_int($pid)) { |
|
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
105 | 105 | // Get our images |
106 | - $media = get_attached_media( 'image', $pid ); |
|
106 | + $media = get_attached_media('image', $pid); |
|
107 | 107 | |
108 | - if ( !empty( $media ) ){ |
|
108 | + if (!empty($media)) { |
|
109 | 109 | |
110 | 110 | // Loop through the media & delete each one |
111 | - foreach ( $media as $attachment ){ |
|
112 | - wp_delete_attachment( $attachment->ID, true ); |
|
111 | + foreach ($media as $attachment) { |
|
112 | + wp_delete_attachment($attachment->ID, true); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @param string $slug a custom post type ID. |
131 | 131 | */ |
132 | - public function delete_terms( $slug, $echo = false ){ |
|
132 | + public function delete_terms($slug, $echo = false) { |
|
133 | 133 | |
134 | 134 | // Query for our terms |
135 | 135 | $args = array( |
@@ -143,15 +143,15 @@ discard block |
||
143 | 143 | ) |
144 | 144 | ); |
145 | 145 | |
146 | - $terms = get_terms( $slug, $args ); |
|
146 | + $terms = get_terms($slug, $args); |
|
147 | 147 | |
148 | - if ( !empty( $terms ) ){ |
|
148 | + if (!empty($terms)) { |
|
149 | 149 | |
150 | 150 | $events = array(); |
151 | 151 | |
152 | - foreach ( $terms as $term ){ |
|
152 | + foreach ($terms as $term) { |
|
153 | 153 | |
154 | - if ( $echo === true ){ |
|
154 | + if ($echo === true) { |
|
155 | 155 | $events[] = array( |
156 | 156 | 'type' => 'deleted', |
157 | 157 | 'pid' => $term->term_id, |
@@ -161,18 +161,18 @@ discard block |
||
161 | 161 | } |
162 | 162 | |
163 | 163 | // Delete our term |
164 | - wp_delete_term( $term->term_id, $slug ); |
|
164 | + wp_delete_term($term->term_id, $slug); |
|
165 | 165 | |
166 | 166 | } |
167 | 167 | |
168 | - $taxonomy = get_taxonomy( $slug ); |
|
168 | + $taxonomy = get_taxonomy($slug); |
|
169 | 169 | |
170 | 170 | $events[] = array( |
171 | 171 | 'type' => 'general', |
172 | 172 | 'message' => 'Deleted ' . $taxonomy->labels->name |
173 | 173 | ); |
174 | 174 | |
175 | - echo \json_encode( $events ); |
|
175 | + echo \json_encode($events); |
|
176 | 176 | |
177 | 177 | } |
178 | 178 |
@@ -89,8 +89,8 @@ |
||
89 | 89 | } else { |
90 | 90 | // We didn't get a reponse so print the notice out |
91 | 91 | echo '<div class="notice notice-error is-dismissible">'; |
92 | - 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>'; |
|
93 | - echo '</div>'; |
|
92 | + 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>'; |
|
93 | + echo '</div>'; |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | } |
@@ -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 | * Hooks function. |
@@ -17,13 +17,13 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @see admin_menu, wp_ajax actions |
19 | 19 | */ |
20 | - public function hooks( $file ){ |
|
20 | + public function hooks($file) { |
|
21 | 21 | |
22 | - add_action( 'admin_menu' , array( $this, 'add_menu_item' ) ); |
|
23 | - add_action( 'wp_ajax_handle_test_data', array( $this, 'handle_test_data_callback' ) ); |
|
24 | - add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts' ) ); |
|
25 | - add_filter( 'plugin_action_links_' . plugin_basename( $file ) , array( $this, 'add_settings_link' ) ); |
|
26 | - add_action( 'admin_notices', array( $this, 'internet_connected_admin_notice' ) ); |
|
22 | + add_action('admin_menu', array($this, 'add_menu_item')); |
|
23 | + add_action('wp_ajax_handle_test_data', array($this, 'handle_test_data_callback')); |
|
24 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts')); |
|
25 | + add_filter('plugin_action_links_' . plugin_basename($file), array($this, 'add_settings_link')); |
|
26 | + add_action('admin_notices', array($this, 'internet_connected_admin_notice')); |
|
27 | 27 | |
28 | 28 | } |
29 | 29 | |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | |
38 | 38 | add_submenu_page( |
39 | 39 | 'tools.php', |
40 | - __( 'Create Test Content', 'otm-test-content' ), |
|
41 | - __( 'Test Content', 'otm-test-content' ), |
|
40 | + __('Create Test Content', 'otm-test-content'), |
|
41 | + __('Test Content', 'otm-test-content'), |
|
42 | 42 | 'manage_options', |
43 | 43 | 'create-test-data', |
44 | - array( $this, 'admin_page' ) |
|
44 | + array($this, 'admin_page') |
|
45 | 45 | ); |
46 | 46 | |
47 | 47 | } |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | * @param array $links Existing links |
53 | 53 | * @return array Modified links |
54 | 54 | */ |
55 | - public function add_settings_link( $links ) { |
|
55 | + public function add_settings_link($links) { |
|
56 | 56 | |
57 | - $settings_link = '<a href="tools.php?page=create-test-data">' . __( 'Build Test Content', 'otm-test-content' ) . '</a>'; |
|
58 | - array_push( $links, $settings_link ); |
|
57 | + $settings_link = '<a href="tools.php?page=create-test-data">' . __('Build Test Content', 'otm-test-content') . '</a>'; |
|
58 | + array_push($links, $settings_link); |
|
59 | 59 | return $links; |
60 | 60 | |
61 | 61 | } |
@@ -68,28 +68,28 @@ discard block |
||
68 | 68 | * Internet, and the test fails displays a notice informing the user that |
69 | 69 | * images will not pull into test data. |
70 | 70 | */ |
71 | - public function internet_connected_admin_notice(){ |
|
71 | + public function internet_connected_admin_notice() { |
|
72 | 72 | |
73 | 73 | // Get the current admin screen & verify that we're on the right one |
74 | 74 | // before continuing. |
75 | 75 | $screen = get_current_screen(); |
76 | 76 | |
77 | - if ( $screen->base != 'tools_page_create-test-data' ){ |
|
77 | + if ($screen->base != 'tools_page_create-test-data') { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Define our test point and try to reach out to the URL |
82 | 82 | $test_url = 'http://www.splashbase.co/api/v1/images/'; |
83 | - $response = wp_remote_get( $test_url ); |
|
83 | + $response = wp_remote_get($test_url); |
|
84 | 84 | |
85 | 85 | // Check the response |
86 | - if ( is_array( $response ) ) { |
|
86 | + if (is_array($response)) { |
|
87 | 87 | // We got a response so early return |
88 | 88 | return; |
89 | 89 | } else { |
90 | 90 | // We didn't get a reponse so print the notice out |
91 | 91 | echo '<div class="notice notice-error is-dismissible">'; |
92 | - 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>'; |
|
92 | + 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>'; |
|
93 | 93 | echo '</div>'; |
94 | 94 | } |
95 | 95 | |
@@ -99,15 +99,15 @@ discard block |
||
99 | 99 | /** |
100 | 100 | * Load our script in the admin section and serve in data. |
101 | 101 | */ |
102 | - public function load_scripts(){ |
|
102 | + public function load_scripts() { |
|
103 | 103 | |
104 | - wp_enqueue_script( 'test-content-js', plugins_url( 'assets/admin.js' , dirname( __FILE__ ) ) ); |
|
104 | + wp_enqueue_script('test-content-js', plugins_url('assets/admin.js', dirname(__FILE__))); |
|
105 | 105 | |
106 | 106 | $data = array( |
107 | - 'nonce' => wp_create_nonce( 'handle-test-data' ) |
|
107 | + 'nonce' => wp_create_nonce('handle-test-data') |
|
108 | 108 | ); |
109 | 109 | |
110 | - wp_localize_script( 'test-content-js', 'test_content', $data ); |
|
110 | + wp_localize_script('test-content-js', 'test_content', $data); |
|
111 | 111 | |
112 | 112 | } |
113 | 113 | |
@@ -119,21 +119,21 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function handle_test_data_callback() { |
121 | 121 | |
122 | - $action = $_REQUEST['todo']; |
|
123 | - $nonce = $_REQUEST['nonce']; |
|
122 | + $action = $_REQUEST['todo']; |
|
123 | + $nonce = $_REQUEST['nonce']; |
|
124 | 124 | |
125 | 125 | // Verify that we have a proper logged in user and it's the right person |
126 | - if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'handle-test-data' ) ){ |
|
126 | + if (empty($nonce) || !wp_verify_nonce($nonce, 'handle-test-data')) { |
|
127 | 127 | return; |
128 | 128 | } |
129 | 129 | |
130 | - if ( $action == 'delete' ){ |
|
130 | + if ($action == 'delete') { |
|
131 | 131 | |
132 | - $this->deletion_routing( $_REQUEST ); |
|
132 | + $this->deletion_routing($_REQUEST); |
|
133 | 133 | |
134 | - } elseif ( $action == 'create' ){ |
|
134 | + } elseif ($action == 'create') { |
|
135 | 135 | |
136 | - $this->creation_routing( $_REQUEST ); |
|
136 | + $this->creation_routing($_REQUEST); |
|
137 | 137 | |
138 | 138 | } |
139 | 139 | |
@@ -146,17 +146,17 @@ discard block |
||
146 | 146 | * Choose which type of creation needs to be accomplished and route through |
147 | 147 | * the correct class. |
148 | 148 | */ |
149 | - private function creation_routing( $data ){ |
|
149 | + private function creation_routing($data) { |
|
150 | 150 | |
151 | - if ( $data['type'] == 'post' ){ |
|
151 | + if ($data['type'] == 'post') { |
|
152 | 152 | |
153 | 153 | $create_content = new CreatePost; |
154 | - $create_content->create_post_type_content( $data['slug'], true, 1 ); |
|
154 | + $create_content->create_post_type_content($data['slug'], true, 1); |
|
155 | 155 | |
156 | - } elseif( $data['type'] == 'term' ){ |
|
156 | + } elseif ($data['type'] == 'term') { |
|
157 | 157 | |
158 | 158 | $create_content = new CreateTerm; |
159 | - $create_content->create_terms( $data['slug'], true, 1 ); |
|
159 | + $create_content->create_terms($data['slug'], true, 1); |
|
160 | 160 | |
161 | 161 | } |
162 | 162 | |
@@ -167,17 +167,17 @@ discard block |
||
167 | 167 | * Choose which type of deletion needs to be accomplished and route through |
168 | 168 | * the correct method of Delete. |
169 | 169 | */ |
170 | - private function deletion_routing( $data ){ |
|
170 | + private function deletion_routing($data) { |
|
171 | 171 | |
172 | 172 | $delete_content = new Delete; |
173 | 173 | |
174 | - if ( $data['type'] == 'post' ){ |
|
174 | + if ($data['type'] == 'post') { |
|
175 | 175 | |
176 | - $delete_content->delete_posts( $data['slug'], true ); |
|
176 | + $delete_content->delete_posts($data['slug'], true); |
|
177 | 177 | |
178 | - } elseif ( $data['type'] == 'term' ){ |
|
178 | + } elseif ($data['type'] == 'term') { |
|
179 | 179 | |
180 | - $delete_content->delete_terms( $data['slug'], true ); |
|
180 | + $delete_content->delete_terms($data['slug'], true); |
|
181 | 181 | |
182 | 182 | } |
183 | 183 | |
@@ -187,16 +187,16 @@ discard block |
||
187 | 187 | /** |
188 | 188 | * Print out our admin page to control test data. |
189 | 189 | */ |
190 | - public function admin_page(){ |
|
190 | + public function admin_page() { |
|
191 | 191 | |
192 | 192 | $html = ""; |
193 | 193 | |
194 | 194 | $html .= '<div class="wrap" id="options_editor">' . "\n"; |
195 | 195 | |
196 | - $html .= '<h2>' . __( 'Create Test Data' , 'otm-test-content' ) . '</h2>' . "\n"; |
|
196 | + $html .= '<h2>' . __('Create Test Data', 'otm-test-content') . '</h2>' . "\n"; |
|
197 | 197 | |
198 | 198 | // Loop through all other cpts |
199 | - $post_types = get_post_types( array( 'public' => true ), 'objects' ); |
|
199 | + $post_types = get_post_types(array('public' => true), 'objects'); |
|
200 | 200 | |
201 | 201 | $html .= "<div>"; |
202 | 202 | |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | $html .= "</div>"; |
209 | 209 | |
210 | 210 | // Loop through every post type available on the site |
211 | - foreach ( $post_types as $post_type ) { |
|
211 | + foreach ($post_types as $post_type) { |
|
212 | 212 | |
213 | 213 | $skipped_cpts = array( |
214 | 214 | 'attachment' |
215 | 215 | ); |
216 | 216 | |
217 | 217 | // Skip banned cpts |
218 | - if ( in_array( $post_type->name, $skipped_cpts ) ){ |
|
218 | + if (in_array($post_type->name, $skipped_cpts)) { |
|
219 | 219 | continue; |
220 | 220 | } |
221 | 221 | |
@@ -225,17 +225,17 @@ discard block |
||
225 | 225 | $html .= "<h3>"; |
226 | 226 | |
227 | 227 | $html .= "<span style='width: 20%; display: inline-block;'>" . $post_type->labels->name . "</span>"; |
228 | - $html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus' style='margin-top: 6px; font-size: 1.2em'></span> ".__( 'Create Test Data', 'otm-test-content' )."</a>"; |
|
229 | - $html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash' style='margin-top: 4px; font-size: 1.2em'></span> ".__( 'Delete Test Data', 'otm-test-content' )."</a>"; |
|
228 | + $html .= " <a href='javascript:void(0);' data-type='post' data-slug='" . $post_type->name . "' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus' style='margin-top: 6px; font-size: 1.2em'></span> " . __('Create Test Data', 'otm-test-content') . "</a>"; |
|
229 | + $html .= " <a href='javascript:void(0);' data-type='post' data-slug='" . $post_type->name . "' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash' style='margin-top: 4px; font-size: 1.2em'></span> " . __('Delete Test Data', 'otm-test-content') . "</a>"; |
|
230 | 230 | |
231 | 231 | $html .= "</h3>"; |
232 | 232 | |
233 | 233 | // Create row for each taxonomy associated with the post/page/cpt |
234 | - $taxonomies = get_object_taxonomies( $post_type->name ); |
|
234 | + $taxonomies = get_object_taxonomies($post_type->name); |
|
235 | 235 | |
236 | - if ( !empty( $taxonomies ) ){ |
|
236 | + if (!empty($taxonomies)) { |
|
237 | 237 | |
238 | - foreach( $taxonomies as $tax ){ |
|
238 | + foreach ($taxonomies as $tax) { |
|
239 | 239 | |
240 | 240 | $html .= "<h3>"; |
241 | 241 | |
@@ -244,17 +244,17 @@ discard block |
||
244 | 244 | ); |
245 | 245 | |
246 | 246 | // Skip banned taxonomies |
247 | - if ( in_array( $tax, $skipped_taxonomies ) ){ |
|
247 | + if (in_array($tax, $skipped_taxonomies)) { |
|
248 | 248 | continue; |
249 | 249 | } |
250 | 250 | |
251 | - $taxonomy = get_taxonomy( $tax ); |
|
251 | + $taxonomy = get_taxonomy($tax); |
|
252 | 252 | |
253 | - $html .= "<span style='width: 20%; display: inline-block; font-size: .9em'> ".$taxonomy->labels->name."</span>"; |
|
253 | + $html .= "<span style='width: 20%; display: inline-block; font-size: .9em'> " . $taxonomy->labels->name . "</span>"; |
|
254 | 254 | |
255 | - $html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-category' style='margin-top: 4px; font-size: 1.2em'></span> ".__( 'Create', 'otm-test-content' )." ".$taxonomy->labels->name."</a>"; |
|
255 | + $html .= " <a href='javascript:void(0);' data-type='term' data-slug='" . $tax . "' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-category' style='margin-top: 4px; font-size: 1.2em'></span> " . __('Create', 'otm-test-content') . " " . $taxonomy->labels->name . "</a>"; |
|
256 | 256 | |
257 | - $html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash' style='margin-top: 4px; font-size: 1.2em'></span> ".__( 'Delete', 'otm-test-content' )." ".$taxonomy->labels->name."</a>"; |
|
257 | + $html .= " <a href='javascript:void(0);' data-type='term' data-slug='" . $tax . "' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash' style='margin-top: 4px; font-size: 1.2em'></span> " . __('Delete', 'otm-test-content') . " " . $taxonomy->labels->name . "</a>"; |
|
258 | 258 | |
259 | 259 | $html .= "</h3>"; |
260 | 260 |