WordPress.org

Ready to get started?Download WordPress

Forums

Post Snippets
[resolved] Kind request for some 'static' values ... please ? (2 posts)

  1. donovanacker
    Member
    Posted 2 years ago #

    Hello,
    First thanks for the awesome plugin. It really is a great tool with many applicable uses !

    I have a request :). I do a lot of exporting and importing of snippets between sites. And many of the snippets we use contain the site url as part of the snippet html (ie. src="http://www.somesite.com" ). So, one of the "hassles" :) I have is that when I import snippets from one site to another I have to manually replace the site URL in all the snippets.

    It would be reeeeallly helpful if there were some 'static' keyword or default we could enter into the snippet, like "site_URL" ....and then you could kindly throw in the site root URL at run time for us :)))). Maybe I am just being lazy ? :)... I guess I could just use the PHP snippet and echo out the html and grab the site URL in the pull ... but I am trying to keep the snippets as "non-programatic" as possible so that I can hand over sites to admins who don't know PHP etc... make sense ?

    Any help appreciated ! Again.. great plugin !

    http://wordpress.org/extend/plugins/post-snippets/

  2. Johan Steen
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    I don't have any plans to add global/static variables at this time, as it could be solved by using the PHP enabling function for the snippets.

    What I did do though, was that in the latest release (1.9.6) I added two new filters to the plugin, post_snippets_import and post_snippets_export.

    While it doesn't do exactly what you are looking for, using them would at least simplify the process you are doing by adding a simple filter to your site/s to replace the urls on either export or import.

    Here is two examples to get you started of either import or export filter you could add to your site/s.

    Example that modifies data in snippets before the export file is created:

    function ps_export( $snippets )
    {
      $snippets = unserialize($snippets);
      foreach ($snippets as &$snippet) {
        $snippet['snippet'] = str_replace('old-url', 'new-url', $snippet['snippet']);
      }
      return serialize($snippets);
    }
    add_filter( 'post_snippets_export', 'ps_export' );

    Example that modifies data in snippets before an imported file populates the site:

    function ps_import( $snippets )
    {
      $snippets = unserialize($snippets);
      foreach ($snippets as &$snippet) {
        $snippet['snippet'] = str_replace('old-url', 'new-url', $snippet['snippet']);
      }
      return serialize($snippets);
    }
    add_filter( 'post_snippets_import', 'ps_import' );

    If you don't want to modify snippets, but variables or variables' default values, you can use $snippet['vars'] instead of $snippet['snippet'].

    Cheers,
    Johan

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic