Regions for WP Job Manager - Version 1.5.0

Version Description

Download this release

Release Info

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

Code changes from version 1.3.1 to 1.5.0

assets/js/main.js ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($) {
2
+ 'use strict';
3
+
4
+ var jobRegions = {
5
+ cache: {
6
+ $document: $(document),
7
+ $window: $(window),
8
+ $search_jobs: $( '.search_jobs, .job_search_form' )
9
+ },
10
+
11
+ init: function() {
12
+ this.cacheElements();
13
+ this.bindEvents();
14
+ },
15
+
16
+ cacheElements: function() {
17
+ this.cache.$location = this.cache.$search_jobs.find( '.search_location' );
18
+ this.cache.$regions = this.cache.$search_jobs.find( '.search_region' ).first();
19
+ },
20
+
21
+ bindEvents: function() {
22
+ var self = this;
23
+
24
+ this.cache.$document.on( 'ready', function() {
25
+ self.addRegions();
26
+ self.updateResults();
27
+ self.resetResults();
28
+ });
29
+ },
30
+
31
+ addRegions: function() {
32
+ this.cache.$location.html( '' );
33
+ this.cache.$regions.detach().appendTo( this.cache.$location );
34
+ },
35
+
36
+ updateResults: function() {
37
+ this.cache.$regions.change(function() {
38
+ var target = jQuery(this).closest( 'div.job_listings' );
39
+
40
+ target.trigger( 'update_results', [ 1, false ] );
41
+ });
42
+ },
43
+
44
+ resetResults: function() {
45
+ var self = this;
46
+
47
+ $( '.job_listings' ).on( 'reset', function() {
48
+ self.cache.$regions.val(0).trigger( 'change' );
49
+ });
50
+ }
51
+ };
52
+
53
+ jobRegions.init();
54
+
55
+ })(jQuery);
includes/class-taxonomy.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Astoundify_Job_Manager_Regions_Taxonomy extends Astoundify_Job_Manager_Regions {
4
+
5
+ public function __construct() {
6
+ add_action( 'init', array( $this, 'register_taxonomy' ), 0 );
7
+ }
8
+
9
+ /**
10
+ * Create the `job_listing_region` taxonomy.
11
+ *
12
+ * @since 1.0.0
13
+ */
14
+ public function register_taxonomy() {
15
+ $admin_capability = 'manage_job_listings';
16
+
17
+ $singular = __( 'Job Region', 'wp-job-manager-locations' );
18
+ $plural = __( 'Job Regions', 'wp-job-manager-locations' );
19
+
20
+ if ( current_theme_supports( 'job-manager-templates' ) ) {
21
+ $rewrite = array(
22
+ 'slug' => _x( 'job-region', 'Job region slug - resave permalinks after changing this', 'wp-job-manager-locations' ),
23
+ 'with_front' => false,
24
+ 'hierarchical' => false
25
+ );
26
+ } else {
27
+ $rewrite = false;
28
+ }
29
+
30
+ register_taxonomy( 'job_listing_region',
31
+ array( 'job_listing' ),
32
+ array(
33
+ 'hierarchical' => true,
34
+ 'update_count_callback' => '_update_post_term_count',
35
+ 'label' => $plural,
36
+ 'labels' => array(
37
+ 'name' => $plural,
38
+ 'singular_name' => $singular,
39
+ 'search_items' => sprintf( __( 'Search %s', 'wp-job-manager-locations' ), $plural ),
40
+ 'all_items' => sprintf( __( 'All %s', 'wp-job-manager-locations' ), $plural ),
41
+ 'parent_item' => sprintf( __( 'Parent %s', 'wp-job-manager-locations' ), $singular ),
42
+ 'parent_item_colon' => sprintf( __( 'Parent %s:', 'wp-job-manager-locations' ), $singular ),
43
+ 'edit_item' => sprintf( __( 'Edit %s', 'wp-job-manager-locations' ), $singular ),
44
+ 'update_item' => sprintf( __( 'Update %s', 'wp-job-manager-locations' ), $singular ),
45
+ 'add_new_item' => sprintf( __( 'Add New %s', 'wp-job-manager-locations' ), $singular ),
46
+ 'new_item_name' => sprintf( __( 'New %s Name', 'wp-job-manager-locations' ), $singular )
47
+ ),
48
+ 'show_ui' => true,
49
+ 'query_var' => true,
50
+ 'has_archive' => true,
51
+ 'capabilities' => array(
52
+ 'manage_terms' => $admin_capability,
53
+ 'edit_terms' => $admin_capability,
54
+ 'delete_terms' => $admin_capability,
55
+ 'assign_terms' => $admin_capability,
56
+ ),
57
+ 'rewrite' => $rewrite,
58
+ )
59
+ );
60
+ }
61
+
62
+ }
includes/class-template.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Astoundify_Job_Manager_Regions_Template extends Astoundify_Job_Manager_Regions {
4
+
5
+ public function __construct() {
6
+ // Template loader
7
+ add_filter( 'job_manager_locate_template', array( $this, 'locate_template' ), 10, 3 );
8
+
9
+ add_filter( 'submit_job_form_fields', array( $this, 'submit_job_form_fields' ) );
10
+ add_filter( 'the_job_location', array( $this, 'the_job_location' ), 10, 2 );
11
+
12
+ if ( get_option( 'job_manager_regions_filter' ) ) {
13
+ add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
14
+ add_action( 'job_manager_job_filters_search_jobs_end', array( $this, 'job_manager_job_filters_search_jobs_end' ) );
15
+ }
16
+ }
17
+
18
+ public function locate_template( $template, $template_name, $template_path ) {
19
+ global $job_manager;
20
+
21
+ if ( ! file_exists( $template ) ) {
22
+ $default_path = wp_job_manager_regions()->plugin_dir . '/templates/';
23
+
24
+ $template = $default_path . $template_name;
25
+ }
26
+
27
+ return $template;
28
+ }
29
+
30
+ public function wp_enqueue_scripts() {
31
+ wp_enqueue_script( 'job-regions', wp_job_manager_regions()->plugin_url . '/assets/js/main.js', array( 'jquery' ), 20140525, true );
32
+ }
33
+
34
+ /**
35
+ * Add the field to the submission form.
36
+ *
37
+ * @since 1.0.0
38
+ */
39
+ public function submit_job_form_fields( $fields ) {
40
+ $fields[ 'job' ][ 'job_region' ] = array(
41
+ 'label' => __( 'Job Region', 'wp-job-manager-locations' ),
42
+ 'type' => 'term-select',
43
+ 'taxonomy' => 'job_listing_region',
44
+ 'required' => true,
45
+ 'priority' => '2.5',
46
+ 'default' => -1
47
+ );
48
+
49
+ return $fields;
50
+ }
51
+
52
+ public function job_manager_job_filters_search_jobs_end( $atts ) {
53
+ if ( ( ! isset( $atts[ 'selected_region' ] ) || '' == $atts[ 'selected_region' ] ) && isset( $_GET[ 'search_region' ] ) ) {
54
+ $atts[ 'selected_region' ] = absint( $_GET[ 'search_region' ] );
55
+ }
56
+
57
+ wp_dropdown_categories( array(
58
+ 'show_option_all' => __( 'All Regions', 'wp-job-manager-locations' ),
59
+ 'hierarchical' => true,
60
+ 'taxonomy' => 'job_listing_region',
61
+ 'name' => 'search_region',
62
+ 'class' => 'search_region',
63
+ 'hide_empty' => false,
64
+ 'selected' => isset( $atts[ 'selected_region' ] ) ? $atts[ 'selected_region' ] : ''
65
+ ) );
66
+ }
67
+
68
+ /**
69
+ * Replace location output with the region.
70
+ *
71
+ * @since 1.0.0
72
+ */
73
+ public function the_job_location( $job_location, $post ) {
74
+ $terms = wp_get_post_terms( $post->ID, 'job_listing_region' );
75
+
76
+ if ( is_wp_error( $terms ) || empty( $terms ) ) {
77
+ return $job_location;
78
+ }
79
+
80
+ $location = $terms[0];
81
+
82
+ return $location->name;
83
+ }
84
+
85
+ }
includes/class-widgets.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Widgets
4
+ */
5
+
6
+ // Exit if accessed directly
7
+ if ( ! defined( 'ABSPATH' ) ) exit;
8
+
9
+ class Astoundify_Job_Manager_Regions_Widgets extends Astoundify_Job_Manager_Regions {
10
+
11
+ public function __construct() {
12
+ if ( ! class_exists( 'Jobify_Widget' ) ) {
13
+ return;
14
+ }
15
+
16
+ $widgets = array(
17
+ 'class-widget-region-list.php'
18
+ );
19
+
20
+ foreach ( $widgets as $widget ) {
21
+ include_once( $this->plugin_dir . '/' . $widget );
22
+ }
23
+
24
+ add_action( 'widgets_init', array( $this, 'widgets_init' ) );
25
+ }
26
+
27
+ public function widgets_init() {
28
+ register_widget( 'Astoundify_Job_Manager_Regions_Widget' );
29
+ }
30
+
31
+ }
includes/widgets/class-widget-region-list.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Simple list
5
+ */
6
+ class Astoundify_Job_Manager_Regions_Widget_List extends Jobify_Widget {
7
+ /**
8
+ * Constructor
9
+ */
10
+ public function __construct() {
11
+ $this->widget_cssclass = 'ajmr_widget_regions';
12
+ $this->widget_description = __( 'Display a list of job regions.', 'ajmr' );
13
+ $this->widget_id = 'ajmr_widget_regions';
14
+ $this->widget_name = __( 'Job Regions', 'ajmr' );
15
+ $this->settings = array(
16
+ 'title' => array(
17
+ 'type' => 'text',
18
+ 'std' => 'Job Regions',
19
+ 'label' => __( 'Title:', 'ajmr' )
20
+ )
21
+ );
22
+ parent::__construct();
23
+ }
24
+
25
+ /**
26
+ * widget function.
27
+ *
28
+ * @see WP_Widget
29
+ * @access public
30
+ * @param array $args
31
+ * @param array $instance
32
+ * @return void
33
+ */
34
+ function widget( $args, $instance ) {
35
+ if ( $this->get_cached_widget( $args ) )
36
+ return;
37
+
38
+ ob_start();
39
+
40
+ extract( $args );
41
+
42
+ echo $before_widget;
43
+
44
+ if ( $instance[ 'title' ] ) echo $before_title . $instance[ 'title' ] . $after_title;
45
+
46
+ wp_list_categories( array(
47
+ 'title_li' => '',
48
+ 'taxonomy' => 'job_listing_region',
49
+ 'hide_empty' => 0
50
+ ) );
51
+
52
+ echo $after_widget;
53
+
54
+ $content = ob_get_clean();
55
+
56
+ echo $content;
57
+
58
+ $this->cache_widget( $args, $content );
59
+ }
60
+ }
languages/wp-job-manager-locations.pot ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2014 WP Job Manager - Predefined Regions
2
+ # This file is distributed under the same license as the WP Job Manager - Predefined Regions package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: WP Job Manager - Predefined Regions 1.5.0\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/wp-job-manager-locations\n"
7
+ "POT-Creation-Date: 2014-09-09 15:19:34+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+
15
+ #: includes/class-taxonomy.php:17 includes/class-template.php:41
16
+ msgid "Job Region"
17
+ msgstr ""
18
+
19
+ #: includes/class-taxonomy.php:18
20
+ #: includes/widgets/class-widget-region-list.php:14
21
+ #: wp-job-manager-locations.php:92
22
+ msgid "Job Regions"
23
+ msgstr ""
24
+
25
+ #: includes/class-taxonomy.php:22
26
+ msgctxt "Job region slug - resave permalinks after changing this"
27
+ msgid "job-region"
28
+ msgstr ""
29
+
30
+ #: includes/class-taxonomy.php:39
31
+ msgid "Search %s"
32
+ msgstr ""
33
+
34
+ #: includes/class-taxonomy.php:40
35
+ msgid "All %s"
36
+ msgstr ""
37
+
38
+ #: includes/class-taxonomy.php:41
39
+ msgid "Parent %s"
40
+ msgstr ""
41
+
42
+ #: includes/class-taxonomy.php:42
43
+ msgid "Parent %s:"
44
+ msgstr ""
45
+
46
+ #: includes/class-taxonomy.php:43
47
+ msgid "Edit %s"
48
+ msgstr ""
49
+
50
+ #: includes/class-taxonomy.php:44
51
+ msgid "Update %s"
52
+ msgstr ""
53
+
54
+ #: includes/class-taxonomy.php:45
55
+ msgid "Add New %s"
56
+ msgstr ""
57
+
58
+ #: includes/class-taxonomy.php:46
59
+ msgid "New %s Name"
60
+ msgstr ""
61
+
62
+ #: includes/class-template.php:58
63
+ msgid "All Regions"
64
+ msgstr ""
65
+
66
+ #: includes/widgets/class-widget-region-list.php:12
67
+ msgid "Display a list of job regions."
68
+ msgstr ""
69
+
70
+ #: includes/widgets/class-widget-region-list.php:19
71
+ msgid "Title:"
72
+ msgstr ""
73
+
74
+ #: templates/form-fields/job-region-field.php:8
75
+ msgctxt "show option none"
76
+ msgid "&mdash;"
77
+ msgstr ""
78
+
79
+ #: wp-job-manager-locations.php:93
80
+ msgid "Filter by Region"
81
+ msgstr ""
82
+
83
+ #: wp-job-manager-locations.php:94
84
+ msgid "Use a dropdown instead of a text input."
85
+ msgstr ""
86
+
87
+ #: wp-job-manager-locations.php:172
88
+ msgid "in %s"
89
+ msgstr ""
90
+ #. Plugin Name of the plugin/theme
91
+ msgid "WP Job Manager - Predefined Regions"
92
+ msgstr ""
93
+
94
+ #. Plugin URI of the plugin/theme
95
+ msgid "https://github.com/astoundify/wp-job-manager-regions/"
96
+ msgstr ""
97
+
98
+ #. Description of the plugin/theme
99
+ msgid "Create predefined regions/locations that job submissions can associate themselves with."
100
+ msgstr ""
101
+
102
+ #. Author of the plugin/theme
103
+ msgid "Astoundify"
104
+ msgstr ""
105
+
106
+ #. Author URI of the plugin/theme
107
+ msgid "http://astoundify.com"
108
+ msgstr ""
readme.txt CHANGED
@@ -1,13 +1,13 @@
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.3.1
11
  License: GPLv3
