{"id":698,"date":"2020-11-04T02:02:59","date_gmt":"2020-11-04T02:02:59","guid":{"rendered":"https:\/\/s-oneill.com\/sov02\/?page_id=698"},"modified":"2020-11-04T02:06:22","modified_gmt":"2020-11-04T02:06:22","slug":"wordpress101","status":"publish","type":"page","link":"https:\/\/s-oneill.com\/sov02\/wordpress101\/","title":{"rendered":"WordPress101"},"content":{"rendered":"\n<p class=\"so-pageIntroP\">\n  Basic WP plugin steps\n<\/p>\n\n<div id=\"accordion\" class=\"so-accordion\">\n\n<!-- step 1 -->\n  <h3>Step 1 &#8211; Create .php file<\/h3>\n   <div style=\"height:auto; padding-bottom: 20px; margin-bottom: 10px;\">\n\n    <p>Create an appropriately named folder and php file<br>\n      &nbsp;&nbsp;&nbsp;\/wp-content\/plugins\/pluginname\/pluginname.php\n    <\/p>\n    <p> Begin the file with an opening &lt;?php tag followed by the standard comment for WP plugins\n    <\/p>\n<pre>  \/ *\n  Plugin Name: Plugin Name Script\n  Plugin URI: https:\/\/s-oneill.com\/\n  Description: Load scripts for Plugin Name page\n  Version: 1.0\n  Author: Sean ONeill\n  Author URI: https:\/\/s-oneill.com\n  License: GPLv2 or later\n  * \/\n<\/pre>\n    <p>\n      The Plugin Name will appear in the Admin Plugins area for you to activate when ready.\n    <\/p>\n\n  <\/div>\n\n\n<!-- step 2 -->\n  <h3>Step 2 &#8211; Add plugin function(s) and action(s) <\/h3>\n\n   <div style=\"height:auto; padding-bottom: 20px; margin-bottom: 10px;\">\n    <p>\n      Create php function(s) to carry out the purpose of the plugin. \n    <br>\n      Note: php functions must be called (or &#8220;hook&#8221;ed) into some action in  the WP process using a function:  <br>\n    <\/p>\n\n\n<pre>  add_action( 'init', 'add_Cookie' )\n\n  function add_Cookie() {\n    setcookie(\"last_visit_time\", date(\"r\"), time()+60*60*24*30, \"\/\");\n  }\n<\/pre>\n\n    <p>\n      The <strong>add action<\/strong> function has two required parameters,  <br>\n      1) Action name (there are many different WP actions )  <br>\n      2) Name of your function.  <br>\n      \n    <\/p>\n\n<pre>  add_action( \n    string $tag, \/\/ req. string - the action name\n    callable $function_to_add, \/\/ req. string - the function to fire \n    int $priority = 10,  \/\/ opt. int. - priority\/call order, 1 called 1st def 10\n    int $accepted_args = 1 \/\/ opt. int. - # of args fn accepts, default is 1\n  )\n<\/pre>\n    <p>\n      \n      (The priority and accepted_args parameters are optional ) <br> <br>\n    <\/p>\n\n  <\/div>\n\n\n<!-- step 3 -->\n  <h3>Step 3 &#8211; Add JS <\/h3>\n\n  <div style=\"height:auto; padding-bottom: 20px; margin-bottom: 10px;\">\n    <p>\n      Any JS needed in the plugin must be included using: \n      <br>\n      &nbsp;&nbsp;&nbsp;<strong>wp_enqueue_script()<\/strong>\n    <\/p>\n<pre>  define( 'MYSCRIPT_VERSION', 1);\n  function our_function_name($hook) {\n\n    wp_enqueue_script( \n      'my-plugin-script-name', \/\/ name of script\n      plugins_url('js\/my-plugin-script-name.js', __FILE__ ), \/\/ location\n      array( 'jquery' ), \/\/ dependencies\n      MYSCRIPT_VERSION, \/\/ version (declared in a var above)\n      true \/\/ include script in footer (false will include in header)\n    );\n  }\n  add_action( 'admin_enqueue_scripts', 'our_function_name' )\n<\/pre>\n    <p>\n      Note: the JS file can be in a \/js folder in your plugin, or external. Be sure to use the proper location in the 2nd param.\n      <br>\n      Also, __FILE__ tells the plugins URL function that we&#8217;re referencing a file in this plugin\n    <\/p>\n\n<\/div>\n\n\n<!-- step 4 -->\n  <h3>Step 4 &#8211; Restrict plugin to specific pages<\/h3>\n   <div style=\"height:auto; padding-bottom: 20px; margin-bottom: 10px;\">\n    <p>\n      Precede the wp_enqueue_script() function with an if() to restrict the script to specific pages\n    <\/p>\n<pre>  function our_function_name_w_enqueue_script($hook) {\n\n      if ( !is_page( 'about') )\n      return;\n\n     wp_enqueue_script( \n      'my-plugin-script-name', \/\/ name of script\n      plugins_url('js\/my-plugin-script-name.js', __FILE__ ), \/\/ location\n      array( 'jquery' ), \/\/ dependencies\n      MYSCRIPT_VERSION, \/\/ version (declared in a var above)\n      true \/\/ include script in footer (false will include in header)\n    );\n  }\n  add_action( 'admin_enqueue_scripts', 'our_function_name' )\n}\n add_action( 'admin_enqueue_scripts', 'our_function_name_w_enqueue_script' )\n<\/pre>\n  <\/div>\n\n\n\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Basic WP plugin steps Step 1 &#8211; Create .php file Create an appropriately named folder and php file &nbsp;&nbsp;&nbsp;\/wp-content\/plugins\/pluginname\/pluginname.php Begin the file with an opening &lt;?php tag followed by the standard comment for WP plugins \/ * Plugin Name: Plugin Name Script Plugin URI: https:\/\/s-oneill.com\/ Description: Load scripts for Plugin Name page Version: 1.0 Author: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"class_list":["post-698","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>WordPress101 - s-oneill.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/s-oneill.com\/sov02\/wordpress101\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WordPress101 - s-oneill.com\" \/>\n<meta property=\"og:description\" content=\"Basic WP plugin steps Step 1 &#8211; Create .php file Create an appropriately named folder and php file &nbsp;&nbsp;&nbsp;\/wp-content\/plugins\/pluginname\/pluginname.php Begin the file with an opening &lt;?php tag followed by the standard comment for WP plugins \/ * Plugin Name: Plugin Name Script Plugin URI: https:\/\/s-oneill.com\/ Description: Load scripts for Plugin Name page Version: 1.0 Author: [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/s-oneill.com\/sov02\/wordpress101\/\" \/>\n<meta property=\"og:site_name\" content=\"s-oneill.com\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-04T02:06:22+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\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:\/\/s-oneill.com\/sov02\/wordpress101\/\",\"url\":\"https:\/\/s-oneill.com\/sov02\/wordpress101\/\",\"name\":\"WordPress101 - s-oneill.com\",\"isPartOf\":{\"@id\":\"https:\/\/s-oneill.com\/sov02\/#website\"},\"datePublished\":\"2020-11-04T02:02:59+00:00\",\"dateModified\":\"2020-11-04T02:06:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/s-oneill.com\/sov02\/wordpress101\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/s-oneill.com\/sov02\/wordpress101\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/s-oneill.com\/sov02\/wordpress101\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/s-oneill.com\/sov02\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WordPress101\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/s-oneill.com\/sov02\/#website\",\"url\":\"https:\/\/s-oneill.com\/sov02\/\",\"name\":\"s-oneill.com\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/s-oneill.com\/sov02\/#\/schema\/person\/a9217b5797251a243dfd504d7ad7d00a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/s-oneill.com\/sov02\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/s-oneill.com\/sov02\/#\/schema\/person\/a9217b5797251a243dfd504d7ad7d00a\",\"name\":\"sean o\",\"logo\":{\"@id\":\"https:\/\/s-oneill.com\/sov02\/#\/schema\/person\/image\/\"},\"description\":\"Web dev over 15 years.\",\"sameAs\":[\"http:\/\/s-oneill.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WordPress101 - s-oneill.com","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:\/\/s-oneill.com\/sov02\/wordpress101\/","og_locale":"en_US","og_type":"article","og_title":"WordPress101 - s-oneill.com","og_description":"Basic WP plugin steps Step 1 &#8211; Create .php file Create an appropriately named folder and php file &nbsp;&nbsp;&nbsp;\/wp-content\/plugins\/pluginname\/pluginname.php Begin the file with an opening &lt;?php tag followed by the standard comment for WP plugins \/ * Plugin Name: Plugin Name Script Plugin URI: https:\/\/s-oneill.com\/ Description: Load scripts for Plugin Name page Version: 1.0 Author: [&hellip;]","og_url":"https:\/\/s-oneill.com\/sov02\/wordpress101\/","og_site_name":"s-oneill.com","article_modified_time":"2020-11-04T02:06:22+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/s-oneill.com\/sov02\/wordpress101\/","url":"https:\/\/s-oneill.com\/sov02\/wordpress101\/","name":"WordPress101 - s-oneill.com","isPartOf":{"@id":"https:\/\/s-oneill.com\/sov02\/#website"},"datePublished":"2020-11-04T02:02:59+00:00","dateModified":"2020-11-04T02:06:22+00:00","breadcrumb":{"@id":"https:\/\/s-oneill.com\/sov02\/wordpress101\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/s-oneill.com\/sov02\/wordpress101\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/s-oneill.com\/sov02\/wordpress101\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/s-oneill.com\/sov02\/"},{"@type":"ListItem","position":2,"name":"WordPress101"}]},{"@type":"WebSite","@id":"https:\/\/s-oneill.com\/sov02\/#website","url":"https:\/\/s-oneill.com\/sov02\/","name":"s-oneill.com","description":"","publisher":{"@id":"https:\/\/s-oneill.com\/sov02\/#\/schema\/person\/a9217b5797251a243dfd504d7ad7d00a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/s-oneill.com\/sov02\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/s-oneill.com\/sov02\/#\/schema\/person\/a9217b5797251a243dfd504d7ad7d00a","name":"sean o","logo":{"@id":"https:\/\/s-oneill.com\/sov02\/#\/schema\/person\/image\/"},"description":"Web dev over 15 years.","sameAs":["http:\/\/s-oneill.com"]}]}},"_links":{"self":[{"href":"https:\/\/s-oneill.com\/sov02\/wp-json\/wp\/v2\/pages\/698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/s-oneill.com\/sov02\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/s-oneill.com\/sov02\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/s-oneill.com\/sov02\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/s-oneill.com\/sov02\/wp-json\/wp\/v2\/comments?post=698"}],"version-history":[{"count":4,"href":"https:\/\/s-oneill.com\/sov02\/wp-json\/wp\/v2\/pages\/698\/revisions"}],"predecessor-version":[{"id":702,"href":"https:\/\/s-oneill.com\/sov02\/wp-json\/wp\/v2\/pages\/698\/revisions\/702"}],"wp:attachment":[{"href":"https:\/\/s-oneill.com\/sov02\/wp-json\/wp\/v2\/media?parent=698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}