Skip to content

Commit

Permalink
Merge pull request #104 from UCF/hf-acf-byline
Browse files Browse the repository at this point in the history
Hotfix: Only load in new ACF field groups for v6+
  • Loading branch information
cadie authored Mar 2, 2022
2 parents 7b196bc + 4918f72 commit b7a123c
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 4 deletions.
110 changes: 110 additions & 0 deletions functions/acf-functions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,104 @@
<?php
/**
* Responsible for ACF related functionality
**/

// Exit early if ACF Pro is not activated
if ( ! class_exists( 'acf_pro' ) ) return;


/**
* Adds a Story Version rule type.
*
* @since 6.0.1
* @author Cadie Stockman
* @param array $choices Array of location rule choices
* @return array $choices
**/
function acf_location_rules_types( $choices ) {
$choices['Story']['story_version'] = 'Story Version';

return $choices;
}

add_filter('acf/location/rule_types', 'acf_location_rules_types');


/**
* Adds a 'greater than or equal to' operator
* to the Story Version location rule.
*
* @since 6.0.1
* @author Cadie Stockman
* @param array $choices Array of operator choices for the Story Version location choices.
* @return array $choices
**/
function acf_location_rules_operators_story_version( $choices ) {
$choices['>='] = 'greater than or equal to';

return $choices;
}

add_filter('acf/location/rule_operators/story_version', 'acf_location_rules_operators_story_version');


/**
* Adds 6 as a choice for the Story Version location rule.
*
* @since 6.0.1
* @author Cadie Stockman
* @param array $choices Array of values for the Story Version location rule.
* @return array $choices
**/
function acf_location_rule_values_story_version( $choices ) {
$choices[6] = 6;

return $choices;
}

add_filter('acf/location/rule_values/story_version', 'acf_location_rule_values_story_version');


/**
* Adds functionality to match the custom Story Version
* location rules depending on the selected operator and value.
*
* @since 6.0.1
* @author Cadie Stockman
* @param bool $match The match result.
* @param array $rule The location rule.
* @param array $options The current edit screen data.
* @param array $field_group The field group array.
* @return bool $match
**/
function acf_location_rule_match_story_version( $match, $rule, $options, $field_group ) {
// Check screen args for "post_id" which will exist when editing a post.
// Return false for all other edit screens.
if ( isset( $options['post_id'] ) ) {
$post_id = $options['post_id'];
} else {
return false;
}

// Load the post object for this edit screen.
$post = get_post( $post_id );
if ( !$post ) {
return false;
}

$post_version = get_relevant_version( $post );
$acf_rule_value = intval( $rule['value'] );

$match = false;

if ( $rule['operator'] == ">=" ) {
$match = ( $post_version >= $acf_rule_value );
}

return $match;
}
add_filter('acf/location/rule_match/story_version', 'acf_location_rule_match_story_version', 10, 4);


/**
* Adds the ACF fields for the story sidebar
Expand Down Expand Up @@ -228,6 +328,11 @@ function add_story_sidebar_acf_fields() {
'param' => 'page_template',
'operator' => '!=',
'value' => 'template-fullwidth.php'
),
array(
'param' => 'story_version',
'operator' => '>=',
'value' => '6',
)
),
),
Expand Down Expand Up @@ -276,6 +381,11 @@ function add_full_width_story_acf_fields() {
'param' => 'page_template',
'operator' => '==',
'value' => 'template-fullwidth.php'
),
array(
'param' => 'story_version',
'operator' => '>=',
'value' => '6',
)
),
),
Expand Down
2 changes: 1 addition & 1 deletion versions/v6/static/css/editor-story.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions versions/v6/static/scss/editor-story.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@

.figure-caption,
.wp-caption-dd {
color: #636c72;
font-size: 1rem;
margin-top: .5rem;
color: #636c72;
font-size: 1rem;
margin-top: .5rem;
margin-bottom: 1rem;
}
}
// sass-lint:enable no-ids

0 comments on commit b7a123c

Please sign in to comment.