• Resolved ignatiusjeroe

    (@ignatiusjeroe)


    I’ve been studying the source code of this plugin and found 1 minor error and 1 design flaw. Below is a detailed description of the issues, proposed solutions and locations of the bug within the code

    ISSUE: esc_attr_e(…) should be esc_attr(…)
    SOURCE: download-monitor/src/Admin/Settings/Fields/Field.php @line 74
    /**
    * Echo the placeholder
    */
    public function e_placeholder() {
    $placeholder = $this->get_placeholder();
    echo ( ! empty( $placeholder ) ) ? ‘placeholder=”‘ . esc_attr_e( $placeholder ) . ‘”‘ : ”;
    }

    //////////////////////////
    ISSUE: no second param ($name) passed to get_template_part(…) that loads gateway methods fields.
    Explanation: …->get_template_part(‘shop/checkout/payment-gateway’,…) loads the file that is responsible for outputting payment gateway fields on checkout page. It’s params are passed to hooks which 3th parties can use for changing the default template file. See download-monitor/src/TemplateHandler.php @line 66. Sadly the second param ($name) is empty which provides the hooks with the needed context for callbacks that are registered to $template = apply_filters( ‘dlm_get_template_part’, $template, $slug, $name ). As seen in below snippet, DLM iterates over all payment gateway objects and calls get_template_part(…). The first 2 params of hook ‘dlm_get_template_part’ remain the same for each iteration. There is no way a callback can make a distinction between which payment gateway is currently being iterated over. So knowing when my callback should change the default template becomes almost impossible to do without workaround. This could all easily resolved if the third param ($name) is passed which is the 2nd param of get_template_part(…). This value should be the id of the payment gateway. Solution found below…

    SOURCE: download-monitor//templates/shop/checkout/payment.php @ line 20
    if ( ! empty( $payment_gateways ) ) {
    ?>

      <?php
      foreach ( $payment_gateways as $gateway ) {
      download_monitor()->service( ‘template_handler’ )->get_template_part( ‘shop/checkout/payment-gateway’, ”, ”, array(
      ‘cart’ => $cart,
      ‘gateway’ => $gateway,
      ‘default_gateway’ => $default_gateway
      ) );
      }
      ?>

    <?php

    //SOLUTION
    if ( ! empty( $payment_gateways ) ) {
    //Added $gateway->get_id() as 2md param.
    ?>

      <?php
      foreach ( $payment_gateways as $gateway ) {
      download_monitor()->service( ‘template_handler’ )->get_template_part( ‘shop/checkout/payment-gateway’, $gateway->get_id() , ”, array(
      ‘cart’ => $cart,
      ‘gateway’ => $gateway,
      ‘default_gateway’ => $default_gateway
      ) );
      }
      ?>

    <?php

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Settings & payment template files bugs found and proposed solution’ is closed to new replies.