#StackBounty: #plugins #php #plugin-development #unit-tests Why is one phpunit test throwing an error on one class when all other class…

Bounty: 50

I’m working on the Liquid Messages plugin. There are some basic PHPUnit tests existing for it and when I run phpunit all pass except for one. It errors out:

There was 1 error:
1) GCS_Async_Test::test_class_access
Exception: Invalid GC_Sermons_Plugin property: async
/long/path/wp-content/plugins/lqd-messages/gc-sermons.php:330
/long/path/wp-content/plugins/lqd-messages/tests/test-async.php:10

The weird thing is that gc-sermons.php contains a number of properties similar to this one. They are initialized like so:

protected $sermons
protected $taxonomies
protected $async

Instances of the classes are attached to the properties:

        public function plugin_classes()
        {
            require_once self::$path . 'functions.php';

            // Attach other plugin classes to the base plugin class.
            $this->sermons = new GCS_Sermons($this);
            $this->taxonomies = new GCS_Taxonomies($this->sermons);
            $this->async = new GCS_Async($this);
            $this->shortcodes = new GCS_Shortcodes($this);
        }

If we look at GCS_Sermons, which is similar to GCS_Async in that it extends another class we see:

class GCS_Sermons extends GCS_Post_Types_Base {

Essentially the same as GCS_Async:

class GCS_Async extends WP_Async_Task {

If we look at the tests we see that the same test is run against GCS_Sermons as GCS_Async, but only fails with GCS_Async:

    function test_class_access() {
        $this->assertTrue( gc_sermons()->sermons instanceof GCS_Sermons );
    }

    function test_class_access() {
        $this->assertTrue( gc_sermons()->async instanceof GCS_Async );
    }

Any ideas why?


Get this bounty!!!

#StackBounty: #javascript #plugins #sketchapp #sketch-3 Implement shadow on the object from my predefine shadows in Sketch

Bounty: 300

I am not pro in javascript but I want to implement shadow on the object from my predefine shadows but the code is not working:

      var selection = context.selection;
      for (var i=0; i < selection.count(); i++){
        var layer = selection.objectAtIndex(i)

           if (layer.isEmpty) UI.message('No layers selected!');
           else {
                var sha_0 = [];
                var sha_1 = [
                color: '#00000024',
                 x: 0,
                 y: 1,
                 blur: 1,
                 spread: 0
                ]
                var sha_2 = [
                color: '#00036024',
                 x: 0,
                 y: 1,
                 blur: 1,
                 spread: 0
                ]
                var options = ['0dp', '1dp', '2dp'];
                var selectDialog = sketch.UI.getSelectionFromUser("Please select shadow depth:", options);
                if (selected == 0) {
                layer.forEach(function (e) {
                   e.style.shadows = sha_0;
                 });
               } else if (selected == 1) {
                 layer.forEach(function (e) {
                   e.style.shadows = sha_1;
                 });
               } else if (selected == 2) {
                 layer.forEach(function (e) {
                   e.style.shadows = sha_2;
                 });
               }
           }
      }


Get this bounty!!!

#StackBounty: #gpl #gpl-3 #lgpl #proprietary-code #plugins GPL Application linked to a LGPL library loading proprietary-plugins

Bounty: 50

This is a bit similar to what asked in this question, unless that here the case is that the application only directly loads LGPL code, and this one then may dlopen a proprietary lib, so:

