Posts Tagged ‘code’

16 June, 2014 — Development, Snippets, WordPress

Hide A WordPress Plugin From Plugin List

I was recently working on a client site, which required me to create a custom plugin for his website. I wanted to hide the plugin from the user, as he was a beginner and the plugin contained some sensitive functions to run his website.

In this snippet, I’ll show you how you can easily hide a WordPress plugin from the plugin list. The plugin will still work, but just won’t appear in the plugin list.

Just add the following snippet to your current theme’s functions.php file:

function hide_my_plugin() {
    global $wp_list_table;
    $hidearr = array('plugin-directory/plugin-file.php');
    $myplugins = $wp_list_table->items;
    foreach ($myplugins as $key => $val) {
        if (in_array($key,$hidearr)) {
            unset($wp_list_table->items[$key]);
        }
    }
}
add_action('pre_current_active_plugins', 'hide_my_plugin');

Replace plugin-directory/plugin-file.php in above code with your plugin’s directory and file name. You can find this info by clicking on edit plugin link from the plugin list.

What about Multisite?

If you wanna hide the plugin from your WordPress Multisite, then you above snippet will not remove the plugin from the Network admin list. Here’s a snippet which will work on the WordPress Multisite

function mu_hide_plugins_network( $plugins ) {
    // let's hide akismet
    if( in_array( 'akismet/akismet.php', array_keys( $plugins ) ) ) {
        unset( $plugins['akismet/akismet.php'] );
    }
    return $plugins;
}
 
add_filter( 'all_plugins', 'mu_hide_plugins_network' );
25 April, 2014 — Snippets, WordPress

Increase WordPress Memory Limit

If you use WordPress often or have a lot of plugins installed you may have come across a PHP memory limit error. This happens when WordPress doesn’t have enough memory to achieve what you are trying to do.

In version 2.5 the WordPress core team added a wp-config.php option WP_MEMORY_LIMIT which allows you to configure the maximum amount of memory that can be used by PHP.

Changing this option in the wp-config.php will only affect your WordPress site and not any other PHP sites.

The default memory allocated to WordPress is 40MB for normal WordPress installations and 64MB for multisite installs. The core will also take into account the php.ini file if there is one and if this number is greater than the default 40MB allocated by WordPress the higher number will then be used.

To change the WordPress memory limit you just add the following into the wp-config.php.

define('WP_MEMORY_LIMIT', '64M');

If this doesn’t change your allocated memory limit your hosts may not allow you change this setting, if this is the case you should contact your hosting company.

28 December, 2013 — Development, Tech

Should Web Designers Be Able To Code?

Over Christmas I was flicking around the internet one evening and stumbled across a blog post here, and after reading it, it got me thinking about events that have happened in my life that leads me to believe that Elliot’s tweet was absolutely correct.

(an old Tweet I know but still just as relevant I think)

If someone is calling themselves a “web designer” they should not only be able to design but have the ability to visually or physically be able to work through the build process for a project’s visual aspect. Thus knowing and getting to know the limitations some designs may have before the final design is signed off by the client, making them think thats what there getting. I can’t remember how many times I have been sent a flat Photoshop (psd) file that is both complex and near impossible to build with the time allocated and the clients budget. Where the designer can’t code and therefore has no reference for the technical abilities needed to achieve the finished design and look they are after.

Web Designers – Can’t or Won’t

As in Elliot’s post there is a clear line between designers who can’t code and those who won’t code. However I think this is somewhat miss leaving in his post as he refers to “can’t” as ‘choosing not to’ – so they can but choose not too – where as I think there are designers who can’t because they don’t know how and need to be taught but are willing to learn.

What’s the options?

So the question is, should people who are web designers be able to code what they see visually? Or maybe we should be designing in the browser from the word go, after all it is 2013 (nearly 2014). Leaving photoshop for what it was built for?

I would love to hear your views from both designers and developers below.

Photo by takorii

15 September, 2013 — Development, Snippets, WordPress

Display A Message On Older Posts

When blog posts get old, sometimes the information in them is not as accurate as they were at the time of writing. This can be misleading and can cause confusion to the reader.

This simple bit of code when either placed in your themes funcions.php file or a functionality plugin will display a message at the top of any posts that are older than 1 year. You can customise the message in the code below and add some styles to your style.css file. Once done upload your file WordPress will automatically take care of the rest.

// display a message on older posts
function tb_older_post_message () {
    $posted = get_the_time('U');
    $current = current_time('timestamp');
    //Convert difference in seconds to days
    $diffTime = ($current - $posted) / (60*60*24);
    if($diffTime > 365){
        echo '<div class=older-post-message>' . __('This post was written more than a year ago and <em>might</em> not be entirely accurate anymore.', 'wptips') . '</div><br />';
    }
}
add_action('get_template_part_content','tb_older_post_message');