default values in wordpress field

hey guys- I'm configuring this great plugin called wp-job-manager for wordpress, and I was hoping to expedite the process for adding jobs by modifying the back end.

When you create a new job, you have the option of including a company name, logo, website, tagline, and twitter page. Well, my company is the only organization that will be posted, so adding these values to an individual listing is redundant.

So my question to you -mighty code warriors- is this: how can I hardcode my own values in there? This is a child theme, so I would like to preserve my changes when an update occurs.

The author has addressed this in a support form, but I'm mystified by the implementation.

http://wordpress.org/support/topic/change-field-titles

Thanks so much!
billypilgrim123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason C. LevineNo oneCommented:
That support topic links to a second support topic:

http://wordpress.org/support/topic/help-with-filters?replies=2

The author further replies with the following filter and function:

The filter isn't 'job_title', it's submit_job_form_fields.

add_filter( 'submit_job_form_fields', 'your_function' );

Then your function needs to change and return the field:

function your_function( $fields ) {
  $fields = ['job']['job_title']['label'] = "Contact Name";
  return $fields;
}

Open in new window


You would add the add_filter and the function to your functions.php file.

Does it make more sense now?
0
billypilgrim123Author Commented:
I saw that, Jason. I'm a real novice at php, so I wasn't exactly sure which part of the function I need to paste in my functions.php file.

the author refers to line 92 in this file:
https://github.com/mikejolley/WP-Job-Manager/blob/master/includes/forms/class-wp-job-manager-form-submit-job.php#L92

I'm not sure what code I should copy to make the function work. Could you point me in the right direction? I'm essentially defining this code, and deploying it as the add_filter, correct? Is there a specific order these need to be written in my php file?

Your advice would help me out greatly! Thank you!
0
Jason C. LevineNo oneCommented:
so I wasn't exactly sure which part of the function I need to paste in my functions.php file.

All of it.  It would look like this:

add_filter( 'submit_job_form_fields', 'change_label' );

function change_label( $fields ) {
  $fields = ['job']['job_title']['label'] = "Contact Name";
  return $fields;
}

Open in new window


The filter intercepts the normal action and changes the label as defined in the function.  The critical thing here is to understand the original author's naming conventions and from there, how to pass it through the WordPress filters.

the author refers to line 92 in this file:

Not 100% sure what is going there.  While you could certainly (and through trial and error) edit the plugin files and change things to your specs that way, it's not a good path to start down because if the plugin updates your changes will be blown away.
0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

billypilgrim123Author Commented:
This is really basic stuff, Jason, but I can't insert this:

function your_function( $fields ) {
  $fields = ['job']['job_title']['label'] = "Contact Name";
  return $fields;
}

inside my functions.php file without a syntax error. I've inserted the code in line 16 of my functions.php file - what's going on here?
functions.php
0
Jason C. LevineNo oneCommented:
Let's back up a few steps here.

So my question to you -mighty code warriors- is this: how can I hardcode my own values in there?

So do you want to change the labels on the fields or change the values being submitted so that they cannot be overridden by the user?

This is a child theme, so I would like to preserve my changes when an update occurs.

Theme and plugin modifications are wholly separate from each other.
0
billypilgrim123Author Commented:
I'd like to change the values being submitted. So instead of manually entering the same information each time we add a new job posting, we'd have it already coded in there.

pre-coded values
so these field here will already be coded with our logo, tagline, URL, etc.
0
billypilgrim123Author Commented:
any ideas, Jason?
0
Jason C. LevineNo oneCommented:
I would have to download the plugin and install and test.  But you should be able to add value="whatever" into the plugin code directly and hardcode values that way
0
billypilgrim123Author Commented:
I'd prefer to do it how the author recommends. Can you give me some assistance as to why I'm getting a syntax error when I add this:

function your_function( $fields ) {
  $fields = ['job']['job_title']['label'] = "Contact Name";
  return $fields;
}

to my functions.php file?
0
Jason C. LevineNo oneCommented:
No idea, and the reason that won't work even if it didn't cause a syntax error is because that code renames the fields.  Doesn't change the default value of the field at all.  

I looked around for code samples to change the default values but didn't find any from the author or the community.
0
billypilgrim123Author Commented:
so...what would you advise?
0
Jason C. LevineNo oneCommented:
In the wp-content/plugins/wp-job-manager/includes/forms folder is the following file:

class-wp-job-manager-form-submit-job.php

