bsf_render_bundled_products( string $product_id, bool $installed )
Displays bundled product list for product.
Description
Parameters
- $product_id
-
(string) (Required) Product ID.
- $installed
-
(bool) (Required) Show installed products?.
Return
(string)
Source
File: admin/bsf-core/plugin-installer/admin-functions.php
function bsf_render_bundled_products( $product_id, $installed ) {
$product_status = check_bsf_product_status( $product_id );
$brainstrom_bundled_products = get_option( 'brainstrom_bundled_products', array() );
if ( isset( $brainstrom_bundled_products[ $product_id ] ) ) {
$brainstrom_bundled_products = $brainstrom_bundled_products[ $product_id ];
}
usort( $brainstrom_bundled_products, 'bsf_sort' );
$global_plugin_installed = 0;
$global_plugin_activated = 0;
$total_bundled_plugins = count( $brainstrom_bundled_products );
foreach ( $brainstrom_bundled_products as $key => $product ) {
if ( ! isset( $product->id ) || empty( $product->id ) ) {
continue;
}
if ( isset( $request_product_id ) && $request_product_id !== $product->id ) {
continue;
}
$plugin_abs_path = WP_PLUGIN_DIR . '/' . $product->init;
if ( is_file( $plugin_abs_path ) ) {
$global_plugin_installed++;
if ( is_plugin_active( $product->init ) ) {
$global_plugin_activated++;
}
}
}
ob_start();
if ( $total_bundled_plugins === $global_plugin_installed ) {
?>
<div class="bsf-extensions-no-active">
<div class="bsf-extensions-title-icon"><span class="dashicons dashicons-smiley"></span></div>
<p class="bsf-text-light"><em><?php esc_html_e( 'All available extensions have been installed!', 'bsf' ); ?></em></p>
</div>
<?php
return ob_get_clean();
}
if ( empty( $brainstrom_bundled_products ) ) {
?>
<div class="bsf-extensions-no-active">
<div class="bsf-extensions-title-icon"><span class="dashicons dashicons-download"></span></div>
<p class="bsf-text-light"><em><?php esc_html_e( 'No extensions available yet!', 'bsf' ); ?></em></p>
<div class="bsf-cp-rem-bundle" style="margin-top: 30px;">
<a class="button-primary" href="<?php echo esc_url( $reset_bundled_url ); ?>"><?php esc_html_e( 'Refresh Bundled Products', 'bsf' ); ?></a>
</div>
</div>
<?php
return ob_get_clean();
}
foreach ( $brainstrom_bundled_products as $key => $product ) {
if ( ! isset( $product->id ) || empty( $product->id ) ) {
continue;
}
if ( isset( $request_product_id ) && $request_product_id !== $product->id ) {
continue;
}
$is_plugin_installed = false;
$is_plugin_activated = false;
$plugin_abs_path = WP_PLUGIN_DIR . '/' . $product->init;
if ( is_file( $plugin_abs_path ) ) {
$is_plugin_installed = true;
if ( is_plugin_active( $product->init ) ) {
$is_plugin_activated = true;
}
}
if ( ( $is_plugin_installed && ! $installed ) || ( ! $is_plugin_installed && $installed ) ) {
continue;
}
if ( $is_plugin_installed && $is_plugin_activated ) {
$class = 'active-plugin';
} elseif ( $is_plugin_installed && ! $is_plugin_activated ) {
$class = 'inactive-plugin';
} else {
$class = 'plugin-not-installed';
}
?>
<li id="ext-<?php echo esc_attr( $key ); ?>" class="bsf-extension <?php echo esc_attr( $class ); ?> bsf-extension-<?php echo esc_attr( $product->slug ); ?>" data-init="<?php echo esc_attr( $product->init ); ?>">
<?php if ( ! $is_plugin_installed ) { ?>
<div class="bsf-extension-start-install">
<div class="bsf-extension-start-install-content">
<h2><?php esc_html_e( 'Downloading', 'bsf' ); ?><div class="bsf-css-loader"></div></h2>
</div>
</div>
<?php } ?>
<div class="top-section">
<?php if ( ! empty( $product->product_image ) ) { ?>
<div class="bsf-extension-product-image">
<div class="bsf-extension-product-image-stick">
<img src="<?php echo esc_url( $product->product_image ); ?>" class="img" alt="image"/>
</div>
</div>
<?php } ?>
<div class="bsf-extension-info">
<?php $name = ( isset( $product->short_name ) ) ? $product->short_name : $product->name; ?>
<h4 class="title"><?php echo esc_html( $name ); ?></h4>
<p class="desc"><?php echo esc_html( $product->description ); ?><span class="author"><cite>By <?php echo esc_html( $product->author ); ?></cite></span></p>
</div>
</div>
<div class="bottom-section">
<?php
$button_class = '';
if ( ! $is_plugin_installed ) {
if ( ( ! $product->licence_require || 'false' === $product->licence_require ) || 'registered' === $product_status ) {
$installer_url = bsf_exension_installer_url( $product_id );
$button = __( 'Install', 'bsf' );
$button_class = 'bsf-install-button install-now';
} elseif ( ( $product->licence_require || 'true' === $product->licence_require ) && 'registered' !== $product_status ) {
$installer_url = bsf_registration_page_url( '&id=' . $product_id, $product_id );
$button = __( 'Validate Purchase', 'bsf' );
$button_class = 'bsf-validate-licence-button';
}
} else {
$current_name = strtolower( bsf_get_current_name( $product->init, $product->type ) );
$current_name = preg_replace( '![^a-z0-9]+!i', '-', $current_name );
if ( is_multisite() ) {
$installer_url = network_admin_url( 'plugins.php#' . $current_name );
} else {
$installer_url = admin_url( 'plugins.php#' . $current_name );
}
$button = __( 'Installed', 'bsf' );
}
?>
<a class="button button-primary extension-button <?php echo esc_attr( $button_class ); ?>" href="<?php echo esc_url( $installer_url ); ?>" data-slug="<?php echo esc_html( $product->slug ); ?>" data-ext="<?php echo esc_attr( $key ); ?>" data-pid="<?php echo esc_attr( $product->id ); ?>" data-bundled="true" data-action="install"><?php echo esc_html( $button ); ?></a>
</div>
</li>
<?php
}
return ob_get_clean();
}
Expand full source code Collapse full source code View on Trac