| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Starter Sites |
| 4 |
Plugin URI: https://wpstartersites.com/plugin/ |
| 5 |
Description: Ready to go WordPress full site editing starter sites and website demos, all with full pages of real content, and all created with the block editor. |
| 6 |
Version: 2.0 |
| 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.4 |
| 13 |
Tested up to: 6.6 |
| 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', '2.0' ); |
| 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_PREVIEW_URL', 'https://demo.wpstartersites.com/' ); |
| 46 |
} |
| 47 |
|
| 48 |
/* |
| 49 |
* Register hooks. |
| 50 |
*/ |
| 51 |
public function register_hooks() { |
| 52 |
register_activation_hook( __FILE__, [ $this, 'activation' ] ); |
| 53 |
register_deactivation_hook( __FILE__, [ $this, 'deactivation' ] ); |
| 54 |
} |
| 55 |
|
| 56 |
/* |
| 57 |
* Filters. |
| 58 |
*/ |
| 59 |
public function filters() { |
| 60 |
add_filter( 'plugin_action_links_' . STARTER_SITES_BASENAME, [ $this, 'action_links' ] ); |
| 61 |
add_filter( 'plugin_row_meta', [ $this, 'plugin_table_meta' ], 10, 2 ); |
| 62 |
} |
| 63 |
|
| 64 |
/* |
| 65 |
* Do required actions. |
| 66 |
*/ |
| 67 |
public function actions() { |
| 68 |
add_action( 'plugins_loaded', [ $this, 'textdomain' ] ); |
| 69 |
add_action( 'admin_init', [ $this, 'redirect' ] ); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Runs on activation. |
| 74 |
*/ |
| 75 |
public function activation() { |
| 76 |
add_option( 'starter_sites_do_activation_redirect', true ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Runs on deactivation. |
| 81 |
*/ |
| 82 |
public function deactivation() { |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Runs on uninstallation. |
| 88 |
*/ |
| 89 |
static function uninstall() { |
| 90 |
delete_option( 'starter_sites_do_activation_redirect' ); |
| 91 |
} |
| 92 |
|
| 93 |
public function is_minimal() { |
| 94 |
$settings = get_option( 'starter_sites_settings' ); |
| 95 |
if ( isset($settings['is_minimal']) && 'yes' === $settings['is_minimal'] ) { |
| 96 |
return true; |
| 97 |
} else { |
| 98 |
return false; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
public function base_link() { |
| 103 |
$settings = get_option( 'starter_sites_settings' ); |
| 104 |
$base_link = 'admin.php'; |
| 105 |
if ( isset($settings['is_minimal']) && 'yes' === $settings['is_minimal'] ) { |
| 106 |
$base_link = 'options-general.php'; |
| 107 |
} elseif ( isset($settings['menu_location']) ) { |
| 108 |
if ( 'appearance' === $settings['menu_location'] ) { |
| 109 |
$base_link = 'themes.php'; |
| 110 |
} elseif ( 'tools' === $settings['menu_location'] ) { |
| 111 |
$base_link = 'tools.php'; |
| 112 |
} |
| 113 |
} |
| 114 |
return $base_link; |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Redirect on single instance of plugin activation. |
| 119 |
*/ |
| 120 |
public function redirect() { |
| 121 |
if ( $this->is_minimal() ) { |
| 122 |
return; |
| 123 |
} else { |
| 124 |
if ( get_option( 'starter_sites_do_activation_redirect', false ) ) { |
| 125 |
delete_option( 'starter_sites_do_activation_redirect' ); |
| 126 |
if ( is_network_admin() || isset($_GET['activate-multi']) ) { |
| 127 |
return; |
| 128 |
} |
| 129 |
$admin_link = admin_url( $this->base_link() ); |
| 130 |
wp_safe_redirect( add_query_arg( [ 'page' => 'starter-sites' ], $admin_link ) ); |
| 131 |
exit; |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Add a plugin action link. |
| 138 |
*/ |
| 139 |
public function action_links( $links ) { |
| 140 |
if ( $this->is_minimal() ) { |
| 141 |
$browse = '<a href="' . esc_url( add_query_arg( [ 'page' => 'starter-sites' ], admin_url( 'options-general.php' ) ) ) . '">' . esc_html__( 'Settings', 'starter-sites' ) . '</a>'; |
| 142 |
} else { |
| 143 |
$admin_link = admin_url( $this->base_link() ); |
| 144 |
$browse = '<a href="' . esc_url( add_query_arg( [ 'page' => 'starter-sites' ], $admin_link ) ) . '">' . esc_html__( 'Browse Sites', 'starter-sites' ) . '</a>'; |
| 145 |
} |
| 146 |
array_unshift( $links, $browse ); |
| 147 |
return $links; |
| 148 |
} |
| 149 |
|
| 150 |
/* |
| 151 |
* Add additional information in plugins table. |
| 152 |
*/ |
| 153 |
public function plugin_table_meta( $plugin_meta, $plugin_file ) { |
| 154 |
if ( STARTER_SITES_BASENAME === $plugin_file ) { |
| 155 |
$plugin_meta['starter_sites_support'] = '<a target="_blank" href="https://wordpress.org/support/plugin/starter-sites/">' . __( 'Support', 'starter-sites' ) . '</a>'; |
| 156 |
$plugin_meta['starter_sites_review'] = '<a target="_blank" href="https://wordpress.org/support/plugin/starter-sites/reviews/#new-post">' . __( 'Rate or Review Starter Sites � |
| 157 |
� |
| 158 |
� |
| 159 |
� |
| 160 |
� |
| 161 |
', 'starter-sites' ) . '</a>'; |
| 162 |
$plugin_meta['starter_sites_upgrade'] = '<a target="_blank" href="https://wpstartersites.com/pricing/">' . __( 'Upgrade to Premium', 'starter-sites' ) . '</a>'; |
| 163 |
} |
| 164 |
return $plugin_meta; |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* Load the plugin textdomain for translations. |
| 169 |
*/ |
| 170 |
public function textdomain() { |
| 171 |
load_plugin_textdomain( 'starter-sites', false, dirname( STARTER_SITES_BASENAME ) . '/languages/' ); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Include files. |
| 176 |
*/ |
| 177 |
public function includes() { |
| 178 |
require_once STARTER_SITES_PATH . 'inc/main.php'; |
| 179 |
require STARTER_SITES_PATH . 'inc/patterns.php'; |
| 180 |
} |
| 181 |
|
| 182 |
public function __construct() { |
| 183 |
$this->define_constants(); |
| 184 |
$this->register_hooks(); |
| 185 |
$this->filters(); |
| 186 |
$this->actions(); |
| 187 |
$this->includes(); |
| 188 |
} |
| 189 |
|
| 190 |
} |
| 191 |
|
| 192 |
/** |
| 193 |
* Starter_Sites Class will be instantiated with a function. |
| 194 |
* @return Starter_Sites |
| 195 |
*/ |
| 196 |
function starter_sites() { |
| 197 |
return Starter_Sites::get_instance(); |
| 198 |
} |
| 199 |
starter_sites(); |
| 200 |
|
| 201 |
/* |
| 202 |
* Register uninstall hook outside the plugin class. |
| 203 |
*/ |
| 204 |
register_uninstall_hook( __FILE__, [ 'Starter_Sites', 'uninstall' ] ); |
| 205 |
|