Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

Functions.php

By: rhandom on Mar 28th, 2012  |  syntax: PHP  |  size: 13.43 KB  |  views: 180  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. if ( function_exists('register_sidebar') ) {
  3.  
  4.         register_sidebar(array(
  5.                 'before_widget' => '<li>',
  6.                 'after_widget' => '</li>',
  7.                 'before_title' => '<h2 class="widgettitle">',
  8.                 'after_title' => '</h2>',
  9.         ));
  10.        
  11.         register_sidebar(array(
  12.                         'name' => __( 'Language Picker'),
  13.                         'id' => 'wpml',
  14.                         'before_widget' => '',
  15.                         'after_widget' => '',
  16.         ));
  17.  
  18.         register_sidebar(array(
  19.                         'name' => __( 'Inner Pages Widgets'),
  20.                         'id' => 'inner',
  21.                         'before_widget' => '',
  22.                         'after_widget' => '',
  23.                        
  24.                 ));
  25.         register_sidebar(array(
  26.                         'name' => __( 'Copyright Widgets'),
  27.                         'id' => 'copyright',
  28.                         'before_widget' => '',
  29.                         'after_widget' => '',
  30.                        
  31.                 ));
  32.        
  33.        
  34. }
  35. add_custom_background();
  36.  
  37. register_post_type('profile', array(
  38.         'label' => __('Profiles'),
  39.         'singular_label' => __('Profile'),
  40.         'public' => true,
  41.         'show_ui' => false, // UI in admin panel
  42.         'capability_type' => 'post',
  43.         'hierarchical' => true,
  44.         'rewrite' => array("slug" => "user-profile"), // Permalinks format
  45.         'supports' => array('title', 'editor','page-attributes','author')
  46. ));
  47.  
  48. add_action("template_redirect", 'my_template_redirect');
  49.  
  50. // Template selection
  51. function my_template_redirect()
  52. {
  53.         global $wp;
  54.         global $wp_query;
  55.        
  56.         if (isset($_REQUEST['post_type']))
  57.        
  58.         {
  59.         if ($_REQUEST['post_type']=="signup")
  60.         {
  61.                 // Let's look for the register.php template file in the current theme
  62.                 if (have_posts())
  63.                 {
  64.                         include(TEMPLATEPATH . '/register.php');
  65.                         die();
  66.                 }
  67.                 else
  68.                 {
  69.                         $wp_query->is_404 = true;
  70.                 }
  71.         }else if ($_REQUEST['post_type']=="user-profile")
  72.         {
  73.                 // Let's look for the viewprofile.php template file in the current theme
  74.                 //http://kovshenin.com/2010/extending-custom-post-types-in-wordpress-3-0/
  75.                 //if (have_posts())
  76.                 //{
  77.                         include(TEMPLATEPATH . '/viewprofile.php');
  78.                 //      die();
  79.                 //}
  80.                 //else
  81.                 //{
  82.                 //      $wp_query->is_404 = true;
  83.                 //}
  84.         }
  85. }
  86. }
  87.  
  88.  
  89.  
  90. add_theme_support('post-thumbnails');
  91. add_filter( 'show_admin_bar', '__return_false' );
  92. function yoast_hide_admin_bar_settings() {
  93. ?>
  94.         <style type="text/css">
  95.                 .show-admin-bar {
  96.                         display: none;
  97.                 }
  98.         </style>
  99. <?php
  100. }
  101.  
  102.  
  103. /*********************************************************************
  104. HIDE DASHBOARD MENU ITEMS
  105. *********************************************************************/
  106.  
  107. function remove_menus () {
  108. global $menu;
  109.         $restricted = array( __('Posts'), __('Links'),__('Comments')); //, __('Tools')
  110.         end ($menu);
  111.         while (prev($menu)){
  112.                 $value = explode(' ',$menu[key($menu)][0]);
  113.                 if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
  114.         }
  115. }
  116. add_action('admin_menu', 'remove_menus');
  117. add_action( 'save_post', 'delete_get_calendar_cache' );
  118. add_action( 'delete_post', 'delete_get_calendar_cache' );
  119. add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
  120. add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
  121.  
  122. add_action( 'show_user_profile', 'extra_user_profile_fields' );
  123. add_action( 'edit_user_profile', 'extra_user_profile_fields' );
  124.  
  125. /*********************************************************************
  126. ACCESS KEY GENERATOR
  127. *********************************************************************/
  128.  
  129. add_action( 'init', 'accesskeygen_func' );
  130.  
  131. function accesskeygen_func() {
  132.     $phpfile = explode('/', $_SERVER['PHP_SELF']);
  133.     $phpfile = $phpfile[count($phpfile)-1];
  134.    
  135.     if (($phpfile=='profile.php') && isset($_GET['accesskeygen'])) {
  136.         echo wp_generate_password();
  137.         exit;
  138.     }
  139. }
  140.  
  141. /*********************************************************************
  142. CALENDAR HOOKS
  143. **********************************************************************/
  144.  
  145. // js hook to include calendar
  146. add_action('admin_head', 'calendar_load');
  147.  
  148. function calendar_load() {
  149.     echo '<link href="'.get_bloginfo('template_directory').'/js/calendar.css" type="text/css" rel="stylesheet" />'."\n";
  150.     echo '<script src="'.get_bloginfo('template_directory').'/js/cal.js" type="text/javascript"></script>'."\n\n";
  151. }
  152.  
  153. /********************************************************************
  154. Image Uploader Necessary Scripts
  155. *********************************************************************/
  156. function my_upload_scripts() {
  157.         wp_enqueue_script('media-upload');
  158. }
  159.  
  160. add_action('admin_print_scripts', 'my_upload_scripts');
  161.  
  162. /********************************************************************
  163. Profile Image Upload Field Code
  164. *********************************************************************/
  165. require_once( STYLESHEETPATH . '/img_upload_resize_crop.php' );
  166.  
  167. add_action( 'init', 'custom_img_uploader' );
  168.  
  169. function custom_img_uploader () {
  170.         global $profilePicture;
  171.         if (isset($_FILES['profilePicture']['name'])!= "" ) {
  172. if ( $_FILES['profilePicture']['name']!="" ) {
  173.         $your_image = new _image;
  174.         $upload_dir = wp_upload_dir();
  175.         //To Upload
  176.         $your_image->uploadTo = $upload_dir['basedir'].'/';
  177.         $upload = $your_image->upload($_FILES['profilePicture']);
  178.        
  179.        
  180.         //To Resize
  181.         $your_image->newPath = $upload_dir['basedir'].'/thumbs/';
  182.         $your_image->newWidth = 150;
  183.         $your_image->newHeight = 200;
  184.         $resized = $your_image->resize();
  185.         $profilePicture=str_replace($upload_dir['basedir'].'/thumbs/', "", $resized );
  186.         unlink($upload);
  187. }else{
  188.         $profilePicture='';
  189. }
  190. }
  191. }
  192.  
  193. /***********************************************************************
  194. EXTRA PROFILE FIELDS
  195. http://bavotasan.com/2009/adding-extra-fields-to-the-wordpress-user-profile/
  196. ************************************************************************/
  197.  
  198. function extra_user_profile_fields( $user ) {
  199.         //global $profilePicture;
  200.        
  201.         ?>
  202. <h3><?php _e("Extra profile information", "blank"); ?></h3>
  203.  
  204. <script type="text/javascript">
  205. jQuery(function($) {
  206.     $("#myaccesskeygen").click( function() {
  207.         var url = 'profile.php?accesskeygen=true';
  208.         $.ajax({url:url,async:true,type:'GET',dataType:'html', success: function(newaccesskey){
  209.             $("#myaccesskey").val(newaccesskey);
  210.         }});
  211.     });
  212.    
  213.     $("#dateofbirth").simpleDatepicker({startdate:'01/01/1930', enddate:'12/01/2012'});
  214. });
  215. </script>  
  216.  
  217. <table class="form-table">
  218. <tr>
  219. <th><label for="city"><?php _e("Birth Date"); ?></label></th>
  220. <td>
  221. <input type="text" name="dateofbirth" id="dateofbirth" value="<?php echo esc_attr( get_the_author_meta( 'dateofbirth', $user->ID ) ); ?>" class="regular-text" /><br />
  222. <span class="description"><?php _e("Please enter your birth date."); ?></span>
  223. </td>
  224. </tr>
  225. <tr>
  226. <th><label for="city"><?php _e("Birth Place"); ?></label></th>
  227. <td>
  228. <input type="text" name="birthplace" id="birthplace" value="<?php echo esc_attr( get_the_author_meta( 'birthplace', $user->ID ) ); ?>" class="regular-text" /><br />
  229. <span class="description"><?php _e("Please enter your birth place."); ?></span>
  230. </td>
  231. </tr>
  232. <tr>
  233. <th><label for="realage"><?php _e("Age"); ?></label></th>
  234. <td>
  235. <input type="text" name="realage" id="realage" value="<?php echo esc_attr( get_the_author_meta( 'realage', $user->ID ) ); ?>" class="regular-text" /><br />
  236. <span class="description"><?php _e("Please enter your age"); ?></span>
  237. </td>
  238. </tr>
  239. <tr>
  240. <th><label for="province"><?php _e("Current City"); ?></label></th>
  241. <td>
  242. <input type="text" name="currentcity" id="currentcity" value="<?php echo esc_attr( get_the_author_meta( 'currentcity', $user->ID ) ); ?>" class="regular-text" /><br />
  243. <span class="description"><?php _e("Please enter your current city."); ?></span>
  244. </td>
  245. </tr>
  246. <tr>
  247. <th><label for="favouritecolour"><?php _e("Favourite Colour"); ?></label></th>
  248. <td>
  249. <input type="text" name="favouritecolour" id="favouritecolour" value="<?php echo esc_attr( get_the_author_meta( 'favouritecolour', $user->ID ) ); ?>" class="regular-text" /><br />
  250. <span class="description"><?php _e("Please enter your favourite colour."); ?></span>
  251. </td>
  252. </tr>
  253. <tr>
  254. <th><label for="favouritebook"><?php _e("Favourite Book"); ?></label></th>
  255. <td>
  256. <input type="text" name="favouritebook" id="favouritebook" value="<?php echo esc_attr( get_the_author_meta( 'favouritebook', $user->ID ) ); ?>" class="regular-text" /><br />
  257. <span class="description"><?php _e("Please enter your favourite book."); ?></span>
  258. </td>
  259. </tr>
  260. <tr>
  261. <th><label for="favouritefilm"><?php _e("Favourite Film"); ?></label></th>
  262. <td>
  263. <input type="text" name="favouritefilm" id="favouritefilm" value="<?php echo esc_attr( get_the_author_meta( 'favouritefilm', $user->ID ) ); ?>" class="regular-text" /><br />
  264. <span class="description"><?php _e("Please enter your favourite film."); ?></span>
  265. </td>
  266. </tr>
  267. <tr>
  268. <th><label for="favouriterestaurant"><?php _e("Favourite Restaurant"); ?></label></th>
  269. <td>
  270. <input type="text" name="favouriterestaurant" id="favouriterestaurant" value="<?php echo esc_attr( get_the_author_meta( 'favouriterestaurant', $user->ID ) ); ?>" class="regular-text" /><br />
  271. <span class="description"><?php _e("Please enter your favourite restaurant."); ?></span>
  272. </td>
  273. </tr>
  274. <tr>
  275. <th><label for="favouritequote"><?php _e("Favourite Quote"); ?></label></th>
  276. <td>
  277. <input type="text" name="favouritequote" id="favouritequote" value="<?php echo esc_attr( get_the_author_meta( 'favouritequote', $user->ID ) ); ?>" class="regular-text" /><br />
  278. <span class="description"><?php _e("Please enter your favourite quote."); ?></span>
  279. </td>
  280. </tr>
  281. <tr>
  282. <th><label for="favouritequalityinaperson"><?php _e("Favourite Quality in a Person"); ?></label></th>
  283. <td>
  284. <input type="text" name="favouritequalityinaperson" id="favouritequalityinaperson" value="<?php echo esc_attr( get_the_author_meta( 'favouritequalityinaperson', $user->ID ) ); ?>" class="regular-text" /><br />
  285. <span class="description"><?php _e("Please enter your favourite quality in a person."); ?></span>
  286. </td>
  287. </tr>
  288. <tr>
  289. <th><label for="myfavouritetvprograms"><?php _e("Favourite TV Programs"); ?></label></th>
  290. <td>
  291. <input type="text" name="myfavouritetvprograms" id="myfavouritetvprograms" value="<?php echo esc_attr( get_the_author_meta( 'myfavouritetvprograms', $user->ID ) ); ?>" class="regular-text" /><br />
  292. <span class="description"><?php _e("Please enter your favourite TV programs."); ?></span>
  293. </td>
  294. </tr>
  295. <tr>
  296. <th><label for="myfavouritegroups"><?php _e("Favourite Groups"); ?></label></th>
  297. <td>
  298. <input type="text" name="myfavouritegroups" id="myfavouritegroups" value="<?php echo esc_attr( get_the_author_meta( 'myfavouritegroups', $user->ID ) ); ?>" class="regular-text" /><br />
  299. <span class="description"><?php _e("Please enter your favourite groups."); ?></span>
  300. </td>
  301. </tr>
  302. <tr>
  303. <th><label for="myfavouritelinks"><?php _e("Favourite Links"); ?></label></th>
  304. <td>
  305. <input type="text" name="myfavouritelinks" id="myfavouritelinks" value="<?php echo esc_attr( get_the_author_meta( 'myfavouritelinks', $user->ID ) ); ?>" class="regular-text" /><br />
  306. <span class="description"><?php _e("Please enter your favourite links."); ?></span>
  307. </td>
  308. </tr>
  309. <tr>
  310. <th><label for="zodiac"><?php _e("Zodiac"); ?></label></th>
  311. <td>
  312. <input type="text" name="zodiac" id="zodiac" value="<?php echo esc_attr( get_the_author_meta( 'zodiac', $user->ID ) ); ?>" class="regular-text" /><br />
  313. <span class="description"><?php _e("Please enter your Zodiac"); ?></span>
  314. </td>
  315. </tr>
  316. <!-- begin image uploader field -->
  317. <tr>
  318. <th><label for="profilePicture"><?php _e("Profile Image"); ?></label></th>
  319. <td>
  320. <input type="file" name="profilePicture" id="profilePicture" style="float:left;" />
  321.  
  322. </td>
  323. </tr>
  324. <!-- begin access key -->
  325. </tr>
  326. <th><label for="myaccesskey"><?php _e("Access Key"); ?></label></th>
  327. <td>
  328. <input type="text" name="myaccesskey" id="myaccesskey" value="<?php echo esc_attr( get_the_author_meta( 'myaccesskey', $user->ID ) ); ?>" class="regular-text" /><br />
  329. <span class="description">
  330.     <input type="button" class="button-secondary" id="myaccesskeygen" value="Generate Access Key"/>&nbsp;
  331.     <?php _e("Please click the button generate access key."); ?>
  332. </span>
  333. </td>
  334. </tr>
  335. <!-- end access key -->
  336. </table>
  337. <?php }
  338.  
  339. add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
  340. add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
  341.  
  342. function save_extra_user_profile_fields( $user_id ) {
  343.  
  344. if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
  345.  
  346. //update_user_meta user_id, key, value, previous
  347. update_user_meta( $user_id, 'dateofbirth', $_POST['dateofbirth']);
  348. update_user_meta( $user_id, 'realage', $_POST['realage']);
  349. update_user_meta( $user_id, 'birthplace', $_POST['birthplace'] );
  350. update_user_meta( $user_id, 'currentcity', $_POST['currentcity'] );
  351. update_user_meta( $user_id, 'favouritecolour', $_POST['favouritecolour'] );
  352. update_user_meta( $user_id, 'favouritebook', $_POST['favouritebook'] );
  353. update_user_meta( $user_id, 'favouritefilm', $_POST['favouritefilm'] );
  354. update_user_meta( $user_id, 'favouriterestaurant', $_POST['favouriterestaurant'] );
  355. update_user_meta( $user_id, 'favouritequote', $_POST['favouritequote'] );
  356. update_user_meta( $user_id, 'favouritequalityinaperson', $_POST['favouritequalityinaperson'] );
  357. update_user_meta( $user_id, 'myfavouritetvprograms', $_POST['myfavouritetvprograms'] );
  358. update_user_meta( $user_id, 'myfavouritegroups', $_POST['myfavouritegroups'] );
  359. update_user_meta( $user_id, 'myfavouritelinks', $_POST['myfavouritelinks'] );
  360. update_user_meta( $user_id, 'zodiac', $_POST['zodiac'] );
  361. update_user_meta( $user_id, 'userphoto_thumb_height', 59);
  362. update_user_meta( $user_id, 'userphoto_thumb_width', 80 );
  363. update_user_meta( $user_id, 'userphoto_thumb_file', $profilePicture );
  364. update_user_meta( $user_id, 'myaccesskey', $_POST['myaccesskey']);
  365.  
  366. }