12
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
13
 
@@ -30,6 +30,14 @@ Astoundify has released the first fully integrated WP Job Manager theme. Check o
30
 
31
  == Changelog ==
32
 
 
 
 
 
 
 
 
 
33
  = 1.3.1: January 20, 2014 =
34
 
35
  * Fix: Avoid priority conflict with existing fields.
1
+ === WP Job Manager - Predefined Regions ===
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: 4.0
9
+ Tested up to: 4.0
10
+ Stable Tag: 1.5.0
11
  License: GPLv3
12
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
13
 
30
 
31
  == Changelog ==
32
 
33
+ = 1.5.0: September 9, 2014 =
34
+
35
+ * New: Regions can now be used to filter listings instead of the standard location text field.
36
+
37
+ = 1.4.0: May 22, 2014 =
38
+
39
+ * New: Use a custom template so the select box can have hierarchy.
40
+
41
  = 1.3.1: January 20, 2014 =
42
 
43
  * Fix: Avoid priority conflict with existing fields.
templates/form-fields/job-region-field.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ wp_dropdown_categories( array(
3
+ 'taxonomy' => 'job_listing_region',
4
+ 'name' => esc_attr( isset( $field['name'] ) ? $field['name'] : $key ),
5
+ 'id' => esc_attr( $key ),
6
+ 'hierarchical' => true,
7
+ 'selected' => isset( $field[ 'value' ] ) ? $field[ 'value' ] : $field[ 'default' ],
8
+ 'show_option_none' => _x( '&mdash;', 'show option none', 'wp-job-manager-locations' ),
9
+ 'hide_empty' => false
10
+ ) );
11
+ ?>
wp-job-manager-locations.php CHANGED
@@ -1,12 +1,12 @@
1
  <?php
