Plural_Forms::execute() WordPress Method

This method is responsible for handling the submission of the plural forms form. It first validates the form data and then saves the settings to the database. If there are any errors, they are displayed to the user.

Plural_Forms::execute( int $n ) #

Execute the plural form function.


Parameters

$n

(int)(Required)Variable "n" to substitute.


Top ↑

Return

(int) Plural form value.


Top ↑

Source

File: wp-includes/pomo/plural-forms.php

		public function execute( $n ) {
			$stack = array();
			$i     = 0;
			$total = count( $this->tokens );
			while ( $i < $total ) {
				$next = $this->tokens[ $i ];
				$i++;
				if ( 'var' === $next[0] ) {
					$stack[] = $n;
					continue;
				} elseif ( 'value' === $next[0] ) {
					$stack[] = $next[1];
					continue;
				}

				// Only operators left.
				switch ( $next[1] ) {
					case '%':
						$v2      = array_pop( $stack );
						$v1      = array_pop( $stack );
						$stack[] = $v1 % $v2;
						break;

					case '||':
						$v2      = array_pop( $stack );
						$v1      = array_pop( $stack );
						$stack[] = $v1 || $v2;
						break;

					case '&&':
						$v2      = array_pop( $stack );
						$v1      = array_pop( $stack );
						$stack[] = $v1 && $v2;
						break;

					case '<':
						$v2      = array_pop( $stack );
						$v1      = array_pop( $stack );
						$stack[] = $v1 < $v2;
						break;

					case '<=':
						$v2      = array_pop( $stack );
						$v1      = array_pop( $stack );
						$stack[] = $v1 <= $v2;
						break;

					case '>':
						$v2      = array_pop( $stack );
						$v1      = array_pop( $stack );
						$stack[] = $v1 > $v2;
						break;

					case '>=':
						$v2      = array_pop( $stack );
						$v1      = array_pop( $stack );
						$stack[] = $v1 >= $v2;
						break;

					case '!=':
						$v2      = array_pop( $stack );
						$v1      = array_pop( $stack );
						$stack[] = $v1 != $v2;
						break;

					case '==':
						$v2      = array_pop( $stack );
						$v1      = array_pop( $stack );
						$stack[] = $v1 == $v2;
						break;

					case '?:':
						$v3      = array_pop( $stack );
						$v2      = array_pop( $stack );
						$v1      = array_pop( $stack );
						$stack[] = $v1 ? $v2 : $v3;
						break;

					default:
						throw new Exception( sprintf( 'Unknown operator "%s"', $next[1] ) );
				}
			}

			if ( count( $stack ) !== 1 ) {
				throw new Exception( 'Too many values remaining on the stack' );
			}

			return (int) $stack[0];
		}


Top ↑

Changelog

Changelog
VersionDescription
4.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.