• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

My Monkey Do

A Log of Coding Solutions

  • Home
  • Web Hosts
  • Tools
  • About

wordpress

TinyMCE add Custom Characters

July 29, 2011 by Webhead

Problem:

The Hawaiian language has the kahako but tinymce does not have these in their charmap.

 

Solution:

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

Filed Under: Coding Tagged With: cms, tinymce, wordpress

Hide WordPress Admin Bar by Default

July 21, 2011 by Webhead

Problem:

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.

 

Solution:

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:

http://digwp.com/2011/04/admin-bar-tricks/

Filed Under: Coding Tagged With: php, wordpress

Restrict Comments on WordPress Page

July 9, 2011 by Webhead

Problem:

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.

Solution:

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:

  • Replace the code in comments-restrict.php with the normal comments_form(); method.   Try to post a comment.  The result should be a page that says you need to be logged in.
  • View the page with and without the wordpress setting to allow anonymous comments.  You should see no difference.

Filed Under: Coding Tagged With: php, wordpress

wordpress mod_rewrite exception url

June 28, 2011 by Webhead

Problem:

I added a wordpress blog to a website, but I still needed to get to a url that was on the same website and not part of wordpress.

Search terms:

wordpress mod_rewrite exception url

Solution Found:

http://stackoverflow.com/questions/6428448/rewriterule-exception-for-static-page-outside-wordpress

Use:

RewriteRule ^test.htm$ - [PT,L]

 

Filed Under: Server Stuff Tagged With: apache, htaccess, wordpress

Custom WordPress Comments

June 27, 2011 by Webhead

This guy explains how to customize WordPress comments pretty well:

http://devpress.com/blog/using-the-wordpress-comment-form/

 

Disable HTML in Comments

You can try this plugin found on :  http://www.theblog.ca/literal-comments

 

// This will occur when the comment is posted
function plc_comment_post( $incoming_comment ) {

	// convert everything in a comment to display literally
	$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);

	// the one exception is single quotes, which cannot be #039; because WordPress marks it as spam
	$incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );

	return( $incoming_comment );
}

// This will occur before a comment is displayed
function plc_comment_display( $comment_to_display ) {

	// Put the single quotes back in
	$comment_to_display = str_replace( ''', "'", $comment_to_display );

	return $comment_to_display;
}

add_filter( 'preprocess_comment', 'plc_comment_post', '', 1);
add_filter( 'comment_text', 'plc_comment_display', '', 1);
add_filter( 'comment_text_rss', 'plc_comment_display', '', 1);
add_filter( 'comment_excerpt', 'plc_comment_display', '', 1);

 

Filed Under: Coding Tagged With: wordpress

WordPress CMS Plugins

June 15, 2011 by Webhead

WordPress has tons of features, but most clients just need to edit pages and want a content management system.  I needed to get rid of all the fat.

Complicated Menus

To get rid of the menus on the dashboard for all roles except the admin place the following code in the functions.php of your theme.

function remove_menus () {
    global $menu;
    if (!(current_user_can('install_themes'))) {
        $restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));
    }
    else {
        return;
    }
	end ($menu);
	while (prev($menu)){
		$value = explode(' ',$menu[key($menu)][0]);
		if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
	}
}
add_action('admin_menu', 'remove_menus');

Thanks to http://www.wprecipes.com/how-to-remove-menus-in-wordpress-dashboard

Redirected Login

A problem that arises from this is the dashboard is pretty much useless.  You can use this plugin to redirect a user to a specific page based on their role:  http://wordpress.org/extend/plugins/peters-login-redirect/

Easy TinyMCE adjustments

One plugin that makes this very simple:  http://wordpress.org/extend/plugins/tinymce-advanced/

 

Filed Under: Coding Tagged With: php, wordpress

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 10
  • Go to page 11
  • Go to page 12
  • Go to page 13
  • Go to Next Page »

Primary Sidebar

Topics

apache apple chrome cms css debug eCommerce embed filters firebug firefox git gmail goDaddy google hosting htaccess html html 5 IE crap image iPad iPhone javascript jquery linux localization macOS mac os x markdown ms sql mysql open source optimize php seo svg tinymce vs code woocommerce wordpress wpengine xss yii youtube

Categories

  • Coding
  • Off the Shelf
  • Plugins
  • Random Thoughts
  • Server Stuff
  • Tools
  • Uncategorized