diff --git a/app/CustomFields.php b/app/CustomFields.php index 8b17a9a..34135dc 100644 --- a/app/CustomFields.php +++ b/app/CustomFields.php @@ -18,13 +18,13 @@ public function register_poll_fields() { 'fields' => [ [ 'key' => $key . 'awswers', - 'label' => 'Poll answer list', + 'label' => 'Poll answer list (please do not reorder them once the poll is published)', 'name' => $key . 'answers', 'type' => 'repeater', 'sub_fields' => [ [ 'key' => $key . 'text', - 'label' => 'Answers for the poll', + 'label' => 'Answers for the poll (please do not reorder them once the poll is published)', 'name' => $key . 'text', 'type' => 'text', ], @@ -64,13 +64,29 @@ public function register_article_fields( array $post_types ) { 'title' => 'Poll', 'fields' => [ [ - 'key' => $key, - 'name' => $key, - 'label' => 'Select a Poll', - 'type' => 'post_object', - 'post_type' => 'poll', + 'key' => 'article_has_poll', + 'name' => 'article_has_poll', + 'label' => 'Post contains a poll?', + 'type' => 'true_false', 'placement' => 'left', ], + [ + 'key' => $key, + 'name' => $key, + 'label' => 'Select a Poll', + 'type' => 'post_object', + 'post_type' => 'poll', + 'placement' => 'left', + 'conditional_logic' => [ + [ + [ + 'field' => 'article_has_poll', + 'operator' => '==', + 'value' => '1', + ], + ], + ], + ], ], 'location' => $locations, 'menu_order' => 3, diff --git a/container.php b/container.php index aedeaf6..feabdc9 100644 --- a/container.php +++ b/container.php @@ -10,4 +10,11 @@ return new CroissantPoll\CustomFields(); }; +$container['allowed_post_types'] = function($c) { + return [ + 'post', + 'longform' + ]; +}; + return $container; diff --git a/plugin.php b/plugin.php index f45c469..9bcc35b 100644 --- a/plugin.php +++ b/plugin.php @@ -22,6 +22,6 @@ $acf = $container['custom_fields']; $acf->register_poll_fields(); - $acf->register_article_fields(['post', 'longform']); + $acf->register_article_fields($container['allowed_post_types']); $acf->load_filters(); } );