Regions for WP Job Manager - Version 1.1

Version Description

Download this release

Release Info

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

Version 1.1

Files changed (3) hide show
  1. astoundify-job-manager-locations.php +268 -0
  2. readme.txt +35 -0
  3. widgets.php +66 -0
astoundify-job-manager-locations.php ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: Predefined Regions for WP Job Manager
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.1
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
+ if ( ! post_type_exists( 'job_listing' ) )
87
+ return;
88
+
89
+ $admin_capability = 'manage_job_listings';
90
+
91
+ $singular = __( 'Job Region', 'ajmr' );
92
+ $plural = __( 'Job Regions', 'ajmr' );
93
+
94
+ if ( current_theme_supports( 'job-manager-templates' ) ) {
95
+ $rewrite = array(
96
+ 'slug' => _x( 'job-region', 'Job region slug - resave permalinks after changing this', 'ajmr' ),
97
+ 'with_front' => false,
98
+ 'hierarchical' => false
99
+ );
100
+ } else {
101
+ $rewrite = false;
102
+ }
103
+
104
+ register_taxonomy( 'job_listing_region',
105
+ array( 'job_listing' ),
106
+ array(
107
+ 'hierarchical' => true,
108
+ 'update_count_callback' => '_update_post_term_count',
109
+ 'label' => $plural,
110
+ 'labels' => array(
111
+ 'name' => $plural,
112
+ 'singular_name' => $singular,
113
+ 'search_items' => sprintf( __( 'Search %s', 'ajmr' ), $plural ),
114
+ 'all_items' => sprintf( __( 'All %s', 'ajmr' ), $plural ),
115
+ 'parent_item' => sprintf( __( 'Parent %s', 'ajmr' ), $singular ),
116
+ 'parent_item_colon' => sprintf( __( 'Parent %s:', 'ajmr' ), $singular ),
117
+ 'edit_item' => sprintf( __( 'Edit %s', 'ajmr' ), $singular ),
118
+ 'update_item' => sprintf( __( 'Update %s', 'ajmr' ), $singular ),
119
+ 'add_new_item' => sprintf( __( 'Add New %s', 'ajmr' ), $singular ),
120
+ 'new_item_name' => sprintf( __( 'New %s Name', 'ajmr' ), $singular )
121
+ ),
122
+ 'show_ui' => true,
123
+ 'query_var' => true,
124
+ 'has_archive' => true,
125
+ 'capabilities' => array(
126
+ 'manage_terms' => $admin_capability,
127
+ 'edit_terms' => $admin_capability,
128
+ 'delete_terms' => $admin_capability,
129
+ 'assign_terms' => $admin_capability,
130
+ ),
131
+ 'rewrite' => $rewrite,
132
+ )
133
+ );
134
+ }
135
+
136
+ /**
137
+ * Add the field to the submission form.
138
+ *
139
+ * @since 1.0
140
+ */
141
+ function form_fields( $fields ) {
142
+ $fields[ 'job' ][ 'job_region' ] = array(
143
+ 'label' => __( 'Job Region', 'job_manager' ),
144
+ 'type' => 'select',
145
+ 'options' => ajmr_get_regions_simple(),
146
+ 'required' => true,
147
+ 'priority' => 3
148
+ );
149
+
150
+ return $fields;
151
+ }
152
+
153
+ /**
154
+ * When the form is submitted, update the data.
155
+ *
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 );
163
+ }
164
+
165
+ /**
166
+ * On a singular job page, append the region to the location.
167
+ *
168
+ * @since 1.0
169
+ */
170
+ function the_job_location( $job_location, $post ) {
171
+ if ( ! is_singular( 'job_listing' ) )
172
+ return $job_location;
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];
180
+ $locname = $location->name;
181
+
182
+ $job_location = sprintf( '%s &mdash; <a href="%s">%s</a>', $job_location, get_term_link( $location, 'job_listing_region' ), $locname );
183
+
184
+ return apply_filters( 'ajmr_job_location', $job_location, $location );
185
+ }
186
+
187
+ /**
188
+ * Loads the plugin language files
189
+ *
190
+ * @since 1.0
191
+ */
192
+ public function load_textdomain() {
193
+ // Traditional WordPress plugin locale filter
194
+ $locale = apply_filters( 'plugin_locale', get_locale(), $this->domain );
195
+ $mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
196
+
197
+ // Setup paths to current locale file
198
+ $mofile_local = $this->lang_dir . $mofile;
199
+ $mofile_global = WP_LANG_DIR . '/' . $this->domain . '/' . $mofile;
200
+
201
+ // Look in global /wp-content/languages/ajmr folder
202
+ if ( file_exists( $mofile_global ) ) {
203
+ return load_textdomain( $this->domain, $mofile_global );
204
+
205
+ // Look in local /wp-content/plugins/ajmr/languages/ folder
206
+ } elseif ( file_exists( $mofile_local ) ) {
207
+ return load_textdomain( $this->domain, $mofile_local );
208
+ }
209
+
210
+ return false;
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Start things up.
216
+ *
217
+ * Use this function instead of a global.
218
+ *
219
+ * $ajmr = ajmr();
220
+ *
221
+ * @since 1.0
222
+ */
223
+ function ajmr() {
224
+ return Astoundify_Job_Manager_Regions::instance();
225
+ }
226
+
227
+ ajmr();
228
+
229
+ /**
230
+ * Get regions (terms) helper.
231
+ *
232
+ * @since 1.0
233
+ */
234
+ function ajmr_get_regions() {
235
+ $locations = get_terms( 'job_listing_region', apply_filters( 'ajmr_get_region_args', array( 'hide_empty' => 0 ) ) );
236
+
237
+ return $locations;
238
+ }
239
+
240
+ /**
241
+ * Create a key => value pair of term ID and term name.
242
+ *
243
+ * @since 1.0
244
+ */
245
+ function ajmr_get_regions_simple() {
246
+ $locations = ajmr_get_regions();
247
+ $simple = array();
248
+
249
+ foreach ( $locations as $location ) {
250
+ $simple[ $location->slug ] = $location->name;
251
+ }
252
+
253
+ return apply_filters( 'ajmr_get_regions_simple', $simple );
254
+ }
255
+
256
+ /**
257
+ * Custom widgets
258
+ *
259
+ * @since 1.1
260
+ */
261
+ function ajmr_widgets_init() {
262
+ $ajmr = ajmr();
263
+
264
+ include_once( $ajmr->plugin_dir . '/widgets.php' );
265
+
266
+ register_widget( 'Astoundify_Job_Manager_Regions_Widget' );
267
+ }
268
+ add_action( 'after_setup_theme', 'ajmr_widgets_init', 11 );
readme.txt ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Predefined Regions for WP Job Manager ===
2
+
3
+ Author URI: http://astoundify.com
4
+ Plugin URI: http://astoundify.com
5
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=contact@appthemer.com&item_name=Donation+for+Astoundify WP Job Manager Regions
6
+ 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
+
14
+ Add predefined regions to WP Job Manager submission form.
15
+
16
+ == Description ==
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
23
+ 2. Go to "Job Listings > Job Regions" and add regions.
24
+
25
+ == Frequently Asked Questions ==
26
+
27
+ == Changelog ==
28
+
29
+ = 1.1: July 27, 2013 =
30
+
31
+ * New: Simple regions list output.
32
+
33
+ = 1.0: July 26, 2013 =
34
+
35
+ * First official release!
widgets.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Widgets
4
+ */
5
+
6
+ // Exit if accessed directly
7
+ if ( ! defined( 'ABSPATH' ) ) exit;
8
+
9
+ /**
10
+ * Simple list
11
+ */
12
+ class Astoundify_Job_Manager_Regions_Widget extends Jobify_Widget {
13
+ /**
14
+ * Constructor
15
+ */
16
+ public function __construct() {
17
+ $this->widget_cssclass = 'ajmr_widget_regions';
18
+ $this->widget_description = __( 'Display a list of job regions.', 'ajmr' );
19
+ $this->widget_id = 'ajmr_widget_regions';
20
+ $this->widget_name = __( 'Job Regions', 'ajmr' );
21
+ $this->settings = array(
22
+ 'title' => array(
23
+ 'type' => 'text',
24
+ 'std' => 'Job Regions',
25
+ 'label' => __( 'Title:', 'ajmr' )
26
+ )
27
+ );
28
+ parent::__construct();
29
+ }
30
+
31
+ /**
32
+ * widget function.
33
+ *
34
+ * @see WP_Widget
35
+ * @access public
36
+ * @param array $args
37
+ * @param array $instance
38
+ * @return void
39
+ */
40
+ function widget( $args, $instance ) {
41
+ if ( $this->get_cached_widget( $args ) )
42
+ return;
43
+
44
+ ob_start();
45
+
46
+ extract( $args );
47
+
48
+ echo $before_widget;
49
+
50
+ if ( $instance[ 'title' ] ) echo $before_title . $instance[ 'title' ] . $after_title;
51
+
52
+ wp_list_categories( array(
53
+ 'title_li' => '',
54
+ 'taxonomy' => 'job_listing_region',
55
+ 'hide_empty' => 0
56
+ ) );
57
+
58
+ echo $after_widget;
59
+
60
+ $content = ob_get_clean();
61
+
62
+ echo $content;
63
+
64
+ $this->cache_widget( $args, $content );
65
+ }
66
+ }