WordPress.org

Ready to get started?Download WordPress

Forums

Multisite Language Switcher
[resolved] Can I Filter admin links (4 posts)

  1. patnz
    Member
    Posted 1 year ago #

    Hi There,

    I'm just wondering if there's a clean way to filter the output of the the Create New translation links that are output by the function get_edit_new() in includes/mslsAdminIcon.php?

    I wrote a clone function that requires some parameters to be added to the url. So I want my links to be something like http://destinationblog.com?action=clonepost&srcblog=1&srcpost=123.

    Is there any way to do this at present without hacking the plugin?

    Thanks for a great plugin by the way!

    http://wordpress.org/extend/plugins/multisite-language-switcher/

  2. realloc
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    excellent request! I added a filter named "msls_admin_icon_get_edit_new" which has one argument (string $path) so you can add you vars to the generated URL too. I recommend to use add_query_arg for this (but I'm sure you know this).

    I pushed the modifications to the GitHub repository:
    https://github.com/lloc/Multisite-Language-Switcher/

    Please let me know if it works for you so I can commit it to the WordPress Plugin Directory.

    Cheers,
    Dennis.

  3. patnz
    Member
    Posted 1 year ago #

    Brilliant, thanks for adding that in! All working well for me. Here's the function I'm using. I actually completely override the default path in this but I tested simply appending parameters to the default path and all works well!

    function add_clone_parameters($path){
    
    	// I'm only looking to clone posts not taxonomies etc so we'll
    	// only modify on post edit or post listing pages.
    	global $pagenow;
    	if( $pagenow != 'edit.php' && $pagenow != 'post.php' ){
    		return $path;
    	}
    
    	global $post;
    	global $current_blog;
    
    	// I'm going to use a custom admin action to fire my create clone function
    	// so since I don't want to link to add post directly I'll unset $path in this case.
    	$path = '';
    
    	// If on a post edit page - i.e. the links on the MSLS meta box
    	// global $post doesn't return the value we want so use $_GET post var
    	if( !$srcpost = $_GET['post'] ){
    		$srcpost = $post->ID;
    	}
    
    	// Get src blog from global $current_blog
    	$srcblog = $current_blog->blog_id;
    
    	// Get destblog from get_current_blog_id().
    	// This may seem odd but in MSLS we are switched to the local blog at present
    	$destblog = get_current_blog_id();
    
        //add variables to path
        $path = add_query_arg( 'action',   'clone_product', $path );
        $path = add_query_arg( 'srcblog',  $srcblog, $path );
        $path = add_query_arg( 'destblog', $destblog, $path );
        $path = add_query_arg( 'srcpost',  $srcpost, $path ); 
    
    	return $path;
    
    }
    add_filter('msls_admin_icon_get_edit_new', 'add_clone_parameters');

    My actual clone function is a bit environment specific but I'll tidy it up and post back here when I get a chance in case anyone is looking for it.

    Cheers for the heads up on add_query_arg too!

    Thanks again,

    Pat

  4. realloc
    Member
    Plugin Author

    Posted 1 year ago #

    OK, excellent. Thanks for sharing your idea!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.