2
  /**
3
  * Plugin Name: WP Job Manager - Predefined Regions
4
- * Plugin URI: https://github.com/astoundify/wp-job-manager-locations
5
- * Description: Create predefined regions that job submissions can associate themselves with.
6
  * Author: Astoundify
7
  * Author URI: http://astoundify.com
8
- * Version: 1.3.1
9
- * Text Domain: ajmr
10
  */
11
 
12
  // Exit if accessed directly
@@ -33,190 +33,175 @@ class Astoundify_Job_Manager_Regions {
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
- add_filter( 'submit_job_form_fields_get_job_data', array( $this, 'form_fields_get_job_data' ), 10, 2 );
75
 
76
- add_filter( 'the_job_location', array( $this, 'the_job_location' ), 10, 2 );
 
 
 
 
77
 
78
  $this->load_textdomain();
79
  }
80
 
81
  /**
82
- * Create the `job_listing_region` taxonomy.
83
  *
84
- * @since 1.0
 
 
85
  */
86
- public function register_post_taxonomy() {
87
- $admin_capability = 'manage_job_listings';
88
-
89
- $singular = __( 'Job Region', 'ajmr' );
90
- $plural = __( 'Job Regions', 'ajmr' );
91
-
92
- if ( current_theme_supports( 'job-manager-templates' ) ) {
93
- $rewrite = array(
94
- 'slug' => _x( 'job-region', 'Job region slug - resave permalinks after changing this', 'ajmr' ),
95
- 'with_front' => false,
96
- 'hierarchical' => false
97
- );
98
- } else {
99
- $rewrite = false;
 
 
 
 
 
 
 
100
  }
101
 
102
- register_taxonomy( 'job_listing_region',
103
- array( 'job_listing' ),
104
- array(
105
- 'hierarchical' => true,
106
- 'update_count_callback' => '_update_post_term_count',
107
- 'label' => $plural,
108
- 'labels' => array(
109
- 'name' => $plural,
110
- 'singular_name' => $singular,
111
- 'search_items' => sprintf( __( 'Search %s', 'ajmr' ), $plural ),
112
- 'all_items' => sprintf( __( 'All %s', 'ajmr' ), $plural ),
113
- 'parent_item' => sprintf( __( 'Parent %s', 'ajmr' ), $singular ),
114
- 'parent_item_colon' => sprintf( __( 'Parent %s:', 'ajmr' ), $singular ),
115
- 'edit_item' => sprintf( __( 'Edit %s', 'ajmr' ), $singular ),
116
- 'update_item' => sprintf( __( 'Update %s', 'ajmr' ), $singular ),
117
- 'add_new_item' => sprintf( __( 'Add New %s', 'ajmr' ), $singular ),
118
- 'new_item_name' => sprintf( __( 'New %s Name', 'ajmr' ), $singular )
119
- ),
120
- 'show_ui' => true,
121
- 'query_var' => true,
122
- 'has_archive' => true,
123
- 'capabilities' => array(
124
- 'manage_terms' => $admin_capability,
125
- 'edit_terms' => $admin_capability,
126
- 'delete_terms' => $admin_capability,
127
- 'assign_terms' => $admin_capability,
128
- ),
129
- 'rewrite' => $rewrite,
130
- )
131
- );
132
  }
