This question is about the famous debate on using Dynamic methods over static methods in classes. According to my research the widely acknowledged idea is to limit the use of static methods as much as we can.
Now in terms of WordPress I have a class that registers a shortcode. The shortcode has some logic built into it and is dependent on fetching some meta values from the page it is being used on.
Now I have recently found out that there is also a widget in the sidebar that needs to use those same metavalues according to the same logic used in the shortcode.
For Ex: In the shortcode class I have a method that grabs all meta values and stores them in an array with a fixed index name that I need the value to correspond to. So my array after fetching is something like:
$locations = array( 'slug' => 'new-york', 'name' => 'New York', 'zipcode' => '123456');
1- If I create a new instance of the class in the sidebar I am worried about the one 'shortcode' and two 'init' hooks within the constructor and I am worried weather they would affect performance.
2- Instead of fetching the post meta one time. Now I am fetching it two times for the same value. One in the shortcode and other in the sidebar.
I need you guys to help me advice a better structure to solve this formula so both of these problems are minimized.