Activator
in package
Uses
UtilsProvider, Activator
The activator class handles the plugin relevant activation hooks: Uninstall, activation, deactivation and installation. The "installation" means installing needed database tables.
Table of Contents
Constants
- OPTION_NAME_INSTALLATION_DATE = RCB_OPT_PREFIX . '-installation-date'
- OPTION_NAME_NEEDS_DEFAULT_CONTENT = RCB_OPT_PREFIX . '-needs-default-content'
Properties
- $charsetCollate : string
- See `$this->getCharsetCollate()`.
Methods
- activate() : mixed
- Method gets fired when the user activates the plugin.
- addInitialContent() : mixed
- Add initial content after first installation. It also supports multiple languages (e.g. WPML and PolyLang).
- anyPluginToggledState() : mixed
- Any plugin got deactivated / activated so let's recalculate the templates cache.
- dbDelta() : mixed
- Install tables, stored procedures or whatever in the database.
- deactivate() : mixed
- Method gets fired when the user deactivates the plugin.
- detectFirstInstallation() : mixed
- Detect first installation and conditionally create initial content.
- getCharsetCollate() : mixed
- Get the charset collate definition for the SQL command. Similar to `$wpdb->get_charset_collate()` but it ensures to **not** mix the collates of our plugin database tables.
- getDatabaseVersion() : mixed
- Get the current persisted database version.
- getFirstDatabaseTableName() : mixed
- getMaxIndexLength() : mixed
- Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
- getPluginConstantPrefix() : string
- Get the prefix of this plugin so composer packages can dynamically build other constant values on it.
- getPreviousDatabaseVersions() : array<string|int, string>
- Get a list of previous installed database versions.
- install() : bool
- Run an installation or dbDelta within a callable.
- isMigrationLocked() : If
- Check if the migration is locked. It uses a time span of 10 minutes (like Yoast SEO plugin).
- persistPreviousVersion() : mixed
- Persist the previous installed versions of this plugin so we can e.g. start migrations.
- registerCapabilities() : mixed
- removeColumnsFromTable() : mixed
- `dbDelta` does currently not support removing columns from tables. For this, we need to read the structure of the table and remove the column accordingly on existence.
- removeIndicesFromTable() : mixed
- `dbDelta` does currently not support removing indices from tables so updating e.g. `UNIQUE KEYS` does not work.
- removePreviousPersistedVersions() : mixed
- Remove the previous persisted versions from the saved option. This is useful if you have successfully finished your migration.
- removeTables() : mixed
- Remove database tables if they exist.
- uninstall() : mixed
- Uninstall our plugin (it does currently not remove any settings!).
Constants
OPTION_NAME_INSTALLATION_DATE
public
mixed
OPTION_NAME_INSTALLATION_DATE
= RCB_OPT_PREFIX . '-installation-date'
OPTION_NAME_NEEDS_DEFAULT_CONTENT
public
mixed
OPTION_NAME_NEEDS_DEFAULT_CONTENT
= RCB_OPT_PREFIX . '-needs-default-content'
Properties
$charsetCollate
See `$this->getCharsetCollate()`.
private
string
$charsetCollate
= null
Methods
activate()
Method gets fired when the user activates the plugin.
public
activate() : mixed
addInitialContent()
Add initial content after first installation. It also supports multiple languages (e.g. WPML and PolyLang).
public
addInitialContent() : mixed
anyPluginToggledState()
Any plugin got deactivated / activated so let's recalculate the templates cache.
public
anyPluginToggledState() : mixed
dbDelta()
Install tables, stored procedures or whatever in the database.
public
dbDelta(bool $errorlevel) : mixed
This method is always called when the version bumps up or for the first initial activation.
Parameters
- $errorlevel : bool
-
If true throw errors
deactivate()
Method gets fired when the user deactivates the plugin.
public
deactivate() : mixed
detectFirstInstallation()
Detect first installation and conditionally create initial content.
public
detectFirstInstallation() : mixed
getCharsetCollate()
Get the charset collate definition for the SQL command. Similar to `$wpdb->get_charset_collate()` but it ensures to **not** mix the collates of our plugin database tables.
public
getCharsetCollate() : mixed
Tags
getDatabaseVersion()
Get the current persisted database version.
public
getDatabaseVersion() : mixed
getFirstDatabaseTableName()
public
getFirstDatabaseTableName() : mixed
getMaxIndexLength()
Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
public
getMaxIndexLength() : mixed
As of 4.2, however, we moved to utf8mb4, which uses 4 bytes per character. This means that an index which used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
Tags
getPluginConstantPrefix()
Get the prefix of this plugin so composer packages can dynamically build other constant values on it.
public
getPluginConstantPrefix() : string
Tags
Return values
stringgetPreviousDatabaseVersions()
Get a list of previous installed database versions.
public
getPreviousDatabaseVersions() : array<string|int, string>
Return values
array<string|int, string>install()
Run an installation or dbDelta within a callable.
public
install([bool $errorlevel = false ][, callable $installThisCallable = null ]) : bool
Parameters
- $errorlevel : bool = false
-
Set true to throw errors.
- $installThisCallable : callable = null
-
Set a callable to install this one instead of the default.
Return values
bool —Returns false
when e.g. the migration got locked
isMigrationLocked()
Check if the migration is locked. It uses a time span of 10 minutes (like Yoast SEO plugin).
public
isMigrationLocked([int $set = null ]) : If
Parameters
- $set : int = null
Tags
Return values
If —$set
is a numeric, it returns a boolean indicating if the update of the migration was successful, otherwise it returns a boolean
if the migration is locked.
persistPreviousVersion()
Persist the previous installed versions of this plugin so we can e.g. start migrations.
public
persistPreviousVersion() : mixed
registerCapabilities()
public
registerCapabilities() : mixed
removeColumnsFromTable()
`dbDelta` does currently not support removing columns from tables. For this, we need to read the structure of the table and remove the column accordingly on existence.
public
removeColumnsFromTable(string $tableName, array<string|int, string> $columnNames) : mixed
Parameters
- $tableName : string
-
This is not escaped, so use only the result of
$this->getTableName()
! - $columnNames : array<string|int, string>
removeIndicesFromTable()
`dbDelta` does currently not support removing indices from tables so updating e.g. `UNIQUE KEYS` does not work.
public
removeIndicesFromTable(string $tableName, array<string|int, array<string|int, mixed>> $indexConfigurations) : mixed
For this, you need to add a new index name and remove the old one.
The index needs to be configured like this:
$indexConfigurations = [
'PRIMARY' = ['myColumn1', 'myColumn2']
]
Parameters
- $tableName : string
-
This is not escaped, so use only the result of
$this->getTableName()
! - $indexConfigurations : array<string|int, array<string|int, mixed>>
Tags
removePreviousPersistedVersions()
Remove the previous persisted versions from the saved option. This is useful if you have successfully finished your migration.
public
removePreviousPersistedVersions(callable $filter) : mixed
Parameters
- $filter : callable
removeTables()
Remove database tables if they exist.
public
removeTables(array<string|int, string> $tableNames) : mixed
Parameters
- $tableNames : array<string|int, string>
-
This is not escaped, so use only the result of
$this->getTableName()
!
uninstall()
Uninstall our plugin (it does currently not remove any settings!).
public
static uninstall() : mixed