133
 
134
- /**
135
- * Add the field to the submission form.
136
- *
137
- * @since 1.0
138
- */
139
- function form_fields( $fields ) {
140
- $fields[ 'job' ][ 'job_region' ] = array(
141
- 'label' => __( 'Job Region', 'job_manager' ),
142
- 'type' => 'select',
143
- 'options' => ajmr_get_regions_simple(),
144
- 'required' => true,
145
- 'priority' => '2.5'
146
- );
147
 
148
- return $fields;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  }
150
 
151
- /**
152
- * Get the current value for the job region. We can't rely
153
- * on basic meta value getting, instead we need to find the term.
154
- *
155
- * @since 1.0
156
- */
157
- function form_fields_get_job_data( $fields, $job ) {
158
- $fields[ 'job' ][ 'job_region' ][ 'value' ] = current( wp_get_object_terms( $job->ID, 'job_listing_region', array( 'fields' => 'slugs' ) ) );
159
 
160
- return $fields;
 
 
 
 
 
 
 
 
 
 
161
  }
162
 
163
  /**
164
- * When the form is submitted, update the data.
165
- *
166
- * @since 1.0
167
  */
168
- function update_job_data( $job_id, $values ) {
169
- $region = isset ( $values[ 'job' ][ 'job_region' ] ) ? $values[ 'job' ][ 'job_region' ] : null;
 
 
170
 
171
- if ( ! $region )
172
- return;
173
 
174
- $term = get_term_by( 'slug', $region, 'job_listing_region' );
175
 
176
- wp_set_post_terms( $job_id, array( $term->term_id ), 'job_listing_region', false );
177
  }
