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.
# 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> |
/* Responsive IFrame example | |
* @author Alain Schlesser <alain.schlesser@gmail.com> | |
/* The wrapper gets resized using padding-bottom with a percentage value. This | |
* way, it's height is always directly dependent on its width */ | |
.iframe-wrapper { | |
/* Necessary so we can position the contained IFrame absolutely */ | |
position: relative; | |
<?php | |
/** | |
* OrderedInvokeTrait | |
* | |
* @package BrightNucleus_Core | |
* @author Alain Schlesser <alain.schlesser@gmail.com> | |
* @license GPL-2.0+ | |
* @link http://www.brightnucleus.com/ | |
* @copyright 2015 Alain Schlesser, Bright Nucleus | |
*/ |
<?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:
<?php | |
// file: src/Controller.php | |
/** | |
* Example Plugin Controller. | |
*/ | |
namespace Example\Plugin; | |
use BrightNucleus\Config\ConfigInterface; |
This is a (partial) example to demonstrate the interaction between different reusable components to build an admin page in the WordPress back-end that shows a near-real-time display of the last 30 lines of my log files.
This code will not work as is, as some of it depends on a larger architecture system. Some of the files have been shortened, and the usual file headers and copyright notices have been removed for brevity's sake.
The related components that are discussed are brightnucleus/dependencies and brightnucleus/settings. The configuration is loaded through brightnucleus/config.
Notable "features" of the below code:
<?php namespace Generic; | |
use RuntimeException; | |
/** | |
* Class Autoloader. | |
* | |
* This is a custom autoloader to replace the functionality that we would | |
* normally get through the autoloader generated by Composer. | |
* |
<?php | |
class Plugin | |
{ | |
protected $plugin_root; | |
private $loaded; | |
public function __construct(PluginRoot $plugin_root) | |
{ |