{"action":"created","issue":{"url":"https://api.github.com/repos/wp-papi/papi/issues/88","labels_url":"https://api.github.com/repos/wp-papi/papi/issues/88/labels{/name}","comments_url":"https://api.github.com/repos/wp-papi/papi/issues/88/comments","events_url":"https://api.github.com/repos/wp-papi/papi/issues/88/events","html_url":"https://github.com/wp-papi/papi/issues/88","id":104636541,"number":88,"title":"Don't use strict type checking when marking selected items in a dropdown","user":{"login":"richardsweeney","id":761071,"avatar_url":"https://avatars.githubusercontent.com/u/761071?v=3","gravatar_id":"","url":"https://api.github.com/users/richardsweeney","html_url":"https://github.com/richardsweeney","followers_url":"https://api.github.com/users/richardsweeney/followers","following_url":"https://api.github.com/users/richardsweeney/following{/other_user}","gists_url":"https://api.github.com/users/richardsweeney/gists{/gist_id}","starred_url":"https://api.github.com/users/richardsweeney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richardsweeney/subscriptions","organizations_url":"https://api.github.com/users/richardsweeney/orgs","repos_url":"https://api.github.com/users/richardsweeney/repos","events_url":"https://api.github.com/users/richardsweeney/events{/privacy}","received_events_url":"https://api.github.com/users/richardsweeney/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-03T07:21:24Z","updated_at":"2015-09-03T07:28:26Z","closed_at":null,"body":"In class Papi_Property_Dropdown on line 75 when setting an item as selected the use of '===' is, I think, unnecessary. It caused me quite a few headaches when a numerical value (a post ID for instance) was returned as a string when fetched from the post_meta table and thus was not marked as selected in the dropdown.\r\n\r\n```php\r\n'selected' => $value === $settings->selected ? 'selected' : null\r\n```\r\n\r\nCan I make a plea to change this to\r\n\r\n```php\r\n'selected' => $value == $settings->selected ? 'selected' : null\r\n```\r\n\r\nSay the word and I'll shoot you a pull request!"},"comment":{"url":"https://api.github.com/repos/wp-papi/papi/issues/comments/137359632","html_url":"https://github.com/wp-papi/papi/issues/88#issuecomment-137359632","issue_url":"https://api.github.com/repos/wp-papi/papi/issues/88","id":137359632,"user":{"login":"richardsweeney","id":761071,"avatar_url":"https://avatars.githubusercontent.com/u/761071?v=3","gravatar_id":"","url":"https://api.github.com/users/richardsweeney","html_url":"https://github.com/richardsweeney","followers_url":"https://api.github.com/users/richardsweeney/followers","following_url":"https://api.github.com/users/richardsweeney/following{/other_user}","gists_url":"https://api.github.com/users/richardsweeney/gists{/gist_id}","starred_url":"https://api.github.com/users/richardsweeney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richardsweeney/subscriptions","organizations_url":"https://api.github.com/users/richardsweeney/orgs","repos_url":"https://api.github.com/users/richardsweeney/repos","events_url":"https://api.github.com/users/richardsweeney/events{/privacy}","received_events_url":"https://api.github.com/users/richardsweeney/received_events","type":"User","site_admin":false},"created_at":"2015-09-03T07:28:26Z","updated_at":"2015-09-03T07:28:26Z","body":"Sure thing!\r\n\r\nThis doesn't work: the value of the year retrieved from the database is a string, not an int.\r\n\r\n```php\r\n<?php\r\n\r\nclass Winner_Page_Type extends Papi_Page_Type {\r\n\r\n\t/**\r\n\t* The page type meta options.\r\n\t*\r\n\t* @return array\r\n\t*/\r\n\r\n\tpublic function page_type () {\r\n\t\treturn [\r\n\t\t\t'name'        => __( 'Winner', 'nlg' ),\r\n\t\t\t'description' => __( 'A winner', 'nlg' ),\r\n\t\t\t'post_type'   => [ 'winner' ],\r\n\t\t\t'template'    => 'winner.php',\r\n\t\t];\r\n\t}\r\n\r\n\r\n\t/**\r\n\t * Lazy way to generate an array of years.\r\n\t */\r\n\tprivate function generate_years_for_dropdown() {\r\n\t\t$years = [];\r\n\t\t$start = date( 'Y', strtotime( '-10 years' ) );\r\n\t\t$now   = date( 'Y' );\r\n\r\n\t\tfor ( $now; $now >= $start; $now-- ) {\r\n\t\t\t$years[] = $now;\r\n\t\t}\r\n\r\n\t\treturn $years;\r\n\t}\r\n\r\n    public function register() {\r\n        $this->box( __( 'Additional information', 'nlg' ), [\r\n            papi_property( [\r\n                'type'  => 'text',\r\n                'title' => __( 'Ingress text', 'nlg' ),\r\n                'slug'  => 'ingress',\r\n            ] ),\r\n            papi_property( [\r\n                'type'  => 'dropdown',\r\n                'title' => __( 'Year awarded', 'nlg' ),\r\n                'slug'  => 'year',\r\n                'settings' => [\r\n\t\t\t        'items' => $this->generate_years_for_dropdown(),\r\n                ],\r\n            ] )\r\n        ] );\r\n\r\n    }\r\n\r\n}\r\n```\r\n\r\nBut if change the generate years method to return a string it works:\r\n\r\n```php\r\n\tprivate function generate_years_for_dropdown() {\r\n\t\t$years = [];\r\n\t\t$start = date( 'Y', strtotime( '-10 years' ) );\r\n\t\t$now   = date( 'Y' );\r\n\r\n\t\tfor ( $now; $now >= $start; $now-- ) {\r\n\t\t\t$years[] = (string) $now;\r\n\t\t}\r\n\r\n\t\treturn $years;\r\n\t}\r\n```\r\n\r\n"}}