Php variables in WordPress

To set a variable, such as an url, you can use the following steps:

  • add to your wp-config a code with something like
require_once ABSPATH . 'wp-settings.php';
/** variabili */
define('GLOSSARIO_URL', 'yourwebsite/glossario.php');
  • add to functions.php (in your wp theme root) something like
define('GLOSSARIO_URL', 'yourwebsite/glossario.php');

function glossario_link($atts) {
    $atts = shortcode_atts([
        'id' => '',
        'testo' => ''
    ], $atts);

    $url = GLOSSARIO_URL . '#' . $atts['id'];

    return '<a href="' . esc_url($url) . '">' . esc_html($atts['testo']) . '</a>';
}

add_shortcode('glossario', 'glossario_link');
  • in wp editor you will be able to call that code inserting a text like this:
[glossario id="universalismo" testo="universalisticamente"]

where the content of testo="" is what will appears in your wp page (while in the editor you will see that code)

Markdown editors

gabbia

As already said, 3 years ago, there are very few md editors really good. Recently I tried if there are alternatives to zettlr, but unsuccessfully.

Zettlr is a very good md editor, open source and customizable, WYSIWYG but respectful of your control of code. Its mayor limit is that cannot recognize symlinks.

Typora has almost all the pros of Zettlr (except the automatic replacement of “), and can recognize symlinks, but it’s not open source.

MdSilo is not too bad: wysing, open source, can open symlinked files. A bit elementar, no much customizable.
MarkFlowy seems very good. Very interesting. Open source, it can read symlinks, and is more customizable than MdSilo, even less than Zettlr. But some doubts about its respect of your privacy (its auth certificate was seen as malicious by Firefox).

Other md editors are far worse:

gabbiaMany of them don’t allow you to open not only symlinked files, but any existing external file. Moreover many they ask you for your e-mail. In a nutshell: a golden cage.

Golden cages are:

  • TriliumNotes-(v0.103.0)
  • Logseq-(0.10.15)
  • Siyuan-3.6.5
  • Beaver-Notes-4.4.0

Other apps were once good, but now are discontinued, such as

  • marktext
  • apricotine
  • remarkable

Set date format in Thunderbird mail list

I have TB in american english, but I hate american english date format (mm/dd).
To fix this ugly, terrible, disgusting way to show dates, I tried unsuccessfully to:

  • go in TB about:config
  • intl.locale.requested = it, en-US

The only way, then, seemed to set whole TB in Italian (or in an other not-english language that has dd/mm).
But there is a real possibility: use en-GB instead of en-US: and so you have both, english and dd/mm as date format.

Thunderbird task manager icon

If you use Wayland and in taskbar TB has an ugly W icon, you can try

  • to check if the path of icon is correct;
  • add this line (or something similar) in tb .desktop file: StartupWMClass=thunderbird-esr. Instead of thunderbird-esr you could have to check the appropiate name of TB in yout system.
  • be sure that the name of your desktop file be capitalized, that is Thunderbird.desktop and not thunderbird.desktop;
  • be sure that you don’t have duplicate Thunderbird entries (i.g. in KDE menu or in .desktop files)



Fix a corrupt innodb

Today happened that mariadb worked almost correctly, but two wordpress db were incorrectly managed. Indeed I could modify a post, but I couldn’t add a new one.

In another PC I, luckily, had the good wp db (perfectlty working with its innodb). So, it was possible to fix this problem. With the following steps:

a) in the well working device dump (from a teminal) the working wp db:

mysqldump -u root -p --single-transaction --routines --triggers your-db-name > dump-yourdbname.sql

b) in the bad working device

  • activate (if not already active) mariadb
  • in a terminal: mysql -u root -p (of course you have to provide your mysql psw)
  • and then, within mysql, you have to delete the old, bad, db, and create a new one:
    • DROP DATABASE IF EXISTS yourdbname;
    • CREATE DATABASE yourdbname CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    • EXIT;
  • Now you have a new, good but empty db. You have now to import the content of it, with this code: mysql -u root -p yourdbname < dump-yourdbname.sql

Now all should work 🙂.

External markdown file in WordPress

If you want keep an external markdown file and include it in a WordPress page, you can follow these steps:

  • add a js file, such as md-block.js, in your js theme folder (typically /wp-content/themes/your-theme/js/ )
  • modify the functions.php file, in your root theme folder,. adding this code:
// per markdown BEGIN

function carica_md_block() {
    wp_enqueue_script(
        'md-block',
        get_stylesheet_directory_uri() . '/js/md-block.js',
        array(),
        null,
        true
    );
}
add_action('wp_enqueue_scripts', 'carica_md_block');

add_filter('script_loader_tag', function($tag, $handle, $src) {
    if ($handle === 'md-block') {
        return '<script type="module" src="' . esc_url($src) . '"></script>';
    }
    return $tag;
}, 10, 3);

function shortcode_scheda_md($atts) {
    $atts = shortcode_atts(array(
        'file' => ''
    ), $atts);

    $file = basename($atts['file']);

    if (empty($file) || pathinfo($file, PATHINFO_EXTENSION) !== 'md') {
        return '';
    }

    $url = content_url('/uploads/some-path/' . rawurlencode($file));

    return '<md-block src="' . esc_url($url) . '"></md-block>';
}
add_shortcode('scheda_md', 'shortcode_scheda_md');

// per markdown END
  • you can put your md files in the path above set: /uploads/some-path/ . Note that the folder some-path could be a symlinked one, from your local PC.
  • in the wordpress page when you want include a md file you can write,
    • using HTML (customized), [scheda_md file="the-name-of-the-file.md"],
    • or the code visualizaztion: something like[scheda_md]the-name-of-the-file.md[/scheda_md]
  • where that file, obviously, should be in /some-path/ folder.

Modify several symlinks at once

adding ../ to the target path

If you have to add the same property, i.g. ../ to several symlinks in the same folder, you can use this code:

#!/bin/bash

for f in *; do 
  [ -L "$f" ] || continue
  [ -e "$f" ] && continue   # skip the valid ones

  target=$(readlink "$f")
  [[ "$target" != /* ]] && ln -snf ../"$target" "$f"
done

You can either save this code in a bash file, or paste it directly in a terminal.

another case: replace the name of the target file

If you have now target files renamed with “-” instead of space ” “, you can use this code:

for f in *; do
  [ -L "$f" ] || continue
  [ -e "$f" ] && continue

  target=$(readlink "$f")
  newtarget=${target// /-}

  [[ "$target" != "$newtarget" ]] && ln -snf "$newtarget" "$f"
done