Code

Getting Started

  1. Source Code
  2. Code Features
  3. Theme Hooks
  4. Digress.it Core Hooks
  5. Comment Browser Hooks
  6. Lightbox Hooks
  7. Ajax Hooks

To download the latest code from the SVN repository follow the instruction on Google Code.

For support, consider subscribing to the mailing list.

Installing Digressit requires access to working installation of WordPress and the ability to install plugins. Sites hosted on WordPress.com cannot use this plugin. If you do not meet this criteria, you can host your project here.

The latest version of Digressit has new support for:

  1. Wordpress 3.0+ (includes support for multisite )
  2. BuddyPress
  3. Customizable widgets
  4. A retractable sidebar
  5. A clear API for coders to expand, customize, and skin

When you use are using Wordpress MU or enable Network Support for WordPress 3.0+, you'll have access to a new file called frontpage.php.

Otherwise the standard mainpage.php is loaded.

  • add_action('add_header_image’, 'functionname');
    If you would like to have a custom header, you override the default header by adding a function that prints out image.
  • add_action('primary_menu’, 'functionname');
    To override the default menu system used by Wordpress. This function print the HTML directly.
  • add_action('optional_menu_item’, 'functionname');
    Similar to primary_menu, except the default menu system is preserved and new menu items are appended.
  • add_action('stylized_content_header’, 'functionname');
    This hooks is printed right before the post title and post content. You can use it to give sections custom static labels.

The following functions are for advanced customizations of Digress.it. The basic internal workings of Digress.it can be overridden here.

When functions are properly registered they will appear in the Digress.it Admin panel under "Advanced".

  • register_digressit_content_function('functionname');
    This function allows you to register a function that parses the_content. You can use this to customize how "paragraphs" are determined.
  • register_digressit_comments_function('functionname');
    This function allows you to override the way each comment appears. Please use the default code as reference.
  • register_digressit_commentbox_function('functionname');
    Register the Javascript function that will handle the display of the comments.
  • add_action('add_commentbrowser’, 'functionname');
    If you would like to add a new filter to the comment browser just create a function that prints the title, prints the filters. In this example below the filters are handled by the function commentbrowser_list_tags, which prints a list of all the tags directly.
    function commentbrowser_comments_by_tag(){
      global $wp;
      echo "<h3>Comments by Tags</h3>";
      commentbrowser_list_tags();
      return get_comments_by_tag(urldecode($wp->query_vars['commentbrowser_params']));
    }
    
    
    function get_comments_by_tag($tag){
      global $wpdb;
      $query = 'SELECT * FROM '.$wpdb->comments.' c, WHERE '.$tag.' CONDITION IS TRUE';
      $comments = $wpdb->get_results( $query);
      return $comments;		
    }
    
    

To create lightboxes, you can use the following hook:

add_action(‘add_lightbox’, ‘lightboxname‘);

The hook takes in a the following function:


<?php
function lightbox_lightboxname(){ ?>
<div id="lightbox-<i>lightboxname</i>">
<form method="post" action="/" id="reset-password">
<div></div>
<div><div></div class>Submit</div>
</form>
</div>
<?php
}

This lightbox will then be printed in the background on every page. To call (display) the lightbox, we need to attach this block of HTML to an event.

Luckily, the event is handled by just adding a the “lighbox” class to a block of HTML.

Here is an example:


<div>Show Lightbox</div>

The first class name attaches the lightbox event and the second class name is the HTML ID of the the lightbox. Notice that we used “lightboxname” through out the examples. It’s best to stick with this consistent naming scheme.

In this HTML example you also might have noticed a few other interesting classes. One is lightbox-close, this class automatically attaches an event that clears the screen of any lightbox. There is also lightbox-submit ajax; lightbox-submit simply styles any block of text to look like a button and places in the the bottom-right corner. The ajax class makes button an AJAX form. More on that in the next section.

This library tries to simplify making AJAX calls within WordPress. There is a clear and consistent naming scheme throughout with events being handled automatically. You can use these AJAX functions anywhere in WordPress, but to continue our previous Lightbox example we’ll suppose you want to submit a form in a Lightbox.

First attach ajax click event to form:


<?php
function lightbox_lightboxname(){ ?>
  <div id="lightbox-<i>lightboxname</i>">
     <form method="post" action="/" id="form_processing_function">
   <div></div>
   <div><div></div class>Submit</div>
  </form>
  </div>
<?php
}

Notice the attributes of this form:

method=post
action=/
id=form_processing_function
name =

Also, take note of the submit button. Inside the div block, there is another div block with the loading-bars class. When a user clicks on the submit button, the form is serialized, the loading bars are shown.

This is when WordPress kicks into action.

First we need to decide what kind of call this is. Is it a form that only registered users can use or is it a call that’s available to all users?

Depending on what you want you can use any of these three hooks:


add_action(‘authenticated_ajax_function’, ‘form_processing_function’);
add_action(‘unauthenticated_ajax_function’, ‘form_processing_function’);
add_action(‘public_ajax_function’, ‘form_processing_function’);



Note: The difference between a unauthenticated_ajax_function and public_ajax_function is subtle, but very important. If you want this call to be available to either logged in users and unregistered/signed out users, use public_ajax_function. unauthenticated_ajax_function will not be available to users that are logged in



function form_processing_function($form_values){
  global $wpdb, $current_user;

   //we whatever we like here
  $status = 1; //this is an error code. Use as you please. Reserve 1 for 'success'
  $message = array('foo'=> 'bar'); //we can return whatever we like.
  //then we die encode the array and die. The browser will get this information back.
  die(json_encode(array('status' => $status, "message" => $message)));
}

In some cases you’re done. But if you would like to manipulate the DOM with this new information, this is your chance. We already have a javascript object that will be called when the form is submitted.

AjaxResult object:


AjaxResult.form_processing_function = function(data) {

 //optional: there is a displayerrorslightbox javascript function that will print whatever error
 //message you return in the "message"
 if(data.status == 0){
 jQuery('body').displayerrorslightbox(data);
 return;
}

//otherwise we can access the PHP result variables easily through the dot syntax.
//example: alert(data.message.foo) will print 'bar'
}

gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.