I am quite new to WordPress and I want to add a custom button to the admin dashboard in the PointFinder theme. I am aware of the action hook concept and already successfully implemented my own action hook with do_action_ref_array()
and called it from the functions.php
with add_action()
.
Approach 1 (put button definition statically into php-file)
The target sidebar widget at which I want to add an additional button is built in the 'dashboard-page.php' file. Here's an excerpt of 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 added to the sidebar widget correctly. But I need to put this code to the functions.php
of my Child-Theme
in order to keep it during future update procedures.
Approach 2 (more dynamic with a self defined action-hook)
I also tried to add my own action hook instead of statically adding the button (replaced the second line with an action hook definition:
$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>';
Afterwards I added an add_action()
call to my child-theme's function.php
and added the button there, which works also 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 only work until I update the PointFinder theme for the first time, since dashboard-page.php
will most probably be overriden during the update.
I did not find any pre-made action-hooks implemented by the theme development team by searching through all the files looking for do_action()
and do_action_ref_array()
. Nothing...
Solution ?
Therefore, is there any other way to get access to this $pfmenu_output
variable from within my child-theme in order to add an extra button?
Am I completely stuck when the theme developers did not build-in some pre-made action-hooks for this specific purpose?