0

I write a plugin. Inside it I use php and javascript files. I also use admin bar and I managed to display it with its nodes under the root menu. I nedd the following functionality: Clicking on one node should run some custopm php file on the server. Clicking on another node should run a javascript file. Is there a way to implement that? Tnx I.Sher

0

Yes. It is possible. Add a custom link to the href attribute of the function, maybe with attributes for the url. This parameter plan you Parse, like about the global $_GET and run your file, script etc. if it the right parameters.

As example, see on the href-Parameter. I add the follow get-parameters in the href-Attribute.

    $scheme = ( is_ssl() ? 'https' : 'http' );
    $url    = $scheme . '://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ];
    $str    = array( '?debug', '&debug', '#debugobjects' );
    $url    = esc_url( str_replace( $str, '', $url ) );
    $get    = '?';
    if ( FALSE !== strpos( $url, '?' ) ) {
        $get = '&';
    }
    $href = $url . $get . "debug#debugobjects";

The completly source to add my custom item in the Admin bar. You find all of this code in this repo.

        $wp_admin_bar->add_menu(
            array(
                'parent'    => 'network-admin',
                'secondary' => FALSE,
                'id'        => 'network-' . self::get_textdomain(),
                'title'     => self::get_plugin_data( 'Name' ),
                'meta'      => array( 'class' => $classes ),
                'href'      => network_admin_url( 'settings.php?page=' . plugin_basename( __FILE__ ) ),
            )
        );
        $scheme = ( is_ssl() ? 'https' : 'http' );
        $url    = $scheme . '://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ];
        $str    = array( '?debug', '&debug', '#debugobjects' );
        $url    = esc_url( str_replace( $str, '', $url ) );
        $get    = '?';
        if ( FALSE !== strpos( $url, '?' ) ) {
            $get = '&';
        }
        $href = $url . $get . "debug#debugobjects";
        $wp_admin_bar->add_menu(
            array(
                'id'     => 'debug_objects',
                'parent' => 'top-secondary',
                'title'  => '<img style="float:left;height:28px;" src="'
                    . plugins_url( '/img/bug-32.png', parent::$plugin )
                    . '" alt="The Bug" />'
                    . __( ' Objects', self::get_textdomain() ),
                'meta'   => array( 'class' => $classes ),
                'href'   => $href
            )
        );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.