Skip file when plugin updated

On you future code files in your plugin, do not include the ‘option’ file in the repository. Since it is not included in the repository zip, the file (if it exists) will not be overwritten on the user’s system. You may need some code in your plugin to create the file on activation with some … Read more

Automatically translating from existing .po and .mo files?

Solved by adding if ( isset( $_POST[‘language’] ) ) { // Input var okay. add_filter( ‘locale’, ‘mbd_set_my_locale’ ); /** * Set locale based on the $_POST choice. * * @param string $locale Locale code. * @return string Selected locale code. */ function mbd_set_my_locale( $locale ) { $language = sanitize_text_field( wp_unslash( $_POST[‘language’] ) ); // Input … Read more

wp_enqueue_script fails to include in footer

Use the approach below to enqueue your scripts using a single action hook: /** * Proper way to enqueue scripts. * The same approach can be used to enqueue styles. */ function my_interface_enqueues() { wp_enqueue_script( ‘require-js’, plugin_dir_url( __FILE__ ) . ‘js/libs/requirejs/require.js’, array(), ‘1.0.0’, true ); wp_enqueue_script( ‘main-js’, plugin_dir_url( __FILE__ ) . ‘js/main.js’, array(), ‘1.0.0’, true … Read more

How WordPress knows where to find locale files?

Plugins and themes pull the translation files manually from (mostly) their directory. There are 2 different functions which handle this: For plugins : load_plugin_textdomain() For themes: load_theme_textdomain() The syntax would be something like this, mostly hooked into init or plugins_loaded action hook: load_plugin_textdomain( ‘text-domain’, get_template_directory() . ‘/some-directory’ ); OR: load_plugin_textdomain( ‘text-domain’, false, basename(dirname(__FILE__)).’/some-directory’); Look for … Read more

What’s the _wp_desired_post_slug value for?

See this line in WordPress core. Explanation: When you move a post to the trash, _wp_desired_post_slug holds the slug that was desired for that post (now in the trash); i.e., when you move a post to the trash, WordPress suffixes the old slug so that it becomes available again, but it remembers the slug that … Read more