-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
// Silence is good |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
// Silence is good |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
// Silence is good |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
/** | ||
* Main Stable Class | ||
* | ||
* @since 0.0.1 | ||
* @package Stable | ||
*/ | ||
|
||
// Exit if ST_PATH is Undefined | ||
defined('ST_PATH') || exit; | ||
|
||
/** | ||
* Stable | ||
* | ||
* @class Stable | ||
*/ | ||
final class Stable | ||
{ | ||
/** | ||
* Stable defaults | ||
* | ||
* @since 0.0.1 | ||
* @static | ||
* @var array | ||
*/ | ||
protected static $defaults = array( | ||
'name' => 'Stable', | ||
/** Enter default options here in array */ | ||
); | ||
|
||
/** | ||
* Stable options | ||
* | ||
* @since 0.0.1 | ||
* @var array | ||
*/ | ||
protected $options = array(); | ||
|
||
/** | ||
* The single instance of the class. | ||
* | ||
* @since 0.0.1 | ||
* @static | ||
* @var Stable | ||
*/ | ||
protected static $instanced = null; | ||
|
||
/** | ||
* Main Stable Instance | ||
* Ensures only one instance of Stable is loaded or can be loaded. | ||
* | ||
* @since 0.0.1 | ||
* @static | ||
* @see ST() | ||
* @param array|object|string $args Optional. Value to merge with `self::defaults`. | ||
* Default: Empty array. | ||
* @return Stable Singleton Stable Instance | ||
*/ | ||
public static function instance($args = array()) | ||
{ | ||
if (is_null(self::$instanced)) { | ||
self::$instanced = new self($args); | ||
} | ||
return self::$instanced; | ||
} | ||
|
||
/** | ||
* Stable Constructor | ||
* | ||
* @since 0.0.1 | ||
* @param array|object|string $args Optional. Value to merge with `self::defaults`. | ||
* Default: Empty array. | ||
* | ||
* @return Stable Stable Instance | ||
*/ | ||
public function __construct(array $args = array()) | ||
{ | ||
$this->options = (array) wp_parse_args($args, self::$defaults); | ||
} | ||
|
||
/** | ||
* Returns the options of the instance | ||
* | ||
* @since 0.0.1 | ||
* | ||
* @return array Full list of options | ||
*/ | ||
public function get_options() | ||
{ | ||
return $this->options; | ||
} | ||
|
||
/** | ||
* Returns the value of a given option | ||
* | ||
* @since 0.0.1 | ||
* @param string $key Optional. Option name. | ||
* Default: `'name'`. | ||
* | ||
* @return array Full list of options | ||
*/ | ||
public function get_option(string $key = 'name') | ||
{ | ||
return (is_array($this->options) && array_key_exists($key, $this->options)) ? $this->options[$key] : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
// Silence is good |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/** | ||
* Main Stable Function | ||
* | ||
* @since 0.0.1 | ||
* @package Stable | ||
*/ | ||
|
||
// Exit if ST_PATH is Undefined | ||
defined('ST_PATH') || exit; | ||
|
||
if (!function_exists('ST')) { | ||
/** | ||
* Returns the main instance of Stable. | ||
* | ||
* @since 0.0.1 | ||
* @param array|object|string $args Optional. Value to merge with `self::defaults`. | ||
* Default: Empty array. | ||
* @return Stable Singleton Stable Instance | ||
*/ | ||
function ST($args = array()) | ||
{ | ||
return Stable::instance($args); | ||
} | ||
} | ||
|
||
if (!function_exists('st_console_log')) { | ||
/** | ||
* Simple helper to debug to the console. | ||
* | ||
* It is used to log into the console with PHP | ||
* by making use of JavaScript. | ||
* | ||
* @category PHP | ||
* | ||
* @since 0.0.1 | ||
* @param mixed|object|array|string $data Value to log to console. Required, Default: NULL | ||
* @param string $context Description. Optional, Default: '' | ||
* | ||
* @return void | ||
* | ||
* @version 1.0 | ||
* @author Onur Boz <[email protected]> | ||
* @copyright (c) 2022 Boz | ||
* @license MIT License, https://onurboz.com/mit | ||
* @link https://bozdev.vom | ||
*/ | ||
function st_console_log($data = null, $context = '') | ||
{ | ||
// Buffering to solve problems frameworks, like header() in this and not a solid return. | ||
ob_start(); | ||
|
||
$output = $context ? 'console.info(\'' . $context . ':\');' : ''; | ||
$output .= 'console.log(' . json_encode($data) . ');'; | ||
$output = sprintf('<script>%s</script>', $output); | ||
|
||
echo $output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
// Silence is good |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/** | ||
* It will set up the Stable environment | ||
* | ||
* @since 0.0.1 | ||
* @package Stable | ||
*/ | ||
|
||
// Exit if ST_PATH is Undefined | ||
defined('ST_PATH') || exit; | ||
|
||
/** | ||
* Load the Stable class library | ||
* | ||
* @package Stable | ||
*/ | ||
if (!class_exists('Stable', false)) { | ||
include_once(ST_INC . 'st-classes/class.stable.php'); | ||
} | ||
|
||
/** | ||
* Load the Stable function library | ||
* | ||
* @package Stable | ||
*/ | ||
if (!function_exists('ST')) { | ||
include_once(ST_INC . 'st-functions/function.stable.php'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/** | ||
* Plugin Name: Stable | ||
* Plugin URI: https://bozdev.com/ | ||
* Description: Ready-made WordPress plugin infrastructure that can be used over and over again. | ||
* Version: 0.0.1 | ||
* Author: Onur BOZ | ||
* Author URI: https://onurboz.com/ | ||
* Text Domain: stable | ||
* | ||
* Requires PHP: 5.0 | ||
* | ||
* @package Stable | ||
*/ | ||
|
||
// Exit if ABSPATH is Undefined | ||
defined('ABSPATH') || exit; | ||
|
||
/** Define ST_FILE as this file */ | ||
if (!defined('ST_FILE')) { | ||
define('ST_FILE', __FILE__); | ||
} | ||
|
||
/** Define ST_PATH as this file's directory */ | ||
if (!defined('ST_PATH')) { | ||
if (file_exists(__DIR__ . '/stable.php')) { | ||
define('ST_PATH', __DIR__ . '/'); | ||
} else { | ||
define('ST_PATH', dirname(__FILE__) . '/'); | ||
} | ||
} | ||
|
||
// Exit if file not exists | ||
file_exists(ST_PATH . 'stable.php') || exit; | ||
|
||
/** Define ST_INC as `st-includes`'s directory */ | ||
if (!defined('ST_INC')) { | ||
define('ST_INC', ST_PATH . 'st-includes/'); | ||
} | ||
|
||
// Exit if add_action is Undefined Function | ||
function_exists('add_action') || exit; | ||
|
||
// Exit if file not exists | ||
file_exists(ST_INC . 'st-load.php') || exit; | ||
|
||
/** | ||
* Load the Stable Environment | ||
* | ||
* @package Stable | ||
*/ | ||
include_once(ST_INC . 'st-load.php'); | ||
|
||
// Global for backwards compatibility. | ||
$GLOBALS['ST'] = ST(); |