is_from_partner( $product ) ) { return false; } if ( $product->is_theme() && ! current_user_can( 'switch_themes' ) ) { return false; } if ( $product->is_plugin() && ! current_user_can( 'install_plugins' ) ) { return false; } return true; } /** * Registers the hooks. * * @param Product $product Product to load. * * @throws \Exception If the configuration is invalid. * * @return Compatibilities Module instance. */ public function load( $product ) { $this->product = $product; $compatibilities = apply_filters( 'themeisle_sdk_compatibilities/' . $this->product->get_slug(), [] ); if ( empty( $compatibilities ) ) { return $this; } $requirement = null; $check_type = null; foreach ( $compatibilities as $compatibility ) { if ( empty( $compatibility['basefile'] ) ) { return $this; } $requirement = new Product( $compatibility['basefile'] ); $tested_up = isset( $compatibility[ self::TESTED_UP ] ) ? $compatibility[ self::TESTED_UP ] : '999'; $required = $compatibility[ self::REQUIRED ]; if ( ! version_compare( $required, $tested_up, '<' ) ) { throw new \Exception( sprintf( 'Invalid required/tested_up configuration. Required version %s should be lower than tested_up %s.', $required, $tested_up ) ); } $check_type = self::REQUIRED; if ( ! version_compare( $requirement->get_version(), $required, '<' ) ) { $check_type = self::TESTED_UP; if ( version_compare( $requirement->get_version(), $tested_up . '.9999', '<' ) ) { return $this; } } break; } if ( empty( $requirement ) ) { return $this; } if ( $check_type === self::REQUIRED ) { $this->mark_required( $product, $requirement ); } if ( $check_type === self::TESTED_UP ) { $this->mark_testedup( $product, $requirement ); } return $this; } /** * Mark the product tested up. * * @param Product $product Product object. * @param Product $requirement Requirement object. * * @return void */ public function mark_testedup( $product, $requirement ) { add_action( 'admin_head', function () use ( $product, $requirement ) { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : ''; if ( empty( $screen ) || ! isset( $screen->id ) ) { return; } if ( $requirement->is_theme() && $screen->id === 'themes' ) { ?> is_plugin() && $screen->id === 'plugins' ) { ?> is_theme() && property_exists( $upgrader, 'skin' ) && property_exists( $upgrader->skin, 'theme_info' ) && $upgrader->skin->theme_info->template === $product->get_slug() ) { $should_block = true; } if ( ! $should_block && $product->is_plugin() && property_exists( $upgrader, 'skin' ) && property_exists( $upgrader->skin, 'plugin_info' ) && $upgrader->skin->plugin_info['Name'] === $product->get_name() ) { $should_block = true; } if ( $should_block ) { echo( sprintf( '%s update requires a newer version of %s. Please %supdate%s %s %s.', esc_attr( $product->get_friendly_name() ), esc_attr( $requirement->get_friendly_name() ), '', '', esc_attr( $requirement->get_friendly_name() ), esc_attr( $requirement->is_theme() ? 'theme' : 'plugin' ) ) ); $upgrader->maintenance_mode( false ); die(); } return $return; }, 10, 3 ); add_action( 'admin_notices', function () use ( $product, $requirement ) { echo '

'; echo( sprintf( '%s requires a newer version of %s. Please %supdate%s %s %s to the latest version.', '' . esc_attr( $product->get_friendly_name() ) . '', '' . esc_attr( $requirement->get_friendly_name() ) . '', '', '', '' . esc_attr( $requirement->get_friendly_name() ) . '', esc_attr( $requirement->is_theme() ? 'theme' : 'plugin' ) ) ); echo '

'; } ); } }