options = get_option( $this->option_name ); ?>

AX LogWriter Settings

option_name, // Option name array( $this, 'sanitize' ) // Sanitize ); add_settings_section( 'axlw_general_section', // ID 'General Settings', // Title array( $this, 'print_section_info' ), // Callback 'axlw-setting-admin' // Page ); add_settings_field( 'error_type', // ID 'Error Type', // Title array( $this, 'error_type_callback' ), // Callback 'axlw-setting-admin', // Page 'axlw_general_section' // Section ); add_settings_field( 'error_log_path', 'CUSTOM Error Log Path (only for CUSTOM error type)', array( $this, 'error_log_path_callback' ), 'axlw-setting-admin', 'axlw_general_section' ); add_settings_field( 'error_log_name', 'CUSTOM Error Log Name (only for CUSTOM error type)', array( $this, 'error_log_name_callback' ), 'axlw-setting-admin', 'axlw_general_section' ); add_settings_field( 'error_log_timezone', 'TIMEZONE', array( $this, 'error_log_timezone_callback' ), 'axlw-setting-admin', 'axlw_general_section' ); } /** * Sanitize each setting field as needed * * @param array $input Contains all settings fields as array keys */ public function sanitize( $input ) { $new_input = array(); if( isset( $input['error_type'] ) ) { $new_input['error_type'] = sanitize_text_field( $input['error_type'] ); // Cannot be blank if( empty( $new_input['error_type'] ) ) { add_settings_error( $this->option_name.'[error_type]', // Setting title esc_attr( 'settings_updated' ), // Error ID 'Please select a valid VALUE for Error Type', // Error message 'error' // Type of message ); $new_input['error_type'] = $this->defaults['error_type']; } // Verify the value if( $new_input['error_type'] != "SYSTEM" && $new_input['error_type'] != "APACHE" && $new_input['error_type'] != "CUSTOM" ) { add_settings_error( $this->option_name.'[error_type]', // Setting title esc_attr( 'settings_updated' ), // Error ID 'Please select a valid VALUE for Error Type', // Error message 'error' // Type of message ); $new_input['error_type'] = $this->defaults['error_type']; } } else { // Set it to the default value $new_input['error_type'] = $this->defaults['error_type']; } if( isset( $input['error_log_path'] ) ) { $new_input['error_log_path'] = sanitize_text_field( $input['error_log_path'] ); // Cannot be blank if( empty( $new_input['error_log_path'] ) ) { add_settings_error( $this->option_name.'[error_log_path]', // Setting title esc_attr( 'settings_updated' ), // Error ID 'Please enter a valid VALUE for CUSTOM Error Log Path', // Error message 'error' // Type of message ); $new_input['error_log_path'] = $this->defaults['error_log_path']; } // Verify if dir exists and i writable if( !is_dir( $new_input['error_log_path'] ) or !is_writable( $new_input['error_log_path'] ) ) { add_settings_error( $this->option_name.'[error_log_path]', // Setting title esc_attr( 'settings_updated' ), // Error ID 'CUSTOM Error Log Path not exist or is not writable', // Error message 'error' // Type of message ); $new_input['error_log_path'] = $this->defaults['error_log_path']; } } else { // Set it to the default value $new_input['error_log_path'] = $this->defaults['error_log_path']; } if( isset( $input['error_log_name'] ) ) { $new_input['error_log_name'] = sanitize_text_field( $input['error_log_name'] ); // Cannot be blank if( empty( $new_input['error_log_name'] ) ) { add_settings_error( $this->option_name.'[error_log_name]', // Setting title esc_attr( 'settings_updated' ), // Error ID 'Please enter a valid VALUE for CUSTOM Error Log Name', // Error message 'error' // Type of message ); $new_input['error_log_name'] = $this->defaults['error_log_name']; } } else { // Set it to the default value $new_input['error_log_name'] = $this->defaults['error_log_name']; } if( isset( $input['error_log_timezone'] ) ) { $new_input['error_log_timezone'] = sanitize_text_field( $input['error_log_timezone'] ); // Cannot be blank if( empty( $new_input['error_log_timezone'] ) ) { add_settings_error( $this->option_name.'[error_log_timezone]', // Setting title esc_attr( 'settings_updated' ), // Error ID 'Please enter a valid VALUE for TIMEZONE', // Error message 'error' // Type of message ); $new_input['error_log_timezone'] = $this->defaults['error_log_timezone']; } // Verify the value if( function_exists( "timezone_identifiers_list" ) ) { $zones = timezone_identifiers_list() ; if( empty( $zones ) or !in_array( $new_input['error_log_timezone'], $zones ) ) { add_settings_error( $this->option_name.'[error_log_timezone]', // Setting title esc_attr( 'settings_updated' ), // Error ID 'Please select a valid VALUE for TIMEZONE', // Error message 'error' // Type of message ); $new_input['error_log_timezone'] = $this->defaults['error_log_timezone']; } } } else { // Set it to the default value $new_input['error_log_timezone'] = $this->defaults['error_log_timezone']; } return $new_input; } /** * Print the Section text */ public function print_section_info() { print 'Enter your settings below:'; } /** * Get the settings option array and print one of its values */ public function error_type_callback() { $selected = isset( $this->options['error_type'] ) ? $this->options['error_type'] : $this->defaults['error_type'] ; $select_options = array( 'SYSTEM' => array( 'SYSTEM', 'log will be written by SYSLOG' ), 'APACHE' => array( 'APACHE', 'log will be written by APACHE error log' ), 'CUSTOM' => array( 'CUSTOM', 'log will be written into setted CUSTOM Error Log Path' ) ) ; print '' ; // Desciption text print ' use this to set where the log will be written ' ; } /** * Get the settings option array and print one of its values */ public function error_log_path_callback() { printf( '', isset( $this->options['error_log_path'] ) ? esc_attr( $this->options['error_log_path']) : esc_attr( $this->defaults['error_log_path']) ); // Desciption text print ' this path will be used in CUSTOM mode. This path must exist and must be writable. E.g. /your/custom/path/' ; } /** * Get the settings option array and print one of its values */ public function error_log_name_callback() { printf( '', isset( $this->options['error_log_name'] ) ? esc_attr( $this->options['error_log_name']) : esc_attr( $this->defaults['error_log_name']) ); } /** * Get the settings option array and print one of its values */ public function error_log_timezone_callback() { if( !function_exists( "timezone_identifiers_list" ) ) { printf( '', isset( $this->options['error_log_timezone'] ) ? esc_attr( $this->options['error_log_timezone']) : esc_attr( $this->defaults['error_log_timezone']) ); } else { $zones = timezone_identifiers_list() ; $selected = isset( $this->options['error_log_timezone'] ) ? $this->options['error_log_timezone'] : $this->defaults['error_log_timezone'] ; print '' ; } // Desciption text print ' Used to prevent WP timezone bug. Use your current server timezone.' ; } } if( is_admin() ) $axlw_settings_page = new axLogWriterSettingsPage();