WordPress.org

Make WordPress Core

Ticket #35905: 35905.diff

File 35905.diff, 2.1 KB (added by jorbin, 4 years ago)
  • tests/phpunit/tests/formatting/Smilies.php

     
    312312                // standard smilies, use_smilies: OFF
    313313                update_option( 'use_smilies', 0 );
    314314        }
     315
     316        /**
     317         * Test to ensure smilies can be removed with a filter
     318         *
     319         * @ticket 35905
     320         */
     321        public function test_smilies_filter_removes_smilies() {
     322                add_filter( 'smilies', array( $this, '_filter_remove_smilies' ) );
     323                smilies_init();
     324                remove_filter( 'smilies', array( $this, '_filter_remove_smilies' ) );
     325
     326                $txt = ':oops: I did it again';
     327
     328                $this->assertEquals( $txt, convert_smilies( $txt ) );
     329        }
     330
     331        /**
     332         * Test to ensure smilies can be added with a filter
     333         *
     334         * @ticket 35905
     335         */
     336        public function test_smilies_filter_adds_smilies() {
     337                add_filter( 'smilies', array( $this, '_filter_add_smilies' ) );
     338                smilies_init();
     339                remove_filter( 'smilies', array( $this, '_filter_add_smilies' ) );
     340
     341                $txt = 'You played with my <3';
     342                $expected_txt = 'You played with my \xe2\x9d\xa4';
     343
     344                $this->assertEquals( $expected_txt, convert_smilies( $txt ) );
     345        }
     346
     347
     348         public function _filter_remove_smilies( $wpsmiliestrans ) {
     349                unset( $wpsmiliestrans[':oops:'] );
     350                return $wpsmiliestrans;
     351         }
     352
     353         public function _filter_add_smilies( $wpsmiliestrans ) {
     354                $wpsmiliestrans['<3'] = '\xe2\x9d\xa4';
     355                return $wpsmiliestrans;
     356         }
    315357}
  • src/wp-includes/functions.php

     
    33423342                );
    33433343        }
    33443344
     3345        /**
     3346         * Filter all the smilies.
     3347         *
     3348         * This filter must be added before `smilies_init` is run, as
     3349         * it is normally only run once to setup the smilies regex.
     3350         *
     3351         * @since 4.6.0
     3352         *
     3353         * @param array $wpsmiliestrans List of the smilies.
     3354         */
     3355        $wpsmiliestrans = apply_filters('smilies', $wpsmiliestrans);
     3356
    33453357        if (count($wpsmiliestrans) == 0) {
    33463358                return;
    33473359        }