Beste forumers,
De code maakt deel uit van een plugin tbv de jobmanager in wordpress. De hier getoonde code is als voorbeeld genomen . Ga geen bedijfsinfo tonen op een forum en is ook niet van belang bij het oplossen.
De totale plugin bestaat uit extra velden met een tekst editor een upload voor pdf bestanden en inderdaad een keuze menu. Dit om de sollicitant meer informatie te geven dan standaard aanwezig in de jobmanager. Om dezelfde aanpak als de jobmanger doet heb ik gekozen voor deze manier van codering. De code is open source en wordt tzt gepubliceerd op de site van github.
Mijn dank voor de input en commentaar.
Arend
De totale code tot dusver en wederom tekst zijn aangepast;
<
<?php
/**
* Plugin Name: Extra fields
* Description: Creates extra fields in the add a job of the Job Manager.
* Version: 1.0.3
* Author: Clown
* Author URI:
https://nu.nl
* Requires at least: 5.2
* Requires PHP: 7.2
* License: GPL v2 or later
*/
/**
* Prevent direct access data leaks
**/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'gma_wpjmef_add_support_link_to_plugin_page' );
// Submit form filters
add_filter( 'submit_job_form_fields', 'gma_wpjmef_frontend_add_omschrijving_field');
add_filter( 'submit_job_form_fields', 'gma_wpjmef_frontend_add_doelgroep_info_field');
// Text fields filters
add_filter( 'job_manager_job_listing_data_fields', 'gma_wpjmef_admin_add_omschrijving_field' ); // #
add_filter( 'job_manager_job_listing_data_fields', 'gma_wpjmef_admin_add_doelgroep_info_field' );
// Single Job page filters
add_action( 'single_job_listing_meta_end', 'gma_wpjmef_display_job_omschrijving_data' );
add_action( 'single_job_listing_meta_end', 'gma_wpjmef_display_doelgroep_info_data' );
// Dashboard: Job Listings > Jobs filters
add_filter( 'manage_edit-job_listing_columns', 'gma_wpjmef_retrieve_omschrijving_column' );
add_filter( 'manage_job_listing_posts_custom_column', 'gma_wpjmef_display_omschrijving_column' );
/**
* Sets the job_omschrijving metadata as a new $column that can be used in the back-end
**/
function gma_wpjmef_retrieve_omschrijving_column($columns){
$columns['job_omschrijving'] = __( 'omschrijving', 'extra-field' );
return $columns;
};
/**
* Adds a new case to WP-Job-Manager/includes/admin/class-wp-job-manager-cpt.php
**/
function gma_wpjmef_display_omschrijving_column($column){
global $post;
switch ($column) {
case 'job_omschrijving':
$omschrijving = get_post_meta( $post->ID, '_job_omschrijving', true );
if ( !empty($omschrijving)) {
echo $omschrijving;
} else {
echo '-';
}
break;
}
return $column;
};
/**
* Adds a new optional "omschrijving" text field at the "Submit a Job" form, generated via the [submit_job_form] shortcode
**/
function gma_wpjmef_frontend_add_omschrijving_field( $fields ) {
$fields['job']['job_omschrijving'] = array(
'label' => __( 'Job vacancy information', 'extra-field' ),
'type' => 'file',
'required' => false,
'placeholder' => '',
'omschrijving' => '',
'priority' => '7',
);
return $fields;
}
/**
* Adds a new optional "doelgroep Information" text field at the "Submit a Job" form, generated via the [submit_job_form] shortcode
**/
function gma_wpjmef_frontend_add_doelgroep_info_field( $fields ) {
$fields['job']['job_doelgroep_info'] = array(
'label' => 'Select',
'type' => 'select',
'required' => false,
'placeholder' => '',
'omschrijving' => '',
'priority' => '8',
'options' => array(
'option1' => 'Kies een optie',
'ww.nu.nl' => 'www.nu.nl',
'www.buienradar.nl' => 'www.buienradar.nl'
)
);
return $fields;
}
/**
* Adds a text field to the Job Listing wp-admin meta box named “omschrijving”
**/
function gma_wpjmef_admin_add_omschrijving_field( $fields ) {
$fields['_job_omschrijving'] = array(
'label' => __( 'Job vacancy information', 'extra-field' ),
'type' => 'file',
'placeholder' => '',
'omschrijving' => ''
);
return $fields;
}
/**
* Adds a text field to the Job Listing wp-admin meta box named "doelgroep Information"
**/
function gma_wpjmef_admin_add_doelgroep_info_field( $fields ) {
$fields['_job_doelgroep_info'] = array(
'label' => __( 'Target information', 'extra-field' ),
'type' => 'select',
'placeholder' => '',
'omschrijving' => ''
);
return $fields;
}
/**
* Displays "omschrijving" on the Single Job Page, by checking if meta for "_job_omschrijving" exists and is displayed via do_action( 'single_job_listing_meta_end' ) on the template
**/
function gma_wpjmef_display_job_omschrijving_data() {
global $post;
$omschrijving = get_post_meta( $post->ID, '_job_omschrijving', true );
$doelgroep_info = get_post_meta( $post->ID, '_job_doelgroep_info', true );
if ( $omschrijving ) {
echo '<a href="'.( $omschrijving ). ' " target="_blank">Vacature informatie</a><br>';
}
}
/**
* Displays the content of the "doelgroep Information" text-field on the Single Job Page, by checking if meta for "_job_doelgroep_info" exists and is displayed via do_action( 'single_job_listing_meta_end' ) on the template
**/
function gma_wpjmef_display_doelgroep_info_data() {
global $post;
$doelgroep_info = get_post_meta( $post->ID, '_job_doelgroep_info', true );
if ( $doelgroep_info ) {
echo '<a href= "'.($doelgroep_info). ' " target="_blank">Doelgroep</a><br>';
}
}
/**
* Display an error message notice in the admin if WP Job Manager is not active
*/
function gma_wpjmef_admin_notice__error() {
$class = 'notice notice-error';
$message = __( 'An error has occurred. WP Job Manager must be installed in order to use this plugin', 'extra-field' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
}
>