Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Adding a "copy link" link to my quick share plugin

  • This topic is empty.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #186324
    sbertrand
    Participant

    Is there any way to add a copy link link/button to the share portion of this? (Currently using the QuickShare plug in). So that instead of routing to email or other social media they have the direct option of copying (and/or pasting) the link? Thanks!

    http://www.mccarthyholiday.com

    #186334
    drose379
    Participant

    $_SESSION['url'] = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; Will get you the link and save it in a session.

    #186335
    sbertrand
    Participant

    Where would I put this in? The plug in folder file for quickshare and that php file?

    #186336
    drose379
    Participant

    Maybe, I’ve never used a plugin before. Do you have any code to show? Maybe I could help you that way.

    #186337
    sbertrand
    Participant
                     $class .= '-color';
    
                }
    
            }
    
            else {
    
                $class = 'quickshare-text';
    
                if(cxnh_quickshare_getOption('text_icons',$options))
    
                    $class .= ' qs-genericons';
    
            }
    
            //effects
    
            if(cxnh_quickshare_getOption('effect-spin',$options))
    
                $class .= ' quickshare-effect-spin';
    
            if(cxnh_quickshare_getOption('effect-round',$options))
    
                $class .= ' quickshare-effect-round';
    
            if(cxnh_quickshare_getOption('effect-glow',$options))
    
                $class .= ' quickshare-effect-glow';
    
            if(cxnh_quickshare_getOption('effect-expand',$options))
    
                $class .= ' quickshare-effect-expand';
    
            if(cxnh_quickshare_getOption('effect-contract',$options))
    
                $class .= ' quickshare-effect-contract';
    
            //size
    
            if(cxnh_quickshare_getOption('size',$options)) // ie, if not "normal"
    
                $class .= ' quickshare-' . cxnh_quickshare_getOption('size',$options);
    
            
    
            return $class;
    
    }
    
    function cxnh_quickshare_get_post_image() {
    
        global $post;
    
        $imgdata;
    
        
    
        // if there's a featured image, use it
    
        if(has_post_thumbnail())
    
            $imgdata = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium' );
    
        elseif(is_attachment())
    
            $imgdata = wp_get_attachment_image_src( $post->ID, 'medium' ); // attachment post type, so post id is attachment id
    
        else {
    
            // next, try grabbing first attached image
    
            $args = array(
    
                'numberposts' => 1,
    
                'post_parent' => $post->ID,
    
                'post_type' => 'attachment',
    
                'post_mime_type' => 'image'
    
            );
    
            $attachments = get_children( $args ); //array is keyed by attachment id
    
            if(!empty($attachments)) {
    
                $rekeyed_array = array_values($attachments);
    
                $imgdata = wp_get_attachment_image_src( $rekeyed_array[0]->ID , 'medium' );
    
            }
    
            else {
    
                //finally, look for the first img tag brute-force. Presumably if there's a caption or it's a gallery or anything it should have come up as an attachment
    
                $result = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches ); // find imag tags, grab srcs
    
                if($result > 0)
    
                    return $matches[1][0]; // return first img src, no way to select size if we've gotten this deep
    
            }
    
        }
    
        
    
        if(!empty($imgdata))
    
            return $imgdata[0]; //image url
    
        else
    
            return cxnh_quickshare_getOption('image');
    
    }
    
    function cxnh_quickshare_get_post_description() {
    
        // essentially a summary of get_the_excerpt(), but avoiding most filters other than custom ones (otherwise results in infinite loop)
    
        $post = get_post();
    
        $excerpt = $post->post_excerpt;
    
        if($excerpt == '')
    
            $excerpt = $post->post_content;
    
        $excerpt = wp_trim_words($excerpt, 40); //do this first so we aren't processing a ton of data
    
        $excerpt = strip_shortcodes( $excerpt );
    
        $excerpt = strip_tags($excerpt);
    
        $excerpt = str_replace(']]>', ']]>', $excerpt);
    
        return $excerpt;
    
    }

    <–This is the quickshare php file code.

    #186338
    drose379
    Participant

    Do you know how to create functions? I would add a property to the class there called ‘url’ and create a method (function) that gets the url of the page using the code I pasted above. $this->url = $url and have the method return $this->url. You can then use that value whenever you need it as long as an instance of the class is created.

    #186339
    drose379
    Participant

    I actually have something the exact same as what you want on a site I have.

    #186340
    sbertrand
    Participant

    It’s been a long long time since I’ve had to write a function…I happen to lean more designer and less coder, but apparently it’s time I learned a bit more, sigh…so something like this?
    function url () {
    $this-&gt;url = $url;
    $_SESSION['url'] = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    }
    <code></code>

    And then would I insert it somewhere else besides my main function.php file?

    #186342
    drose379
    Participant
    #186343
    sbertrand
    Participant

    Well, I inserted what you sent over and it gave me a lot of error messages…and to clarify – I am not inserting to a single page, but to the plug in because this needs to be included on all the pages, lightboxes, post pages, etc.

    BTW – thank you for all your help. If I knew who you were or where you were at, I’d invite you to share a nice beverage with me. :)

    #186405
    drose379
    Participant

    Sorry, what I sent was not ready to be thrown right into code. It would have to be tailored to how you set up your code in order to work.

Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘Back End’ is closed to new topics and replies.