wordpress get_plugin_version and show by way of plugin_row_meta – Uplaza

In case you are right here to looking for wordpress
get_plugin_version and show by way of plugin_row_meta then you might be at proper place
we’ll see right here let’s begin it.

1. Outline
the
get_plugin_version() perform:

PHP

perform my_plugin_version() {

    // Retrieve
the plugin’s model quantity from the plugin header

    $plugin_data
= get_plugin_data( __FILE__ );

    return $plugin_data[‘Version’];

}

2. Use plugin_row_meta() to show the model quantity:

PHP

perform my_plugin_row_meta( $plugin_meta, $plugin_file
) {

    // Test if
the present plugin file matches the one you wish to show the model for

    if ( $plugin_file
== plugin_basename( __FILE__ ) ) {

        // Add
the model quantity to the plugin row metadata

        $plugin_meta[]
= sprintf( __( ‘Model: %s’, ‘my-plugin’ ), my_plugin_version() );

    }

 

    return $plugin_meta;

}

add_filter( ‘plugin_row_meta’, ‘my_plugin_row_meta’, 10,
2 );

Rationalization:

  1. The get_plugin_version() perform retrieves the
    plugin’s model quantity from the plugin header utilizing
    get_plugin_data().
  2. The my_plugin_row_meta() perform checks if the present
    plugin file matches the one you wish to show the model for.
  3. If it matches, the perform
    provides the model quantity to the plugin row metadata utilizing
    sprintf().
  4. The add_filter() perform hooks the my_plugin_row_meta() perform into the plugin_row_meta filter, making certain that the
    model quantity is displayed within the plugin record.

Key Factors:

  • Exchange __FILE__ with the precise path to your
    plugin file.
  • Exchange ‘my-plugin’ with the textual content area of your
    plugin.
  • Alter the filter precedence (10)
    if wanted to regulate the order through which the model quantity is displayed.

By following
these steps, you’ll efficiently show the plugin’s model quantity within the
plugin record inside your WordPress admin space. If you wish to see extra associated articles then maintain studying saeeddeveloper web site 🙂  

Thanks for studying 🙂 

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version