178
 
179
  /**
180
- * On a singular job page, append the region to the location.
181
- *
182
- * @since 1.0
183
  */
184
- function the_job_location( $job_location, $post ) {
185
- if ( ! is_singular( 'job_listing' ) )
186
- return $job_location;
187
-
188
- $terms = wp_get_post_terms( $post->ID, 'job_listing_region' );
189
 
190
- if ( is_wp_error( $terms ) || empty( $terms ) )
191
- return $job_location;
192
 
193
- $location = $terms[0];
194
- $locname = $location->name;
195
 
196
- $job_location = sprintf( '%s &mdash; <a href="%s">%s</a>', $job_location, get_term_link( $location, 'job_listing_region' ), $locname );
197
-
198
- return apply_filters( 'ajmr_job_location', $job_location, $location );
199
  }
200
 
201
  /**
202
  * Loads the plugin language files
203
  *
204
- * @since 1.0
205
  */
206
  public function load_textdomain() {
207
- // Traditional WordPress plugin locale filter
208
- $locale = apply_filters( 'plugin_locale', get_locale(), $this->domain );
209
- $mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
210
 
211
- // Setup paths to current locale file
212
- $mofile_local = $this->lang_dir . $mofile;
213
  $mofile_global = WP_LANG_DIR . '/' . $this->domain . '/' . $mofile;
214
 
215
- // Look in global /wp-content/languages/ajmr folder
216
  if ( file_exists( $mofile_global ) ) {
217
  return load_textdomain( $this->domain, $mofile_global );
218
-
219
- // Look in local /wp-content/plugins/ajmr/languages/ folder
220
  } elseif ( file_exists( $mofile_local ) ) {
221
  return load_textdomain( $this->domain, $mofile_local );
222
  }
@@ -224,6 +209,7 @@ class Astoundify_Job_Manager_Regions {
224
  return false;
225
  }
226
  }
 
