PluginProbe
Starter Sites / 2.4
Starter Sites v2.4
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 2.4, at starter-sites.php

245 lines 7.1 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 sites 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.4
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: 6.8
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.4';
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 ( !in_array( 'starter-sites-pro/starter-sites-pro.php', $this->plugins_list() ) ) {
169 $go_pro_link = '<a target="_blank" href="https://wpstartersites.com/pricing/" style="font-weight:700;color:#2d59f2;display:inline-block;">' . __( 'Go Pro', 'starter-sites' ) . '</a>';
170 array_push( $links, $go_pro_link );
171 }
172
173 return $links;
174 }
175
176 /*
177 * Return a list of installed plugins.
178 */
179 public function plugins_list() {
180 $plugins = array();
181 $installed_plugins = get_plugins();
182 if ( is_array( $installed_plugins ) ) {
183 foreach ( $installed_plugins as $plugin_file => $plugin ) {
184 $plugins[] = $plugin_file;
185 }
186 }
187 return $plugins;
188 }
189
190 /*
191 * Add additional information in plugins table.
192 */
193 public function plugin_table_meta( $plugin_meta, $plugin_file ) {
194 if ( STARTER_SITES_BASENAME === $plugin_file ) {
195 $plugin_meta['starter_sites_support'] = '<a target="_blank" href="https://wordpress.org/support/plugin/starter-sites/">' . __( 'Support', 'starter-sites' ) . '</a>';
196 $plugin_meta['starter_sites_review'] = '<a target="_blank" href="https://wordpress.org/support/plugin/starter-sites/reviews/#new-post">' . __( 'Rate or Review Starter Sites �
197
198
199
200
201 ', 'starter-sites' ) . '</a>';
202 $plugin_meta['starter_sites_upgrade'] = '<a target="_blank" href="https://wpstartersites.com/pricing/">' . __( 'Upgrade to Premium', 'starter-sites' ) . '</a>';
203 }
204 return $plugin_meta;
205 }
206
207 /**
208 * Load the plugin textdomain for translations.
209 */
210 public function textdomain() {
211 load_plugin_textdomain( 'starter-sites', false, dirname( STARTER_SITES_BASENAME ) . '/languages/' );
212 }
213
214 /**
215 * Include files.
216 */
217 public function includes() {
218 require_once STARTER_SITES_PATH . 'inc/main.php';
219 require STARTER_SITES_PATH . 'inc/patterns.php';
220 }
221
222 public function __construct() {
223 $this->define_constants();
224 $this->register_hooks();
225 $this->filters();
226 $this->actions();
227 $this->includes();
228 }
229
230 }
231
232 /**
233 * Starter_Sites Class will be instantiated with a function.
234 * @return Starter_Sites
235 */
236 function starter_sites() {
237 return Starter_Sites::get_instance();
238 }
239 starter_sites();
240
241 /*
242 * Register uninstall hook outside the plugin class.
243 */
244 register_uninstall_hook( __FILE__, [ 'Starter_Sites', 'uninstall' ] );
245