Validate form input
This commit is contained in:
parent
3a97551bf1
commit
abd8c65ee7
5 changed files with 168 additions and 150 deletions
|
@ -215,8 +215,8 @@ if ( ! function_exists( 'omphaloskepsis_fonts_url' ) ) :
|
|||
if ( $fonts ) {
|
||||
$fonts_url = add_query_arg(
|
||||
array(
|
||||
'family' => urlencode( implode( '|', $fonts ) ),
|
||||
'subset' => urlencode( $subsets ),
|
||||
'family' => rawurlencode( implode( '|', $fonts ) ),
|
||||
'subset' => rawurlencode( $subsets ),
|
||||
),
|
||||
'https://fonts.googleapis.com/css'
|
||||
);
|
||||
|
@ -452,6 +452,7 @@ function omphaloskepsis_the_content( $content ) {
|
|||
global $post;
|
||||
if ( 'program' === $post->post_type ) {
|
||||
// phpcs:disable Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
|
||||
// phpcs:disable WordPress.CodeAnalysis.AssignmentInCondition.Found
|
||||
if ( $meta = get_post_meta( $post->ID, 'Link', true ) ) {
|
||||
$links = $links . '<a class="hyperlink-button" target="_blank" href="' . $meta . '">Download</a>';
|
||||
}
|
||||
|
@ -517,10 +518,14 @@ function display_companies() {
|
|||
echo '<th>Associated Items</th>';
|
||||
echo '</tr>';
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
// phpcs:disable WordPress.PHP.YodaConditions.NotYoda
|
||||
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated
|
||||
if ( $_POST['toplevel'] == 'true' ) {
|
||||
if ( isset( $_SERVER['REQUEST_METHOD'] ) && ( 'POST' === $_SERVER['REQUEST_METHOD'] ) ) {
|
||||
if ( ! isset( $_POST['settings_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( filter_input( INPUT_POST, 'settings_nonce' ) ), 'experience' ) ) {
|
||||
echo '<tr><td>Error</td></tr>';
|
||||
wp_die( 'Invalid nonce' );
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
|
||||
if ( isset( $_POST['toplevel'] ) && 'true' === $_POST['toplevel'] ) {
|
||||
// Gets all of the top-level company terms.
|
||||
$terms = apply_filters(
|
||||
'taxonomy-images-get-terms',
|
||||
|
@ -544,6 +549,7 @@ function display_companies() {
|
|||
);
|
||||
$include = 0;
|
||||
}
|
||||
// phpcs:enable
|
||||
|
||||
if ( ! empty( $terms ) ) {
|
||||
foreach ( $terms as $term ) {
|
||||
|
@ -563,6 +569,8 @@ function display_companies() {
|
|||
$term_items = array();
|
||||
$term_item_counts = array();
|
||||
|
||||
// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_tax_query
|
||||
// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
foreach ( $post_types as $post_type ) {
|
||||
$args = array(
|
||||
'posts_per_page' => -1,
|
||||
|
@ -578,7 +586,7 @@ function display_companies() {
|
|||
'meta_query' => array(),
|
||||
);
|
||||
|
||||
if ( $_POST['currentjobs'] == 'true' && $post_type == 'job' ) {
|
||||
if ( isset( $_POST['currentjobs'] ) && 'true' === $_POST['currentjobs'] && 'job' === $post_type ) {
|
||||
$args['meta_query'] = array(
|
||||
array(
|
||||
'key' => 'end-date',
|
||||
|
@ -588,7 +596,7 @@ function display_companies() {
|
|||
);
|
||||
}
|
||||
|
||||
if ( $_POST['showexpired'] != 'true' && $post_type == 'qualification' ) {
|
||||
if ( isset( $_POST['showexpired'] ) && 'true' !== $_POST['showexpired'] && 'qualification' === $post_type ) {
|
||||
$args['meta_query'] = array(
|
||||
array(
|
||||
'key' => 'Expired',
|
||||
|
@ -597,6 +605,7 @@ function display_companies() {
|
|||
),
|
||||
);
|
||||
}
|
||||
// phpcs:enable
|
||||
|
||||
$posts = get_posts( $args );
|
||||
|
||||
|
@ -604,19 +613,19 @@ function display_companies() {
|
|||
array_push( $term_item_counts, count( $posts ) );
|
||||
}
|
||||
|
||||
if ( ( $_POST['job'] == 'true' && $term_item_counts[0] > 0 ) ||
|
||||
( $_POST['post'] == 'true' && $term_item_counts[1] > 0 ) ||
|
||||
( $_POST['website'] == 'true' && $term_item_counts[2] > 0 ) ||
|
||||
( $_POST['program'] == 'true' && $term_item_counts[3] > 0 ) ||
|
||||
( $_POST['writing'] == 'true' && $term_item_counts[4] > 0 ) ||
|
||||
( $_POST['video'] == 'true' && $term_item_counts[5] > 0 ) ||
|
||||
( $_POST['other'] == 'true' && $term_item_counts[6] > 0 ) ||
|
||||
( $_POST['qualification'] == 'true' && $term_item_counts[7] > 0 ) ||
|
||||
( $_POST['award'] == 'true' && $term_item_counts[8] > 0 ) ) {
|
||||
if ( ( isset( $_POST['job'] ) && 'true' === $_POST['job'] && $term_item_counts[0] > 0 ) ||
|
||||
( isset( $_POST['post'] ) && 'true' === $_POST['post'] && $term_item_counts[1] > 0 ) ||
|
||||
( isset( $_POST['website'] ) && 'true' === $_POST['website'] && $term_item_counts[2] > 0 ) ||
|
||||
( isset( $_POST['program'] ) && 'true' === $_POST['program'] && $term_item_counts[3] > 0 ) ||
|
||||
( isset( $_POST['writing'] ) && 'true' === $_POST['writing'] && $term_item_counts[4] > 0 ) ||
|
||||
( isset( $_POST['video'] ) && 'true' === $_POST['video'] && $term_item_counts[5] > 0 ) ||
|
||||
( isset( $_POST['other'] ) && 'true' === $_POST['other'] && $term_item_counts[6] > 0 ) ||
|
||||
( isset( $_POST['qualification'] ) && 'true' === $_POST['qualification'] && $term_item_counts[7] > 0 ) ||
|
||||
( isset( $_POST['award'] ) && 'true' === $_POST['award'] && $term_item_counts[8] > 0 ) ) {
|
||||
$img_url = wp_get_attachment_image_src( $term->image_id, 'full' )[0];
|
||||
$bg_img = ( ! $img_url ) ? '' : ' background-image: url(' . strtok( $img_url, '?' ) . ');';
|
||||
$colour = get_term_meta( $term->term_id, 'color', true );
|
||||
$colour = ( $colour != '' ) ? $colour : 'transparent';
|
||||
$colour = ( '' !== $colour ) ? $colour : 'transparent';
|
||||
|
||||
echo '<tr class="organisation">';
|
||||
echo '<td class="organisation-logo">';
|
||||
|
@ -654,7 +663,7 @@ function display_companies() {
|
|||
} else {
|
||||
echo '<p>No companies found</p>';
|
||||
}
|
||||
// phpcs:enable
|
||||
}
|
||||
die();
|
||||
}
|
||||
add_action( 'wp_ajax_display_companies', 'display_companies' );
|
||||
|
|
|
@ -26,8 +26,8 @@ get_header(); ?>
|
|||
|
||||
<div class="entry-content tile" id="settings">
|
||||
<h3 style="margin-bottom: 14px;" class="subheading">Settings</h3>
|
||||
<form action="/experience-by-companies" id="settings" method="GET">
|
||||
<?php wp_nonce_field( 'experience-by-companies' ); ?>
|
||||
<form action="/experience" id="settings" method="POST">
|
||||
<?php echo wp_kses_post(wp_nonce_field( 'experience', 'settings_nonce' )); ?>
|
||||
<input class="checkbox" type="checkbox" id="toplevel" value="toplevel" checked="checked">
|
||||
<label for="toplevel">Display only top-level organisations</label>
|
||||
<br>
|
||||
|
@ -79,8 +79,14 @@ get_header(); ?>
|
|||
$('.controlgroup').controlgroup();
|
||||
$('.refresh').button();
|
||||
|
||||
// Displays the initial organisations grid.
|
||||
$('#refresh').click(function(event) {
|
||||
$(this).css('border-width', '1px');
|
||||
event.preventDefault();
|
||||
displayCompanies();
|
||||
});
|
||||
|
||||
// Displays the initial organisations grid.
|
||||
$('#refresh').click();
|
||||
|
||||
$('.expired').hide();
|
||||
|
||||
|
@ -104,17 +110,13 @@ get_header(); ?>
|
|||
}
|
||||
});
|
||||
|
||||
$('#refresh').click(function(event) {
|
||||
$(this).css('border-width', '1px');
|
||||
event.preventDefault();
|
||||
displayCompanies();
|
||||
});
|
||||
|
||||
function displayCompanies() {
|
||||
$('#organisations-grid').html('<img class="loading" src="/wp-content/uploads/2016/12/ajax-loader.gif">');
|
||||
|
||||
var settings = {
|
||||
'action': 'display_companies',
|
||||
'settings_nonce': $('#settings_nonce').val(),
|
||||
'toplevel': $('#toplevel').is(':checked'),
|
||||
'job': $('#jobs').is(':checked'),
|
||||
'currentjobs': $('#currentjobs').is(':checked'),
|
||||
|
|
|
@ -607,6 +607,7 @@ html {
|
|||
body > footer {
|
||||
grid-area: footer;
|
||||
margin-top: 1em;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,9 @@
|
|||
|
||||
<main id="split-page" role="main">
|
||||
<?php
|
||||
// phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
|
||||
$company_logo = apply_filters( 'taxonomy-images-queried-term-image-url', '', array( 'image_size' => 'full' ) );
|
||||
// phpcs:enable
|
||||
$company_name = get_queried_object()->name;
|
||||
?>
|
||||
<div id="wrapper">
|
||||
|
@ -130,6 +132,7 @@
|
|||
<div id="parents" class="col-6 col-m-12">
|
||||
<?php
|
||||
if ( get_queried_object()->parent != 0 ) {
|
||||
// phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
|
||||
$parents = apply_filters(
|
||||
'taxonomy-images-get-terms',
|
||||
'',
|
||||
|
@ -141,6 +144,7 @@
|
|||
),
|
||||
)
|
||||
);
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
if ( count( $parents ) > 0 ) :
|
||||
|
@ -162,6 +166,7 @@
|
|||
|
||||
<div id="children" class="col-6 col-m-12">
|
||||
<?php
|
||||
// phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
|
||||
$children = apply_filters(
|
||||
'taxonomy-images-get-terms',
|
||||
'',
|
||||
|
@ -171,6 +176,7 @@
|
|||
'term_args' => array( 'parent' => get_queried_object()->term_id ),
|
||||
)
|
||||
);
|
||||
// phpcs:enable
|
||||
if ( count( $children ) > 0 ) :
|
||||
?>
|
||||
<h2 class="subheading">Child<?php echo ( count( $children ) != 1 ) ? 'ren' : ''; ?></h2>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<header style="background-image: url('<?php the_post_thumbnail_url(); ?>');">
|
||||
<div>
|
||||
<h1 id="post-title">
|
||||
<?php echo esc_html( get_the_title() ); ?>
|
||||
<?php echo wp_kses_post( get_the_title() ); ?>
|
||||
</h1>
|
||||
|
||||
<?php
|
||||
|
@ -171,7 +171,7 @@
|
|||
?>
|
||||
<li>
|
||||
<a href="#section-<?php echo esc_attr( $i++ ); ?>">
|
||||
<?php echo wp_kses_post( $content ); ?>
|
||||
<?php echo wp_kses_post( $section_title ); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
|
|
Reference in a new issue