227
 
228
  /**
229
  * Start things up.
@@ -232,54 +218,8 @@ class Astoundify_Job_Manager_Regions {
232
  *
233
  * $ajmr = ajmr();
234
  *
235
- * @since 1.0
236
  */
237
- function ajmr() {
238
  return Astoundify_Job_Manager_Regions::instance();
239
- }
240
-
241
- ajmr();
242
-
243
- /**
244
- * Get regions (terms) helper.
245
- *
246
- * @since 1.0
247
- */
248
- function ajmr_get_regions() {
249
- $locations = get_terms( 'job_listing_region', apply_filters( 'ajmr_get_region_args', array( 'hide_empty' => 0 ) ) );
250
-
251
- return $locations;
252
- }
253
-
254
- /**
255
- * Create a key => value pair of term ID and term name.
256
- *
257
- * @since 1.0
258
- */
259
- function ajmr_get_regions_simple() {
260
- $locations = ajmr_get_regions();
261
- $simple = array();
262
-
263
- foreach ( $locations as $location ) {
264
- $simple[ $location->slug ] = $location->name;
265
- }
266
-
267
- return apply_filters( 'ajmr_get_regions_simple', $simple );
268
- }
269
-
270
- /**
271
- * Custom widgets
272
- *
273
- * @since 1.1
274
- */
275
- function ajmr_widgets_init() {
276
- if ( ! class_exists( 'Jobify_Widget' ) )
277
- return;
278
-
279
- $ajmr = ajmr();
280
-
281
- include_once( $ajmr->plugin_dir . '/widgets.php' );
282
-
283
- register_widget( 'Astoundify_Job_Manager_Regions_Widget' );
284
- }
285
- add_action( 'after_setup_theme', 'ajmr_widgets_init', 11 );
1
  <?php
