| 1 |
<?php |
| 2 |
/** |
| 3 |
* Gas Framework. |
| 4 |
* |
| 5 |
* @package Admin/Gas |
| 6 |
* @author Julien Liabeuf <julien@liabeuf.fr> |
| 7 |
* @license GPL-2.0+ |
| 8 |
* @link https://getawesomesupport.com |
| 9 |
* @copyright 2014-2017 AwesomeSupport |
| 10 |
*/ |
| 11 |
|
| 12 |
class WPAS_Gas { |
| 13 |
|
| 14 |
/** |
| 15 |
* Instance of this class. |
| 16 |
* |
| 17 |
* @since 1.0.0 |
| 18 |
* @var object |
| 19 |
*/ |
| 20 |
protected static $instance = null; |
| 21 |
|
| 22 |
public function __construct() { |
| 23 |
|
| 24 |
add_action( 'wp_loaded', array( $this, 'load_gas_framework' ), 12 ); |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Return an instance of this class. |
| 30 |
* |
| 31 |
* @since 3.0.0 |
| 32 |
* @return object A single instance of this class. |
| 33 |
*/ |
| 34 |
public static function get_instance() { |
| 35 |
|
| 36 |
// If the single instance hasn't been set, set it now. |
| 37 |
if ( null == self::$instance ) { |
| 38 |
self::$instance = new self; |
| 39 |
} |
| 40 |
|
| 41 |
return self::$instance; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Load Gas Framework. |
| 46 |
* |
| 47 |
* @link |
| 48 |
* @since 3.0.0 |
| 49 |
*/ |
| 50 |
public function load_gas_framework() { |
| 51 |
|
| 52 |
/* |
| 53 |
* When using the embedded framework, use it only if the framework |
| 54 |
* plugin isn't activated. |
| 55 |
*/ |
| 56 |
|
| 57 |
// Don't do anything when we're activating a plugin to prevent errors |
| 58 |
// on redeclaring Gas classes |
| 59 |
$action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; |
| 60 |
if( 'activate' === $action && ! empty( filter_input( INPUT_GET, 'plugin' ) ) ) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
// Check if the framework plugin is activated |
| 65 |
$useEmbeddedFramework = true; |
| 66 |
$activePlugins = get_option('active_plugins'); |
| 67 |
if ( is_array( $activePlugins ) ) { |
| 68 |
foreach ( $activePlugins as $plugin ) { |
| 69 |
if ( is_string( $plugin ) ) { |
| 70 |
if ( stripos( $plugin, '/gas-framework.php' ) !== false ) { |
| 71 |
$useEmbeddedFramework = false; |
| 72 |
break; |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
// Use the embedded Gas Framework |
| 79 |
if ( $useEmbeddedFramework && ! class_exists( 'GASFramework' ) ) { |
| 80 |
require_once( WPAS_PATH . 'includes/gas-framework/gas-framework.php' ); |
| 81 |
} |
| 82 |
|
| 83 |
/* |
| 84 |
* Start your Gas code below |
| 85 |
*/ |
| 86 |
$gas = GASFramework::getInstance( 'wpas' ); |
| 87 |
|
| 88 |
$settings = $gas->createContainer( array( |
| 89 |
'type' => 'admin-page', |
| 90 |
'name' => __( 'Settings', 'awesome-support' ), |
| 91 |
'title' => __( 'Settings', 'awesome-support' ), |
| 92 |
'id' => 'wpas-settings', |
| 93 |
'parent' => 'edit.php?post_type=ticket', |
| 94 |
'capability' => 'settings_tickets' |
| 95 |
) |
| 96 |
); |
| 97 |
|
| 98 |
/** |
| 99 |
* Get plugin core options |
| 100 |
* |
| 101 |
* @var (array) |
| 102 |
* @see admin/includes/settings.php |
| 103 |
*/ |
| 104 |
$options = wpas_get_settings(); |
| 105 |
|
| 106 |
/* Parse options */ |
| 107 |
foreach ( $options as $tab => $content ) { |
| 108 |
|
| 109 |
/* Add a new tab */ |
| 110 |
$tab = $settings->createTab( array( |
| 111 |
'name' => $content['name'], |
| 112 |
'title' => isset( $content['title'] ) ? $content['title'] : $content['name'], |
| 113 |
'id' => $tab |
| 114 |
) |
| 115 |
); |
| 116 |
|
| 117 |
/* Add all options to current tab */ |
| 118 |
foreach( $content['options'] as $option ) { |
| 119 |
|
| 120 |
$tab->createOption( $option ); |
| 121 |
|
| 122 |
if ( isset( $option['type'] ) && 'heading' === $option['type'] && isset( $option['options'] ) && is_array( $option['options'] ) ) { |
| 123 |
|
| 124 |
foreach ( $option['options'] as $opt ) { |
| 125 |
$tab->createOption( $opt ); |
| 126 |
} |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
$tab->createOption( array( 'type' => 'save', ) ); |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
} |
| 140 |
|