|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BetterOptin Options |
|
4
|
|
|
* |
|
5
|
|
|
* @package BetterOptin/Titan Framework |
|
6
|
|
|
* @author ThemeAvenue <[email protected]> |
|
7
|
|
|
* @license GPL-2.0+ |
|
8
|
|
|
* @link http://themeavenue.net |
|
9
|
|
|
* @copyright 2015 ThemeAvenue |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// If this file is called directly, abort. |
|
13
|
|
|
if ( ! defined( 'WPINC' ) ) { |
|
14
|
|
|
die; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
add_action( 'setup_theme', array( 'WPBO_Titan', 'get_instance' ), 11 ); |
|
18
|
|
|
|
|
19
|
|
|
class WPBO_Titan { |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Instance of the Titan Framework. |
|
23
|
|
|
* |
|
24
|
|
|
* @since 1.0.0 |
|
25
|
|
|
* @var object |
|
26
|
|
|
*/ |
|
27
|
|
|
public static $instance = null; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Instance of the plugin settings page. |
|
31
|
|
|
* |
|
32
|
|
|
* @since 1.0.0 |
|
33
|
|
|
* @var object |
|
34
|
|
|
*/ |
|
35
|
|
|
public $settings = null; |
|
36
|
|
|
|
|
37
|
|
|
public $titan; |
|
38
|
|
|
|
|
39
|
|
|
public function __construct() { |
|
40
|
|
|
$this->load_titan_framework(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Return an instance of this class. |
|
45
|
|
|
* |
|
46
|
|
|
* @since 1.0.0 |
|
47
|
|
|
* |
|
48
|
|
|
* @return object A single instance of this class. |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function get_instance() { |
|
51
|
|
|
|
|
52
|
|
|
// If the single instance hasn't been set, set it now. |
|
53
|
|
|
if ( null == self::$instance ) { |
|
54
|
|
|
self::$instance = new self; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return self::$instance; |
|
58
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Loads Titan Framework. |
|
63
|
|
|
* |
|
64
|
|
|
* Titan Framework is used to handle all plugin options. |
|
65
|
|
|
* |
|
66
|
|
|
* @since 1.0.0 |
|
67
|
|
|
*/ |
|
68
|
|
|
public function load_titan_framework() { |
|
69
|
|
|
|
|
70
|
|
|
// Don't do anything when we're activating a plugin to prevent errors |
|
71
|
|
|
// on redeclaring Titan classes |
|
72
|
|
|
if ( ! empty( $_GET['action'] ) && ! empty( $_GET['plugin'] ) ) { |
|
73
|
|
|
if ( $_GET['action'] == 'activate' ) { |
|
74
|
|
|
return; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
// Check if the framework plugin is activated |
|
79
|
|
|
$useEmbeddedFramework = true; |
|
80
|
|
|
$activePlugins = get_option('active_plugins'); |
|
81
|
|
|
if ( is_array( $activePlugins ) ) { |
|
82
|
|
|
foreach ( $activePlugins as $plugin ) { |
|
83
|
|
|
if ( is_string( $plugin ) ) { |
|
84
|
|
|
if ( stripos( $plugin, '/titan-framework.php' ) !== false ) { |
|
85
|
|
|
$useEmbeddedFramework = false; |
|
86
|
|
|
break; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
// Use the embedded Titan Framework |
|
92
|
|
|
if ( $useEmbeddedFramework && ! class_exists( 'TitanFramework' ) ) { |
|
93
|
|
|
// require_once( WPBO_PATH . 'vendor/gambitph/titan-framework/titan-framework.php' ); |
|
|
|
|
|
|
94
|
|
|
require_once( ABSPATH . 'wp-content/Titan-Framework/titan-framework.php' ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* wpbo_before_load_titan hook |
|
99
|
|
|
*/ |
|
100
|
|
|
do_action( 'wpbo_before_load_titan' ); |
|
101
|
|
|
|
|
102
|
|
|
$this->titan = TitanFramework::getInstance( 'wpbo' ); |
|
103
|
|
|
$this->settings = $this->titan->createAdminPage( array( |
|
104
|
|
|
'name' => __( 'Settings', 'betteroptin' ), |
|
105
|
|
|
'title' => __( 'BetterOptin Settings', 'betteroptin' ), |
|
106
|
|
|
'parent' => 'edit.php?post_type=wpbo-popup', |
|
107
|
|
|
'position' => 999, |
|
108
|
|
|
'id' => 'wpbo-settings' |
|
109
|
|
|
) ); |
|
110
|
|
|
|
|
111
|
|
|
/* Get all options */ |
|
112
|
|
|
$options = $this->get_options(); |
|
113
|
|
|
|
|
114
|
|
|
/* Iterate */ |
|
115
|
|
|
foreach( $options as $tab => $content ) { |
|
116
|
|
|
|
|
117
|
|
|
/* Add a new tab */ |
|
118
|
|
|
$tab = $this->settings->createTab( array( |
|
119
|
|
|
'name' => $content['name'], |
|
120
|
|
|
'title' => isset( $content['title'] ) ? $content['title'] : $content['name'], |
|
121
|
|
|
'id' => $tab |
|
122
|
|
|
) |
|
123
|
|
|
); |
|
124
|
|
|
|
|
125
|
|
|
/* Add all options to current tab */ |
|
126
|
|
|
foreach( $content['options'] as $option ) { |
|
127
|
|
|
$tab->createOption( $option ); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
$tab->createOption( array( 'type' => 'save', ) ); |
|
131
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
protected function get_options() { |
|
137
|
|
|
return apply_filters( 'wpbo_plugin_settings', array() ); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.