How To Increase WordPress Memory After PHP Fatal error: Allowed memory size exhausted

Author: , February 13th, 2017

PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 277644940 bytes) in /volumes/data/customer/wordpress/wp-content/plugins/searchwp/vendor/pdfparser/vendor/smalot/pdfparser/src/Smalot/PdfParser/Parser.php on line 72, referer: http://dev.thecustomer.com/index.php?swpnonce=1387006674.5392169952592578125000 To increase the PHP memory limit to 256MB, edit wp-config.php and add the following just before the line that says “That’s all, stop editing! Happy blogging.”: 1 define( ‘WP_MEMORY_LIMIT’, ’256M’ ); define( ‘WP_MEMORY_LIMIT’, […]

How To Convert from mysql_ to mysqli_ in WordPress Plugins Easily

Author: , August 24th, 2016

As PHP deprecates old functions, sometimes code maintenance changes become required for long-running sites. As of PHP 5.5, the MySQL functions are deprecated and are removed in PHP 7! I recently had to convert multiple sites to mysqli PHP functions because a new server was running PHP 5.6 and the old server was on PHP […]

How To Convert UNIX Timestamps to Date using PHP CLI

Author: , August 15th, 2015

For a quick visual check to see what the human-readable date is based on a UNIX timestamp integer: php -r ‘print date(“r”,1483228799);’ php -r ‘print strtotime(“1 Jan 2015″) – 1;’

How To Get SMF 2.0.6 to Open in a New Frame

Author: , October 23rd, 2013

The latest patch version of the SMF forum, 2.0.6, now prevents the site from opening up in an HTML frame. Simply comment out line 104 inside index.php: The Problem: $ grep -Rni X-Frame-Options * index.php:104: header(‘X-Frame-Options: SAMEORIGIN’); The Solution: //header(‘X-Frame-Options: SAMEORIGIN’);

How To Install AWS SDK v2 Using PEAR

Author: , August 3rd, 2013

1 2 3 pear upgrade pear pear -D auto_discover=1 install pear.amazonwebservices.com/sdk require ‘AWSSDKforPHP/aws.phar’; pear upgrade pear pear -D auto_discover=1 install pear.amazonwebservices.com/sdk require ‘AWSSDKforPHP/aws.phar’; http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/installation.html#installing-via-pear http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/quick-start.html http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/configuration.html

How To Find the Complete Page URL in PHP

Author: , October 25th, 2012

1 2 3 4 5 $URL   = ‘http’; if ($_SERVER["HTTPS"] == "on") {     $URL   .= "s"; }   $URL   .= ‘://’.$_SERVER[’HTTP_HOST’].$_SERVER[’REQUEST_URI’]; $URL = ‘http’; if ($_SERVER["HTTPS"] == “on”) { $URL .= “s”; } $URL .= ‘://’.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

How To Create Public and Private ShortCodes in WordPress

Author: , October 22nd, 2012

Add this to your theme’s functions.php file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 /* Add the [private] shortcode. */ add_shortcode( ‘private’, ‘is_user_logged_in_shortcode’ );   /* Add the [public] shortcode. */ add_shortcode( ‘public’, ‘is_user_not_logged_in_shortcode’ );   function is_user_logged_in_shortcode( $attr, $content = […]

How To Validate Email Addresses in PHP

Author: , October 21st, 2012

1 2 3 4 5 6 $valid = validateEmailAddress(’yourName@yourDomain.com’);   function validateEmailAddress($email = ”) {    // returns 1 for valid and 0 for invalid    return (int) (filter_var($email, FILTER_VALIDATE_EMAIL) && preg_match(’/@.+\./’, $email)); } $valid = validateEmailAddress(‘yourName@yourDomain.com’); function validateEmailAddress($email = ”) { // returns 1 for valid and 0 for invalid return (int) (filter_var($email, FILTER_VALIDATE_EMAIL) […]

How To Create a Code Block in PHP for Error Handling

Author: , October 19th, 2012

The do/while statement is sometimes used to break out of a block of code when an error condition occurs. For example: 1 2 3 4 5 6 do {   // do some stuff   if ($error_condition)     break;   // do some other stuff } while (false); do { // do some stuff […]

How To Create a New Directory in AWS S3

Author: , October 10th, 2012

1 2 3 $s3->create_object(’<bucket_name>’, ‘folder/’, array(’body’ => ”)); ~OR~ $s3->create_object(’<bucket_name>’, ‘folder/’, array(’body’ => ”, ‘contentType’ => ‘application/x-directory’)); $s3->create_object(‘<bucket_name>’, ‘folder/’, array(‘body’ => ”)); ~OR~ $s3->create_object(‘<bucket_name>’, ‘folder/’, array(‘body’ => ”, ‘contentType’ => ‘application/x-directory’));