2
  /**
3
  * Plugin Name: WP Job Manager - Predefined Regions
4
+ * Plugin URI: https://github.com/astoundify/wp-job-manager-regions/
5
+ * Description: Create predefined regions/locations that job submissions can associate themselves with.
6
  * Author: Astoundify
7
  * Author URI: http://astoundify.com
8
+ * Version: 1.5.0
9
+ * Text Domain: wp-job-manager-locations
10
  */
11
 
12
  // Exit if accessed directly
33
  /**
34
  * Start things up.
35
  *
36
+ * @since 1.0.0
37
  */
38
  public function __construct() {
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  $this->file = __FILE__;
40
+ $this->basename = plugin_basename( $this->file );
41
+ $this->plugin_dir = plugin_dir_path( $this->file );
42
+ $this->plugin_url = plugin_dir_url ( $this->file );
43
+ $this->lang_dir = trailingslashit( $this->plugin_dir . 'languages' );
44
+ $this->domain = 'wp-job-manager-locations';
45
+
46
+ $files = array(
47
+ 'includes/class-taxonomy.php',
48
+ 'includes/class-template.php',
49
+ 'includes/class-widgets.php'
50
+ );
51
 
52
+ foreach ( $files as $file ) {
53
+ include_once( $this->plugin_dir . '/' . $file );
54
+ }
55
 
56
+ $this->taxonomy = new Astoundify_Job_Manager_Regions_Taxonomy;
57
+ $this->template = new Astoundify_Job_Manager_Regions_Template;
58
 
59
+ $this->setup_actions();
60
  }
61
 
62
  /**
63
  * Setup the default hooks and actions
64
  *
65
+ * @since 1.0.0
66
  *
67
  * @return void
68
  */
69
  private function setup_actions() {
70
+ add_filter( 'job_manager_settings', array( $this, 'job_manager_settings' ) );
 
 
 
71
 
72
+ if ( get_option( 'job_manager_regions_filter' ) ) {
73
+ add_filter( 'job_manager_output_jobs_defaults', array( $this, 'job_manager_output_jobs_defaults' ) );
74
+ add_filter( 'job_manager_get_listings', array( $this, 'job_manager_get_listings' ) );
75
+ add_filter( 'job_manager_get_listings_args', array( $this, 'job_manager_get_listings_args' ) );
76
+ }
77
 
78
  $this->load_textdomain();
79
  }
80
 
81
  /**
82
+ * Add settings fields to select the appropriate form for each listing type.
83
  *
84
+ * @since WP Job Manager - Predefiend Regions 1.4.1
85
+ *
86
+ * @return void
87
  */
88
+ public function job_manager_settings($settings) {
89
+ $settings[ 'job_listings' ][1][] = array(
90
+ 'name' => 'job_manager_regions_filter',
91
+ 'std' => '1',
92
+ 'label' => __( 'Job Regions', 'wp-job-manager-locations' ),
93
+ 'cb_label' => __( 'Filter by Region', 'wp-job-manager-locations' ),
94
+ 'desc' => __( 'Use a dropdown instead of a text input.' ),
95
+ 'type' => 'checkbox'
96
+ );
97
+
98
+ return $settings;
99
+ }
100
+
101
+ public function job_manager_output_jobs_defaults( $defaults ) {
102
+ $defaults[ 'selected_region' ] = '';
103
+
104
+ if ( is_tax( 'job_listing_region' ) ) {
105
+ $type = get_queried_object();
106
+
107
+ $defaults[ 'show_categories' ] = true;
108
+ $defaults[ 'selected_region' ] = $type->term_id;
109
  }
110
 
111
+ return $defaults;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  }
113
 
