{"id":13148,"date":"2022-12-05T20:54:29","date_gmt":"2022-12-05T18:54:29","guid":{"rendered":"https:\/\/user-meta.com\/?p=13148"},"modified":"2023-03-22T15:59:38","modified_gmt":"2023-03-22T13:59:38","slug":"create-wordpress-plugin","status":"publish","type":"post","link":"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/","title":{"rendered":"How to Create a WordPress Plugin"},"content":{"rendered":"<p>If you want to create a WordPress plugin but don&#8217;t know where to start, this guide is for you! We will walk you through the basics of plugin development.<\/p>\n<p>A plugin generally consists 0of PHP code, JavaScript code, CSS stylesheets, and template files. The exact combination will depend on the particular plugin. Some plugins are small, with just one PHP file. While others are much larger, with multiple files of each type.<\/p>\n<h4><strong>Methods to create a WordPress plugin:<\/strong><\/h4>\n<p><strong><u>Step 1: Choose a Plugin Name<\/u><\/strong><\/p>\n<p>The first step in developing a WordPress plugin is to give an official name.\u00a0 However, the name should be relevant to the purpose and unique from other plugins. Checking the WordPress Plugin Directory and performing a few Google searches can help to determine if your desired name is already in use.<\/p>\n<p><strong><u>Step 2: Create Your Plugin Folder and PHP File<\/u><\/strong><\/p>\n<p>To create a plugin, navigate to the wp-content\/plugins folder and create a new folder. Inside this new folder, create a file named after your plugin. The important thing is the .php extension, but you can name it according to your want. Open the file in a text editor and add a plugin header to your plugin file. This comment block tells WordPress the name of your plugin, version, website, and plugin author name.<\/p>\n<blockquote><p>&lt;?php<br \/>\n\/**<br \/>\n* Plugin Name: test-plugin<br \/>\n* Plugin URI: https:\/\/www.your-site.com\/<br \/>\n* Description: Test.<br \/>\n* Version: 0.1<br \/>\n* Author: your-name<br \/>\n* Author URI: https:\/\/www.your-site.com\/<br \/>\n**\/<\/p><\/blockquote>\n<p>After that, Go back to WordPress Dashboard. In the Plugin option, you will see the new plugin.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-13149 \" src=\"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin.png\" alt=\"\" width=\"751\" height=\"138\" srcset=\"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin.png 1012w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-300x55.png 300w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-150x28.png 150w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-768x141.png 768w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-125x23.png 125w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-75x14.png 75w\" sizes=\"auto, (max-width: 751px) 100vw, 751px\" \/><\/p>\n<p>However, this plugin won\u2019t do anything yet if you were to activate it.<\/p>\n<p><strong><u>Step 3: Add Code to Your Plugin<\/u><\/strong><\/p>\n<p><span data-preserver-spaces=\"true\">When you add code to your plugin, it might not do anything until you trigger it somehow. There are a few methods of activating your code or bringing in code from WordPress.<\/span><\/p>\n<ul>\n<li><span data-preserver-spaces=\"true\">Functions<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Action and filter hooks<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Classes<\/span><\/li>\n<\/ul>\n<p><strong><span data-preserver-spaces=\"true\">Functions:\u00a0<\/span><\/strong><span data-preserver-spaces=\"true\">Functions are the building blocks of WordPress code. They make it easy to start writing your plugins and help you code more quickly. You will find plenty of functions in your theme files too.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">Each function has its name, followed by braces and the code inside those braces. Your plugin&#8217;s code won&#8217;t run unless you call the function somehow. The simplest way to do that is by directly calling the function somewhere else in your code.<\/span><\/p>\n<p><strong><span data-preserver-spaces=\"true\">Action and filter hooks:\u00a0\u00a0<\/span><\/strong><span data-preserver-spaces=\"true\">Hooks are like bridges that allow plugins to access and interact with the existing code of WordPress. Using them, developers can add or change functionality in their plugins without directly editing the core code. That makes it possible to extend the functionality of WordPress without compromising the stability of the site.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">There are two types of hooks that you will need to consider when creating your plugin:<\/span><\/p>\n<p><a href=\"https:\/\/developer.wordpress.org\/plugins\/hooks\/actions\/\"><span data-preserver-spaces=\"true\">Actions<\/span><\/a><span data-preserver-spaces=\"true\">: These add or change WordPress functionality and make up the majority of hooks.\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/developer.wordpress.org\/plugins\/hooks\/filters\/\"><span data-preserver-spaces=\"true\">Filters<\/span><\/a><span data-preserver-spaces=\"true\">: These are used to modify the functionality of actions.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">To code your plugin, familiarize yourself with hooks and how they work. Fortunately, the\u00a0<a href=\"https:\/\/developer.wordpress.org\/plugins\/\">Plugin Developer Handbook<\/a>\u00a0can help you get started. Besides, <a href=\"https:\/\/user-meta.com\/\">User Meta<\/a> has their\u00a0<a href=\"https:\/\/developer-docs.user-meta.com\/\">Developer Handbook<\/a>\u00a0containing a list of actions and filters with examples.\u00a0<\/span><\/p>\n<p><strong><span data-preserver-spaces=\"true\">add_action syntax is like this:<\/span><\/strong><\/p>\n<blockquote><p><span data-preserver-spaces=\"true\">add_action(&#8220;custom_action_name&#8221;, &#8220;custom_function_name&#8221;, priority, number_of_acceptable_arguments);<\/span><\/p><\/blockquote>\n<p><strong><span data-preserver-spaces=\"true\">add_filter syntax is like this:<\/span><\/strong><\/p>\n<blockquote><p><span data-preserver-spaces=\"true\">add_filter(&#8216;filter_hook_name&#8217;,&#8217;custom_function_name&#8217;,priority);<\/span><\/p><\/blockquote>\n<p><strong><u>Step 4: Test Your Plugin<\/u><\/strong><\/p>\n<p>As you continue developing your plugin, save your work regularly and test your changes on a staging site. Also, keep an eye out for any security issues that may arise. Once you&#8217;re satisfied with your plugin, try it on a live site.<\/p>\n<p>Make sure to thoroughly test your plugin before doing so. It&#8217;s also a good idea to back up your live site before testing the plugin. If you&#8217;re happy with the performance of your plugin, offer it to other developers for feedback or testing purposes.<\/p>\n<p><strong><u>Step 5: Distribute Your Plugin<\/u><\/strong><\/p>\n<p>Your plugin is now ready to be reviewed by WordPress.org&#8217;s plugins team. To submit your plugin, you will need a free WordPress.org account. Visit the Add Your Plugin page and log in.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-13150 \" src=\"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-1-1024x475.png\" alt=\"\" width=\"575\" height=\"267\" srcset=\"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-1-1024x475.png 1024w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-1-300x139.png 300w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-1-150x70.png 150w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-1-768x356.png 768w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-1-125x58.png 125w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-1-75x35.png 75w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-1.png 1252w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/>Once logged in, you&#8217;ll be able to upload and submit your plugin for review. Simply click on the Select File button, select your plugin&#8217;s zip file, and then click on the Upload button.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-13151 \" src=\"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin.jpg\" alt=\"\" width=\"566\" height=\"361\" srcset=\"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin.jpg 898w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-300x191.jpg 300w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-150x96.jpg 150w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-768x490.jpg 768w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-125x80.jpg 125w, https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/create-plugin-75x48.jpg 75w\" sizes=\"auto, (max-width: 566px) 100vw, 566px\" \/><\/p>\n<p>The WordPress.org plugin review team will then take a look at your plugin code for common errors and security checks. Once approved, you&#8217;ll receive an email from the plugins team.<\/p>\n<p>Besides uploading your plugin to the WordPress directory, you could create a website for it. You could also include documentation, tutorials, and marketing pieces of information.<\/p>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-13148\" data-postid=\"13148\" class=\"themify_builder_content themify_builder_content-13148 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>If you want to create a WordPress plugin but don&#8217;t know where to start, this guide is for you! We will walk you through the basics of plugin development. A plugin generally consists 0of PHP code, JavaScript code, CSS stylesheets, &hellip; <a href=\"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":8647,"featured_media":13164,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[716],"tags":[1250,1052,1251],"class_list":["post-13148","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-create-wordpress-plugin","tag-wordpress","tag-wordpress-plugin-development","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Create a WordPress Plugin | User Meta Pro<\/title>\n<meta name=\"description\" content=\"Create a WordPress plugin by only five simple steps. We will walk you through the basics of plugin development.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create a WordPress Plugin | User Meta Pro\" \/>\n<meta property=\"og:description\" content=\"Create a WordPress plugin by only five simple steps. We will walk you through the basics of plugin development.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/\" \/>\n<meta property=\"og:site_name\" content=\"User Meta Pro\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/UserMetaPro\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-05T18:54:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-22T13:59:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/how-to-create-worpress-plugin.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"atira\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"atira\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/\",\"url\":\"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/\",\"name\":\"How to Create a WordPress Plugin | User Meta Pro\",\"isPartOf\":{\"@id\":\"https:\/\/user-meta.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/how-to-create-worpress-plugin.png\",\"datePublished\":\"2022-12-05T18:54:29+00:00\",\"dateModified\":\"2023-03-22T13:59:38+00:00\",\"author\":{\"@id\":\"https:\/\/user-meta.com\/#\/schema\/person\/15b411af4987479ab8b05db37a7c8ce0\"},\"description\":\"Create a WordPress plugin by only five simple steps. We will walk you through the basics of plugin development.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/#primaryimage\",\"url\":\"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/how-to-create-worpress-plugin.png\",\"contentUrl\":\"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/how-to-create-worpress-plugin.png\",\"width\":1280,\"height\":720,\"caption\":\"how-to-create-worpress-plugin\"},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/user-meta.com\/#website\",\"url\":\"https:\/\/user-meta.com\/\",\"name\":\"User Meta Pro\",\"description\":\"WordPress user management plugin\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/user-meta.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/user-meta.com\/#\/schema\/person\/15b411af4987479ab8b05db37a7c8ce0\",\"name\":\"atira\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/user-meta.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5a7533a99c6e146426ca91e3de638e2d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5a7533a99c6e146426ca91e3de638e2d?s=96&d=mm&r=g\",\"caption\":\"atira\"},\"url\":\"https:\/\/user-meta.com\/author\/atira\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Create a WordPress Plugin | User Meta Pro","description":"Create a WordPress plugin by only five simple steps. We will walk you through the basics of plugin development.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/","og_locale":"en_US","og_type":"article","og_title":"How to Create a WordPress Plugin | User Meta Pro","og_description":"Create a WordPress plugin by only five simple steps. We will walk you through the basics of plugin development.","og_url":"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/","og_site_name":"User Meta Pro","article_publisher":"https:\/\/www.facebook.com\/UserMetaPro","article_published_time":"2022-12-05T18:54:29+00:00","article_modified_time":"2023-03-22T13:59:38+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/how-to-create-worpress-plugin.png","type":"image\/png"}],"author":"atira","twitter_misc":{"Written by":"atira","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/","url":"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/","name":"How to Create a WordPress Plugin | User Meta Pro","isPartOf":{"@id":"https:\/\/user-meta.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/#primaryimage"},"image":{"@id":"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/#primaryimage"},"thumbnailUrl":"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/how-to-create-worpress-plugin.png","datePublished":"2022-12-05T18:54:29+00:00","dateModified":"2023-03-22T13:59:38+00:00","author":{"@id":"https:\/\/user-meta.com\/#\/schema\/person\/15b411af4987479ab8b05db37a7c8ce0"},"description":"Create a WordPress plugin by only five simple steps. We will walk you through the basics of plugin development.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/user-meta.com\/blog\/create-wordpress-plugin\/#primaryimage","url":"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/how-to-create-worpress-plugin.png","contentUrl":"https:\/\/user-meta.com\/wp-content\/blogs.dir\/2\/files\/2022\/12\/how-to-create-worpress-plugin.png","width":1280,"height":720,"caption":"how-to-create-worpress-plugin"},{"@type":"WebSite","@id":"https:\/\/user-meta.com\/#website","url":"https:\/\/user-meta.com\/","name":"User Meta Pro","description":"WordPress user management plugin","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/user-meta.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/user-meta.com\/#\/schema\/person\/15b411af4987479ab8b05db37a7c8ce0","name":"atira","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/user-meta.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5a7533a99c6e146426ca91e3de638e2d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5a7533a99c6e146426ca91e3de638e2d?s=96&d=mm&r=g","caption":"atira"},"url":"https:\/\/user-meta.com\/author\/atira\/"}]}},"_links":{"self":[{"href":"https:\/\/user-meta.com\/wp-json\/wp\/v2\/posts\/13148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/user-meta.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/user-meta.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/user-meta.com\/wp-json\/wp\/v2\/users\/8647"}],"replies":[{"embeddable":true,"href":"https:\/\/user-meta.com\/wp-json\/wp\/v2\/comments?post=13148"}],"version-history":[{"count":15,"href":"https:\/\/user-meta.com\/wp-json\/wp\/v2\/posts\/13148\/revisions"}],"predecessor-version":[{"id":13155,"href":"https:\/\/user-meta.com\/wp-json\/wp\/v2\/posts\/13148\/revisions\/13155"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/user-meta.com\/wp-json\/wp\/v2\/media\/13164"}],"wp:attachment":[{"href":"https:\/\/user-meta.com\/wp-json\/wp\/v2\/media?parent=13148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/user-meta.com\/wp-json\/wp\/v2\/categories?post=13148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/user-meta.com\/wp-json\/wp\/v2\/tags?post=13148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}