| 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 |
$product_pages = isset( $this->about_data['product_pages'] ) ? $this->about_data['product_pages'] : []; |
| 178 |
return [ |
| 179 |
'links' => $links, |
| 180 |
'logoUrl' => $this->about_data['logo'], |
| 181 |
'productPages' => $this->get_product_pages_data( $product_pages ), |
| 182 |
'products' => $this->get_other_products_data(), |
| 183 |
'homeUrl' => esc_url( home_url() ), |
| 184 |
'pageSlug' => $this->get_about_page_slug(), |
| 185 |
'currentProduct' => [ |
| 186 |
'slug' => $this->product->get_key(), |
| 187 |
'name' => $this->product->get_name(), |
| 188 |
], |
| 189 |
'teamImage' => $this->get_sdk_uri() . 'assets/images/team.jpg', |
| 190 |
'strings' => [ |
| 191 |
'aboutUs' => __( 'About us', 'textdomain' ), |
| 192 |
'heroHeader' => __( 'Our Story', 'textdomain' ), |
| 193 |
'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' ), |
| 194 |
'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' ), |
| 195 |
'teamImageCaption' => __( 'Our team in WCEU2022 in Portugal', 'textdomain' ), |
| 196 |
'newsHeading' => __( 'Stay connected for news & updates!', 'textdomain' ), |
| 197 |
'emailPlaceholder' => __( 'Your email address', 'textdomain' ), |
| 198 |
'signMeUp' => __( 'Sign me up', 'textdomain' ), |
| 199 |
'installNow' => __( 'Install Now', 'textdomain' ), |
| 200 |
'activate' => __( 'Activate', 'textdomain' ), |
| 201 |
'learnMore' => __( 'Learn More', 'textdomain' ), |
| 202 |
'installed' => __( 'Installed', 'textdomain' ), |
| 203 |
'notInstalled' => __( 'Not Installed', 'textdomain' ), |
| 204 |
'active' => __( 'Active', 'textdomain' ), |
| 205 |
], |
| 206 |
'canInstallPlugins' => current_user_can( 'install_plugins' ), |
| 207 |
'canActivatePlugins' => current_user_can( 'activate_plugins' ), |
| 208 |
]; |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* Get product pages data. |
| 213 |
* |
| 214 |
* @param array $product_pages Product pages. |
| 215 |
* |
| 216 |
* @return array |
| 217 |
*/ |
| 218 |
private function get_product_pages_data( $product_pages ) { |
| 219 |
|
| 220 |
$otter_slug = 'otter-blocks'; |
| 221 |
$otter_plugin = [ |
| 222 |
'status' => 'not-installed', |
| 223 |
]; |
| 224 |
$otter_plugin['status'] = $this->is_plugin_installed( $otter_slug ) ? 'installed' : 'not-installed'; |
| 225 |
$otter_plugin['status'] = $this->is_plugin_active( $otter_slug ) ? 'active' : $otter_plugin['status']; |
| 226 |
$otter_plugin['activationLink'] = $this->get_plugin_activation_link( $otter_slug ); |
| 227 |
|
| 228 |
$pages = [ |
| 229 |
'otter-page' => [ |
| 230 |
'name' => 'Otter Blocks', |
| 231 |
'hash' => '#otter-page', |
| 232 |
'product' => $otter_slug, |
| 233 |
'plugin' => $otter_plugin, |
| 234 |
'strings' => [ |
| 235 |
'heading' => __( 'Build innovative layouts with Otter Blocks and Gutenberg', 'textdomain' ), |
| 236 |
'text' => __( 'Otter is a lightweight, dynamic collection of page building blocks and templates for the WordPress block editor.', 'textdomain' ), |
| 237 |
'buttons' => [ |
| 238 |
'install_otter_free' => __( "Install Otter - It's free!", 'textdomain' ), |
| 239 |
'install_now' => __( 'Install Now', 'textdomain' ), |
| 240 |
'learn_more' => __( 'Learn More', 'textdomain' ), |
| 241 |
'learn_more_link' => tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/', 'otter-page', 'about-us' ), |
| 242 |
], |
| 243 |
'features' => [ |
| 244 |
'advancedTitle' => __( 'Advanced Features', 'textdomain' ), |
| 245 |
'advancedDesc' => __( 'Add features such as Custom CSS, Animations & Visibility Conditions to all blocks.', 'textdomain' ), |
| 246 |
'fastTitle' => __( 'Lightweight and Fast', 'textdomain' ), |
| 247 |
'fastDesc' => __( 'Otter enhances WordPress site building experience without impacting site speed.', 'textdomain' ), |
| 248 |
'mobileTitle' => __( 'Mobile-Friendly', 'textdomain' ), |
| 249 |
'mobileDesc' => __( 'Each block can be tweaked to provide a consistent experience across all devices.', 'textdomain' ), |
| 250 |
], |
| 251 |
'details' => [ |
| 252 |
's1Image' => $this->get_sdk_uri() . 'assets/images/otter/otter-builder.png', |
| 253 |
's1Title' => __( 'A Better Page Building Experience', 'textdomain' ), |
| 254 |
's1Text' => __( 'Otter can be used to build everything from a personal blog to an e-commerce site without losing the personal touch. Otter’s ease of use transforms basic blocks into expressive layouts in seconds.', 'textdomain' ), |
| 255 |
's2Image' => $this->get_sdk_uri() . 'assets/images/otter/otter-patterns.png', |
| 256 |
's2Title' => __( 'A New Collection of Patterns', 'textdomain' ), |
| 257 |
's2Text' => __( 'A New Patterns Library, containing a range of different elements in a variety of styles to help you build great pages. All of your website’s most important areas are covered: headers, testimonials, pricing tables, sections and more.', 'textdomain' ), |
| 258 |
's3Image' => $this->get_sdk_uri() . 'assets/images/otter/otter-library.png', |
| 259 |
's3Title' => __( 'Advanced Blocks', 'textdomain' ), |
| 260 |
's3Text' => __( 'Enhance your website’s design with powerful blocks, like the Add to Cart, Business Hours, Review Comparison, and dozens of WooCommerce blocks.', 'textdomain' ), |
| 261 |
], |
| 262 |
'testimonials' => [ |
| 263 |
'heading' => __( 'Trusted by more than 300K website owners', 'textdomain' ), |
| 264 |
'users' => [ |
| 265 |
[ |
| 266 |
'avatar' => 'https://mllj2j8xvfl0.i.optimole.com/cb:3970~373ad/w:80/h:80/q:mauto/https://themeisle.com/wp-content/uploads/2021/05/avatar-03.png', |
| 267 |
'name' => 'Michael Burry', |
| 268 |
'text' => 'Loved the collection of blocks. If you want to create nice Gutenberg Pages, this plugin will be very handy and useful.', |
| 269 |
], |
| 270 |
[ |
| 271 |
'avatar' => 'https://mllj2j8xvfl0.i.optimole.com/cb:3970~373ad/w:80/h:80/q:mauto/https://themeisle.com/wp-content/uploads/2022/04/avatar-04.png', |
| 272 |
'name' => 'Maria Gonzales', |
| 273 |
'text' => 'I am very satisfied with Otter – a fantastic collection of blocks. And the plugin is perfectly integrated with Gutenberg and complete enough for my needs. ', |
| 274 |
], |
| 275 |
[ |
| 276 |
'avatar' => 'https://mllj2j8xvfl0.i.optimole.com/cb:3970~373ad/w:80/h:80/q:mauto/https://themeisle.com/wp-content/uploads/2022/04/avatar-05.png', |
| 277 |
'name' => 'Florian Henckel', |
| 278 |
'text' => 'Otter Blocks work really well and I like the customization options. Easy to use and format to fit in with my site theme – and I’ve not encountered any compatibility or speed issues.', |
| 279 |
], |
| 280 |
], |
| 281 |
], |
| 282 |
], |
| 283 |
], |
| 284 |
]; |
| 285 |
|
| 286 |
return array_filter( |
| 287 |
$pages, |
| 288 |
function ( $page_data, $page_key ) use ( $product_pages ) { |
| 289 |
return in_array( $page_key, $product_pages, true ) && |
| 290 |
isset( $page_data['plugin']['status'] ) && |
| 291 |
$page_data['plugin']['status'] === 'not-installed'; |
| 292 |
}, |
| 293 |
ARRAY_FILTER_USE_BOTH |
| 294 |
); |
| 295 |
} |
| 296 |
|
| 297 |
/** |
| 298 |
* Get products data. |
| 299 |
* |
| 300 |
* @return array |
| 301 |
*/ |
| 302 |
private function get_other_products_data() { |
| 303 |
$products = [ |
| 304 |
'optimole-wp' => [ |
| 305 |
'name' => 'Optimole', |
| 306 |
'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.', |
| 307 |
], |
| 308 |
'neve' => [ |
| 309 |
'skip_api' => true, |
| 310 |
'name' => 'Neve', |
| 311 |
'description' => __( 'A fast, lightweight, customizable WordPress theme offering responsive design, speed, and flexibility for various website types.', 'textdomain' ), |
| 312 |
'icon' => $this->get_sdk_uri() . 'assets/images/neve.png', |
| 313 |
], |
| 314 |
'otter-blocks' => [ |
| 315 |
'name' => 'Otter', |
| 316 |
], |
| 317 |
'tweet-old-post' => [ |
| 318 |
'name' => 'Revive Old Post', |
| 319 |
], |
| 320 |
'feedzy-rss-feeds' => [ |
| 321 |
'name' => 'Feedzy', |
| 322 |
], |
| 323 |
'woocommerce-product-addon' => [ |
| 324 |
'name' => 'PPOM', |
| 325 |
'condition' => class_exists( 'WooCommerce', false ), |
| 326 |
], |
| 327 |
'visualizer' => [ |
| 328 |
'name' => 'Visualizer', |
| 329 |
], |
| 330 |
'wp-landing-kit' => [ |
| 331 |
'skip_api' => true, |
| 332 |
'premiumUrl' => tsdk_utmify( 'https://themeisle.com/plugins/wp-landing-kit', $this->get_about_page_slug() ), |
| 333 |
'name' => 'WP Landing Kit', |
| 334 |
'description' => __( 'Turn WordPress into a landing page powerhouse with Landing Kit, map domains to pages or any other published resource.', 'textdomain' ), |
| 335 |
'icon' => $this->get_sdk_uri() . 'assets/images/wplk.png', |
| 336 |
], |
| 337 |
'multiple-pages-generator-by-porthas' => [ |
| 338 |
'name' => 'MPG', |
| 339 |
], |
| 340 |
'sparks-for-woocommerce' => [ |
| 341 |
'skip_api' => true, |
| 342 |
'premiumUrl' => tsdk_utmify( 'https://themeisle.com/plugins/sparks-for-woocommerce', $this->get_about_page_slug() ), |
| 343 |
'name' => 'Sparks', |
| 344 |
'description' => __( 'Extend your store functionality with 8 ultra-performant features like product comparisons, variation swatches, wishlist, and more.', 'textdomain' ), |
| 345 |
'icon' => $this->get_sdk_uri() . 'assets/images/sparks.png', |
| 346 |
'condition' => class_exists( 'WooCommerce', false ), |
| 347 |
], |
| 348 |
'templates-patterns-collection' => [ |
| 349 |
'name' => 'Templates Cloud', |
| 350 |
'description' => __( 'Design, save, and revisit your templates anytime with your personal vault on Templates Cloud.', 'textdomain' ), |
| 351 |
], |
| 352 |
]; |
| 353 |
|
| 354 |
foreach ( $products as $slug => $product ) { |
| 355 |
if ( isset( $product['condition'] ) && ! $product['condition'] ) { |
| 356 |
unset( $products[ $slug ] ); |
| 357 |
continue; |
| 358 |
} |
| 359 |
|
| 360 |
if ( $slug === 'neve' ) { |
| 361 |
$theme = get_template(); |
| 362 |
$themes = wp_get_themes(); |
| 363 |
|
| 364 |
$products[ $slug ]['status'] = isset( $themes['neve'] ) ? 'installed' : 'not-installed'; |
| 365 |
$products[ $slug ]['status'] = $theme === 'neve' ? 'active' : $products[ $slug ]['status']; |
| 366 |
|
| 367 |
$products[ $slug ]['activationLink'] = add_query_arg( |
| 368 |
[ |
| 369 |
'stylesheet' => 'neve', |
| 370 |
'action' => 'activate', |
| 371 |
'_wpnonce' => wp_create_nonce( 'switch-theme_neve' ), |
| 372 |
], |
| 373 |
admin_url( 'themes.php' ) |
| 374 |
); |
| 375 |
|
| 376 |
continue; |
| 377 |
} |
| 378 |
|
| 379 |
$products[ $slug ]['status'] = $this->is_plugin_installed( $slug ) ? 'installed' : 'not-installed'; |
| 380 |
$products[ $slug ]['status'] = $this->is_plugin_active( $slug ) ? 'active' : $products[ $slug ]['status']; |
| 381 |
$products[ $slug ]['activationLink'] = $this->get_plugin_activation_link( $slug ); |
| 382 |
|
| 383 |
|
| 384 |
if ( isset( $product['skip_api'] ) ) { |
| 385 |
continue; |
| 386 |
} |
| 387 |
|
| 388 |
$api_data = $this->call_plugin_api( $slug ); |
| 389 |
|
| 390 |
if ( ! isset( $product['icon'] ) ) { |
| 391 |
$products[ $slug ]['icon'] = isset( $api_data->icons['2x'] ) ? $api_data->icons['2x'] : $api_data->icons['1x']; |
| 392 |
} |
| 393 |
if ( ! isset( $product['description'] ) ) { |
| 394 |
$products[ $slug ]['description'] = $api_data->short_description; |
| 395 |
} |
| 396 |
if ( ! isset( $product['name'] ) ) { |
| 397 |
$products[ $slug ]['name'] = $api_data->name; |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
return $products; |
| 402 |
} |
| 403 |
|
| 404 |
/** |
| 405 |
* Get the page slug. |
| 406 |
* |
| 407 |
* @return string |
| 408 |
*/ |
| 409 |
private function get_about_page_slug() { |
| 410 |
return 'ti-about-' . $this->product->get_key(); |
| 411 |
} |
| 412 |
} |
| 413 |
|