assets
1 year ago
dist
1 year ago
includes
1 year ago
languages
1 year ago
lib
4 years ago
templates
1 year ago
init.php
1 year ago
license.txt
2 years ago
phpcs.xml
3 years ago
yit-deactive-plugin.php
3 years ago
yit-functions.php
1 year ago
yit-plugin-registration-hook.php
5 years ago
yit-plugin.php
1 year ago
yit-woocommerce-compatibility.php
2 years ago
yit-plugin.php
304 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Define constants and include Plugin Framework files. |
| 4 | * |
| 5 | * @author YITH <plugins@yithemes.com> |
| 6 | * @package YITH\PluginFramework |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
| 10 | |
| 11 | |
| 12 | ! defined( 'YIT_CORE_PLUGIN' ) && define( 'YIT_CORE_PLUGIN', true ); |
| 13 | ! defined( 'YIT_CORE_PLUGIN_PATH' ) && define( 'YIT_CORE_PLUGIN_PATH', dirname( __FILE__ ) ); |
| 14 | ! defined( 'YIT_CORE_PLUGIN_URL' ) && define( 'YIT_CORE_PLUGIN_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) ); |
| 15 | ! defined( 'YIT_CORE_PLUGIN_TEMPLATE_PATH' ) && define( 'YIT_CORE_PLUGIN_TEMPLATE_PATH', YIT_CORE_PLUGIN_PATH . '/templates' ); |
| 16 | |
| 17 | require_once 'yit-functions.php'; |
| 18 | require_once 'yit-woocommerce-compatibility.php'; |
| 19 | require_once 'yit-plugin-registration-hook.php'; |
| 20 | require_once 'includes/class-yit-metabox.php'; |
| 21 | require_once 'includes/class-yit-plugin-panel.php'; |
| 22 | require_once 'includes/class-yit-plugin-panel-woocommerce.php'; |
| 23 | require_once 'includes/class-yit-ajax.php'; |
| 24 | require_once 'includes/class-yit-plugin-subpanel.php'; |
| 25 | require_once 'includes/class-yit-plugin-common.php'; |
| 26 | require_once 'includes/class-yit-gradients.php'; |
| 27 | require_once 'includes/class-yit-plugin-licence.php'; |
| 28 | require_once 'includes/class-yit-theme-licence.php'; |
| 29 | require_once 'includes/class-yit-help-desk.php'; |
| 30 | require_once 'includes/class-yit-video.php'; |
| 31 | require_once 'includes/class-yit-upgrade.php'; |
| 32 | require_once 'includes/class-yit-pointers.php'; |
| 33 | require_once 'includes/class-yit-icons.php'; |
| 34 | require_once 'includes/class-yit-assets.php'; |
| 35 | require_once 'includes/class-yith-debug.php'; |
| 36 | require_once 'includes/class-yith-dashboard.php'; |
| 37 | require_once 'includes/privacy/class-yith-privacy.php'; |
| 38 | require_once 'includes/privacy/class-yith-privacy-plugin-abstract.php'; |
| 39 | require_once 'includes/class-yith-system-status.php'; |
| 40 | require_once 'includes/class-yith-post-type-admin.php'; |
| 41 | require_once 'includes/class-yith-bh-onboarding.php'; |
| 42 | require_once 'includes/class-yith-external-services.php'; |
| 43 | |
| 44 | // Gutenberg Support. |
| 45 | if ( class_exists( 'WP_Block_Type_Registry' ) ) { |
| 46 | require_once 'includes/builders/gutenberg/class-yith-gutenberg.php'; |
| 47 | } |
| 48 | |
| 49 | require_once 'includes/builders/elementor/class-yith-elementor.php'; |
| 50 | |
| 51 | // load from theme folder... |
| 52 | load_textdomain( 'yith-plugin-fw', get_template_directory() . '/core/plugin-fw/yith-plugin-fw-' . apply_filters( 'plugin_locale', determine_locale(), 'yith-plugin-fw' ) . '.mo' ) || |
| 53 | // ...or from plugin folder. |
| 54 | load_textdomain( 'yith-plugin-fw', dirname( __FILE__ ) . '/languages/yith-plugin-fw-' . apply_filters( 'plugin_locale', determine_locale(), 'yith-plugin-fw' ) . '.mo' ); |
| 55 | |
| 56 | add_filter( 'plugin_row_meta', 'yit_plugin_fw_row_meta', 20, 4 ); |
| 57 | |
| 58 | if ( ! function_exists( 'yit_plugin_fw_row_meta' ) ) { |
| 59 | /** |
| 60 | * Show the plugin row meta. |
| 61 | * |
| 62 | * @param string[] $plugin_meta An array of the plugin's metadata, including the version, author, author URI, and plugin URI. |
| 63 | * @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 64 | * @param array $plugin_data An array of plugin data. |
| 65 | * @param string $status Status filter currently applied to the plugin list. |
| 66 | * |
| 67 | * @return string[] array of the plugin's metadata. |
| 68 | * @since 3.0.17 |
| 69 | */ |
| 70 | function yit_plugin_fw_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) { |
| 71 | if ( false === strstr( $plugin_file, 'yith' ) ) { |
| 72 | // Not an YITH plugin. |
| 73 | return $plugin_meta; |
| 74 | } |
| 75 | |
| 76 | $base_uri = array( |
| 77 | 'live_demo' => 'https://plugins.yithemes.com/', |
| 78 | 'documentation' => 'https://docs.yithemes.com/', |
| 79 | 'premium_support' => 'https://yithemes.com/my-account/support/dashboard/', |
| 80 | 'free_support' => 'https://wordpress.org/support/plugin/', |
| 81 | 'premium_version' => 'https://yithemes.com/themes/plugins/', |
| 82 | ); |
| 83 | |
| 84 | $default = array( |
| 85 | 'live_demo' => array( |
| 86 | 'label' => _x( 'Live Demo', 'Plugin Row Meta', 'yith-plugin-fw' ), |
| 87 | 'icon' => 'dashicons dashicons-laptop', |
| 88 | ), |
| 89 | 'documentation' => array( |
| 90 | 'label' => _x( 'Documentation', 'Plugin Row Meta', 'yith-plugin-fw' ), |
| 91 | 'icon' => 'dashicons dashicons-search', |
| 92 | ), |
| 93 | 'support' => array( |
| 94 | 'label' => _x( 'Support', 'Plugin Row Meta', 'yith-plugin-fw' ), |
| 95 | 'icon' => 'dashicons dashicons-admin-users', |
| 96 | ), |
| 97 | 'premium_version' => array( |
| 98 | 'label' => _x( 'Premium version', 'Plugin Row Meta', 'yith-plugin-fw' ), |
| 99 | 'icon' => 'dashicons dashicons-cart', |
| 100 | ), |
| 101 | ); |
| 102 | |
| 103 | $to_show = array( 'live_demo', 'documentation', 'support', 'premium_version' ); |
| 104 | $new_row_meta_args = apply_filters( |
| 105 | 'yith_show_plugin_row_meta', |
| 106 | array( |
| 107 | 'to_show' => $to_show, |
| 108 | 'slug' => '', |
| 109 | ), |
| 110 | $plugin_meta, |
| 111 | $plugin_file, |
| 112 | $plugin_data, |
| 113 | $status |
| 114 | ); |
| 115 | $fields = $new_row_meta_args['to_show'] ?? array(); |
| 116 | $slug = $new_row_meta_args['slug'] ?? ''; |
| 117 | $is_extended = $new_row_meta_args['is_extended'] ?? ( false !== strpos( $plugin_file, '-extended' ) ); |
| 118 | $is_premium = $new_row_meta_args['is_premium'] ?? ( false !== strpos( $plugin_file, '-premium' ) ); |
| 119 | $utm_campaign = 'plugin-row-meta'; |
| 120 | |
| 121 | if ( $is_premium ) { |
| 122 | $plugin_version = 'premium'; |
| 123 | $to_remove = array( 'premium_version' ); |
| 124 | } elseif ( $is_extended ) { |
| 125 | $plugin_version = 'extended'; |
| 126 | $to_remove = array( 'live_demo' ); |
| 127 | |
| 128 | // set custom base uri. |
| 129 | $base_uri['documentation'] = 'https://docs.yithemes.com/'; |
| 130 | $base_uri['free_support'] = 'https://docs.yithemes.com/'; |
| 131 | } else { |
| 132 | $plugin_version = 'free'; |
| 133 | } |
| 134 | |
| 135 | // remove meta not required for current plugin. |
| 136 | if ( ! empty( $to_remove ) ) { |
| 137 | foreach ( $to_remove as $item_to_remove ) { |
| 138 | $item_to_remove_pos = array_search( $item_to_remove, $fields, true ); |
| 139 | |
| 140 | if ( false === $item_to_remove_pos ) { |
| 141 | continue; |
| 142 | } |
| 143 | |
| 144 | unset( $fields[ $item_to_remove_pos ] ); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | foreach ( $fields as $field ) { |
| 149 | $row_meta = isset( $new_row_meta_args[ $field ] ) ? wp_parse_args( $new_row_meta_args[ $field ], $default[ $field ] ) : $default[ $field ]; |
| 150 | $url = ''; |
| 151 | $icon = ''; |
| 152 | $label = ''; |
| 153 | |
| 154 | // Check for Label. |
| 155 | if ( isset( $row_meta['label'] ) ) { |
| 156 | $label = $row_meta['label']; |
| 157 | } |
| 158 | |
| 159 | // Check for Icon. |
| 160 | if ( isset( $row_meta['icon'] ) ) { |
| 161 | $icon = $row_meta['icon']; |
| 162 | } |
| 163 | |
| 164 | // Check for URL. |
| 165 | if ( isset( $row_meta['url'] ) ) { |
| 166 | $url = $row_meta['url']; |
| 167 | } else { |
| 168 | if ( ! empty( $slug ) ) { |
| 169 | if ( 'support' === $field ) { |
| 170 | $support_field = true === $is_premium ? 'premium_support' : 'free_support'; |
| 171 | |
| 172 | if ( ! empty( $base_uri[ $support_field ] ) ) { |
| 173 | $url = $base_uri[ $support_field ]; |
| 174 | } |
| 175 | |
| 176 | if ( 'free_support' === $support_field ) { |
| 177 | $url = $url . $slug; |
| 178 | |
| 179 | if ( $is_extended ) { |
| 180 | $url .= '-extended/overview/need-support/'; |
| 181 | } |
| 182 | } |
| 183 | } else { |
| 184 | if ( isset( $base_uri[ $field ] ) ) { |
| 185 | $url = $base_uri[ $field ] . $slug; |
| 186 | |
| 187 | if ( 'documentation' === $field && $is_extended ) { |
| 188 | $url .= '-extended'; |
| 189 | } |
| 190 | |
| 191 | $url = apply_filters( "yith_plugin_row_meta_{$field}_url", $url, $field, $slug, $base_uri ); |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | if ( ! empty( $url ) && ! empty( $label ) ) { |
| 198 | if ( ! ( $is_extended && in_array( $field, array( 'support', 'documentation' ), true ) ) ) { |
| 199 | $url = yith_plugin_fw_add_utm_data( $url, $slug, $utm_campaign, $plugin_version ); |
| 200 | } |
| 201 | |
| 202 | $plugin_meta[] = sprintf( '<a href="%s" target="_blank"><span class="%s"></span>%s</a>', $url, $icon, $label ); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | if ( isset( $plugin_meta[1] ) ) { |
| 207 | $utm_author_uri = yith_plugin_fw_add_utm_data( $plugin_data['AuthorURI'], $slug, $utm_campaign, $plugin_version ); |
| 208 | $plugin_meta[1] = str_replace( $plugin_data['AuthorURI'], $utm_author_uri, $plugin_meta[1] ); |
| 209 | } |
| 210 | |
| 211 | if ( isset( $plugin_meta[2] ) ) { |
| 212 | if ( $is_extended ) { |
| 213 | unset( $plugin_meta[2] ); |
| 214 | } else { |
| 215 | $utm_plugin_uri = yith_plugin_fw_add_utm_data( $plugin_data['PluginURI'], $slug, $utm_campaign, $plugin_version ); |
| 216 | $plugin_meta[2] = str_replace( $plugin_data['PluginURI'], $utm_plugin_uri, $plugin_meta[2] ); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | return $plugin_meta; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | if ( ! function_exists( 'yith_add_action_links' ) ) { |
| 225 | /** |
| 226 | * Add the action links to plugin admin page |
| 227 | * |
| 228 | * @param array $links The plugin links. |
| 229 | * @param string $panel_page The panel page. |
| 230 | * @param bool $is_premium Is this plugin premium? True if the plugin is premium. False otherwise. |
| 231 | * @param string $plugin_slug The plugin slug. |
| 232 | * |
| 233 | * @return array |
| 234 | * @since 1.6.5 |
| 235 | */ |
| 236 | function yith_add_action_links( $links, $panel_page = '', $is_premium = false, $plugin_slug = '' ) { |
| 237 | $links = is_array( $links ) ? $links : array(); |
| 238 | if ( ! empty( $panel_page ) ) { |
| 239 | $links[] = sprintf( '<a href="%s">%s</a>', admin_url( "admin.php?page={$panel_page}" ), _x( 'Settings', 'Action links', 'yith-plugin-fw' ) ); |
| 240 | } |
| 241 | |
| 242 | if ( $is_premium && class_exists( 'YIT_Plugin_Licence' ) ) { |
| 243 | $links[] = sprintf( '<a href="%s">%s</a>', YIT_Plugin_Licence()->get_license_activation_url( $plugin_slug ), __( 'License', 'yith-plugin-fw' ) ); |
| 244 | } |
| 245 | |
| 246 | return $links; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | if ( ! function_exists( 'yith_plugin_fw_print_deactivation_message' ) ) { |
| 251 | /** |
| 252 | * Prints message about plugins deactivation, due to multiple versions active of the same software active at the same time |
| 253 | * |
| 254 | * @return void |
| 255 | * @since 3.9.8 |
| 256 | */ |
| 257 | function yith_plugin_fw_print_deactivation_message() { |
| 258 | global $pagenow; |
| 259 | |
| 260 | // phpcs:disable WordPress.Security.NonceVerification |
| 261 | if ( 'plugins.php' !== $pagenow || ! isset( $_GET['yith_deactivated_plugins'] ) ) { |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | $names = sanitize_text_field( wp_unslash( $_GET['yith_deactivated_plugins'] ) ); |
| 266 | $names = explode( ',', $names ); |
| 267 | $names = array_map( |
| 268 | function ( $init_file ) { |
| 269 | $name = get_plugin_data( WP_PLUGIN_DIR . '/' . $init_file )['Name'] ?? ''; |
| 270 | if ( ! $name ) { |
| 271 | $name = str_replace( array( '-', 'init.php', '/' ), ' ', $init_file ); |
| 272 | $name = str_replace( array( 'yith', 'woocommerce', 'wordpress' ), array( 'YITH', 'WooCommerce', 'WordPress' ), $name ); |
| 273 | $name = trim( ucwords( $name ) ); |
| 274 | } |
| 275 | |
| 276 | return $name; |
| 277 | }, |
| 278 | $names |
| 279 | ); |
| 280 | |
| 281 | // translators: 1. Plugin(s) name(s). |
| 282 | $message = _n( |
| 283 | '%s was deactivated as you\'re running an higher tier version of the same plugin.', |
| 284 | '%s were deactivated as you\'re running higher tier versions of the same plugins.', |
| 285 | count( $names ), |
| 286 | 'yit-plugin-fw' |
| 287 | ); |
| 288 | $message = sprintf( $message, implode( ', ', $names ) ); |
| 289 | ?> |
| 290 | <div class="notice"> |
| 291 | <p><?php echo esc_html( $message ); ?></p> |
| 292 | </div> |
| 293 | <?php |
| 294 | // phpcs:enable |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | add_action( 'admin_notices', 'yith_plugin_fw_print_deactivation_message' ); |
| 299 | |
| 300 | /** |
| 301 | * Action triggered after the Plugin Framework initialization finishes. |
| 302 | */ |
| 303 | do_action( 'yith_plugin_fw_loaded' ); |
| 304 |