Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

MichaelNi on "[Feedback / Questions] Simple Self-Stylable Pop-Up (first plugin)"

$
0
0

I hope I am posting this in the right forum:
I have recently developed my first plugin. Before releasing it (I am well aware that there are many plugins out there that already offer the featuers I have built, still, this is a "learning plugin" before I get onto bigger things), I'd like to hear some feedback, especially about the coding style and coding in general. I also have some general questions concerning plugin development.

You may download it here:
http://askella.de/customer/ssspu/simple-self-stylable-popup.zip

Or the individual files:
http://askella/customer/ssspu/ssspu.php
http://askella/customer/ssspu/ssspu_admin_js.js
http://askella/customer/ssspu/ssspu_js.js
http://askella/customer/ssspu/yes.png
And move them into a plugin folder called "simple-self-stylable-popup".

Now to the outstanding questions I have:
I'm using jQuery on the plugin, for both the front- and backend section. In the beginning, I was checking whether jQuery was already loaded this way:

if(!window.jQuery){
	alert("not loaded");
	echo("test");
	script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js';
	script.onload = ssspu_run;
	document.getElementsByTagName("head")[0].appendChild(script);
}
else{
	alert("loaded");
	ssspu_run();
}

I later read about this being bad practice and therefore used these WP functions / hooks:

wp_deregister_script('jquery');
	wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js');
	wp_enqueue_script('jquery');

The first question: Does WP ensure that jQuery is only loaded once?

Obviously, as the plugin is called "self stylable pop-up", I need to load CSS into the frontend. I am not using a hook for this yet, as I can not think of another possibility than to dynamically write some sort of frontend.css into the plugin folder (with the css the user has entered in the backend) and hook this up.

Same goes with the CSS in the admin menu, but I also need a PHP call here:

#ssspu_saved:before{
			position:absolute;
			content:url(<? echo(plugins_url('yes.png', __FILE__)); ?>);
			width:22px;
			height:22px;
			margin-left:-30px;
		}

As I can not use PHP in .css files, it is impossible for me to use the correct hook - or am I overlooking something here?

Exactly the same in Javascript, by the way:

<script type="text/javascript">
        var ssspu_active = "<? echo(get_option('ssspu_activated'));?>";
        var ssspu_outsideclick = "<? echo(get_option('ssspu_outsideclick'));?>";
        var ssspu_firstvisit = "<? echo(get_option('ssspu_firstvisit'));?>";
        var ssspu_fadein = "<? echo(get_option('ssspu_fadein'));?>";
        var ssspu_fadeout = "<? echo(get_option('ssspu_fadeout'));?>";
        var ssspu_delay = "<? echo(get_option('ssspu_delay'));?>";
        var cookiename = ("<? echo(get_bloginfo('wpurl'));?>".replace(/[^A-Z0-9]/ig, '') + "popup");
		ssspu_run();
        </script>

(This version of the plugin will be/is released under GPL2)

Thank you very much for your time, answers and feedback!


Viewing all articles
Browse latest Browse all 8245

Trending Articles