Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save marbaque/2946bcc7886d636d0ea8b3a3570f3a68 to your computer and use it in GitHub Desktop.

Select an option

Save marbaque/2946bcc7886d636d0ea8b3a3570f3a68 to your computer and use it in GitHub Desktop.

Revisions

  1. @wpscholar wpscholar revised this gist Jul 10, 2015. 1 changed file with 16 additions and 3 deletions.
    19 changes: 16 additions & 3 deletions wp-snapshot-shortcode.php
    Original file line number Diff line number Diff line change
    @@ -13,12 +13,25 @@
    'width' => '400',
    'height' => '300'
    ), $atts );
    $params = array(
    'w' => $atts['width'],
    $params = array(
    'w' => $atts['width'],
    'h' => $atts['height'],
    );
    $url = urlencode( $atts['url'] );
    $src = 'http://s.wordpress.com/mshots/v1/' . $url . '?' . http_build_query( $params, null, '&' );

    return '<img src="' . esc_url( $src ) . '" alt="' . esc_attr( $atts['alt'] ) . '"/>';
    $cache_key = 'snapshot_' . md5( $src );
    $data_uri = get_transient( $cache_key );
    if ( ! $data_uri ) {
    $response = wp_remote_get( $src );
    if ( 200 === wp_remote_retrieve_response_code( $response ) ) {
    $image_data = wp_remote_retrieve_body( $response );
    if ( $image_data && is_string( $image_data ) ) {
    $src = $data_uri = 'data:image/jpeg;base64,' . base64_encode( $image_data );
    set_transient( $cache_key, $data_uri, DAY_IN_SECONDS );
    }
    }
    }

    return '<img src="' . esc_attr( $src ) . '" alt="' . esc_attr( $atts['alt'] ) . '"/>';
    } );
  2. @wpscholar wpscholar revised this gist Jul 8, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wp-snapshot-shortcode.php
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    * This shortcode will allow you to create a snapshot of a remote website and post it
    * on your WordPress site.
    *
    * [snapshot url="http://www.wordpress.org" alt="My description" width="400" height="300"]
    * [snapshot url="http://www.wordpress.org" alt="WordPress.org" width="400" height="300"]
    */
    add_shortcode( 'snapshot', function ( $atts ) {
    $atts = shortcode_atts( array(
  3. @wpscholar wpscholar revised this gist Jul 7, 2015. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion wp-snapshot-shortcode.php
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,10 @@
    'width' => '400',
    'height' => '300'
    ), $atts );
    $params = array( 'w' => $atts['width'], 'h' => $atts['height'] );
    $params = array(
    'w' => $atts['width'],
    'h' => $atts['height'],
    );
    $url = urlencode( $atts['url'] );
    $src = 'http://s.wordpress.com/mshots/v1/' . $url . '?' . http_build_query( $params, null, '&' );

  4. @wpscholar wpscholar revised this gist Jul 7, 2015. 2 changed files with 21 additions and 19 deletions.
    19 changes: 0 additions & 19 deletions wp-screenshot-shortcode.php
    Original file line number Diff line number Diff line change
    @@ -1,19 +0,0 @@
    <?php

    /**
    * This shortcode will allow you to create a snapshot of a remote website and post it
    * on your WordPress site.
    *
    * [snap url="http://www.wordpress.org" alt="My description" w="400" h="300"]
    */
    function snap($atts, $content = null) {
    extract(shortcode_atts(array(
    "snap" => 'http://s.wordpress.com/mshots/v1/',
    "url" => 'http://www.wordpress.org',
    "alt" => '',
    "w" => '400', // width
    "h" => '300' // height
    ), $atts));
    return '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>';
    }
    add_shortcode("snap", "snap");
    21 changes: 21 additions & 0 deletions wp-snapshot-shortcode.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    <?php

    /**
    * This shortcode will allow you to create a snapshot of a remote website and post it
    * on your WordPress site.
    *
    * [snapshot url="http://www.wordpress.org" alt="My description" width="400" height="300"]
    */
    add_shortcode( 'snapshot', function ( $atts ) {
    $atts = shortcode_atts( array(
    'alt' => '',
    'url' => 'http://www.wordpress.org',
    'width' => '400',
    'height' => '300'
    ), $atts );
    $params = array( 'w' => $atts['width'], 'h' => $atts['height'] );
    $url = urlencode( $atts['url'] );
    $src = 'http://s.wordpress.com/mshots/v1/' . $url . '?' . http_build_query( $params, null, '&' );

    return '<img src="' . esc_url( $src ) . '" alt="' . esc_attr( $atts['alt'] ) . '"/>';
    } );
  5. @wpscholar wpscholar renamed this gist Jun 4, 2013. 1 changed file with 7 additions and 5 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    <?php

    /**
    * This shortcode will allow you to create a snapshot of a remote website and post it
    * on your WordPress site.
    *
    * [snap url="http://www.wordpress.org" alt="My description" w="400" h="300"]
    */
    * This shortcode will allow you to create a snapshot of a remote website and post it
    * on your WordPress site.
    *
    * [snap url="http://www.wordpress.org" alt="My description" w="400" h="300"]
    */
    function snap($atts, $content = null) {
    extract(shortcode_atts(array(
    "snap" => 'http://s.wordpress.com/mshots/v1/',
  6. Micah Wood created this gist Sep 26, 2011.
    17 changes: 17 additions & 0 deletions WordPress - Remote website snapshot
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    /**
    * This shortcode will allow you to create a snapshot of a remote website and post it
    * on your WordPress site.
    *
    * [snap url="http://www.wordpress.org" alt="My description" w="400" h="300"]
    */
    function snap($atts, $content = null) {
    extract(shortcode_atts(array(
    "snap" => 'http://s.wordpress.com/mshots/v1/',
    "url" => 'http://www.wordpress.org',
    "alt" => '',
    "w" => '400', // width
    "h" => '300' // height
    ), $atts));
    return '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>';
    }
    add_shortcode("snap", "snap");