Can I use/edit WordPress Core Functions in my own plugin?

So I am currently fooling around with creating a site options plugin. I want to add tab functionality between settings sections, but I don’t want to have separate pages for each tab (like I have seen in most tutorials, I think it is because of the nonce). I am Looking to have just a simple jQuery Tab functionality.

So in order to do this I need to wrap a div around each setting section. There doesn’t seem to be a way to hook into do_settings_sections or add_setting_section wordpress functions.

Read More

So my solution is just to duplicate the do_settings_sections function in my plugin and add what I need. Is this a silly thing to do, will I encounter issues the next time WordPress updates?

Here is my new do_settings_section function (called in my plugin)

function do_settings_sections_new( $page ) {
global $wp_settings_sections, $wp_settings_fields;

if ( ! isset( $wp_settings_sections[$page] ) )
    return;

$numCategory=0; //Added by me
foreach ( (array) $wp_settings_sections[$page] as $section ) {

    $numCategory++;//Added by me
    if ( $section['title'] )
        echo "<div class='opt-category active' data-content=". $numCategory .">"; //Added by me
        echo "<h3>{$section['title']}</h3>n";

    if ( $section['callback'] )
        call_user_func( $section['callback'], $section );

    if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) )
        continue;
    echo '<table class="form-table2">';
    do_settings_fields( $page, $section['id'] );
    echo '</table>';
    echo '</div>'; //Added by me

}

}

Related posts

1 comment

  1. WordPress provides a few options for overwriting or modifying core functionality. By using Actions and Filters you can alter the logic and/or view of several WordPress features. There is also a list of Pluggable Functions which WordPress allows you to overwrite directly. Other than this, modifying or overwriting core functionality is frowned upon and will break with updates.

    There are a ton of options with Actions and Filters. One approach may be to hide the default Settings menu altogether using remove menu page(); and build your own view for it.

    You could also use a some jQuery/AJAX magic to accomplish the tab switch without page load.

    Good Luck!

Comments are closed.