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

Structure of a WordPress plugin #222

Open
szepeviktor opened this issue Dec 9, 2019 · 1 comment
Open

Structure of a WordPress plugin #222

szepeviktor opened this issue Dec 9, 2019 · 1 comment

Comments

@szepeviktor
Copy link

szepeviktor commented Dec 9, 2019

While trying to run static analysis on OneSignal-WordPress-Plugin I've faced the structure of the plugin.

Please consider having clean class and function files.

  • /inc/class-$CLASSNAME.php (only 1 class, no instantiation, no add_action)
  • /inc/class-$CLASSNAME.php (only 1 class, no instantiation, no add_action)
  • /inc/class-$CLASSNAME.php (only 1 class, no instantiation, no add_action)
  • /inc/helpers.php <-- all - really all - functions here (only function definitions, no add_action)
  • global function names like load_javascript name conflict with other plugins/WordPress core, so have a unique onesignal_ prefix in all global names
  • if you have a tiny code to hook use an anonymous function
add_action(
	'admin_enqueue_scripts',
	function () {
		global $post;
 	    if ( ! $post ) {
			return;
    	}
       	wp_register_script('notice_script', plugins_url('notice.js', __FILE__), array('jquery'), '1.1', true);
        wp_enqueue_script('notice_script');
        wp_localize_script('notice_script', 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php'), 'post_id' => $post->ID))
	},
	10,
	0
);
@szepeviktor szepeviktor changed the title Structure a WordPress plugin Structure of a WordPress plugin Dec 9, 2019
@szepeviktor
Copy link
Author

szepeviktor commented Sep 17, 2020

The dream main file 💭 looks like this.
https://github.com/kingkero/wordpress-demoplugin/blob/master/wordpress-demoplugin.php

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

No branches or pull requests

2 participants