shustry icon

EVENT_SMARTLING_BEFORE_SERIALIZE_CONNENT event test

shustry | PRO | 11/19/15 11:30:22 AM UTC | 0 ⭐ | 216 👁️ | Never ⏰ | []
PHP |

2.16 KB

|

None

|

0 👍

/

0 👎

<?php
/**
 * @link              http://example.com
 * @since             1.0.0
 * @package           smartling-event-test-before-serialize
 *
 * @wordpress-plugin
 * Plugin Name:       Smartling Event Test (before serialize)
 * Plugin URI:        http://example.com
 * Description:       Just simple test
 * Version:           1.0.0
 * Author:            para
 * Author URI:        http://example.com
 * License:           GPL-2.0+
 * Network:           true
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 */
 
add_action( 'plugins_loaded', function () {
    add_action( 'EVENT_SMARTLING_BEFORE_SERIALIZE_CONNENT',
        function ( $params ) {
            /**
             * @var \Smartling\Helpers\EventParameters\BeforeSerializeContentEventParameters $params
             */
            $paramsClassName = '\Smartling\Helpers\EventParameters\BeforeSerializeContentEventParameters';
            if ( $params instanceof $paramsClassName ) {
                if ( \Smartling\Helpers\WordpressContentTypeHelper::CONTENT_TYPE_WIDGET
                     === $params->getSubmission()->getContentType()
                ) {
                    $fields = &$params->getPreparedFields();
 
                    $msg = vsprintf(
                        'Step 1.<br>Setting up entity->index to <b>%s</b> from <b>%s</b>',
                        [
                            999,
                            $fields['entity']['index'],
                        ]
                    );
                    echo vsprintf( '<div class="updated"><p>%s</p></div>', [ $msg ] );
                    $fields['entity']['index'] = 999;
                }
            }
        } );
 
    add_action( 'EVENT_SMARTLING_BEFORE_SERIALIZE_CONNENT',
        function ( $params ) {
            /**
             * @var \Smartling\Helpers\EventParameters\BeforeSerializeContentEventParameters $params
             */
            $paramsClassName = '\Smartling\Helpers\EventParameters\BeforeSerializeContentEventParameters';
            if ( \Smartling\Helpers\WordpressContentTypeHelper::CONTENT_TYPE_WIDGET
                 === $params->getSubmission()->getContentType()
            ) {
                if ( $params instanceof $paramsClassName ) {
                    $fields = $params->getPreparedFields();
                    $msg    = vsprintf(
                        'Step 2.<br>Checking the entity->index value : <b>%s</b>.',
                        [
                            $fields['entity']['index'],
                        ]
                    );
                    echo vsprintf( '<div class="updated"><p>%s</p></div>', [ $msg ] );
                }
            }
        } );
} );

Comments