0 ) {
foreach ( self::$errors as $error )
echo '
' . esc_html( $error ) . '
';
} elseif ( sizeof( self::$messages ) > 0 ) {
foreach ( self::$messages as $message )
echo '' . esc_html( $message ) . '
';
}
}
/**
* Settings page.
*
* Handles the display of the main sportspress settings page in admin.
*
* @access public
* @return void
*/
public static function output() {
global $current_section, $current_tab;
do_action( 'sportspress_settings_start' );
wp_enqueue_script( 'sportspress_settings', SP()->plugin_url() . '/assets/js/admin/settings.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'iris', 'chosen' ), SP()->version, true );
wp_localize_script( 'sportspress_settings', 'localized_strings', array(
'none' => __( 'None', 'sportspress' )
) );
// Include settings pages
self::get_settings_pages();
// Get current tab/section
$current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( $_GET['tab'] );
$current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( $_REQUEST['section'] );
// Save settings if data has been posted
if ( ! empty( $_POST ) )
self::save();
// Add any posted messages
if ( ! empty( $_GET['sp_error'] ) )
self::add_error( stripslashes( $_GET['sp_error'] ) );
if ( ! empty( $_GET['sp_message'] ) )
self::add_message( stripslashes( $_GET['sp_message'] ) );
self::show_messages();
// Get tabs for the settings page
$tabs = apply_filters( 'sportspress_settings_tabs_array', array() );
include 'views/html-admin-settings.php';
}
/**
* Get a setting from the settings API.
*
* @param mixed $option
* @return string
*/
public static function get_option( $option_name, $default = '' ) {
// Array value
if ( strstr( $option_name, '[' ) ) {
parse_str( $option_name, $option_array );
// Option name is first key
$option_name = current( array_keys( $option_array ) );
// Get value
$option_values = get_option( $option_name, '' );
$key = key( $option_array[ $option_name ] );
if ( isset( $option_values[ $key ] ) )
$option_value = $option_values[ $key ];
else
$option_value = null;
// Single value
} else {
$option_value = get_option( $option_name, null );
}
if ( is_array( $option_value ) )
$option_value = array_map( 'stripslashes', $option_value );
elseif ( ! is_null( $option_value ) )
$option_value = stripslashes( $option_value );
return $option_value === null ? $default : $option_value;
}
/**
* Output admin fields.
*
* Loops though the sportspress options array and outputs each field.
*
* @access public
* @param array $options Opens array to output
*/
public static function output_fields( $options ) {
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( ! isset( $value['id'] ) ) $value['id'] = '';
if ( ! isset( $value['title'] ) ) $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
if ( ! isset( $value['class'] ) ) $value['class'] = '';
if ( ! isset( $value['css'] ) ) $value['css'] = '';
if ( ! isset( $value['default'] ) ) $value['default'] = '';
if ( ! isset( $value['desc'] ) ) $value['desc'] = '';
if ( ! isset( $value['desc_tip'] ) ) $value['desc_tip'] = false;
if ( ! isset( $value['placeholder'] ) ) $value['placeholder'] = '';
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) )
foreach ( $value['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
// Description handling
if ( $value['desc_tip'] === true ) {
$description = '';
$tip = $value['desc'];
} elseif ( ! empty( $value['desc_tip'] ) ) {
$description = $value['desc'];
$tip = $value['desc_tip'];
} elseif ( ! empty( $value['desc'] ) ) {
$description = $value['desc'];
$tip = '';
} else {
$description = $tip = '';
}
if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) {
$description = '' . wp_kses_post( $description ) . '
';
} elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) {
$description = wp_kses_post( $description );
} elseif ( $description ) {
$description = '' . wp_kses_post( $description ) . '';
}
if ( $tip && in_array( $value['type'], array( 'checkbox' ) ) ) {
$tip = '' . $tip . '
';
} elseif ( $tip ) {
$tip = '
';
}
// Switch based on type
switch( $value['type'] ) {
// Section Titles
case 'title':
if ( ! empty( $value['title'] ) ) {
echo '' . esc_html( $value['title'] ) . '
';
}
if ( ! empty( $value['desc'] ) ) {
echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) );
}
echo '';
if ( ! empty( $value['id'] ) ) {
do_action( 'sportspress_settings_' . sanitize_title( $value['id'] ) . '_after' );
}
break;
// Standard text inputs and subtypes like 'number'
case 'text':
case 'email':
case 'number':
case 'color' :
case 'password' :
$type = $value['type'];
$class = '';
$option_value = self::get_option( $value['id'], $value['default'] );
if ( $value['type'] == 'color' ) {
$type = 'text';
$value['class'] .= 'colorpick';
$description .= '';
}
?>
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
$value )
update_option( $name, $value );
return true;
}
/**
* Configure sport
*
* @access public
* @return void
*/
public static function configure_sport( $sport ) {
// Get array of taxonomies to insert
$term_groups = sp_array_value( $sport, 'term', array() );
foreach( $term_groups as $taxonomy => $terms ):
// Find empty terms and destroy
$allterms = get_terms( $taxonomy, 'hide_empty=0' );
foreach( $allterms as $term ):
if ( $term->count == 0 )
wp_delete_term( $term->term_id, $taxonomy );
endforeach;
// Insert terms
foreach( $terms as $term ):
wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
endforeach;
endforeach;
// Get array of post types to insert
$post_groups = sp_array_value( $sport, 'posts', array() );
// Loop through each post type
foreach( $post_groups as $post_type => $posts ):
$args = array(
'post_type' => $post_type,
'numberposts' => -1,
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_sp_preset',
'value' => 1
)
)
);
// Delete posts
$old_posts = get_posts( $args );
foreach( $old_posts as $post ):
wp_delete_post( $post->ID, true);
endforeach;
// Add posts
foreach( $posts as $index => $post ):
// Make sure post doesn't overlap
if ( ! get_page_by_path( $post['post_name'], OBJECT, $post_type ) ):
// Translate post title
$post['post_title'] = __( $post['post_title'], 'sportspress' );
// Set post type
$post['post_type'] = $post_type;
// Increment menu order by 2 and publish post
$post['menu_order'] = $index * 2 + 2;
$post['post_status'] = 'publish';
$id = wp_insert_post( $post );
// Flag as preset
update_post_meta( $id, '_sp_preset', 1 );
// Update meta
if ( array_key_exists( 'meta', $post ) ):
foreach ( $post['meta'] as $key => $value ):
update_post_meta( $id, $key, $value );
endforeach;
endif;
// Update terms
if ( array_key_exists( 'tax_input', $post ) ):
foreach ( $post['tax_input'] as $taxonomy => $terms ):
wp_set_object_terms( $id, $terms, $taxonomy, false );
endforeach;
endif;
endif;
endforeach;
endforeach;
update_option( 'sportspress_primary_result', 0 );
}
}
endif;