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