shustry

EVENT_SMARTLING_BEFORE_SERIALIZE_CONNENT event test

Nov 19th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @link              http://example.com
  4.  * @since             1.0.0
  5.  * @package           smartling-event-test-before-serialize
  6.  *
  7.  * @wordpress-plugin
  8.  * Plugin Name:       Smartling Event Test (before serialize)
  9.  * Plugin URI:        http://example.com
  10.  * Description:       Just simple test
  11.  * Version:           1.0.0
  12.  * Author:            para
  13.  * Author URI:        http://example.com
  14.  * License:           GPL-2.0+
  15.  * Network:           true
  16.  * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
  17.  */
  18.  
  19. add_action( 'plugins_loaded', function () {
  20.     add_action( 'EVENT_SMARTLING_BEFORE_SERIALIZE_CONNENT',
  21.         function ( $params ) {
  22.             /**
  23.              * @var \Smartling\Helpers\EventParameters\BeforeSerializeContentEventParameters $params
  24.              */
  25.             $paramsClassName = '\Smartling\Helpers\EventParameters\BeforeSerializeContentEventParameters';
  26.             if ( $params instanceof $paramsClassName ) {
  27.                 if ( \Smartling\Helpers\WordpressContentTypeHelper::CONTENT_TYPE_WIDGET
  28.                      === $params->getSubmission()->getContentType()
  29.                 ) {
  30.                     $fields = &$params->getPreparedFields();
  31.  
  32.                     $msg = vsprintf(
  33.                         'Step 1.<br>Setting up entity->index to <b>%s</b> from <b>%s</b>',
  34.                         [
  35.                             999,
  36.                             $fields['entity']['index'],
  37.                         ]
  38.                     );
  39.                     echo vsprintf( '<div class="updated"><p>%s</p></div>', [ $msg ] );
  40.                     $fields['entity']['index'] = 999;
  41.                 }
  42.             }
  43.         } );
  44.  
  45.     add_action( 'EVENT_SMARTLING_BEFORE_SERIALIZE_CONNENT',
  46.         function ( $params ) {
  47.             /**
  48.              * @var \Smartling\Helpers\EventParameters\BeforeSerializeContentEventParameters $params
  49.              */
  50.             $paramsClassName = '\Smartling\Helpers\EventParameters\BeforeSerializeContentEventParameters';
  51.             if ( \Smartling\Helpers\WordpressContentTypeHelper::CONTENT_TYPE_WIDGET
  52.                  === $params->getSubmission()->getContentType()
  53.             ) {
  54.                 if ( $params instanceof $paramsClassName ) {
  55.                     $fields = $params->getPreparedFields();
  56.                     $msg    = vsprintf(
  57.                         'Step 2.<br>Checking the entity->index value : <b>%s</b>.',
  58.                         [
  59.                             $fields['entity']['index'],
  60.                         ]
  61.                     );
  62.                     echo vsprintf( '<div class="updated"><p>%s</p></div>', [ $msg ] );
  63.                 }
  64.             }
  65.         } );
  66. } );
Advertisement
Add Comment
Please, Sign In to add comment