Can I create a WordPress plugin with JavaScript only? - javascript

I am scared to ask this question, because StackOverflow is already warning me about my question being likely to be downvoted. But I am very curious about this.
I have read that you must have at least one php file in your WordPress Plugin. Which sounds to me like you only need something like an index/entry php file.
However, I wasn't able to find much about JavaScript in WordPress Plugins by using google. Which seemed weird to me, because we're talking here about the web of 2017.
An answer would be very appreciated!

The answer is no, you cannot, as you have referenced in your question. By definition, a plugin is at the very least a "PHP file with a WordPress plugin header comment" (Wordpress Docs).
However, there is no reason a Wordpress plugin can't be primarily Javascript. You can follow this guide for some different approaches to include it in your plugin.

Since WordPress is (basically) purely php, then all its plugins will also be php. This is they way it has been set up.
In order to have a 'WordPress plugin', yes you will need at least one php file to register to WordPress and enqueue your javascript/css/what-have-you..
This means if you want something like React/Ember on your WP installation, they aren't going to be 'WordPress' plugins, they will belong to the React/Ember ecosystem. You will just have the minimum to enqueue the javascript libraries you want to use.
You can then use your javascript frontend and talk to WP's REST API, and now WP has basically become your server 'framework'.
So, no, there's no such thing as a 'JavaScript WordPress Plugin'. But you can have a plugin that includes as much fancy JS as you may want.

The following article should give you insight about this.
Your WordPress Plugin must have at least one PHP file; it could also contain JavaScript files, CSS files, image files and language files. If there are multiple files, pick a unique name for a directory and a name of your choice for the main PHP file. (This file name is often, but not essentially, the same as the directory name.) Example directory and file names could be mycompanyname-fabulous-functionality and mycompanyname-fabulous-functionality.php respectively. Put all your Plugin's files into the directory you've created and tell your Plugin users to upload the whole directory to wp-content/plugins/.
Hope this helps. But no, you can't create a Wordpress plugin with only Javascript.

Related

Need ScriptReferenceProfiler.dll or alternate

I improving site performance and for that, I try to Bundle or combine ScriptResource.axd and Webresource.axd but before combine to I need to know javascript file reference name which is used by ajax control toolkit in asp.net web form
like this https://lancezhang.wordpress.com/2008/11/15/aspnet-ajax-performance/
I need ScriptReferenceProfiler.DLL to get a reference of the javascript file which is used in ajax toolkit on the web page.
do you have any idea to get this dll file
I go through this tutorial
https://channel9.msdn.com/Blogs/ASP-NET-Site-Videos/using-script-combining-to-improve-ajax-performance
Or if you have any alternate solution please let me know
The file you looking and reference from the link you add was here : http://aspnet.codeplex.com/releases/view/13356
I can not find it now so I uploaded for you here, both source code and binaries.
http://planethost.gr/so/ScriptReferenceProfiler.zip
http://planethost.gr/so/ScriptReferenceProfilerBinaries.zip

How to find source of dlls and js files?

I'm building a Powershell script to find the source of dlls and js files. This is to keep track of internal and external code.
So far for dlls, I've come up with $dll.VersionInfo.LegalCopyright which works if they provide copyright information. (e.g. Microsoft, Twitter, Google, Company, etc)
If there's a better way, do tell.
However, I'm stumped on JS files. For most cases, the js file will be just jQuery but not always.
JS files aren't compiled so there isn't anything I can scrape from. Maybe inside the file? Is there a pattern/convention that developers sign js files with that I can try to match?
Thinking about it further, this seems like a far-fetched endeavor. There is no way to generalize all the signing conventions of everyone. For the time being, I'll just separate js into Jquery and Other, seeing as how 90% of the js files seem to be Jquery.

How to modify bigcommerce frontend with api (add js code in app)

I am writing and app for biggommerce which should a bit of code JS to the header. Does bigcommerce allow to do something like that? (something like ScriptTag in Shopify)
Best Regards
Vahe Abelyan
There is no way to access/edit template files thru the Bigcommerce API. It would just be best to guide the user to pasting the JS into their header (as most apps already do).
Rob is correct, however, depending on how complex you want to get you could technically write an app that would fetch or put a file into the theme's template structure using WebDAV.
Basically
if /template/panels/htmlhead.html exists find it, add your script code before , then post file back to webdav
if /template/panels/htmlhead.html does not exist, allow user to upload the default one from their theme, and then have you app do the same thing.
However I'd recommend sticking with the easy way, just provide instructions for a user to place the code into the file themselves. If you want a great example of this, see YOTPO's installation instructions.

Multiple javascripts solution

I Have created a flatfile based cms. PHP and jquery mostly. It is very dynamic and easy in use. I have 3 javascript includes for juery and other functions. This is for the main cms files. So that is quite allright.
But i have written multiple plugins/addons for he cms, also jquery and php, guestbook, comments, rating system, album galleries, site search,.... The problem is that each plugin has javascripts included. And i need to include all scripts in the head part of my main cms in order for the plugin to work on the cms. Now all javascripts get loaded every time the page reloads or if u click a link. That gives many http requests wich slows the cms down. About 15 javascrip files are included in the head now
Is here a way i can load only the needed javascript files and not all of them with a function of some kind.
i tried to compress all the javascript into one file, but that gives errors...
I hope my question is clear in my bad english :)
thx for any response
The tool you are looking for is called grunt.
http://gruntjs.com/
You have over 2000 packages for doing many things and one of them in concatenation and minification.
grunt-contrib-cssmin
grunt-contrib-uglify
grunt-contrib-concat
the list goes on an on, but check 'em all here.
https://github.com/gruntjs/grunt-contrib
grunt is a little confusing the first time you see it, but there are heaps of resources for it and also heaps of stackoverflow examples.
Once you go grunt you never go back!
I'd think you can merge all javascript files and then minify it. are you using double function names or do you have javascript code outside of functions? maybe that is what is throwing up your errors.
would leave you with only one request to retrieve all your javascript functions , and you would only need to minify / compress one file.

How to include an external PHP file into a Joomla article?

So basically, I have a single article that I would like to load a PHP file into. This PHP file has a bunch of PHP and Javascript, along with HTML.
I need to include this full PHP file into my article since it contains an application form that I need on my website.
I have tried the following:
Using an extension to allow PHP and Javascript code within an article. Although, this is extremely time consuming since all PHP and Javascript must be wrapped in some special tags for the extension to recognise it, therefore this would take me days.
I tried using the extension and then trying <?php include "form.php"; ?> within the special tags, although this returned a major error since I believe it is because the PHP code is not within the tags itself.
Does anyone have any suggestions to how I can accomplish this?
Try this ,
Create a module that have your forms. For module development tutorial
And create an article and set the module inside that like.
{loadposition contact_form_pos}
Inside your article just mention the module position like above
for more
Using extensions is the only way to do that.
If you don't want to use a plugin that allows PHP into articles, you would have to write your own custom component to show that php page in your own menu item, out of an article.
It's a little hard to answer when you haven't said if you want to just do this one time in one specific article or you want to be able to put it into any article.

Categories

Resources