WordPress plugin Cachify cache clear

May 1st, 2012
This little WordPress plug-in will allow any logged in user to clear the cachify cache manually. Will only work if the cachify cache mode is set to “cache ondisk”.

/*
Plugin Name: Clear Cachify cache
Description: Enables Clear cache buttons for all users
Version: The Plugin"s Version Number, e.g.: 1.0
Author: Thorsten Krug
License: GPL
*/

// prepare cachlink
$currenturl = substr($_SERVER["REQUEST_URI"], 0, strpos($_SERVER["REQUEST_URI"], "?"))."?";
$getvars = $_GET; 
if(! in_array("clearifycache", $getvars)){
  $getvars["clearifycache"]="clearifycache";
}
foreach ($getvars as $key =>$val){
  $currenturl .=$key."=".$val."&";
}
$GLOBALS["cache-clear-uri"] = substr($currenturl,0,-1);

// action
function clearcachify_go(){
  if(isset($_GET["clearifycache"]) and is_user_logged_in() ){

  if (CACHIFY_CACHE_DIR){
    if( 0 == shell_exec ( "rm -rf ".CACHIFY_CACHE_DIR."/*"  ) ){
        add_action("admin_notices", "clearcachify_cleared");
      }
    }
  }
}

function clearcachify_cleared(){
    echo "<div class="updated settings-error"><p>Cache cleared</p></div>";
}

function newMenu() { 
?>
<li class="wp-has-submenu wp-not-current-submenu menu-top toplevel_page_wibstats menu-top-last">
  <div class="wp-menu-image">
    <a href="<?php print $GLOBALS["cache-clear-uri"]; ?>" class="menu-top  menu-top-first menu-top-last" style="line-height: 26px;">
    <img alt="" src="/wp-admin/images/generic.png" style="margin-right: 5px;"> Clear Cache
    </a>
  </div>
  <br />
</li>
<?php }


//this inputs our custom menu
add_filter("adminmenu", "newMenu");
add_action( "admin_init", "clearcachify_go" );


Disable Update for WordPress Plugin

April 18th, 2011
In order to prevent a User from updating a hacked WordPress Plugin, you should implement to following
add_filter('site_transient_update_plugins', 'ap_remove_update_nag'); 
function ap_remove_update_nag() {  unset(--->response[ plugin_basename(__FILE__) ]);
return ;
}
Thanks to hacksandmore.com

How to remove the depreceated target=”_blank” in WordPress TinyMCE?

August 29th, 2010
If you let your users set their Links in WordPress with TinyMCE editor, you might run into some validation Problem, because target=”_blank” is part of the XHTML-Strict Standard. To remove the Options in TinyMCE you need to edit two Files: in wp-includes/js/tinymce/themes/advanced/link.htm remove the Table Row offering the Link Target:
<tr>
<td><label id="targetlistlabel" for="targetlist">{#advanced_dlg.link_target}</label></td>
<td><select id="target_list" name="target_list"></select></td>
</tr>
in wp-includes/js/tinymce/themes/advanced/js/link.js comment out the the call to fillTargetList() in the init-function. If you still want to open external Links in new Windows (or Tabs) you can use this Little Javascript. Links to different Domains will be opened in a new Window.
/** Creating custom :external selector **/
  $.expr[':'].external = function(obj){
      return !obj.href.match(/^mailto\:/)
              && (obj.hostname != location.hostname);
  };
  // Add 'external' CSS class to all external links
  $('a:external').bind( 'click', function(){
      open(this.href);
      return false;
  });

WORDPRESS: Add CSS to Tinymce Editor

August 28th, 2010
There is an easy way to add custom styles to the Editor Panel in WordPress.
  • Create a custom CSS file in your Theme Folder
  • Add the following function to the functions.php file of your theme

if ( ! function_exists('tdav_css') ) {
	function tdav_css() {
		 .= ',' . get_bloginfo('stylesheet_directory') . '/css/tinymce.css';
		return ;
	}
}
add_filter( 'mce_css', 'tdav_css' );

I my Template I use a right Floatbox which can be Edited as a section:
div.tinymceSection + * {
  padding-top: 2em;
  border-top: 3px dashed #cc0000;
  clear: both; /* avoid Images floating into the next section in tinymce textarea */
}

Worpress Plug-in: Multilingual Contact Form

August 26th, 2010
With WordPress and the qtranslate plug-in it is easy to create multilingual websites for small business. My favorite contact form plug-in was discontinued I needed some replacement, which is usable on a multilingual site.

Features:

  • Simple and basic easy to use on any Page or Post
  • Enter and edit all text for fields and error messages in the Backend
  • Compatible with qtranslate and other multi-language Plugins
  • XHTML/HTM5 standard compliant

Read the rest of this entry »

Make All in One SEO and qtranslate work together

April 30th, 2010

In the main Plugin file all_in_one_seo_pack.php on lines #709 and #711, the $title_attrib and $menulabel variables are not created as Multilingual Variables. In order to make them so you need to add __() around the variables:

#709 :

$filtered = '<li class="page_item page-item-'.$postID.$matches[2].'"><a href="'.$matches[3].'" title="'.__($title_attrib).'">'.__($menulabel).'</a>';

#679 :

$filtered = '<li class="page_item page-item-'.$postID.$matches[2].'"><a href="'.$matches[3].'">'.__($menulabel).'</a>';

Thanks t Karlsan at this Forum

Easy Jquery Syntax Highlighter

April 25th, 2010
Searching for a proper syntax-highlighter for my WordPress Blog is not an easy thing. Many of them support only a few browsers, mass around with XHTML standards or make extensive use of libraries like prototype I don’t want to add to my site. Finally I found a jquery based syntax highlighter which requires only one file in the latest version. It is really easy to integrate into a WordPress template and doing it the smart way it is only loaded if you need it. After installing it to your website you just need to add the following to you jQuery document.ready function:
$(function ($) {
    var SyntaxRoot = template_directory+"/jquery-syntax/";
    if ($('.syntax').length) {
        $.getScript(SyntaxRoot + "jquery.syntax.min.js", function () {
            $.syntax({root: SyntaxRoot});
        });
    }
});
In order to use different jQuery Plugins I added my Template directory as a variable for javascript into the WordPress header:
<script type="text/javascript" charset="utf-8"><!--
var template_directory = "<?php echo get_bloginfo('template_directory'); ?>";
--></script>
In WordPress I use a php Plugin which enables to write php in every Post. With the following function in my Wordoress Theme template.php I can copy and paste my code right into a post by using <?php codeIt('myWhateverCodeSnipplet( echo \'Mind the quotes\' )', 'javascript'); ?>
/* Highlight code */
function codeIt($text, $brush="html"){
  echo '<pre class="syntax brush-'.$brush.'">'."\n".htmlentities($text)."\n".'</pre>'."\n";
}
I set the default brush to html (which recognizes basic <css…> and <script…> tags and optionally overwrite it with the used language. The only drawback i need to quote all single with a Slash to \’

Same template for Category and Subcategory

April 20th, 2010
Using the same template file for a category and its children is not possible with WordPress. In order to do you need to use Elevate Parent Category Template-Plugin. If you using the Plugin you’ll be able to use some adittional template functions:
  • get_category_child()
    returns the current post child category ID.
  • is_parent()
    checks if the current post is at the parent category.
  • get_category_title($id)
    gets the title of the category that is $id.
  • get_category_parent()
    returns the current post’s parent category ID.