| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Extendify WordPress Onboarding and AI Assistant |
| 4 |
* Description: AI-powered WordPress assistant for onboarding and ongoing editing offered exclusively through select WordPress hosting providers. |
| 5 |
* Plugin URI: https://extendify.com/?utm_source=wp-plugins&utm_campaign=plugin-uri&utm_medium=wp-dash |
| 6 |
* Author: Extendify |
| 7 |
* Author URI: https://extendify.com/?utm_source=wp-plugins&utm_campaign=author-uri&utm_medium=wp-dash |
| 8 |
* Version: 1.16.1 |
| 9 |
* License: GPL-2.0-or-later |
| 10 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 11 |
* Text Domain: extendify-local |
| 12 |
* Domain Path: /languages |
| 13 |
* |
| 14 |
* Extendify is free software: you can redistribute it and/or modify |
| 15 |
* it under the terms of the GNU General Public License as published by |
| 16 |
* the Free Software Foundation, either version 2 of the License, or |
| 17 |
* any later version. |
| 18 |
* |
| 19 |
* Extendify is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
*/ |
| 24 |
|
| 25 |
defined('ABSPATH') || exit; |
| 26 |
|
| 27 |
/** ExtendifySdk is the previous class name used */ |
| 28 |
if (!class_exists('ExtendifySdk') && !class_exists('Extendify')) : |
| 29 |
|
| 30 |
/** |
| 31 |
* The Extendify Library |
| 32 |
*/ |
| 33 |
// phpcs:ignore Squiz.Classes.ClassFileName.NoMatch,Squiz.Commenting.ClassComment.Missing,PEAR.Commenting.ClassComment.Missing |
| 34 |
final class Extendify |
| 35 |
{ |
| 36 |
/** |
| 37 |
* Var to make sure we only load once |
| 38 |
* |
| 39 |
* @var boolean $loaded |
| 40 |
*/ |
| 41 |
public static $loaded = false; |
| 42 |
|
| 43 |
/** |
| 44 |
* Set up the Library |
| 45 |
* |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
public function __invoke() |
| 49 |
{ |
| 50 |
// Allow users to disable the libary. The latter is left in for historical reasons. |
| 51 |
if (!apply_filters('extendify_load_library', true) || !apply_filters('extendifysdk_load_library', true)) { |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
if (version_compare(PHP_VERSION, '7.0', '<') || version_compare($GLOBALS['wp_version'], '6.0', '<')) { |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
if (!self::$loaded) { |
| 60 |
self::$loaded = true; |
| 61 |
require dirname(__FILE__) . '/bootstrap.php'; |
| 62 |
if (!defined('EXTENDIFY_BASE_URL')) { |
| 63 |
define('EXTENDIFY_BASE_URL', plugin_dir_url(__FILE__)); |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
// phpcs:ignore Squiz.Classes.ClassDeclaration.SpaceBeforeCloseBrace |
| 68 |
} |
| 69 |
|
| 70 |
add_action('plugins_loaded', function () { |
| 71 |
$extendify = new Extendify(); |
| 72 |
$extendify(); |
| 73 |
}); |
| 74 |
|
| 75 |
add_action('update_option', function ($option) { |
| 76 |
if (in_array($option, ['WPLANG', 'blogname'], true)) { |
| 77 |
\delete_transient('extendify_recommendations'); |
| 78 |
\delete_transient('extendify_domains'); |
| 79 |
\delete_transient('extendify_supportArticles'); |
| 80 |
} |
| 81 |
}); |
| 82 |
|
| 83 |
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed |
| 84 |
add_action('upgrader_process_complete', function ($upgrader, $options) { |
| 85 |
$updatedExtendify = isset($options['plugins']) && array_filter($options['plugins'], function ($plugin) { |
| 86 |
return strpos($plugin, 'extendify') !== false; |
| 87 |
}); |
| 88 |
|
| 89 |
if (!$updatedExtendify) { |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
\delete_transient('extendify_recommendations'); |
| 94 |
\delete_transient('extendify_domains'); |
| 95 |
\delete_transient('extendify_supportArticles'); |
| 96 |
}, 10, 2); |
| 97 |
|
| 98 |
// Redirect logins to the Extendify Assist dashboard if they are an admin. |
| 99 |
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed |
| 100 |
\add_filter('login_redirect', function ($redirectTo, $requestedRedirectTo, $user) { |
| 101 |
if (!$user || !is_a($user, 'WP_User')) { |
| 102 |
return $redirectTo; |
| 103 |
} |
| 104 |
|
| 105 |
$partnerData = get_option('extendify_partner_data_v2', []); |
| 106 |
if (!$user->has_cap('manage_options') || empty($partnerData)) { |
| 107 |
return $redirectTo; |
| 108 |
} |
| 109 |
|
| 110 |
return \admin_url() . 'admin.php?page=extendify-assist'; |
| 111 |
}, 10, 3); |
| 112 |
|
| 113 |
// ALlow Extendify requests to have a longer timeout. |
| 114 |
add_filter('http_request_args', function ($args, $url) { |
| 115 |
if (strpos($url, 'extendify') !== false) { |
| 116 |
$args['timeout'] = 45; |
| 117 |
} |
| 118 |
|
| 119 |
return $args; |
| 120 |
}, 100, 2); |
| 121 |
endif; |
| 122 |
|