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

225 lines 6.5 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.3
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', 'eternal' );
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.3';
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 return $links;
168 }
169
170 /*
171 * Add additional information in plugins table.
172 */
173 public function plugin_table_meta( $plugin_meta, $plugin_file ) {
174 if ( STARTER_SITES_BASENAME === $plugin_file ) {
175 $plugin_meta['starter_sites_support'] = '<a target="_blank" href="https://wordpress.org/support/plugin/starter-sites/">' . __( 'Support', 'starter-sites' ) . '</a>';
176 $plugin_meta['starter_sites_review'] = '<a target="_blank" href="https://wordpress.org/support/plugin/starter-sites/reviews/#new-post">' . __( 'Rate or Review Starter Sites �
177
178
179
180
181 ', 'starter-sites' ) . '</a>';
182 $plugin_meta['starter_sites_upgrade'] = '<a target="_blank" href="https://wpstartersites.com/pricing/">' . __( 'Upgrade to Premium', 'starter-sites' ) . '</a>';
183 }
184 return $plugin_meta;
185 }
186
187 /**
188 * Load the plugin textdomain for translations.
189 */
190 public function textdomain() {
191 load_plugin_textdomain( 'starter-sites', false, dirname( STARTER_SITES_BASENAME ) . '/languages/' );
192 }
193
194 /**
195 * Include files.
196 */
197 public function includes() {
198 require_once STARTER_SITES_PATH . 'inc/main.php';
199 require STARTER_SITES_PATH . 'inc/patterns.php';
200 }
201
202 public function __construct() {
203 $this->define_constants();
204 $this->register_hooks();
205 $this->filters();
206 $this->actions();
207 $this->includes();
208 }
209
210 }
211
212 /**
213 * Starter_Sites Class will be instantiated with a function.
214 * @return Starter_Sites
215 */
216 function starter_sites() {
217 return Starter_Sites::get_instance();
218 }
219 starter_sites();
220
221 /*
222 * Register uninstall hook outside the plugin class.
223 */
224 register_uninstall_hook( __FILE__, [ 'Starter_Sites', 'uninstall' ] );
225