Skip to content

Commit

Permalink
Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ionurboz committed Mar 14, 2024
1 parent e198e97 commit 9db78c2
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is good
2 changes: 2 additions & 0 deletions st-includes/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is good
2 changes: 2 additions & 0 deletions st-includes/st-assets/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is good
107 changes: 107 additions & 0 deletions st-includes/st-classes/class.stable.php
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;
}
}
2 changes: 2 additions & 0 deletions st-includes/st-classes/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is good
60 changes: 60 additions & 0 deletions st-includes/st-functions/function.stable.php
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;
}
}
2 changes: 2 additions & 0 deletions st-includes/st-functions/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is good
29 changes: 29 additions & 0 deletions st-includes/st-load.php
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');
}
56 changes: 56 additions & 0 deletions stable.php
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();

0 comments on commit 9db78c2

Please sign in to comment.