/**
 * True if an the user can post a job. If accounts are required, and reg is enabled, users can post (they signup at the same time).
 *
 * @return bool
 */
function job_manager_user_can_post_job()
{
    $can_post = true;
    if (!is_user_logged_in()) {
        if (job_manager_user_requires_account() && !job_manager_enable_registration()) {
            $can_post = false;
        }
    }
    return apply_filters('job_manager_user_can_post_job', $can_post);
}
 /**
  * Submit Step is posted
  */
 public function submit_handler()
 {
     try {
         // Init fields
         $this->init_fields();
         // Get posted values
         $values = $this->get_posted_fields();
         if (empty($_POST['submit_job'])) {
             return;
         }
         // Validate required
         if (is_wp_error($return = $this->validate_fields($values))) {
             throw new Exception($return->get_error_message());
         }
         // Account creation
         if (!is_user_logged_in()) {
             $create_account = false;
             if (job_manager_enable_registration()) {
                 if (job_manager_user_requires_account()) {
                     if (!job_manager_generate_username_from_email() && empty($_POST['create_account_username'])) {
                         throw new Exception(__('Please enter a username.', 'wp-job-manager'));
                     }
                     if (empty($_POST['create_account_email'])) {
                         throw new Exception(__('Please enter your email address.', 'wp-job-manager'));
                     }
                 }
                 if (!empty($_POST['create_account_email'])) {
                     $create_account = wp_job_manager_create_account(array('username' => empty($_POST['create_account_username']) ? '' : $_POST['create_account_username'], 'email' => $_POST['create_account_email'], 'role' => get_option('job_manager_registration_role')));
                 }
             }
             if (is_wp_error($create_account)) {
                 throw new Exception($create_account->get_error_message());
             }
         }
         if (job_manager_user_requires_account() && !is_user_logged_in()) {
             throw new Exception(__('You must be signed in to post a new listing.'));
         }
         // Update the job
         $this->save_job($values['job']['job_title'], $values['job']['job_description'], $this->job_id ? '' : 'preview', $values);
         $this->update_job_data($values);
         // Successful, show next step
         $this->step++;
     } catch (Exception $e) {
         $this->add_error($e->getMessage());
         return;
     }
 }
Пример #3
0
    printf(__('You are currently signed in as <strong>%s</strong>.', 'wp-job-manager'), $user->user_login);
    ?>

			<a class="button" href="<?php 
    echo apply_filters('submit_job_form_logout_url', wp_logout_url(get_permalink()));
    ?>
"><?php 
    _e('Sign out', 'wp-job-manager');
    ?>
</a>
		</div>
	</fieldset>

<?php 
} else {
    $account_required = job_manager_user_requires_account();
    $registration_enabled = job_manager_enable_registration();
    ?>
	<fieldset>
		<label><?php 
    _e('Have an account?', 'wp-job-manager');
    ?>
</label>
		<div class="field account-sign-in">
			<a class="button" href="<?php 
    echo apply_filters('submit_job_form_login_url', wp_login_url(get_permalink()));
    ?>
"><?php 
    _e('Sign in', 'wp-job-manager');
    ?>
</a>
 /**
  * Submit Step is posted
  */
 public static function submit_handler()
 {
     try {
         // Init fields
         self::init_fields();
         // Get posted values
         $values = self::get_posted_fields();
         if (empty($_POST['submit_job']) || !wp_verify_nonce($_POST['_wpnonce'], 'submit_form_posted')) {
             return;
         }
         // Validate required
         if (is_wp_error($return = self::validate_fields($values))) {
             throw new Exception($return->get_error_message());
         }
         // Account creation
         if (!is_user_logged_in()) {
             $create_account = false;
             if (job_manager_enable_registration() && !empty($_POST['create_account_email'])) {
                 $create_account = wp_job_manager_create_account($_POST['create_account_email'], get_option('job_manager_registration_role'));
             }
             if (is_wp_error($create_account)) {
                 throw new Exception($create_account->get_error_message());
             }
         }
         if (job_manager_user_requires_account() && !is_user_logged_in()) {
             throw new Exception(__('You must be signed in to post a new job listing.'));
         }
         // Update the job
         self::save_job($values['job']['job_title'], $values['job']['job_description'], self::$job_id ? '' : 'preview', $values);
         self::update_job_data($values);
         // Successful, show next step
         self::$step++;
     } catch (Exception $e) {
         self::add_error($e->getMessage());
         return;
     }
 }