13 events
when toggle format what by license comment
Mar 21 '18 at 15:39 comment added dewd I should point out I've been a full stack developer for 20 years, just so you know I know client/server achitecture. It's possible to load <script type="text\javascript" src="/foo.php" ></script> : parses script as PHP on the server side, javascript on the client side. Server side, the script has access to the full PHP API, but not the Wordpress API. This makes sense for security puposes. REST API is a good idea. Just return JSON to load in script. However, It is that is conceivable that Wordpress would have a method to load server vars encapsulated into a script without this workaround.
Mar 21 '18 at 10:19 comment added Tom J Nowell @dewd you mean the REST API? Javascript and PHP don't run on the same machine, one is client side, the other is server side so you can't just pass PHP functions back and forth into JS as you describe, else there'd be a huge amount of back and forth and resources wasted. You have to bundle data with the page or request it via the REST API, it's the same in any other system
Mar 21 '18 at 2:25 comment added dewd @TomJNowell Unofrtunately, wp_localize_script only allows the attachment of objects to the global window object. Since javascript can be written out via PHP, a better solution might be to allow such a script to have direct access to the WordPress API. That way any server variables could be encapsulated within the script itself protecting any window pollution issues. Much in the same way that is is best to build plugins within an OO environment to avoid clashes within the WordPress environment.
Mar 20 '18 at 0:11 comment added Tom J Nowell @dewd you mean via something like wp_localize_script? That's more than doable, see the top answer
Mar 19 '18 at 18:43 comment added dewd @TomJNowell isn't it also an issue that WordPress doesn't respect encapsulation? It's a big shame that WordPress can't pass the JS file the parameters as a JSON string or similar to reduce the chance of a namespace clash.
May 6 '16 at 6:45 history tweeted twitter.com/StackWordPress/status/728475818423402496
May 6 '16 at 6:38 comment added madalinivascu if you are using a php file why don't you just put the select query in it not in the in_home function?
May 6 '16 at 6:35 comment added madalinivascu its a js file with a php extension nice :)))
May 6 '16 at 1:02 comment added Tom J Nowell As a sidenote, you should route all requests through WordPress, never make direct calls to PHP files inside your plugin or theme from the browser, be it for AJAX, form submissions, etc, it's a huge security headache
May 5 '16 at 22:49 answer Andrew Bartel timeline score: 8
May 5 '16 at 22:48 answer Manu timeline score: 2
May 5 '16 at 22:36 review First posts
May 5 '16 at 23:22
May 5 '16 at 22:34 history asked Met El Idrissi CC BY-SA 3.0