function eStore_show_button_based_on_condition($id, $ret_product, $button_type, $restriction, $style = '', $args = array())
{
    $output = "";
    $show_button = false;
    if (!empty($restriction)) {
        if (function_exists('wp_eMember_install')) {
            $restriction_args = explode('|', $restriction);
            $args_size = count($restriction_args);
            if ($args_size == 1) {
                //Only level restriction restriction="1-2-3"
                $permitted_levels = explode('-', $restriction_args[0]);
                $show_button = eStore_member_belongs_to_specified_levels($permitted_levels);
            } else {
                if ($args_size > 1) {
                    //Level restriction with conditional buttons restriction="1-2|4|2"
                    if ($args_size == 3) {
                        if (eStore_is_product_using_custom_button_image($id)) {
                            //Check if button image is being used
                            $output .= '<div class="eStore_error_message">Error! You have specified a custom button image for this product in the product configuration. This shortcode cannot work with a custom button image. Edit this product and remove the URL value from the "Button Image URL" field.</div>';
                            return $output;
                        }
                        $permitted_levels = explode('-', $restriction_args[0]);
                        if (eStore_member_belongs_to_specified_levels($permitted_levels)) {
                            $button_type = $restriction_args[1];
                        } else {
                            $button_type = $restriction_args[2];
                        }
                        $show_button = true;
                    } else {
                        $output .= '<div class="eStore_error_message">Error! You have an error in the "restriction" parameter. Please check the documentation and update the shortcode accordingly.</div>';
                    }
                }
            }
        } else {
            $output .= '<strong><i>The restriction option can be only be used if you are using the <a href="http://www.tipsandtricks-hq.com/?p=1706" target="_blank">WP eMember</a> plugin!</i></strong>';
        }
    }
    if (empty($restriction) || $show_button) {
        if ($button_type == 1) {
            if ($style == '2') {
                $output .= get_button_code_fancy2_for_element($ret_product, false);
            } else {
                $output .= get_button_code_for_element($ret_product);
            }
        } else {
            if ($button_type == 2) {
                $output .= print_eStore_buy_now_button($id);
            } else {
                if ($button_type == 3) {
                    if (isset($args['gateway'])) {
                        if (function_exists('print_wp_pg_eStore_subscription_button_form')) {
                            $output .= print_wp_pg_eStore_subscription_button_form($id, $args['gateway']);
                        }
                    } else {
                        $output .= print_eStore_subscribe_button_form($id);
                    }
                } else {
                    if ($button_type == 4) {
                        $output .= eStore_show_download_now_button($id);
                    } else {
                        if ($button_type == 5) {
                            //download now button with PDF Stamping
                            if (function_exists('eStore_show_download_now_button_with_stamping')) {
                                $output .= eStore_show_download_now_button_with_stamping($id);
                            } else {
                                $output .= '<div class="eStore_error_message">Error! You need to have the eStore extra shortocdes plugin installed for this type of button.</div>';
                            }
                        } else {
                            if ($button_type == 6) {
                                //Donate now button
                                $args = array('id' => $id);
                                $output .= eStore_donate_button_code($args);
                            }
                        }
                    }
                }
            }
        }
    } else {
        $output .= '<div class="eStore_eMember_restricted_message">' . EMEMBER_CONTENT_RESTRICTED . '</div>';
    }
    return $output;
}
Example #2
0
function eStore_download_now_button($atts)
{
    extract(shortcode_atts(array('id' => 'no id'), $atts));
    return eStore_show_download_now_button($id);
}