{"id":1035830,"date":"2015-12-04T18:15:49","date_gmt":"2015-12-05T02:15:49","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/"},"modified":"2015-12-10T08:59:27","modified_gmt":"2015-12-10T16:59:27","slug":"start-time-changes-when-error-message-is-returned","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/","title":{"rendered":"Start Time Changes When Error Message is Returned"},"content":{"rendered":"<p>Hi,<\/p>\n<p>We are using some code you supplied in <a href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/change-the-default-startend-time-for-new-community-events\/\" target=\"_blank\">snippets<\/a> to alter the default Start Time and End Time for events on the Community Events: Submit an Event form. It works fine, except that when an error message is returned (because the user left a required field blank, etc), the Start Time is changed to be the same as the End Time that was entered when the user first tried to submit the form.<\/p>\n<p>We&#8217;ve confirmed that the issue only occurs with this snippet activated. How can we modify this so that when error messages are returned on the Community Events: Submit an Event form, the Start Time that was originally entered is not altered?<\/p>\n<pre><code>\/**\n * Helps to change the default start\/end times for new event.\n *\/\nclass Change_Tribe_Default_Event_Times\n{\n    const TWELVEHOUR     = 12;\n    const TWENTYFOURHOUR = 24;\n\n    protected $start    = 9;\n    protected $end      = 11;\n    protected $mode     = self::TWELVEHOUR;\n    protected $mode_set = false;\n\n    \/**\n     * Provide the desired default start and end hours in 24hr format (ie 15 = 3pm).\n     *\n     * @param $start_hour\n     * @param $end_hour\n     *\/\n    public function __construct( $start_hour, $end_hour ) {\n        $this-&gt;settings( $start_hour, $end_hour );\n        $this-&gt;add_filters();\n    }\n\n    protected function settings( $start_hour, $end_hour ) {\n        $this-&gt;start = $this-&gt;safe_hour( $start_hour );\n        $this-&gt;end   = $this-&gt;safe_hour( $end_hour );\n    }\n\n    protected function add_filters() {\n        add_filter( &#039;tribe_get_hour_options&#039;, array( $this, &#039;change_default_time&#039; ), 10, 3 );\n        add_filter( &#039;tribe_get_meridian_options&#039;, array( $this, &#039;change_default_meridian&#039; ), 10, 3 );\n    }\n\n    protected function set_mode() {\n        if ( $this-&gt;mode_set ) return;\n\n        if ( strstr( get_option(&#039;time_format&#039;, $this-&gt;time_format() ), &#039;H&#039; ) )\n            $this-&gt;mode = self::TWENTYFOURHOUR;\n\n        $this-&gt;mode_set = true;\n    }\n\n    protected function safe_hour( $hour ) {\n        $hour = absint( $hour );\n        if ( $hour &lt; 0 )  $hour = 0;\n        if ( $hour &gt; 23 ) $hour = 23;\n        return $hour;\n    }\n\n    public function change_default_time( $hour, $date, $isStart ) {\n        $this-&gt;set_mode();\n        if ( &#039;post-new.php&#039; !== $GLOBALS[&#039;pagenow&#039;] ) return $hour; \/\/ Only intervene if it&#039;s a new event\n\n        if ( $isStart ) return $this-&gt;corrected_time( $this-&gt;start );\n        else return $this-&gt;corrected_time( $this-&gt;end );\n    }\n\n    \/**\n     * If working in the 12hr clock, converts the hour appropriately.\n     *\n     * @param $hour\n     * @return int\n     *\/\n    protected function corrected_time( $hour ) {\n        $this-&gt;set_mode();\n        if ( self::TWENTYFOURHOUR === $this-&gt;mode ) return $hour;\n        if ( $hour &gt; 12 ) return $hour - 12;\n        return $hour;\n    }\n\n    public function change_default_meridian( $meridian, $date, $isStart ) {\n        if ( &#039;post-new.php&#039; !== $GLOBALS[&#039;pagenow&#039;] ) return $meridian; \/\/ Only intervene if it&#039;s a new event\n\n        $meridian = &#039;am&#039;;\n        if ( $isStart &amp;&amp; 12 &lt;= $this-&gt;start ) $meridian = &#039;pm&#039;;\n        if ( ! $isStart &amp;&amp; 12 &lt;= $this-&gt;end ) $meridian = &#039;pm&#039;;\n\n        if ( strstr( get_option(&#039;time_format&#039;, $this-&gt;time_format() ), &#039;A&#039; ) )\n            $meridian = strtoupper( $meridian );\n\n        return $meridian;\n    }\n\n    protected function time_format() {\n        if ( class_exists( &#039;Tribe__Events__Date_Utils&#039; ) ) return Tribe__Events__Date_Utils::TIMEFORMAT;\n        if ( class_exists( &#039;TribeDateUtils&#039;) ) return TribeDateUtils::TIMEFORMAT;\n        return &#039;g:i A&#039;;\n    }\n}\nnew Change_Tribe_Default_Event_Times(0, 0);\n\n\/\/ Change Start Time on Community Events Submit an Event form\nadd_action( &#039;tribe_community_events_form_start_time_selector&#039;, &#039;comm_default_start_time&#039;, 10, 2 );\nfunction comm_default_start_time( $output, $event_id ) {\n\n    if ( !$event_id ) {\n\n        $new_time = strtotime( &#039;12am&#039; );\n\n        $start_date = tribe_event_format_date( $new_time, true, Tribe__Events__Date_Utils::DBDATETIMEFORMAT );\n\n        $start_minutes     = Tribe__Events__View_Helpers::getMinuteOptions( $start_date, true );\n        $start_hours = Tribe__Events__View_Helpers::getHourOptions( $is_all_day == &#039;yes&#039; ? null : $start_date, true );\n        $start_meridian = Tribe__Events__View_Helpers::getMeridianOptions( $start_date, true );\n\n        $output = &#039;&#039;;\n        $output .= sprintf( &#039;&lt;select name=&quot;EventStartHour&quot;&gt;%s&lt;\/select&gt;&#039;, $start_hours );\n        $output .= sprintf( &#039;&lt;select name=&quot;EventStartMinute&quot;&gt;%s&lt;\/select&gt;&#039;, $start_minutes );\n        if ( ! tribe_community_events_use_24hr_format() ) {\n            $output .= sprintf( &#039;&lt;select name=&quot;EventStartMeridian&quot;&gt;%s&lt;\/select&gt;&#039;, $start_meridian );\n        }\n    }\n\n    return $output;\n}\n\nadd_action( &#039;tribe_community_events_form_end_time_selector&#039;, &#039;comm_default_end_time&#039;, 10, 2 );\nfunction comm_default_end_time( $output, $event_id ) {\n\n    if ( !$event_id ) {\n\n        $new_time = strtotime( &#039;12am&#039; );\n\n        $start_date = tribe_event_format_date( $new_time, true, Tribe__Events__Date_Utils::DBDATETIMEFORMAT );\n\n        $start_minutes     = Tribe__Events__View_Helpers::getMinuteOptions( $start_date, true );\n        $start_hours = Tribe__Events__View_Helpers::getHourOptions( $is_all_day == &#039;yes&#039; ? null : $start_date, true );\n        $start_meridian = Tribe__Events__View_Helpers::getMeridianOptions( $start_date, true );\n\n        $output = &#039;&#039;;\n        $output .= sprintf( &#039;&lt;select name=&quot;EventStartHour&quot;&gt;%s&lt;\/select&gt;&#039;, $start_hours );\n        $output .= sprintf( &#039;&lt;select name=&quot;EventStartMinute&quot;&gt;%s&lt;\/select&gt;&#039;, $start_minutes );\n        if ( ! tribe_community_events_use_24hr_format() ) {\n            $output .= sprintf( &#039;&lt;select name=&quot;EventStartMeridian&quot;&gt;%s&lt;\/select&gt;&#039;, $start_meridian );\n        }\n    }\n\n    return $output;\n}<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-1035830","topic","type-topic","status-closed","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Start Time Changes When Error Message is Returned -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Start Time Changes When Error Message is Returned -\" \/>\n<meta property=\"og:description\" content=\"Hi, We are using some code you supplied in snippets to alter the default Start Time and End Time for events on the Community Events: Submit an Event form. It works fine, except that when an error message is returned (because the user left a required field blank, etc), the Start Time is changed to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/\" \/>\n<meta property=\"article:modified_time\" content=\"2015-12-10T16:59:27+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/\",\"name\":\"Start Time Changes When Error Message is Returned -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2015-12-05T02:15:49+00:00\",\"dateModified\":\"2015-12-10T16:59:27+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/theeventscalendar.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\/\/theeventscalendar.com\/support\/topics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Calendar Products\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Community Events\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/community-events\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Start Time Changes When Error Message is Returned\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\",\"url\":\"https:\/\/theeventscalendar.com\/support\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Start Time Changes When Error Message is Returned -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/","og_locale":"en_US","og_type":"article","og_title":"Start Time Changes When Error Message is Returned -","og_description":"Hi, We are using some code you supplied in snippets to alter the default Start Time and End Time for events on the Community Events: Submit an Event form. It works fine, except that when an error message is returned (because the user left a required field blank, etc), the Start Time is changed to [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/","article_modified_time":"2015-12-10T16:59:27+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/","name":"Start Time Changes When Error Message is Returned -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2015-12-05T02:15:49+00:00","dateModified":"2015-12-10T16:59:27+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/start-time-changes-when-error-message-is-returned\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/theeventscalendar.com\/support\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"https:\/\/theeventscalendar.com\/support\/topics\/"},{"@type":"ListItem","position":3,"name":"Calendar Products","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/"},{"@type":"ListItem","position":4,"name":"Community Events","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/community-events\/"},{"@type":"ListItem","position":5,"name":"Start Time Changes When Error Message is Returned"}]},{"@type":"WebSite","@id":"https:\/\/theeventscalendar.com\/support\/#website","url":"https:\/\/theeventscalendar.com\/support\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1035830","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1035830\/revisions"}],"predecessor-version":[{"id":1036911,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1035830\/revisions\/1036911"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1035830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}