Filters

Estimated reading: 2 minutes 315 views

The following filters are available for hooking into the plugin:

  • post_snippets_import   serialized array   Modify snippets and related data before the imported file populates the snippets.
  • post_snippets_export   serialized array   Modify snippets and related data before the export file is created.
  • post_snippets_snippets_list   array   Modify the array of snippets that are used as the snippet list for the jQuery UI dialog in the edit post screen.

Examples

Post_snippets_export

// Filter Exported Snippets

function ps_export( $snippets )

{

  $snippets = unserialize( $snippets );

  foreach ( $snippets as &$snippet ) {

    // Do something here. Example below search and replaces in snippets

    $snippet[‘snippet’] = str_replace(‘search’,’replace’, $snippet[‘snippet’]);

  }

  return serialize( $snippets );

}

add_filter( ‘post_snippets_export’, ‘ps_export’ );

Post_snippets_import

// Filter Imported Snippets

function ps_import( $snippets )

{

  $snippets = unserialize( $snippets );

  foreach ( $snippets as &$snippet ) {

    // Do something here. Example below search and replaces in variables

    $snippet[‘vars’] = str_replace(‘search’, ‘replace’, $snippet[‘vars’]);

  }

  return serialize( $snippets );

}

add_filter( ‘post_snippets_import’, ‘ps_import’ );

Leave a Reply

Your email address will not be published. Required fields are marked *

Share this Doc

Filters

Or copy link

CONTENTS
Scroll to Top