PluginProbe
Starter Sites / trunk
Starter Sites vtrunk
trunk 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.3 2.3.1 2.3.2 2.4 2.5 2.6
starter-sites / starter-sites.php

starter-sites.php in Starter Sites trunk, at starter-sites.php

255 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Starter Sites
4 Plugin URI: https://wpstartersites.com/plugin/
5 Description: Ready to go WordPress starter site themes and website demos, all with full pages of real content, and all created with the full site editing block editor. Quickly import global styles, templates, template parts, block patterns, fonts and full website demo content including pages, posts, products and images.
6 Version: 2.6
7 Author: WP Starter Sites
8 Author URI: https://wpstartersites.com/
9 License: GPLv2 or later
10 License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 Text Domain: starter-sites
12 Requires at least: 6.6
13 Tested up to: 7.0
14 Requires PHP: 7.4
15 */
16
17 // Block direct access to the main plugin file.
18 defined( 'ABSPATH' ) || exit;
19
20 class Starter_Sites {
21
22 protected static $instance = null;
23
24 /**
25 * Creates a new Starter_Sites object and implements singleton.
26 *
27 * @return Starter_Sites
28 */
29 static function get_instance() {
30 if ( !is_a( self::$instance, 'Starter_Sites' ) ) {
31 self::$instance = new Starter_Sites();
32 }
33 return self::$instance;
34 }
35
36 /*
37 * Define constants.
38 */
39 public function define_constants() {
40 define( 'STARTER_SITES_VERSION', $this->get_version() );
41 define( 'STARTER_SITES_PATH', plugin_dir_path( __FILE__ ) );
42 define( 'STARTER_SITES_URL', plugin_dir_url( __FILE__ ) );
43 define( 'STARTER_SITES_BASENAME', plugin_basename( __FILE__ ) );
44 define( 'STARTER_SITES_THEME_DEFAULT', 'acai' );
45 define( 'STARTER_SITES_HOME_URL', 'https://wpstartersites.com/' );
46 define( 'STARTER_SITES_PREVIEW_URL', 'https://demo.wpstartersites.com/' );
47 }
48
49 public function get_version() {
50 if ( wp_is_development_mode( 'plugin' ) ) {
51 return time();
52 } else {
53 return '2.6';
54 }
55 }
56
57 /*
58 * Register hooks.
59 */
60 public function register_hooks() {
61 register_activation_hook( __FILE__, [ $this, 'activation' ] );
62 register_deactivation_hook( __FILE__, [ $this, 'deactivation' ] );
63 }
64
65 /*
66 * Filters.
67 */
68 public function filters() {
69 add_filter( 'plugin_action_links_' . STARTER_SITES_BASENAME, [ $this, 'action_links' ] );
70 add_filter( 'plugin_row_meta', [ $this, 'plugin_table_meta' ], 10, 2 );
71 }
72
73 /*
74 * Do required actions.
75 */
76 public function actions() {
77 add_action( 'plugins_loaded', [ $this, 'textdomain' ] );
78 add_action( 'admin_init', [ $this, 'redirect' ] );
79 }
80
81 /**
82 * Runs on activation.
83 */
84 public function activation() {
85 add_option( 'starter_sites_do_activation_redirect', true );
86 add_option( 'starter_sites_activated', time() );
87 }
88
89 /**
90 * Runs on deactivation.
91 */
92 public function deactivation() {
93
94 }
95
96 /**
97 * Runs on uninstallation.
98 */
99 static function uninstall() {
100 delete_option( 'starter_sites_do_activation_redirect' );
101 delete_option( 'starter_sites_activated' );
102 }
103
104 public function is_minimal() {
105 $settings = get_option( 'starter_sites_settings' );
106 if ( isset($settings['is_minimal']) && 'yes' === $settings['is_minimal'] ) {
107 return true;
108 } else {
109 return false;
110 }
111 }
112
113 public function base_link() {
114 $settings = get_option( 'starter_sites_settings' );
115 $base_link = 'admin.php';
116 if ( isset($settings['is_minimal']) && 'yes' === $settings['is_minimal'] ) {
117 $base_link = 'options-general.php';
118 } elseif ( isset($settings['menu_location']) ) {
119 if ( 'appearance' === $settings['menu_location'] ) {
120 $base_link = 'themes.php';
121 } elseif ( 'tools' === $settings['menu_location'] ) {
122 $base_link = 'tools.php';
123 }
124 }
125 return $base_link;
126 }
127
128 /**
129 * Redirect on single instance of plugin activation.
130 * Filterable e.g. to prevent automatic redirection upon activation,
131 * add the following to your theme's functions.php file,
132 * or your plugin's main file (replace themeslug prefix with your theme or plugin prefix):
133 *
134 function themeslug_prevent_starter_sites_redirect() {
135 return true;
136 }
137 add_filter( 'starter_sites_prevent_redirect_on_activation', 'themeslug_prevent_starter_sites_redirect' );
138 *
139 */
140 public function redirect() {
141 if ( $this->is_minimal() ) {
142 return;
143 } else {
144 if ( get_option( 'starter_sites_do_activation_redirect', false ) ) {
145 delete_option( 'starter_sites_do_activation_redirect' );
146 if ( is_network_admin() || isset($_GET['activate-multi']) || apply_filters( 'starter_sites_prevent_redirect_on_activation', false ) ) {
147 return;
148 }
149 $admin_link = admin_url( $this->base_link() );
150 wp_safe_redirect( add_query_arg( [ 'page' => 'starter-sites' ], $admin_link ) );
151 exit;
152 }
153 }
154 }
155
156 /**
157 * Add a plugin action link.
158 */
159 public function action_links( $links ) {
160 if ( $this->is_minimal() ) {
161 $browse = '<a href="' . esc_url( add_query_arg( [ 'page' => 'starter-sites' ], admin_url( 'options-general.php' ) ) ) . '">' . esc_html__( 'Settings', 'starter-sites' ) . '</a>';
162 } else {
163 $admin_link = admin_url( $this->base_link() );
164 $browse = '<a href="' . esc_url( add_query_arg( [ 'page' => 'starter-sites' ], $admin_link ) ) . '">' . esc_html__( 'Browse Sites', 'starter-sites' ) . '</a>';
165 }
166 array_unshift( $links, $browse );
167
168 if ( !$this->is_pro_installed() ) {
169 $go_pro_link = '<a target="_blank" href="https://wpstartersites.com/pricing/" style="font-weight:700;color:#29b03d;display:inline-block;">' . __( 'Upgrade to Pro', 'starter-sites' ) . '</a>';
170 array_unshift( $links, $go_pro_link );
171 }
172
173 return $links;
174 }
175
176 /*
177 * Add additional information in plugins table.
178 */
179 public function plugin_table_meta( $plugin_meta, $plugin_file ) {
180 if ( STARTER_SITES_BASENAME === $plugin_file ) {
181 $plugin_meta['starter_sites_support'] = '<a target="_blank" href="https://wordpress.org/support/plugin/starter-sites/">' . __( 'Support', 'starter-sites' ) . '</a>';
182 $plugin_meta['starter_sites_review'] = '<a target="_blank" href="https://wordpress.org/support/plugin/starter-sites/reviews/#new-post">' . __( 'Rate or Review Starter Sites �
183
184
185
186
187 ', 'starter-sites' ) . '</a>';
188 if ( !$this->is_pro_installed() ) {
189 $plugin_meta['starter_sites_upgrade'] = '<a target="_blank" href="https://wpstartersites.com/pricing/">' . __( 'Upgrade to Pro', 'starter-sites' ) . '</a>';
190 }
191 }
192 return $plugin_meta;
193 }
194
195 /*
196 * Return a list of installed plugins.
197 */
198 public function plugins_list() {
199 $plugins = array();
200 $installed_plugins = get_plugins();
201 if ( is_array( $installed_plugins ) ) {
202 foreach ( $installed_plugins as $plugin_file => $plugin ) {
203 $plugins[] = $plugin_file;
204 }
205 }
206 return $plugins;
207 }
208
209 public function is_pro_installed() {
210 if ( in_array( 'starter-sites-pro/starter-sites-pro.php', $this->plugins_list() ) ) {
211 return true;
212 } else {
213 return false;
214 }
215 }
216
217 /**
218 * Load the plugin textdomain for translations.
219 */
220 public function textdomain() {
221 load_plugin_textdomain( 'starter-sites', false, dirname( STARTER_SITES_BASENAME ) . '/languages/' );
222 }
223
224 /**
225 * Include files.
226 */
227 public function includes() {
228 require_once STARTER_SITES_PATH . 'inc/main.php';
229 require STARTER_SITES_PATH . 'inc/patterns.php';
230 }
231
232 public function __construct() {
233 $this->define_constants();
234 $this->register_hooks();
235 $this->filters();
236 $this->actions();
237 $this->includes();
238 }
239
240 }
241
242 /**
243 * Starter_Sites Class will be instantiated with a function.
244 * @return Starter_Sites
245 */
246 function starter_sites() {
247 return Starter_Sites::get_instance();
248 }
249 starter_sites();
250
251 /*
252 * Register uninstall hook outside the plugin class.
253 */
254 register_uninstall_hook( __FILE__, [ 'Starter_Sites', 'uninstall' ] );
255