Regions for WP Job Manager - Version 1.2

Version Description

Download this release

Release Info

Developer adampickering
Plugin Icon wp plugin Regions for WP Job Manager
Version 1.2
Comparing to
See all releases

Code changes from version 1.1 to 1.2

astoundify-job-manager-locations.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Create predefined regions that job submissions can associate themselves with.
6
  * Author: Astoundify
7
  * Author URI: http://astoundify.com
8
- * Version: 1.1
9
  * Text Domain: ajmr
10
  */
11
 
@@ -83,9 +83,6 @@ class Astoundify_Job_Manager_Regions {
83
  * @since 1.0
84
  */
85
  public function register_post_taxonomy() {
86
- if ( ! post_type_exists( 'job_listing' ) )
87
- return;
88
-
89
  $admin_capability = 'manage_job_listings';
90
 
91
  $singular = __( 'Job Region', 'ajmr' );
@@ -156,7 +153,11 @@ class Astoundify_Job_Manager_Regions {
156
  * @since 1.0
157
  */
158
  function update_job_data( $job_id, $values ) {
159
- $region = $values[ 'job' ][ 'job_region' ];
 
 
 
 
160
  $term = get_term_by( 'slug', $region, 'job_listing_region' );
161
 
162
  wp_set_post_terms( $job_id, array( $term->term_id ), 'job_listing_region', false );
@@ -173,7 +174,7 @@ class Astoundify_Job_Manager_Regions {
173
 
174
  $terms = wp_get_post_terms( $post->ID, 'job_listing_region' );
175
 
176
- if ( is_wp_error( $terms ) )
177
  return $job_location;
178
 
179
  $location = $terms[0];
5
  * Description: Create predefined regions that job submissions can associate themselves with.
6
  * Author: Astoundify
7
  * Author URI: http://astoundify.com
8
+ * Version: 1.2
9
  * Text Domain: ajmr
10
  */
11
 
83
  * @since 1.0
84
  */
85
  public function register_post_taxonomy() {
 
 
 
86
  $admin_capability = 'manage_job_listings';
87
 
88
  $singular = __( 'Job Region', 'ajmr' );
153
  * @since 1.0
154
  */
155
  function update_job_data( $job_id, $values ) {
156
+ $region = isset ( $values[ 'job' ][ 'job_region' ] ) ? $values[ 'job' ][ 'job_region' ] : null;
157
+
158
+ if ( ! $revion )
159
+ return;
160
+
161
  $term = get_term_by( 'slug', $region, 'job_listing_region' );
162
 
163
  wp_set_post_terms( $job_id, array( $term->term_id ), 'job_listing_region', false );
174
 
175
  $terms = wp_get_post_terms( $post->ID, 'job_listing_region' );
176
 
177
+ if ( is_wp_error( $terms ) || empty( $terms ) )
178
  return $job_location;
179
 
180
  $location = $terms[0];
readme.txt CHANGED
@@ -7,7 +7,7 @@ Contributors: SpencerFinnell
7
  Tags: job, job listing, job region
8
  Requires at least: 3.5
9
  Tested up to: 3.5
10
- Stable Tag: 1.0
11
  License: GPLv3
12
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
13
 
@@ -17,6 +17,10 @@ Add predefined regions to WP Job Manager submission form.
17
 
18
  Adds a "Job Region" taxonomy so the site administrator can control a set of predefined regions listings can be assigned to.
19
 
 
 
 
 
20
  == Installation ==
21
 
22
  1. Install and Activate
@@ -26,6 +30,11 @@ Adds a "Job Region" taxonomy so the site administrator can control a set of pred
26
 
27
  == Changelog ==
28
 
 
 
 
 
 
29
  = 1.1: July 27, 2013 =
30
 
31
  * New: Simple regions list output.
7
  Tags: job, job listing, job region
8
  Requires at least: 3.5
9
  Tested up to: 3.5
10
+ Stable Tag: 1.2
11
  License: GPLv3
12
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
13
 
17
 
18
  Adds a "Job Region" taxonomy so the site administrator can control a set of predefined regions listings can be assigned to.
19
 
20
+ = Where can I use this? =
21
+
22
+ Astoundify has released the first fully integrated WP Job Manager theme. Check out ["Jobify"](http://themeforest.net/item/jobify-job-board-wordpress-theme/5247604?ref=Astoundify)
23
+
24
  == Installation ==
25
 
26
  1. Install and Activate
30
 
31
  == Changelog ==
32
 
33
+ = 1.2: July 28, 2013 =
34
+
35
+ * Fix: Make sure the taxononmy is properly added.
36
+ * Fix: Don't error if the plugin is activated, but no term is added via the backend
37
+
38
  = 1.1: July 27, 2013 =
39
 
40
  * New: Simple regions list output.
widgets.php CHANGED
@@ -6,6 +6,7 @@
6
  // Exit if accessed directly
7
  if ( ! defined( 'ABSPATH' ) ) exit;
8
 
 
9
  /**
10
  * Simple list
11
  */
@@ -63,4 +64,5 @@ class Astoundify_Job_Manager_Regions_Widget extends Jobify_Widget {
63
 
64
  $this->cache_widget( $args, $content );
65
  }
66
- }
 
6
  // Exit if accessed directly
7
  if ( ! defined( 'ABSPATH' ) ) exit;
8
 
9
+ if ( class_exists( 'Jobify_Widget' ) ) :
10
  /**
11
  * Simple list
12
  */
64
 
65
  $this->cache_widget( $args, $content );
66
  }
67
+ }
68
+ endif;
wp-job-manager-locations.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: WP Job Manager - Predefined Regions
4
+ * Plugin URI: https://github.com/astoundify/wp-job-manager-colors
5
+ * Description: Create predefined regions that job submissions can associate themselves with.
6
+ * Author: Astoundify
7
+ * Author URI: http://astoundify.com
8
+ * Version: 1.2
9
+ * Text Domain: ajmr
10
+ */
11
+
12
+ // Exit if accessed directly
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ class Astoundify_Job_Manager_Regions {
16
+
17
+ /**
18
+ * @var $instance
19
+ */
20
+ private static $instance;
21
+
22
+ /**
23
+ * Make sure only one instance is only running.
24
+ */
25
+ public static function instance() {
26
+ if ( ! isset ( self::$instance ) ) {
27
+ self::$instance = new self;
28
+ }
29
+
30
+ return self::$instance;
31
+ }
32
+
33
+ /**
34
+ * Start things up.
35
+ *
36
+ * @since 1.0
37
+ */
38
+ public function __construct() {
39
+ $this->setup_globals();
40
+ $this->setup_actions();
41
+ }
42
+
43
+ /**
44
+ * Set some smart defaults to class variables. Allow some of them to be
45
+ * filtered to allow for early overriding.
46
+ *
47
+ * @since 1.0
48
+ *
49
+ * @return void
50
+ */
51
+ private function setup_globals() {
52
+ $this->file = __FILE__;
53
+
54
+ $this->basename = apply_filters( 'ajmr_plugin_basenname', plugin_basename( $this->file ) );
55
+ $this->plugin_dir = apply_filters( 'ajmr_plugin_dir_path', plugin_dir_path( $this->file ) );
56
+ $this->plugin_url = apply_filters( 'ajmr_plugin_dir_url', plugin_dir_url ( $this->file ) );
57
+
58
+ $this->lang_dir = apply_filters( 'ajmr_lang_dir', trailingslashit( $this->plugin_dir . 'languages' ) );
59
+
60
+ $this->domain = 'ajmr';
61
+ }
62
+
63
+ /**
64
+ * Setup the default hooks and actions
65
+ *
66
+ * @since 1.0
67
+ *
68
+ * @return void
69
+ */
70
+ private function setup_actions() {
71
+ add_action( 'init', array( $this, 'register_post_taxonomy' ) );
72
+ add_filter( 'submit_job_form_fields', array( $this, 'form_fields' ) );
73
+ add_action( 'job_manager_update_job_data', array( $this, 'update_job_data' ), 10, 2 );
74
+
75
+ add_filter( 'the_job_location', array( $this, 'the_job_location' ), 10, 2 );
76
+
77
+ $this->load_textdomain();
78
+ }
79
+
80
+ /**
81
+ * Create the `job_listing_region` taxonomy.
82
+ *
83
+ * @since 1.0
84
+ */
85
+ public function register_post_taxonomy() {
86
+ $admin_capability = 'manage_job_listings';
87
+
88
+ $singular = __( 'Job Region', 'ajmr' );
89
+ $plural = __( 'Job Regions', 'ajmr' );
90
+
91
+ if ( current_theme_supports( 'job-manager-templates' ) ) {
92
+ $rewrite = array(
93
+ 'slug' => _x( 'job-region', 'Job region slug - resave permalinks after changing this', 'ajmr' ),
94
+ 'with_front' => false,
95
+ 'hierarchical' => false
96
+ );
97
+ } else {
98
+ $rewrite = false;
99
+ }
100
+
101
+ register_taxonomy( 'job_listing_region',
102
+ array( 'job_listing' ),
103
+ array(
104
+ 'hierarchical' => true,
105
+ 'update_count_callback' => '_update_post_term_count',
106
+ 'label' => $plural,
107
+ 'labels' => array(
108
+ 'name' => $plural,
109
+ 'singular_name' => $singular,
110
+ 'search_items' => sprintf( __( 'Search %s', 'ajmr' ), $plural ),
111
+ 'all_items' => sprintf( __( 'All %s', 'ajmr' ), $plural ),
112
+ 'parent_item' => sprintf( __( 'Parent %s', 'ajmr' ), $singular ),
113
+ 'parent_item_colon' => sprintf( __( 'Parent %s:', 'ajmr' ), $singular ),
114
+ 'edit_item' => sprintf( __( 'Edit %s', 'ajmr' ), $singular ),
115
+ 'update_item' => sprintf( __( 'Update %s', 'ajmr' ), $singular ),
116
+ 'add_new_item' => sprintf( __( 'Add New %s', 'ajmr' ), $singular ),
117
+ 'new_item_name' => sprintf( __( 'New %s Name', 'ajmr' ), $singular )
118
+ ),
119
+ 'show_ui' => true,
120
+ 'query_var' => true,
121
+ 'has_archive' => true,
122
+ 'capabilities' => array(
123
+ 'manage_terms' => $admin_capability,
124
+ 'edit_terms' => $admin_capability,
125
+ 'delete_terms' => $admin_capability,
126
+ 'assign_terms' => $admin_capability,
127
+ ),
128
+ 'rewrite' => $rewrite,
129
+ )
130
+ );
131
+ }
132
+
133
+ /**
134
+ * Add the field to the submission form.
135
+ *
136
+ * @since 1.0
137
+ */
138
+ function form_fields( $fields ) {
139
+ $fields[ 'job' ][ 'job_region' ] = array(
140
+ 'label' => __( 'Job Region', 'job_manager' ),
141
+ 'type' => 'select',
142
+ 'options' => ajmr_get_regions_simple(),
143
+ 'required' => true,
144
+ 'priority' => 3
145
+ );
146
+
147
+ return $fields;
148
+ }
149
+
150
+ /**
151
+ * When the form is submitted, update the data.
152
+ *
153
+ * @since 1.0
154
+ */
155
+ function update_job_data( $job_id, $values ) {
156
+ $region = isset ( $values[ 'job' ][ 'job_region' ] ) ? $values[ 'job' ][ 'job_region' ] : null;
157
+
158
+ if ( ! $revion )
159
+ return;
160
+
161
+ $term = get_term_by( 'slug', $region, 'job_listing_region' );
162
+
163
+ wp_set_post_terms( $job_id, array( $term->term_id ), 'job_listing_region', false );
164
+ }
165
+
166
+ /**
167
+ * On a singular job page, append the region to the location.
168
+ *
169
+ * @since 1.0
170
+ */
171
+ function the_job_location( $job_location, $post ) {
172
+ if ( ! is_singular( 'job_listing' ) )
173
+ return $job_location;
174
+
175
+ $terms = wp_get_post_terms( $post->ID, 'job_listing_region' );
176
+
177
+ if ( is_wp_error( $terms ) || empty( $terms ) )
178
+ return $job_location;
179
+
180
+ $location = $terms[0];
181
+ $locname = $location->name;
182
+
183
+ $job_location = sprintf( '%s &mdash; <a href="%s">%s</a>', $job_location, get_term_link( $location, 'job_listing_region' ), $locname );
184
+
185
+ return apply_filters( 'ajmr_job_location', $job_location, $location );
186
+ }
187
+
188
+ /**
189
+ * Loads the plugin language files
190
+ *
191
+ * @since 1.0
192
+ */
193
+ public function load_textdomain() {
194
+ // Traditional WordPress plugin locale filter
195
+ $locale = apply_filters( 'plugin_locale', get_locale(), $this->domain );
196
+ $mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
197
+
198
+ // Setup paths to current locale file
199
+ $mofile_local = $this->lang_dir . $mofile;
200
+ $mofile_global = WP_LANG_DIR . '/' . $this->domain . '/' . $mofile;
201
+
202
+ // Look in global /wp-content/languages/ajmr folder
203
+ if ( file_exists( $mofile_global ) ) {
204
+ return load_textdomain( $this->domain, $mofile_global );
205
+
206
+ // Look in local /wp-content/plugins/ajmr/languages/ folder
207
+ } elseif ( file_exists( $mofile_local ) ) {
208
+ return load_textdomain( $this->domain, $mofile_local );
209
+ }
210
+
211
+ return false;
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Start things up.
217
+ *
218
+ * Use this function instead of a global.
219
+ *
220
+ * $ajmr = ajmr();
221
+ *
222
+ * @since 1.0
223
+ */
224
+ function ajmr() {
225
+ return Astoundify_Job_Manager_Regions::instance();
226
+ }
227
+
228
+ ajmr();
229
+
230
+ /**
231
+ * Get regions (terms) helper.
232
+ *
233
+ * @since 1.0
234
+ */
235
+ function ajmr_get_regions() {
236
+ $locations = get_terms( 'job_listing_region', apply_filters( 'ajmr_get_region_args', array( 'hide_empty' => 0 ) ) );
237
+
238
+ return $locations;
239
+ }
240
+
241
+ /**
242
+ * Create a key => value pair of term ID and term name.
243
+ *
244
+ * @since 1.0
245
+ */
246
+ function ajmr_get_regions_simple() {
247
+ $locations = ajmr_get_regions();
248
+ $simple = array();
249
+
250
+ foreach ( $locations as $location ) {
251
+ $simple[ $location->slug ] = $location->name;
252
+ }
253
+
254
+ return apply_filters( 'ajmr_get_regions_simple', $simple );
255
+ }
256
+
257
+ /**
258
+ * Custom widgets
259
+ *
260
+ * @since 1.1
261
+ */
262
+ function ajmr_widgets_init() {
263
+ $ajmr = ajmr();
264
+
265
+ include_once( $ajmr->plugin_dir . '/widgets.php' );
266
+
267
+ register_widget( 'Astoundify_Job_Manager_Regions_Widget' );
268
+ }
269
+ add_action( 'after_setup_theme', 'ajmr_widgets_init', 11 );