| 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, patterns, fonts and full website demo content including pages, posts, products and images. |
| 6 |
Version: 2.1 |
| 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.7 |
| 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.1'; |
| 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 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Runs on deactivation. |
| 90 |
*/ |
| 91 |
public function deactivation() { |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Runs on uninstallation. |
| 97 |
*/ |
| 98 |
static function uninstall() { |
| 99 |
delete_option( 'starter_sites_do_activation_redirect' ); |
| 100 |
} |
| 101 |
|
| 102 |
public function is_minimal() { |
| 103 |
$settings = get_option( 'starter_sites_settings' ); |
| 104 |
if ( isset($settings['is_minimal']) && 'yes' === $settings['is_minimal'] ) { |
| 105 |
return true; |
| 106 |
} else { |
| 107 |
return false; |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
public function base_link() { |
| 112 |
$settings = get_option( 'starter_sites_settings' ); |
| 113 |
$base_link = 'admin.php'; |
| 114 |
if ( isset($settings['is_minimal']) && 'yes' === $settings['is_minimal'] ) { |
| 115 |
$base_link = 'options-general.php'; |
| 116 |
} elseif ( isset($settings['menu_location']) ) { |
| 117 |
if ( 'appearance' === $settings['menu_location'] ) { |
| 118 |
$base_link = 'themes.php'; |
| 119 |
} elseif ( 'tools' === $settings['menu_location'] ) { |
| 120 |
$base_link = 'tools.php'; |
| 121 |
} |
| 122 |
} |
| 123 |
return $base_link; |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Redirect on single instance of plugin activation. |
| 128 |
* Filterable e.g. to prevent automatic redirection upon activation, |
| 129 |
* add the following to your theme's functions.php file, |
| 130 |
* or your plugin's main file (replace themeslug prefix with your theme or plugin prefix): |
| 131 |
* |
| 132 |
function themeslug_prevent_starter_sites_redirect() { |
| 133 |
return true; |
| 134 |
} |
| 135 |
add_filter( 'starter_sites_prevent_redirect_on_activation', 'themeslug_prevent_starter_sites_redirect' ); |
| 136 |
* |
| 137 |
*/ |
| 138 |
public function redirect() { |
| 139 |
if ( $this->is_minimal() ) { |
| 140 |
return; |
| 141 |
} else { |
| 142 |
if ( get_option( 'starter_sites_do_activation_redirect', false ) ) { |
| 143 |
delete_option( 'starter_sites_do_activation_redirect' ); |
| 144 |
if ( is_network_admin() || isset($_GET['activate-multi']) || apply_filters( 'starter_sites_prevent_redirect_on_activation', false ) ) { |
| 145 |
return; |
| 146 |
} |
| 147 |
$admin_link = admin_url( $this->base_link() ); |
| 148 |
wp_safe_redirect( add_query_arg( [ 'page' => 'starter-sites' ], $admin_link ) ); |
| 149 |
exit; |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Add a plugin action link. |
| 156 |
*/ |
| 157 |
public function action_links( $links ) { |
| 158 |
if ( $this->is_minimal() ) { |
| 159 |
$browse = '<a href="' . esc_url( add_query_arg( [ 'page' => 'starter-sites' ], admin_url( 'options-general.php' ) ) ) . '">' . esc_html__( 'Settings', 'starter-sites' ) . '</a>'; |
| 160 |
} else { |
| 161 |
$admin_link = admin_url( $this->base_link() ); |
| 162 |
$browse = '<a href="' . esc_url( add_query_arg( [ 'page' => 'starter-sites' ], $admin_link ) ) . '">' . esc_html__( 'Browse Sites', 'starter-sites' ) . '</a>'; |
| 163 |
} |
| 164 |
array_unshift( $links, $browse ); |
| 165 |
return $links; |
| 166 |
} |
| 167 |
|
| 168 |
/* |
| 169 |
* Add additional information in plugins table. |
| 170 |
*/ |
| 171 |
public function plugin_table_meta( $plugin_meta, $plugin_file ) { |
| 172 |
if ( STARTER_SITES_BASENAME === $plugin_file ) { |
| 173 |
$plugin_meta['starter_sites_support'] = '<a target="_blank" href="https://wordpress.org/support/plugin/starter-sites/">' . __( 'Support', 'starter-sites' ) . '</a>'; |
| 174 |
$plugin_meta['starter_sites_review'] = '<a target="_blank" href="https://wordpress.org/support/plugin/starter-sites/reviews/#new-post">' . __( 'Rate or Review Starter Sites � |
| 175 |
� |
| 176 |
� |
| 177 |
� |
| 178 |
� |
| 179 |
', 'starter-sites' ) . '</a>'; |
| 180 |
$plugin_meta['starter_sites_upgrade'] = '<a target="_blank" href="https://wpstartersites.com/pricing/">' . __( 'Upgrade to Premium', 'starter-sites' ) . '</a>'; |
| 181 |
} |
| 182 |
return $plugin_meta; |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* Load the plugin textdomain for translations. |
| 187 |
*/ |
| 188 |
public function textdomain() { |
| 189 |
load_plugin_textdomain( 'starter-sites', false, dirname( STARTER_SITES_BASENAME ) . '/languages/' ); |
| 190 |
} |
| 191 |
|
| 192 |
/** |
| 193 |
* Include files. |
| 194 |
*/ |
| 195 |
public function includes() { |
| 196 |
require_once STARTER_SITES_PATH . 'inc/main.php'; |
| 197 |
require STARTER_SITES_PATH . 'inc/patterns.php'; |
| 198 |
} |
| 199 |
|
| 200 |
public function __construct() { |
| 201 |
$this->define_constants(); |
| 202 |
$this->register_hooks(); |
| 203 |
$this->filters(); |
| 204 |
$this->actions(); |
| 205 |
$this->includes(); |
| 206 |
} |
| 207 |
|
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* Starter_Sites Class will be instantiated with a function. |
| 212 |
* @return Starter_Sites |
| 213 |
*/ |
| 214 |
function starter_sites() { |
| 215 |
return Starter_Sites::get_instance(); |
| 216 |
} |
| 217 |
starter_sites(); |
| 218 |
|
| 219 |
/* |
| 220 |
* Register uninstall hook outside the plugin class. |
| 221 |
*/ |
| 222 |
register_uninstall_hook( __FILE__, [ 'Starter_Sites', 'uninstall' ] ); |
| 223 |
|