Skip to content

Commit

Permalink
fixed - WPCS errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveJonesDev committed May 8, 2024
1 parent 580be93 commit 4ad8448
Show file tree
Hide file tree
Showing 55 changed files with 1,013 additions and 889 deletions.
66 changes: 35 additions & 31 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function eqd_archive_body_class( $classes ) {
function eqd_archive_header() {

$title = false;
$subtitle = false;
$subtitle = false; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Leaving for future use.
$description = false;

if ( is_author() ) {
Expand Down Expand Up @@ -93,7 +93,7 @@ function eqd_archive_recommended_post() {

<?php
if ( is_tax() ) {
echo 'Recommended Resources for ' . $term->name;
echo 'Recommended Resources for ' . esc_html( $term->name );
} else {
echo 'Featured articles';
}
Expand All @@ -105,13 +105,13 @@ function eqd_archive_recommended_post() {
$args = array(
'post__in' => $post_recommened,
'post_type' => 'post',
'orderby' => 'post__in', // This will preserve the order of IDs as you provided
'posts_per_page' => -1, // Get all posts matching the criteria
'orderby' => 'post__in', // phpcs:ignore WordPress.VIP.PostsPerPage.posts_per_page_posts_per_page -- This will preserve the order of IDs as you provided.
'posts_per_page' => -1, // Get all posts matching the criteria.
);

$the_query = new WP_Query( $args );

// The Loop
// The Loop.
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
Expand All @@ -120,7 +120,7 @@ function eqd_archive_recommended_post() {
<figure>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail(); // This will output the featured image with default settings
the_post_thumbnail(); // This will output the featured image with default settings.
}
?>
<?php
Expand All @@ -135,7 +135,7 @@ function eqd_archive_recommended_post() {
?>
</figure>
<div class="date">
<?php echo get_the_date(); // This will output the date the post was published ?>
<?php echo get_the_date(); // This will output the date the post was published. ?>
</div>
<h3 class="title"><?php echo wp_kses_post( get_the_title() ); ?></h3>
<div class="author">
Expand All @@ -151,10 +151,9 @@ function eqd_archive_recommended_post() {

<?php
}
/* Restore original Post Data */
wp_reset_postdata();
} else {
// No posts found
// No posts found.
echo 'No posts found';
}
?>
Expand All @@ -166,36 +165,41 @@ function eqd_archive_recommended_post() {
}
add_action( 'tha_content_before_container', 'eqd_archive_recommended_post' );

/**
* Archive Recommended CTA.
*
* @return void
*/
function eqd_archive_recommended_cta() {
$term = get_queried_object();
$cta = get_field( 'cta', $term );

if ( $cta ) :
if ( ! is_paged() ) :
?>
<section class="archive_cta">
<div class="archive_cta_container">
<?php if ( ! empty( $cta['image'] ) ) : ?>
<div class="archive_cta_container_figure">
<img src="<?php echo wp_kses_post( $cta['image']['url'] ); ?>" alt="<?php echo wp_kses_post( $cta['title'] ); ?>">
</div>
<?php endif; ?>
<?php if ( ! empty( $cta['title'] ) ) : ?>
<div class="archive_cta_container_copy">
<h2 class="title"><?php echo wp_kses_post( $cta['title'] ); ?></h2>
<div class="copy">
<?php echo wp_kses_post( $cta['copy'] ); ?>
</div>
<div class="form">
<?php echo do_shortcode( $cta['form_code'] ); ?>
</div>
</div>
<?php endif; ?>
</div>
</section>
<section class="archive_cta">
<div class="archive_cta_container">
<?php if ( ! empty( $cta['image'] ) ) : ?>
<div class="archive_cta_container_figure">
<img src="<?php echo wp_kses_post( $cta['image']['url'] ); ?>" alt="<?php echo wp_kses_post( $cta['title'] ); ?>">
</div>
<?php endif; ?>
<?php if ( ! empty( $cta['title'] ) ) : ?>
<div class="archive_cta_container_copy">
<h2 class="title"><?php echo wp_kses_post( $cta['title'] ); ?></h2>
<div class="copy">
<?php echo wp_kses_post( $cta['copy'] ); ?>
</div>
<div class="form">
<?php echo do_shortcode( $cta['form_code'] ); ?>
</div>
</div>
<?php endif; ?>
</div>
</section>
<?php
endif;
endif;
endif;
endif;
}
add_action( 'tha_content_before_container', 'eqd_archive_recommended_cta' );

Expand Down
35 changes: 29 additions & 6 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@
return;
}

/**
* Has children.
*
* @param int $comment_id The comment ID.
* @return boolean
*/
function has_children( $comment_id ) {
$children = get_comments( array( 'parent' => $comment_id ) );
return ! empty( $children );
}

/**
* Add class to comment with children.
*
* @param array $classes The comment classes.
* @return array
*/
function add_class_to_comment_with_children( $classes ) {
global $comment;
if ( has_children( $comment->comment_ID ) ) {
Expand All @@ -32,7 +44,15 @@ function add_class_to_comment_with_children( $classes ) {
add_filter( 'comment_class', 'add_class_to_comment_with_children' );

if ( ! function_exists( 'comments_callback' ) ) :


/**
* Comments callback.
*
* @param string $comment The comment.
* @param array $args The arguments.
* @param int $depth The depth.
* @return void
*/
function comments_callback( $comment, $args, $depth ) {
?>

Expand All @@ -41,19 +61,22 @@ function comments_callback( $comment, $args, $depth ) {
<div class="comment-container">
<div class="comment-author">
<div class="comment-authorimg">
<img src="<?php echo get_avatar_url( $comment->user_id, 32 ); ?>" alt="">
<img src="<?php echo esc_url( get_avatar_url( $comment->user_id, 32 ) ); ?>" alt="">
</div>
<div class="author-info">
<strong><?php echo get_comment_author(); ?></strong>
<strong><?php echo esc_html( get_comment_author() ); ?></strong>
<span class="date align-right">
<?php printf( esc_html__( '%1$s at %2$s', '5balloons_theme' ), get_comment_date(), get_comment_time( 'g:i A' ) ); ?>
<?php
/* translators: 1: comment date, 2: comment time */
printf( esc_html__( '%1$s at %2$s', 'eqd' ), esc_html( get_comment_date() ), esc_html( get_comment_time( 'g:i A' ) ) );
?>
</span>
</div>
</div>

<div class="comment-block">
<?php if ( $comment->comment_approved === '0' ) : ?>
<em><?php esc_html_e( 'Your comment is awaiting moderation.', '5balloons_theme' ); ?></em>
<?php if ( '0' === $comment->comment_approved ) : ?>
<em><?php esc_html_e( 'Your comment is awaiting moderation.', 'eqd' ); ?></em>
<?php endif; ?>

<span class="comment-by">
Expand Down
53 changes: 33 additions & 20 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,16 @@ function eqd_template_hierarchy( $template ) {
*
* @return array The modified query arguments.
*/
function npp_custom_acf_post_object_query( $args, $field, $post_id ) {
function eqd_custom_acf_post_object_query( $args, $field, $post_id ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- ACF hook.
// Check if the field being queried is named 'recommended_posts'.
if ( $field['name'] === 'recommended_posts' ) {
if ( 'recommended_posts' === $field['name'] ) {
// Modify the query to search for post titles only.
$args['post_type'] = 'post';
// $args['s'] = ''; // Clear any previous search query.
$args['post_type'] = 'post';
$args['search_columns'] = array( 'post_title' );
}
return $args;
}
add_filter( 'acf/fields/post_object/query', 'npp_custom_acf_post_object_query', 10, 3 );
add_filter( 'acf/fields/post_object/query', 'eqd_custom_acf_post_object_query', 10, 3 );

/**
* Filters the query arguments for the 'recommendedfeatured_posts' ACF Post Object field.
Expand All @@ -336,7 +335,7 @@ function npp_custom_acf_post_object_query( $args, $field, $post_id ) {
*
* @return array Modified query arguments.
*/
function npp_filter_post_object_query( $args, $field, $post_id ) {
function eqd_filter_post_object_query( $args, $field, $post_id ) {
// Check if this is the specific field we want to modify.
if ( 'recommendedfeatured_posts' === $field['name'] ) {

Expand All @@ -347,7 +346,7 @@ function npp_filter_post_object_query( $args, $field, $post_id ) {

// Check if term belongs to the specified taxonomies.
if ( $term instanceof WP_Term && in_array( $term->taxonomy, array( 'category', 'post_tag', 'slp_occupation' ), true ) ) {
$args['tax_query'] = array(
$args['tax_query'] = array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- This is a necessary query.
array(
'taxonomy' => $term->taxonomy,
'field' => 'term_id',
Expand All @@ -361,30 +360,44 @@ function npp_filter_post_object_query( $args, $field, $post_id ) {

return $args;
}
add_filter( 'acf/fields/post_object/query', 'npp_filter_post_object_query', 10, 3 );
add_filter( 'acf/fields/post_object/query', 'eqd_filter_post_object_query', 10, 3 );

function modify_post_object_query( $args, $field, $post_id ) {
// Check if the parent block is 'acf/recommended-posts-block'
if ( isset( $field['parent'] ) && $field['parent'] === 'block_acf/recommended-posts-block' ) {
// If there's a search term, modify the query to search by title only
/**
* Modify the query for the 'recommended_posts' field to search by title only.
*
* @param array $args The original query arguments.
* @param array $field Information about the ACF field.
* @param int $post_id The ID of the current post being edited, if applicable.
* @return array
*/
function eqd_modify_post_object_query( $args, $field, $post_id ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
// Check if the parent block is 'acf/recommended-posts-block'.
if ( isset( $field['parent'] ) && 'block_acf/recommended-posts-block' === $field['parent'] ) {
// If there's a search term, modify the query to search by title only.
if ( isset( $args['s'] ) ) {
// Set search term to a variable
// Set search term to a variable.
$search_term = $args['s'];

// Modify the query
unset( $args['s'] ); // Remove default search
$args['post_title_like'] = $search_term; // Add title search
// Modify the query.
unset( $args['s'] ); // Remove default search.
$args['post_title_like'] = $search_term; // Add title search.
}
}

// Return the modified arguments
return $args;
}
add_filter( 'acf/fields/post_object/query', 'modify_post_object_query', 10, 3 );
add_filter( 'acf/fields/post_object/query', 'eqd_modify_post_object_query', 10, 3 );

/**
* This function modifies the query for the 'recommended_posts' field to search by title only.
*
* @param string $where The original WHERE clause.
* @param object $wp_query The WP_Query object.
* @return string
*/
function title_like_posts_where( $where, $wp_query ) {
global $wpdb;
if ( $post_title_like = $wp_query->get( 'post_title_like' ) ) {
$post_title_like = $wp_query->get( 'post_title_like' );
if ( $post_title_like ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( $wpdb->esc_like( $post_title_like ) ) . '%\'';
}
return $where;
Expand Down
33 changes: 16 additions & 17 deletions header.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

/**
* Site Header
* Site Header.
*
* @package Equalize Digital Base Theme
* @author Equalize Digital
* @since 1.0.0
* @license GPL-2.0+
**/

?>

<!DOCTYPE html>
Expand All @@ -23,7 +23,7 @@
</head>

<?php
$featured_press_classes = is_post_type_archive( 'eqd-featured-press' ) ? 'press-archive-page' : '';
$featured_press_classes = is_post_type_archive( 'eqd-featured-press' ) ? 'press-archive-page' : ''; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Leaving for future use.
$body_classes = implode( ' ', get_body_class() );

if ( is_post_type_archive( 'eqd-featured-press' ) ) {
Expand Down Expand Up @@ -56,9 +56,9 @@
$logo = wp_get_attachment_image_src( $custom_logo_id, 'full' );

if ( has_custom_logo() ) {
$site_logo = esc_url( $logo[0] ); // This is your logo's URL
$site_logo = esc_url( $logo[0] );
} else {
$site_logo = esc_url( get_stylesheet_directory_uri() ) . '/images/default-logo.png'; // Path to default logo
$site_logo = esc_url( get_stylesheet_directory_uri() ) . '/images/default-logo.png';
}

?>
Expand Down Expand Up @@ -91,29 +91,28 @@
</div>
<?php
} else {
// Check if 'slug' is set in the URL parameters
if ( isset( $_GET['landing_page'] ) ) {
$page_slug = $_GET['landing_page'];
// Check if 'slug' is set in the URL parameters.
if ( isset( $_GET['landing_page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Used to get the landing page slug.
$page_slug = sanitize_text_field( $_GET['landing_page'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Used to get the landing page slug.

// Query for the page by slug
$args = array(
// Query for the page by slug.
$args = array(
'post_type' => 'slp_landing',
'post_status' => 'publish',
'numberposts' => 1,
'meta_query' => array(
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Meta query is needed.
array(
'key' => 'landing_page_url_text',
'value' => $page_slug,
'compare' => '=',
),
),
);
$page = get_posts( $args );

// If the page exists, redirect or load the page
if ( $page ) {
$page_id = $page[0]->ID;
$landing_page = get_posts( $args );

// If the page exists, redirect or load the page.
if ( $landing_page ) {
$page_id = $landing_page[0]->ID;
$parameter_page = $page_id;
}
}
Expand All @@ -126,7 +125,7 @@
?>

<section class="landing-page-navigation">
<a href="<?php the_field( 'booking_link', $parameter_page ); ?>" class="btn">Get Help</a>
<a href="<?php echo esc_url( get_field( 'booking_link', $parameter_page ) ); ?>" class="btn">Get Help</a>
</section>
<?php endif; ?>

Expand Down
Loading

0 comments on commit 4ad8448

Please sign in to comment.