  • GPL Program links to an LGPL library
  • LGPL library dlopen‘s and uses a proprietary module (optionally linked with the lib)
  • The module will provide structures and methods that the GPL application will consume or call, but will not use any library or data of the GPL application, while it will use the ones provided by the LGPL lib.

So, is this legal (as this parapgrah is a bit confusing)?


Get this bounty!!!

#StackBounty: #sound #alsa #plugins #soundcard #equalizer How can I route a system-wide ALSA EQ (alsaequal) through my volume control?

Bounty: 250

I have a rather specific issue and can’t solve it on my own.

As explained in this Question, I have set up a system-wide volume control for my single USB audio card (M-Audio Fast Track). Now, I would also like to add a system-wide equalizer (libasound2-plugin-equal) to it, while keeping the volume control intact.

Unfortunately, I have been unable to accomplish this, probably because of the routing. My current /etc/asound.conf looks like this:

ctl.equal {
    type equal;
}

pcm.plugequal {
    type equal;
    slave.pcm "plug:softvol";
}

pcm.!default {
    type plug;
    slave.pcm plugequal;
}

ctl.!default {
    type hw
    card Track
}

pcm.softvol {
    type softvol
    slave {
        pcm "hw:Track"
    } 
    control {
        name "Master"
        card Track
    }
}

The sound source (either PulseAudio or JACK) would have to be routed one of these ways:

pcm.softvol -> alsaequal -> hw:Track -> Analog Outputs

or

alsaequal -> pcm.softvol -> hw:Track -> Analog Outputs

However, none of the changes of pcm.!default and slave.pcm that I’ve tried so far have worked. Unfortunately, I need softvol to be active, since I can’t control my hardware card’s Master volume directly.

I am usually able to get sound output and working volume control, but the EQ does not appear to function this way (I’ve set all frequencies except 16 kHz to 0, so it should be audible).

When I try to test the equalizer channel with speaker-test -D plugequal -c 2 -twav, I get the following error:

speaker-test 1.1.9

Playback device is plugequal
Stream parameters are 48000Hz, S16_LE, 2 channels
WAV file(s)
Sample format not available for playback: Invalid argument
Setting of hwparams failed: Invalid argument

Does somebody have an idea of what could be the problem here or how to route the ALSA connections so that both the Master volume and the EQ for my device can be active at the same time?


Get this bounty!!!

#StackBounty: #8 #files #plugins Field formatter module throws cannot declare class error

Bounty: 50

I am trying to write a custom module, which defines a field formatter plugin, but when I visit the Manage display page, I get this error:

Fatal error: Cannot declare class Drupalmy_formatterPluginFieldFieldFormatterMyFormatter, because the name is already in use in /var/www/sites/drupalroot/web/modules/custom/my_formatter/src/Plugin/Field/FieldFormatter/MyFormatter.php on line 0

I’ve compared my module to several other working field formatter plugins and can’t seem to figure out what I’m missing.

My module directory is laid out like this:

web/modules/custom/my_formatter/
├── my_formatter.info.yml
├── my_formatter.module
├── src
│   └── Plugin
│       └── Field
│           └── FieldFormatter
│               └── MyFormatter.php
└── templates
    └── my-formatter.html.twig

My info file:

name: My Formatter
type: module
description: 'Do some fun stuff.'
package: Field types
core: 8.x
dependencies:
  - field
  - file

And my MyFormatter.php file:

<?php
/**
 * @file
 * Contains Drupalmy_formatterPluginFieldFieldFormatterMyFormatter.
 */

namespace Drupalmy_formatterPluginFieldFieldFormatter;

use DrupalCoreFieldFieldItemListInterface;
use DrupalfilePluginFieldFieldFormatterFileFormatterBase;

/**
 * Plugin implementation of the 'my' formatter.
 *
 * @FieldFormatter(
 *   id = "my",
 *   label = @Translation("My Formatter"),
 *   field_types = {
 *     "file"
 *   }
 * )
 */
class MyFormatter extends FileFormatterBase {

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    foreach ($items as $delta => $item) {
      $elements[$delta] = [
        '#theme' => 'my_formatter',
        '#my_var' => 'Hello',
      ];
    }
    return $elements;
  }

}

Any help would be greatly appreciated.


Get this bounty!!!

#StackBounty: #plugins #advanced-custom-fields #translation #plugin-polylang ACF Pro with Polylang

Bounty: 50

I need to create a “new admin option” for my footer component in my WP project so I’m using ACF Pro “Options Page” value. In my functions.php it looks like:

function register_footer_options_pages() {

    // Check function exists.
    if( !function_exists('acf_add_options_page') )
        return;

    // register options page.
    $option_page = acf_add_options_page(array(
        'page_title'    => __('Footer Settings'),
        'menu_title'    => __('Footer Settings'),
        'menu_slug'     => 'footer-settings',
        'capability'    => 'edit_posts',
        'redirect'      => false
    ));
}

// Hook into acf initialization.
add_action('acf/init', 'register_footer_options_pages');

Which adds the Footer Settings in my WP admin and it works fine.

But now I need to add translations for that part so I’m using Polylang. The issue is that Polylang doesn’t translate ACF Pros “Options Page” value by default.

So I found ACF Options For Polylang plugin which should do just that.

However, I can’t manage to make it work.

My steps:

