PluginProbe ʕ •ᴥ•ʔ
WPFront Scroll Top / 1.6
WPFront Scroll Top v1.6
1.5 1.6 1.6.1 1.6.2 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1 2.1.1 2.2 3.0.0 3.0.1 trunk 1.0 1.0.1 1.1 1.1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5
wpfront-scroll-top / classes / base / class-wpfront-base.php
wpfront-scroll-top / classes / base Last commit date
images 8 years ago class-wpfront-base-menu.php 8 years ago class-wpfront-base.php 8 years ago class-wpfront-options-base.php 8 years ago class-wpfront-static.php 8 years ago
class-wpfront-base.php
209 lines
1 <?php
2
3 /*
4 WPFront Plugins Base
5 Copyright (C) 2013, WPFront.com
6 Website: wpfront.com
7 Contact: syam@wpfront.com
8
9 WPFront Plugins are distributed under the GNU General Public License, Version 3,
10 June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11 St, Fifth Floor, Boston, MA 02110, USA
12
13 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25 require_once("class-wpfront-static.php");
26 require_once("class-wpfront-base-menu.php");
27
28 if (!class_exists('WPFront_Base_ST')) {
29
30 /**
31 * Plugin framework base class
32 *
33 * @author Syam Mohan <syam@wpfront.com>
34 * @copyright 2013 WPFront.com
35 */
36 class WPFront_Base_ST {
37
38 private $plugin_slug;
39 private $options_page_slug;
40 private $settingsLink;
41 private $FAQLink;
42
43 protected $pluginURLRoot;
44 protected $pluginDIRRoot;
45 private static $menu_data = array();
46
47 function __construct($file, $pluginSlug, $wpfrontBaseMenu = NULL) {
48 $this->plugin_slug = $pluginSlug;
49 $this->options_page_slug = $this->plugin_slug;
50 if ($wpfrontBaseMenu == NULL)
51 $wpfrontBaseMenu = new WPFront_Base_Menu($this);
52
53 $this->pluginURLRoot = plugins_url() . '/' . $this->plugin_slug . '/';
54 $this->pluginDIRRoot = dirname($file) . '/../';
55
56 add_action('init', array(&$this, 'init'));
57 add_action('plugins_loaded', array(&$this, 'plugins_loaded_base'));
58
59 //register actions
60 if (is_admin()) {
61 add_action('admin_init', array(&$this, 'admin_init'));
62 add_action('admin_menu', array(&$this, 'admin_menu'));
63 add_filter('plugin_action_links', array(&$this, 'action_links'), 10, 2);
64 } else {
65 add_action('wp_enqueue_scripts', array(&$this, 'enqueue_styles'));
66 add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
67 }
68 }
69
70 protected function add_menu($title, $link) {
71 self::$menu_data[] = array(
72 'title' => $title,
73 'link' => $link,
74 'this' => $this,
75 'slug' => $this->options_page_slug
76 );
77 }
78
79 public function init() {
80
81 }
82
83 public function plugins_loaded_base() {
84 //for localization
85 //load_plugin_textdomain($this->plugin_slug, FALSE, $this->plugin_slug . '/languages/');
86
87 $this->plugins_loaded();
88 }
89
90 public function plugins_loaded() {
91
92 }
93
94 public function admin_init() {
95
96 }
97
98 public function admin_menu() {
99 WPFront_Base_Menu::admin_menu(self::$menu_data);
100 }
101
102 public static function submenu_compare($a, $b) {
103 return strcmp($a[0], $b[0]);
104 }
105
106 public function action_links($links, $file) {
107 if ($file == $this->plugin_slug . '/' . $this->plugin_slug . '.php') {
108 $settings_link = '<a href="' . menu_page_url($this->options_page_slug, FALSE) . '">' . __('Settings', 'wpfront-scroll-top') . '</a>';
109 array_unshift($links, $settings_link);
110 }
111 return $links;
112 }
113
114 public function enqueue_styles() {
115
116 }
117
118 public function enqueue_scripts() {
119
120 }
121
122 public function enqueue_options_styles() {
123
124 }
125
126 public function enqueue_options_scripts() {
127
128 }
129
130 //creates options page
131 public function options_page() {
132 if (!current_user_can('manage_options')) {
133 wp_die(__('You do not have sufficient permissions to access this page.', 'wpfront-scroll-top'));
134 return;
135 }
136
137 include($this->pluginDIRRoot . 'templates/options-template.php');
138 }
139
140 protected function options_page_header($title, $optionsGroupName) {
141 echo '<div class="wrap">';
142 @screen_icon($this->options_page_slug);
143 echo '<h2>' . $title . '</h2>';
144 echo '<div id="' . $this->options_page_slug . '-options" class="inside">';
145 echo '<form method="post" action="options.php">';
146 @settings_fields($optionsGroupName);
147 @do_settings_sections($this->options_page_slug);
148
149 if ((isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true') || (isset($_GET['updated']) && $_GET['updated'] == 'true')) {
150 echo '
151 <div class="updated">
152 <p>
153 <strong>' . __('If you have a caching plugin, clear the cache for the new settings to take effect.', 'wpfront-scroll-top') . '</strong>
154 </p>
155 </div>
156 ';
157 }
158 }
159
160 protected function options_page_footer($settingsLink, $FAQLink, $extraLinks = NULL) {
161 @$this->submit_button();
162
163 if ($extraLinks != NULL) {
164 foreach ($extraLinks as $value) {
165 echo '<a href="' . $value['href'] . '" target="' . $value['target'] . '">' . $value['text'] . '</a>';
166 echo ' | ';
167 }
168 }
169
170 echo '</form>';
171 echo '</div>';
172 echo '</div>';
173
174 $this->settingsLink = $settingsLink;
175 $this->FAQLink = $FAQLink;
176
177 add_filter('admin_footer_text', array($this, 'admin_footer_text'));
178 }
179
180 public function admin_footer_text($text) {
181 $settingsLink = sprintf('<a href="%s" target="_blank">%s</a>', 'https://wpfront.com/' . $this->settingsLink, __('Settings Description', 'wpfront-scroll-top'));
182 $reviewLink = sprintf('<a href="%s" target="_blank">%s</a>', 'https://wordpress.org/support/plugin/' . $this->plugin_slug . '/reviews/', __('Write a Review', 'wpfront-scroll-top'));
183 $donateLink = sprintf('<a href="%s" target="_blank">%s</a>', 'https://wpfront.com/donate/', __('Buy me a Beer or Coffee', 'wpfront-scroll-top'));
184
185 return sprintf('%s | %s | %s | %s', $settingsLink, $reviewLink, $donateLink, $text);
186 }
187
188 //for compatibility
189 public function submit_button() {
190 if (function_exists('submit_button')) {
191 submit_button();
192 } else {
193 echo '<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="' . __('Save Changes', 'wpfront-scroll-top') . '" /></p>';
194 }
195 }
196
197 public function pluginURL() {
198 return $this->pluginURLRoot;
199 }
200
201 public function pluginDIR() {
202 return $this->pluginDIRRoot;
203 }
204
205 }
206
207 }
208
209