Posts Tagged ‘php’

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' );
29 April, 2014 — Development

Debitoor API Helper Class Version 2.0

Last year I published a PHP API Helper class for the ever-growing Debitoor accounting software. The API is a RESTful API meaning it responds to JSON and HTTPS requests.

As I have got to use this class in projects of mine, I have built upon this class adding improvements and a new Debitoor class that will process your requests for you returning a clean PHP array ready for you to use.

So what has changed?

You can find a list below of what I changed in this release and some newly added files.

Example.php

//Debitoor API Class
// Code by Daniel Roizer - http://thatblogger.co
// v2.0

define(req_code, "REQUEST_CODE");
define(clientID, "CLIENT_ID");
define(clientSecret, "SECRET_KEY");
define(token, "TOKEN_FROM_API");
define(apiURL, "https://app.debitoor.com/api/v1.0/");

require_once("debitoorapi.class.php");
require_once("debitoor.class.php");

$debitoor = new Debitoor();

// Get list of clients as an array()
print_r($debitoor->GetCustomers());

// Get list of products as an array()
print_r($debitoor->GetProducts());

// Add a client
print_r($debitoor->AddClient($name, $address, $phone, $email, $homepage, $cinumber, $vatnumber, $countrycode));

Download Now

You can download version 2.0 of the helper class over at GitHub!
– OR –
View on GitHub

This is not part of Debitoor and is code written by myself. If you wish to have something added or have any questions please comment below or submit a ticket over a GitHub.

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.

9 January, 2014 — Development, Snippets, WordPress

Create a “Recent Posts” Module Outside of WordPress

Not all websites run on WordPress, but some websites might decide to use WordPress as their blogging choice. They decide they want to display the recent posts from the blog on the website. However the website isn’t in the WordPress core. So how do we display the recent posts on the website?

The Code

To be able to use WordPress outside of the WordPress core is simple. Just include the 

wp-load.php
 file in your website:

// Include the wp-load from WordPress Install
include('wp-load.php');

// Get the last 10 posts
$recent_posts = wp_get_recent_posts(array(
    'numberposts' => 10
));

// Output the posts
echo '<ul>';
foreach($recent_posts as $post) {
    echo '<li><a href="', get_permalink($post['ID']), '">', $post['post_title'], '</a></li>';
}
echo '</ul>';

Once you have the 

wp-load.php
 file included, the entire WordPress core is open to use!

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

24 October, 2013 — Development

PHP.net Flagged “Contains Malware” UPDATED

Tried to access php.net today? You might be surprised when you try to and receive the following message.

The Website Ahead Contains Malware!

It would appear that php.net has been flagged as a website that contains malware. Its unclear yet as to if php.net was hacked or this was a mistake?

A message displayed when trying to access php.net via Google states the following:

What happened when Google visited this site?

Of the 1613 pages we tested on the site over the past 90 days, 4 page(s) resulted in malicious software being downloaded and installed without user consent. The last time Google visited this site was on 2013-10-24, and the last time suspicious content was found on this site was on 2013-10-23.

Malicious software includes 4 trojan(s).

Malicious software is hosted on 4 domain(s), including cobbcountybankruptcylawyer.com/stephaniemari.com/northgadui.com/.

3 domain(s) appear to be functioning as intermediaries for distributing malware to visitors of this site, including stephaniemari.com/,northgadui.com/satnavreviewed.co.uk/.

This site was hosted on 79 network(s) including AS36752 (YAHOO-SP1)AS23148 (TERREMARK)AS36444 (NEXCESS-NET).

We will have to see if PHP.net manage to get this issue sorted, in the meantime try using W3 School

 UPDATE: Please see this topic on Google’s forum.