114
+ public function job_manager_get_listings( $args ) {
115
+ $params = array();
116
+
117
+ if ( isset( $_POST[ 'form_data' ] ) ) {
118
+
119
+ parse_str( $_POST[ 'form_data' ], $params );
120
+
121
+ if ( isset( $params[ 'search_region' ] ) && 0 != $params[ 'search_region' ] ) {
122
+ $region = $params[ 'search_region' ];
 
 
 
 
123
 
124
+ if ( is_int( $region ) ) {
125
+ $region = array( $region );
126
+ }
127
+
128
+ $args[ 'tax_query' ][] = array(
129
+ 'taxonomy' => 'job_listing_region',
130
+ 'field' => 'id',
131
+ 'terms' => $region,
132
+ 'operator' => 'IN'
133
+ );
134
+
135
+ add_filter( 'job_manager_get_listings_custom_filter', '__return_true' );
136
+ add_filter( 'job_manager_get_listings_custom_filter_text', array( $this, 'custom_filter_text' ) );
137
+ add_filter( 'job_manager_get_listings_custom_filter_rss_args', array( $this, 'custom_filter_rss' ) );
138
+ }
139
+
140
+ }
141
+
142
+ return $args;
143
  }
144
 
145
+ public function job_manager_get_listings_args( $args ) {
146
+ $params = array();
 
 
 
 
 
 
147
 
148
+ if ( isset( $_POST[ 'form_data' ] ) ) {
149
+
150
+ parse_str( $_POST[ 'form_data' ], $params );
151
+
152
+ if ( isset( $params[ 'search_region' ] ) && 0 != $params[ 'search_region' ] ) {
153
+ $args[ 'search_location' ] = ' ';
154
+ }
155
+
156
+ }
157
+
158
+ return $args;
159
  }
160
 
161
  /**
162
+ * Append 'showing' text
163
+ * @return string
 
164
  */
165
+ public function custom_filter_text( $text ) {
166
+ $params = array();
167
+
168
+ parse_str( $_POST[ 'form_data' ], $params );
169
 
170
+ $term = get_term( $params[ 'search_region' ], 'job_listing_region' );
 
171
 
172
+ $text .= sprintf( ' ' . __( 'in %s', 'wp-job-manager-locations' ) . ' ', $term->name );
173
 
174
+ return $text;
175
  }
176
 
177
  /**
178
+ * apply_tag_filter_rss
179
+ * @return array
 
180
  */
181
+ public function custom_filter_rss( $args ) {
182
+ $params = array();
 
 
 
183
 
184
+ parse_str( $_POST[ 'form_data' ], $params );
 
185
 
186
+ $args[ 'job_region' ] = $params[ 'search_region' ];
 
187
 
188
+ return $args;
 
 
189
  }
190
 
191
  /**
192
  * Loads the plugin language files
193
  *
194
+ * @since 1.0.0
195
  */
196
  public function load_textdomain() {
197
+ $locale = apply_filters( 'plugin_locale', get_locale(), $this->domain );
198
+ $mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
 
199
 
200
+ $mofile_local = $this->lang_dir . $mofile;
 
201
  $mofile_global = WP_LANG_DIR . '/' . $this->domain . '/' . $mofile;
202
 
 
203
  if ( file_exists( $mofile_global ) ) {
204
  return load_textdomain( $this->domain, $mofile_global );
 
 
205
  } elseif ( file_exists( $mofile_local ) ) {
206
  return load_textdomain( $this->domain, $mofile_local );
207
  }
209
  return false;
210
  }
211
  }
212
+ add_action( 'plugins_loaded', array( 'Astoundify_Job_Manager_Regions', 'instance' ) );
213
 
214
  /**
215
  * Start things up.
218
  *
219
  * $ajmr = ajmr();
220
  *
221
+ * @since 1.0.0
222
  */
223
+ function wp_job_manager_regions() {
224
  return Astoundify_Job_Manager_Regions::instance();
225
+ }