Updating WordPress from the dashboard.

I have a bunch of old WordPress installs that I manage. I have been updating them from the command line and updating plug-ins by dragging them from my desktop to the plugins folder using Cyberduck. There is an easier way but it requires a few tweaks to your install.

First you need to change the ownership of each file to www-data. I also change the group to the users group.


sudo chown -R www-data .
sudo chgrp -R user .

Then you need to add a line to the wp-config.php file. I added it to the last line of the file.


/* Sets up direct method for updating without FTP */
define('FS_METHOD','direct'); 

Now anyone with a dashboard login can update the site.

Update from Ubuntu 18.04 to 20.04

I decided to let the update process overwrite any config files that I had edited, knowing that I had a few that might need updating.

There was one issue with Apache2 where the newest version of PHP wasn’t linked in the config files for Apache. The problem was that there were two the load files—one for 7.2 and one for 7.4. I deleted the one for 7.2 and renamed the one for 7.4 then reloaded the modules and restarted Apache. That seems to have worked.


sudo rm /etc/apache2/mods-available/php7.2.load

mv /etc/apache2/mods-available/php7.2.conf /etc/apache2/mods-available/php7.4.conf
sudo a2enmod php7.4

Mail stopped working, but that’s because Dovecot didn’t know where to find the SSL certificates from Let’s Encrypt and where to put the mail. I followed the directions in a previous post and it works now.

Randomizing a PHP Array

I wrote this before it occurred to me to see if MariaDB could randomize the output. It can, with ORDER BY RAND();.

PHP has a shuffle function that can randomize one array, but I have a bunch that need to have the same random order.


// Create an array of numbers
$randomArray = range(0,$numWords-1); 
shuffle($randomArray); 

// Create empty target arrays     
$word = []; $sounds = []; $phrase = []; $sentence = [];

for ( $i = 0; $i < $numWords; $i++ ) {
  // Use the numbers in the random array to swap elements.
  $random = $randomArray[$i];
  $word[$i] = $word_S[$random];
  $sounds[$i] = $sounds_S[$random];
  $phrase[$i] = $phrase_S[$random];
  $sentence[$i] = $sentence_S[$random];
}

Updating sites—PHP Notes

As I mentioned in the previous posts, I’m using W3Schools to review HTML, CSS, and PHP in order to create some exercises. Here are a few things that I didn’t know about PHP or want to remind myself about.

When sending users to specific pages I often use numbers to indicate which page they should go to. Spambots will frequently put in random junk so I do some tests before I process the request. PHP has some odd behaviour with some of the functions. For example,


// Invalid calculation will return a NaN value
$x = acos(8);
echo is_nan($x);     --> 1
echo var_dump($x);   --> float(NAN)
echo is_null($x);    --> expect 0 but get a blank line, so only works on numbers—not NAN
echo is_finite($x);  --> blank line, so only works on numbers—not NAN

echo is_finite("Hello");     --> Warning: is_finite() expects parameter to be a float
echo is_finite(10);          --> 1
echo is_infinite(10);        --> expect 0 but get a blank line
echo is_infinite(10e1111);   --> 1

// $hello not defined
echo var_dump($hello);       --> NULL
echo is_nan($hello);         --> blank line
echo is_null($hello);        --> 1
echo is_finite($hello);      --> 1
echo is_infinite($hello);    --> expect 0 but get a blank line
echo is_int($hello);         --> expect 0 but get a blank line

var_dump(is_numeric($hello)); --> bool(true) 
is_numeric($hello);           --> expect 0 but get a blank line

I never gave constants much thought when developing web pages, but i’m thinking that they might come in handy when making interactive games. If I access the database and grab a bunch of data that will be displayed but won’t change, it should go into a constant array which is then accessible to any function on the page. Note that both constant arrays and variables are referenced by their name without a $ before the name.


define("cars", [
    "Alfa Romeo",
    "BMW",
    "Toyota"
]);
echo cars[0];  --> Alfa Romeo

function arrayDisplay() {
  foreach (cars as $value) {
        echo "$value ";
    }
}
arrayDisplay();  --> Alfa Romeo BMW Toyota

If you use a variable array, the array isn’t available to functions.


$cars = array(
    "Alfa Romeo",
    "BMW",
    "Toyota"
);
var_dump($cars);  -->  array(3) { [0]=> string(10) "Alfa Romeo" [1]=> string(3) "BMW" [2]=> string(6) "Toyota" }

function arrayDisplay() {
  foreach ($cars as $value) {
        echo "$value ";
    }
}
arrayDisplay(); -- > Warning: Invalid argument supplied for foreach() … 

Updating sites—CSS Notes

As I mentioned in the previous post, I’m using W3Schools to review HTML and CSS in order to create some exercises. Here are a few things that I didn’t know about CSS or want to remind myself about.

“Note: Remember that the height and width properties do not include padding, borders, or margins! They set the height/width of the area inside the padding, border, and margin of the element!”

Padding (outline, margins, and border) in CSS is added to the width of an element. So div { width: 300px; padding: 25px;} will have a width of 325 pixels. To keep the width at 300 px you need to add the declaration box-sizing: border-box; inside the brackets.

Occasionally I want to add whitespace and end up using &nbsp; a bunch of times. There is a descriptor, white-space: pre; that will work.

This is a paragraph that has a bunch of spaces before the last word.

There are a bunch of ways to control elements based on where they appear in relation to other elements. I haven’t made much use of these selectors, but mostly because I’m not familiar with them. You can explore them at this W3Schools page.

The column-count:n property is something I wish I had known about. It can be used to divide a div (or p) into columns.

The column-count property is something I wish I had known about. It can be used to divide a div (or p) into columns. There are also a bunch of other properties to control the look as well including: column-fill, column-gap, and column-rule-color.

Here’s another property that can come in handy in association with justify, margin-right: 20%; -webkit-hyphens: auto; -ms-hyphens: hyphens: auto. You need all three to handle different browsers.

Suppose you want to justify your text but you have a bunch of technical terms like bootstrap and alignment and javascript which sometimes mess up the justification. Then you can use -webkit-hyphens: auto; -ms-hyphens: auto; hyphens: auto to clean it up a bit.

Suppose you want to justify your text but you have a bunch of technical terms like bootstrap and alignment and javascript which sometimes mess up the justification. Then you can use -webkit-hyphens: auto; -ms-hyphens: auto; hyphens: auto;.

I just learned about display: flex; justify-content: center; when laying out the previous two paragraphs. I first put them in a div and did a float: left and float:right to get them to display next to each other. Then I manipulated the margins to get them closer to the center. This works better and I just need to make sure there is enough padding so that they don’t brush up against each other.