From be15b6c5e7f204ed727b080569f51d2cdbab42ae Mon Sep 17 00:00:00 2001
From: Myles McNamara
Date: Wed, 22 Mar 2017 00:18:07 -0400
Subject: [PATCH 1/2] $id unused, no need to expect both params passed (#875)
---
wp-job-manager.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/wp-job-manager.php b/wp-job-manager.php
index d71da7f05..7e27555f0 100644
--- a/wp-job-manager.php
+++ b/wp-job-manager.php
@@ -171,10 +171,10 @@ public function frontend_scripts() {
}
}
-function job_manager_add_post_types( $types, $id ) {
+function job_manager_add_post_types( $types ) {
$types[] = 'job_listing';
return $types;
}
-add_filter( 'post_types_to_delete_with_user', 'job_manager_add_post_types', 10, 2 );
+add_filter( 'post_types_to_delete_with_user', 'job_manager_add_post_types', 10 );
$GLOBALS['job_manager'] = new WP_Job_Manager();
From 6951d06b0df8c18c4968796b6bd41c14d2659d17 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Donncha=20=C3=93=20Caoimh?=
Date: Wed, 22 Mar 2017 04:20:56 +0000
Subject: [PATCH 2/2] Warn the user if they're editing an existing job. (#847)
* Warn the user if they're editing an existing job.
See #835
The plugin allows the user to edit jobs before they're published, but if the paid listings plugin is installed a new job may be in "pending_payment" status even after the user has submitted it. This patch warns the user and displays a link to delete the cookie. The link will allow users to start a new job submission even without the paid listing plugin installed.
* Check for paid listings before job listing while resuming and move code
If we're using the paid listings plugin and it shows packages before
jobs are displayed then the job_id will be set and resuming using the
cookie doesn't work properly.
Moved cookie reset code into the abstract form class so it's neater,
maybe.
---
.../abstracts/abstract-wp-job-manager-form.php | 14 ++++++++++++++
.../forms/class-wp-job-manager-form-submit-job.php | 5 ++++-
templates/job-submit.php | 6 ++++++
wp-job-manager-functions.php | 1 +
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/includes/abstracts/abstract-wp-job-manager-form.php b/includes/abstracts/abstract-wp-job-manager-form.php
index b0446f565..273c1809c 100644
--- a/includes/abstracts/abstract-wp-job-manager-form.php
+++ b/includes/abstracts/abstract-wp-job-manager-form.php
@@ -73,6 +73,20 @@ public function __wakeup() {
* Process function. all processing code if needed - can also change view if step is complete
*/
public function process() {
+
+ // reset cookie
+ if (
+ isset( $_GET[ 'new' ] ) &&
+ isset( $_COOKIE[ 'wp-job-manager-submitting-job-id' ] ) &&
+ isset( $_COOKIE[ 'wp-job-manager-submitting-job-key' ] ) &&
+ get_post_meta( $_COOKIE[ 'wp-job-manager-submitting-job-id' ], '_submitting_key', true ) == $_COOKIE['wp-job-manager-submitting-job-key']
+ ) {
+ delete_post_meta( $_COOKIE[ 'wp-job-manager-submitting-job-id' ], '_submitting_key' );
+ setcookie( 'wp-job-manager-submitting-job-id', '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN, false );
+ setcookie( 'wp-job-manager-submitting-job-key', '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN, false );
+ wp_redirect( remove_query_arg( array( 'new', 'key' ), $_SERVER[ 'REQUEST_URI' ] ) );
+ }
+
$step_key = $this->get_step_key( $this->step );
if ( $step_key && is_callable( $this->steps[ $step_key ]['handler'] ) ) {
diff --git a/includes/forms/class-wp-job-manager-form-submit-job.php b/includes/forms/class-wp-job-manager-form-submit-job.php
index 10950d727..f4d26ccc4 100644
--- a/includes/forms/class-wp-job-manager-form-submit-job.php
+++ b/includes/forms/class-wp-job-manager-form-submit-job.php
@@ -89,12 +89,14 @@ public function __construct() {
}
// Allow resuming from cookie.
- if ( ! $this->job_id && ! empty( $_COOKIE['wp-job-manager-submitting-job-id'] ) && ! empty( $_COOKIE['wp-job-manager-submitting-job-key'] ) ) {
+ $this->resume_edit = false;
+ if ( ! isset( $_GET[ 'new' ] ) && ( 'before' === get_option( 'job_manager_paid_listings_flow' ) || ! $this->job_id ) && ! empty( $_COOKIE['wp-job-manager-submitting-job-id'] ) && ! empty( $_COOKIE['wp-job-manager-submitting-job-key'] ) ) {
$job_id = absint( $_COOKIE['wp-job-manager-submitting-job-id'] );
$job_status = get_post_status( $job_id );
if ( ( 'preview' === $job_status || 'pending_payment' === $job_status ) && get_post_meta( $job_id, '_submitting_key', true ) === $_COOKIE['wp-job-manager-submitting-job-key'] ) {
$this->job_id = $job_id;
+ $this->resume_edit = get_post_meta( $job_id, '_submitting_key', true );
}
}
@@ -412,6 +414,7 @@ public function submit() {
get_job_manager_template( 'job-submit.php', array(
'form' => $this->form_name,
'job_id' => $this->get_job_id(),
+ 'resume_edit' => $this->resume_edit,
'action' => $this->get_action(),
'job_fields' => $this->get_fields( 'job' ),
'company_fields' => $this->get_fields( 'company' ),
diff --git a/templates/job-submit.php b/templates/job-submit.php
index 0f25607ef..0bdee70c8 100644
--- a/templates/job-submit.php
+++ b/templates/job-submit.php
@@ -8,6 +8,12 @@
?>
', '' . __( 'Create A New Job' ) . '' );
+ }
+ ?>
+
diff --git a/wp-job-manager-functions.php b/wp-job-manager-functions.php
index 816db5c3d..6b29cddf8 100644
--- a/wp-job-manager-functions.php
+++ b/wp-job-manager-functions.php
@@ -919,3 +919,4 @@ function job_manager_duplicate_listing( $post_id ) {
return $new_post_id;
}
+