If you are working with bbPress or are thinking about using bbPress as your websites support forum, I would highly recommend becoming familiar with the following shortcodes for displaying your forum content. We created this directory as a result of our team trying to work with what bbPress is today. Unfortunately, it seems there is not a lot of effort being put into the current bbPress site now. bbPress 2.0 has a lot of potential and we felt offering some guidance to get you started as we love the WordPress community.
Git: Revert and Reset Changes
Here are some quick tips on resetting your local branch when you have committed changes or have made changes and want to unstage them (ie. after git add )
Revert changes made to your working copy ( before git add )
git checkout .
Revert changes made to your index ( git add )
git reset
Revert a change you have made to a commit
git revert ...
Whats up?
Well it has been a crazy busy month. To help reduce amount of wasted time and stress I have done two important things that I think have helped just in the past 24 hours.
- From now on my phone is always on silent ( vibrate mode )
- I deactivated my FaceBook account
With the last one, I no longer need a pass lock on my phone.
Ahh the joys of 11/11/11
So over the past couple years I have seen the number 11 everywhere all the time. 11:11 on my phone, on my computer. It seems like very time I look at a clock I will see that number. So my girlfriend jokes that she does not want me to do, or go any where on 11/11/11 as we think something might happen to me. So I did expect something to happen today.
Thank god so far nothing has happened to me be, but, server did go down today for Mojo Themes. And we have discovered that we will be switching our hosting provider.
I have never liked VPS.net in the first place but their lack of response, which is only via email ( no phone number available ), has been the last straw. Good bye terrible customer service.
We’ll release more info about our new services. But right now our major goal is to just get the site back up and running.
Adding code to the head tag in WordPress
When you want to add code into the head tag of a WordPress blog the best way of doing so, especially if you are a theme builder, is to use the add_action() function that WordPress provides.
Actions are there to allow you to attach functions or classes to a specific part of WordPress’ output. So when you are coding in the functions.php file you can create a function that will output a meta tag into your head without going into the template files and manually adding this.
This is perfect for when you are developing a WordPress theme for sale.
We start with the add_action() function and use the value of ‘wp_head’:
add_action ( 'wp_head', 'my_custom_function_name' );
The first value of ‘wp_head’ is the name of the WordPress action we want to attach a function to. The second value ‘my_custom_function_name’ is the name of the function we are creating to output code.
Below is the function we will be using to insert a meta tag into our head tag.
function my_custom_function_name()
{
echo '<meta name="author" value="Will Ayers">';
}
And there you have it. The author meta tag will now show up in your head tag as long as the theme has the function wp_head() inside the head tag.
PHP arrays to Javascript
How do you get a php array into a javascript array/object? You use json! Below is a simple way of doing so.
Here is our php array.
$player = array( 'id' => 24, 'first_name' => 'kobe', 'last_name' => 'Bryant' );
Here is how we turn it into a json string.
$json_string = json_encode ( $player );
Now when grabbing that string with javascript you can simply call the JSON.parse method like so.
var player = JSON.parse ( my_php_encoded_json_string );
You can now access that php array in javascript by either array or object.
player.first_name; // Kobe
player['last_name']; // Bryant
WordPress: Get Url Of Featured Image
There is a very easy way to display the featured image of a post or custom post type, but what about getting just the url? Had some trouble finding any documentation about finding a solution to this. Then I came across some code that worked for me. Here is what I got to work.
In this example I am echoing out the url to the screen. This will actually return an array. See Edit #1 below.
<?php echo wp_get_attachment_image_src ( get_post_thumbnail_id ( $post_id ), 'single-post-thumbnail' ) ?>
EDIT #1
The above code was wrong where it was echoing out the result. It actually returns an array. So below is the how to get the url:
$image = wp_get_attachment_image_src ( get_post_thumbnail_id ( $post_id ), 'single-post-thumbnail' );
echo $image[0];
Running PHP Files With Command Line
Do you have a php file you want to run via command line? It would make it a lot easier to show what is going on with your script especially when you are doing some sort of import. The easiest way is to simple call the name of the file after typing php like below.
php filename.php
WordPress: Attaching a function after a comment is saved.
I had previously been trying to attach a function to a filter called “comment_pre_save”. Below is the solution I found.
I needed to add an entry into a table in the db everytime someone added a comment. I tried running "comment_pre_save" filter to no avail. I did some more research today ( as it was around 4:30 am when I originally set out to solve this ) and found another filter that works perfectly. "comment_post".
I don’t know how I missed this but I am glad I found it. Here is an example of how to get a function called when someone posts a comment.
add_filter ( 'comment_post', 'new_comment_added' );
function new_comment_added(){ die ( 'You just added a comment.' );}
I did a simple die command to let me know that it was working.
WordPress Comment Save Filter
Since I can not sleep tonight, I am working on a project in WordPress. I am attempting to add a filter or a hook to attach some code to run when a comment is saved to the database. I have searched through WordPress’s codex and have found a filter called “comment_pre_save”.
WordPress does not have any documentation on this filter so I am left in the dark on this one. We will see how this goes. I will post a solution if when I find one.
Update #1:
I have found a solution to this here.