  1. Installed ACF, then ACF PRO
  2. Installed Polylang
  3. Installed ACF Options For Polylang
  4. Updated my functions.php with code above

WP admin preview

And as you can see, I don’t have the possibility to add translations.

How to manage that?

Thanks


Get this bounty!!!

#StackBounty: #plugins #php #woocommerce WooCommerce Shopping Cart Not Initially Showing Products

Bounty: 50

I’m working with a client to create a WooCommerce shopping site. However, for some reason after people add items do their cart, these items take approximately 30 seconds to actually add to the cart.

I have been able to determine that the WooCommerce session is not being set immediately. Products are being saved in the database, but the session cannot access them until shortly afterwards.

I created a shortcode to print out the sessions so that I can see what’s happening. This script is irrelevant, but it is as follows:

function test_func( $atts ){
    $customer = @WC()->session;
    return print_r($customer);
}
add_shortcode( 'test', 'test_func' );

Here is a screenshot of the cart directly after adding the product. Note how it says “Your cart is currently empty” and the _customer_id:protected value:

Sessions print out that doesn't match anything

Here is a screenshot from phpMyAdmin which shows the session being stored:

PHPMyadmin screen shot of sessions

And 32 seconds after the first screen shot, I refreshed the page and this appeared, matching the _customer_id.

Session print out that does match

So my question: why is there a 30-second delay and how can I fix it?

I have already tried changing WooCommerce to go straight to checkout (didn’t work) and I have used these tips from BusinessBloomer.com that everybody links to.

I am running WooCommerce v.3.6.5, running WordPress 5.2.2, with PHP version 7.0.33. My host is GoDaddy.


Get this bounty!!!

#StackBounty: #plugins #templates #woocommerce WooCommerce – Load Templates From Plugin For All Template Files

Bounty: 50

I’ve read a bunch of articles about overriding the default /woocommerce/ templates and tried implementing the following (which were the best/most relevant that I could find all to no avail):

Essentially, what I would like to accomplish is: load all template files (for archives and posts not just template parts) from ~/wp-content/my-plugin/templates/woocommerce/* UNLESS the files are in my theme (and I don’t have to override each file instance in my function) . For instance:

  • ~/wp-content/my-plugin/templates/woocommerce/single-product.php (this seems like it just doesn’t want to load via plugin)
  • ~/wp-content/my-plugin/templates/woocommerce/archive-products.php (this seems like it just doesn’t want to load via plugin)
  • ~/wp-content/my-plugin/templates/woocommerce-pdf-invoices-packing-slips/* (I also want to be able to override other plugin extension templates just like I would be able to in my child theme)

EDIT:

The friendly folks at SkyVerge sent me the following code, which I tested and confirm that it works for template parts.

// Locate the template in a plugin
function myplugin_woocommerce_locate_template( $template, $template_name, $template_path ) {

    $_template = $template;

    if ( ! $template_path ) {
        $template_path = WC()->template_path();
    }

    $plugin_path = myplugin_plugin_path() . '/templates/';

    // Look within passed path within the theme - this is priority
    $template = locate_template(
        array(
            trailingslashit( $template_path ) . $template_name,
            $template_name
        )
    );

    // Modification: Get the template from this plugin, if it exists
    if ( ! $template && file_exists( $plugin_path . $template_name ) ) {
        $template = $plugin_path . $template_name;
    }

    // Use default template
    if ( ! $template ) {
        $template = $_template;
    }

    return $template;
}
add_filter( 'woocommerce_locate_template', 'myplugin_woocommerce_locate_template', 10, 3 );

// Helper to get the plugin's path on the server
function myplugin_plugin_path() {
    // gets the absolute path to this plugin directory
    return untrailingslashit( plugin_dir_path( __FILE__ ) );
}

The above code works for something like:

  • ~/myplugin/templates/single-product/product-image.php

But does NOT work for:

  • ~/myplugin/templates/single-product.php

Where I’m getting stuck:

  • There are solutions to override bits and pieces of WC templates, but there I’ve not found / been able to create a solution that does comprehensive overrides (i.e. overriding ability just like a child theme would)
  • I can’t seem to find the right combination of filter hooks; single-product.php and archive-product.php seem to be controlled by functions outside the standard WC template functions

Thanks in advance!


Get this bounty!!!

#StackBounty: #plugins #plugin-development #svn #wordpress.org WordPress SVN UTF-8 issue

Bounty: 50

I tried to commit the changes to the “Filenames to latin” plugin and got the SVN error.

The error message:

Error: Commit failed (details follow): Error: Commit blocked by
pre-commit hook (exit code 1) with output: Error: [Error output could
not be translated from the native locale to UTF-8.] Error: This error
was generated by a custom hook script on the Subversion server. Error:
Please contact your server administrator for help with resolving this
issue.

The latest code for the plugin I had issues with is in the GIT repo.

Does anyone know how can I solve this issue?

Thank you in advance.


Get this bounty!!!

#StackBounty: #laravel #api #plugins #moodle Moodle autologin plugin – how to direct user to a specific course?

Bounty: 50

I am building a laravel web application which involves the usage of Moodle Service (version 3.6). I have done autologin with a plugin.

The problem is that clicking the Take Course button on my external application will autologin to Moodle (via the plugin), but does not redirect the user to the course described in the button.

Is there a mechanism to do this?


Get this bounty!!!