{"id":1772,"date":"2019-05-17T20:10:50","date_gmt":"2019-05-17T20:10:50","guid":{"rendered":"http:\/\/tutorialsclass.com\/?post_type=faq&#038;p=1772"},"modified":"2020-04-30T12:13:24","modified_gmt":"2020-04-30T12:13:24","slug":"create-wordpress-plugin-scratch","status":"publish","type":"faq","link":"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/","title":{"rendered":"How to create WordPress plugin from scratch?"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">How do WordPress plugins work?<\/h3>\n\n\n\n<p>A WordPress Plugin is a set of one or more functions, that specifies set of features at certain points using Plugin APIs Hooks.<br>Hooks allow your plugin to call functions at specific times to alter or enhance the existing functionality.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">There are two kinds of hooks<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Actions:<\/strong> In WordPress; an Action is a PHP function that is executed at specific points throughout the WordPress Core. For example: A developer may want to add code to the footer of a Theme. This could be accomplished by writing new function, then Hooking it to the wp_footer Action<\/li><li><strong>Filters:<\/strong> In WordPress, a Filter is a function that is associated with an existing Action by specifying any existing Hook. Filters usually come with content already associated with them. They allow you to add or remove code from existing Actions.<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Creating the Plugin folder with unique name<\/h3>\n\n\n\n<p>In this folder, we will create two files:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>readme.txt<\/li><li>wp-plugin-name.php<\/li><\/ul>\n\n\n\n<p>The readme file is required if you want to host your plugin on the WordPress.org Plugin Directory.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">File Headers<\/h3>\n\n\n\n<p>Now it&#8217;s time to put some information into your main Plugin PHP file. At a minimum, a header can contain just a Plugin Name, but several pieces should be included:<\/p>\n\n\n\n<p>It is recommended that you prevent direct access to this file by including this line after your file headers:<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Enqueueing JavaScript and CSS files<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Make data available to JavaScript<\/h4>\n\n\n\n<p>Now we have some settings stored, we need to make them available to the JavaScript. &#8220;wp localize script&#8221; can be used to make any data available to your script that you can normally only get from the server-side of WordPress.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Activation and Deactivation hooks<\/h4>\n\n\n\n<p>register_activation_hook and register_deactivation_hook, run their callbacks on activation and deactivation of the plugin and perform the required functionality like adding or erasing the plugin&#8217;s metadata.<\/p>\n\n\n\n<p>Full Example: <a href=\"https:\/\/gist.github.com\/deepak-rajpal\/f8fb397d16bb161b3ba1\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/gist.github.com\/deepak-rajpal\/f8fb397d16bb161b3ba1<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Why Do We Use Activation\/Deactivation Hooks<\/h4>\n\n\n\n<p>We can create basic plugins without considering activation and deactivation functions. But advanced plugin will require these functions to provide additional features:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Create custom database tables on activation to store data and remove tables on deactivation.<\/li><li>Create custom options for plugins and activation and reset in deactivation.<\/li><li>Validate other dependent plugins on activation.<\/li><li>Any other necessary task you need to execute inactivation.<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>How do WordPress plugins work? A WordPress Plugin is a set of one or more functions, that specifies set of features at certain points using Plugin APIs Hooks.Hooks allow your plugin to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"faq_type":[118],"keywords":[],"class_list":["post-1772","faq","type-faq","status-publish","hentry","faq_type-all-wordpress-interview-questions-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to create WordPress plugin from scratch? - FAQs - Tutorials Class<\/title>\n<meta name=\"description\" content=\"How to create WordPress plugin from scratch? - Interview Questions with Answer\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create WordPress plugin from scratch? - FAQs - Tutorials Class\" \/>\n<meta property=\"og:description\" content=\"How to create WordPress plugin from scratch? - Interview Questions with Answer\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorials Class\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/tutorialsclass\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-30T12:13:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/07\/tutorials-class-logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@TutorialsClass\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/\",\"url\":\"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/\",\"name\":\"How to create WordPress plugin from scratch? - FAQs - Tutorials Class\",\"isPartOf\":{\"@id\":\"https:\/\/tutorialsclass.com\/#website\"},\"datePublished\":\"2019-05-17T20:10:50+00:00\",\"dateModified\":\"2020-04-30T12:13:24+00:00\",\"description\":\"How to create WordPress plugin from scratch? - Interview Questions with Answer\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorialsclass.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"FAQs\",\"item\":\"https:\/\/tutorialsclass.com\/faq\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"WordPress Interview Questions\",\"item\":\"https:\/\/tutorialsclass.com\/faqs\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"WordPress Interview Questions &amp; Answers\",\"item\":\"https:\/\/tutorialsclass.com\/faqs\/wordpress\/all-wordpress-interview-questions-answers\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to create WordPress plugin from scratch?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorialsclass.com\/#website\",\"url\":\"https:\/\/tutorialsclass.com\/\",\"name\":\"Tutorials Class\",\"description\":\"Online Tutorials for Beginners\",\"publisher\":{\"@id\":\"https:\/\/tutorialsclass.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorialsclass.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/tutorialsclass.com\/#organization\",\"name\":\"Tutorials Class\",\"url\":\"https:\/\/tutorialsclass.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorialsclass.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/05\/tutorials-class-logo.png\",\"contentUrl\":\"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/05\/tutorials-class-logo.png\",\"width\":442,\"height\":94,\"caption\":\"Tutorials Class\"},\"image\":{\"@id\":\"https:\/\/tutorialsclass.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/tutorialsclass\",\"https:\/\/x.com\/TutorialsClass\",\"https:\/\/in.pinterest.com\/merientinfotech\/boards\/\",\"https:\/\/www.youtube.com\/channel\/UCzbpQXlqec-bQf1_kwrTuoA\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create WordPress plugin from scratch? - FAQs - Tutorials Class","description":"How to create WordPress plugin from scratch? - Interview Questions with Answer","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:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/","og_locale":"en_US","og_type":"article","og_title":"How to create WordPress plugin from scratch? - FAQs - Tutorials Class","og_description":"How to create WordPress plugin from scratch? - Interview Questions with Answer","og_url":"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/","og_site_name":"Tutorials Class","article_publisher":"https:\/\/www.facebook.com\/tutorialsclass","article_modified_time":"2020-04-30T12:13:24+00:00","og_image":[{"width":600,"height":600,"url":"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/07\/tutorials-class-logo.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@TutorialsClass","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/","url":"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/","name":"How to create WordPress plugin from scratch? - FAQs - Tutorials Class","isPartOf":{"@id":"https:\/\/tutorialsclass.com\/#website"},"datePublished":"2019-05-17T20:10:50+00:00","dateModified":"2020-04-30T12:13:24+00:00","description":"How to create WordPress plugin from scratch? - Interview Questions with Answer","breadcrumb":{"@id":"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/tutorialsclass.com\/faq\/create-wordpress-plugin-scratch\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorialsclass.com\/"},{"@type":"ListItem","position":2,"name":"FAQs","item":"https:\/\/tutorialsclass.com\/faq\/"},{"@type":"ListItem","position":3,"name":"WordPress Interview Questions","item":"https:\/\/tutorialsclass.com\/faqs\/wordpress\/"},{"@type":"ListItem","position":4,"name":"WordPress Interview Questions &amp; Answers","item":"https:\/\/tutorialsclass.com\/faqs\/wordpress\/all-wordpress-interview-questions-answers\/"},{"@type":"ListItem","position":5,"name":"How to create WordPress plugin from scratch?"}]},{"@type":"WebSite","@id":"https:\/\/tutorialsclass.com\/#website","url":"https:\/\/tutorialsclass.com\/","name":"Tutorials Class","description":"Online Tutorials for Beginners","publisher":{"@id":"https:\/\/tutorialsclass.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorialsclass.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/tutorialsclass.com\/#organization","name":"Tutorials Class","url":"https:\/\/tutorialsclass.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorialsclass.com\/#\/schema\/logo\/image\/","url":"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/05\/tutorials-class-logo.png","contentUrl":"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/05\/tutorials-class-logo.png","width":442,"height":94,"caption":"Tutorials Class"},"image":{"@id":"https:\/\/tutorialsclass.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/tutorialsclass","https:\/\/x.com\/TutorialsClass","https:\/\/in.pinterest.com\/merientinfotech\/boards\/","https:\/\/www.youtube.com\/channel\/UCzbpQXlqec-bQf1_kwrTuoA"]}]}},"_links":{"self":[{"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/faq\/1772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/faq"}],"about":[{"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/types\/faq"}],"author":[{"embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/comments?post=1772"}],"version-history":[{"count":3,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/faq\/1772\/revisions"}],"predecessor-version":[{"id":5923,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/faq\/1772\/revisions\/5923"}],"wp:attachment":[{"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/media?parent=1772"}],"wp:term":[{"taxonomy":"faq_type","embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/faq_type?post=1772"},{"taxonomy":"keywords","embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/keywords?post=1772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}