Example code to an answer on StackExchange:
Demonstrates accessing an OOP plugin's object instance and using its methods through:
- a static method of the plugin;
- a function of the plugin.
<?php | |
/* | |
* PHPFeature example usage code | |
*/ | |
// Array of strings to define what features you need. | |
$features = array( 'namespaces', 'traits' ); | |
// Instantiate the PHPFeature library. | |
// When you don't provide a version number as the first argument, |
<?php | |
/** | |
* Example plugin. | |
* | |
* @see http://wordpress.stackexchange.com/questions/220286/what-is-the-best-way-to-instantiate-a-class-of-a-plugin-in-your-wordpress-theme/ | |
* | |
* @wordpress-plugin | |
* Plugin Name: Example plugin. | |
* Description: Accessing a plugin object from a theme. | |
* Version: 0.1.0 |
Example code to an answer on StackExchange:
Demonstrates accessing an OOP plugin's object instance and using its methods through:
# Redirect HTTP to HTTPS, for the main domain as well as all subdomains. | |
# | |
# Example: | |
# http://domain.com/ => https://domain.com/ | |
# http://subdomain.domain.com/ => https://subdomain.domain.com/ | |
# | |
# Make sure you replace "replacewithyourdomain" with your actual root domain! | |
# | |
# @author: Alain Schlesser <alain.schlesser@gmail.com> |
<?php | |
/** | |
* Translatable string with multiple links that can be reordered and renamed | |
* @author Alain Schlesser (alain.schlesser@gmail.com) | |
* | |
* @see http://php.net/manual/function.preg-replace.php | |
* @see http://codex.wordpress.org/Function_Reference/_2 | |
*/ |
<?php | |
class Plugin | |
{ | |
protected $plugin_root; | |
private $loaded; | |
public function __construct(PluginRoot $plugin_root) | |
{ |
I hereby claim:
To claim this, I am signing this object:
<?php | |
/** | |
* Shortcode to display copyright notice with current year | |
* @author Alain Schlesser (alain.schlesser@gmail.com) | |
*/ | |
function as_shortcode_copyright() { | |
// generate output in the form of "(C) 2015 Greatest Blog Ever" | |
$copyright = '© ' . date( 'Y' ) . ' ' . get_bloginfo( 'name' ); |
<?php declare( strict_types=1 ); | |
final class RoboFile extends \Robo\Tasks { | |
public function createEmpty( string $name, string $tld = 'localhost', string $email = 'alain.schlesser@gmail.com' ) { | |
$io = $this->io(); | |
$root = __DIR__; | |
$io->title( 'Creating an empty local WordPress site' ); |
This simple Robo script let's you quickly pull up a new site via Valet+.
This was mention and demonstrated during Episode of my "Personal Home Page" livestream. More information about the livestream can be found at https://www.alainschlesser.com/streaming/.