GithubHelp home page GithubHelp logo

Comments (3)

tommyZZM avatar tommyZZM commented on July 28, 2024

Solve the problem by adding
Action::listen('admin_head', $this, 'install')->dispatch();
in plugins/themosis-framework/src/Themosis/Ajax/Ajax.php line 30

but maybe it’s not good to change the source code of framework..

from framework.

tommyZZM avatar tommyZZM commented on July 28, 2024

In order to keep the source by framework.

Also solve the problem by adding this to php files in app/admin/

/** AdminAjax **/
if(!class_exists('AdminAjax')){
class AdminAjax{

    private $namespace;

    private $url;

    public function __construct(){

        $this->namespace = (Application::get('namespace')) ? Application::get('namespace') : 'themosis';

        $this->url = (Application::get('ajaxurl')) ? admin_url().Application::get('ajaxurl').'.php' : '';

        add_action( "admin_head" , array($this,'install') );
    }

    public function install()
    {
        $datas = apply_filters('themosisGlobalObject', array());

        $ajaxurl = array(
            'ajaxurl' => $this->url
        );

        $namespace = array_merge($ajaxurl, $datas);

        $namespace = json_encode($namespace);

        $output = "<script type=\"text/javascript\">\n\r";
        $output.= "//<![CDATA[\n\r";
        $output.= "var ".$this->namespace." = ".$namespace;
        $output.= "//]]>\n\r";
        $output.= "</script>";

        echo($output);
    }
}

if(is_admin()){
    new AdminAjax();
}

}

from framework.

jlambe avatar jlambe commented on July 28, 2024

Hi,

there is no need for all this code :) By default, WordPress admin has a global JS variable called ajaxurl. Inspect the top of the <head> tag.

Also, there is already a Themosis framework global JS object available in the admin which is totally different than the one for the front-end.

The admin global JS can't be renamed. You can add key/values to it by using this filter:

add_filter('themosisAdminGlobalObject', function($data)
{
    return $data['key'] = 'Some value';
});

Then use it for your admin script like so:

    var foo = thfmk_themosis.key;

Hope this helps. I will add these info in the docs ;)

from framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.