Myzwer / foothillschurch

Bootcamp II is a wordpress theme (as well as an inside joke) designed to suit the needs of foothillschurch.com. It makes use of webpack, Babel, Sass, Tailwind, Browsersync, PostCSS, ESLint, Stylelint, Prettier and more. It is meant for that site, but if you can use it by all means go for it.
1 stars 1 forks source link

Simplify the conditions #50

Closed rain2o closed 1 month ago

rain2o commented 1 month ago

These conditions take a minute to understand what's happening.

https://github.com/Myzwer/foothillschurch/blob/effc5bbf81497ae99f0561ab7849412fe9272bfd/linktree.php#L82-L95

They could be simplified a bit. For starters, we could check hide_button first and continue if it's true.

while ( have_rows( 'link' ) ) : the_row();
  if (get_sub_field( 'hide_button' ) !== 'no') continue; ?>

Then we can remove the hide_button condition from these checks.


Also, the HTML looks very similar between prioritized and non-prioritized. You could reduce it to one block of code with conditional classes and img tag. You could either do inline conditions like this

while ( have_rows( 'link' ) ) : the_row();
    if (get_sub_field( 'hide_button' ) !== 'no') continue;
    $prioritize = get_sub_field('prioritize') === 'yes'; ?>
    <div class="col-span-12<?php if ($prioritize) echo ' relative mt-5'; ?>">

or declare the classes like you do in other places

$prioritize = get_sub_field('prioritize') === 'yes';
    $wrapperClass = $prioritize ? ' relative mt-5' : ''; ?>
    <div class="col-span-12<?php echo $wrapperClass; ?>">

It's just up to personal preference at this point. But the advantage is that you're not duplicating HTML, so any changes will only need to be made once (and reduces likelihood of bugs from changing one and not the other).

rain2o commented 1 month ago

Here's another location that could benefit from the same changes mentioned above. https://github.com/Myzwer/foothillschurch/blob/effc5bbf81497ae99f0561ab7849412fe9272bfd/resource.php#L63-L76

As a side note - this file also has really messed up indentation making it really difficult to follow.

rain2o commented 1 month ago

Also in components/blocks/card.php, the primary and secondary CTA buttons could probably be simplified into a single block with some conditional classes, just to avoid duplicate HTML that's so similar. https://github.com/Myzwer/foothillschurch/blob/effc5bbf81497ae99f0561ab7849412fe9272bfd/components/blocks/card.php#L56-L80