repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
Behat/Behat
src/Behat/Behat/Context/Suite/Setup/SuiteWithContextsSetup.php
SuiteWithContextsSetup.findClasspathAndClass
private function findClasspathAndClass($class) { if (false !== $pos = strrpos($class, '\\')) { // namespaced class name $classpath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR; $classname = substr($class, $pos + 1); return array($classpath, $classname); } // PEAR-like class name $classpath = null; $classname = $class; return array($classpath, $classname); }
php
private function findClasspathAndClass($class) { if (false !== $pos = strrpos($class, '\\')) { // namespaced class name $classpath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR; $classname = substr($class, $pos + 1); return array($classpath, $classname); } // PEAR-like class name $classpath = null; $classname = $class; return array($classpath, $classname); }
[ "private", "function", "findClasspathAndClass", "(", "$", "class", ")", "{", "if", "(", "false", "!==", "$", "pos", "=", "strrpos", "(", "$", "class", ",", "'\\\\'", ")", ")", "{", "// namespaced class name", "$", "classpath", "=", "str_replace", "(", "'\\\\'", ",", "DIRECTORY_SEPARATOR", ",", "substr", "(", "$", "class", ",", "0", ",", "$", "pos", ")", ")", ".", "DIRECTORY_SEPARATOR", ";", "$", "classname", "=", "substr", "(", "$", "class", ",", "$", "pos", "+", "1", ")", ";", "return", "array", "(", "$", "classpath", ",", "$", "classname", ")", ";", "}", "// PEAR-like class name", "$", "classpath", "=", "null", ";", "$", "classname", "=", "$", "class", ";", "return", "array", "(", "$", "classpath", ",", "$", "classname", ")", ";", "}" ]
Finds classpath and classname from class. @param string $class @return array
[ "Finds", "classpath", "and", "classname", "from", "class", "." ]
eb6c5d39420a47c08344598b58ec5f8d26a75b9b
https://github.com/Behat/Behat/blob/eb6c5d39420a47c08344598b58ec5f8d26a75b9b/src/Behat/Behat/Context/Suite/Setup/SuiteWithContextsSetup.php#L230-L245
train
Behat/Behat
src/Behat/Behat/HelperContainer/Argument/ServicesResolver.php
ServicesResolver.resolveArgument
private function resolveArgument($value) { if (is_string($value) && 0 === mb_strpos($value, '@')) { return $this->container->get(mb_substr($value, 1)); } return $value; }
php
private function resolveArgument($value) { if (is_string($value) && 0 === mb_strpos($value, '@')) { return $this->container->get(mb_substr($value, 1)); } return $value; }
[ "private", "function", "resolveArgument", "(", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", "&&", "0", "===", "mb_strpos", "(", "$", "value", ",", "'@'", ")", ")", "{", "return", "$", "this", "->", "container", "->", "get", "(", "mb_substr", "(", "$", "value", ",", "1", ")", ")", ";", "}", "return", "$", "value", ";", "}" ]
Attempts to resolve singular argument from container. Convention is strings starting with `@` are considered services and are expected to be present in the container. @param mixed $value @return mixed @throws ContainerExceptionInterface
[ "Attempts", "to", "resolve", "singular", "argument", "from", "container", "." ]
eb6c5d39420a47c08344598b58ec5f8d26a75b9b
https://github.com/Behat/Behat/blob/eb6c5d39420a47c08344598b58ec5f8d26a75b9b/src/Behat/Behat/HelperContainer/Argument/ServicesResolver.php#L64-L71
train
Behat/Behat
src/Behat/Behat/Output/Printer/Formatter/ConsoleFormatter.php
ConsoleFormatter.replaceStyle
private function replaceStyle($match) { if (!$this->isDecorated()) { return $match[2]; } if ($this->hasStyle($match[1])) { $style = $this->getStyle($match[1]); } else { return $match[0]; } return $style->apply($match[2]); }
php
private function replaceStyle($match) { if (!$this->isDecorated()) { return $match[2]; } if ($this->hasStyle($match[1])) { $style = $this->getStyle($match[1]); } else { return $match[0]; } return $style->apply($match[2]); }
[ "private", "function", "replaceStyle", "(", "$", "match", ")", "{", "if", "(", "!", "$", "this", "->", "isDecorated", "(", ")", ")", "{", "return", "$", "match", "[", "2", "]", ";", "}", "if", "(", "$", "this", "->", "hasStyle", "(", "$", "match", "[", "1", "]", ")", ")", "{", "$", "style", "=", "$", "this", "->", "getStyle", "(", "$", "match", "[", "1", "]", ")", ";", "}", "else", "{", "return", "$", "match", "[", "0", "]", ";", "}", "return", "$", "style", "->", "apply", "(", "$", "match", "[", "2", "]", ")", ";", "}" ]
Replaces style of the output. @param array $match @return string The replaced style
[ "Replaces", "style", "of", "the", "output", "." ]
eb6c5d39420a47c08344598b58ec5f8d26a75b9b
https://github.com/Behat/Behat/blob/eb6c5d39420a47c08344598b58ec5f8d26a75b9b/src/Behat/Behat/Output/Printer/Formatter/ConsoleFormatter.php#L43-L56
train
Behat/Behat
src/Behat/Behat/Snippet/SnippetWriter.php
SnippetWriter.printSnippets
public function printSnippets(SnippetPrinter $printer, array $snippets) { $printableSnippets = array(); foreach ($snippets as $snippet) { foreach ($snippet->getTargets() as $target) { $targetSnippets = array(); if (isset($printableSnippets[$target])) { $targetSnippets = $printableSnippets[$target]; } $targetSnippets[] = $snippet; $printableSnippets[$target] = $targetSnippets; } } foreach ($printableSnippets as $target => $targetSnippets) { $printer->printSnippets($target, $targetSnippets); } }
php
public function printSnippets(SnippetPrinter $printer, array $snippets) { $printableSnippets = array(); foreach ($snippets as $snippet) { foreach ($snippet->getTargets() as $target) { $targetSnippets = array(); if (isset($printableSnippets[$target])) { $targetSnippets = $printableSnippets[$target]; } $targetSnippets[] = $snippet; $printableSnippets[$target] = $targetSnippets; } } foreach ($printableSnippets as $target => $targetSnippets) { $printer->printSnippets($target, $targetSnippets); } }
[ "public", "function", "printSnippets", "(", "SnippetPrinter", "$", "printer", ",", "array", "$", "snippets", ")", "{", "$", "printableSnippets", "=", "array", "(", ")", ";", "foreach", "(", "$", "snippets", "as", "$", "snippet", ")", "{", "foreach", "(", "$", "snippet", "->", "getTargets", "(", ")", "as", "$", "target", ")", "{", "$", "targetSnippets", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "printableSnippets", "[", "$", "target", "]", ")", ")", "{", "$", "targetSnippets", "=", "$", "printableSnippets", "[", "$", "target", "]", ";", "}", "$", "targetSnippets", "[", "]", "=", "$", "snippet", ";", "$", "printableSnippets", "[", "$", "target", "]", "=", "$", "targetSnippets", ";", "}", "}", "foreach", "(", "$", "printableSnippets", "as", "$", "target", "=>", "$", "targetSnippets", ")", "{", "$", "printer", "->", "printSnippets", "(", "$", "target", ",", "$", "targetSnippets", ")", ";", "}", "}" ]
Prints snippets using provided printer. @param SnippetPrinter $printer @param AggregateSnippet[] $snippets
[ "Prints", "snippets", "using", "provided", "printer", "." ]
eb6c5d39420a47c08344598b58ec5f8d26a75b9b
https://github.com/Behat/Behat/blob/eb6c5d39420a47c08344598b58ec5f8d26a75b9b/src/Behat/Behat/Snippet/SnippetWriter.php#L56-L75
train
Behat/Behat
src/Behat/Behat/Snippet/SnippetWriter.php
SnippetWriter.printUndefinedSteps
public function printUndefinedSteps(SnippetPrinter $printer, array $undefinedSteps) { $printableSteps = array(); foreach ($undefinedSteps as $undefinedStep) { $suiteName = $undefinedStep->getEnvironment()->getSuite()->getName(); $step = $undefinedStep->getStep(); if (!isset($printableSteps[$suiteName])) { $printableSteps[$suiteName] = array(); } $printableSteps[$suiteName][$step->getText()] = $step; } foreach ($printableSteps as $suiteName => $steps) { $printer->printUndefinedSteps($suiteName, array_values($steps)); } }
php
public function printUndefinedSteps(SnippetPrinter $printer, array $undefinedSteps) { $printableSteps = array(); foreach ($undefinedSteps as $undefinedStep) { $suiteName = $undefinedStep->getEnvironment()->getSuite()->getName(); $step = $undefinedStep->getStep(); if (!isset($printableSteps[$suiteName])) { $printableSteps[$suiteName] = array(); } $printableSteps[$suiteName][$step->getText()] = $step; } foreach ($printableSteps as $suiteName => $steps) { $printer->printUndefinedSteps($suiteName, array_values($steps)); } }
[ "public", "function", "printUndefinedSteps", "(", "SnippetPrinter", "$", "printer", ",", "array", "$", "undefinedSteps", ")", "{", "$", "printableSteps", "=", "array", "(", ")", ";", "foreach", "(", "$", "undefinedSteps", "as", "$", "undefinedStep", ")", "{", "$", "suiteName", "=", "$", "undefinedStep", "->", "getEnvironment", "(", ")", "->", "getSuite", "(", ")", "->", "getName", "(", ")", ";", "$", "step", "=", "$", "undefinedStep", "->", "getStep", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "printableSteps", "[", "$", "suiteName", "]", ")", ")", "{", "$", "printableSteps", "[", "$", "suiteName", "]", "=", "array", "(", ")", ";", "}", "$", "printableSteps", "[", "$", "suiteName", "]", "[", "$", "step", "->", "getText", "(", ")", "]", "=", "$", "step", ";", "}", "foreach", "(", "$", "printableSteps", "as", "$", "suiteName", "=>", "$", "steps", ")", "{", "$", "printer", "->", "printUndefinedSteps", "(", "$", "suiteName", ",", "array_values", "(", "$", "steps", ")", ")", ";", "}", "}" ]
Prints undefined steps using provided printer. @param SnippetPrinter $printer @param UndefinedStep[] $undefinedSteps
[ "Prints", "undefined", "steps", "using", "provided", "printer", "." ]
eb6c5d39420a47c08344598b58ec5f8d26a75b9b
https://github.com/Behat/Behat/blob/eb6c5d39420a47c08344598b58ec5f8d26a75b9b/src/Behat/Behat/Snippet/SnippetWriter.php#L83-L100
train
Behat/Behat
src/Behat/Behat/Snippet/SnippetWriter.php
SnippetWriter.appendSnippet
private function appendSnippet(AggregateSnippet $snippet) { foreach ($this->appenders as $appender) { if (!$appender->supportsSnippet($snippet)) { continue; } $appender->appendSnippet($snippet); } }
php
private function appendSnippet(AggregateSnippet $snippet) { foreach ($this->appenders as $appender) { if (!$appender->supportsSnippet($snippet)) { continue; } $appender->appendSnippet($snippet); } }
[ "private", "function", "appendSnippet", "(", "AggregateSnippet", "$", "snippet", ")", "{", "foreach", "(", "$", "this", "->", "appenders", "as", "$", "appender", ")", "{", "if", "(", "!", "$", "appender", "->", "supportsSnippet", "(", "$", "snippet", ")", ")", "{", "continue", ";", "}", "$", "appender", "->", "appendSnippet", "(", "$", "snippet", ")", ";", "}", "}" ]
Appends snippet to appropriate targets. @param AggregateSnippet $snippet
[ "Appends", "snippet", "to", "appropriate", "targets", "." ]
eb6c5d39420a47c08344598b58ec5f8d26a75b9b
https://github.com/Behat/Behat/blob/eb6c5d39420a47c08344598b58ec5f8d26a75b9b/src/Behat/Behat/Snippet/SnippetWriter.php#L107-L116
train
Behat/Behat
src/Behat/Behat/Transformation/Transformer/RepositoryArgumentTransformer.php
RepositoryArgumentTransformer.applySimpleTransformations
private function applySimpleTransformations(array $transformations, DefinitionCall $definitionCall, $index, $value) { usort($transformations, function (SimpleArgumentTransformation $t1, SimpleArgumentTransformation $t2) { if ($t1->getPriority() == $t2->getPriority()) { return 0; } return ($t1->getPriority() > $t2->getPriority()) ? -1 : 1; }); $newValue = $value; foreach ($transformations as $transformation) { $newValue = $this->transform($definitionCall, $transformation, $index, $newValue); } return $newValue; }
php
private function applySimpleTransformations(array $transformations, DefinitionCall $definitionCall, $index, $value) { usort($transformations, function (SimpleArgumentTransformation $t1, SimpleArgumentTransformation $t2) { if ($t1->getPriority() == $t2->getPriority()) { return 0; } return ($t1->getPriority() > $t2->getPriority()) ? -1 : 1; }); $newValue = $value; foreach ($transformations as $transformation) { $newValue = $this->transform($definitionCall, $transformation, $index, $newValue); } return $newValue; }
[ "private", "function", "applySimpleTransformations", "(", "array", "$", "transformations", ",", "DefinitionCall", "$", "definitionCall", ",", "$", "index", ",", "$", "value", ")", "{", "usort", "(", "$", "transformations", ",", "function", "(", "SimpleArgumentTransformation", "$", "t1", ",", "SimpleArgumentTransformation", "$", "t2", ")", "{", "if", "(", "$", "t1", "->", "getPriority", "(", ")", "==", "$", "t2", "->", "getPriority", "(", ")", ")", "{", "return", "0", ";", "}", "return", "(", "$", "t1", "->", "getPriority", "(", ")", ">", "$", "t2", "->", "getPriority", "(", ")", ")", "?", "-", "1", ":", "1", ";", "}", ")", ";", "$", "newValue", "=", "$", "value", ";", "foreach", "(", "$", "transformations", "as", "$", "transformation", ")", "{", "$", "newValue", "=", "$", "this", "->", "transform", "(", "$", "definitionCall", ",", "$", "transformation", ",", "$", "index", ",", "$", "newValue", ")", ";", "}", "return", "$", "newValue", ";", "}" ]
Apply simple argument transformations in priority order. @param SimpleArgumentTransformation[] $transformations @param DefinitionCall $definitionCall @param integer|string $index @param mixed $value @return mixed
[ "Apply", "simple", "argument", "transformations", "in", "priority", "order", "." ]
eb6c5d39420a47c08344598b58ec5f8d26a75b9b
https://github.com/Behat/Behat/blob/eb6c5d39420a47c08344598b58ec5f8d26a75b9b/src/Behat/Behat/Transformation/Transformer/RepositoryArgumentTransformer.php#L115-L131
train
Behat/Behat
src/Behat/Behat/Transformation/Transformer/RepositoryArgumentTransformer.php
RepositoryArgumentTransformer.transform
private function transform(DefinitionCall $definitionCall, Transformation $transformation, $index, $value) { if (is_object($value) && !$value instanceof ArgumentInterface) { return $value; } if ($transformation instanceof SimpleArgumentTransformation && $transformation->supportsDefinitionAndArgument($definitionCall, $index, $value)) { return $transformation->transformArgument($this->callCenter, $definitionCall, $index, $value); } if ($transformation instanceof PatternTransformation && $transformation->supportsDefinitionAndArgument($this, $definitionCall, $value)) { return $transformation->transformArgument($this, $this->callCenter, $definitionCall, $value); } return $value; }
php
private function transform(DefinitionCall $definitionCall, Transformation $transformation, $index, $value) { if (is_object($value) && !$value instanceof ArgumentInterface) { return $value; } if ($transformation instanceof SimpleArgumentTransformation && $transformation->supportsDefinitionAndArgument($definitionCall, $index, $value)) { return $transformation->transformArgument($this->callCenter, $definitionCall, $index, $value); } if ($transformation instanceof PatternTransformation && $transformation->supportsDefinitionAndArgument($this, $definitionCall, $value)) { return $transformation->transformArgument($this, $this->callCenter, $definitionCall, $value); } return $value; }
[ "private", "function", "transform", "(", "DefinitionCall", "$", "definitionCall", ",", "Transformation", "$", "transformation", ",", "$", "index", ",", "$", "value", ")", "{", "if", "(", "is_object", "(", "$", "value", ")", "&&", "!", "$", "value", "instanceof", "ArgumentInterface", ")", "{", "return", "$", "value", ";", "}", "if", "(", "$", "transformation", "instanceof", "SimpleArgumentTransformation", "&&", "$", "transformation", "->", "supportsDefinitionAndArgument", "(", "$", "definitionCall", ",", "$", "index", ",", "$", "value", ")", ")", "{", "return", "$", "transformation", "->", "transformArgument", "(", "$", "this", "->", "callCenter", ",", "$", "definitionCall", ",", "$", "index", ",", "$", "value", ")", ";", "}", "if", "(", "$", "transformation", "instanceof", "PatternTransformation", "&&", "$", "transformation", "->", "supportsDefinitionAndArgument", "(", "$", "this", ",", "$", "definitionCall", ",", "$", "value", ")", ")", "{", "return", "$", "transformation", "->", "transformArgument", "(", "$", "this", ",", "$", "this", "->", "callCenter", ",", "$", "definitionCall", ",", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Transforms argument value using registered transformers. @param Transformation $transformation @param DefinitionCall $definitionCall @param integer|string $index @param mixed $value @return mixed
[ "Transforms", "argument", "value", "using", "registered", "transformers", "." ]
eb6c5d39420a47c08344598b58ec5f8d26a75b9b
https://github.com/Behat/Behat/blob/eb6c5d39420a47c08344598b58ec5f8d26a75b9b/src/Behat/Behat/Transformation/Transformer/RepositoryArgumentTransformer.php#L163-L180
train
Behat/Behat
src/Behat/Behat/Transformation/Transformer/RepositoryArgumentTransformer.php
RepositoryArgumentTransformer.splitSimpleAndNormalTransformations
private function splitSimpleAndNormalTransformations(array $transformations) { return array_reduce($transformations, function ($acc, $t) { return array( $t instanceof SimpleArgumentTransformation ? array_merge($acc[0], array($t)) : $acc[0], !$t instanceof SimpleArgumentTransformation ? array_merge($acc[1], array($t)) : $acc[1], ); }, array(array(), array())); }
php
private function splitSimpleAndNormalTransformations(array $transformations) { return array_reduce($transformations, function ($acc, $t) { return array( $t instanceof SimpleArgumentTransformation ? array_merge($acc[0], array($t)) : $acc[0], !$t instanceof SimpleArgumentTransformation ? array_merge($acc[1], array($t)) : $acc[1], ); }, array(array(), array())); }
[ "private", "function", "splitSimpleAndNormalTransformations", "(", "array", "$", "transformations", ")", "{", "return", "array_reduce", "(", "$", "transformations", ",", "function", "(", "$", "acc", ",", "$", "t", ")", "{", "return", "array", "(", "$", "t", "instanceof", "SimpleArgumentTransformation", "?", "array_merge", "(", "$", "acc", "[", "0", "]", ",", "array", "(", "$", "t", ")", ")", ":", "$", "acc", "[", "0", "]", ",", "!", "$", "t", "instanceof", "SimpleArgumentTransformation", "?", "array_merge", "(", "$", "acc", "[", "1", "]", ",", "array", "(", "$", "t", ")", ")", ":", "$", "acc", "[", "1", "]", ",", ")", ";", "}", ",", "array", "(", "array", "(", ")", ",", "array", "(", ")", ")", ")", ";", "}" ]
Splits transformations into simple and normal ones. @param Transformation[] $transformations @return array
[ "Splits", "transformations", "into", "simple", "and", "normal", "ones", "." ]
eb6c5d39420a47c08344598b58ec5f8d26a75b9b
https://github.com/Behat/Behat/blob/eb6c5d39420a47c08344598b58ec5f8d26a75b9b/src/Behat/Behat/Transformation/Transformer/RepositoryArgumentTransformer.php#L189-L197
train
Behat/Behat
src/Behat/Behat/Output/ServiceContainer/Formatter/ProgressFormatterFactory.php
ProgressFormatterFactory.loadRootNodeListener
protected function loadRootNodeListener(ContainerBuilder $container) { $definition = new Definition('Behat\Behat\Output\Node\EventListener\AST\StepListener', array( new Reference('output.node.printer.progress.step') )); $container->setDefinition(self::ROOT_LISTENER_ID, $definition); }
php
protected function loadRootNodeListener(ContainerBuilder $container) { $definition = new Definition('Behat\Behat\Output\Node\EventListener\AST\StepListener', array( new Reference('output.node.printer.progress.step') )); $container->setDefinition(self::ROOT_LISTENER_ID, $definition); }
[ "protected", "function", "loadRootNodeListener", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "definition", "=", "new", "Definition", "(", "'Behat\\Behat\\Output\\Node\\EventListener\\AST\\StepListener'", ",", "array", "(", "new", "Reference", "(", "'output.node.printer.progress.step'", ")", ")", ")", ";", "$", "container", "->", "setDefinition", "(", "self", "::", "ROOT_LISTENER_ID", ",", "$", "definition", ")", ";", "}" ]
Loads progress formatter node event listener. @param ContainerBuilder $container
[ "Loads", "progress", "formatter", "node", "event", "listener", "." ]
eb6c5d39420a47c08344598b58ec5f8d26a75b9b
https://github.com/Behat/Behat/blob/eb6c5d39420a47c08344598b58ec5f8d26a75b9b/src/Behat/Behat/Output/ServiceContainer/Formatter/ProgressFormatterFactory.php#L79-L85
train
Behat/Behat
src/Behat/Behat/Output/ServiceContainer/Formatter/ProgressFormatterFactory.php
ProgressFormatterFactory.loadCorePrinters
protected function loadCorePrinters(ContainerBuilder $container) { $definition = new Definition('Behat\Behat\Output\Node\Printer\CounterPrinter', array( new Reference(self::RESULT_TO_STRING_CONVERTER_ID), new Reference(TranslatorExtension::TRANSLATOR_ID), )); $container->setDefinition('output.node.printer.counter', $definition); $definition = new Definition('Behat\Behat\Output\Node\Printer\ListPrinter', array( new Reference(self::RESULT_TO_STRING_CONVERTER_ID), new Reference(ExceptionExtension::PRESENTER_ID), new Reference(TranslatorExtension::TRANSLATOR_ID), '%paths.base%' )); $container->setDefinition('output.node.printer.list', $definition); $definition = new Definition('Behat\Behat\Output\Node\Printer\Progress\ProgressStepPrinter', array( new Reference(self::RESULT_TO_STRING_CONVERTER_ID) )); $container->setDefinition('output.node.printer.progress.step', $definition); $definition = new Definition('Behat\Behat\Output\Node\Printer\Progress\ProgressStatisticsPrinter', array( new Reference('output.node.printer.counter'), new Reference('output.node.printer.list') )); $container->setDefinition('output.node.printer.progress.statistics', $definition); }
php
protected function loadCorePrinters(ContainerBuilder $container) { $definition = new Definition('Behat\Behat\Output\Node\Printer\CounterPrinter', array( new Reference(self::RESULT_TO_STRING_CONVERTER_ID), new Reference(TranslatorExtension::TRANSLATOR_ID), )); $container->setDefinition('output.node.printer.counter', $definition); $definition = new Definition('Behat\Behat\Output\Node\Printer\ListPrinter', array( new Reference(self::RESULT_TO_STRING_CONVERTER_ID), new Reference(ExceptionExtension::PRESENTER_ID), new Reference(TranslatorExtension::TRANSLATOR_ID), '%paths.base%' )); $container->setDefinition('output.node.printer.list', $definition); $definition = new Definition('Behat\Behat\Output\Node\Printer\Progress\ProgressStepPrinter', array( new Reference(self::RESULT_TO_STRING_CONVERTER_ID) )); $container->setDefinition('output.node.printer.progress.step', $definition); $definition = new Definition('Behat\Behat\Output\Node\Printer\Progress\ProgressStatisticsPrinter', array( new Reference('output.node.printer.counter'), new Reference('output.node.printer.list') )); $container->setDefinition('output.node.printer.progress.statistics', $definition); }
[ "protected", "function", "loadCorePrinters", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "definition", "=", "new", "Definition", "(", "'Behat\\Behat\\Output\\Node\\Printer\\CounterPrinter'", ",", "array", "(", "new", "Reference", "(", "self", "::", "RESULT_TO_STRING_CONVERTER_ID", ")", ",", "new", "Reference", "(", "TranslatorExtension", "::", "TRANSLATOR_ID", ")", ",", ")", ")", ";", "$", "container", "->", "setDefinition", "(", "'output.node.printer.counter'", ",", "$", "definition", ")", ";", "$", "definition", "=", "new", "Definition", "(", "'Behat\\Behat\\Output\\Node\\Printer\\ListPrinter'", ",", "array", "(", "new", "Reference", "(", "self", "::", "RESULT_TO_STRING_CONVERTER_ID", ")", ",", "new", "Reference", "(", "ExceptionExtension", "::", "PRESENTER_ID", ")", ",", "new", "Reference", "(", "TranslatorExtension", "::", "TRANSLATOR_ID", ")", ",", "'%paths.base%'", ")", ")", ";", "$", "container", "->", "setDefinition", "(", "'output.node.printer.list'", ",", "$", "definition", ")", ";", "$", "definition", "=", "new", "Definition", "(", "'Behat\\Behat\\Output\\Node\\Printer\\Progress\\ProgressStepPrinter'", ",", "array", "(", "new", "Reference", "(", "self", "::", "RESULT_TO_STRING_CONVERTER_ID", ")", ")", ")", ";", "$", "container", "->", "setDefinition", "(", "'output.node.printer.progress.step'", ",", "$", "definition", ")", ";", "$", "definition", "=", "new", "Definition", "(", "'Behat\\Behat\\Output\\Node\\Printer\\Progress\\ProgressStatisticsPrinter'", ",", "array", "(", "new", "Reference", "(", "'output.node.printer.counter'", ")", ",", "new", "Reference", "(", "'output.node.printer.list'", ")", ")", ")", ";", "$", "container", "->", "setDefinition", "(", "'output.node.printer.progress.statistics'", ",", "$", "definition", ")", ";", "}" ]
Loads feature, scenario and step printers. @param ContainerBuilder $container
[ "Loads", "feature", "scenario", "and", "step", "printers", "." ]
eb6c5d39420a47c08344598b58ec5f8d26a75b9b
https://github.com/Behat/Behat/blob/eb6c5d39420a47c08344598b58ec5f8d26a75b9b/src/Behat/Behat/Output/ServiceContainer/Formatter/ProgressFormatterFactory.php#L92-L118
train
lavary/crunz
src/Invoker.php
Invoker.call
public function call($closure, array $parameters = [], $buffer = false) { if ($buffer) { \ob_start(); } $rslt = \call_user_func_array($closure, $parameters); if ($buffer) { return \ob_get_clean(); } return $rslt; }
php
public function call($closure, array $parameters = [], $buffer = false) { if ($buffer) { \ob_start(); } $rslt = \call_user_func_array($closure, $parameters); if ($buffer) { return \ob_get_clean(); } return $rslt; }
[ "public", "function", "call", "(", "$", "closure", ",", "array", "$", "parameters", "=", "[", "]", ",", "$", "buffer", "=", "false", ")", "{", "if", "(", "$", "buffer", ")", "{", "\\", "ob_start", "(", ")", ";", "}", "$", "rslt", "=", "\\", "call_user_func_array", "(", "$", "closure", ",", "$", "parameters", ")", ";", "if", "(", "$", "buffer", ")", "{", "return", "\\", "ob_get_clean", "(", ")", ";", "}", "return", "$", "rslt", ";", "}" ]
Call the given Closure with buffering support. @param callable $closure
[ "Call", "the", "given", "Closure", "with", "buffering", "support", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Invoker.php#L14-L27
train
lavary/crunz
src/Event.php
Event.start
public function start() { $command = $this->buildCommand(); $process = Process::fromStringCommand($command); $this->setProcess($process); $this->getProcess()->start( function ($type, $content): void { $this->wholeOutput[] = $content; } ); if ($this->preventOverlapping) { $this->lock(); } /** @var int $pid */ $pid = $this->getProcess() ->getPid(); return $pid; }
php
public function start() { $command = $this->buildCommand(); $process = Process::fromStringCommand($command); $this->setProcess($process); $this->getProcess()->start( function ($type, $content): void { $this->wholeOutput[] = $content; } ); if ($this->preventOverlapping) { $this->lock(); } /** @var int $pid */ $pid = $this->getProcess() ->getPid(); return $pid; }
[ "public", "function", "start", "(", ")", "{", "$", "command", "=", "$", "this", "->", "buildCommand", "(", ")", ";", "$", "process", "=", "Process", "::", "fromStringCommand", "(", "$", "command", ")", ";", "$", "this", "->", "setProcess", "(", "$", "process", ")", ";", "$", "this", "->", "getProcess", "(", ")", "->", "start", "(", "function", "(", "$", "type", ",", "$", "content", ")", ":", "void", "{", "$", "this", "->", "wholeOutput", "[", "]", "=", "$", "content", ";", "}", ")", ";", "if", "(", "$", "this", "->", "preventOverlapping", ")", "{", "$", "this", "->", "lock", "(", ")", ";", "}", "/** @var int $pid */", "$", "pid", "=", "$", "this", "->", "getProcess", "(", ")", "->", "getPid", "(", ")", ";", "return", "$", "pid", ";", "}" ]
Start the event execution. @return int
[ "Start", "the", "event", "execution", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Event.php#L326-L347
train
lavary/crunz
src/Event.php
Event.cron
public function cron(string $expression): self { /** @var array $parts */ $parts = \preg_split( '/\s/', $expression, -1, PREG_SPLIT_NO_EMPTY ); if (\count($parts) > 5) { throw new TaskException("Expression '{$expression}' has more than five parts and this is not allowed."); } $this->expression = $expression; return $this; }
php
public function cron(string $expression): self { /** @var array $parts */ $parts = \preg_split( '/\s/', $expression, -1, PREG_SPLIT_NO_EMPTY ); if (\count($parts) > 5) { throw new TaskException("Expression '{$expression}' has more than five parts and this is not allowed."); } $this->expression = $expression; return $this; }
[ "public", "function", "cron", "(", "string", "$", "expression", ")", ":", "self", "{", "/** @var array $parts */", "$", "parts", "=", "\\", "preg_split", "(", "'/\\s/'", ",", "$", "expression", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", ")", ";", "if", "(", "\\", "count", "(", "$", "parts", ")", ">", "5", ")", "{", "throw", "new", "TaskException", "(", "\"Expression '{$expression}' has more than five parts and this is not allowed.\"", ")", ";", "}", "$", "this", "->", "expression", "=", "$", "expression", ";", "return", "$", "this", ";", "}" ]
The Cron expression representing the event's frequency. @throws TaskException
[ "The", "Cron", "expression", "representing", "the", "event", "s", "frequency", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Event.php#L354-L371
train
lavary/crunz
src/Event.php
Event.on
public function on($date) { $parsedDate = \date_parse($date); $segments = \array_intersect_key($parsedDate, $this->fieldsPosition); if ($parsedDate['year']) { $this->skip(static function () use ($parsedDate) { return (int) \date('Y') !== $parsedDate['year']; }); } foreach ($segments as $key => $value) { if (false !== $value) { $this->spliceIntoPosition($this->fieldsPosition[$key], (string) $value); } } return $this; }
php
public function on($date) { $parsedDate = \date_parse($date); $segments = \array_intersect_key($parsedDate, $this->fieldsPosition); if ($parsedDate['year']) { $this->skip(static function () use ($parsedDate) { return (int) \date('Y') !== $parsedDate['year']; }); } foreach ($segments as $key => $value) { if (false !== $value) { $this->spliceIntoPosition($this->fieldsPosition[$key], (string) $value); } } return $this; }
[ "public", "function", "on", "(", "$", "date", ")", "{", "$", "parsedDate", "=", "\\", "date_parse", "(", "$", "date", ")", ";", "$", "segments", "=", "\\", "array_intersect_key", "(", "$", "parsedDate", ",", "$", "this", "->", "fieldsPosition", ")", ";", "if", "(", "$", "parsedDate", "[", "'year'", "]", ")", "{", "$", "this", "->", "skip", "(", "static", "function", "(", ")", "use", "(", "$", "parsedDate", ")", "{", "return", "(", "int", ")", "\\", "date", "(", "'Y'", ")", "!==", "$", "parsedDate", "[", "'year'", "]", ";", "}", ")", ";", "}", "foreach", "(", "$", "segments", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "false", "!==", "$", "value", ")", "{", "$", "this", "->", "spliceIntoPosition", "(", "$", "this", "->", "fieldsPosition", "[", "$", "key", "]", ",", "(", "string", ")", "$", "value", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Schedule the event to run on a certain date. @param string $date @return $this
[ "Schedule", "the", "event", "to", "run", "on", "a", "certain", "date", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Event.php#L396-L414
train
lavary/crunz
src/Event.php
Event.weeklyOn
public function weeklyOn($day, $time = '0:0'): self { $this->dailyAt($time); return $this->spliceIntoPosition(5, (string) $day); }
php
public function weeklyOn($day, $time = '0:0'): self { $this->dailyAt($time); return $this->spliceIntoPosition(5, (string) $day); }
[ "public", "function", "weeklyOn", "(", "$", "day", ",", "$", "time", "=", "'0:0'", ")", ":", "self", "{", "$", "this", "->", "dailyAt", "(", "$", "time", ")", ";", "return", "$", "this", "->", "spliceIntoPosition", "(", "5", ",", "(", "string", ")", "$", "day", ")", ";", "}" ]
Schedule the event to run weekly on a given day and time. @param int|string $day @param string $time
[ "Schedule", "the", "event", "to", "run", "weekly", "on", "a", "given", "day", "and", "time", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Event.php#L573-L578
train
lavary/crunz
src/Event.php
Event.days
public function days($days): self { $days = \is_array($days) ? $days : \func_get_args(); return $this->spliceIntoPosition(5, \implode(',', $days)); }
php
public function days($days): self { $days = \is_array($days) ? $days : \func_get_args(); return $this->spliceIntoPosition(5, \implode(',', $days)); }
[ "public", "function", "days", "(", "$", "days", ")", ":", "self", "{", "$", "days", "=", "\\", "is_array", "(", "$", "days", ")", "?", "$", "days", ":", "\\", "func_get_args", "(", ")", ";", "return", "$", "this", "->", "spliceIntoPosition", "(", "5", ",", "\\", "implode", "(", "','", ",", "$", "days", ")", ")", ";", "}" ]
Set the days of the week the command should run on. @param mixed $days
[ "Set", "the", "days", "of", "the", "week", "the", "command", "should", "run", "on", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Event.php#L609-L614
train
lavary/crunz
src/Event.php
Event.minute
public function minute($value): self { $value = \is_array($value) ? $value : \func_get_args(); return $this->spliceIntoPosition(1, \implode(',', $value)); }
php
public function minute($value): self { $value = \is_array($value) ? $value : \func_get_args(); return $this->spliceIntoPosition(1, \implode(',', $value)); }
[ "public", "function", "minute", "(", "$", "value", ")", ":", "self", "{", "$", "value", "=", "\\", "is_array", "(", "$", "value", ")", "?", "$", "value", ":", "\\", "func_get_args", "(", ")", ";", "return", "$", "this", "->", "spliceIntoPosition", "(", "1", ",", "\\", "implode", "(", "','", ",", "$", "value", ")", ")", ";", "}" ]
Set minute for the cron job. @param mixed $value
[ "Set", "minute", "for", "the", "cron", "job", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Event.php#L633-L638
train
lavary/crunz
src/Event.php
Event.every
public function every($unit = null, $value = null): self { if (null === $unit || !isset($this->fieldsPosition[$unit])) { return $this; } $value = (1 === (int) $value) ? '*' : '*/' . $value; return $this->spliceIntoPosition($this->fieldsPosition[$unit], $value) ->applyMask($unit); }
php
public function every($unit = null, $value = null): self { if (null === $unit || !isset($this->fieldsPosition[$unit])) { return $this; } $value = (1 === (int) $value) ? '*' : '*/' . $value; return $this->spliceIntoPosition($this->fieldsPosition[$unit], $value) ->applyMask($unit); }
[ "public", "function", "every", "(", "$", "unit", "=", "null", ",", "$", "value", "=", "null", ")", ":", "self", "{", "if", "(", "null", "===", "$", "unit", "||", "!", "isset", "(", "$", "this", "->", "fieldsPosition", "[", "$", "unit", "]", ")", ")", "{", "return", "$", "this", ";", "}", "$", "value", "=", "(", "1", "===", "(", "int", ")", "$", "value", ")", "?", "'*'", ":", "'*/'", ".", "$", "value", ";", "return", "$", "this", "->", "spliceIntoPosition", "(", "$", "this", "->", "fieldsPosition", "[", "$", "unit", "]", ",", "$", "value", ")", "->", "applyMask", "(", "$", "unit", ")", ";", "}" ]
Another way to the frequency of the cron job.
[ "Another", "way", "to", "the", "frequency", "of", "the", "cron", "job", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Event.php#L876-L886
train
lavary/crunz
src/Event.php
Event.refreshLock
public function refreshLock(): void { if (!$this->preventOverlapping) { return; } $lock = $this->createLockObject(); $remainingLifetime = $lock->getRemainingLifetime(); // Lock will never expire if (null === $remainingLifetime) { return; } // Refresh 15s before lock expiration $lockRefreshNeeded = $remainingLifetime < 15; if ($lockRefreshNeeded) { $lock->refresh(); } }
php
public function refreshLock(): void { if (!$this->preventOverlapping) { return; } $lock = $this->createLockObject(); $remainingLifetime = $lock->getRemainingLifetime(); // Lock will never expire if (null === $remainingLifetime) { return; } // Refresh 15s before lock expiration $lockRefreshNeeded = $remainingLifetime < 15; if ($lockRefreshNeeded) { $lock->refresh(); } }
[ "public", "function", "refreshLock", "(", ")", ":", "void", "{", "if", "(", "!", "$", "this", "->", "preventOverlapping", ")", "{", "return", ";", "}", "$", "lock", "=", "$", "this", "->", "createLockObject", "(", ")", ";", "$", "remainingLifetime", "=", "$", "lock", "->", "getRemainingLifetime", "(", ")", ";", "// Lock will never expire", "if", "(", "null", "===", "$", "remainingLifetime", ")", "{", "return", ";", "}", "// Refresh 15s before lock expiration", "$", "lockRefreshNeeded", "=", "$", "remainingLifetime", "<", "15", ";", "if", "(", "$", "lockRefreshNeeded", ")", "{", "$", "lock", "->", "refresh", "(", ")", ";", "}", "}" ]
If this event is prevented from overlapping, this method should be called regularly to refresh the lock.
[ "If", "this", "event", "is", "prevented", "from", "overlapping", "this", "method", "should", "be", "called", "regularly", "to", "refresh", "the", "lock", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Event.php#L999-L1018
train
lavary/crunz
src/Event.php
Event.createLockObject
protected function createLockObject() { $this->checkLockFactory(); if (null === $this->lock && null !== $this->lockFactory) { $ttl = 30; $this->lock = $this->lockFactory ->createLock($this->lockKey(), $ttl); } return $this->lock; }
php
protected function createLockObject() { $this->checkLockFactory(); if (null === $this->lock && null !== $this->lockFactory) { $ttl = 30; $this->lock = $this->lockFactory ->createLock($this->lockKey(), $ttl); } return $this->lock; }
[ "protected", "function", "createLockObject", "(", ")", "{", "$", "this", "->", "checkLockFactory", "(", ")", ";", "if", "(", "null", "===", "$", "this", "->", "lock", "&&", "null", "!==", "$", "this", "->", "lockFactory", ")", "{", "$", "ttl", "=", "30", ";", "$", "this", "->", "lock", "=", "$", "this", "->", "lockFactory", "->", "createLock", "(", "$", "this", "->", "lockKey", "(", ")", ",", "$", "ttl", ")", ";", "}", "return", "$", "this", "->", "lock", ";", "}" ]
Get the symfony lock object for the task. @return Lock
[ "Get", "the", "symfony", "lock", "object", "for", "the", "task", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Event.php#L1025-L1037
train
lavary/crunz
src/Event.php
Event.serializeClosure
protected function serializeClosure(Closure $closure) { $closure = (new Serializer())->serialize($closure); $serializedClosure = \http_build_query([$closure]); $crunzRoot = CRUNZ_BIN; return PHP_BINARY . " {$crunzRoot} closure:run {$serializedClosure}"; }
php
protected function serializeClosure(Closure $closure) { $closure = (new Serializer())->serialize($closure); $serializedClosure = \http_build_query([$closure]); $crunzRoot = CRUNZ_BIN; return PHP_BINARY . " {$crunzRoot} closure:run {$serializedClosure}"; }
[ "protected", "function", "serializeClosure", "(", "Closure", "$", "closure", ")", "{", "$", "closure", "=", "(", "new", "Serializer", "(", ")", ")", "->", "serialize", "(", "$", "closure", ")", ";", "$", "serializedClosure", "=", "\\", "http_build_query", "(", "[", "$", "closure", "]", ")", ";", "$", "crunzRoot", "=", "CRUNZ_BIN", ";", "return", "PHP_BINARY", ".", "\" {$crunzRoot} closure:run {$serializedClosure}\"", ";", "}" ]
Convert closure to an executable command. @return string
[ "Convert", "closure", "to", "an", "executable", "command", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Event.php#L1077-L1084
train
lavary/crunz
src/Event.php
Event.applyMask
protected function applyMask($unit) { $cron = \explode(' ', $this->expression); $mask = ['0', '0', '1', '1', '*', '*']; $fpos = $this->fieldsPosition[$unit] - 1; \array_splice($cron, 0, $fpos, \array_slice($mask, 0, $fpos)); return $this->cron(\implode(' ', $cron)); }
php
protected function applyMask($unit) { $cron = \explode(' ', $this->expression); $mask = ['0', '0', '1', '1', '*', '*']; $fpos = $this->fieldsPosition[$unit] - 1; \array_splice($cron, 0, $fpos, \array_slice($mask, 0, $fpos)); return $this->cron(\implode(' ', $cron)); }
[ "protected", "function", "applyMask", "(", "$", "unit", ")", "{", "$", "cron", "=", "\\", "explode", "(", "' '", ",", "$", "this", "->", "expression", ")", ";", "$", "mask", "=", "[", "'0'", ",", "'0'", ",", "'1'", ",", "'1'", ",", "'*'", ",", "'*'", "]", ";", "$", "fpos", "=", "$", "this", "->", "fieldsPosition", "[", "$", "unit", "]", "-", "1", ";", "\\", "array_splice", "(", "$", "cron", ",", "0", ",", "$", "fpos", ",", "\\", "array_slice", "(", "$", "mask", ",", "0", ",", "$", "fpos", ")", ")", ";", "return", "$", "this", "->", "cron", "(", "\\", "implode", "(", "' '", ",", "$", "cron", ")", ")", ";", "}" ]
Mask a cron expression. @param string $unit @return self
[ "Mask", "a", "cron", "expression", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Event.php#L1160-L1169
train
lavary/crunz
src/Console/Command/TaskGeneratorCommand.php
TaskGeneratorCommand.save
protected function save() { $filename = Path::create([$this->outputPath(), $this->outputFile()]); return (bool) \file_put_contents($filename->toString(), $this->stub); }
php
protected function save() { $filename = Path::create([$this->outputPath(), $this->outputFile()]); return (bool) \file_put_contents($filename->toString(), $this->stub); }
[ "protected", "function", "save", "(", ")", "{", "$", "filename", "=", "Path", "::", "create", "(", "[", "$", "this", "->", "outputPath", "(", ")", ",", "$", "this", "->", "outputFile", "(", ")", "]", ")", ";", "return", "(", "bool", ")", "\\", "file_put_contents", "(", "$", "filename", "->", "toString", "(", ")", ",", "$", "this", "->", "stub", ")", ";", "}" ]
Save the generate task skeleton into a file. @return bool
[ "Save", "the", "generate", "task", "skeleton", "into", "a", "file", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Console/Command/TaskGeneratorCommand.php#L151-L156
train
lavary/crunz
src/Console/Command/TaskGeneratorCommand.php
TaskGeneratorCommand.outputPath
protected function outputPath() { $source = $this->config ->getSourcePath() ; $destination = $this->ask('Where do you want to save the file? (Press enter for the current directory)'); $outputPath = null !== $destination ? $destination : $source; if (!\file_exists($outputPath)) { \mkdir($outputPath, 0744, true); } return $outputPath; }
php
protected function outputPath() { $source = $this->config ->getSourcePath() ; $destination = $this->ask('Where do you want to save the file? (Press enter for the current directory)'); $outputPath = null !== $destination ? $destination : $source; if (!\file_exists($outputPath)) { \mkdir($outputPath, 0744, true); } return $outputPath; }
[ "protected", "function", "outputPath", "(", ")", "{", "$", "source", "=", "$", "this", "->", "config", "->", "getSourcePath", "(", ")", ";", "$", "destination", "=", "$", "this", "->", "ask", "(", "'Where do you want to save the file? (Press enter for the current directory)'", ")", ";", "$", "outputPath", "=", "null", "!==", "$", "destination", "?", "$", "destination", ":", "$", "source", ";", "if", "(", "!", "\\", "file_exists", "(", "$", "outputPath", ")", ")", "{", "\\", "mkdir", "(", "$", "outputPath", ",", "0744", ",", "true", ")", ";", "}", "return", "$", "outputPath", ";", "}" ]
Return the output path. @return string
[ "Return", "the", "output", "path", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Console/Command/TaskGeneratorCommand.php#L178-L191
train
lavary/crunz
src/Console/Command/TaskGeneratorCommand.php
TaskGeneratorCommand.getStub
protected function getStub() { $projectRootDirectory = $this->filesystem ->projectRootDirectory(); $path = Path::fromStrings( $projectRootDirectory, 'src', 'Stubs', \ucfirst($this->type() . 'Task.php') ); return $this->filesystem ->readContent($path->toString()); }
php
protected function getStub() { $projectRootDirectory = $this->filesystem ->projectRootDirectory(); $path = Path::fromStrings( $projectRootDirectory, 'src', 'Stubs', \ucfirst($this->type() . 'Task.php') ); return $this->filesystem ->readContent($path->toString()); }
[ "protected", "function", "getStub", "(", ")", "{", "$", "projectRootDirectory", "=", "$", "this", "->", "filesystem", "->", "projectRootDirectory", "(", ")", ";", "$", "path", "=", "Path", "::", "fromStrings", "(", "$", "projectRootDirectory", ",", "'src'", ",", "'Stubs'", ",", "\\", "ucfirst", "(", "$", "this", "->", "type", "(", ")", ".", "'Task.php'", ")", ")", ";", "return", "$", "this", "->", "filesystem", "->", "readContent", "(", "$", "path", "->", "toString", "(", ")", ")", ";", "}" ]
Get the task stub. @return string
[ "Get", "the", "task", "stub", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Console/Command/TaskGeneratorCommand.php#L212-L225
train
lavary/crunz
src/Console/Command/TaskGeneratorCommand.php
TaskGeneratorCommand.replaceFrequency
protected function replaceFrequency() { $this->stub = \str_replace('DummyFrequency', \rtrim($this->options['frequency'], '()'), $this->stub); return $this; }
php
protected function replaceFrequency() { $this->stub = \str_replace('DummyFrequency', \rtrim($this->options['frequency'], '()'), $this->stub); return $this; }
[ "protected", "function", "replaceFrequency", "(", ")", "{", "$", "this", "->", "stub", "=", "\\", "str_replace", "(", "'DummyFrequency'", ",", "\\", "rtrim", "(", "$", "this", "->", "options", "[", "'frequency'", "]", ",", "'()'", ")", ",", "$", "this", "->", "stub", ")", ";", "return", "$", "this", ";", "}" ]
Replace frequency.
[ "Replace", "frequency", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Console/Command/TaskGeneratorCommand.php#L240-L245
train
lavary/crunz
src/Console/Command/TaskGeneratorCommand.php
TaskGeneratorCommand.replaceConstraint
protected function replaceConstraint() { $this->stub = \str_replace('DummyConstraint', \rtrim($this->options['constraint'], '()'), $this->stub); return $this; }
php
protected function replaceConstraint() { $this->stub = \str_replace('DummyConstraint', \rtrim($this->options['constraint'], '()'), $this->stub); return $this; }
[ "protected", "function", "replaceConstraint", "(", ")", "{", "$", "this", "->", "stub", "=", "\\", "str_replace", "(", "'DummyConstraint'", ",", "\\", "rtrim", "(", "$", "this", "->", "options", "[", "'constraint'", "]", ",", "'()'", ")", ",", "$", "this", "->", "stub", ")", ";", "return", "$", "this", ";", "}" ]
Replace constraint.
[ "Replace", "constraint", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Console/Command/TaskGeneratorCommand.php#L250-L255
train
lavary/crunz
src/Schedule.php
Schedule.run
public function run($command, array $parameters = []) { if (\is_string($command) && \count($parameters)) { $command .= ' ' . $this->compileParameters($parameters); } $this->events[] = $event = new Event($this->id(), $command); return $event; }
php
public function run($command, array $parameters = []) { if (\is_string($command) && \count($parameters)) { $command .= ' ' . $this->compileParameters($parameters); } $this->events[] = $event = new Event($this->id(), $command); return $event; }
[ "public", "function", "run", "(", "$", "command", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "if", "(", "\\", "is_string", "(", "$", "command", ")", "&&", "\\", "count", "(", "$", "parameters", ")", ")", "{", "$", "command", ".=", "' '", ".", "$", "this", "->", "compileParameters", "(", "$", "parameters", ")", ";", "}", "$", "this", "->", "events", "[", "]", "=", "$", "event", "=", "new", "Event", "(", "$", "this", "->", "id", "(", ")", ",", "$", "command", ")", ";", "return", "$", "event", ";", "}" ]
Add a new event to the schedule object. @param string|\Closure $command @param array $parameters @return \Crunz\Event
[ "Add", "a", "new", "event", "to", "the", "schedule", "object", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Schedule.php#L50-L59
train
lavary/crunz
src/Schedule.php
Schedule.events
public function events(array $events = null) { if (null !== $events) { return $this->events = $events; } return $this->events; }
php
public function events(array $events = null) { if (null !== $events) { return $this->events = $events; } return $this->events; }
[ "public", "function", "events", "(", "array", "$", "events", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "events", ")", "{", "return", "$", "this", "->", "events", "=", "$", "events", ";", "}", "return", "$", "this", "->", "events", ";", "}" ]
Get or set the events of the schedule object. @param array $events @return Event[]
[ "Get", "or", "set", "the", "events", "of", "the", "schedule", "object", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Schedule.php#L152-L159
train
lavary/crunz
src/Schedule.php
Schedule.id
protected function id() { while (true) { $id = \uniqid('crunz', true); if (!\array_key_exists($id, $this->events)) { return $id; } } }
php
protected function id() { while (true) { $id = \uniqid('crunz', true); if (!\array_key_exists($id, $this->events)) { return $id; } } }
[ "protected", "function", "id", "(", ")", "{", "while", "(", "true", ")", "{", "$", "id", "=", "\\", "uniqid", "(", "'crunz'", ",", "true", ")", ";", "if", "(", "!", "\\", "array_key_exists", "(", "$", "id", ",", "$", "this", "->", "events", ")", ")", "{", "return", "$", "id", ";", "}", "}", "}" ]
Generate a unique task id. @return string
[ "Generate", "a", "unique", "task", "id", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Schedule.php#L195-L203
train
lavary/crunz
src/ProcessUtils.php
ProcessUtils.validateInput
public static function validateInput($caller, $input) { if (null !== $input) { if (\is_resource($input)) { return $input; } if (\is_string($input)) { return $input; } if (\is_scalar($input)) { return (string) $input; } if ($input instanceof Process) { return $input->getIterator($input::ITER_SKIP_ERR); } if ($input instanceof \Iterator) { return $input; } if ($input instanceof \Traversable) { return new \IteratorIterator($input); } throw new InvalidArgumentException(\sprintf('%s only accepts strings, Traversable objects or stream resources.', $caller)); } return $input; }
php
public static function validateInput($caller, $input) { if (null !== $input) { if (\is_resource($input)) { return $input; } if (\is_string($input)) { return $input; } if (\is_scalar($input)) { return (string) $input; } if ($input instanceof Process) { return $input->getIterator($input::ITER_SKIP_ERR); } if ($input instanceof \Iterator) { return $input; } if ($input instanceof \Traversable) { return new \IteratorIterator($input); } throw new InvalidArgumentException(\sprintf('%s only accepts strings, Traversable objects or stream resources.', $caller)); } return $input; }
[ "public", "static", "function", "validateInput", "(", "$", "caller", ",", "$", "input", ")", "{", "if", "(", "null", "!==", "$", "input", ")", "{", "if", "(", "\\", "is_resource", "(", "$", "input", ")", ")", "{", "return", "$", "input", ";", "}", "if", "(", "\\", "is_string", "(", "$", "input", ")", ")", "{", "return", "$", "input", ";", "}", "if", "(", "\\", "is_scalar", "(", "$", "input", ")", ")", "{", "return", "(", "string", ")", "$", "input", ";", "}", "if", "(", "$", "input", "instanceof", "Process", ")", "{", "return", "$", "input", "->", "getIterator", "(", "$", "input", "::", "ITER_SKIP_ERR", ")", ";", "}", "if", "(", "$", "input", "instanceof", "\\", "Iterator", ")", "{", "return", "$", "input", ";", "}", "if", "(", "$", "input", "instanceof", "\\", "Traversable", ")", "{", "return", "new", "\\", "IteratorIterator", "(", "$", "input", ")", ";", "}", "throw", "new", "InvalidArgumentException", "(", "\\", "sprintf", "(", "'%s only accepts strings, Traversable objects or stream resources.'", ",", "$", "caller", ")", ")", ";", "}", "return", "$", "input", ";", "}" ]
Validates and normalizes a Process input. @param string $caller The name of method call that validates the input @param mixed $input The input to validate @return mixed The validated input @throws InvalidArgumentException In case the input is not valid
[ "Validates", "and", "normalizes", "a", "Process", "input", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/ProcessUtils.php#L97-L123
train
lavary/crunz
src/Logger/Logger.php
Logger.addStream
public function addStream($path, $level, $bubble = true) { $handler = new StreamHandler( $path, $this->parseLevel($level), $bubble ); $handler->setFormatter($this->getDefaultFormatter()); $this->logger ->pushHandler($handler) ; return $this; }
php
public function addStream($path, $level, $bubble = true) { $handler = new StreamHandler( $path, $this->parseLevel($level), $bubble ); $handler->setFormatter($this->getDefaultFormatter()); $this->logger ->pushHandler($handler) ; return $this; }
[ "public", "function", "addStream", "(", "$", "path", ",", "$", "level", ",", "$", "bubble", "=", "true", ")", "{", "$", "handler", "=", "new", "StreamHandler", "(", "$", "path", ",", "$", "this", "->", "parseLevel", "(", "$", "level", ")", ",", "$", "bubble", ")", ";", "$", "handler", "->", "setFormatter", "(", "$", "this", "->", "getDefaultFormatter", "(", ")", ")", ";", "$", "this", "->", "logger", "->", "pushHandler", "(", "$", "handler", ")", ";", "return", "$", "this", ";", "}" ]
Create a neaw stream handler. @param string $path @param string $level @param bool $bubble @return self
[ "Create", "a", "neaw", "stream", "handler", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Logger/Logger.php#L55-L69
train
lavary/crunz
src/Logger/Logger.php
Logger.getDefaultFormatter
protected function getDefaultFormatter() { $allowLinebreaks = $this->configuration ->get('log_allow_line_breaks') ; return new LineFormatter( null, null, $allowLinebreaks, false ); }
php
protected function getDefaultFormatter() { $allowLinebreaks = $this->configuration ->get('log_allow_line_breaks') ; return new LineFormatter( null, null, $allowLinebreaks, false ); }
[ "protected", "function", "getDefaultFormatter", "(", ")", "{", "$", "allowLinebreaks", "=", "$", "this", "->", "configuration", "->", "get", "(", "'log_allow_line_breaks'", ")", ";", "return", "new", "LineFormatter", "(", "null", ",", "null", ",", "$", "allowLinebreaks", ",", "false", ")", ";", "}" ]
Get a default Monolog formatter instance. @return \Monolog\Formatter\LineFormatter
[ "Get", "a", "default", "Monolog", "formatter", "instance", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Logger/Logger.php#L113-L125
train
lavary/crunz
src/EventRunner.php
EventRunner.handle
public function handle(OutputInterface $output, array $schedules = []): void { $this->schedules = $schedules; $this->output = $output; foreach ($this->schedules as $schedule) { $this->consoleLogger ->debug("Invoke Schedule's ping before"); $this->pingBefore($schedule); // Running the before-callbacks of the current schedule $this->invoke($schedule->beforeCallbacks()); $events = $schedule->events(); foreach ($events as $event) { $this->start($event); } } // Watch events until they are finished $this->manageStartedEvents(); }
php
public function handle(OutputInterface $output, array $schedules = []): void { $this->schedules = $schedules; $this->output = $output; foreach ($this->schedules as $schedule) { $this->consoleLogger ->debug("Invoke Schedule's ping before"); $this->pingBefore($schedule); // Running the before-callbacks of the current schedule $this->invoke($schedule->beforeCallbacks()); $events = $schedule->events(); foreach ($events as $event) { $this->start($event); } } // Watch events until they are finished $this->manageStartedEvents(); }
[ "public", "function", "handle", "(", "OutputInterface", "$", "output", ",", "array", "$", "schedules", "=", "[", "]", ")", ":", "void", "{", "$", "this", "->", "schedules", "=", "$", "schedules", ";", "$", "this", "->", "output", "=", "$", "output", ";", "foreach", "(", "$", "this", "->", "schedules", "as", "$", "schedule", ")", "{", "$", "this", "->", "consoleLogger", "->", "debug", "(", "\"Invoke Schedule's ping before\"", ")", ";", "$", "this", "->", "pingBefore", "(", "$", "schedule", ")", ";", "// Running the before-callbacks of the current schedule", "$", "this", "->", "invoke", "(", "$", "schedule", "->", "beforeCallbacks", "(", ")", ")", ";", "$", "events", "=", "$", "schedule", "->", "events", "(", ")", ";", "foreach", "(", "$", "events", "as", "$", "event", ")", "{", "$", "this", "->", "start", "(", "$", "event", ")", ";", "}", "}", "// Watch events until they are finished", "$", "this", "->", "manageStartedEvents", "(", ")", ";", "}" ]
Handle an array of Schedule objects.
[ "Handle", "an", "array", "of", "Schedule", "objects", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/EventRunner.php#L83-L105
train
lavary/crunz
src/EventRunner.php
EventRunner.start
protected function start(Event $event): void { // if sendOutputTo or appendOutputTo have been specified if (!$event->nullOutput()) { // if sendOutputTo then truncate the log file if it exists if (!$event->shouldAppendOutput) { $f = @\fopen($event->output, 'r+'); if (false !== $f) { \ftruncate($f, 0); \fclose($f); } } // Create an instance of the Logger specific to the event $event->logger = $this->loggerFactory->create( [ // Logging streams 'info' => $event->output, ] ); } $this->consoleLogger ->debug("Invoke Event's ping before."); $this->pingBefore($event); // Running the before-callbacks $event->outputStream = ($this->invoke($event->beforeCallbacks())); $event->start(); }
php
protected function start(Event $event): void { // if sendOutputTo or appendOutputTo have been specified if (!$event->nullOutput()) { // if sendOutputTo then truncate the log file if it exists if (!$event->shouldAppendOutput) { $f = @\fopen($event->output, 'r+'); if (false !== $f) { \ftruncate($f, 0); \fclose($f); } } // Create an instance of the Logger specific to the event $event->logger = $this->loggerFactory->create( [ // Logging streams 'info' => $event->output, ] ); } $this->consoleLogger ->debug("Invoke Event's ping before."); $this->pingBefore($event); // Running the before-callbacks $event->outputStream = ($this->invoke($event->beforeCallbacks())); $event->start(); }
[ "protected", "function", "start", "(", "Event", "$", "event", ")", ":", "void", "{", "// if sendOutputTo or appendOutputTo have been specified", "if", "(", "!", "$", "event", "->", "nullOutput", "(", ")", ")", "{", "// if sendOutputTo then truncate the log file if it exists", "if", "(", "!", "$", "event", "->", "shouldAppendOutput", ")", "{", "$", "f", "=", "@", "\\", "fopen", "(", "$", "event", "->", "output", ",", "'r+'", ")", ";", "if", "(", "false", "!==", "$", "f", ")", "{", "\\", "ftruncate", "(", "$", "f", ",", "0", ")", ";", "\\", "fclose", "(", "$", "f", ")", ";", "}", "}", "// Create an instance of the Logger specific to the event", "$", "event", "->", "logger", "=", "$", "this", "->", "loggerFactory", "->", "create", "(", "[", "// Logging streams", "'info'", "=>", "$", "event", "->", "output", ",", "]", ")", ";", "}", "$", "this", "->", "consoleLogger", "->", "debug", "(", "\"Invoke Event's ping before.\"", ")", ";", "$", "this", "->", "pingBefore", "(", "$", "event", ")", ";", "// Running the before-callbacks", "$", "event", "->", "outputStream", "=", "(", "$", "this", "->", "invoke", "(", "$", "event", "->", "beforeCallbacks", "(", ")", ")", ")", ";", "$", "event", "->", "start", "(", ")", ";", "}" ]
Run an event process. @param \Crunz\Event $event
[ "Run", "an", "event", "process", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/EventRunner.php#L113-L142
train
lavary/crunz
src/EventRunner.php
EventRunner.manageStartedEvents
protected function manageStartedEvents(): void { while ($this->schedules) { foreach ($this->schedules as $scheduleKey => $schedule) { $events = $schedule->events(); // 10% chance that refresh will be called $refreshLocks = (\mt_rand(1, 100) <= 10); /** @var Event $event */ foreach ($events as $eventKey => $event) { if ($refreshLocks) { $event->refreshLock(); } $proc = $event->getProcess(); if ($proc->isRunning()) { continue; } $runStatus = ''; if ($proc->isSuccessful()) { $this->consoleLogger ->debug("Invoke Event's ping after."); $this->pingAfter($event); $runStatus = '<info>success</info>'; $event->outputStream .= $event->wholeOutput(); $event->outputStream .= $this->invoke($event->afterCallbacks()); $this->handleOutput($event); } else { $runStatus = '<error>fail</error>'; // Calling registered error callbacks with an instance of $event as argument $this->invoke($schedule->errorCallbacks(), [$event]); $this->handleError($event); } $id = $event->description ?: $event->getId(); $this->consoleLogger ->debug("Task <info>${id}</info> status: {$runStatus}."); // Dismiss the event if it's finished $schedule->dismissEvent($eventKey); } // If there's no event left for the Schedule instance, // run the schedule's after-callbacks and remove // the Schedule from list of active schedules. zzzwwscxqqqAAAQ11 if (!\count($schedule->events())) { $this->consoleLogger ->debug("Invoke Schedule's ping after."); $this->pingAfter($schedule); $this->invoke($schedule->afterCallbacks()); unset($this->schedules[$scheduleKey]); } } \usleep(250000); } }
php
protected function manageStartedEvents(): void { while ($this->schedules) { foreach ($this->schedules as $scheduleKey => $schedule) { $events = $schedule->events(); // 10% chance that refresh will be called $refreshLocks = (\mt_rand(1, 100) <= 10); /** @var Event $event */ foreach ($events as $eventKey => $event) { if ($refreshLocks) { $event->refreshLock(); } $proc = $event->getProcess(); if ($proc->isRunning()) { continue; } $runStatus = ''; if ($proc->isSuccessful()) { $this->consoleLogger ->debug("Invoke Event's ping after."); $this->pingAfter($event); $runStatus = '<info>success</info>'; $event->outputStream .= $event->wholeOutput(); $event->outputStream .= $this->invoke($event->afterCallbacks()); $this->handleOutput($event); } else { $runStatus = '<error>fail</error>'; // Calling registered error callbacks with an instance of $event as argument $this->invoke($schedule->errorCallbacks(), [$event]); $this->handleError($event); } $id = $event->description ?: $event->getId(); $this->consoleLogger ->debug("Task <info>${id}</info> status: {$runStatus}."); // Dismiss the event if it's finished $schedule->dismissEvent($eventKey); } // If there's no event left for the Schedule instance, // run the schedule's after-callbacks and remove // the Schedule from list of active schedules. zzzwwscxqqqAAAQ11 if (!\count($schedule->events())) { $this->consoleLogger ->debug("Invoke Schedule's ping after."); $this->pingAfter($schedule); $this->invoke($schedule->afterCallbacks()); unset($this->schedules[$scheduleKey]); } } \usleep(250000); } }
[ "protected", "function", "manageStartedEvents", "(", ")", ":", "void", "{", "while", "(", "$", "this", "->", "schedules", ")", "{", "foreach", "(", "$", "this", "->", "schedules", "as", "$", "scheduleKey", "=>", "$", "schedule", ")", "{", "$", "events", "=", "$", "schedule", "->", "events", "(", ")", ";", "// 10% chance that refresh will be called", "$", "refreshLocks", "=", "(", "\\", "mt_rand", "(", "1", ",", "100", ")", "<=", "10", ")", ";", "/** @var Event $event */", "foreach", "(", "$", "events", "as", "$", "eventKey", "=>", "$", "event", ")", "{", "if", "(", "$", "refreshLocks", ")", "{", "$", "event", "->", "refreshLock", "(", ")", ";", "}", "$", "proc", "=", "$", "event", "->", "getProcess", "(", ")", ";", "if", "(", "$", "proc", "->", "isRunning", "(", ")", ")", "{", "continue", ";", "}", "$", "runStatus", "=", "''", ";", "if", "(", "$", "proc", "->", "isSuccessful", "(", ")", ")", "{", "$", "this", "->", "consoleLogger", "->", "debug", "(", "\"Invoke Event's ping after.\"", ")", ";", "$", "this", "->", "pingAfter", "(", "$", "event", ")", ";", "$", "runStatus", "=", "'<info>success</info>'", ";", "$", "event", "->", "outputStream", ".=", "$", "event", "->", "wholeOutput", "(", ")", ";", "$", "event", "->", "outputStream", ".=", "$", "this", "->", "invoke", "(", "$", "event", "->", "afterCallbacks", "(", ")", ")", ";", "$", "this", "->", "handleOutput", "(", "$", "event", ")", ";", "}", "else", "{", "$", "runStatus", "=", "'<error>fail</error>'", ";", "// Calling registered error callbacks with an instance of $event as argument", "$", "this", "->", "invoke", "(", "$", "schedule", "->", "errorCallbacks", "(", ")", ",", "[", "$", "event", "]", ")", ";", "$", "this", "->", "handleError", "(", "$", "event", ")", ";", "}", "$", "id", "=", "$", "event", "->", "description", "?", ":", "$", "event", "->", "getId", "(", ")", ";", "$", "this", "->", "consoleLogger", "->", "debug", "(", "\"Task <info>${id}</info> status: {$runStatus}.\"", ")", ";", "// Dismiss the event if it's finished", "$", "schedule", "->", "dismissEvent", "(", "$", "eventKey", ")", ";", "}", "// If there's no event left for the Schedule instance,", "// run the schedule's after-callbacks and remove", "// the Schedule from list of active schedules. zzzwwscxqqqAAAQ11", "if", "(", "!", "\\", "count", "(", "$", "schedule", "->", "events", "(", ")", ")", ")", "{", "$", "this", "->", "consoleLogger", "->", "debug", "(", "\"Invoke Schedule's ping after.\"", ")", ";", "$", "this", "->", "pingAfter", "(", "$", "schedule", ")", ";", "$", "this", "->", "invoke", "(", "$", "schedule", "->", "afterCallbacks", "(", ")", ")", ";", "unset", "(", "$", "this", "->", "schedules", "[", "$", "scheduleKey", "]", ")", ";", "}", "}", "\\", "usleep", "(", "250000", ")", ";", "}", "}" ]
Manage the running processes.
[ "Manage", "the", "running", "processes", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/EventRunner.php#L147-L210
train
lavary/crunz
src/EventRunner.php
EventRunner.invoke
protected function invoke(array $callbacks = [], array $parameters = []) { $output = ''; foreach ($callbacks as $callback) { // Invoke the callback with buffering enabled $output .= $this->invoker->call($callback, $parameters, true); } return $output; }
php
protected function invoke(array $callbacks = [], array $parameters = []) { $output = ''; foreach ($callbacks as $callback) { // Invoke the callback with buffering enabled $output .= $this->invoker->call($callback, $parameters, true); } return $output; }
[ "protected", "function", "invoke", "(", "array", "$", "callbacks", "=", "[", "]", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "$", "output", "=", "''", ";", "foreach", "(", "$", "callbacks", "as", "$", "callback", ")", "{", "// Invoke the callback with buffering enabled", "$", "output", ".=", "$", "this", "->", "invoker", "->", "call", "(", "$", "callback", ",", "$", "parameters", ",", "true", ")", ";", "}", "return", "$", "output", ";", "}" ]
Invoke an array of callables. @param array $callbacks @param array $parameters @return string
[ "Invoke", "an", "array", "of", "callables", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/EventRunner.php#L220-L229
train
lavary/crunz
src/EventRunner.php
EventRunner.formatEventError
protected function formatEventError(Event $event) { return $event->description . '(' . $event->getCommandForDisplay() . ') ' . PHP_EOL . $event->wholeOutput() . PHP_EOL; }
php
protected function formatEventError(Event $event) { return $event->description . '(' . $event->getCommandForDisplay() . ') ' . PHP_EOL . $event->wholeOutput() . PHP_EOL; }
[ "protected", "function", "formatEventError", "(", "Event", "$", "event", ")", "{", "return", "$", "event", "->", "description", ".", "'('", ".", "$", "event", "->", "getCommandForDisplay", "(", ")", ".", "') '", ".", "PHP_EOL", ".", "$", "event", "->", "wholeOutput", "(", ")", ".", "PHP_EOL", ";", "}" ]
Format the event error message. @param \Crunz\Event $event @return string
[ "Format", "the", "event", "error", "message", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/EventRunner.php#L313-L322
train
lavary/crunz
src/Mailer.php
Mailer.getMailer
private function getMailer(): \Swift_Mailer { // If the mailer has already been defined via the constructor, return it. if ($this->mailer) { return $this->mailer; } // Get the proper transporter switch ($this->config('mailer.transport')) { case 'smtp': $transport = $this->getSmtpTransport(); break; case 'mail': throw new MailerException( "'mail' transport is no longer supported, please use 'smtp' or 'sendmail' transport." ); break; default: $transport = $this->getSendMailTransport(); } $this->mailer = new \Swift_Mailer($transport); return $this->mailer; }
php
private function getMailer(): \Swift_Mailer { // If the mailer has already been defined via the constructor, return it. if ($this->mailer) { return $this->mailer; } // Get the proper transporter switch ($this->config('mailer.transport')) { case 'smtp': $transport = $this->getSmtpTransport(); break; case 'mail': throw new MailerException( "'mail' transport is no longer supported, please use 'smtp' or 'sendmail' transport." ); break; default: $transport = $this->getSendMailTransport(); } $this->mailer = new \Swift_Mailer($transport); return $this->mailer; }
[ "private", "function", "getMailer", "(", ")", ":", "\\", "Swift_Mailer", "{", "// If the mailer has already been defined via the constructor, return it.", "if", "(", "$", "this", "->", "mailer", ")", "{", "return", "$", "this", "->", "mailer", ";", "}", "// Get the proper transporter", "switch", "(", "$", "this", "->", "config", "(", "'mailer.transport'", ")", ")", "{", "case", "'smtp'", ":", "$", "transport", "=", "$", "this", "->", "getSmtpTransport", "(", ")", ";", "break", ";", "case", "'mail'", ":", "throw", "new", "MailerException", "(", "\"'mail' transport is no longer supported, please use 'smtp' or 'sendmail' transport.\"", ")", ";", "break", ";", "default", ":", "$", "transport", "=", "$", "this", "->", "getSendMailTransport", "(", ")", ";", "}", "$", "this", "->", "mailer", "=", "new", "\\", "Swift_Mailer", "(", "$", "transport", ")", ";", "return", "$", "this", "->", "mailer", ";", "}" ]
Return the proper mailer. @throws MailerException
[ "Return", "the", "proper", "mailer", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Mailer.php#L41-L69
train
lavary/crunz
src/Mailer.php
Mailer.getSmtpTransport
private function getSmtpTransport(): \Swift_SmtpTransport { $object = new \Swift_SmtpTransport( $this->config('smtp.host'), $this->config('smtp.port'), $this->config('smtp.encryption') ); return $object ->setUsername($this->config('smtp.username')) ->setPassword($this->config('smtp.password')) ; }
php
private function getSmtpTransport(): \Swift_SmtpTransport { $object = new \Swift_SmtpTransport( $this->config('smtp.host'), $this->config('smtp.port'), $this->config('smtp.encryption') ); return $object ->setUsername($this->config('smtp.username')) ->setPassword($this->config('smtp.password')) ; }
[ "private", "function", "getSmtpTransport", "(", ")", ":", "\\", "Swift_SmtpTransport", "{", "$", "object", "=", "new", "\\", "Swift_SmtpTransport", "(", "$", "this", "->", "config", "(", "'smtp.host'", ")", ",", "$", "this", "->", "config", "(", "'smtp.port'", ")", ",", "$", "this", "->", "config", "(", "'smtp.encryption'", ")", ")", ";", "return", "$", "object", "->", "setUsername", "(", "$", "this", "->", "config", "(", "'smtp.username'", ")", ")", "->", "setPassword", "(", "$", "this", "->", "config", "(", "'smtp.password'", ")", ")", ";", "}" ]
Get the SMTP transport.
[ "Get", "the", "SMTP", "transport", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Mailer.php#L74-L86
train
lavary/crunz
src/Mailer.php
Mailer.getMessage
private function getMessage(string $subject, string $message): \Swift_Message { $messageObject = new \Swift_Message($subject, $message); $messageObject ->setFrom([$this->config('mailer.sender_email') => $this->config('mailer.sender_name')]) ->setTo($this->config('mailer.recipients')) ; return $messageObject; }
php
private function getMessage(string $subject, string $message): \Swift_Message { $messageObject = new \Swift_Message($subject, $message); $messageObject ->setFrom([$this->config('mailer.sender_email') => $this->config('mailer.sender_name')]) ->setTo($this->config('mailer.recipients')) ; return $messageObject; }
[ "private", "function", "getMessage", "(", "string", "$", "subject", ",", "string", "$", "message", ")", ":", "\\", "Swift_Message", "{", "$", "messageObject", "=", "new", "\\", "Swift_Message", "(", "$", "subject", ",", "$", "message", ")", ";", "$", "messageObject", "->", "setFrom", "(", "[", "$", "this", "->", "config", "(", "'mailer.sender_email'", ")", "=>", "$", "this", "->", "config", "(", "'mailer.sender_name'", ")", "]", ")", "->", "setTo", "(", "$", "this", "->", "config", "(", "'mailer.recipients'", ")", ")", ";", "return", "$", "messageObject", ";", "}" ]
Prepare a swift message object.
[ "Prepare", "a", "swift", "message", "object", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Mailer.php#L99-L108
train
lavary/crunz
src/Configuration/Configuration.php
Configuration.get
public function get(string $key, $default = null) { if (null === $this->config) { $this->config = $this->configurationParser ->parseConfig(); } if (\array_key_exists($key, $this->config)) { return $this->config[$key]; } $parts = \explode('.', $key); $value = $this->config; foreach ($parts as $part) { if (!\is_array($value) || !\array_key_exists($part, $value)) { return $default; } $value = $value[$part]; } return $value; }
php
public function get(string $key, $default = null) { if (null === $this->config) { $this->config = $this->configurationParser ->parseConfig(); } if (\array_key_exists($key, $this->config)) { return $this->config[$key]; } $parts = \explode('.', $key); $value = $this->config; foreach ($parts as $part) { if (!\is_array($value) || !\array_key_exists($part, $value)) { return $default; } $value = $value[$part]; } return $value; }
[ "public", "function", "get", "(", "string", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "null", "===", "$", "this", "->", "config", ")", "{", "$", "this", "->", "config", "=", "$", "this", "->", "configurationParser", "->", "parseConfig", "(", ")", ";", "}", "if", "(", "\\", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "config", ")", ")", "{", "return", "$", "this", "->", "config", "[", "$", "key", "]", ";", "}", "$", "parts", "=", "\\", "explode", "(", "'.'", ",", "$", "key", ")", ";", "$", "value", "=", "$", "this", "->", "config", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "if", "(", "!", "\\", "is_array", "(", "$", "value", ")", "||", "!", "\\", "array_key_exists", "(", "$", "part", ",", "$", "value", ")", ")", "{", "return", "$", "default", ";", "}", "$", "value", "=", "$", "value", "[", "$", "part", "]", ";", "}", "return", "$", "value", ";", "}" ]
Return a parameter based on a key. @param string $key @param mixed $default @return mixed
[ "Return", "a", "parameter", "based", "on", "a", "key", "." ]
a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e
https://github.com/lavary/crunz/blob/a9a4bf75f6ecb33ee620f7ee6eb8a73314429a9e/src/Configuration/Configuration.php#L33-L56
train
aristath/kirki
packages/kirki-framework/core/src/Sections.php
Sections.outer_sections_css
public function outer_sections_css() { echo '<style>'; $css = ''; if ( ! empty( Kirki::$sections ) ) { foreach ( Kirki::$sections as $section_args ) { if ( isset( $section_args['id'] ) && isset( $section_args['type'] ) && 'outer' === $section_args['type'] || 'kirki-outer' === $section_args['type'] ) { echo '#customize-theme-controls li#accordion-section-' . esc_html( $section_args['id'] ) . '{display:list-item!important;}'; } } } echo '</style>'; }
php
public function outer_sections_css() { echo '<style>'; $css = ''; if ( ! empty( Kirki::$sections ) ) { foreach ( Kirki::$sections as $section_args ) { if ( isset( $section_args['id'] ) && isset( $section_args['type'] ) && 'outer' === $section_args['type'] || 'kirki-outer' === $section_args['type'] ) { echo '#customize-theme-controls li#accordion-section-' . esc_html( $section_args['id'] ) . '{display:list-item!important;}'; } } } echo '</style>'; }
[ "public", "function", "outer_sections_css", "(", ")", "{", "echo", "'<style>'", ";", "$", "css", "=", "''", ";", "if", "(", "!", "empty", "(", "Kirki", "::", "$", "sections", ")", ")", "{", "foreach", "(", "Kirki", "::", "$", "sections", "as", "$", "section_args", ")", "{", "if", "(", "isset", "(", "$", "section_args", "[", "'id'", "]", ")", "&&", "isset", "(", "$", "section_args", "[", "'type'", "]", ")", "&&", "'outer'", "===", "$", "section_args", "[", "'type'", "]", "||", "'kirki-outer'", "===", "$", "section_args", "[", "'type'", "]", ")", "{", "echo", "'#customize-theme-controls li#accordion-section-'", ".", "esc_html", "(", "$", "section_args", "[", "'id'", "]", ")", ".", "'{display:list-item!important;}'", ";", "}", "}", "}", "echo", "'</style>'", ";", "}" ]
Generate CSS for the outer sections. These are by default hidden, we need to expose them. @since 3.0.17 @return void
[ "Generate", "CSS", "for", "the", "outer", "sections", ".", "These", "are", "by", "default", "hidden", "we", "need", "to", "expose", "them", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Sections.php#L37-L48
train
aristath/kirki
packages/kirki-framework/core/src/Setting/User_Meta.php
User_Meta.get_root_value
protected function get_root_value( $default = null ) { $id_base = $this->id_data['base']; // Get all user-meta. // We'll use this to check if the value is set or not, // in order to figure out if we need to return the default value. $user_meta = get_user_meta( get_current_user_id() ); // Get the single meta. $single_meta = get_user_meta( get_current_user_id(), $id_base, true ); if ( isset( $user_meta[ $id_base ] ) ) { return $single_meta; } return $default; }
php
protected function get_root_value( $default = null ) { $id_base = $this->id_data['base']; // Get all user-meta. // We'll use this to check if the value is set or not, // in order to figure out if we need to return the default value. $user_meta = get_user_meta( get_current_user_id() ); // Get the single meta. $single_meta = get_user_meta( get_current_user_id(), $id_base, true ); if ( isset( $user_meta[ $id_base ] ) ) { return $single_meta; } return $default; }
[ "protected", "function", "get_root_value", "(", "$", "default", "=", "null", ")", "{", "$", "id_base", "=", "$", "this", "->", "id_data", "[", "'base'", "]", ";", "// Get all user-meta.", "// We'll use this to check if the value is set or not,", "// in order to figure out if we need to return the default value.", "$", "user_meta", "=", "get_user_meta", "(", "get_current_user_id", "(", ")", ")", ";", "// Get the single meta.", "$", "single_meta", "=", "get_user_meta", "(", "get_current_user_id", "(", ")", ",", "$", "id_base", ",", "true", ")", ";", "if", "(", "isset", "(", "$", "user_meta", "[", "$", "id_base", "]", ")", ")", "{", "return", "$", "single_meta", ";", "}", "return", "$", "default", ";", "}" ]
Get the root value for a setting, especially for multidimensional ones. @access protected @since 3.0.0 @param mixed $default Value to return if root does not exist. @return mixed
[ "Get", "the", "root", "value", "for", "a", "setting", "especially", "for", "multidimensional", "ones", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Setting/User_Meta.php#L37-L52
train
aristath/kirki
packages/kirki-framework/core/src/Setting/User_Meta.php
User_Meta.set_root_value
protected function set_root_value( $value ) { $id_base = $this->id_data['base']; // First delete the current user-meta. // We're doing this to avoid duplicate entries. delete_user_meta( get_current_user_id(), $id_base ); // Update the user-meta. return update_user_meta( get_current_user_id(), $id_base, $value ); }
php
protected function set_root_value( $value ) { $id_base = $this->id_data['base']; // First delete the current user-meta. // We're doing this to avoid duplicate entries. delete_user_meta( get_current_user_id(), $id_base ); // Update the user-meta. return update_user_meta( get_current_user_id(), $id_base, $value ); }
[ "protected", "function", "set_root_value", "(", "$", "value", ")", "{", "$", "id_base", "=", "$", "this", "->", "id_data", "[", "'base'", "]", ";", "// First delete the current user-meta.", "// We're doing this to avoid duplicate entries.", "delete_user_meta", "(", "get_current_user_id", "(", ")", ",", "$", "id_base", ")", ";", "// Update the user-meta.", "return", "update_user_meta", "(", "get_current_user_id", "(", ")", ",", "$", "id_base", ",", "$", "value", ")", ";", "}" ]
Set the root value for a setting, especially for multidimensional ones. @access protected @since 3.0.0 @param mixed $value Value to set as root of multidimensional setting. @return bool Whether the multidimensional root was updated successfully.
[ "Set", "the", "root", "value", "for", "a", "setting", "especially", "for", "multidimensional", "ones", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Setting/User_Meta.php#L62-L71
train
aristath/kirki
packages/kirki-framework/module-postmessage/src/Module.php
Module.field_add_setting_args
public function field_add_setting_args( $args ) { if ( ! isset( $args['transport'] ) ) { return $args; } if ( 'postMessage' === $args['transport'] && isset( $args['js_vars'] ) && ! empty( $args['js_vars'] ) ) { $this->fields[] = $args; return $args; } if ( 'auto' === $args['transport'] ) { $args['js_vars'] = isset( $args['js_vars'] ) ? $args['js_vars'] : []; $args['js_vars'] = (array) $args['js_vars']; // Set transport to refresh initially. // Serves as a fallback in case we failt to auto-calculate js_vars. $args['transport'] = 'refresh'; // Try to auto-generate js_vars. // First we need to check if js_vars are empty, and that output is not empty. if ( empty( $args['js_vars'] ) && ! empty( $args['output'] ) ) { foreach ( $args['output'] as $output ) { $output['function'] = ( isset( $output['function'] ) ) ? $output['function'] : 'style'; // If 'element' is not defined, skip this. if ( ! isset( $output['element'] ) ) { continue; } if ( is_array( $output['element'] ) ) { $output['element'] = implode( ',', $output['element'] ); } // If there's a sanitize_callback defined skip this, unless we also have a js_callback defined. if ( isset( $output['sanitize_callback'] ) && ! empty( $output['sanitize_callback'] ) && ! isset( $output['js_callback'] ) ) { continue; } // If we got this far, it's safe to add this. $js_vars[] = $output; } } // Did we manage to get all the items from 'output'? // If not, then we're missing something so don't add this. if ( count( $js_vars ) !== count( $args['output'] ) ) { $js_vars = []; } $args['js_vars'] = $js_vars; if ( ! empty( $args['js_vars'] ) ) { $args['transport'] = 'postMessage'; } } $this->fields[] = $args; return $args; }
php
public function field_add_setting_args( $args ) { if ( ! isset( $args['transport'] ) ) { return $args; } if ( 'postMessage' === $args['transport'] && isset( $args['js_vars'] ) && ! empty( $args['js_vars'] ) ) { $this->fields[] = $args; return $args; } if ( 'auto' === $args['transport'] ) { $args['js_vars'] = isset( $args['js_vars'] ) ? $args['js_vars'] : []; $args['js_vars'] = (array) $args['js_vars']; // Set transport to refresh initially. // Serves as a fallback in case we failt to auto-calculate js_vars. $args['transport'] = 'refresh'; // Try to auto-generate js_vars. // First we need to check if js_vars are empty, and that output is not empty. if ( empty( $args['js_vars'] ) && ! empty( $args['output'] ) ) { foreach ( $args['output'] as $output ) { $output['function'] = ( isset( $output['function'] ) ) ? $output['function'] : 'style'; // If 'element' is not defined, skip this. if ( ! isset( $output['element'] ) ) { continue; } if ( is_array( $output['element'] ) ) { $output['element'] = implode( ',', $output['element'] ); } // If there's a sanitize_callback defined skip this, unless we also have a js_callback defined. if ( isset( $output['sanitize_callback'] ) && ! empty( $output['sanitize_callback'] ) && ! isset( $output['js_callback'] ) ) { continue; } // If we got this far, it's safe to add this. $js_vars[] = $output; } } // Did we manage to get all the items from 'output'? // If not, then we're missing something so don't add this. if ( count( $js_vars ) !== count( $args['output'] ) ) { $js_vars = []; } $args['js_vars'] = $js_vars; if ( ! empty( $args['js_vars'] ) ) { $args['transport'] = 'postMessage'; } } $this->fields[] = $args; return $args; }
[ "public", "function", "field_add_setting_args", "(", "$", "args", ")", "{", "if", "(", "!", "isset", "(", "$", "args", "[", "'transport'", "]", ")", ")", "{", "return", "$", "args", ";", "}", "if", "(", "'postMessage'", "===", "$", "args", "[", "'transport'", "]", "&&", "isset", "(", "$", "args", "[", "'js_vars'", "]", ")", "&&", "!", "empty", "(", "$", "args", "[", "'js_vars'", "]", ")", ")", "{", "$", "this", "->", "fields", "[", "]", "=", "$", "args", ";", "return", "$", "args", ";", "}", "if", "(", "'auto'", "===", "$", "args", "[", "'transport'", "]", ")", "{", "$", "args", "[", "'js_vars'", "]", "=", "isset", "(", "$", "args", "[", "'js_vars'", "]", ")", "?", "$", "args", "[", "'js_vars'", "]", ":", "[", "]", ";", "$", "args", "[", "'js_vars'", "]", "=", "(", "array", ")", "$", "args", "[", "'js_vars'", "]", ";", "// Set transport to refresh initially.", "// Serves as a fallback in case we failt to auto-calculate js_vars.", "$", "args", "[", "'transport'", "]", "=", "'refresh'", ";", "// Try to auto-generate js_vars.", "// First we need to check if js_vars are empty, and that output is not empty.", "if", "(", "empty", "(", "$", "args", "[", "'js_vars'", "]", ")", "&&", "!", "empty", "(", "$", "args", "[", "'output'", "]", ")", ")", "{", "foreach", "(", "$", "args", "[", "'output'", "]", "as", "$", "output", ")", "{", "$", "output", "[", "'function'", "]", "=", "(", "isset", "(", "$", "output", "[", "'function'", "]", ")", ")", "?", "$", "output", "[", "'function'", "]", ":", "'style'", ";", "// If 'element' is not defined, skip this.", "if", "(", "!", "isset", "(", "$", "output", "[", "'element'", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "is_array", "(", "$", "output", "[", "'element'", "]", ")", ")", "{", "$", "output", "[", "'element'", "]", "=", "implode", "(", "','", ",", "$", "output", "[", "'element'", "]", ")", ";", "}", "// If there's a sanitize_callback defined skip this, unless we also have a js_callback defined.", "if", "(", "isset", "(", "$", "output", "[", "'sanitize_callback'", "]", ")", "&&", "!", "empty", "(", "$", "output", "[", "'sanitize_callback'", "]", ")", "&&", "!", "isset", "(", "$", "output", "[", "'js_callback'", "]", ")", ")", "{", "continue", ";", "}", "// If we got this far, it's safe to add this.", "$", "js_vars", "[", "]", "=", "$", "output", ";", "}", "}", "// Did we manage to get all the items from 'output'?", "// If not, then we're missing something so don't add this.", "if", "(", "count", "(", "$", "js_vars", ")", "!==", "count", "(", "$", "args", "[", "'output'", "]", ")", ")", "{", "$", "js_vars", "=", "[", "]", ";", "}", "$", "args", "[", "'js_vars'", "]", "=", "$", "js_vars", ";", "if", "(", "!", "empty", "(", "$", "args", "[", "'js_vars'", "]", ")", ")", "{", "$", "args", "[", "'transport'", "]", "=", "'postMessage'", ";", "}", "}", "$", "this", "->", "fields", "[", "]", "=", "$", "args", ";", "return", "$", "args", ";", "}" ]
Filter setting args before adding the setting to the customizer. @access public @since 1.0 @param array $args The field arguments. @return void
[ "Filter", "setting", "args", "before", "adding", "the", "setting", "to", "the", "customizer", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-postmessage/src/Module.php#L82-L139
train
aristath/kirki
packages/kirki-framework/module-postmessage/src/Module.php
Module.postmessage
public function postmessage() { wp_enqueue_script( 'kirki_auto_postmessage', URL::get_from_path( __DIR__ . '/assets/scripts/script.js' ), [ 'jquery', 'customize-preview' ], KIRKI_VERSION, true ); $fields = array_merge( Kirki::$fields, $this->fields ); $data = []; foreach ( $fields as $field ) { if ( isset( $field['transport'] ) && 'postMessage' === $field['transport'] && isset( $field['js_vars'] ) && ! empty( $field['js_vars'] ) && is_array( $field['js_vars'] ) && isset( $field['settings'] ) ) { $data[] = $field; } } wp_localize_script( 'kirki_auto_postmessage', 'kirkiPostMessageFields', $data ); $extras = apply_filters( 'kirki_postmessage_script', false ); if ( $extras ) { wp_add_inline_script( 'kirki_auto_postmessage', $extras, 'after' ); } }
php
public function postmessage() { wp_enqueue_script( 'kirki_auto_postmessage', URL::get_from_path( __DIR__ . '/assets/scripts/script.js' ), [ 'jquery', 'customize-preview' ], KIRKI_VERSION, true ); $fields = array_merge( Kirki::$fields, $this->fields ); $data = []; foreach ( $fields as $field ) { if ( isset( $field['transport'] ) && 'postMessage' === $field['transport'] && isset( $field['js_vars'] ) && ! empty( $field['js_vars'] ) && is_array( $field['js_vars'] ) && isset( $field['settings'] ) ) { $data[] = $field; } } wp_localize_script( 'kirki_auto_postmessage', 'kirkiPostMessageFields', $data ); $extras = apply_filters( 'kirki_postmessage_script', false ); if ( $extras ) { wp_add_inline_script( 'kirki_auto_postmessage', $extras, 'after' ); } }
[ "public", "function", "postmessage", "(", ")", "{", "wp_enqueue_script", "(", "'kirki_auto_postmessage'", ",", "URL", "::", "get_from_path", "(", "__DIR__", ".", "'/assets/scripts/script.js'", ")", ",", "[", "'jquery'", ",", "'customize-preview'", "]", ",", "KIRKI_VERSION", ",", "true", ")", ";", "$", "fields", "=", "array_merge", "(", "Kirki", "::", "$", "fields", ",", "$", "this", "->", "fields", ")", ";", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "field", "[", "'transport'", "]", ")", "&&", "'postMessage'", "===", "$", "field", "[", "'transport'", "]", "&&", "isset", "(", "$", "field", "[", "'js_vars'", "]", ")", "&&", "!", "empty", "(", "$", "field", "[", "'js_vars'", "]", ")", "&&", "is_array", "(", "$", "field", "[", "'js_vars'", "]", ")", "&&", "isset", "(", "$", "field", "[", "'settings'", "]", ")", ")", "{", "$", "data", "[", "]", "=", "$", "field", ";", "}", "}", "wp_localize_script", "(", "'kirki_auto_postmessage'", ",", "'kirkiPostMessageFields'", ",", "$", "data", ")", ";", "$", "extras", "=", "apply_filters", "(", "'kirki_postmessage_script'", ",", "false", ")", ";", "if", "(", "$", "extras", ")", "{", "wp_add_inline_script", "(", "'kirki_auto_postmessage'", ",", "$", "extras", ",", "'after'", ")", ";", "}", "}" ]
Enqueues the postMessage script and adds variables to it using the wp_localize_script function. The rest is handled via JS.
[ "Enqueues", "the", "postMessage", "script", "and", "adds", "variables", "to", "it", "using", "the", "wp_localize_script", "function", ".", "The", "rest", "is", "handled", "via", "JS", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-postmessage/src/Module.php#L146-L160
train
aristath/kirki
packages/kirki-framework/module-css/src/Output.php
Output.apply_sanitize_callback
protected function apply_sanitize_callback( $output, $value ) { if ( isset( $output['sanitize_callback'] ) && null !== $output['sanitize_callback'] ) { // If the sanitize_callback is invalid, return the value. if ( ! is_callable( $output['sanitize_callback'] ) ) { return $value; } return call_user_func( $output['sanitize_callback'], $this->value ); } return $value; }
php
protected function apply_sanitize_callback( $output, $value ) { if ( isset( $output['sanitize_callback'] ) && null !== $output['sanitize_callback'] ) { // If the sanitize_callback is invalid, return the value. if ( ! is_callable( $output['sanitize_callback'] ) ) { return $value; } return call_user_func( $output['sanitize_callback'], $this->value ); } return $value; }
[ "protected", "function", "apply_sanitize_callback", "(", "$", "output", ",", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "output", "[", "'sanitize_callback'", "]", ")", "&&", "null", "!==", "$", "output", "[", "'sanitize_callback'", "]", ")", "{", "// If the sanitize_callback is invalid, return the value.", "if", "(", "!", "is_callable", "(", "$", "output", "[", "'sanitize_callback'", "]", ")", ")", "{", "return", "$", "value", ";", "}", "return", "call_user_func", "(", "$", "output", "[", "'sanitize_callback'", "]", ",", "$", "this", "->", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
If we have a sanitize_callback defined, apply it to the value. @param array $output The output args. @param string|array $value The value. @return string|array
[ "If", "we", "have", "a", "sanitize_callback", "defined", "apply", "it", "to", "the", "value", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-css/src/Output.php#L87-L97
train
aristath/kirki
packages/kirki-framework/module-css/src/Output.php
Output.parse_output
protected function parse_output() { foreach ( $this->output as $output ) { $skip = false; // Apply any sanitization callbacks defined. $value = $this->apply_sanitize_callback( $output, $this->value ); // Skip if value is empty. if ( '' === $this->value ) { $skip = true; } // No need to proceed this if the current value is the same as in the "exclude" value. if ( isset( $output['exclude'] ) && is_array( $output['exclude'] ) ) { foreach ( $output['exclude'] as $exclude ) { if ( is_array( $value ) ) { if ( is_array( $exclude ) ) { $diff1 = array_diff( $value, $exclude ); $diff2 = array_diff( $exclude, $value ); if ( empty( $diff1 ) && empty( $diff2 ) ) { $skip = true; } } // If 'choice' is defined check for sub-values too. // Fixes https://github.com/aristath/kirki/issues/1416. if ( isset( $output['choice'] ) && isset( $value[ $output['choice'] ] ) && $exclude == $value[ $output['choice'] ] ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison $skip = true; } } if ( $skip ) { continue; } // Skip if value is defined as excluded. if ( $exclude === $value || ( '' === $exclude && empty( $value ) ) ) { $skip = true; } } } if ( $skip ) { continue; } // Apply any value patterns defined. $value = $this->apply_value_pattern( $output, $value ); if ( isset( $output['element'] ) && is_array( $output['element'] ) ) { $output['element'] = array_unique( $output['element'] ); sort( $output['element'] ); $output['element'] = implode( ',', $output['element'] ); } $value = $this->process_value( $value, $output ); if ( ( is_admin() && ! is_customize_preview() ) || ( isset( $_GET['editor'] ) && '1' === $_GET['editor'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification // Check if this is an admin style. if ( ! isset( $output['context'] ) || ! in_array( 'editor', $output['context'], true ) ) { continue; } } elseif ( isset( $output['context'] ) && ! in_array( 'front', $output['context'], true ) ) { // Check if this is a frontend style. continue; } $this->process_output( $output, $value ); } }
php
protected function parse_output() { foreach ( $this->output as $output ) { $skip = false; // Apply any sanitization callbacks defined. $value = $this->apply_sanitize_callback( $output, $this->value ); // Skip if value is empty. if ( '' === $this->value ) { $skip = true; } // No need to proceed this if the current value is the same as in the "exclude" value. if ( isset( $output['exclude'] ) && is_array( $output['exclude'] ) ) { foreach ( $output['exclude'] as $exclude ) { if ( is_array( $value ) ) { if ( is_array( $exclude ) ) { $diff1 = array_diff( $value, $exclude ); $diff2 = array_diff( $exclude, $value ); if ( empty( $diff1 ) && empty( $diff2 ) ) { $skip = true; } } // If 'choice' is defined check for sub-values too. // Fixes https://github.com/aristath/kirki/issues/1416. if ( isset( $output['choice'] ) && isset( $value[ $output['choice'] ] ) && $exclude == $value[ $output['choice'] ] ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison $skip = true; } } if ( $skip ) { continue; } // Skip if value is defined as excluded. if ( $exclude === $value || ( '' === $exclude && empty( $value ) ) ) { $skip = true; } } } if ( $skip ) { continue; } // Apply any value patterns defined. $value = $this->apply_value_pattern( $output, $value ); if ( isset( $output['element'] ) && is_array( $output['element'] ) ) { $output['element'] = array_unique( $output['element'] ); sort( $output['element'] ); $output['element'] = implode( ',', $output['element'] ); } $value = $this->process_value( $value, $output ); if ( ( is_admin() && ! is_customize_preview() ) || ( isset( $_GET['editor'] ) && '1' === $_GET['editor'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification // Check if this is an admin style. if ( ! isset( $output['context'] ) || ! in_array( 'editor', $output['context'], true ) ) { continue; } } elseif ( isset( $output['context'] ) && ! in_array( 'front', $output['context'], true ) ) { // Check if this is a frontend style. continue; } $this->process_output( $output, $value ); } }
[ "protected", "function", "parse_output", "(", ")", "{", "foreach", "(", "$", "this", "->", "output", "as", "$", "output", ")", "{", "$", "skip", "=", "false", ";", "// Apply any sanitization callbacks defined.", "$", "value", "=", "$", "this", "->", "apply_sanitize_callback", "(", "$", "output", ",", "$", "this", "->", "value", ")", ";", "// Skip if value is empty.", "if", "(", "''", "===", "$", "this", "->", "value", ")", "{", "$", "skip", "=", "true", ";", "}", "// No need to proceed this if the current value is the same as in the \"exclude\" value.", "if", "(", "isset", "(", "$", "output", "[", "'exclude'", "]", ")", "&&", "is_array", "(", "$", "output", "[", "'exclude'", "]", ")", ")", "{", "foreach", "(", "$", "output", "[", "'exclude'", "]", "as", "$", "exclude", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "if", "(", "is_array", "(", "$", "exclude", ")", ")", "{", "$", "diff1", "=", "array_diff", "(", "$", "value", ",", "$", "exclude", ")", ";", "$", "diff2", "=", "array_diff", "(", "$", "exclude", ",", "$", "value", ")", ";", "if", "(", "empty", "(", "$", "diff1", ")", "&&", "empty", "(", "$", "diff2", ")", ")", "{", "$", "skip", "=", "true", ";", "}", "}", "// If 'choice' is defined check for sub-values too.", "// Fixes https://github.com/aristath/kirki/issues/1416.", "if", "(", "isset", "(", "$", "output", "[", "'choice'", "]", ")", "&&", "isset", "(", "$", "value", "[", "$", "output", "[", "'choice'", "]", "]", ")", "&&", "$", "exclude", "==", "$", "value", "[", "$", "output", "[", "'choice'", "]", "]", ")", "{", "// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison", "$", "skip", "=", "true", ";", "}", "}", "if", "(", "$", "skip", ")", "{", "continue", ";", "}", "// Skip if value is defined as excluded.", "if", "(", "$", "exclude", "===", "$", "value", "||", "(", "''", "===", "$", "exclude", "&&", "empty", "(", "$", "value", ")", ")", ")", "{", "$", "skip", "=", "true", ";", "}", "}", "}", "if", "(", "$", "skip", ")", "{", "continue", ";", "}", "// Apply any value patterns defined.", "$", "value", "=", "$", "this", "->", "apply_value_pattern", "(", "$", "output", ",", "$", "value", ")", ";", "if", "(", "isset", "(", "$", "output", "[", "'element'", "]", ")", "&&", "is_array", "(", "$", "output", "[", "'element'", "]", ")", ")", "{", "$", "output", "[", "'element'", "]", "=", "array_unique", "(", "$", "output", "[", "'element'", "]", ")", ";", "sort", "(", "$", "output", "[", "'element'", "]", ")", ";", "$", "output", "[", "'element'", "]", "=", "implode", "(", "','", ",", "$", "output", "[", "'element'", "]", ")", ";", "}", "$", "value", "=", "$", "this", "->", "process_value", "(", "$", "value", ",", "$", "output", ")", ";", "if", "(", "(", "is_admin", "(", ")", "&&", "!", "is_customize_preview", "(", ")", ")", "||", "(", "isset", "(", "$", "_GET", "[", "'editor'", "]", ")", "&&", "'1'", "===", "$", "_GET", "[", "'editor'", "]", ")", ")", "{", "// phpcs:ignore WordPress.Security.NonceVerification", "// Check if this is an admin style.", "if", "(", "!", "isset", "(", "$", "output", "[", "'context'", "]", ")", "||", "!", "in_array", "(", "'editor'", ",", "$", "output", "[", "'context'", "]", ",", "true", ")", ")", "{", "continue", ";", "}", "}", "elseif", "(", "isset", "(", "$", "output", "[", "'context'", "]", ")", "&&", "!", "in_array", "(", "'front'", ",", "$", "output", "[", "'context'", "]", ",", "true", ")", ")", "{", "// Check if this is a frontend style.", "continue", ";", "}", "$", "this", "->", "process_output", "(", "$", "output", ",", "$", "value", ")", ";", "}", "}" ]
Parses the output arguments. Calls the process_output method for each of them. @access protected
[ "Parses", "the", "output", "arguments", ".", "Calls", "the", "process_output", "method", "for", "each", "of", "them", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-css/src/Output.php#L195-L263
train
aristath/kirki
packages/kirki-framework/module-css/src/Output.php
Output.process_output
protected function process_output( $output, $value ) { if ( ! isset( $output['element'] ) || ! isset( $output['property'] ) ) { return; } $output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global'; $output['prefix'] = ( isset( $output['prefix'] ) ) ? $output['prefix'] : ''; $output['units'] = ( isset( $output['units'] ) ) ? $output['units'] : ''; $output['suffix'] = ( isset( $output['suffix'] ) ) ? $output['suffix'] : ''; // Properties that can accept multiple values. // Useful for example for gradients where all browsers use the "background-image" property // and the browser prefixes go in the value_pattern arg. $accepts_multiple = [ 'background-image', 'background', ]; if ( in_array( $output['property'], $accepts_multiple, true ) ) { if ( isset( $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] ) && ! is_array( $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] ) ) { $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = (array) $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ]; } $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ][] = $output['prefix'] . $value . $output['units'] . $output['suffix']; return; } if ( is_string( $value ) || is_numeric( $value ) ) { $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value ) . $output['units'] . $output['suffix']; } }
php
protected function process_output( $output, $value ) { if ( ! isset( $output['element'] ) || ! isset( $output['property'] ) ) { return; } $output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global'; $output['prefix'] = ( isset( $output['prefix'] ) ) ? $output['prefix'] : ''; $output['units'] = ( isset( $output['units'] ) ) ? $output['units'] : ''; $output['suffix'] = ( isset( $output['suffix'] ) ) ? $output['suffix'] : ''; // Properties that can accept multiple values. // Useful for example for gradients where all browsers use the "background-image" property // and the browser prefixes go in the value_pattern arg. $accepts_multiple = [ 'background-image', 'background', ]; if ( in_array( $output['property'], $accepts_multiple, true ) ) { if ( isset( $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] ) && ! is_array( $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] ) ) { $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = (array) $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ]; } $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ][] = $output['prefix'] . $value . $output['units'] . $output['suffix']; return; } if ( is_string( $value ) || is_numeric( $value ) ) { $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value ) . $output['units'] . $output['suffix']; } }
[ "protected", "function", "process_output", "(", "$", "output", ",", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "output", "[", "'element'", "]", ")", "||", "!", "isset", "(", "$", "output", "[", "'property'", "]", ")", ")", "{", "return", ";", "}", "$", "output", "[", "'media_query'", "]", "=", "(", "isset", "(", "$", "output", "[", "'media_query'", "]", ")", ")", "?", "$", "output", "[", "'media_query'", "]", ":", "'global'", ";", "$", "output", "[", "'prefix'", "]", "=", "(", "isset", "(", "$", "output", "[", "'prefix'", "]", ")", ")", "?", "$", "output", "[", "'prefix'", "]", ":", "''", ";", "$", "output", "[", "'units'", "]", "=", "(", "isset", "(", "$", "output", "[", "'units'", "]", ")", ")", "?", "$", "output", "[", "'units'", "]", ":", "''", ";", "$", "output", "[", "'suffix'", "]", "=", "(", "isset", "(", "$", "output", "[", "'suffix'", "]", ")", ")", "?", "$", "output", "[", "'suffix'", "]", ":", "''", ";", "// Properties that can accept multiple values.", "// Useful for example for gradients where all browsers use the \"background-image\" property", "// and the browser prefixes go in the value_pattern arg.", "$", "accepts_multiple", "=", "[", "'background-image'", ",", "'background'", ",", "]", ";", "if", "(", "in_array", "(", "$", "output", "[", "'property'", "]", ",", "$", "accepts_multiple", ",", "true", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "styles", "[", "$", "output", "[", "'media_query'", "]", "]", "[", "$", "output", "[", "'element'", "]", "]", "[", "$", "output", "[", "'property'", "]", "]", ")", "&&", "!", "is_array", "(", "$", "this", "->", "styles", "[", "$", "output", "[", "'media_query'", "]", "]", "[", "$", "output", "[", "'element'", "]", "]", "[", "$", "output", "[", "'property'", "]", "]", ")", ")", "{", "$", "this", "->", "styles", "[", "$", "output", "[", "'media_query'", "]", "]", "[", "$", "output", "[", "'element'", "]", "]", "[", "$", "output", "[", "'property'", "]", "]", "=", "(", "array", ")", "$", "this", "->", "styles", "[", "$", "output", "[", "'media_query'", "]", "]", "[", "$", "output", "[", "'element'", "]", "]", "[", "$", "output", "[", "'property'", "]", "]", ";", "}", "$", "this", "->", "styles", "[", "$", "output", "[", "'media_query'", "]", "]", "[", "$", "output", "[", "'element'", "]", "]", "[", "$", "output", "[", "'property'", "]", "]", "[", "]", "=", "$", "output", "[", "'prefix'", "]", ".", "$", "value", ".", "$", "output", "[", "'units'", "]", ".", "$", "output", "[", "'suffix'", "]", ";", "return", ";", "}", "if", "(", "is_string", "(", "$", "value", ")", "||", "is_numeric", "(", "$", "value", ")", ")", "{", "$", "this", "->", "styles", "[", "$", "output", "[", "'media_query'", "]", "]", "[", "$", "output", "[", "'element'", "]", "]", "[", "$", "output", "[", "'property'", "]", "]", "=", "$", "output", "[", "'prefix'", "]", ".", "$", "this", "->", "process_property_value", "(", "$", "output", "[", "'property'", "]", ",", "$", "value", ")", ".", "$", "output", "[", "'units'", "]", ".", "$", "output", "[", "'suffix'", "]", ";", "}", "}" ]
Parses an output and creates the styles array for it. @access protected @param array $output The field output. @param string|array $value The value. @return null
[ "Parses", "an", "output", "and", "creates", "the", "styles", "array", "for", "it", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-css/src/Output.php#L274-L300
train
aristath/kirki
packages/kirki-framework/module-css/src/Output.php
Output.process_property_value
protected function process_property_value( $property, $value ) { $properties = apply_filters( 'kirki_output_property_classnames', [ 'font-family' => '\Kirki\Modules\CSS\Property\Font_Family', 'background-image' => '\Kirki\Modules\CSS\Property\Background_Image', 'background-position' => '\Kirki\Modules\CSS\Property\Background_Position', ] ); if ( array_key_exists( $property, $properties ) ) { $classname = $properties[ $property ]; $obj = new $classname( $property, $value ); return $obj->get_value(); } return $value; }
php
protected function process_property_value( $property, $value ) { $properties = apply_filters( 'kirki_output_property_classnames', [ 'font-family' => '\Kirki\Modules\CSS\Property\Font_Family', 'background-image' => '\Kirki\Modules\CSS\Property\Background_Image', 'background-position' => '\Kirki\Modules\CSS\Property\Background_Position', ] ); if ( array_key_exists( $property, $properties ) ) { $classname = $properties[ $property ]; $obj = new $classname( $property, $value ); return $obj->get_value(); } return $value; }
[ "protected", "function", "process_property_value", "(", "$", "property", ",", "$", "value", ")", "{", "$", "properties", "=", "apply_filters", "(", "'kirki_output_property_classnames'", ",", "[", "'font-family'", "=>", "'\\Kirki\\Modules\\CSS\\Property\\Font_Family'", ",", "'background-image'", "=>", "'\\Kirki\\Modules\\CSS\\Property\\Background_Image'", ",", "'background-position'", "=>", "'\\Kirki\\Modules\\CSS\\Property\\Background_Position'", ",", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "property", ",", "$", "properties", ")", ")", "{", "$", "classname", "=", "$", "properties", "[", "$", "property", "]", ";", "$", "obj", "=", "new", "$", "classname", "(", "$", "property", ",", "$", "value", ")", ";", "return", "$", "obj", "->", "get_value", "(", ")", ";", "}", "return", "$", "value", ";", "}" ]
Some CSS properties are unique. We need to tweak the value to make everything works as expected. @access protected @param string $property The CSS property. @param string|array $value The value. @return array
[ "Some", "CSS", "properties", "are", "unique", ".", "We", "need", "to", "tweak", "the", "value", "to", "make", "everything", "works", "as", "expected", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-css/src/Output.php#L312-L327
train
aristath/kirki
packages/kirki-framework/module-css/src/Output.php
Output.process_value
protected function process_value( $value, $output ) { if ( isset( $output['property'] ) ) { return $this->process_property_value( $output['property'], $value ); } return $value; }
php
protected function process_value( $value, $output ) { if ( isset( $output['property'] ) ) { return $this->process_property_value( $output['property'], $value ); } return $value; }
[ "protected", "function", "process_value", "(", "$", "value", ",", "$", "output", ")", "{", "if", "(", "isset", "(", "$", "output", "[", "'property'", "]", ")", ")", "{", "return", "$", "this", "->", "process_property_value", "(", "$", "output", "[", "'property'", "]", ",", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Returns the value. @access protected @param string|array $value The value. @param array $output The field "output". @return string|array
[ "Returns", "the", "value", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-css/src/Output.php#L337-L342
train
aristath/kirki
packages/kirki-framework/url-getter/src/URL.php
URL.get_instance
public static function get_instance( $path ) { $path = \wp_normalize_path( $path ); if ( ! isset( self::$instances[ $path ] ) ) { self::$instances[ $path ] = new self( $path ); } return self::$instances[ $path ]; }
php
public static function get_instance( $path ) { $path = \wp_normalize_path( $path ); if ( ! isset( self::$instances[ $path ] ) ) { self::$instances[ $path ] = new self( $path ); } return self::$instances[ $path ]; }
[ "public", "static", "function", "get_instance", "(", "$", "path", ")", "{", "$", "path", "=", "\\", "wp_normalize_path", "(", "$", "path", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "instances", "[", "$", "path", "]", ")", ")", "{", "self", "::", "$", "instances", "[", "$", "path", "]", "=", "new", "self", "(", "$", "path", ")", ";", "}", "return", "self", "::", "$", "instances", "[", "$", "path", "]", ";", "}" ]
Gets an instance based on the path. @static @access public @since 1.0.2 @param string $path Absolute path to a file. @return URL An instance of this object.
[ "Gets", "an", "instance", "based", "on", "the", "path", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/url-getter/src/URL.php#L81-L87
train
aristath/kirki
packages/kirki-framework/url-getter/src/URL.php
URL.get_url
public function get_url() { /** * Start by replacing ABSPATH with site_url. * This is not accurate at all and only serves as a fallback in case everything else fails. */ $this->url = \str_replace( ABSPATH, \trailingslashit( \site_url() ), $this->path ); /** * If the file-path is inside wp-content replace the content-path with the content-url. * This serves as a fallback in case the other tests below fail. */ if ( false !== \strpos( $this->path, self::$content_path ) ) { $this->url = \str_replace( self::$content_path, self::$content_url, $this->path ); } /** * If the file is in a parent theme use the template directory. */ if ( $this->in_parent_theme() ) { $this->url = \get_template_directory_uri() . \str_replace( \get_template_directory(), '', $this->path ); } /** * If the file is in a child-theme use the stylesheet directory. */ if ( ! $this->in_parent_theme() && $this->in_child_theme() ) { $this->url = \get_stylesheet_directory_uri() . \str_replace( \get_stylesheet_directory(), '', $this->path ); } $this->url = \set_url_scheme( $this->url ); return \apply_filters( 'kirki_path_url', $this->url, $this->path ); }
php
public function get_url() { /** * Start by replacing ABSPATH with site_url. * This is not accurate at all and only serves as a fallback in case everything else fails. */ $this->url = \str_replace( ABSPATH, \trailingslashit( \site_url() ), $this->path ); /** * If the file-path is inside wp-content replace the content-path with the content-url. * This serves as a fallback in case the other tests below fail. */ if ( false !== \strpos( $this->path, self::$content_path ) ) { $this->url = \str_replace( self::$content_path, self::$content_url, $this->path ); } /** * If the file is in a parent theme use the template directory. */ if ( $this->in_parent_theme() ) { $this->url = \get_template_directory_uri() . \str_replace( \get_template_directory(), '', $this->path ); } /** * If the file is in a child-theme use the stylesheet directory. */ if ( ! $this->in_parent_theme() && $this->in_child_theme() ) { $this->url = \get_stylesheet_directory_uri() . \str_replace( \get_stylesheet_directory(), '', $this->path ); } $this->url = \set_url_scheme( $this->url ); return \apply_filters( 'kirki_path_url', $this->url, $this->path ); }
[ "public", "function", "get_url", "(", ")", "{", "/**\n\t\t * Start by replacing ABSPATH with site_url.\n\t\t * This is not accurate at all and only serves as a fallback in case everything else fails.\n\t\t */", "$", "this", "->", "url", "=", "\\", "str_replace", "(", "ABSPATH", ",", "\\", "trailingslashit", "(", "\\", "site_url", "(", ")", ")", ",", "$", "this", "->", "path", ")", ";", "/**\n\t\t * If the file-path is inside wp-content replace the content-path with the content-url.\n\t\t * This serves as a fallback in case the other tests below fail.\n\t\t */", "if", "(", "false", "!==", "\\", "strpos", "(", "$", "this", "->", "path", ",", "self", "::", "$", "content_path", ")", ")", "{", "$", "this", "->", "url", "=", "\\", "str_replace", "(", "self", "::", "$", "content_path", ",", "self", "::", "$", "content_url", ",", "$", "this", "->", "path", ")", ";", "}", "/**\n\t\t * If the file is in a parent theme use the template directory.\n\t\t */", "if", "(", "$", "this", "->", "in_parent_theme", "(", ")", ")", "{", "$", "this", "->", "url", "=", "\\", "get_template_directory_uri", "(", ")", ".", "\\", "str_replace", "(", "\\", "get_template_directory", "(", ")", ",", "''", ",", "$", "this", "->", "path", ")", ";", "}", "/**\n\t\t * If the file is in a child-theme use the stylesheet directory.\n\t\t */", "if", "(", "!", "$", "this", "->", "in_parent_theme", "(", ")", "&&", "$", "this", "->", "in_child_theme", "(", ")", ")", "{", "$", "this", "->", "url", "=", "\\", "get_stylesheet_directory_uri", "(", ")", ".", "\\", "str_replace", "(", "\\", "get_stylesheet_directory", "(", ")", ",", "''", ",", "$", "this", "->", "path", ")", ";", "}", "$", "this", "->", "url", "=", "\\", "set_url_scheme", "(", "$", "this", "->", "url", ")", ";", "return", "\\", "apply_filters", "(", "'kirki_path_url'", ",", "$", "this", "->", "url", ",", "$", "this", "->", "path", ")", ";", "}" ]
Get the file URL. @access public @since 1.0 @return string
[ "Get", "the", "file", "URL", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/url-getter/src/URL.php#L122-L154
train
aristath/kirki
packages/kirki-framework/control-color-palette/src/Field/Color_Palette.php
Color_Palette.sanitize
public static function sanitize( $value ) { if ( class_exists( '\Kirki\Field\Color' ) ) { return \Kirki\Field\Color::sanitize( $value ); } return esc_attr( $value ); }
php
public static function sanitize( $value ) { if ( class_exists( '\Kirki\Field\Color' ) ) { return \Kirki\Field\Color::sanitize( $value ); } return esc_attr( $value ); }
[ "public", "static", "function", "sanitize", "(", "$", "value", ")", "{", "if", "(", "class_exists", "(", "'\\Kirki\\Field\\Color'", ")", ")", "{", "return", "\\", "Kirki", "\\", "Field", "\\", "Color", "::", "sanitize", "(", "$", "value", ")", ";", "}", "return", "esc_attr", "(", "$", "value", ")", ";", "}" ]
Sanitization callback. @static @access public @since 1.0 @param string $value The color value. @return string
[ "Sanitization", "callback", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-color-palette/src/Field/Color_Palette.php#L57-L62
train
aristath/kirki
packages/kirki-framework/core/src/Modules.php
Modules.add_module
public static function add_module( $module ) { if ( ! in_array( $module, self::$modules, true ) ) { self::$modules[] = $module; } }
php
public static function add_module( $module ) { if ( ! in_array( $module, self::$modules, true ) ) { self::$modules[] = $module; } }
[ "public", "static", "function", "add_module", "(", "$", "module", ")", "{", "if", "(", "!", "in_array", "(", "$", "module", ",", "self", "::", "$", "modules", ",", "true", ")", ")", "{", "self", "::", "$", "modules", "[", "]", "=", "$", "module", ";", "}", "}" ]
Add a module. @static @access public @param string $module The classname of the module to add. @since 3.0.0
[ "Add", "a", "module", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Modules.php#L106-L110
train
aristath/kirki
packages/kirki-framework/core/src/Modules.php
Modules.remove_module
public static function remove_module( $module ) { $key = array_search( $module, self::$modules, true ); if ( false !== $key ) { unset( self::$modules[ $key ] ); } }
php
public static function remove_module( $module ) { $key = array_search( $module, self::$modules, true ); if ( false !== $key ) { unset( self::$modules[ $key ] ); } }
[ "public", "static", "function", "remove_module", "(", "$", "module", ")", "{", "$", "key", "=", "array_search", "(", "$", "module", ",", "self", "::", "$", "modules", ",", "true", ")", ";", "if", "(", "false", "!==", "$", "key", ")", "{", "unset", "(", "self", "::", "$", "modules", "[", "$", "key", "]", ")", ";", "}", "}" ]
Remove a module. @static @access public @param string $module The classname of the module to add. @since 3.0.0
[ "Remove", "a", "module", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Modules.php#L120-L125
train
aristath/kirki
packages/kirki-framework/control-select/src/Field/Preset.php
Preset.set_preset
protected function set_preset() { // Set preset from the choices. $this->preset = $this->choices; // We're using a flat select. foreach ( $this->choices as $key => $args ) { $this->choices[ $key ] = $args['label']; } }
php
protected function set_preset() { // Set preset from the choices. $this->preset = $this->choices; // We're using a flat select. foreach ( $this->choices as $key => $args ) { $this->choices[ $key ] = $args['label']; } }
[ "protected", "function", "set_preset", "(", ")", "{", "// Set preset from the choices.", "$", "this", "->", "preset", "=", "$", "this", "->", "choices", ";", "// We're using a flat select.", "foreach", "(", "$", "this", "->", "choices", "as", "$", "key", "=>", "$", "args", ")", "{", "$", "this", "->", "choices", "[", "$", "key", "]", "=", "$", "args", "[", "'label'", "]", ";", "}", "}" ]
Set the preset. @access protected @since 1.0
[ "Set", "the", "preset", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-select/src/Field/Preset.php#L36-L45
train
aristath/kirki
packages/kirki-framework/control-repeater/src/Control/Repeater.php
Repeater.row_label
protected function row_label( $args ) { // Validating args for row labels. if ( isset( $args['row_label'] ) && is_array( $args['row_label'] ) && ! empty( $args['row_label'] ) ) { // Validating row label type. if ( isset( $args['row_label']['type'] ) && ( 'text' === $args['row_label']['type'] || 'field' === $args['row_label']['type'] ) ) { $this->row_label['type'] = $args['row_label']['type']; } // Validating row label type. if ( isset( $args['row_label']['value'] ) && ! empty( $args['row_label']['value'] ) ) { $this->row_label['value'] = esc_html( $args['row_label']['value'] ); } // Validating row label field. if ( isset( $args['row_label']['field'] ) && ! empty( $args['row_label']['field'] ) && isset( $args['fields'][ sanitize_key( $args['row_label']['field'] ) ] ) ) { $this->row_label['field'] = esc_html( $args['row_label']['field'] ); } else { // If from field is not set correctly, making sure standard is set as the type. $this->row_label['type'] = 'text'; } } }
php
protected function row_label( $args ) { // Validating args for row labels. if ( isset( $args['row_label'] ) && is_array( $args['row_label'] ) && ! empty( $args['row_label'] ) ) { // Validating row label type. if ( isset( $args['row_label']['type'] ) && ( 'text' === $args['row_label']['type'] || 'field' === $args['row_label']['type'] ) ) { $this->row_label['type'] = $args['row_label']['type']; } // Validating row label type. if ( isset( $args['row_label']['value'] ) && ! empty( $args['row_label']['value'] ) ) { $this->row_label['value'] = esc_html( $args['row_label']['value'] ); } // Validating row label field. if ( isset( $args['row_label']['field'] ) && ! empty( $args['row_label']['field'] ) && isset( $args['fields'][ sanitize_key( $args['row_label']['field'] ) ] ) ) { $this->row_label['field'] = esc_html( $args['row_label']['field'] ); } else { // If from field is not set correctly, making sure standard is set as the type. $this->row_label['type'] = 'text'; } } }
[ "protected", "function", "row_label", "(", "$", "args", ")", "{", "// Validating args for row labels.", "if", "(", "isset", "(", "$", "args", "[", "'row_label'", "]", ")", "&&", "is_array", "(", "$", "args", "[", "'row_label'", "]", ")", "&&", "!", "empty", "(", "$", "args", "[", "'row_label'", "]", ")", ")", "{", "// Validating row label type.", "if", "(", "isset", "(", "$", "args", "[", "'row_label'", "]", "[", "'type'", "]", ")", "&&", "(", "'text'", "===", "$", "args", "[", "'row_label'", "]", "[", "'type'", "]", "||", "'field'", "===", "$", "args", "[", "'row_label'", "]", "[", "'type'", "]", ")", ")", "{", "$", "this", "->", "row_label", "[", "'type'", "]", "=", "$", "args", "[", "'row_label'", "]", "[", "'type'", "]", ";", "}", "// Validating row label type.", "if", "(", "isset", "(", "$", "args", "[", "'row_label'", "]", "[", "'value'", "]", ")", "&&", "!", "empty", "(", "$", "args", "[", "'row_label'", "]", "[", "'value'", "]", ")", ")", "{", "$", "this", "->", "row_label", "[", "'value'", "]", "=", "esc_html", "(", "$", "args", "[", "'row_label'", "]", "[", "'value'", "]", ")", ";", "}", "// Validating row label field.", "if", "(", "isset", "(", "$", "args", "[", "'row_label'", "]", "[", "'field'", "]", ")", "&&", "!", "empty", "(", "$", "args", "[", "'row_label'", "]", "[", "'field'", "]", ")", "&&", "isset", "(", "$", "args", "[", "'fields'", "]", "[", "sanitize_key", "(", "$", "args", "[", "'row_label'", "]", "[", "'field'", "]", ")", "]", ")", ")", "{", "$", "this", "->", "row_label", "[", "'field'", "]", "=", "esc_html", "(", "$", "args", "[", "'row_label'", "]", "[", "'field'", "]", ")", ";", "}", "else", "{", "// If from field is not set correctly, making sure standard is set as the type.", "$", "this", "->", "row_label", "[", "'type'", "]", "=", "'text'", ";", "}", "}", "}" ]
Validate row-labels. @access protected @since 1.0 @param array $args {@see WP_Customize_Control::__construct}. @return void
[ "Validate", "row", "-", "labels", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-repeater/src/Control/Repeater.php#L505-L528
train
aristath/kirki
packages/kirki-framework/module-css/src/Generator.php
Generator.css
public static function css( $field ) { // Set class vars. self::$settings = $field['settings']; self::$callback = isset( $field['sanitize_callback'] ) ? $field['sanitize_callback'] : ''; self::$field_type = $field['type']; self::$field_type = ( isset( $field['choices'] ) && isset( $field['choices']['parent_type'] ) ) ? $field['choices']['parent_type'] : self::$field_type; self::$output = $field['output']; if ( ! is_array( self::$output ) ) { self::$output = [ [ 'element' => self::$output, 'sanitize_callback' => null, ], ]; } // Get the value of this field. self::$value = Values::get_sanitized_field_value( $field ); // Find the class that will handle the outpout for this field. $classname = '\Kirki\Modules\CSS\Output'; $default_classnames = [ 'kirki-background' => '\Kirki\Modules\CSS\Field\Background', 'kirki-dimensions' => '\Kirki\Modules\CSS\Field\Dimensions', 'kirki-image' => '\Kirki\Modules\CSS\Field\Image', 'kirki-typography' => '\Kirki\Modules\CSS\Field\Typography', 'kirki-multicolor' => '\Kirki\Modules\CSS\Field\Multicolor', ]; $field_output_classes = apply_filters( 'kirki_output_control_classnames', $default_classnames ); $field_output_classes = apply_filters( "kirki_{$field['kirki_config']}_output_control_classnames", $field_output_classes ); if ( array_key_exists( self::$field_type, $field_output_classes ) ) { $classname = $field_output_classes[ self::$field_type ]; } $obj = new $classname( $field['kirki_config'], self::$output, self::$value, $field ); return $obj->get_styles(); }
php
public static function css( $field ) { // Set class vars. self::$settings = $field['settings']; self::$callback = isset( $field['sanitize_callback'] ) ? $field['sanitize_callback'] : ''; self::$field_type = $field['type']; self::$field_type = ( isset( $field['choices'] ) && isset( $field['choices']['parent_type'] ) ) ? $field['choices']['parent_type'] : self::$field_type; self::$output = $field['output']; if ( ! is_array( self::$output ) ) { self::$output = [ [ 'element' => self::$output, 'sanitize_callback' => null, ], ]; } // Get the value of this field. self::$value = Values::get_sanitized_field_value( $field ); // Find the class that will handle the outpout for this field. $classname = '\Kirki\Modules\CSS\Output'; $default_classnames = [ 'kirki-background' => '\Kirki\Modules\CSS\Field\Background', 'kirki-dimensions' => '\Kirki\Modules\CSS\Field\Dimensions', 'kirki-image' => '\Kirki\Modules\CSS\Field\Image', 'kirki-typography' => '\Kirki\Modules\CSS\Field\Typography', 'kirki-multicolor' => '\Kirki\Modules\CSS\Field\Multicolor', ]; $field_output_classes = apply_filters( 'kirki_output_control_classnames', $default_classnames ); $field_output_classes = apply_filters( "kirki_{$field['kirki_config']}_output_control_classnames", $field_output_classes ); if ( array_key_exists( self::$field_type, $field_output_classes ) ) { $classname = $field_output_classes[ self::$field_type ]; } $obj = new $classname( $field['kirki_config'], self::$output, self::$value, $field ); return $obj->get_styles(); }
[ "public", "static", "function", "css", "(", "$", "field", ")", "{", "// Set class vars.", "self", "::", "$", "settings", "=", "$", "field", "[", "'settings'", "]", ";", "self", "::", "$", "callback", "=", "isset", "(", "$", "field", "[", "'sanitize_callback'", "]", ")", "?", "$", "field", "[", "'sanitize_callback'", "]", ":", "''", ";", "self", "::", "$", "field_type", "=", "$", "field", "[", "'type'", "]", ";", "self", "::", "$", "field_type", "=", "(", "isset", "(", "$", "field", "[", "'choices'", "]", ")", "&&", "isset", "(", "$", "field", "[", "'choices'", "]", "[", "'parent_type'", "]", ")", ")", "?", "$", "field", "[", "'choices'", "]", "[", "'parent_type'", "]", ":", "self", "::", "$", "field_type", ";", "self", "::", "$", "output", "=", "$", "field", "[", "'output'", "]", ";", "if", "(", "!", "is_array", "(", "self", "::", "$", "output", ")", ")", "{", "self", "::", "$", "output", "=", "[", "[", "'element'", "=>", "self", "::", "$", "output", ",", "'sanitize_callback'", "=>", "null", ",", "]", ",", "]", ";", "}", "// Get the value of this field.", "self", "::", "$", "value", "=", "Values", "::", "get_sanitized_field_value", "(", "$", "field", ")", ";", "// Find the class that will handle the outpout for this field.", "$", "classname", "=", "'\\Kirki\\Modules\\CSS\\Output'", ";", "$", "default_classnames", "=", "[", "'kirki-background'", "=>", "'\\Kirki\\Modules\\CSS\\Field\\Background'", ",", "'kirki-dimensions'", "=>", "'\\Kirki\\Modules\\CSS\\Field\\Dimensions'", ",", "'kirki-image'", "=>", "'\\Kirki\\Modules\\CSS\\Field\\Image'", ",", "'kirki-typography'", "=>", "'\\Kirki\\Modules\\CSS\\Field\\Typography'", ",", "'kirki-multicolor'", "=>", "'\\Kirki\\Modules\\CSS\\Field\\Multicolor'", ",", "]", ";", "$", "field_output_classes", "=", "apply_filters", "(", "'kirki_output_control_classnames'", ",", "$", "default_classnames", ")", ";", "$", "field_output_classes", "=", "apply_filters", "(", "\"kirki_{$field['kirki_config']}_output_control_classnames\"", ",", "$", "field_output_classes", ")", ";", "if", "(", "array_key_exists", "(", "self", "::", "$", "field_type", ",", "$", "field_output_classes", ")", ")", "{", "$", "classname", "=", "$", "field_output_classes", "[", "self", "::", "$", "field_type", "]", ";", "}", "$", "obj", "=", "new", "$", "classname", "(", "$", "field", "[", "'kirki_config'", "]", ",", "self", "::", "$", "output", ",", "self", "::", "$", "value", ",", "$", "field", ")", ";", "return", "$", "obj", "->", "get_styles", "(", ")", ";", "}" ]
Get the CSS for a field. @static @access public @param array $field The field. @return array
[ "Get", "the", "CSS", "for", "a", "field", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-css/src/Generator.php#L151-L188
train
aristath/kirki
packages/kirki-framework/module-css/src/Generator.php
Generator.styles_parse
public static function styles_parse( $css = [] ) { // Pass our styles from the kirki_styles_array filter. $css = apply_filters( 'kirki_styles_array', $css ); // Process the array of CSS properties and produce the final CSS. $final_css = ''; if ( ! is_array( $css ) || empty( $css ) ) { return ''; } foreach ( $css as $media_query => $styles ) { $final_css .= ( 'global' !== $media_query ) ? $media_query . '{' : ''; foreach ( $styles as $style => $style_array ) { $css_for_style = ''; foreach ( $style_array as $property => $value ) { if ( is_string( $value ) && '' !== $value ) { $css_for_style .= $property . ':' . $value . ';'; } elseif ( is_array( $value ) ) { foreach ( $value as $subvalue ) { if ( is_string( $subvalue ) && '' !== $subvalue ) { $css_for_style .= $property . ':' . $subvalue . ';'; } } } $value = ( is_string( $value ) ) ? $value : ''; } if ( '' !== $css_for_style ) { $final_css .= $style . '{' . $css_for_style . '}'; } } $final_css .= ( 'global' !== $media_query ) ? '}' : ''; } return $final_css; }
php
public static function styles_parse( $css = [] ) { // Pass our styles from the kirki_styles_array filter. $css = apply_filters( 'kirki_styles_array', $css ); // Process the array of CSS properties and produce the final CSS. $final_css = ''; if ( ! is_array( $css ) || empty( $css ) ) { return ''; } foreach ( $css as $media_query => $styles ) { $final_css .= ( 'global' !== $media_query ) ? $media_query . '{' : ''; foreach ( $styles as $style => $style_array ) { $css_for_style = ''; foreach ( $style_array as $property => $value ) { if ( is_string( $value ) && '' !== $value ) { $css_for_style .= $property . ':' . $value . ';'; } elseif ( is_array( $value ) ) { foreach ( $value as $subvalue ) { if ( is_string( $subvalue ) && '' !== $subvalue ) { $css_for_style .= $property . ':' . $subvalue . ';'; } } } $value = ( is_string( $value ) ) ? $value : ''; } if ( '' !== $css_for_style ) { $final_css .= $style . '{' . $css_for_style . '}'; } } $final_css .= ( 'global' !== $media_query ) ? '}' : ''; } return $final_css; }
[ "public", "static", "function", "styles_parse", "(", "$", "css", "=", "[", "]", ")", "{", "// Pass our styles from the kirki_styles_array filter.", "$", "css", "=", "apply_filters", "(", "'kirki_styles_array'", ",", "$", "css", ")", ";", "// Process the array of CSS properties and produce the final CSS.", "$", "final_css", "=", "''", ";", "if", "(", "!", "is_array", "(", "$", "css", ")", "||", "empty", "(", "$", "css", ")", ")", "{", "return", "''", ";", "}", "foreach", "(", "$", "css", "as", "$", "media_query", "=>", "$", "styles", ")", "{", "$", "final_css", ".=", "(", "'global'", "!==", "$", "media_query", ")", "?", "$", "media_query", ".", "'{'", ":", "''", ";", "foreach", "(", "$", "styles", "as", "$", "style", "=>", "$", "style_array", ")", "{", "$", "css_for_style", "=", "''", ";", "foreach", "(", "$", "style_array", "as", "$", "property", "=>", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", "&&", "''", "!==", "$", "value", ")", "{", "$", "css_for_style", ".=", "$", "property", ".", "':'", ".", "$", "value", ".", "';'", ";", "}", "elseif", "(", "is_array", "(", "$", "value", ")", ")", "{", "foreach", "(", "$", "value", "as", "$", "subvalue", ")", "{", "if", "(", "is_string", "(", "$", "subvalue", ")", "&&", "''", "!==", "$", "subvalue", ")", "{", "$", "css_for_style", ".=", "$", "property", ".", "':'", ".", "$", "subvalue", ".", "';'", ";", "}", "}", "}", "$", "value", "=", "(", "is_string", "(", "$", "value", ")", ")", "?", "$", "value", ":", "''", ";", "}", "if", "(", "''", "!==", "$", "css_for_style", ")", "{", "$", "final_css", ".=", "$", "style", ".", "'{'", ".", "$", "css_for_style", ".", "'}'", ";", "}", "}", "$", "final_css", ".=", "(", "'global'", "!==", "$", "media_query", ")", "?", "'}'", ":", "''", ";", "}", "return", "$", "final_css", ";", "}" ]
Gets the array of generated styles and creates the minimized, inline CSS. @static @access public @param array $css The CSS definitions array. @return string The generated CSS.
[ "Gets", "the", "array", "of", "generated", "styles", "and", "creates", "the", "minimized", "inline", "CSS", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-css/src/Generator.php#L198-L232
train
aristath/kirki
packages/kirki-framework/module-css/src/Generator.php
Generator.add_prefixes
public static function add_prefixes( $css ) { if ( is_array( $css ) ) { foreach ( $css as $media_query => $elements ) { foreach ( $elements as $element => $style_array ) { foreach ( $style_array as $property => $value ) { // Add -webkit-* and -moz-*. if ( is_string( $property ) && in_array( $property, [ 'border-radius', 'box-shadow', 'box-sizing', 'text-shadow', 'transform', 'background-size', 'transition', 'transition-property', ], true ) ) { unset( $css[ $media_query ][ $element ][ $property ] ); $css[ $media_query ][ $element ][ '-webkit-' . $property ] = $value; $css[ $media_query ][ $element ][ '-moz-' . $property ] = $value; $css[ $media_query ][ $element ][ $property ] = $value; } // Add -ms-* and -o-*. if ( is_string( $property ) && in_array( $property, [ 'transform', 'background-size', 'transition', 'transition-property', ], true ) ) { unset( $css[ $media_query ][ $element ][ $property ] ); $css[ $media_query ][ $element ][ '-ms-' . $property ] = $value; $css[ $media_query ][ $element ][ '-o-' . $property ] = $value; $css[ $media_query ][ $element ][ $property ] = $value; } } } } } return $css; }
php
public static function add_prefixes( $css ) { if ( is_array( $css ) ) { foreach ( $css as $media_query => $elements ) { foreach ( $elements as $element => $style_array ) { foreach ( $style_array as $property => $value ) { // Add -webkit-* and -moz-*. if ( is_string( $property ) && in_array( $property, [ 'border-radius', 'box-shadow', 'box-sizing', 'text-shadow', 'transform', 'background-size', 'transition', 'transition-property', ], true ) ) { unset( $css[ $media_query ][ $element ][ $property ] ); $css[ $media_query ][ $element ][ '-webkit-' . $property ] = $value; $css[ $media_query ][ $element ][ '-moz-' . $property ] = $value; $css[ $media_query ][ $element ][ $property ] = $value; } // Add -ms-* and -o-*. if ( is_string( $property ) && in_array( $property, [ 'transform', 'background-size', 'transition', 'transition-property', ], true ) ) { unset( $css[ $media_query ][ $element ][ $property ] ); $css[ $media_query ][ $element ][ '-ms-' . $property ] = $value; $css[ $media_query ][ $element ][ '-o-' . $property ] = $value; $css[ $media_query ][ $element ][ $property ] = $value; } } } } } return $css; }
[ "public", "static", "function", "add_prefixes", "(", "$", "css", ")", "{", "if", "(", "is_array", "(", "$", "css", ")", ")", "{", "foreach", "(", "$", "css", "as", "$", "media_query", "=>", "$", "elements", ")", "{", "foreach", "(", "$", "elements", "as", "$", "element", "=>", "$", "style_array", ")", "{", "foreach", "(", "$", "style_array", "as", "$", "property", "=>", "$", "value", ")", "{", "// Add -webkit-* and -moz-*.", "if", "(", "is_string", "(", "$", "property", ")", "&&", "in_array", "(", "$", "property", ",", "[", "'border-radius'", ",", "'box-shadow'", ",", "'box-sizing'", ",", "'text-shadow'", ",", "'transform'", ",", "'background-size'", ",", "'transition'", ",", "'transition-property'", ",", "]", ",", "true", ")", ")", "{", "unset", "(", "$", "css", "[", "$", "media_query", "]", "[", "$", "element", "]", "[", "$", "property", "]", ")", ";", "$", "css", "[", "$", "media_query", "]", "[", "$", "element", "]", "[", "'-webkit-'", ".", "$", "property", "]", "=", "$", "value", ";", "$", "css", "[", "$", "media_query", "]", "[", "$", "element", "]", "[", "'-moz-'", ".", "$", "property", "]", "=", "$", "value", ";", "$", "css", "[", "$", "media_query", "]", "[", "$", "element", "]", "[", "$", "property", "]", "=", "$", "value", ";", "}", "// Add -ms-* and -o-*.", "if", "(", "is_string", "(", "$", "property", ")", "&&", "in_array", "(", "$", "property", ",", "[", "'transform'", ",", "'background-size'", ",", "'transition'", ",", "'transition-property'", ",", "]", ",", "true", ")", ")", "{", "unset", "(", "$", "css", "[", "$", "media_query", "]", "[", "$", "element", "]", "[", "$", "property", "]", ")", ";", "$", "css", "[", "$", "media_query", "]", "[", "$", "element", "]", "[", "'-ms-'", ".", "$", "property", "]", "=", "$", "value", ";", "$", "css", "[", "$", "media_query", "]", "[", "$", "element", "]", "[", "'-o-'", ".", "$", "property", "]", "=", "$", "value", ";", "$", "css", "[", "$", "media_query", "]", "[", "$", "element", "]", "[", "$", "property", "]", "=", "$", "value", ";", "}", "}", "}", "}", "}", "return", "$", "css", ";", "}" ]
Add prefixes if necessary. @param array $css The CSS definitions array. @return array
[ "Add", "prefixes", "if", "necessary", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-css/src/Generator.php#L240-L288
train
aristath/kirki
packages/kirki-framework/control-checkbox/src/Field/Checkbox_Switch.php
Checkbox_Switch.set_choices
protected function set_choices() { if ( ! is_array( $this->choices ) ) { $this->choices = []; } $this->choices = wp_parse_args( $this->choices, [ 'on' => esc_html__( 'On', 'kirki' ), 'off' => esc_html__( 'Off', 'kirki' ), 'round' => false, ] ); }
php
protected function set_choices() { if ( ! is_array( $this->choices ) ) { $this->choices = []; } $this->choices = wp_parse_args( $this->choices, [ 'on' => esc_html__( 'On', 'kirki' ), 'off' => esc_html__( 'Off', 'kirki' ), 'round' => false, ] ); }
[ "protected", "function", "set_choices", "(", ")", "{", "if", "(", "!", "is_array", "(", "$", "this", "->", "choices", ")", ")", "{", "$", "this", "->", "choices", "=", "[", "]", ";", "}", "$", "this", "->", "choices", "=", "wp_parse_args", "(", "$", "this", "->", "choices", ",", "[", "'on'", "=>", "esc_html__", "(", "'On'", ",", "'kirki'", ")", ",", "'off'", "=>", "esc_html__", "(", "'Off'", ",", "'kirki'", ")", ",", "'round'", "=>", "false", ",", "]", ")", ";", "}" ]
Sets the control choices. @access protected
[ "Sets", "the", "control", "choices", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-checkbox/src/Field/Checkbox_Switch.php#L36-L49
train
aristath/kirki
packages/kirki-framework/core/src/Kirki.php
Kirki.add_panel
public static function add_panel( $id = '', $args = [] ) { $args['id'] = $id; if ( ! isset( $args['description'] ) ) { $args['description'] = ''; } if ( ! isset( $args['priority'] ) ) { $args['priority'] = 10; } if ( ! isset( $args['type'] ) ) { $args['type'] = 'default'; } if ( false === strpos( $args['type'], 'kirki-' ) ) { $args['type'] = 'kirki-' . $args['type']; } self::$panels[ $id ] = $args; }
php
public static function add_panel( $id = '', $args = [] ) { $args['id'] = $id; if ( ! isset( $args['description'] ) ) { $args['description'] = ''; } if ( ! isset( $args['priority'] ) ) { $args['priority'] = 10; } if ( ! isset( $args['type'] ) ) { $args['type'] = 'default'; } if ( false === strpos( $args['type'], 'kirki-' ) ) { $args['type'] = 'kirki-' . $args['type']; } self::$panels[ $id ] = $args; }
[ "public", "static", "function", "add_panel", "(", "$", "id", "=", "''", ",", "$", "args", "=", "[", "]", ")", "{", "$", "args", "[", "'id'", "]", "=", "$", "id", ";", "if", "(", "!", "isset", "(", "$", "args", "[", "'description'", "]", ")", ")", "{", "$", "args", "[", "'description'", "]", "=", "''", ";", "}", "if", "(", "!", "isset", "(", "$", "args", "[", "'priority'", "]", ")", ")", "{", "$", "args", "[", "'priority'", "]", "=", "10", ";", "}", "if", "(", "!", "isset", "(", "$", "args", "[", "'type'", "]", ")", ")", "{", "$", "args", "[", "'type'", "]", "=", "'default'", ";", "}", "if", "(", "false", "===", "strpos", "(", "$", "args", "[", "'type'", "]", ",", "'kirki-'", ")", ")", "{", "$", "args", "[", "'type'", "]", "=", "'kirki-'", ".", "$", "args", "[", "'type'", "]", ";", "}", "self", "::", "$", "panels", "[", "$", "id", "]", "=", "$", "args", ";", "}" ]
Create a new panel. @static @access public @param string $id The ID for this panel. @param array $args The panel arguments.
[ "Create", "a", "new", "panel", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Kirki.php#L150-L165
train
aristath/kirki
packages/kirki-framework/core/src/Kirki.php
Kirki.remove_panel
public static function remove_panel( $id = '' ) { if ( ! in_array( $id, self::$panels_to_remove, true ) ) { self::$panels_to_remove[] = $id; } }
php
public static function remove_panel( $id = '' ) { if ( ! in_array( $id, self::$panels_to_remove, true ) ) { self::$panels_to_remove[] = $id; } }
[ "public", "static", "function", "remove_panel", "(", "$", "id", "=", "''", ")", "{", "if", "(", "!", "in_array", "(", "$", "id", ",", "self", "::", "$", "panels_to_remove", ",", "true", ")", ")", "{", "self", "::", "$", "panels_to_remove", "[", "]", "=", "$", "id", ";", "}", "}" ]
Remove a panel. @static @access public @since 3.0.17 @param string $id The ID for this panel.
[ "Remove", "a", "panel", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Kirki.php#L175-L179
train
aristath/kirki
packages/kirki-framework/core/src/Kirki.php
Kirki.remove_section
public static function remove_section( $id = '' ) { if ( ! in_array( $id, self::$sections_to_remove, true ) ) { self::$sections_to_remove[] = $id; } }
php
public static function remove_section( $id = '' ) { if ( ! in_array( $id, self::$sections_to_remove, true ) ) { self::$sections_to_remove[] = $id; } }
[ "public", "static", "function", "remove_section", "(", "$", "id", "=", "''", ")", "{", "if", "(", "!", "in_array", "(", "$", "id", ",", "self", "::", "$", "sections_to_remove", ",", "true", ")", ")", "{", "self", "::", "$", "sections_to_remove", "[", "]", "=", "$", "id", ";", "}", "}" ]
Remove a section. @static @access public @since 3.0.17 @param string $id The ID for this panel.
[ "Remove", "a", "section", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Kirki.php#L215-L219
train
aristath/kirki
packages/kirki-framework/core/src/Kirki.php
Kirki.add_field
public static function add_field( $config_id, $args = [] ) { if ( doing_action( 'customize_register' ) ) { _doing_it_wrong( __METHOD__, esc_html__( 'Kirki fields should not be added on customize_register. Please add them directly, or on init.', 'kirki' ), '3.0.10' ); } // Early exit if 'type' is not defined. if ( ! isset( $args['type'] ) ) { return; } // If the field is font-awesome, enqueue the icons on the frontend. if ( class_exists( '\Kirki\Modules\CSS\Module' ) && ( 'fontawesome' === $args['type'] || 'kirki-fontawesome' === $args['type'] ) ) { \Kirki\Modules\CSS\Module::add_fontawesome_script(); } $str = str_replace( [ '-', '_' ], ' ', $args['type'] ); $classname = '\Kirki\Field\\' . str_replace( ' ', '_', ucwords( $str ) ); $config = Config::get_instance( $config_id )->get_config(); $args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : $config_id; unset( $config['id'] ); $args = wp_parse_args( $args, $config ); if ( class_exists( $classname ) ) { new $classname( $args ); return; } new Field( $args ); }
php
public static function add_field( $config_id, $args = [] ) { if ( doing_action( 'customize_register' ) ) { _doing_it_wrong( __METHOD__, esc_html__( 'Kirki fields should not be added on customize_register. Please add them directly, or on init.', 'kirki' ), '3.0.10' ); } // Early exit if 'type' is not defined. if ( ! isset( $args['type'] ) ) { return; } // If the field is font-awesome, enqueue the icons on the frontend. if ( class_exists( '\Kirki\Modules\CSS\Module' ) && ( 'fontawesome' === $args['type'] || 'kirki-fontawesome' === $args['type'] ) ) { \Kirki\Modules\CSS\Module::add_fontawesome_script(); } $str = str_replace( [ '-', '_' ], ' ', $args['type'] ); $classname = '\Kirki\Field\\' . str_replace( ' ', '_', ucwords( $str ) ); $config = Config::get_instance( $config_id )->get_config(); $args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : $config_id; unset( $config['id'] ); $args = wp_parse_args( $args, $config ); if ( class_exists( $classname ) ) { new $classname( $args ); return; } new Field( $args ); }
[ "public", "static", "function", "add_field", "(", "$", "config_id", ",", "$", "args", "=", "[", "]", ")", "{", "if", "(", "doing_action", "(", "'customize_register'", ")", ")", "{", "_doing_it_wrong", "(", "__METHOD__", ",", "esc_html__", "(", "'Kirki fields should not be added on customize_register. Please add them directly, or on init.'", ",", "'kirki'", ")", ",", "'3.0.10'", ")", ";", "}", "// Early exit if 'type' is not defined.", "if", "(", "!", "isset", "(", "$", "args", "[", "'type'", "]", ")", ")", "{", "return", ";", "}", "// If the field is font-awesome, enqueue the icons on the frontend.", "if", "(", "class_exists", "(", "'\\Kirki\\Modules\\CSS\\Module'", ")", "&&", "(", "'fontawesome'", "===", "$", "args", "[", "'type'", "]", "||", "'kirki-fontawesome'", "===", "$", "args", "[", "'type'", "]", ")", ")", "{", "\\", "Kirki", "\\", "Modules", "\\", "CSS", "\\", "Module", "::", "add_fontawesome_script", "(", ")", ";", "}", "$", "str", "=", "str_replace", "(", "[", "'-'", ",", "'_'", "]", ",", "' '", ",", "$", "args", "[", "'type'", "]", ")", ";", "$", "classname", "=", "'\\Kirki\\Field\\\\'", ".", "str_replace", "(", "' '", ",", "'_'", ",", "ucwords", "(", "$", "str", ")", ")", ";", "$", "config", "=", "Config", "::", "get_instance", "(", "$", "config_id", ")", "->", "get_config", "(", ")", ";", "$", "args", "[", "'kirki_config'", "]", "=", "isset", "(", "$", "args", "[", "'kirki_config'", "]", ")", "?", "$", "args", "[", "'kirki_config'", "]", ":", "$", "config_id", ";", "unset", "(", "$", "config", "[", "'id'", "]", ")", ";", "$", "args", "=", "wp_parse_args", "(", "$", "args", ",", "$", "config", ")", ";", "if", "(", "class_exists", "(", "$", "classname", ")", ")", "{", "new", "$", "classname", "(", "$", "args", ")", ";", "return", ";", "}", "new", "Field", "(", "$", "args", ")", ";", "}" ]
Create a new field. @static @access public @param string $config_id The configuration ID for this field. @param array $args The field arguments.
[ "Create", "a", "new", "field", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Kirki.php#L229-L257
train
aristath/kirki
packages/kirki-framework/core/src/Kirki.php
Kirki.remove_control
public static function remove_control( $id ) { if ( ! in_array( $id, self::$controls_to_remove, true ) ) { self::$controls_to_remove[] = $id; } }
php
public static function remove_control( $id ) { if ( ! in_array( $id, self::$controls_to_remove, true ) ) { self::$controls_to_remove[] = $id; } }
[ "public", "static", "function", "remove_control", "(", "$", "id", ")", "{", "if", "(", "!", "in_array", "(", "$", "id", ",", "self", "::", "$", "controls_to_remove", ",", "true", ")", ")", "{", "self", "::", "$", "controls_to_remove", "[", "]", "=", "$", "id", ";", "}", "}" ]
Remove a control. @static @access public @since 3.0.17 @param string $id The field ID.
[ "Remove", "a", "control", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Kirki.php#L267-L271
train
aristath/kirki
packages/kirki-framework/core/src/Kirki.php
Kirki.get_config_param
public static function get_config_param( $id, $param ) { if ( ! isset( self::$config[ $id ] ) || ! isset( self::$config[ $id ][ $param ] ) ) { return ''; } return self::$config[ $id ][ $param ]; }
php
public static function get_config_param( $id, $param ) { if ( ! isset( self::$config[ $id ] ) || ! isset( self::$config[ $id ][ $param ] ) ) { return ''; } return self::$config[ $id ][ $param ]; }
[ "public", "static", "function", "get_config_param", "(", "$", "id", ",", "$", "param", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "config", "[", "$", "id", "]", ")", "||", "!", "isset", "(", "self", "::", "$", "config", "[", "$", "id", "]", "[", "$", "param", "]", ")", ")", "{", "return", "''", ";", "}", "return", "self", "::", "$", "config", "[", "$", "id", "]", "[", "$", "param", "]", ";", "}" ]
Gets a parameter for a config-id. @static @access public @since 3.0.10 @param string $id The config-ID. @param string $param The parameter we want. @return string
[ "Gets", "a", "parameter", "for", "a", "config", "-", "id", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Kirki.php#L283-L288
train
aristath/kirki
packages/kirki-framework/control-multicolor/src/Field/Multicolor.php
Multicolor.sanitize
public static function sanitize( $value ) { if ( ! is_array( $value ) ) { return []; } foreach ( $value as $key => $val ) { $value[ $key ] = Color::sanitize( $val ); } return $value; }
php
public static function sanitize( $value ) { if ( ! is_array( $value ) ) { return []; } foreach ( $value as $key => $val ) { $value[ $key ] = Color::sanitize( $val ); } return $value; }
[ "public", "static", "function", "sanitize", "(", "$", "value", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "return", "[", "]", ";", "}", "foreach", "(", "$", "value", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "value", "[", "$", "key", "]", "=", "Color", "::", "sanitize", "(", "$", "val", ")", ";", "}", "return", "$", "value", ";", "}" ]
The method that will be used as a `sanitize_callback`. @static @access public @since 1.0 @param array $value The value to be sanitized. @return array The value.
[ "The", "method", "that", "will", "be", "used", "as", "a", "sanitize_callback", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-multicolor/src/Field/Multicolor.php#L71-L79
train
aristath/kirki
packages/kirki-framework/core/src/Section.php
Section.add_section
public function add_section( $args ) { global $wp_customize; // The default class to be used when creating a section. $section_classname = 'WP_Customize_Section'; if ( isset( $args['type'] ) && array_key_exists( $args['type'], $this->section_types ) ) { $section_classname = $this->section_types[ $args['type'] ]; } if ( isset( $args['type'] ) && 'kirki-outer' === $args['type'] ) { $args['type'] = 'outer'; $section_classname = 'WP_Customize_Section'; } // Add the section. $wp_customize->add_section( new $section_classname( $wp_customize, $args['id'], $args ) ); }
php
public function add_section( $args ) { global $wp_customize; // The default class to be used when creating a section. $section_classname = 'WP_Customize_Section'; if ( isset( $args['type'] ) && array_key_exists( $args['type'], $this->section_types ) ) { $section_classname = $this->section_types[ $args['type'] ]; } if ( isset( $args['type'] ) && 'kirki-outer' === $args['type'] ) { $args['type'] = 'outer'; $section_classname = 'WP_Customize_Section'; } // Add the section. $wp_customize->add_section( new $section_classname( $wp_customize, $args['id'], $args ) ); }
[ "public", "function", "add_section", "(", "$", "args", ")", "{", "global", "$", "wp_customize", ";", "// The default class to be used when creating a section.", "$", "section_classname", "=", "'WP_Customize_Section'", ";", "if", "(", "isset", "(", "$", "args", "[", "'type'", "]", ")", "&&", "array_key_exists", "(", "$", "args", "[", "'type'", "]", ",", "$", "this", "->", "section_types", ")", ")", "{", "$", "section_classname", "=", "$", "this", "->", "section_types", "[", "$", "args", "[", "'type'", "]", "]", ";", "}", "if", "(", "isset", "(", "$", "args", "[", "'type'", "]", ")", "&&", "'kirki-outer'", "===", "$", "args", "[", "'type'", "]", ")", "{", "$", "args", "[", "'type'", "]", "=", "'outer'", ";", "$", "section_classname", "=", "'WP_Customize_Section'", ";", "}", "// Add the section.", "$", "wp_customize", "->", "add_section", "(", "new", "$", "section_classname", "(", "$", "wp_customize", ",", "$", "args", "[", "'id'", "]", ",", "$", "args", ")", ")", ";", "}" ]
Adds the section using the WordPress Customizer API. @access public @param array $args The section parameters.
[ "Adds", "the", "section", "using", "the", "WordPress", "Customizer", "API", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Section.php#L45-L61
train
aristath/kirki
packages/kirki-framework/module-webfonts/src/Embed.php
Embed.resource_hints
public function resource_hints( $urls, $relation_type ) { $fonts_to_load = $this->googlefonts->fonts; if ( ! empty( $fonts_to_load ) && 'preconnect' === $relation_type ) { $urls[] = [ 'href' => 'https://fonts.gstatic.com', 'crossorigin', ]; } return $urls; }
php
public function resource_hints( $urls, $relation_type ) { $fonts_to_load = $this->googlefonts->fonts; if ( ! empty( $fonts_to_load ) && 'preconnect' === $relation_type ) { $urls[] = [ 'href' => 'https://fonts.gstatic.com', 'crossorigin', ]; } return $urls; }
[ "public", "function", "resource_hints", "(", "$", "urls", ",", "$", "relation_type", ")", "{", "$", "fonts_to_load", "=", "$", "this", "->", "googlefonts", "->", "fonts", ";", "if", "(", "!", "empty", "(", "$", "fonts_to_load", ")", "&&", "'preconnect'", "===", "$", "relation_type", ")", "{", "$", "urls", "[", "]", "=", "[", "'href'", "=>", "'https://fonts.gstatic.com'", ",", "'crossorigin'", ",", "]", ";", "}", "return", "$", "urls", ";", "}" ]
Add preconnect for Google Fonts. @access public @param array $urls URLs to print for resource hints. @param string $relation_type The relation type the URLs are printed. @return array $urls URLs to print for resource hints.
[ "Add", "preconnect", "for", "Google", "Fonts", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Embed.php#L97-L107
train
aristath/kirki
packages/kirki-framework/module-webfonts/src/Embed.php
Embed.the_css
public function the_css() { foreach ( $this->fonts_to_load as $font ) { $family = str_replace( ' ', '+', trim( $font['family'] ) ); $weights = join( ',', $font['weights'] ); $url = "https://fonts.googleapis.com/css?family={$family}:{$weights}&subset=cyrillic,cyrillic-ext,devanagari,greek,greek-ext,khmer,latin,latin-ext,vietnamese,hebrew,arabic,bengali,gujarati,tamil,telugu,thai"; $transient_id = 'kirki_gfonts_' . md5( $url ); $contents = get_site_transient( $transient_id ); /** * Note to code reviewers: * There's no need to check nonces or anything else, this is a simple true/false evaluation. */ if ( ! empty( $_GET['action'] ) && 'kirki-reset-cache' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification $contents = false; } if ( ! $contents ) { // Get the contents of the remote URL. $contents = Helper::get_remote_url_contents( $url, [ 'headers' => [ /** * Set user-agent to firefox so that we get woff files. * If we want woff2, use this instead: 'Mozilla/5.0 (X11; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0' */ 'user-agent' => 'Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Firefox/21.0', ], ] ); /** * Allow filtering the font-display property. */ $font_display = apply_filters( 'kirki_googlefonts_font_display', 'swap' ); if ( $contents ) { // Add font-display:swap to improve rendering speed. $contents = str_replace( '@font-face {', '@font-face{', $contents ); $contents = str_replace( '@font-face{', '@font-face{font-display:' . $font_display . ';', $contents ); // Remove blank lines and extra spaces. $contents = str_replace( [ ': ', '; ', '; ', ' ' ], [ ':', ';', ';', ' ' ], preg_replace( "/\r|\n/", '', $contents ) ); // Use local fonts. if ( apply_filters( 'kirki_use_local_fonts', true ) ) { $contents = $this->use_local_files( $contents ); } // Set the transient for a week. set_site_transient( $transient_id, $contents, WEEK_IN_SECONDS ); } } if ( $contents ) { /** * Note to code reviewers: * * Though all output should be run through an escaping function, this is pure CSS * and it is added on a call that has a PHP `header( 'Content-type: text/css' );`. * No code, script or anything else can be executed from inside a stylesheet. * For extra security we're using the wp_strip_all_tags() function here * just to make sure there's no <script> tags in there or anything else. */ echo wp_strip_all_tags( $contents ); // phpcs:ignore WordPress.Security.EscapeOutput } } }
php
public function the_css() { foreach ( $this->fonts_to_load as $font ) { $family = str_replace( ' ', '+', trim( $font['family'] ) ); $weights = join( ',', $font['weights'] ); $url = "https://fonts.googleapis.com/css?family={$family}:{$weights}&subset=cyrillic,cyrillic-ext,devanagari,greek,greek-ext,khmer,latin,latin-ext,vietnamese,hebrew,arabic,bengali,gujarati,tamil,telugu,thai"; $transient_id = 'kirki_gfonts_' . md5( $url ); $contents = get_site_transient( $transient_id ); /** * Note to code reviewers: * There's no need to check nonces or anything else, this is a simple true/false evaluation. */ if ( ! empty( $_GET['action'] ) && 'kirki-reset-cache' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification $contents = false; } if ( ! $contents ) { // Get the contents of the remote URL. $contents = Helper::get_remote_url_contents( $url, [ 'headers' => [ /** * Set user-agent to firefox so that we get woff files. * If we want woff2, use this instead: 'Mozilla/5.0 (X11; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0' */ 'user-agent' => 'Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Firefox/21.0', ], ] ); /** * Allow filtering the font-display property. */ $font_display = apply_filters( 'kirki_googlefonts_font_display', 'swap' ); if ( $contents ) { // Add font-display:swap to improve rendering speed. $contents = str_replace( '@font-face {', '@font-face{', $contents ); $contents = str_replace( '@font-face{', '@font-face{font-display:' . $font_display . ';', $contents ); // Remove blank lines and extra spaces. $contents = str_replace( [ ': ', '; ', '; ', ' ' ], [ ':', ';', ';', ' ' ], preg_replace( "/\r|\n/", '', $contents ) ); // Use local fonts. if ( apply_filters( 'kirki_use_local_fonts', true ) ) { $contents = $this->use_local_files( $contents ); } // Set the transient for a week. set_site_transient( $transient_id, $contents, WEEK_IN_SECONDS ); } } if ( $contents ) { /** * Note to code reviewers: * * Though all output should be run through an escaping function, this is pure CSS * and it is added on a call that has a PHP `header( 'Content-type: text/css' );`. * No code, script or anything else can be executed from inside a stylesheet. * For extra security we're using the wp_strip_all_tags() function here * just to make sure there's no <script> tags in there or anything else. */ echo wp_strip_all_tags( $contents ); // phpcs:ignore WordPress.Security.EscapeOutput } } }
[ "public", "function", "the_css", "(", ")", "{", "foreach", "(", "$", "this", "->", "fonts_to_load", "as", "$", "font", ")", "{", "$", "family", "=", "str_replace", "(", "' '", ",", "'+'", ",", "trim", "(", "$", "font", "[", "'family'", "]", ")", ")", ";", "$", "weights", "=", "join", "(", "','", ",", "$", "font", "[", "'weights'", "]", ")", ";", "$", "url", "=", "\"https://fonts.googleapis.com/css?family={$family}:{$weights}&subset=cyrillic,cyrillic-ext,devanagari,greek,greek-ext,khmer,latin,latin-ext,vietnamese,hebrew,arabic,bengali,gujarati,tamil,telugu,thai\"", ";", "$", "transient_id", "=", "'kirki_gfonts_'", ".", "md5", "(", "$", "url", ")", ";", "$", "contents", "=", "get_site_transient", "(", "$", "transient_id", ")", ";", "/**\n\t\t\t * Note to code reviewers:\n\t\t\t * There's no need to check nonces or anything else, this is a simple true/false evaluation.\n\t\t\t */", "if", "(", "!", "empty", "(", "$", "_GET", "[", "'action'", "]", ")", "&&", "'kirki-reset-cache'", "===", "$", "_GET", "[", "'action'", "]", ")", "{", "// phpcs:ignore WordPress.Security.NonceVerification", "$", "contents", "=", "false", ";", "}", "if", "(", "!", "$", "contents", ")", "{", "// Get the contents of the remote URL.", "$", "contents", "=", "Helper", "::", "get_remote_url_contents", "(", "$", "url", ",", "[", "'headers'", "=>", "[", "/**\n\t\t\t\t\t\t\t * Set user-agent to firefox so that we get woff files.\n\t\t\t\t\t\t\t * If we want woff2, use this instead: 'Mozilla/5.0 (X11; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0'\n\t\t\t\t\t\t\t */", "'user-agent'", "=>", "'Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Firefox/21.0'", ",", "]", ",", "]", ")", ";", "/**\n\t\t\t\t * Allow filtering the font-display property.\n\t\t\t\t */", "$", "font_display", "=", "apply_filters", "(", "'kirki_googlefonts_font_display'", ",", "'swap'", ")", ";", "if", "(", "$", "contents", ")", "{", "// Add font-display:swap to improve rendering speed.", "$", "contents", "=", "str_replace", "(", "'@font-face {'", ",", "'@font-face{'", ",", "$", "contents", ")", ";", "$", "contents", "=", "str_replace", "(", "'@font-face{'", ",", "'@font-face{font-display:'", ".", "$", "font_display", ".", "';'", ",", "$", "contents", ")", ";", "// Remove blank lines and extra spaces.", "$", "contents", "=", "str_replace", "(", "[", "': '", ",", "'; '", ",", "'; '", ",", "' '", "]", ",", "[", "':'", ",", "';'", ",", "';'", ",", "' '", "]", ",", "preg_replace", "(", "\"/\\r|\\n/\"", ",", "''", ",", "$", "contents", ")", ")", ";", "// Use local fonts.", "if", "(", "apply_filters", "(", "'kirki_use_local_fonts'", ",", "true", ")", ")", "{", "$", "contents", "=", "$", "this", "->", "use_local_files", "(", "$", "contents", ")", ";", "}", "// Set the transient for a week.", "set_site_transient", "(", "$", "transient_id", ",", "$", "contents", ",", "WEEK_IN_SECONDS", ")", ";", "}", "}", "if", "(", "$", "contents", ")", "{", "/**\n\t\t\t\t * Note to code reviewers:\n\t\t\t\t *\n\t\t\t\t * Though all output should be run through an escaping function, this is pure CSS\n\t\t\t\t * and it is added on a call that has a PHP `header( 'Content-type: text/css' );`.\n\t\t\t\t * No code, script or anything else can be executed from inside a stylesheet.\n\t\t\t\t * For extra security we're using the wp_strip_all_tags() function here\n\t\t\t\t * just to make sure there's no <script> tags in there or anything else.\n\t\t\t\t */", "echo", "wp_strip_all_tags", "(", "$", "contents", ")", ";", "// phpcs:ignore WordPress.Security.EscapeOutput", "}", "}", "}" ]
Webfont Loader script for Google Fonts. @access public @since 3.0.0
[ "Webfont", "Loader", "script", "for", "Google", "Fonts", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Embed.php#L146-L217
train
aristath/kirki
packages/kirki-framework/module-webfonts/src/Embed.php
Embed.use_local_files
private function use_local_files( $css ) { preg_match_all( '/https\:.*?\.woff/', $css, $matches ); $matches = array_shift( $matches ); foreach ( $matches as $match ) { if ( 0 === strpos( $match, 'https://fonts.gstatic.com' ) ) { $new_url = Helper::download_font_file( $match ); if ( $new_url ) { $css = str_replace( $match, $new_url, $css ); } } } return $css; }
php
private function use_local_files( $css ) { preg_match_all( '/https\:.*?\.woff/', $css, $matches ); $matches = array_shift( $matches ); foreach ( $matches as $match ) { if ( 0 === strpos( $match, 'https://fonts.gstatic.com' ) ) { $new_url = Helper::download_font_file( $match ); if ( $new_url ) { $css = str_replace( $match, $new_url, $css ); } } } return $css; }
[ "private", "function", "use_local_files", "(", "$", "css", ")", "{", "preg_match_all", "(", "'/https\\:.*?\\.woff/'", ",", "$", "css", ",", "$", "matches", ")", ";", "$", "matches", "=", "array_shift", "(", "$", "matches", ")", ";", "foreach", "(", "$", "matches", "as", "$", "match", ")", "{", "if", "(", "0", "===", "strpos", "(", "$", "match", ",", "'https://fonts.gstatic.com'", ")", ")", "{", "$", "new_url", "=", "Helper", "::", "download_font_file", "(", "$", "match", ")", ";", "if", "(", "$", "new_url", ")", "{", "$", "css", "=", "str_replace", "(", "$", "match", ",", "$", "new_url", ",", "$", "css", ")", ";", "}", "}", "}", "return", "$", "css", ";", "}" ]
Downloads font-files locally and uses the local files instead of the ones from Google's servers. This addresses any and all GDPR concerns, as well as firewalls that exist in some parts of the world. @access private @since 3.0.36 @param string $css The CSS with original URLs. @return string The CSS with local URLs.
[ "Downloads", "font", "-", "files", "locally", "and", "uses", "the", "local", "files", "instead", "of", "the", "ones", "from", "Google", "s", "servers", ".", "This", "addresses", "any", "and", "all", "GDPR", "concerns", "as", "well", "as", "firewalls", "that", "exist", "in", "some", "parts", "of", "the", "world", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Embed.php#L228-L242
train
aristath/kirki
packages/kirki-framework/core/src/L10n.php
L10n.load_textdomain
public function load_textdomain() { if ( null !== $this->get_path() ) { load_textdomain( $this->textdomain, $this->get_path() ); } load_plugin_textdomain( $this->textdomain, false, dirname( KIRKI_PLUGIN_FILE ) . '/languages' ); }
php
public function load_textdomain() { if ( null !== $this->get_path() ) { load_textdomain( $this->textdomain, $this->get_path() ); } load_plugin_textdomain( $this->textdomain, false, dirname( KIRKI_PLUGIN_FILE ) . '/languages' ); }
[ "public", "function", "load_textdomain", "(", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "get_path", "(", ")", ")", "{", "load_textdomain", "(", "$", "this", "->", "textdomain", ",", "$", "this", "->", "get_path", "(", ")", ")", ";", "}", "load_plugin_textdomain", "(", "$", "this", "->", "textdomain", ",", "false", ",", "dirname", "(", "KIRKI_PLUGIN_FILE", ")", ".", "'/languages'", ")", ";", "}" ]
Load the plugin textdomain @access public
[ "Load", "the", "plugin", "textdomain" ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/L10n.php#L62-L67
train
aristath/kirki
packages/kirki-framework/core/src/L10n.php
L10n.get_path
protected function get_path() { $path_found = false; $found_path = null; foreach ( $this->get_paths() as $path ) { if ( $path_found ) { continue; } $path = wp_normalize_path( $path ); if ( file_exists( $path ) ) { $path_found = true; $found_path = $path; } } return $found_path; }
php
protected function get_path() { $path_found = false; $found_path = null; foreach ( $this->get_paths() as $path ) { if ( $path_found ) { continue; } $path = wp_normalize_path( $path ); if ( file_exists( $path ) ) { $path_found = true; $found_path = $path; } } return $found_path; }
[ "protected", "function", "get_path", "(", ")", "{", "$", "path_found", "=", "false", ";", "$", "found_path", "=", "null", ";", "foreach", "(", "$", "this", "->", "get_paths", "(", ")", "as", "$", "path", ")", "{", "if", "(", "$", "path_found", ")", "{", "continue", ";", "}", "$", "path", "=", "wp_normalize_path", "(", "$", "path", ")", ";", "if", "(", "file_exists", "(", "$", "path", ")", ")", "{", "$", "path_found", "=", "true", ";", "$", "found_path", "=", "$", "path", ";", "}", "}", "return", "$", "found_path", ";", "}" ]
Gets the path to a translation file. @access protected @return string Absolute path to the translation file.
[ "Gets", "the", "path", "to", "a", "translation", "file", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/L10n.php#L75-L89
train
aristath/kirki
packages/kirki-framework/core/src/L10n.php
L10n.get_paths
protected function get_paths() { return [ WP_LANG_DIR . '/' . $this->textdomain . '-' . get_locale() . '.mo', dirname( KIRKI_PLUGIN_FILE ) . '/languages/' . $this->textdomain . '-' . get_locale() . '.mo', ]; }
php
protected function get_paths() { return [ WP_LANG_DIR . '/' . $this->textdomain . '-' . get_locale() . '.mo', dirname( KIRKI_PLUGIN_FILE ) . '/languages/' . $this->textdomain . '-' . get_locale() . '.mo', ]; }
[ "protected", "function", "get_paths", "(", ")", "{", "return", "[", "WP_LANG_DIR", ".", "'/'", ".", "$", "this", "->", "textdomain", ".", "'-'", ".", "get_locale", "(", ")", ".", "'.mo'", ",", "dirname", "(", "KIRKI_PLUGIN_FILE", ")", ".", "'/languages/'", ".", "$", "this", "->", "textdomain", ".", "'-'", ".", "get_locale", "(", ")", ".", "'.mo'", ",", "]", ";", "}" ]
Returns an array of paths where translation files may be located. @access protected @return array
[ "Returns", "an", "array", "of", "paths", "where", "translation", "files", "may", "be", "located", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/L10n.php#L97-L102
train
aristath/kirki
packages/kirki-framework/core/src/L10n.php
L10n.override_load_textdomain
public function override_load_textdomain( $override, $domain, $mofile ) { global $l10n; if ( isset( $l10n[ $this->get_theme_textdomain() ] ) ) { $l10n['kirki'] = $l10n[ $this->get_theme_textdomain() ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride } // Check if the domain is "kirki". if ( 'kirki' === $domain ) { return true; } return $override; }
php
public function override_load_textdomain( $override, $domain, $mofile ) { global $l10n; if ( isset( $l10n[ $this->get_theme_textdomain() ] ) ) { $l10n['kirki'] = $l10n[ $this->get_theme_textdomain() ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride } // Check if the domain is "kirki". if ( 'kirki' === $domain ) { return true; } return $override; }
[ "public", "function", "override_load_textdomain", "(", "$", "override", ",", "$", "domain", ",", "$", "mofile", ")", "{", "global", "$", "l10n", ";", "if", "(", "isset", "(", "$", "l10n", "[", "$", "this", "->", "get_theme_textdomain", "(", ")", "]", ")", ")", "{", "$", "l10n", "[", "'kirki'", "]", "=", "$", "l10n", "[", "$", "this", "->", "get_theme_textdomain", "(", ")", "]", ";", "// phpcs:ignore WordPress.WP.GlobalVariablesOverride", "}", "// Check if the domain is \"kirki\".", "if", "(", "'kirki'", "===", "$", "domain", ")", "{", "return", "true", ";", "}", "return", "$", "override", ";", "}" ]
Allows overriding the "kirki" textdomain from a theme. @since 3.0.12 @access public @param bool $override Whether to override the .mo file loading. Default false. @param string $domain Text domain. Unique identifier for retrieving translated strings. @param string $mofile Path to the MO file. @return bool
[ "Allows", "overriding", "the", "kirki", "textdomain", "from", "a", "theme", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/L10n.php#L114-L125
train
aristath/kirki
packages/kirki-framework/core/src/L10n.php
L10n.get_theme_textdomain
private function get_theme_textdomain() { if ( '' === $this->theme_textdomain ) { // Get the textdomain. $theme = wp_get_theme(); $this->theme_textdomain = $theme->get( 'TextDomain' ); // If no texdomain was found, use the template folder name. if ( ! $this->theme_textdomain ) { $this->theme_textdomain = get_template(); } } return $this->theme_textdomain; }
php
private function get_theme_textdomain() { if ( '' === $this->theme_textdomain ) { // Get the textdomain. $theme = wp_get_theme(); $this->theme_textdomain = $theme->get( 'TextDomain' ); // If no texdomain was found, use the template folder name. if ( ! $this->theme_textdomain ) { $this->theme_textdomain = get_template(); } } return $this->theme_textdomain; }
[ "private", "function", "get_theme_textdomain", "(", ")", "{", "if", "(", "''", "===", "$", "this", "->", "theme_textdomain", ")", "{", "// Get the textdomain.", "$", "theme", "=", "wp_get_theme", "(", ")", ";", "$", "this", "->", "theme_textdomain", "=", "$", "theme", "->", "get", "(", "'TextDomain'", ")", ";", "// If no texdomain was found, use the template folder name.", "if", "(", "!", "$", "this", "->", "theme_textdomain", ")", "{", "$", "this", "->", "theme_textdomain", "=", "get_template", "(", ")", ";", "}", "}", "return", "$", "this", "->", "theme_textdomain", ";", "}" ]
Get the theme's textdomain. @since 3.0.12 @access private @return string
[ "Get", "the", "theme", "s", "textdomain", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/L10n.php#L134-L147
train
aristath/kirki
lib/class-kirki-color.php
Kirki_Color.sanitize_hex
public static function sanitize_hex( $color = '#FFFFFF', $hash = true ) { if ( ! $hash ) { return ltrim( self::sanitize_color( $color, 'hex' ), '#' ); } return self::sanitize_color( $color, 'hex' ); }
php
public static function sanitize_hex( $color = '#FFFFFF', $hash = true ) { if ( ! $hash ) { return ltrim( self::sanitize_color( $color, 'hex' ), '#' ); } return self::sanitize_color( $color, 'hex' ); }
[ "public", "static", "function", "sanitize_hex", "(", "$", "color", "=", "'#FFFFFF'", ",", "$", "hash", "=", "true", ")", "{", "if", "(", "!", "$", "hash", ")", "{", "return", "ltrim", "(", "self", "::", "sanitize_color", "(", "$", "color", ",", "'hex'", ")", ",", "'#'", ")", ";", "}", "return", "self", "::", "sanitize_color", "(", "$", "color", ",", "'hex'", ")", ";", "}" ]
A proxy for the sanitize_color method. @param string|array $color The color. @param bool $hash Whether we want to include a hash (#) at the beginning or not. @return string The sanitized hex color.
[ "A", "proxy", "for", "the", "sanitize_color", "method", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/lib/class-kirki-color.php#L33-L38
train
aristath/kirki
lib/class-kirki-color.php
Kirki_Color.sanitize_color
public static function sanitize_color( $color = '', $mode = 'auto' ) { if ( is_string( $color ) && 'transparent' == trim( $color ) ) { return 'transparent'; } $obj = ariColor::newColor( $color ); if ( 'auto' == $mode ) { $mode = $obj->mode; } return $obj->toCSS( $mode ); }
php
public static function sanitize_color( $color = '', $mode = 'auto' ) { if ( is_string( $color ) && 'transparent' == trim( $color ) ) { return 'transparent'; } $obj = ariColor::newColor( $color ); if ( 'auto' == $mode ) { $mode = $obj->mode; } return $obj->toCSS( $mode ); }
[ "public", "static", "function", "sanitize_color", "(", "$", "color", "=", "''", ",", "$", "mode", "=", "'auto'", ")", "{", "if", "(", "is_string", "(", "$", "color", ")", "&&", "'transparent'", "==", "trim", "(", "$", "color", ")", ")", "{", "return", "'transparent'", ";", "}", "$", "obj", "=", "ariColor", "::", "newColor", "(", "$", "color", ")", ";", "if", "(", "'auto'", "==", "$", "mode", ")", "{", "$", "mode", "=", "$", "obj", "->", "mode", ";", "}", "return", "$", "obj", "->", "toCSS", "(", "$", "mode", ")", ";", "}" ]
Sanitize colors. Determine if the current value is a hex or an rgba color and call the appropriate method. @static @access public @since 0.8.5 @param string|array $color The color. @param string $mode The mode to be used. @return string
[ "Sanitize", "colors", ".", "Determine", "if", "the", "current", "value", "is", "a", "hex", "or", "an", "rgba", "color", "and", "call", "the", "appropriate", "method", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/lib/class-kirki-color.php#L63-L72
train
aristath/kirki
lib/class-kirki-color.php
Kirki_Color.get_rgb
public static function get_rgb( $color, $implode = false ) { $obj = ariColor::newColor( $color ); if ( $implode ) { return $obj->toCSS( 'rgb' ); } return array( $obj->red, $obj->green, $obj->blue ); }
php
public static function get_rgb( $color, $implode = false ) { $obj = ariColor::newColor( $color ); if ( $implode ) { return $obj->toCSS( 'rgb' ); } return array( $obj->red, $obj->green, $obj->blue ); }
[ "public", "static", "function", "get_rgb", "(", "$", "color", ",", "$", "implode", "=", "false", ")", "{", "$", "obj", "=", "ariColor", "::", "newColor", "(", "$", "color", ")", ";", "if", "(", "$", "implode", ")", "{", "return", "$", "obj", "->", "toCSS", "(", "'rgb'", ")", ";", "}", "return", "array", "(", "$", "obj", "->", "red", ",", "$", "obj", "->", "green", ",", "$", "obj", "->", "blue", ")", ";", "}" ]
Gets the rgb value of a color. @static @access public @param string $color The color. @param boolean $implode Whether we want to implode the values or not. @return array|string
[ "Gets", "the", "rgb", "value", "of", "a", "color", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/lib/class-kirki-color.php#L83-L89
train
aristath/kirki
lib/class-kirki-color.php
Kirki_Color.color_difference
public static function color_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { $color_1 = self::sanitize_hex( $color_1, false ); $color_2 = self::sanitize_hex( $color_2, false ); $color_1_rgb = self::get_rgb( $color_1 ); $color_2_rgb = self::get_rgb( $color_2 ); $r_diff = max( $color_1_rgb[0], $color_2_rgb[0] ) - min( $color_1_rgb[0], $color_2_rgb[0] ); $g_diff = max( $color_1_rgb[1], $color_2_rgb[1] ) - min( $color_1_rgb[1], $color_2_rgb[1] ); $b_diff = max( $color_1_rgb[2], $color_2_rgb[2] ) - min( $color_1_rgb[2], $color_2_rgb[2] ); $color_diff = $r_diff + $g_diff + $b_diff; return $color_diff; }
php
public static function color_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { $color_1 = self::sanitize_hex( $color_1, false ); $color_2 = self::sanitize_hex( $color_2, false ); $color_1_rgb = self::get_rgb( $color_1 ); $color_2_rgb = self::get_rgb( $color_2 ); $r_diff = max( $color_1_rgb[0], $color_2_rgb[0] ) - min( $color_1_rgb[0], $color_2_rgb[0] ); $g_diff = max( $color_1_rgb[1], $color_2_rgb[1] ) - min( $color_1_rgb[1], $color_2_rgb[1] ); $b_diff = max( $color_1_rgb[2], $color_2_rgb[2] ) - min( $color_1_rgb[2], $color_2_rgb[2] ); $color_diff = $r_diff + $g_diff + $b_diff; return $color_diff; }
[ "public", "static", "function", "color_difference", "(", "$", "color_1", "=", "'#ffffff'", ",", "$", "color_2", "=", "'#000000'", ")", "{", "$", "color_1", "=", "self", "::", "sanitize_hex", "(", "$", "color_1", ",", "false", ")", ";", "$", "color_2", "=", "self", "::", "sanitize_hex", "(", "$", "color_2", ",", "false", ")", ";", "$", "color_1_rgb", "=", "self", "::", "get_rgb", "(", "$", "color_1", ")", ";", "$", "color_2_rgb", "=", "self", "::", "get_rgb", "(", "$", "color_2", ")", ";", "$", "r_diff", "=", "max", "(", "$", "color_1_rgb", "[", "0", "]", ",", "$", "color_2_rgb", "[", "0", "]", ")", "-", "min", "(", "$", "color_1_rgb", "[", "0", "]", ",", "$", "color_2_rgb", "[", "0", "]", ")", ";", "$", "g_diff", "=", "max", "(", "$", "color_1_rgb", "[", "1", "]", ",", "$", "color_2_rgb", "[", "1", "]", ")", "-", "min", "(", "$", "color_1_rgb", "[", "1", "]", ",", "$", "color_2_rgb", "[", "1", "]", ")", ";", "$", "b_diff", "=", "max", "(", "$", "color_1_rgb", "[", "2", "]", ",", "$", "color_2_rgb", "[", "2", "]", ")", "-", "min", "(", "$", "color_1_rgb", "[", "2", "]", ",", "$", "color_2_rgb", "[", "2", "]", ")", ";", "$", "color_diff", "=", "$", "r_diff", "+", "$", "g_diff", "+", "$", "b_diff", ";", "return", "$", "color_diff", ";", "}" ]
This is a very simple algorithm that works by summing up the differences between the three color components red, green and blue. A value higher than 500 is recommended for good readability. @static @access public @param string $color_1 The 1st color. @param string $color_2 The 2nd color. @return string
[ "This", "is", "a", "very", "simple", "algorithm", "that", "works", "by", "summing", "up", "the", "differences", "between", "the", "three", "color", "components", "red", "green", "and", "blue", ".", "A", "value", "higher", "than", "500", "is", "recommended", "for", "good", "readability", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/lib/class-kirki-color.php#L289-L299
train
aristath/kirki
lib/class-kirki-color.php
Kirki_Color.brightness_difference
public static function brightness_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { $color_1 = self::sanitize_hex( $color_1, false ); $color_2 = self::sanitize_hex( $color_2, false ); $color_1_rgb = self::get_rgb( $color_1 ); $color_2_rgb = self::get_rgb( $color_2 ); $br_1 = ( 299 * $color_1_rgb[0] + 587 * $color_1_rgb[1] + 114 * $color_1_rgb[2] ) / 1000; $br_2 = ( 299 * $color_2_rgb[0] + 587 * $color_2_rgb[1] + 114 * $color_2_rgb[2] ) / 1000; return intval( abs( $br_1 - $br_2 ) ); }
php
public static function brightness_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { $color_1 = self::sanitize_hex( $color_1, false ); $color_2 = self::sanitize_hex( $color_2, false ); $color_1_rgb = self::get_rgb( $color_1 ); $color_2_rgb = self::get_rgb( $color_2 ); $br_1 = ( 299 * $color_1_rgb[0] + 587 * $color_1_rgb[1] + 114 * $color_1_rgb[2] ) / 1000; $br_2 = ( 299 * $color_2_rgb[0] + 587 * $color_2_rgb[1] + 114 * $color_2_rgb[2] ) / 1000; return intval( abs( $br_1 - $br_2 ) ); }
[ "public", "static", "function", "brightness_difference", "(", "$", "color_1", "=", "'#ffffff'", ",", "$", "color_2", "=", "'#000000'", ")", "{", "$", "color_1", "=", "self", "::", "sanitize_hex", "(", "$", "color_1", ",", "false", ")", ";", "$", "color_2", "=", "self", "::", "sanitize_hex", "(", "$", "color_2", ",", "false", ")", ";", "$", "color_1_rgb", "=", "self", "::", "get_rgb", "(", "$", "color_1", ")", ";", "$", "color_2_rgb", "=", "self", "::", "get_rgb", "(", "$", "color_2", ")", ";", "$", "br_1", "=", "(", "299", "*", "$", "color_1_rgb", "[", "0", "]", "+", "587", "*", "$", "color_1_rgb", "[", "1", "]", "+", "114", "*", "$", "color_1_rgb", "[", "2", "]", ")", "/", "1000", ";", "$", "br_2", "=", "(", "299", "*", "$", "color_2_rgb", "[", "0", "]", "+", "587", "*", "$", "color_2_rgb", "[", "1", "]", "+", "114", "*", "$", "color_2_rgb", "[", "2", "]", ")", "/", "1000", ";", "return", "intval", "(", "abs", "(", "$", "br_1", "-", "$", "br_2", ")", ")", ";", "}" ]
This function tries to compare the brightness of the colors. A return value of more than 125 is recommended. Combining it with the color_difference function above might make sense. @static @access public @param string $color_1 The 1st color. @param string $color_2 The 2nd color. @return string
[ "This", "function", "tries", "to", "compare", "the", "brightness", "of", "the", "colors", ".", "A", "return", "value", "of", "more", "than", "125", "is", "recommended", ".", "Combining", "it", "with", "the", "color_difference", "function", "above", "might", "make", "sense", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/lib/class-kirki-color.php#L312-L320
train
aristath/kirki
lib/class-kirki-color.php
Kirki_Color.lumosity_difference
public static function lumosity_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { $color_1 = self::sanitize_hex( $color_1, false ); $color_2 = self::sanitize_hex( $color_2, false ); $color_1_rgb = self::get_rgb( $color_1 ); $color_2_rgb = self::get_rgb( $color_2 ); $l1 = 0.2126 * pow( $color_1_rgb[0] / 255, 2.2 ) + 0.7152 * pow( $color_1_rgb[1] / 255, 2.2 ) + 0.0722 * pow( $color_1_rgb[2] / 255, 2.2 ); $l2 = 0.2126 * pow( $color_2_rgb[0] / 255, 2.2 ) + 0.7152 * pow( $color_2_rgb[1] / 255, 2.2 ) + 0.0722 * pow( $color_2_rgb[2] / 255, 2.2 ); $lum_diff = ( $l1 > $l2 ) ? ( $l1 + 0.05 ) / ( $l2 + 0.05 ) : ( $l2 + 0.05 ) / ( $l1 + 0.05 ); return round( $lum_diff, 2 ); }
php
public static function lumosity_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { $color_1 = self::sanitize_hex( $color_1, false ); $color_2 = self::sanitize_hex( $color_2, false ); $color_1_rgb = self::get_rgb( $color_1 ); $color_2_rgb = self::get_rgb( $color_2 ); $l1 = 0.2126 * pow( $color_1_rgb[0] / 255, 2.2 ) + 0.7152 * pow( $color_1_rgb[1] / 255, 2.2 ) + 0.0722 * pow( $color_1_rgb[2] / 255, 2.2 ); $l2 = 0.2126 * pow( $color_2_rgb[0] / 255, 2.2 ) + 0.7152 * pow( $color_2_rgb[1] / 255, 2.2 ) + 0.0722 * pow( $color_2_rgb[2] / 255, 2.2 ); $lum_diff = ( $l1 > $l2 ) ? ( $l1 + 0.05 ) / ( $l2 + 0.05 ) : ( $l2 + 0.05 ) / ( $l1 + 0.05 ); return round( $lum_diff, 2 ); }
[ "public", "static", "function", "lumosity_difference", "(", "$", "color_1", "=", "'#ffffff'", ",", "$", "color_2", "=", "'#000000'", ")", "{", "$", "color_1", "=", "self", "::", "sanitize_hex", "(", "$", "color_1", ",", "false", ")", ";", "$", "color_2", "=", "self", "::", "sanitize_hex", "(", "$", "color_2", ",", "false", ")", ";", "$", "color_1_rgb", "=", "self", "::", "get_rgb", "(", "$", "color_1", ")", ";", "$", "color_2_rgb", "=", "self", "::", "get_rgb", "(", "$", "color_2", ")", ";", "$", "l1", "=", "0.2126", "*", "pow", "(", "$", "color_1_rgb", "[", "0", "]", "/", "255", ",", "2.2", ")", "+", "0.7152", "*", "pow", "(", "$", "color_1_rgb", "[", "1", "]", "/", "255", ",", "2.2", ")", "+", "0.0722", "*", "pow", "(", "$", "color_1_rgb", "[", "2", "]", "/", "255", ",", "2.2", ")", ";", "$", "l2", "=", "0.2126", "*", "pow", "(", "$", "color_2_rgb", "[", "0", "]", "/", "255", ",", "2.2", ")", "+", "0.7152", "*", "pow", "(", "$", "color_2_rgb", "[", "1", "]", "/", "255", ",", "2.2", ")", "+", "0.0722", "*", "pow", "(", "$", "color_2_rgb", "[", "2", "]", "/", "255", ",", "2.2", ")", ";", "$", "lum_diff", "=", "(", "$", "l1", ">", "$", "l2", ")", "?", "(", "$", "l1", "+", "0.05", ")", "/", "(", "$", "l2", "+", "0.05", ")", ":", "(", "$", "l2", "+", "0.05", ")", "/", "(", "$", "l1", "+", "0.05", ")", ";", "return", "round", "(", "$", "lum_diff", ",", "2", ")", ";", "}" ]
Uses the luminosity to calculate the difference between the given colors. The returned value should be bigger than 5 for best readability. @static @access public @param string $color_1 The 1st color. @param string $color_2 The 2nd color. @return string
[ "Uses", "the", "luminosity", "to", "calculate", "the", "difference", "between", "the", "given", "colors", ".", "The", "returned", "value", "should", "be", "bigger", "than", "5", "for", "best", "readability", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/lib/class-kirki-color.php#L332-L341
train
aristath/kirki
packages/kirki-framework/module-custom-sections/src/Module.php
Module.include_sections_and_panels
public function include_sections_and_panels() { // Sections. $folder_path = dirname( __FILE__ ) . '/sections/'; $section_types = apply_filters( 'kirki_section_types', [] ); foreach ( $section_types as $id => $class ) { if ( ! class_exists( $class ) ) { $path = wp_normalize_path( $folder_path . 'class-kirki-sections-' . $id . '-section.php' ); if ( file_exists( $path ) ) { include_once $path; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude continue; } $path = str_replace( 'class-kirki-sections-kirki-', 'class-kirki-sections-', $path ); if ( file_exists( $path ) ) { include_once $path; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude } } } // Panels. $folder_path = dirname( __FILE__ ) . '/panels/'; $panel_types = apply_filters( 'kirki_panel_types', [] ); foreach ( $panel_types as $id => $class ) { if ( ! class_exists( $class ) ) { $path = wp_normalize_path( $folder_path . 'class-kirki-panels-' . $id . '-panel.php' ); if ( file_exists( $path ) ) { include_once $path; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude continue; } $path = str_replace( 'class-kirki-panels-kirki-', 'class-kirki-panels-', $path ); if ( file_exists( $path ) ) { include_once $path; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude } } } }
php
public function include_sections_and_panels() { // Sections. $folder_path = dirname( __FILE__ ) . '/sections/'; $section_types = apply_filters( 'kirki_section_types', [] ); foreach ( $section_types as $id => $class ) { if ( ! class_exists( $class ) ) { $path = wp_normalize_path( $folder_path . 'class-kirki-sections-' . $id . '-section.php' ); if ( file_exists( $path ) ) { include_once $path; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude continue; } $path = str_replace( 'class-kirki-sections-kirki-', 'class-kirki-sections-', $path ); if ( file_exists( $path ) ) { include_once $path; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude } } } // Panels. $folder_path = dirname( __FILE__ ) . '/panels/'; $panel_types = apply_filters( 'kirki_panel_types', [] ); foreach ( $panel_types as $id => $class ) { if ( ! class_exists( $class ) ) { $path = wp_normalize_path( $folder_path . 'class-kirki-panels-' . $id . '-panel.php' ); if ( file_exists( $path ) ) { include_once $path; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude continue; } $path = str_replace( 'class-kirki-panels-kirki-', 'class-kirki-panels-', $path ); if ( file_exists( $path ) ) { include_once $path; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude } } } }
[ "public", "function", "include_sections_and_panels", "(", ")", "{", "// Sections.", "$", "folder_path", "=", "dirname", "(", "__FILE__", ")", ".", "'/sections/'", ";", "$", "section_types", "=", "apply_filters", "(", "'kirki_section_types'", ",", "[", "]", ")", ";", "foreach", "(", "$", "section_types", "as", "$", "id", "=>", "$", "class", ")", "{", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "$", "path", "=", "wp_normalize_path", "(", "$", "folder_path", ".", "'class-kirki-sections-'", ".", "$", "id", ".", "'-section.php'", ")", ";", "if", "(", "file_exists", "(", "$", "path", ")", ")", "{", "include_once", "$", "path", ";", "// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude", "continue", ";", "}", "$", "path", "=", "str_replace", "(", "'class-kirki-sections-kirki-'", ",", "'class-kirki-sections-'", ",", "$", "path", ")", ";", "if", "(", "file_exists", "(", "$", "path", ")", ")", "{", "include_once", "$", "path", ";", "// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude", "}", "}", "}", "// Panels.", "$", "folder_path", "=", "dirname", "(", "__FILE__", ")", ".", "'/panels/'", ";", "$", "panel_types", "=", "apply_filters", "(", "'kirki_panel_types'", ",", "[", "]", ")", ";", "foreach", "(", "$", "panel_types", "as", "$", "id", "=>", "$", "class", ")", "{", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "$", "path", "=", "wp_normalize_path", "(", "$", "folder_path", ".", "'class-kirki-panels-'", ".", "$", "id", ".", "'-panel.php'", ")", ";", "if", "(", "file_exists", "(", "$", "path", ")", ")", "{", "include_once", "$", "path", ";", "// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude", "continue", ";", "}", "$", "path", "=", "str_replace", "(", "'class-kirki-panels-kirki-'", ",", "'class-kirki-panels-'", ",", "$", "path", ")", ";", "if", "(", "file_exists", "(", "$", "path", ")", ")", "{", "include_once", "$", "path", ";", "// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude", "}", "}", "}", "}" ]
Include the custom-section classes. @access public @since 3.0.0
[ "Include", "the", "custom", "-", "section", "classes", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-custom-sections/src/Module.php#L119-L156
train
aristath/kirki
packages/kirki-framework/module-custom-sections/src/Module.php
Module.enqueue_scrips
public function enqueue_scrips() { wp_enqueue_style( 'kirki-custom-sections', URL::get_from_path( __DIR__ . '/assets/styles/sections.css' ), [], KIRKI_VERSION ); wp_enqueue_script( 'kirki-custom-sections', URL::get_from_path( __DIR__ . '/assets/scripts/sections.js' ), [ 'jquery', 'customize-base', 'customize-controls' ], KIRKI_VERSION, false ); }
php
public function enqueue_scrips() { wp_enqueue_style( 'kirki-custom-sections', URL::get_from_path( __DIR__ . '/assets/styles/sections.css' ), [], KIRKI_VERSION ); wp_enqueue_script( 'kirki-custom-sections', URL::get_from_path( __DIR__ . '/assets/scripts/sections.js' ), [ 'jquery', 'customize-base', 'customize-controls' ], KIRKI_VERSION, false ); }
[ "public", "function", "enqueue_scrips", "(", ")", "{", "wp_enqueue_style", "(", "'kirki-custom-sections'", ",", "URL", "::", "get_from_path", "(", "__DIR__", ".", "'/assets/styles/sections.css'", ")", ",", "[", "]", ",", "KIRKI_VERSION", ")", ";", "wp_enqueue_script", "(", "'kirki-custom-sections'", ",", "URL", "::", "get_from_path", "(", "__DIR__", ".", "'/assets/scripts/sections.js'", ")", ",", "[", "'jquery'", ",", "'customize-base'", ",", "'customize-controls'", "]", ",", "KIRKI_VERSION", ",", "false", ")", ";", "}" ]
Enqueues any necessary scripts and styles. @access public @since 3.0.0
[ "Enqueues", "any", "necessary", "scripts", "and", "styles", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-custom-sections/src/Module.php#L164-L167
train
aristath/kirki
packages/kirki-framework/control-dimensions/src/Field/Dimensions.php
Dimensions.sanitize
public static function sanitize( $value ) { // Sanitize each sub-value separately. foreach ( $value as $key => $sub_value ) { $value[ $key ] = sanitize_text_field( $sub_value ); } return $value; }
php
public static function sanitize( $value ) { // Sanitize each sub-value separately. foreach ( $value as $key => $sub_value ) { $value[ $key ] = sanitize_text_field( $sub_value ); } return $value; }
[ "public", "static", "function", "sanitize", "(", "$", "value", ")", "{", "// Sanitize each sub-value separately.", "foreach", "(", "$", "value", "as", "$", "key", "=>", "$", "sub_value", ")", "{", "$", "value", "[", "$", "key", "]", "=", "sanitize_text_field", "(", "$", "sub_value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Sanitizes the value. @static @access public @since 1.0 @param array $value The value. @return array
[ "Sanitizes", "the", "value", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-dimensions/src/Field/Dimensions.php#L55-L62
train
aristath/kirki
packages/kirki-framework/control-color/src/Field/Color.php
Color.filter_setting_args
public function filter_setting_args( $args, $wp_customize ) { if ( $args['settings'] !== $args['settings'] ) { return $args; } // Set the sanitize-callback if none is defined. if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { $args['sanitize_callback'] = [ __CLASS__, 'sanitize' ]; // If this is a hue control then its value should be an integer. if ( isset( $args['mode'] ) && 'hue' === $args['mode'] ) { $args['sanitize_callback'] = 'absint'; } } return $args; }
php
public function filter_setting_args( $args, $wp_customize ) { if ( $args['settings'] !== $args['settings'] ) { return $args; } // Set the sanitize-callback if none is defined. if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { $args['sanitize_callback'] = [ __CLASS__, 'sanitize' ]; // If this is a hue control then its value should be an integer. if ( isset( $args['mode'] ) && 'hue' === $args['mode'] ) { $args['sanitize_callback'] = 'absint'; } } return $args; }
[ "public", "function", "filter_setting_args", "(", "$", "args", ",", "$", "wp_customize", ")", "{", "if", "(", "$", "args", "[", "'settings'", "]", "!==", "$", "args", "[", "'settings'", "]", ")", "{", "return", "$", "args", ";", "}", "// Set the sanitize-callback if none is defined.", "if", "(", "!", "isset", "(", "$", "args", "[", "'sanitize_callback'", "]", ")", "||", "!", "$", "args", "[", "'sanitize_callback'", "]", ")", "{", "$", "args", "[", "'sanitize_callback'", "]", "=", "[", "__CLASS__", ",", "'sanitize'", "]", ";", "// If this is a hue control then its value should be an integer.", "if", "(", "isset", "(", "$", "args", "[", "'mode'", "]", ")", "&&", "'hue'", "===", "$", "args", "[", "'mode'", "]", ")", "{", "$", "args", "[", "'sanitize_callback'", "]", "=", "'absint'", ";", "}", "}", "return", "$", "args", ";", "}" ]
Filter arguments before creating the setting. @access public @since 0.1 @param array $args The field arguments. @param WP_Customize_Manager $wp_customize The customizer instance. @return array
[ "Filter", "arguments", "before", "creating", "the", "setting", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-color/src/Field/Color.php#L52-L68
train
aristath/kirki
packages/kirki-framework/control-color/src/Field/Color.php
Color.filter_control_args
public function filter_control_args( $args, $wp_customize ) { if ( $args['settings'] !== $args['settings'] ) { return $args; } $args = parent::filter_control_args( $args, $wp_customize ); // Set the control-type. $args['type'] = 'kirki-color'; // Make sure choices is an array. if ( ! isset( $args['choices'] ) || ! \is_array( $args['choices'] ) ) { $args['choices'] = []; } // Set alpha argument. $args['choices']['alpha'] = isset( $args['choices']['alpha'] ) ? (bool) $args['choices']['alpha'] : false; // Set mode. if ( ! isset( $args['choices']['mode'] ) ) { $args['choices']['mode'] = isset( $args['mode'] ) ? $args['mode'] : 'full'; } return $args; }
php
public function filter_control_args( $args, $wp_customize ) { if ( $args['settings'] !== $args['settings'] ) { return $args; } $args = parent::filter_control_args( $args, $wp_customize ); // Set the control-type. $args['type'] = 'kirki-color'; // Make sure choices is an array. if ( ! isset( $args['choices'] ) || ! \is_array( $args['choices'] ) ) { $args['choices'] = []; } // Set alpha argument. $args['choices']['alpha'] = isset( $args['choices']['alpha'] ) ? (bool) $args['choices']['alpha'] : false; // Set mode. if ( ! isset( $args['choices']['mode'] ) ) { $args['choices']['mode'] = isset( $args['mode'] ) ? $args['mode'] : 'full'; } return $args; }
[ "public", "function", "filter_control_args", "(", "$", "args", ",", "$", "wp_customize", ")", "{", "if", "(", "$", "args", "[", "'settings'", "]", "!==", "$", "args", "[", "'settings'", "]", ")", "{", "return", "$", "args", ";", "}", "$", "args", "=", "parent", "::", "filter_control_args", "(", "$", "args", ",", "$", "wp_customize", ")", ";", "// Set the control-type.", "$", "args", "[", "'type'", "]", "=", "'kirki-color'", ";", "// Make sure choices is an array.", "if", "(", "!", "isset", "(", "$", "args", "[", "'choices'", "]", ")", "||", "!", "\\", "is_array", "(", "$", "args", "[", "'choices'", "]", ")", ")", "{", "$", "args", "[", "'choices'", "]", "=", "[", "]", ";", "}", "// Set alpha argument.", "$", "args", "[", "'choices'", "]", "[", "'alpha'", "]", "=", "isset", "(", "$", "args", "[", "'choices'", "]", "[", "'alpha'", "]", ")", "?", "(", "bool", ")", "$", "args", "[", "'choices'", "]", "[", "'alpha'", "]", ":", "false", ";", "// Set mode.", "if", "(", "!", "isset", "(", "$", "args", "[", "'choices'", "]", "[", "'mode'", "]", ")", ")", "{", "$", "args", "[", "'choices'", "]", "[", "'mode'", "]", "=", "isset", "(", "$", "args", "[", "'mode'", "]", ")", "?", "$", "args", "[", "'mode'", "]", ":", "'full'", ";", "}", "return", "$", "args", ";", "}" ]
Filter arguments before creating the control. @access public @since 0.1 @param array $args The field arguments. @param WP_Customize_Manager $wp_customize The customizer instance. @return array
[ "Filter", "arguments", "before", "creating", "the", "control", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-color/src/Field/Color.php#L79-L103
train
aristath/kirki
packages/kirki-framework/module-loading/src/Module.php
Module.init
public function init() { global $wp_customize; if ( ! $wp_customize ) { return; } // Allow disabling the custom loader using the kirki_config filter. $config = apply_filters( 'kirki_config', [] ); if ( isset( $config['disable_loader'] ) && true === $config['disable_loader'] ) { return; } // Add the "loading" icon. add_action( 'wp_footer', [ $this, 'add_loader_to_footer' ] ); add_action( 'wp_head', [ $this, 'add_loader_styles_to_header' ], 99 ); $this->remove_default_loading_styles(); }
php
public function init() { global $wp_customize; if ( ! $wp_customize ) { return; } // Allow disabling the custom loader using the kirki_config filter. $config = apply_filters( 'kirki_config', [] ); if ( isset( $config['disable_loader'] ) && true === $config['disable_loader'] ) { return; } // Add the "loading" icon. add_action( 'wp_footer', [ $this, 'add_loader_to_footer' ] ); add_action( 'wp_head', [ $this, 'add_loader_styles_to_header' ], 99 ); $this->remove_default_loading_styles(); }
[ "public", "function", "init", "(", ")", "{", "global", "$", "wp_customize", ";", "if", "(", "!", "$", "wp_customize", ")", "{", "return", ";", "}", "// Allow disabling the custom loader using the kirki_config filter.", "$", "config", "=", "apply_filters", "(", "'kirki_config'", ",", "[", "]", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'disable_loader'", "]", ")", "&&", "true", "===", "$", "config", "[", "'disable_loader'", "]", ")", "{", "return", ";", "}", "// Add the \"loading\" icon.", "add_action", "(", "'wp_footer'", ",", "[", "$", "this", ",", "'add_loader_to_footer'", "]", ")", ";", "add_action", "(", "'wp_head'", ",", "[", "$", "this", ",", "'add_loader_styles_to_header'", "]", ",", "99", ")", ";", "$", "this", "->", "remove_default_loading_styles", "(", ")", ";", "}" ]
Runs on init. @access public @since 3.0.0
[ "Runs", "on", "init", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-loading/src/Module.php#L63-L77
train
aristath/kirki
packages/kirki-framework/core/src/Control.php
Control.get_control_class_name
final private function get_control_class_name( $args ) { // Set a default class name. $class_name = 'WP_Customize_Control'; // Get the classname from the array of control classnames. if ( array_key_exists( $args['type'], self::$control_types ) ) { $class_name = self::$control_types[ $args['type'] ]; } return $class_name; }
php
final private function get_control_class_name( $args ) { // Set a default class name. $class_name = 'WP_Customize_Control'; // Get the classname from the array of control classnames. if ( array_key_exists( $args['type'], self::$control_types ) ) { $class_name = self::$control_types[ $args['type'] ]; } return $class_name; }
[ "final", "private", "function", "get_control_class_name", "(", "$", "args", ")", "{", "// Set a default class name.", "$", "class_name", "=", "'WP_Customize_Control'", ";", "// Get the classname from the array of control classnames.", "if", "(", "array_key_exists", "(", "$", "args", "[", "'type'", "]", ",", "self", "::", "$", "control_types", ")", ")", "{", "$", "class_name", "=", "self", "::", "$", "control_types", "[", "$", "args", "[", "'type'", "]", "]", ";", "}", "return", "$", "class_name", ";", "}" ]
Get the class name of the class needed to create tis control. @access private @param array $args The field definition as sanitized in Kirki\Field. @return string the name of the class that will be used to create this control.
[ "Get", "the", "class", "name", "of", "the", "class", "needed", "to", "create", "tis", "control", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Control.php#L67-L77
train
aristath/kirki
packages/kirki-framework/core/src/Control.php
Control.add_control
final protected function add_control( $args ) { // Get the name of the class we're going to use. $class_name = $this->get_control_class_name( $args ); // Add the control. $this->wp_customize->add_control( new $class_name( $this->wp_customize, $args['settings'], $args ) ); }
php
final protected function add_control( $args ) { // Get the name of the class we're going to use. $class_name = $this->get_control_class_name( $args ); // Add the control. $this->wp_customize->add_control( new $class_name( $this->wp_customize, $args['settings'], $args ) ); }
[ "final", "protected", "function", "add_control", "(", "$", "args", ")", "{", "// Get the name of the class we're going to use.", "$", "class_name", "=", "$", "this", "->", "get_control_class_name", "(", "$", "args", ")", ";", "// Add the control.", "$", "this", "->", "wp_customize", "->", "add_control", "(", "new", "$", "class_name", "(", "$", "this", "->", "wp_customize", ",", "$", "args", "[", "'settings'", "]", ",", "$", "args", ")", ")", ";", "}" ]
Adds the control. @access protected @param array $args The field definition as sanitized in Kirki\Field.
[ "Adds", "the", "control", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Control.php#L85-L93
train
aristath/kirki
packages/kirki-framework/control-image/src/Field/Image.php
Image.set_button_labels
protected function set_button_labels() { $this->button_labels = wp_parse_args( $this->button_labels, [ 'select' => esc_html__( 'Select image', 'kirki' ), 'change' => esc_html__( 'Change image', 'kirki' ), 'default' => esc_html__( 'Default', 'kirki' ), 'remove' => esc_html__( 'Remove', 'kirki' ), 'placeholder' => esc_html__( 'No image selected', 'kirki' ), 'frame_title' => esc_html__( 'Select image', 'kirki' ), 'frame_button' => esc_html__( 'Choose image', 'kirki' ), ] ); }
php
protected function set_button_labels() { $this->button_labels = wp_parse_args( $this->button_labels, [ 'select' => esc_html__( 'Select image', 'kirki' ), 'change' => esc_html__( 'Change image', 'kirki' ), 'default' => esc_html__( 'Default', 'kirki' ), 'remove' => esc_html__( 'Remove', 'kirki' ), 'placeholder' => esc_html__( 'No image selected', 'kirki' ), 'frame_title' => esc_html__( 'Select image', 'kirki' ), 'frame_button' => esc_html__( 'Choose image', 'kirki' ), ] ); }
[ "protected", "function", "set_button_labels", "(", ")", "{", "$", "this", "->", "button_labels", "=", "wp_parse_args", "(", "$", "this", "->", "button_labels", ",", "[", "'select'", "=>", "esc_html__", "(", "'Select image'", ",", "'kirki'", ")", ",", "'change'", "=>", "esc_html__", "(", "'Change image'", ",", "'kirki'", ")", ",", "'default'", "=>", "esc_html__", "(", "'Default'", ",", "'kirki'", ")", ",", "'remove'", "=>", "esc_html__", "(", "'Remove'", ",", "'kirki'", ")", ",", "'placeholder'", "=>", "esc_html__", "(", "'No image selected'", ",", "'kirki'", ")", ",", "'frame_title'", "=>", "esc_html__", "(", "'Select image'", ",", "'kirki'", ")", ",", "'frame_button'", "=>", "esc_html__", "(", "'Choose image'", ",", "'kirki'", ")", ",", "]", ")", ";", "}" ]
Sets the button labels. @access protected @since 1.0 @return void
[ "Sets", "the", "button", "labels", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-image/src/Field/Image.php#L48-L61
train
aristath/kirki
packages/kirki-framework/core/src/Util.php
Util.is_plugin
public static function is_plugin() { $is_plugin = false; if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude } // Get all plugins. $plugins = get_plugins(); $_plugin = ''; foreach ( $plugins as $plugin => $args ) { if ( ! $is_plugin && isset( $args['Name'] ) && ( 'Kirki' === $args['Name'] || 'Kirki Toolkit' === $args['Name'] ) ) { $is_plugin = true; $_plugin = $plugin; } } // No need to proceed any further if Kirki wasn't found in the list of plugins. if ( ! $is_plugin ) { return false; } // Make sure the is_plugins_loaded function is loaded. include_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude // Extra logic in case the plugin is installed but not activated. if ( $_plugin && is_plugin_inactive( $_plugin ) ) { return false; } return $is_plugin; }
php
public static function is_plugin() { $is_plugin = false; if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude } // Get all plugins. $plugins = get_plugins(); $_plugin = ''; foreach ( $plugins as $plugin => $args ) { if ( ! $is_plugin && isset( $args['Name'] ) && ( 'Kirki' === $args['Name'] || 'Kirki Toolkit' === $args['Name'] ) ) { $is_plugin = true; $_plugin = $plugin; } } // No need to proceed any further if Kirki wasn't found in the list of plugins. if ( ! $is_plugin ) { return false; } // Make sure the is_plugins_loaded function is loaded. include_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude // Extra logic in case the plugin is installed but not activated. if ( $_plugin && is_plugin_inactive( $_plugin ) ) { return false; } return $is_plugin; }
[ "public", "static", "function", "is_plugin", "(", ")", "{", "$", "is_plugin", "=", "false", ";", "if", "(", "!", "function_exists", "(", "'get_plugins'", ")", ")", "{", "require_once", "ABSPATH", ".", "'wp-admin/includes/plugin.php'", ";", "// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude", "}", "// Get all plugins.", "$", "plugins", "=", "get_plugins", "(", ")", ";", "$", "_plugin", "=", "''", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", "=>", "$", "args", ")", "{", "if", "(", "!", "$", "is_plugin", "&&", "isset", "(", "$", "args", "[", "'Name'", "]", ")", "&&", "(", "'Kirki'", "===", "$", "args", "[", "'Name'", "]", "||", "'Kirki Toolkit'", "===", "$", "args", "[", "'Name'", "]", ")", ")", "{", "$", "is_plugin", "=", "true", ";", "$", "_plugin", "=", "$", "plugin", ";", "}", "}", "// No need to proceed any further if Kirki wasn't found in the list of plugins.", "if", "(", "!", "$", "is_plugin", ")", "{", "return", "false", ";", "}", "// Make sure the is_plugins_loaded function is loaded.", "include_once", "ABSPATH", ".", "'wp-admin/includes/plugin.php'", ";", "// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude", "// Extra logic in case the plugin is installed but not activated.", "if", "(", "$", "_plugin", "&&", "is_plugin_inactive", "(", "$", "_plugin", ")", ")", "{", "return", "false", ";", "}", "return", "$", "is_plugin", ";", "}" ]
Determine if Kirki is installed as a plugin. @static @access public @since 3.0.0 @return bool
[ "Determine", "if", "Kirki", "is", "installed", "as", "a", "plugin", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Util.php#L40-L69
train
aristath/kirki
packages/kirki-framework/core/src/Util.php
Util.get_variables
public static function get_variables() { $variables = []; // Loop through all fields. foreach ( Kirki::$fields as $field ) { // Check if we have variables for this field. if ( isset( $field['variables'] ) && $field['variables'] && ! empty( $field['variables'] ) ) { // Loop through the array of variables. foreach ( $field['variables'] as $field_variable ) { // Is the variable ['name'] defined? If yes, then we can proceed. if ( isset( $field_variable['name'] ) ) { // Do we have a callback function defined? If not then set $variable_callback to false. $variable_callback = ( isset( $field_variable['callback'] ) && is_callable( $field_variable['callback'] ) ) ? $field_variable['callback'] : false; // If we have a variable_callback defined then get the value of the option // and run it through the callback function. // If no callback is defined (false) then just get the value. $variables[ $field_variable['name'] ] = Values::get_value( $field['settings'] ); if ( $variable_callback ) { $variables[ $field_variable['name'] ] = call_user_func( $field_variable['callback'], Values::get_value( $field['settings'] ) ); } } } } } // Pass the variables through a filter ('kirki_variable') and return the array of variables. return apply_filters( 'kirki_variable', $variables ); }
php
public static function get_variables() { $variables = []; // Loop through all fields. foreach ( Kirki::$fields as $field ) { // Check if we have variables for this field. if ( isset( $field['variables'] ) && $field['variables'] && ! empty( $field['variables'] ) ) { // Loop through the array of variables. foreach ( $field['variables'] as $field_variable ) { // Is the variable ['name'] defined? If yes, then we can proceed. if ( isset( $field_variable['name'] ) ) { // Do we have a callback function defined? If not then set $variable_callback to false. $variable_callback = ( isset( $field_variable['callback'] ) && is_callable( $field_variable['callback'] ) ) ? $field_variable['callback'] : false; // If we have a variable_callback defined then get the value of the option // and run it through the callback function. // If no callback is defined (false) then just get the value. $variables[ $field_variable['name'] ] = Values::get_value( $field['settings'] ); if ( $variable_callback ) { $variables[ $field_variable['name'] ] = call_user_func( $field_variable['callback'], Values::get_value( $field['settings'] ) ); } } } } } // Pass the variables through a filter ('kirki_variable') and return the array of variables. return apply_filters( 'kirki_variable', $variables ); }
[ "public", "static", "function", "get_variables", "(", ")", "{", "$", "variables", "=", "[", "]", ";", "// Loop through all fields.", "foreach", "(", "Kirki", "::", "$", "fields", "as", "$", "field", ")", "{", "// Check if we have variables for this field.", "if", "(", "isset", "(", "$", "field", "[", "'variables'", "]", ")", "&&", "$", "field", "[", "'variables'", "]", "&&", "!", "empty", "(", "$", "field", "[", "'variables'", "]", ")", ")", "{", "// Loop through the array of variables.", "foreach", "(", "$", "field", "[", "'variables'", "]", "as", "$", "field_variable", ")", "{", "// Is the variable ['name'] defined? If yes, then we can proceed.", "if", "(", "isset", "(", "$", "field_variable", "[", "'name'", "]", ")", ")", "{", "// Do we have a callback function defined? If not then set $variable_callback to false.", "$", "variable_callback", "=", "(", "isset", "(", "$", "field_variable", "[", "'callback'", "]", ")", "&&", "is_callable", "(", "$", "field_variable", "[", "'callback'", "]", ")", ")", "?", "$", "field_variable", "[", "'callback'", "]", ":", "false", ";", "// If we have a variable_callback defined then get the value of the option", "// and run it through the callback function.", "// If no callback is defined (false) then just get the value.", "$", "variables", "[", "$", "field_variable", "[", "'name'", "]", "]", "=", "Values", "::", "get_value", "(", "$", "field", "[", "'settings'", "]", ")", ";", "if", "(", "$", "variable_callback", ")", "{", "$", "variables", "[", "$", "field_variable", "[", "'name'", "]", "]", "=", "call_user_func", "(", "$", "field_variable", "[", "'callback'", "]", ",", "Values", "::", "get_value", "(", "$", "field", "[", "'settings'", "]", ")", ")", ";", "}", "}", "}", "}", "}", "// Pass the variables through a filter ('kirki_variable') and return the array of variables.", "return", "apply_filters", "(", "'kirki_variable'", ",", "$", "variables", ")", ";", "}" ]
Build the variables. @static @access public @since 3.0.9 @return array Formatted as array( 'variable-name' => value ).
[ "Build", "the", "variables", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Util.php#L79-L112
train
aristath/kirki
packages/kirki-framework/core/src/Util.php
Util.http_request
public function http_request( $request = [], $url = '' ) { // Early exit if installed as a plugin or not a request to wordpress.org, // or finally if we don't have everything we need. if ( self::is_plugin() || false === strpos( $url, 'wordpress.org' ) || ( ! isset( $request['body'] ) || ! isset( $request['body']['plugins'] ) || ! isset( $request['body']['translations'] ) || ! isset( $request['body']['locale'] ) || ! isset( $request['body']['all'] ) ) ) { return $request; } $plugins = json_decode( $request['body']['plugins'], true ); if ( ! isset( $plugins['plugins'] ) ) { return $request; } $exists = false; foreach ( $plugins['plugins'] as $plugin ) { if ( isset( $plugin['Name'] ) && 'Kirki Toolkit' === $plugin['Name'] ) { $exists = true; } } // Inject data. if ( ! $exists && defined( 'KIRKI_PLUGIN_FILE' ) ) { $plugins['plugins']['kirki/kirki.php'] = get_plugin_data( KIRKI_PLUGIN_FILE ); } $request['body']['plugins'] = wp_json_encode( $plugins ); return $request; }
php
public function http_request( $request = [], $url = '' ) { // Early exit if installed as a plugin or not a request to wordpress.org, // or finally if we don't have everything we need. if ( self::is_plugin() || false === strpos( $url, 'wordpress.org' ) || ( ! isset( $request['body'] ) || ! isset( $request['body']['plugins'] ) || ! isset( $request['body']['translations'] ) || ! isset( $request['body']['locale'] ) || ! isset( $request['body']['all'] ) ) ) { return $request; } $plugins = json_decode( $request['body']['plugins'], true ); if ( ! isset( $plugins['plugins'] ) ) { return $request; } $exists = false; foreach ( $plugins['plugins'] as $plugin ) { if ( isset( $plugin['Name'] ) && 'Kirki Toolkit' === $plugin['Name'] ) { $exists = true; } } // Inject data. if ( ! $exists && defined( 'KIRKI_PLUGIN_FILE' ) ) { $plugins['plugins']['kirki/kirki.php'] = get_plugin_data( KIRKI_PLUGIN_FILE ); } $request['body']['plugins'] = wp_json_encode( $plugins ); return $request; }
[ "public", "function", "http_request", "(", "$", "request", "=", "[", "]", ",", "$", "url", "=", "''", ")", "{", "// Early exit if installed as a plugin or not a request to wordpress.org,", "// or finally if we don't have everything we need.", "if", "(", "self", "::", "is_plugin", "(", ")", "||", "false", "===", "strpos", "(", "$", "url", ",", "'wordpress.org'", ")", "||", "(", "!", "isset", "(", "$", "request", "[", "'body'", "]", ")", "||", "!", "isset", "(", "$", "request", "[", "'body'", "]", "[", "'plugins'", "]", ")", "||", "!", "isset", "(", "$", "request", "[", "'body'", "]", "[", "'translations'", "]", ")", "||", "!", "isset", "(", "$", "request", "[", "'body'", "]", "[", "'locale'", "]", ")", "||", "!", "isset", "(", "$", "request", "[", "'body'", "]", "[", "'all'", "]", ")", ")", ")", "{", "return", "$", "request", ";", "}", "$", "plugins", "=", "json_decode", "(", "$", "request", "[", "'body'", "]", "[", "'plugins'", "]", ",", "true", ")", ";", "if", "(", "!", "isset", "(", "$", "plugins", "[", "'plugins'", "]", ")", ")", "{", "return", "$", "request", ";", "}", "$", "exists", "=", "false", ";", "foreach", "(", "$", "plugins", "[", "'plugins'", "]", "as", "$", "plugin", ")", "{", "if", "(", "isset", "(", "$", "plugin", "[", "'Name'", "]", ")", "&&", "'Kirki Toolkit'", "===", "$", "plugin", "[", "'Name'", "]", ")", "{", "$", "exists", "=", "true", ";", "}", "}", "// Inject data.", "if", "(", "!", "$", "exists", "&&", "defined", "(", "'KIRKI_PLUGIN_FILE'", ")", ")", "{", "$", "plugins", "[", "'plugins'", "]", "[", "'kirki/kirki.php'", "]", "=", "get_plugin_data", "(", "KIRKI_PLUGIN_FILE", ")", ";", "}", "$", "request", "[", "'body'", "]", "[", "'plugins'", "]", "=", "wp_json_encode", "(", "$", "plugins", ")", ";", "return", "$", "request", ";", "}" ]
HTTP Request injection. @access public @since 3.0.0 @param array $request The request params. @param string $url The request URL. @return array
[ "HTTP", "Request", "injection", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Util.php#L123-L156
train
aristath/kirki
packages/kirki-framework/module-css/src/Module.php
Module.enqueue_styles
public function enqueue_styles() { $args = [ 'action' => apply_filters( 'kirki_styles_action_handle', 'kirki-styles' ), ]; if ( is_admin() && ! is_customize_preview() ) { $args['editor'] = '1'; } // Enqueue the dynamic stylesheet. wp_enqueue_style( 'kirki-styles', add_query_arg( $args, site_url() ), [], KIRKI_VERSION ); // Enqueue FA if needed (I hope not, this FA version is pretty old, only kept here for backwards-compatibility purposes). if ( self::$enqueue_fa && apply_filters( 'kirki_load_fontawesome', true ) ) { wp_enqueue_script( 'kirki-fontawesome-font', 'https://use.fontawesome.com/30858dc40a.js', [], '4.0.7', true ); } }
php
public function enqueue_styles() { $args = [ 'action' => apply_filters( 'kirki_styles_action_handle', 'kirki-styles' ), ]; if ( is_admin() && ! is_customize_preview() ) { $args['editor'] = '1'; } // Enqueue the dynamic stylesheet. wp_enqueue_style( 'kirki-styles', add_query_arg( $args, site_url() ), [], KIRKI_VERSION ); // Enqueue FA if needed (I hope not, this FA version is pretty old, only kept here for backwards-compatibility purposes). if ( self::$enqueue_fa && apply_filters( 'kirki_load_fontawesome', true ) ) { wp_enqueue_script( 'kirki-fontawesome-font', 'https://use.fontawesome.com/30858dc40a.js', [], '4.0.7', true ); } }
[ "public", "function", "enqueue_styles", "(", ")", "{", "$", "args", "=", "[", "'action'", "=>", "apply_filters", "(", "'kirki_styles_action_handle'", ",", "'kirki-styles'", ")", ",", "]", ";", "if", "(", "is_admin", "(", ")", "&&", "!", "is_customize_preview", "(", ")", ")", "{", "$", "args", "[", "'editor'", "]", "=", "'1'", ";", "}", "// Enqueue the dynamic stylesheet.", "wp_enqueue_style", "(", "'kirki-styles'", ",", "add_query_arg", "(", "$", "args", ",", "site_url", "(", ")", ")", ",", "[", "]", ",", "KIRKI_VERSION", ")", ";", "// Enqueue FA if needed (I hope not, this FA version is pretty old, only kept here for backwards-compatibility purposes).", "if", "(", "self", "::", "$", "enqueue_fa", "&&", "apply_filters", "(", "'kirki_load_fontawesome'", ",", "true", ")", ")", "{", "wp_enqueue_script", "(", "'kirki-fontawesome-font'", ",", "'https://use.fontawesome.com/30858dc40a.js'", ",", "[", "]", ",", "'4.0.7'", ",", "true", ")", ";", "}", "}" ]
Enqueue the styles. @access public @since 3.0.36 @return void
[ "Enqueue", "the", "styles", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-css/src/Module.php#L198-L219
train
aristath/kirki
packages/kirki-framework/module-css/src/Module.php
Module.print_styles
public function print_styles() { // Go through all configs. $configs = Kirki::$config; foreach ( $configs as $config_id => $args ) { if ( isset( $args['disable_output'] ) && true === $args['disable_output'] ) { continue; } $styles = self::loop_controls( $config_id ); $styles = apply_filters( "kirki_{$config_id}_dynamic_css", $styles ); if ( ! empty( $styles ) ) { /** * Note to code reviewers: * * Though all output should be run through an escaping function, this is pure CSS. * * When used in the print_styles_action() method the PHP header() call makes the browser interpret it as such. * No code, script or anything else can be executed from inside a stylesheet. * * When using in the print_styles_inline() method the wp_strip_all_tags call we use below * strips anything that has the possibility to be malicious, and since this is inslide a <style> tag * it can only be interpreted by the browser as such. * wp_strip_all_tags() excludes the possibility of someone closing the <style> tag and then opening something else. */ echo wp_strip_all_tags( $styles ); // phpcs:ignore WordPress.Security.EscapeOutput } } do_action( 'kirki_dynamic_css' ); }
php
public function print_styles() { // Go through all configs. $configs = Kirki::$config; foreach ( $configs as $config_id => $args ) { if ( isset( $args['disable_output'] ) && true === $args['disable_output'] ) { continue; } $styles = self::loop_controls( $config_id ); $styles = apply_filters( "kirki_{$config_id}_dynamic_css", $styles ); if ( ! empty( $styles ) ) { /** * Note to code reviewers: * * Though all output should be run through an escaping function, this is pure CSS. * * When used in the print_styles_action() method the PHP header() call makes the browser interpret it as such. * No code, script or anything else can be executed from inside a stylesheet. * * When using in the print_styles_inline() method the wp_strip_all_tags call we use below * strips anything that has the possibility to be malicious, and since this is inslide a <style> tag * it can only be interpreted by the browser as such. * wp_strip_all_tags() excludes the possibility of someone closing the <style> tag and then opening something else. */ echo wp_strip_all_tags( $styles ); // phpcs:ignore WordPress.Security.EscapeOutput } } do_action( 'kirki_dynamic_css' ); }
[ "public", "function", "print_styles", "(", ")", "{", "// Go through all configs.", "$", "configs", "=", "Kirki", "::", "$", "config", ";", "foreach", "(", "$", "configs", "as", "$", "config_id", "=>", "$", "args", ")", "{", "if", "(", "isset", "(", "$", "args", "[", "'disable_output'", "]", ")", "&&", "true", "===", "$", "args", "[", "'disable_output'", "]", ")", "{", "continue", ";", "}", "$", "styles", "=", "self", "::", "loop_controls", "(", "$", "config_id", ")", ";", "$", "styles", "=", "apply_filters", "(", "\"kirki_{$config_id}_dynamic_css\"", ",", "$", "styles", ")", ";", "if", "(", "!", "empty", "(", "$", "styles", ")", ")", "{", "/**\n\t\t\t\t * Note to code reviewers:\n\t\t\t\t *\n\t\t\t\t * Though all output should be run through an escaping function, this is pure CSS.\n\t\t\t\t *\n\t\t\t\t * When used in the print_styles_action() method the PHP header() call makes the browser interpret it as such.\n\t\t\t\t * No code, script or anything else can be executed from inside a stylesheet.\n\t\t\t\t *\n\t\t\t\t * When using in the print_styles_inline() method the wp_strip_all_tags call we use below\n\t\t\t\t * strips anything that has the possibility to be malicious, and since this is inslide a <style> tag\n\t\t\t\t * it can only be interpreted by the browser as such.\n\t\t\t\t * wp_strip_all_tags() excludes the possibility of someone closing the <style> tag and then opening something else.\n\t\t\t\t */", "echo", "wp_strip_all_tags", "(", "$", "styles", ")", ";", "// phpcs:ignore WordPress.Security.EscapeOutput", "}", "}", "do_action", "(", "'kirki_dynamic_css'", ")", ";", "}" ]
Prints the styles. @access public
[ "Prints", "the", "styles", "." ]
b7549b52a3c470960d691357df262e6c9e9483f8
https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-css/src/Module.php#L248-L276
train