| 1 |
<?php |
| 2 |
/** |
| 3 |
* The about page model class for ThemeIsle SDK |
| 4 |
* |
| 5 |
* Here's how to hook it in your plugin: |
| 6 |
* |
| 7 |
* add_filter( <product_slug>_about_us_metadata', 'add_about_meta' ); |
| 8 |
* |
| 9 |
* function add_about_meta($data) { |
| 10 |
* return [ |
| 11 |
* 'location' => <top level page - e.g. themes.php>, |
| 12 |
* 'logo' => <logo url>, |
| 13 |
* 'page_menu' => [['text' => '', 'url' => '']], // optional |
| 14 |
* 'has_upgrade_menu' => <condition>, |
| 15 |
* 'upgrade_link' => <url>, |
| 16 |
* 'upgrade_text' => 'Get Pro Version', |
| 17 |
* ] |
| 18 |
* } |
| 19 |
* |
| 20 |
* @package ThemeIsleSDK |
| 21 |
* @subpackage Modules |
| 22 |
* @copyright Copyright (c) 2023, Andrei Baicus |
| 23 |
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License |
| 24 |
* @since 3.2.42 |
| 25 |
*/ |
| 26 |
|
| 27 |
namespace ThemeisleSDK\Modules; |
| 28 |
|
| 29 |
use ThemeisleSDK\Common\Abstract_Module; |
| 30 |
use ThemeisleSDK\Product; |
| 31 |
|
| 32 |
// Exit if accessed directly. |
| 33 |
if ( ! defined( 'ABSPATH' ) ) { |
| 34 |
exit; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Promotions module for ThemeIsle SDK. |
| 39 |
*/ |
| 40 |
class About_Us extends Abstract_Module { |
| 41 |
/** |
| 42 |
* About data. |
| 43 |
* |
| 44 |
* @var array $about_data About page data, received from the filter. |
| 45 |
* |
| 46 |
* Shape of the $about_data property array: |
| 47 |
* [ |
| 48 |
* 'location' => 'top level page', |
| 49 |
* 'logo' => 'logo path', |
| 50 |
* 'page_menu' => [['text' => '', 'url' => '']], // Optional |
| 51 |
* 'has_upgrade_menu' => !defined('NEVE_PRO_VERSION'), |
| 52 |
* 'upgrade_link' => 'upgrade url', |
| 53 |
* 'upgrade_text' => 'Get Pro Version', |
| 54 |
* ] |
| 55 |
*/ |
| 56 |
private $about_data = array(); |
| 57 |
|
| 58 |
/** |
| 59 |
* Should we load this module. |
| 60 |
* |
| 61 |
* @param Product $product Product object. |
| 62 |
* |
| 63 |
* @return bool |
| 64 |
*/ |
| 65 |
public function can_load( $product ) { |
| 66 |
if ( $this->is_from_partner( $product ) ) { |
| 67 |
return false; |
| 68 |
} |
| 69 |
|
| 70 |
$this->about_data = apply_filters( $product->get_key() . '_about_us_metadata', array() ); |
| 71 |
|
| 72 |
return ! empty( $this->about_data ); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Registers the hooks. |
| 77 |
* |
| 78 |
* @param Product $product Product to load. |
| 79 |
*/ |
| 80 |
public function load( $product ) { |
| 81 |
$this->product = $product; |
| 82 |
|
| 83 |
add_action( 'admin_menu', [ $this, 'add_submenu_pages' ] ); |
| 84 |
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_about_page_script' ] ); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Adds submenu pages. |
| 89 |
* |
| 90 |
* @return void |
| 91 |
*/ |
| 92 |
public function add_submenu_pages() { |
| 93 |
if ( ! isset( $this->about_data['location'] ) ) { |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
add_submenu_page( |
| 98 |
$this->about_data['location'], |
| 99 |
__( 'About Us', 'textdomain' ), |
| 100 |
__( 'About Us', 'textdomain' ), |
| 101 |
'manage_options', |
| 102 |
$this->get_about_page_slug(), |
| 103 |
array( $this, 'render_about_us_page' ), |
| 104 |
100 |
| 105 |
); |
| 106 |
|
| 107 |
if ( ! isset( $this->about_data['has_upgrade_menu'] ) ) { |
| 108 |
return; |
| 109 |
} |
| 110 |
|
| 111 |
if ( $this->about_data['has_upgrade_menu'] !== true ) { |
| 112 |
return; |
| 113 |
} |
| 114 |
|
| 115 |
if ( ! isset( $this->about_data['upgrade_link'] ) ) { |
| 116 |
return; |
| 117 |
} |
| 118 |
|
| 119 |
if ( ! isset( $this->about_data['upgrade_text'] ) ) { |
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
add_submenu_page( |
| 124 |
$this->about_data['location'], |
| 125 |
$this->about_data['upgrade_text'], |
| 126 |
$this->about_data['upgrade_text'], |
| 127 |
'manage_options', |
| 128 |
$this->about_data['upgrade_link'], |
| 129 |
'', |
| 130 |
101 |
| 131 |
); |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Render page content. |
| 136 |
* |
| 137 |
* @return void |
| 138 |
*/ |
| 139 |
public function render_about_us_page() { |
| 140 |
echo '<div id="ti-sdk-about"></div>'; |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Enqueue scripts & styles. |
| 145 |
* |
| 146 |
* @return void |
| 147 |
*/ |
| 148 |
public function enqueue_about_page_script() { |
| 149 |
$current_screen = get_current_screen(); |
| 150 |
|
| 151 |
if ( ! isset( $current_screen->id ) ) { |
| 152 |
return; |
| 153 |
} |
| 154 |
|
| 155 |
if ( strpos( $current_screen->id, $this->get_about_page_slug() ) === false ) { |
| 156 |
return; |
| 157 |
} |
| 158 |
global $themeisle_sdk_max_path; |
| 159 |
$handle = 'ti-sdk-about-' . $this->product->get_key(); |
| 160 |
$asset_file = require $themeisle_sdk_max_path . '/assets/js/build/about/about.asset.php'; |
| 161 |
$deps = array_merge( $asset_file['dependencies'], [ 'updates' ] ); |
| 162 |
|
| 163 |
wp_register_script( $handle, $this->get_sdk_uri() . 'assets/js/build/about/about.js', $deps, $asset_file['version'], true ); |
| 164 |
wp_localize_script( $handle, 'tiSDKAboutData', $this->get_about_localization_data() ); |
| 165 |
|
| 166 |
wp_enqueue_script( $handle ); |
| 167 |
wp_enqueue_style( $handle, $this->get_sdk_uri() . 'assets/js/build/about/about.css', [ 'wp-components' ], $asset_file['version'] ); |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Get localized data. |
| 172 |
* |
| 173 |
* @return array |
| 174 |
*/ |
| 175 |
private function get_about_localization_data() { |
| 176 |
$links = isset( $this->about_data['page_menu'] ) ? $this->about_data['page_menu'] : []; |
| 177 |
|
| 178 |
return [ |
| 179 |
'links' => $links, |
| 180 |
'logoUrl' => $this->about_data['logo'], |
| 181 |
'products' => $this->get_other_products_data(), |
| 182 |
'homeUrl' => esc_url( home_url() ), |
| 183 |
'pageSlug' => $this->get_about_page_slug(), |
| 184 |
'currentProduct' => [ |
| 185 |
'slug' => $this->product->get_key(), |
| 186 |
'name' => $this->product->get_name(), |
| 187 |
], |
| 188 |
'teamImage' => $this->get_sdk_uri() . 'assets/images/team.jpg', |
| 189 |
'strings' => [ |
| 190 |
'aboutUs' => __( 'About us', 'textdomain' ), |
| 191 |
'heroHeader' => __( 'Our Story', 'textdomain' ), |
| 192 |
'heroTextFirst' => __( 'Themeisle was founded in 2012 by a group of passionate developers who wanted to create beautiful and functional WordPress themes and plugins. Since then, we have grown into a team of over 20 dedicated professionals who are committed to delivering the best possible products to our customers.', 'textdomain' ), |
| 193 |
'heroTextSecond' => __( 'At Themeisle, we offer a wide range of WordPress themes and plugins that are designed to meet the needs of both beginners and advanced users. Our products are feature-rich, easy to use, and are designed to help you create beautiful and functional websites.', 'textdomain' ), |
| 194 |
'teamImageCaption' => __( 'Our team in WCEU2022 in Portugal', 'textdomain' ), |
| 195 |
'newsHeading' => __( 'Stay connected for news & updates!', 'textdomain' ), |
| 196 |
'emailPlaceholder' => __( 'Your email address', 'textdomain' ), |
| 197 |
'signMeUp' => __( 'Sign me up', 'textdomain' ), |
| 198 |
'installNow' => __( 'Install Now', 'textdomain' ), |
| 199 |
'activate' => __( 'Activate', 'textdomain' ), |
| 200 |
'learnMore' => __( 'Learn More', 'textdomain' ), |
| 201 |
'installed' => __( 'Installed', 'textdomain' ), |
| 202 |
'notInstalled' => __( 'Not Installed', 'textdomain' ), |
| 203 |
'active' => __( 'Active', 'textdomain' ), |
| 204 |
], |
| 205 |
]; |
| 206 |
} |
| 207 |
|
| 208 |
/** |
| 209 |
* Get products data. |
| 210 |
* |
| 211 |
* @return array |
| 212 |
*/ |
| 213 |
private function get_other_products_data() { |
| 214 |
$products = [ |
| 215 |
'optimole-wp' => [ |
| 216 |
'name' => 'Optimole', |
| 217 |
'description' => 'Optimole is an image optimization service that automatically optimizes your images and serves them to your visitors via a global CDN, making your website lighter, faster and helping you reduce your bandwidth usage.', |
| 218 |
], |
| 219 |
'neve' => [ |
| 220 |
'skip_api' => true, |
| 221 |
'name' => 'Neve', |
| 222 |
'description' => __( 'A fast, lightweight, customizable WordPress theme offering responsive design, speed, and flexibility for various website types.', 'textdomain' ), |
| 223 |
'icon' => $this->get_sdk_uri() . 'assets/images/neve.png', |
| 224 |
], |
| 225 |
'otter-blocks' => [ |
| 226 |
'name' => 'Otter', |
| 227 |
], |
| 228 |
'tweet-old-post' => [ |
| 229 |
'name' => 'Revive Old Post', |
| 230 |
], |
| 231 |
'feedzy-rss-feeds' => [ |
| 232 |
'name' => 'Feedzy', |
| 233 |
], |
| 234 |
'woocommerce-product-addon' => [ |
| 235 |
'name' => 'PPOM', |
| 236 |
'condition' => class_exists( 'WooCommerce', false ), |
| 237 |
], |
| 238 |
'visualizer' => [ |
| 239 |
'name' => 'Visualizer', |
| 240 |
], |
| 241 |
'wp-landing-kit' => [ |
| 242 |
'skip_api' => true, |
| 243 |
'premiumUrl' => tsdk_utmify( 'https://themeisle.com/plugins/wp-landing-kit', $this->get_about_page_slug() ), |
| 244 |
'name' => 'WP Landing Kit', |
| 245 |
'description' => __( 'Turn WordPress into a landing page powerhouse with Landing Kit, map domains to pages or any other published resource.', 'textdomain' ), |
| 246 |
'icon' => $this->get_sdk_uri() . 'assets/images/wplk.png', |
| 247 |
], |
| 248 |
'multiple-pages-generator-by-porthas' => [ |
| 249 |
'name' => 'MPG', |
| 250 |
], |
| 251 |
'sparks-for-woocommerce' => [ |
| 252 |
'skip_api' => true, |
| 253 |
'premiumUrl' => tsdk_utmify( 'https://themeisle.com/plugins/sparks-for-woocommerce', $this->get_about_page_slug() ), |
| 254 |
'name' => 'Sparks', |
| 255 |
'description' => __( 'Extend your store functionality with 8 ultra-performant features like product comparisons, variation swatches, wishlist, and more.', 'textdomain' ), |
| 256 |
'icon' => $this->get_sdk_uri() . 'assets/images/sparks.png', |
| 257 |
'condition' => class_exists( 'WooCommerce', false ), |
| 258 |
], |
| 259 |
'templates-patterns-collection' => [ |
| 260 |
'name' => 'Template Cloud', |
| 261 |
'description' => __( 'Ultimate Free Templates Cloud for WordPress, for blocks, patters of full pages.', 'textdomain' ), |
| 262 |
], |
| 263 |
]; |
| 264 |
|
| 265 |
foreach ( $products as $slug => $product ) { |
| 266 |
if ( isset( $product['condition'] ) && ! $product['condition'] ) { |
| 267 |
unset( $products[ $slug ] ); |
| 268 |
continue; |
| 269 |
} |
| 270 |
|
| 271 |
if ( $slug === 'neve' ) { |
| 272 |
$theme = get_template(); |
| 273 |
$themes = wp_get_themes(); |
| 274 |
|
| 275 |
$products[ $slug ]['status'] = isset( $themes['neve'] ) ? 'installed' : 'not-installed'; |
| 276 |
$products[ $slug ]['status'] = $theme === 'neve' ? 'active' : $products[ $slug ]['status']; |
| 277 |
|
| 278 |
$products[ $slug ]['activationLink'] = add_query_arg( |
| 279 |
[ |
| 280 |
'stylesheet' => 'neve', |
| 281 |
'action' => 'activate', |
| 282 |
'_wpnonce' => wp_create_nonce( 'switch-theme_neve' ), |
| 283 |
], |
| 284 |
admin_url( 'themes.php' ) |
| 285 |
); |
| 286 |
|
| 287 |
continue; |
| 288 |
} |
| 289 |
|
| 290 |
$products[ $slug ]['status'] = $this->is_plugin_installed( $slug ) ? 'installed' : 'not-installed'; |
| 291 |
$products[ $slug ]['status'] = $this->is_plugin_active( $slug ) ? 'active' : $products[ $slug ]['status']; |
| 292 |
$products[ $slug ]['activationLink'] = $this->get_plugin_activation_link( $slug ); |
| 293 |
|
| 294 |
|
| 295 |
if ( isset( $product['skip_api'] ) ) { |
| 296 |
continue; |
| 297 |
} |
| 298 |
|
| 299 |
$api_data = $this->call_plugin_api( $slug ); |
| 300 |
|
| 301 |
if ( ! isset( $product['icon'] ) ) { |
| 302 |
$products[ $slug ]['icon'] = isset( $api_data->icons['2x'] ) ? $api_data->icons['2x'] : $api_data->icons['1x']; |
| 303 |
} |
| 304 |
if ( ! isset( $product['description'] ) ) { |
| 305 |
$products[ $slug ]['description'] = $api_data->short_description; |
| 306 |
} |
| 307 |
if ( ! isset( $product['name'] ) ) { |
| 308 |
$products[ $slug ]['name'] = $api_data->name; |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
return $products; |
| 313 |
} |
| 314 |
|
| 315 |
/** |
| 316 |
* Get the page slug. |
| 317 |
* |
| 318 |
* @return string |
| 319 |
*/ |
| 320 |
private function get_about_page_slug() { |
| 321 |
return 'ti-about-' . $this->product->get_key(); |
| 322 |
} |
| 323 |
} |
| 324 |
|