Q1: Why is the error happening?
Let's look at what the error says. The message you get tells you what the problem is and where it's throwing the error. Let's break it down.
Plugin could not be activated because it triggered a fatal error. Parse error: syntax error, unexpected 'function' (T_FUNCTION) in /latamconnex/wp-content/plugins/my-wp-cron-test/my-wp-cron-test.php on line 12
- It's a "syntax error"
- It's located in the file
/latamconnex/wp-content/plugins/my-wp-cron-test/my-wp-cron-test.php
- The error is thrown on line 12 of that file.
It's telling you there is a syntax error on or before line 12 of that file.
Looking at your code, line 1 has an error in it. Do you see it? You have <? php
on line 1. PHP is not going to recognize that line as the opening PHP tag. Why? There's a space in between the ?
and php
.
Change that line to <?php
. Notice, there's no space.
Make sure there are no other syntax errors between line 1 and 12.
Tip: Remove the Closing PHP Tag
You don't need the closing PHP tag ?>
at the end of the file. I recommend removing the closing PHP tag.
Why? Any extra spaces or lines after that tag will cause the dreaded white screen of death. You can see the conversation about it here on Stack Overflow.
The best practice here is to omit the optional closing tag from all PHP files.
Q2:
Basically, I'd like to know what I need to know in order for even the simplest of plugins to activate.
First, WordPress has to recognize your code as a "plugin." Then once it finds it, then it's available for activation. There does not have to be a single line of code in the file for it to be activated.
How does WordPress recognize the plugin?
WordPress searches each folder in the wp-content/plugins
folder. It's looking in the root of each folder for a bootstrap file.
What makes a file the "bootstrap?"
It's the file header (DocBlock) that identifies the plugin and makes it available to WordPress. That's your bootstrap file.
WordPress searches in the plugin folder's root for the file that has the properly structured file header.
The structure is defined in this Header Requirements document.
What should be in a plugin file?
All that's needed for the file to be activated is:
- The opening PHP tag, i.e.
<?php
- The file's DocBlock
That's it. Now it's added to the list of plugins in Plugins > Installed Plugins (in the WordPress back-end admin).