Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active Jan 18, 2017
Embed
What would you like to do?
<?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