In there are lines 94-180

		self::$fields = apply_filters( 'submit_job_form_fields', array(
			'job' => array(
				'job_title' => array(
					'label'       => __( 'Job title', 'job_manager' ),
					'type'        => 'text',
					'required'    => true,
					'placeholder' => '',
					'priority'    => 1
				),
				'job_location' => array(
					'label'       => __( 'Job location', 'job_manager' ),
					'description' => __( 'Leave this blank if the job can be done from anywhere (i.e. telecommuting)', 'job_manager' ),
					'type'        => 'text',
					'required'    => false,
					'placeholder' => __( 'e.g. "London, UK", "New York", "Houston, TX"', 'job_manager' ),
					'priority'    => 2
				),
				'job_type' => array(
					'label'       => __( 'Job type', 'job_manager' ),
					'type'        => 'select',
					'required'    => true,
					'options'     => self::job_types(),
					'placeholder' => '',
					'priority'    => 3
				),
				'job_category' => array(
					'label'       => __( 'Job category', 'job_manager' ),
					'type'        => 'select',
					'required'    => true,
					'options'     => self::job_categories(),
					'placeholder' => '',
					'priority'    => 4
				),
				'job_description' => array(
					'label'       => __( 'Description', 'job_manager' ),
					'type'        => 'job-description',
					'required'    => true,
					'placeholder' => '',
					'priority'    => 5
				),
				'application' => array(
					'label'       => __( 'Application email/URL', 'job_manager' ),
					'type'        => 'text',
					'required'    => true,
					'placeholder' => __( 'Enter an email address or website URL', 'job_manager' ),
					'priority'    => 6
				)
			),
			'company' => array(
				'company_name' => array(
					'label'       => __( 'Company name', 'job_manager' ),
					'type'        => 'text',
					'required'    => true,
					'placeholder' => __( 'Enter the name of the company', 'job_manager' ),
					'priority'    => 1
				),
				'company_website' => array(
					'label'       => __( 'Website', 'job_manager' ),
					'type'        => 'text',
					'required'    => false,
					'placeholder' => __( 'http://', 'job_manager' ),
					'priority'    => 2
				),
				'company_tagline' => array(
					'label'       => __( 'Tagline', 'job_manager' ),
					'type'        => 'text',
					'required'    => false,
					'placeholder' => __( 'Briefly describe your company', 'job_manager' ),
					'maxlength'   => 64,
					'priority'    => 3
				),
				'company_twitter' => array(
					'label'       => __( 'Twitter username', 'job_manager' ),
					'type'        => 'text',
					'required'    => false,
					'placeholder' => __( '@yourcompany', 'job_manager' ),
					'priority'    => 4
				),
				'company_logo' => array(
					'label'       => __( 'Logo', 'job_manager' ),
					'type'        => 'file',
					'required'    => false,
					'placeholder' => '',
					'priority'    => 5
				)
			)
		) );

Open in new window


See how each field has a placeholder array key->item?  Enter the default text for the desired fields in between the ''.

Then you need to edit the plugin files and look for something like this:

value="<?php echo isset( $field['value'] ) ? esc_attr( $field['value'] ) : ''; ?>"

Open in new window


to

value="<?php echo isset( $field['value'] ) ? esc_attr( $field['value'] ) : echo esc_attr( $field['placeholder']; ?>"

Open in new window


The problems with the above are:

1) It may not work.  The proposed syntax is correct but there may be other stuff going on that causes it to evaluate improperly.

2) It may be hard to find/located all over the dang place.  If the author is not calling the form fields from a single template location you need to look in both the front end and admin plugin files to get all of the instances

3) It sort of kills the "placeholder" attribute.  A better solution might be to create a new array pair for default value and code that in the above doing something similar but this is looking less like a quick volunteer answer to a question and a lot more like work...

4) It absolutely won't survive a plugin upgrade from the author.

In all seriousness, as good as this plugin is, all it is really doing is creating a custom post type and a version of custom fields.  Your best bet to get the functionality you want is to engage the plugin developer and hope he includes default values in the next release.  Barring that, I wouldn't use the plugin at all and instead go with Easy Custom Post Types and Advanced Custom Fields to create my own Jobs manager.  That would give you a lot more control over the fields without the overhead of someone else's code.  The downside is that you will have to learn how to deal with Custom Post Types and Custom Fields...
0
billypilgrim123Author Commented:
I really appreciate your thorough assistance on this, Jason - if I would be so bold as to ask you one more time for something -and, if it doesn't sound plausible- I'll close this request and give you your due points.

I contacted the author, and he had a couple more suggestions. One was to post another action, the other was to use this filter:

add_filter( 'submit_job_form_fields', 'custom_submit_job_form_fields' );

function custom_submit_job_form_fields(  $fields ) {

$fields['job']['job_title']['label'] = "Contact Name";

return $fields;
}

Open in new window


this time, the filter didn't give me a syntax error (because the $fields variable didn't have two = signs), but when I included this in my functions.php file, there was no change. I suspect I needed to add something else to the filter - but I'm not sure. Anyways, the author gave some more insight here: http://wordpress.org/support/topic/change-field-titles if you wanted to take a peak.

Thanks again for your help!
0
Jason C. LevineNo oneCommented:
but when I included this in my functions.php file, there was no change

That code changes the label on the field and does nothing to set the default value of the field anyway.  The author may be misunderstanding your request.  I would expect the following to be more appropriate:

$fields['job']['job_title']['value'] = "Default Job Title"

Open in new window


But that still may not work as expected.  For one, the author would have to have provided the appropriate hooks to alter the value.  Two, it may override actual itself when the form is displayed for editing (which may or may not be bad).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
billypilgrim123Author Commented:
Appreciate the comprehensive support - unfortunately, I was not able to make this work.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WordPress

From novice to tech pro — start learning today.