$product ) { if ( $product['id'] === $id ) { $status = ( isset( $product['status'] ) ) ? $product['status'] : ''; break; } } } return $status; } } if ( ! function_exists( 'get_bundled_plugins' ) ) { /** * Retrieves bundled plugin data. * * @param string $template product template. * @return void */ function get_bundled_plugins( $template = '' ) { global $ultimate_referer; $brainstrom_products = get_option( 'brainstrom_products', array() ); $prd_ids = array(); // If brainstrom_products is not yet set, call bsf core init. if ( is_array( $brainstrom_products ) ) { init_bsf_core(); $brainstrom_products = get_option( 'brainstrom_products', array() ); } foreach ( $brainstrom_products as $key => $value ) { foreach ( $value as $key => $value2 ) { array_push( $prd_ids, $key ); } } $path = bsf_get_api_url() . '?referer=' . $ultimate_referer; $data = array( 'action' => 'bsf_fetch_brainstorm_products', 'id' => $prd_ids, ); $request = wp_remote_post( $path, array( 'body' => $data, 'timeout' => '10', ) ); // Request http URL if the https version fails. if ( is_wp_error( $request ) && wp_remote_retrieve_response_code( $request ) !== 200 ) { $path = bsf_get_api_url( true ) . '?referer=' . $ultimate_referer; $request = wp_remote_post( $path, array( 'body' => $data, 'timeout' => '8', ) ); } if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) { $result = json_decode( $request['body'] ); $bundled = array(); $simple = array(); if ( ! empty( $result ) ) { if ( ! empty( $result->bundled ) ) { $bundled = $result->bundled; } if ( ! empty( $result->simple ) ) { $simple = $result->simple; } } foreach ( $bundled as $key => $value ) { if ( empty( $value ) ) { unset( $bundled->$key ); } } $brainstrom_bundled_products = (array) $bundled; update_option( 'brainstrom_bundled_products', $brainstrom_bundled_products ); // update 'brainstorm_products'. $simple = json_decode( wp_json_encode( $simple ), 1 ); foreach ( $brainstrom_products as $type => $products ) { foreach ( $products as $key => $product ) { $old_id = isset( $product['id'] ) ? $product['id'] : ''; $simple[ $type ][ $old_id ]['template'] = isset( $brainstrom_products[ $type ][ $old_id ]['template'] ) ? $brainstrom_products[ $type ][ $old_id ]['template'] : ''; $simple[ $type ][ $old_id ]['remote'] = isset( $simple[ $type ][ $old_id ]['version'] ) ? $simple[ $type ][ $old_id ]['version'] : ''; $simple[ $type ][ $old_id ]['version'] = isset( $brainstrom_products[ $type ][ $old_id ]['version'] ) ? $brainstrom_products[ $type ][ $old_id ]['version'] : ''; $simple[ $type ][ $old_id ]['purchase_key'] = isset( $brainstrom_products[ $type ][ $old_id ]['purchase_key'] ) ? $brainstrom_products[ $type ][ $old_id ]['purchase_key'] : ''; $simple[ $type ][ $old_id ]['status'] = isset( $brainstrom_products[ $type ][ $old_id ]['status'] ) ? $brainstrom_products[ $type ][ $old_id ]['status'] : ''; $simple[ $type ][ $old_id ]['message'] = isset( $brainstrom_products[ $type ][ $old_id ]['message'] ) ? $brainstrom_products[ $type ][ $old_id ]['message'] : ''; } } update_option( 'brainstrom_products', $simple ); } } } /** * Displays bundled product list for product. * * @param string $product_id Product ID. * @param bool $installed Show installed products?. * @return string */ 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 ) { ?>
description ); ?>