{"id":43582,"date":"2019-02-13T03:01:46","date_gmt":"2019-02-12T17:01:46","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=43582"},"modified":"2019-02-12T18:25:26","modified_gmt":"2019-02-12T08:25:26","slug":"wordpress-plugin-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wordpress-plugin-primer-tutorial\/","title":{"rendered":"WordPress Plugin Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/wordpress_plugin_simple.gif\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"WordPress Plugin Primer Tutorial\" src=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/wordpress_plugin_simple.gif\" title=\"WordPress Plugin Primer Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">WordPress Plugin Primer Tutorial<\/p><\/div>\n<p>Normally we make changes to this TwentyTen themed WordPress blog by changing that theme&#8217;s wp-content\/themes\/twentyten\/header.php file.  But today we show you how to write the PHP code needed to write a <a target=_blank title='WordPress.org' href='http:\/\/www.wordpress.org'>WordPress.org<\/a> admin login <a target=_blank title='Plugin information from Wikipedia' href='https:\/\/en.wikipedia.org\/wiki\/Plug-in_(computing)'>plugin<\/a> to create a hyperlink to a Wikipedia page regarding any text you have highlighted on your WordPress admin area webpage.<\/p>\n<p>We thank &#8230;<\/p>\n<ul>\n<li><a target=_blank title='Codex' href='https:\/\/codex.wordpress.org\/'>WordPress Codex<\/a><\/li>\n<li><a target=_blank title='Writing a Plugin' href='https:\/\/codex.wordpress.org\/Writing_a_Plugin'>WordPress Codex &#8220;Writing a Plugin&#8221;<\/a><\/li>\n<li><a target=_blank title='Plugin API' href='https:\/\/codex.wordpress.org\/Plugin_API'>WordPress Codex &#8220;Plugin API&#8221;<\/a><\/li>\n<li><a target=_blank title='Hello Dolly plugin' href='https:\/\/wordpress.org\/plugins\/hello-dolly\/'>Hello Dolly plugin<\/a><\/li>\n<\/ul>\n<p> &#8230; and we think you should read &#8230;<\/p>\n<ul>\n<li><a target=_blank title='WordPress Codex Hooks' href='https:\/\/developer.wordpress.org\/reference\/hooks\/'>Hooks<\/a><\/li>\n<li><a target=_blank title='WordPress Codex Actions' href='https:\/\/codex.wordpress.org\/Glossary#Action'>Actions<\/a><\/li>\n<li><a target=_blank title='WordPress Codex Filters' href='https:\/\/codex.wordpress.org\/Glossary#Filter'>Filters<\/a><\/li>\n<li><a target=_blank title='WordPress Codex Pluggable Functions' href='https:\/\/codex.wordpress.org\/Plugin_API#Pluggable_Functions'>Pluggable Functions<\/a><\/li>\n<li><a target=_blank title='WordPress Codex Plugins directory' href='https:\/\/codex.wordpress.org\/Function_Reference\/plugin_dir_url'><b>Plugins directory<\/b><\/a><\/li>\n<\/ul>\n<p>For us, with our very simple <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-content\/plugins\/rjmprogramming-wikipedia-lookup.php_GETME\">rjmprogramming-wikipedia-lookup.php<\/a> plugin, we only needed the one piece of PHP to sit in the current WordPress <b>wp-content\/plugins<\/b> directory, and then immediately be accessible to the WordPress blog admin area\u2019s Plugins -&gt; Activate option &#8230;<\/p>\n<p><code><br \/>\n&lt;?php<br \/>\n\/**<br \/>\n * @package Rjmprogramming_Wikipedia_Lookup<br \/>\n * @version 1.6<br \/>\n *\/<br \/>\n\/*<br \/>\nPlugin Name: Rjmprogramming Wikipedia Lookup<br \/>\nDescription: Float a Wikipedia lookup link for highlighted text of an admin webpage.<br \/>\nAuthor: Robert James Metcalfe<br \/>\nVersion: 1.6<br \/>\nAuthor URI: http:\/\/www.rjmprogramming.com.au\/<br \/>\n*\/<br \/>\n<br \/>\n\/\/ This creates the Wikipedia lookup hyperlink<br \/>\nfunction rjmprogramming_wikipedia_lookup() {<br \/>\n\t$wikipedia_page = \"Wikipedia Main Page\";<br \/>\n\techo '&lt;a target=\"_blank\" title=\"Wikipedia lookup of ...\" onmouseover=\"var xsel=' .<br \/>\n\t  \"''\" . '; xsel=window.getSelection().toString(); if (xsel.length == 0) {' .<br \/>\n\t  ' xsel=document.selection.createRange().htmlText;' .<br \/>\n\t  ' } if (xsel.length != 0) { this.innerHTML=xsel; this.href=' . \"'\" . '\/\/wikipedia.org\/wiki\/' .<br \/>\n\t  \"'\" . ' + xsel.replace(\/\\ \/g,' . \"'\" . '_' . \"'\" . '); } \" ontouchstart=\"var xsel=' .<br \/>\n\t  '; xsel=window.getSelection().toString(); if (xsel.length == 0) {' .<br \/>\n\t  ' xsel=document.selection.createRange().htmlText; }' .<br \/>\n\t  ' if (xsel.length != 0) { this.innerHTML=xsel; this.href=' . \"'\" . '\/\/wikipedia.org\/wiki\/' . \"'\" .<br \/>\n\t  ' + xsel.replace(\/\\ \/g,' . \"'\" . '_' . \"'\" . '); } \" id=\"rjmprogramming_wikipedia_lookup\"' .<br \/>\n\t  ' href=\"\/\/wikipedia.org\/wiki\/Main_Page\"&gt;' . $wikipedia_page . '&lt;\/a&gt;';<br \/>\n}<br \/>\n<br \/>\n\/\/ Now we set that function up to execute when the admin_notices action is called<br \/>\nadd_action( 'admin_notices', 'rjmprogramming_wikipedia_lookup' );<br \/>\n<br \/>\n\/\/ We need some CSS to position the hyperlink<br \/>\nfunction rjmprogramming_wikipedia_css() {<br \/>\n\t\/\/ This makes sure that the positioning is also good for right-to-left languages<br \/>\n\t$x = is_rtl() ? 'left' : 'right';<br \/>\n<br \/>\n\techo \"<br \/>\n\t&lt;style type='text\/css'&gt;<br \/>\n\t#rjmprogramming_wikipedia_lookup {<br \/>\n\t\tfloat: $x;<br \/>\n\t\tpadding-$x: 15px;<br \/>\n\t\tpadding-top: 5px;<br \/>\n\t\tmargin: 0;<br \/>\n\t\tfont-size: 11px;<br \/>\n\t}<br \/>\n\t&lt;\/style&gt;<br \/>\n\t\";<br \/>\n}<br \/>\n<br \/>\nadd_action( 'admin_footer', 'rjmprogramming_wikipedia_css' );<br \/>\n<br \/>\n?&gt;<br \/>\n<\/code><\/p>\n<p>We hope this is of interest to you.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d43582' onclick='var dv=document.getElementById(\"d43582\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/plugin\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d43582' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Normally we make changes to this TwentyTen themed WordPress blog by changing that theme&#8217;s wp-content\/themes\/twentyten\/header.php file. But today we show you how to write the PHP code needed to write a WordPress.org admin login plugin to create a hyperlink to &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/wordpress-plugin-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,37],"tags":[151,1887,2827,2828,932,956,997,1319,1431,1456],"class_list":["post-43582","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-blog","tag-codex","tag-hook","tag-hyperlink","tag-php","tag-plugin","tag-programming","tag-tutorial","tag-wikipedia","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/43582"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=43582"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/43582\/revisions"}],"predecessor-version":[{"id":43587,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/43582\/revisions\/43587"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=43582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=43582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=43582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}