Advertisement
Guest User

functions.php

a guest
Sep 6th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.39 KB | None | 0 0
  1. <?php
  2.  
  3. // HIDE THE ADMIN BAR
  4. function my_function_admin_bar(){
  5.     return false;
  6. }
  7. add_filter( 'show_admin_bar' , 'my_function_admin_bar');
  8.  
  9.  
  10. //lsit situations for /situations page
  11. function list_situations_func(){
  12.     $pages = get_pages('parent=2&child_of=2&sort_column=menu_order&title_li=');
  13.     $list='<ul class="situations_list">';
  14.     foreach ($pages as $page) {
  15.         $var = get_post_meta($page->ID,'aka');
  16.         $list.= '<li><a href="'.
  17.                 get_permalink($page->ID).'" alt="">'.
  18.                 ($var[0]!=''? $var[0]:$page->post_title).
  19.                 '</a></li>';
  20.     }
  21.     $list.= '</ul>';
  22.     return $list;
  23. }
  24.  
  25. //list categories of situations shortcode for the /situations/x/ page
  26. function list_categories_func(){
  27.     $page_id= get_the_id();
  28.     $pages = get_pages('parent='.$page_id.'&child_of='.$page_id.'&sort_column=menu_order&title_li=');
  29.     $list='<ul class="categories_list">';
  30.     foreach ($pages as $page) {
  31.         $var = get_post_meta($page->ID,'aka');
  32.         $number_of_comments = get_comments_number($page->ID);
  33.         $list.= '<ul><li>Situation: '.
  34.                 '<a class="situation" href="'.
  35.                 get_permalink($page->ID).'" alt="">'.
  36.                 ($var[0]!=''? $var[0]:$page->post_title).
  37.                 '</a></li>'.
  38.                 '<li class="comment_count">Comments: '.$number_of_comments.'</li>'.
  39.                 '</li></ul>';
  40.     }
  41.     $list.= '</ul>';
  42.     return $list;
  43. }
  44.  
  45. //shortcode to add the .wrong class
  46. function wrong( $atts, $content = null ) {
  47.     return '<div class="wrong"><span>Wrong:</span><p>'.$content.'</p></div>';
  48. }
  49.  
  50. //shortcode to add the .right class
  51. function right( $atts, $content = null ) {
  52.     return '<div class="right"><span>Right:</span><p>'.$content.'</p></div>';
  53. }
  54.  
  55. // add the buttons to tinyMCE
  56. function add_button() {
  57.     if ( current_user_can('edit_posts') &&  current_user_can('edit_pages') ){
  58.         add_filter('mce_external_plugins', 'add_plugin');
  59.         add_filter('mce_buttons', 'register_button');
  60.    }
  61. }
  62.  
  63. // register the buttons for tinyMCE
  64. function register_button($buttons) {
  65.    array_push($buttons, "wrong");
  66.    array_push($buttons, "right");
  67.    return $buttons;
  68. }
  69.  
  70. //add the plugin to tinyMCE
  71. function add_plugin($plugin_array) {
  72.    $plugin_array['wrong'] = get_bloginfo('template_url').'/customcodes.js';
  73.    $plugin_array['right'] = get_bloginfo('template_url').'/customcodes.js';
  74.    return $plugin_array;
  75. }
  76.  
  77. // register the shortcodes
  78. function register_shortcodes(){
  79.     add_shortcode('list_situations','list_situations_func');
  80.     add_shortcode('list_categories','list_categories_func');
  81.     add_shortcode('wrong','wrong');
  82.     add_shortcode('right','right');
  83. }
  84.  
  85.  
  86. add_action('init','register_shortcodes');
  87. add_action('init','add_button');
  88.  
  89.  
  90.  
  91. //The comments layout
  92. function comment_layout ( $comment, $args, $depth ) {
  93.  
  94.     $GLOBALS['comment'] = $comment;
  95.     $location = get_comment_meta(get_comment_ID(),'location',true);
  96.  
  97.     ?>
  98.     <li <?php comment_class(); ?> id="comment-<?php echo $comment->comment_ID; ?>">
  99.  
  100.         <?php comment_text(); ?>
  101.         <?php echo '<cite>-'.get_comment_author().($location ? ', '.$location : '').'</cite>';?>
  102.  
  103.  
  104.     <?php if ($comment->comment_approved == '0') _e("<span class='unapproved'>Your comment is awaiting moderation.</span>\n", 'matty') ?>
  105.  
  106.     </li>
  107.     <?php
  108.  
  109. } // End comment_layout()
  110.  
  111.  
  112. // change the comment form defaults
  113. add_filter( 'comment_form_defaults',    'change_comment_form_defaults');
  114.  
  115. function change_comment_form_defaults($default) {
  116.     $commenter = wp_get_current_commenter();
  117.     $req = get_option('require_name_email ');
  118.  
  119.  
  120.     $fields =  array(
  121.         'author' => '<p class="comment-form-author"><label for="author">' . 'Name [your name, class, group or organization]' . '</label> ' . ( $req ? '<span class="required">*:</span>' : ':' ) .
  122.                     '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
  123.         'email'  => '<p class="comment-form-email"><label for="email">' . 'Email Address [for notification only, NEVER printed on the site]'. '</label> ' . ( $req ? '<span class="required">*:</span>' : ':' ) .
  124.                     '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
  125.         'location'  => '<p class="comment-form-location"><label for="location">' .'Location [City and State]:'. '</label> '.
  126.                     '<input id="location" name="location" type="text" size="30"' . ' /></p>',
  127.     );
  128.  
  129.  
  130.     $default=array(
  131.         'fields'=>$fields,
  132.         'label_submit'=>'Submit',
  133.         'logged_in_as'=>'<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '</p>',
  134.         'comment_field'=>'<p class="comment-form-comment"><label for="comment">' . _x( 'Add Your Comments Here:', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
  135.         'comment_notes_before'=>'<p>* required fields</p>',
  136.         'title_reply'=>'',
  137.         'title_reply_to'=>'',
  138.         'cancel_reply_link'=>'',
  139.  
  140.     );
  141.  
  142.     return $default;
  143. }
  144.  
  145.  
  146. //save the data to the DB
  147. add_action( 'comment_post', 'save_comment_meta_data' );
  148. function save_comment_meta_data( $comment_id ) {
  149.     add_comment_meta( $comment_id, 'location', $_POST['location'] );
  150. }
  151.  
  152.  
  153.  
  154. //TODO: add meta box to admin page
  155. // tut is here http://wp.tutsplus.com/tutorials/plugins/how-to-create-custom-wordpress-writemeta-boxes/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement