I am new to WordPress and I want to add a custom button to the admin control panel in a PointFinder theme. I know the concept of an action hook and have already successfully implemented my own action hook using do_action_ref_array() and called it from functions.php using add_action() .
Approach 1 (definition of put button statically in php file)
In the file 'dashboard-page.php', a widget of the target sidebar is built into which I want to add an additional button. Here is an excerpt from the code:
$pfmenu_output .= ($setup11_reviewsystem_check == 1) ? '<li><a href="'.$setup4_membersettings_dashboard_link.$pfmenu_perout.'ua=reviews"><i class="pfadmicon-glyph-377"></i> '. $setup29_dashboard_contents_rev_page_menuname.'</a></li>' : ''; $pfmenu_output .= '<li><a href="http://my.testsite.com/market"><i class="pfadmicon-glyph-476"></i> '. esc_html__('Car Market','pointfindert2d').'</a></li>'; $pfmenu_output .= '<li><a href="'.esc_url(wp_logout_url( home_url() )).'"><i class="pfadmicon-glyph-476"></i> '. esc_html__('Logout','pointfindert2d').'</a></li>';
The second line is my static approach. The button is correctly added to the sidebar widget. But I need to put this code in the functions.php my Child-Theme in order to save it during future update procedures.
Approach 2 (more dynamic with self-defined action)
I also tried adding my own action hook instead of statically adding a button (replaced the second line with the definition of the action hook:
$pfmenu_output .= ($setup11_reviewsystem_check == 1) ? '<li><a href="'.$setup4_membersettings_dashboard_link.$pfmenu_perout.'ua=reviews"><i class="pfadmicon-glyph-377"></i> '. $setup29_dashboard_contents_rev_page_menuname.'</a></li>' : ''; do_action_ref_array( 'pf_add_widget_button', array(&$pfmenu_output) ); $pfmenu_output .= '<li><a href="'.esc_url(wp_logout_url( home_url() )).'"><i class="pfadmicon-glyph-476"></i> '. esc_html__('Logout','pointfindert2d').'</a></li>';
Subsequently, I added a call to add_action() my child function.php topic and added a button there, which also works fine:
function swi_add_button_to_widget(&$pfmenu_output) { $pfmenu_output .= '<li><a href="http://my.testsite.com/market"><i class="pfadmicon-glyph-476"></i> '. esc_html__('Car Market,'pointfindert2d').'</a></li>'; } add_action( 'pf_add_widget_button', 'swi_add_button_to_widget' );
Problem definition
But both approaches described above will work only until I update the PointFinder theme for the first time, since dashboard-page.php is likely to be overridden during the update.
I did not find any preliminary action hooks implemented by the theme development team by searching all files looking for do_action() and do_action_ref_array() . Nothing...
Decision?
Therefore, is there another way to access this $pfmenu_output variable from my child theme to add an extra button?
Am I completely stuck when theme developers did n't embed some pre-created action hooks for this particular purpose?