Programming is like sex: One mistake and you have to support it for the rest of your life.
WORDPRESS: Get your plugin version number 'n things
A quick and dirty "get plugin version number" example, borrowed from these guys: https://wordpress.stackexchange.com/questions/18268/i-want-to-get-a-plugin-version-number-dynamically
A method like this will always be available. Unlike the admin only get_plugin_data() (https://codex.wordpress.org/Function_Reference/get_plugin_data)
function get_fi_mi_plugin_version(){
if(preg_match('/version:[\s\t]+?([0-9.]+)/i',file_get_contents( __FILE__ ), $v)){
return $v[1];
}
return "";
}
Naturally, your regex '/version:[\s\t]+?([0-9.]+)/i' may vary. Depends on how your header comments are laid out. I typically do this:
/*
Plugin Name: WP Plugin
Plugin URI: somewhere.com
Description: Something something plugin header
Version: 6.6.6
Author: some idiot
Author URI: somewhere.com
License: Creative Commons 'n things
*/
WORDPRESS, inject custom-fields into a custom HTML widget from a plugin
Though recommended, time and time again. I did not want to register a new widget, or muck about with a child-theme. Just want to inject some data from a posts custom-field into any custom HTML widget I wanted. I know, it would have been easier with a javascript request followed by an append, but I have this little plugin that I toy with you see, and would like to implement that ability there.
Could not find what I was looking for, when hunting for examples. Perhaps not asking the right questions, the likely reason, since my Wordpress-fu leaves a lot to be desired. Eventually came up with the following.
Embed an element in the custom html widget using your preferred identifier. In my case:
<span id="my-custom-post-field-1"></span>
Add a new filter to your plugins library, in my case it's a class:
add_filter('widget_text', array($this,'mycustompostthing'),10,3);
Add a new function to check the text for that identifier, then inject at will.
function mycustompostthing( $text,$inst,$args ) {
global $post;
if( strpos($text, 'my-custom-post-field-1')){
$upsell = $this->get_upsell ( $post, 'my-custom-post-field-1' );
if($upsell){
$text = $upsell .'<div class="newline"></div>'. $text;
}
}
return $text;
}
And that's it. Not the best solution, but gets the job done.
Dump located here: https://github.com/dreaddymck/dump/blob/master/wordpress-inject-custom-fields-example
Netplan - Dafuq is that?
Nothing like a side mission, suddenly becoming a requirement.
Well that's what happened. You see I woke up ready fix a stupid bug in one of my shitty apps. I had a strategy in place, I always do. Linux had other plans, a thing interestingly enough called a Netplan ( https://netplan.io/ )
After a scheduled power outage, machines were rebooted, some did not fare well, background updates had made changes, walked away and left a few challenges.
One machine, my primary boss battle had the following problem.
As for the other machine, the one thing I worried least about stopped behaving as it should, damn thing would not remember the network settings. The old school solution is to tell the Network Managers to suck it and edit /etc/network/interfaces directly, but I had spent some time playing with the Network Manager Command Line tool and figured, what the hell, let's try that.
Then I see this Netplan thing sitting in my wifi list. I don't have an access point called Netplan. My neighbors don't have one either, yet this machine was connected to it.
"Dafuq is a Netplan?" I asked, don't recall seeing this before, then did some reading.
"Fine!" I thought, "I'll try to use this instead"
It worked. Followed the instructions provided by this blog and fixed it. I have yet to understand Netplans' relationship with Network Manager or the reason for the failure.
Netplan setup is not bad at all and I like it. Just resent having to travel that road at such an impromptu moment.
The side mission was worth it though, now off to deal with the other boss fight
Well that's what happened. You see I woke up ready fix a stupid bug in one of my shitty apps. I had a strategy in place, I always do. Linux had other plans, a thing interestingly enough called a Netplan ( https://netplan.io/ )
After a scheduled power outage, machines were rebooted, some did not fare well, background updates had made changes, walked away and left a few challenges.
One machine, my primary boss battle had the following problem.
Help with curl from r/RASPBERRY_PI_PROJECTS
As for the other machine, the one thing I worried least about stopped behaving as it should, damn thing would not remember the network settings. The old school solution is to tell the Network Managers to suck it and edit /etc/network/interfaces directly, but I had spent some time playing with the Network Manager Command Line tool and figured, what the hell, let's try that.
Then I see this Netplan thing sitting in my wifi list. I don't have an access point called Netplan. My neighbors don't have one either, yet this machine was connected to it.
"Dafuq is a Netplan?" I asked, don't recall seeing this before, then did some reading.
Netplan is a utility for easily configuring networking on a Linux system. You simply create a YAML description of the required network interfaces and what each should be configured to do. From this description Netplan will generate all the necessary configuration for your chosen renderer tool.
"Fine!" I thought, "I'll try to use this instead"
It worked. Followed the instructions provided by this blog and fixed it. I have yet to understand Netplans' relationship with Network Manager or the reason for the failure.
Netplan setup is not bad at all and I like it. Just resent having to travel that road at such an impromptu moment.
The side mission was worth it though, now off to deal with the other boss fight
Subscribe to:
Posts (Atom)
goBloggerCrawler Blogger Web Crawler in Go
Go-based web crawler used to efficiently extract structured data (titles, video URLs, and tags) from Google Blogger sites using concurrent p...
-
A friend brought one of them original Apple IPads over. His issue is a common one. "What the fuck do I do with this thing?" ...

