WPSwitzerland / plugin-boilerplate-wordpress

A starting point for development of a WordPress plugin using PHP Namespaces, adhering to WordPress' own coding standards
3 stars 2 forks source link

php incorrectness #4

Open wiejakp opened 7 years ago

wiejakp commented 7 years ago

how and what version are you running this script? I could not on 7.1.

these are changes that php actually happen to render 'class-plugin.php':

<?php

namespace name\app;

/**
 * Class wp_chat_support
 *
 * @package name\app
 */
class app
{
    private $plugin;

    private static $name = '';
    private static $prefix = '';
    private static $version = '';
    private static $file = '';

    /**
     * Creates an instance if one isn't already available,
     * then return the current instance.
     *
     * @param  string $file The file from which the class is being instantiated.
     *
     * @return object       The class instance.
     */
    public function get_instance($file)
    {
        if (!isset($this->plugin) && !($this->plugin instanceof app)) {
            $this->plugin = new wp_chat_support;
            $this->plugin->run();

            $data = get_plugin_data($file);

            $this->plugin->name = $data['Name'];
            $this->plugin->prefix = 'PLUGIN_PREFIX';
            $this->plugin->version = $data['Version'];
            $this->plugin->file = $file;
        }
    }

    /**
     * Non-essential dump function to debug variables.
     *
     * @param  mixed   $var The variable to be output
     * @param  boolean $die Should the script stop immediately after outputting $var?
     */
    public function dump($var, $die = false)
    {
        echo '<pre>' . print_r($var, 1) . '</pre>';
        if ($die) {
            die();
        }
    }

    /**
     * Execution function which is called after the class has been initialized.
     * This contains hook and filter assignments, etc.
     */
    private function run()
    {
        add_action('plugins_loaded', [$this, 'load_plugin_textdomain']);
    }

    /**
     * Load translation files from the indicated directory.
     */
    public function load_plugin_textdomain()
    {
        load_plugin_textdomain('TEXT_DOMAIN', false, dirname(plugin_basename($this->file)) . '/languages');
    }
}
maurobringolf commented 7 years ago

Thank you for your feedback. This is a work in progress though, so if you want to make a pull request and suggest your changes that would be highly appreciated! Then we can directly see what changes you made.