Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php incorrectness #4

Open
wiejakp opened this issue Jun 3, 2017 · 1 comment
Open

php incorrectness #4

wiejakp opened this issue Jun 3, 2017 · 1 comment

Comments

@wiejakp
Copy link

wiejakp commented Jun 3, 2017

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');
    }
}
@wiejakp wiejakp closed this as completed Jun 3, 2017
@wiejakp wiejakp reopened this Jun 3, 2017
@maurobringolf
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants