Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active January 18, 2017 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/5426f8d7e592eb99a128d663aec87b01 to your computer and use it in GitHub Desktop.
Save tommcfarlin/5426f8d7e592eb99a128d663aec87b01 to your computer and use it in GitHub Desktop.
<?php
private function load_dates() {
$options = get_option( 'acme_date_options' );
$event_settings = $options['event'];
$import = $event_settings['import'];
$post_type = $event_settings['post-type'];
if ( ( 0 === strcmp( 'yes', $import ) ) && ( 0 === strcmp( 'events', $post_type ) ) ) {
// This is where you take whatever action you want.
}
}
<?php
private function load_dates() {
$options = get_option( 'acme_date_options' );
if ( ! isset( $options['event'] ) ) {
return;
}
$event_settings = $options['event'];
if ( ! isset( $event_settings['import'] ) || ! isset( $event_settings['post-type'] ) ) {
return;
}
$import = $event_settings['import'];
$post_type = $event_settings['post-type'];
if ( ( 0 === strcmp( 'yes', $import ) ) && ( 0 === strcmp( 'events', $post_type ) ) ) {
// This is where you take whatever action you want.
}
}
<?php
private function has_valid_option( $option ) {
return isset( $option );
}
private function has_valid_values( $value1, $value2 ) {
return ! ( isset( $value1 ) && isset( $value2 ) );
}
private function can_import_data( $value1, $value2 ) {
return
( 0 === strcmp( 'yes', $value1 ) ) &&
( 0 === strcmp( 'events', $value2 ) );
}
<?php
private function load_dates() {
$options = get_option( 'acme_date_options' );
if ( ! $this->has_valid_option( $options ) ) {
return;
}
$event_settings = $options['event'];
if ( ! $this->has_valid_values( $event_settings['import'], $event_settings['post-type'] ) ) {
return;
}
$import = $event_settings['import'];
$post_type = $event_settings['post-type'];
if ( $this->can_import_data( $import, $post_type ) ) {
// This is where you take whatever action you want.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment