Head Ads

wordpress get_plugin_version and display via plugin_row_meta

Share:

wordpress get_plugin_version and display via plugin_row_meta

If you are here to searching for wordpress get_plugin_version and display via plugin_row_meta then you are at right place we will see here let’s start it.

wordpress get_plugin_version and display via plugin_row_meta

1. Define the get_plugin_version() function:

PHP

function my_plugin_version() {

    // Retrieve the plugin's version number from the plugin header

    $plugin_data = get_plugin_data( __FILE__ );

    return $plugin_data['Version'];

}

Wordpress get plugin and display via plugin



2. Use plugin_row_meta() to display the version number:

PHP

function my_plugin_row_meta( $plugin_meta, $plugin_file ) {

    // Check if the current plugin file matches the one you want to display the version for

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

        // Add the version number to the plugin row metadata

        $plugin_meta[] = sprintf( __( 'Version: %s', 'my-plugin' ), my_plugin_version() );

    }

 

    return $plugin_meta;

}

add_filter( 'plugin_row_meta', 'my_plugin_row_meta', 10, 2 );

Explanation:

  1. The get_plugin_version() function retrieves the plugin's version number from the plugin header using get_plugin_data().
  2. The my_plugin_row_meta() function checks if the current plugin file matches the one you want to display the version for.
  3. If it matches, the function adds the version number to the plugin row metadata using sprintf().
  4. The add_filter() function hooks the my_plugin_row_meta() function into the plugin_row_meta filter, ensuring that the version number is displayed in the plugin list.

Key Points:

  • Replace __FILE__ with the actual path to your plugin file.
  • Replace 'my-plugin' with the text domain of your plugin.
  • Adjust the filter priority (10) if needed to control the order in which the version number is displayed.

By following these steps, you will successfully display the plugin's version number in the plugin list within your WordPress admin area. If you want to see more related articles then keep reading saeeddeveloper website :)  

Thanks for reading :) 

No comments

Note: Only a member of this blog may post a comment.