* @package FortyFortyPlugin * @version $Id$ */ /** * Register the 40/40 Prayer Vigil options page. */ function fortyforty_plugin_menu() { add_options_page( __( '40/40 Prayer Vigil Options', 'fortyforty_plugin' ), __( '40/40 Prayer Vigil', 'fortyforty_plugin' ), 'manage_options', '4040-prayer-vigil', 'fortyforty_plugin_options' ); } /** * Register the options with the settings API. */ function fortyforty_register_settings() { $menuSlug = '4040-prayer-vigil'; $optionGroup = sprintf( '%s_main', FortyForty::PLUGIN_OPTION_SET ); register_setting( $menuSlug, FortyForty::PLUGIN_OPTION_SET, 'fortyforty_validate_options' ); add_settings_section( $optionGroup, __( 'Options', 'fortyforty_plugin' ), sprintf( '%s_text', $optionGroup ), $menuSlug ); // Regular settings. add_settings_field( FortyForty::YEAR, __( 'Year', 'fortyforty_plugin' ), 'fortyforty_option_year', $menuSlug, $optionGroup ); add_settings_field( FortyForty::LANGUAGE, __( 'Language', 'fortyforty_plugin' ), 'fortyforty_option_language', $menuSlug, $optionGroup ); add_settings_field( FortyForty::SCRIPTURE_VERSION, __( 'Scripture Version', 'fortyforty_plugin' ), 'fortyforty_option_scripture_version', $menuSlug, $optionGroup ); add_settings_field( FortyForty::TYPE, __( 'Prayer Guide Type', 'fortyforty_plugin' ), 'fortyforty_option_type', $menuSlug, $optionGroup ); add_settings_field( FortyForty::OVERLAP, __( 'Days to Overlap', 'fortyforty_plugin' ), 'fortyforty_option_overlap', $menuSlug, $optionGroup ); // Debugging settings. $debugGroup = sprintf( '%s_debug', FortyForty::PLUGIN_OPTION_SET ); add_settings_section( $debugGroup, __( 'Debugging', 'fortyforty_plugin' ), sprintf( '%s_text', $debugGroup ), $menuSlug ); add_settings_field( FortyForty::DEBUG_DATE, __( 'Force Date or Date/Time', 'fortyforty_plugin' ), 'fortyforty_option_debug_date', $menuSlug, $debugGroup ); add_settings_field( FortyForty::DEBUG_NUMBER, __( 'Force Day/Hour Number', 'fortyforty_plugin' ), 'fortyforty_option_debug_number', $menuSlug, $debugGroup ); } add_action( 'admin_menu', 'fortyforty_plugin_menu' ); add_action( 'admin_init', 'fortyforty_register_settings' ); /** * Handle the option administration for this plugin. */ function fortyforty_plugin_options() { if ( !current_user_can( 'manage_options' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); } ?>

:

:

'; _e( 'These options can be used to force a particular date/time or number to be displayed.', 'fortyforty_plugin' ); _e( 'If they are not valid, they will be blanked when the page is saved.', 'fortyforty_plugin' ); echo '
'; _e( '(The "Number" setting overrides the "Date/Time" setting.)', 'fortyforty_plugin' ); echo '

'; } /** * Display options for the YEAR setting. */ function fortyforty_option_year() { fortyforty_option_dropdown( FortyForty::YEAR, FortyForty::GetOptionList( '/List/Year', 'year' ) ); } /** * Display options for the LANGUAGE setting. */ function fortyforty_option_language() { fortyforty_option_dropdown( FortyForty::LANGUAGE, FortyForty::GetOptionList( '/List/Language', 'language' ) ); } /** * Display options for the SCRIPTURE_VERSION setting. */ function fortyforty_option_scripture_version() { fortyforty_option_dropdown( FortyForty::SCRIPTURE_VERSION, FortyForty::GetOptionList( '/List/Version', 'version' ) ); } /** * Display options for the TYPE setting. */ function fortyforty_option_type() { fortyforty_option_dropdown( FortyForty::TYPE, array( array ( 'id' => 'day', 'value' => 'Daily (40 Days)' ), array( 'id' => 'hour', 'value' => 'Hourly (40 Hours)') )); } /** * Display options for the OVERLAP setting. */ function fortyforty_option_overlap() { fortyforty_option_input( FortyForty::OVERLAP, 2 ); } /** * Display options for the DEBUG_DATE setting. */ function fortyforty_option_debug_date() { fortyforty_option_input(FortyForty::DEBUG_DATE, 20); ?> YYYY-MM-DD YYYY-MM-DD HH:MM:SS " value="" /> $overlap ) ) { return "$overlap"; } } add_action( 'admin_notices', create_function( '', sprintf( 'echo \'

%s

\';', __( 'WARNING: "Overlap" value must be between 0 and 60; value set to 30.', 'fortyforty_plugin' )))); return '30'; } /** * Validate the debug date. * * @param string $inputDate The value input by the user. * @param string $type The prayer guide type. * @return string The debug date, properly formatted. */ function fortyforty_plugin_validate_debug_date( $inputDate, $type ) { if ( empty( $inputDate ) ) return ''; try { $date = new DateTime( $inputDate ); return ( 'hour' == $type ) ? $date->format( 'Y-m-d H:00:00' ) : $date->format( 'Y-m-d' ); } catch (Exception $exception) { // Invalid date; we'll catch that below. } add_action( 'admin_notices', create_function('', sprintf( 'echo \'

%s

\';', __( 'WARNING: "Force Date or Date/Time" was not valid; value cleared.', 'fortyforty_plugin' )))); return ''; } /** * Validate the debug number. * * @param string $inputNumber The value input by the user. * @return string The number to set. */ function fortyforty_plugin_validate_debug_number( $inputNumber ) { if ( is_numeric( $inputNumber ) ) { $number = ( $inputNumber + 0) / 1; if ( ( -1 < $number ) && ( 42 > $number ) ) { return "$number"; } } add_action( 'admin_notices', create_function( '', sprintf( 'echo \'

%s

\';', __( 'WARNING: "Force Day/Hour Number" must be between 0 and 41; value cleared.', 'fortyforty_plugin' )))); return ''; }