Skip to content

Commit

Permalink
add checkbox field for polls and add better message to poll custom fi…
Browse files Browse the repository at this point in the history
…elds
  • Loading branch information
romulodl committed Jun 13, 2018
1 parent a0ae79d commit 264b208
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
30 changes: 23 additions & 7 deletions app/CustomFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions container.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@
return new CroissantPoll\CustomFields();
};

$container['allowed_post_types'] = function($c) {
return [
'post',
'longform'
];
};

return $container;
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );

0 comments on commit 264b208

Please sign in to comment.