wp/wp-includes/shortcodes.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 21 48c4eec2b7e6
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    62  */
    62  */
    63 function add_shortcode( $tag, $callback ) {
    63 function add_shortcode( $tag, $callback ) {
    64 	global $shortcode_tags;
    64 	global $shortcode_tags;
    65 
    65 
    66 	if ( '' === trim( $tag ) ) {
    66 	if ( '' === trim( $tag ) ) {
    67 		$message = __( 'Invalid shortcode name: Empty name given.' );
    67 		_doing_it_wrong(
    68 		_doing_it_wrong( __FUNCTION__, $message, '4.4.0' );
    68 			__FUNCTION__,
       
    69 			__( 'Invalid shortcode name: Empty name given.' ),
       
    70 			'4.4.0'
       
    71 		);
    69 		return;
    72 		return;
    70 	}
    73 	}
    71 
    74 
    72 	if ( 0 !== preg_match( '@[<>&/\[\]\x00-\x20=]@', $tag ) ) {
    75 	if ( 0 !== preg_match( '@[<>&/\[\]\x00-\x20=]@', $tag ) ) {
    73 		/* translators: 1: Shortcode name, 2: Space-separated list of reserved characters. */
    76 		_doing_it_wrong(
    74 		$message = sprintf( __( 'Invalid shortcode name: %1$s. Do not use spaces or reserved characters: %2$s' ), $tag, '& / < > [ ] =' );
    77 			__FUNCTION__,
    75 		_doing_it_wrong( __FUNCTION__, $message, '4.4.0' );
    78 			sprintf(
       
    79 				/* translators: 1: Shortcode name, 2: Space-separated list of reserved characters. */
       
    80 				__( 'Invalid shortcode name: %1$s. Do not use spaces or reserved characters: %2$s' ),
       
    81 				$tag,
       
    82 				'& / < > [ ] ='
       
    83 			),
       
    84 			'4.4.0'
       
    85 		);
    76 		return;
    86 		return;
    77 	}
    87 	}
    78 
    88 
    79 	$shortcode_tags[ $tag ] = $callback;
    89 	$shortcode_tags[ $tag ] = $callback;
    80 }
    90 }
   250 	global $shortcode_tags;
   260 	global $shortcode_tags;
   251 
   261 
   252 	if ( empty( $tagnames ) ) {
   262 	if ( empty( $tagnames ) ) {
   253 		$tagnames = array_keys( $shortcode_tags );
   263 		$tagnames = array_keys( $shortcode_tags );
   254 	}
   264 	}
   255 	$tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
   265 	$tagregexp = implode( '|', array_map( 'preg_quote', $tagnames ) );
   256 
   266 
   257 	// WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag().
   267 	// WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag().
   258 	// Also, see shortcode_unautop() and shortcode.js.
   268 	// Also, see shortcode_unautop() and shortcode.js.
   259 
   269 
   260 	// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
   270 	// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
   290 }
   300 }
   291 
   301 
   292 /**
   302 /**
   293  * Regular Expression callable for do_shortcode() for calling shortcode hook.
   303  * Regular Expression callable for do_shortcode() for calling shortcode hook.
   294  *
   304  *
   295  * @see get_shortcode_regex for details of the match array contents.
   305  * @see get_shortcode_regex() for details of the match array contents.
   296  *
   306  *
   297  * @since 2.5.0
   307  * @since 2.5.0
   298  * @access private
   308  * @access private
   299  *
   309  *
   300  * @global array $shortcode_tags
   310  * @global array $shortcode_tags
   301  *
   311  *
   302  * @param array $m Regular expression match array
   312  * @param array $m Regular expression match array.
   303  * @return string|false False on failure.
   313  * @return string|false Shortcode output on success, false on failure.
   304  */
   314  */
   305 function do_shortcode_tag( $m ) {
   315 function do_shortcode_tag( $m ) {
   306 	global $shortcode_tags;
   316 	global $shortcode_tags;
   307 
   317 
   308 	// Allow [[foo]] syntax for escaping a tag.
   318 	// Allow [[foo]] syntax for escaping a tag.
   312 
   322 
   313 	$tag  = $m[2];
   323 	$tag  = $m[2];
   314 	$attr = shortcode_parse_atts( $m[3] );
   324 	$attr = shortcode_parse_atts( $m[3] );
   315 
   325 
   316 	if ( ! is_callable( $shortcode_tags[ $tag ] ) ) {
   326 	if ( ! is_callable( $shortcode_tags[ $tag ] ) ) {
   317 		/* translators: %s: Shortcode tag. */
   327 		_doing_it_wrong(
   318 		$message = sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag );
   328 			__FUNCTION__,
   319 		_doing_it_wrong( __FUNCTION__, $message, '4.3.0' );
   329 			/* translators: %s: Shortcode tag. */
       
   330 			sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag ),
       
   331 			'4.3.0'
       
   332 		);
   320 		return $m[0];
   333 		return $m[0];
   321 	}
   334 	}
   322 
   335 
   323 	/**
   336 	/**
   324 	 * Filters whether to call a shortcode callback.
   337 	 * Filters whether to call a shortcode callback.