Problem:
When using Canvas and making a image appear with a grayscale when loading, the images sometimes do not display.
Solution:
Use “onload” html attribute to change the image source after it gets a chance to load.
A Log of Coding Solutions
by Webhead
When using Canvas and making a image appear with a grayscale when loading, the images sometimes do not display.
Use “onload” html attribute to change the image source after it gets a chance to load.
by Webhead
A great explanation on box shadows:
by Webhead
IE was throwing a ‘undefined’ error when using the jquery.bgpos.js script. Here is an example of what it can do:
http://snook.ca/technical/jquery-bg/
Found on Stack Overflow as usual, here is the fixed jquery.bgpos.js made especially for Microsoft Internet Explorer.
http://stackoverflow.com/questions/1780617/ie8-and-jquery-null-pointers
Keywords: bgpos jquery ie
by Webhead
The Hawaiian language has the kahako but tinymce does not have these in their charmap.
To add more characters to the custom character map in tinymce, find the file:
themes/advanced/js/charmap.js
If you are using wordpress that directory is located in wp-includes/js/tinymce/
Open that file and you’ll see a list of characters in the charmap. The first parameter is the html code, the second is the unicode character, the third is whether to display or not, the fourth is a description. The easiest way to do this is to first know how many characters you are adding. Then comment out that many lines which are displayed (have “true” as the third parameter). Then add you characters. Below are the characters I added for Hawaiian.
['Ā', 'Ā', true,'A kahako'], ['Ē', 'Ē', true,'E kahako'], ['Ī', 'Ī', true,'I kahako'], ['Ō', 'Ō', true,'O kahako'], ['Ū', 'Ū', true,'U kahako'], ['ā', 'ā', true,'a kahako'], ['ē', 'ē', true,'e kahako'], ['ī', 'ī', true,'i kahako'], ['ō', 'ō', true,'o kahako'], ['ū', 'ū', true,'u kahako'],
For a full explanation to add characters or if you don’t want to comment out existing characters, visit: http://www.patrickgmj.net/node/66
by Webhead
When users register for a site, they are usually just registering to comment on a page. This means they DO NOT need the admin bar at the top hiding a portion of your page.
To get rid of this you can add this to your functions page:
// show admin bar only for admins and editors if (!current_user_can('edit_posts')) { add_filter('show_admin_bar', '__return_false'); }
More solutions can be found here:
by Webhead
A client needed just one page to have comments where the user must log in. The client wanted the rest of the pages to be open to anyone to comment. I found no such plugin.
At first I was going to write a plugin, but being that I have never wrote an official plugin before I decided to go the simpler route. I ended up creating 3 template files and adding a function to the functions.php file. Since almost all pages will allow anonymous comments, the wordpress setting will allow comments. The following changes will prevent users from posting a comment to specific page-templates.
page-comment-restrict.php
This is a copy of page.php. the only difference is the loop part will call ‘page-comments-restrict’ instead of the ‘page’ template. Use this template for each page that needs the comments restricted.
loop-page-comment-restrict.php
This is a copy of loop-page.php. The only difference is the comment template. Instead of calling the default comment template it will call ‘/comments-restrict.php’.
comments_template( '/comments-restrict.php', true );
comments-restrict.php
This is a copy of the comments.php. The difference is you need to copy some login code from “/wp-includes/comment-template.php”. Specifically the part where it checks for comment_registration and is_user_logged_in. After making a copy of comments.php, replace comment_form() with the code below.
<?php if ( comments_open() ) : ?> <?php do_action( 'comment_form_before' ); ?> <div id="respond"> <h3 id="reply-title"><?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?> <small><?php cancel_comment_reply_link( 'Cancel reply' ); ?></small></h3> <?php if ( !is_user_logged_in() ) : ?> <?php echo '<p>' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>'; ?> <?php do_action( 'comment_form_must_log_in_after' ); ?> <?php else : comment_form(); endif; ?> <?php endif; ?>
functions.php
All the changes up until now are to hide the comments form on the page. However, a malicious user could still try to post a comment to your page because the wordpress setting is to allow anonymous comments. To prevent this, we need to catch all comments before it is posted by adding an action hook at ‘pre_comment_on_post’. Add the following code to the functions.php file.
if ( ! function_exists( 'comments_restrict' ) ) : /** * Restricts comments to logged in users only for the specific pages determined by page template. * */ function comments_restrict($post_ID) { $meta_value = get_post_meta($post_ID, '_wp_page_template', true); if ($meta_value == 'page-comments-restrict.php') { $user = wp_get_current_user(); if (!$user->ID) wp_die( __('Sorry, you must be logged in to post a comment.') ); } } endif; add_action('pre_comment_on_post', 'comments_restrict');
That’s it. It should restrict users who are not logged in from commenting. Test it out with the following steps: