File: /hosting/kak.bg/web/wp-content/themes/kak/functions.php
<?php
/* CUSTOM AUTHOR WIDGET */
require( get_stylesheet_directory() . '/homepage/widget_home_author_carousel.php' );
/* CUSTOM TABS WIDGET */
require( get_stylesheet_directory() . '/framework/widgets/widget_tabs.php' );
/* CUSTOM SIZE FOR MAIN SLIDER */
add_action( 'after_setup_theme', 'designpicnic_theme_setup' );
if ( ! function_exists( 'fairpixels_theme_setup' ) ):
function designpicnic_theme_setup() {
add_image_size( 'fp1100_375', 1100, 375, true );
}
endif;
/* CUSTOM FIELDS FOR USERS */
add_action('show_user_profile', 'my_show_extra_profile_fields');
add_action('edit_user_profile', 'my_show_extra_profile_fields');
function my_show_extra_profile_fields($user) {
?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="profile_picture">Profile picture</label></th>
<td>
<?php $profile_attachment_id = get_user_meta($user->ID, 'profile_picture'); ?>
<?php echo wp_get_attachment_image($profile_attachment_id[0], array(240, 165), 0, array('style' => 'display: block; margin-bottom: 10px;')); ?>
<input type="file" name="profile_picture" id="profile_picture" class="regular-text" /><br />
<span class="description">Please submit a photo before u can preview it.</span>
</td>
</tr>
<?php if (wp_get_current_user()->roles[0] == 'administrator'): ?>
<tr>
<th><label for="ad_system">Ad system code</label></th>
<td>
<textarea autocomplete="off" name="ad_system" id="ad_system"><?php echo esc_attr(get_the_author_meta('ad_system', $user->ID)); ?></textarea>
<span class="description">Type in the code from the ad system for the current user</span>
</td>
</tr>
<?php endif; ?>
</table>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#your-profile').attr('enctype', 'multipart/form-data');
});
</script>
<?php
}
add_action('personal_options_update', 'my_save_extra_profile_fields');
add_action('edit_user_profile_update', 'my_save_extra_profile_fields');
function my_save_extra_profile_fields($user_id) {
if (!current_user_can('edit_user', $user_id))
return false;
if (!function_exists('wp_handle_upload'))
require_once( ABSPATH . 'wp-admin/includes/file.php' );
$uploadedfile = $_FILES['profile_picture'];
if ($uploadedfile['size']) {
$upload_overrides = array('test_form' => false);
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
if ($movefile) {
$wp_filetype = $movefile['type'];
$filename = $movefile['file'];
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename($filename),
'post_mime_type' => $wp_filetype,
'post_title' => get_userdata($user_id)->display_name,
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment($attachment, $filename);
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
update_usermeta($user_id, 'profile_picture', $attach_id);
}
}
update_usermeta($user_id, 'ad_system', $_POST['ad_system']);
}
/* CUSTOM POST SETTING FOR SLIDER */
function designpicnic_post_meta_settings() {
if (get_post_type( $post ) == 'slider' ) {
add_meta_box("fp_meta_post_slider_big", "Homepage slider url", "fp_meta_post_slider_big", "slider", "normal", "high");
}
}
add_action( 'add_meta_boxes', 'designpicnic_post_meta_settings' );
function fp_meta_post_slider_big() {
global $post;
wp_nonce_field( 'fairpixels_save_postmeta_nonce', 'fairpixels_postmeta_nonce' ); ?>
<div class="meta-field field-checkbox first-field">
<label for="dp_meta_post_slider_big_add"><?php _e( 'url', 'fairpixels' ); ?></label>
<input type="text" name="dp_meta_post_slider_big_add" id="dp_meta_post_slider_big_add" value="<?php echo get_post_meta($post->ID, 'dp_meta_post_slider_big_add', true); ?>" />
</div>
<?php
}
function dp_post_meta_save_post_settings() {
global $post;
if( !isset( $_POST['fairpixels_postmeta_nonce'] ) || !wp_verify_nonce( $_POST['fairpixels_postmeta_nonce'], 'fairpixels_save_postmeta_nonce' ) )
return;
if( !current_user_can( 'edit_posts' ) )
return;
if ( isset( $_POST['dp_meta_post_slider_big_add'] ) ) {
update_post_meta( $post->ID, 'dp_meta_post_slider_big_add', $_POST['dp_meta_post_slider_big_add'] );
}
if (get_post_type( $post ) == 'post' ) {
$post_cat = get_the_category($post->ID);
if (count($post_cat))
update_usermeta($post->post_author, 'user_category', $post_cat[0]->term_id);
}
}
add_action( 'save_post', 'dp_post_meta_save_post_settings' );
/* CUSTOM SIDEBAR */
function dp_widgets_init() {
register_sidebar( array(
'name' => __( 'Category Page Banner', 'category_sidebar' ),
'id' => 'sidebar-category',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<div class="widget-title">',
'after_title' => '</div>',
) );
}
add_action( 'widgets_init', 'dp_widgets_init' );
/* CUSTOM POST TYPES */
// sets custom post type
function register_custom_posttypes() {
global $user_login;
get_currentuserinfo();
if (current_user_can('update_plugins')) {
register_post_type('slider', array(
'label' => 'HomePage Slider','description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'hierarchical' => false,
'publicly_queryable' => true,
'rewrite' => true,
'query_var' => true,
'has_archive' => false,
'supports' => array('title','thumbnail'),
));
}
}
add_action('init', 'register_custom_posttypes');
?>