idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
9,100
|
private function findClasspathAndClass ( $ class ) { if ( false !== $ pos = strrpos ( $ class , '\\' ) ) { $ classpath = str_replace ( '\\' , DIRECTORY_SEPARATOR , substr ( $ class , 0 , $ pos ) ) . DIRECTORY_SEPARATOR ; $ classname = substr ( $ class , $ pos + 1 ) ; return array ( $ classpath , $ classname ) ; } $ classpath = null ; $ classname = $ class ; return array ( $ classpath , $ classname ) ; }
|
Finds classpath and classname from class .
|
9,101
|
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 .
|
9,102
|
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 .
|
9,103
|
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 .
|
9,104
|
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 .
|
9,105
|
private function appendSnippet ( AggregateSnippet $ snippet ) { foreach ( $ this -> appenders as $ appender ) { if ( ! $ appender -> supportsSnippet ( $ snippet ) ) { continue ; } $ appender -> appendSnippet ( $ snippet ) ; } }
|
Appends snippet to appropriate targets .
|
9,106
|
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 .
|
9,107
|
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 .
|
9,108
|
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 .
|
9,109
|
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 .
|
9,110
|
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 .
|
9,111
|
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 .
|
9,112
|
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 ( ) ; } $ pid = $ this -> getProcess ( ) -> getPid ( ) ; return $ pid ; }
|
Start the event execution .
|
9,113
|
public function cron ( string $ expression ) : self { $ 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 .
|
9,114
|
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 .
|
9,115
|
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 .
|
9,116
|
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 .
|
9,117
|
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 .
|
9,118
|
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 .
|
9,119
|
public function refreshLock ( ) : void { if ( ! $ this -> preventOverlapping ) { return ; } $ lock = $ this -> createLockObject ( ) ; $ remainingLifetime = $ lock -> getRemainingLifetime ( ) ; if ( null === $ remainingLifetime ) { return ; } $ lockRefreshNeeded = $ remainingLifetime < 15 ; if ( $ lockRefreshNeeded ) { $ lock -> refresh ( ) ; } }
|
If this event is prevented from overlapping this method should be called regularly to refresh the lock .
|
9,120
|
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 .
|
9,121
|
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 .
|
9,122
|
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 .
|
9,123
|
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 .
|
9,124
|
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 .
|
9,125
|
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 .
|
9,126
|
protected function replaceFrequency ( ) { $ this -> stub = \ str_replace ( 'DummyFrequency' , \ rtrim ( $ this -> options [ 'frequency' ] , '()' ) , $ this -> stub ) ; return $ this ; }
|
Replace frequency .
|
9,127
|
protected function replaceConstraint ( ) { $ this -> stub = \ str_replace ( 'DummyConstraint' , \ rtrim ( $ this -> options [ 'constraint' ] , '()' ) , $ this -> stub ) ; return $ this ; }
|
Replace constraint .
|
9,128
|
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 .
|
9,129
|
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 .
|
9,130
|
protected function id ( ) { while ( true ) { $ id = \ uniqid ( 'crunz' , true ) ; if ( ! \ array_key_exists ( $ id , $ this -> events ) ) { return $ id ; } } }
|
Generate a unique task id .
|
9,131
|
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 .
|
9,132
|
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 .
|
9,133
|
protected function getDefaultFormatter ( ) { $ allowLinebreaks = $ this -> configuration -> get ( 'log_allow_line_breaks' ) ; return new LineFormatter ( null , null , $ allowLinebreaks , false ) ; }
|
Get a default Monolog formatter instance .
|
9,134
|
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 ) ; $ this -> invoke ( $ schedule -> beforeCallbacks ( ) ) ; $ events = $ schedule -> events ( ) ; foreach ( $ events as $ event ) { $ this -> start ( $ event ) ; } } $ this -> manageStartedEvents ( ) ; }
|
Handle an array of Schedule objects .
|
9,135
|
protected function start ( Event $ event ) : void { if ( ! $ event -> nullOutput ( ) ) { if ( ! $ event -> shouldAppendOutput ) { $ f = @ \ fopen ( $ event -> output , 'r+' ) ; if ( false !== $ f ) { \ ftruncate ( $ f , 0 ) ; \ fclose ( $ f ) ; } } $ event -> logger = $ this -> loggerFactory -> create ( [ 'info' => $ event -> output , ] ) ; } $ this -> consoleLogger -> debug ( "Invoke Event's ping before." ) ; $ this -> pingBefore ( $ event ) ; $ event -> outputStream = ( $ this -> invoke ( $ event -> beforeCallbacks ( ) ) ) ; $ event -> start ( ) ; }
|
Run an event process .
|
9,136
|
protected function manageStartedEvents ( ) : void { while ( $ this -> schedules ) { foreach ( $ this -> schedules as $ scheduleKey => $ schedule ) { $ events = $ schedule -> events ( ) ; $ refreshLocks = ( \ mt_rand ( 1 , 100 ) <= 10 ) ; 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>' ; $ this -> invoke ( $ schedule -> errorCallbacks ( ) , [ $ event ] ) ; $ this -> handleError ( $ event ) ; } $ id = $ event -> description ? : $ event -> getId ( ) ; $ this -> consoleLogger -> debug ( "Task <info>${id}</info> status: {$runStatus}." ) ; $ schedule -> dismissEvent ( $ eventKey ) ; } 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 .
|
9,137
|
protected function invoke ( array $ callbacks = [ ] , array $ parameters = [ ] ) { $ output = '' ; foreach ( $ callbacks as $ callback ) { $ output .= $ this -> invoker -> call ( $ callback , $ parameters , true ) ; } return $ output ; }
|
Invoke an array of callables .
|
9,138
|
protected function formatEventError ( Event $ event ) { return $ event -> description . '(' . $ event -> getCommandForDisplay ( ) . ') ' . PHP_EOL . $ event -> wholeOutput ( ) . PHP_EOL ; }
|
Format the event error message .
|
9,139
|
private function getMailer ( ) : \ Swift_Mailer { if ( $ this -> mailer ) { return $ this -> mailer ; } 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 .
|
9,140
|
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 .
|
9,141
|
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 .
|
9,142
|
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 .
|
9,143
|
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 .
|
9,144
|
protected function get_root_value ( $ default = null ) { $ id_base = $ this -> id_data [ 'base' ] ; $ user_meta = get_user_meta ( get_current_user_id ( ) ) ; $ 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 .
|
9,145
|
protected function set_root_value ( $ value ) { $ id_base = $ this -> id_data [ 'base' ] ; delete_user_meta ( get_current_user_id ( ) , $ id_base ) ; return update_user_meta ( get_current_user_id ( ) , $ id_base , $ value ) ; }
|
Set the root value for a setting especially for multidimensional ones .
|
9,146
|
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' ] ; $ args [ 'transport' ] = 'refresh' ; if ( empty ( $ args [ 'js_vars' ] ) && ! empty ( $ args [ 'output' ] ) ) { foreach ( $ args [ 'output' ] as $ output ) { $ output [ 'function' ] = ( isset ( $ output [ 'function' ] ) ) ? $ output [ 'function' ] : 'style' ; if ( ! isset ( $ output [ 'element' ] ) ) { continue ; } if ( is_array ( $ output [ 'element' ] ) ) { $ output [ 'element' ] = implode ( ',' , $ output [ 'element' ] ) ; } if ( isset ( $ output [ 'sanitize_callback' ] ) && ! empty ( $ output [ 'sanitize_callback' ] ) && ! isset ( $ output [ 'js_callback' ] ) ) { continue ; } $ js_vars [ ] = $ output ; } } 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 .
|
9,147
|
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 .
|
9,148
|
protected function apply_sanitize_callback ( $ output , $ value ) { if ( isset ( $ output [ 'sanitize_callback' ] ) && null !== $ output [ 'sanitize_callback' ] ) { 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 .
|
9,149
|
protected function parse_output ( ) { foreach ( $ this -> output as $ output ) { $ skip = false ; $ value = $ this -> apply_sanitize_callback ( $ output , $ this -> value ) ; if ( '' === $ this -> value ) { $ skip = true ; } 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 ( isset ( $ output [ 'choice' ] ) && isset ( $ value [ $ output [ 'choice' ] ] ) && $ exclude == $ value [ $ output [ 'choice' ] ] ) { $ skip = true ; } } if ( $ skip ) { continue ; } if ( $ exclude === $ value || ( '' === $ exclude && empty ( $ value ) ) ) { $ skip = true ; } } } if ( $ skip ) { continue ; } $ 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' ] ) ) { if ( ! isset ( $ output [ 'context' ] ) || ! in_array ( 'editor' , $ output [ 'context' ] , true ) ) { continue ; } } elseif ( isset ( $ output [ 'context' ] ) && ! in_array ( 'front' , $ output [ 'context' ] , true ) ) { continue ; } $ this -> process_output ( $ output , $ value ) ; } }
|
Parses the output arguments . Calls the process_output method for each of them .
|
9,150
|
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' ] : '' ; $ 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 .
|
9,151
|
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 .
|
9,152
|
protected function process_value ( $ value , $ output ) { if ( isset ( $ output [ 'property' ] ) ) { return $ this -> process_property_value ( $ output [ 'property' ] , $ value ) ; } return $ value ; }
|
Returns the value .
|
9,153
|
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 .
|
9,154
|
public function get_url ( ) { $ this -> url = \ str_replace ( ABSPATH , \ trailingslashit ( \ site_url ( ) ) , $ this -> path ) ; if ( false !== \ strpos ( $ this -> path , self :: $ content_path ) ) { $ this -> url = \ str_replace ( self :: $ content_path , self :: $ content_url , $ this -> path ) ; } if ( $ this -> in_parent_theme ( ) ) { $ this -> url = \ get_template_directory_uri ( ) . \ str_replace ( \ get_template_directory ( ) , '' , $ this -> path ) ; } 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 .
|
9,155
|
public static function sanitize ( $ value ) { if ( class_exists ( '\Kirki\Field\Color' ) ) { return \ Kirki \ Field \ Color :: sanitize ( $ value ) ; } return esc_attr ( $ value ) ; }
|
Sanitization callback .
|
9,156
|
public static function add_module ( $ module ) { if ( ! in_array ( $ module , self :: $ modules , true ) ) { self :: $ modules [ ] = $ module ; } }
|
Add a module .
|
9,157
|
public static function remove_module ( $ module ) { $ key = array_search ( $ module , self :: $ modules , true ) ; if ( false !== $ key ) { unset ( self :: $ modules [ $ key ] ) ; } }
|
Remove a module .
|
9,158
|
protected function set_preset ( ) { $ this -> preset = $ this -> choices ; foreach ( $ this -> choices as $ key => $ args ) { $ this -> choices [ $ key ] = $ args [ 'label' ] ; } }
|
Set the preset .
|
9,159
|
protected function row_label ( $ args ) { if ( isset ( $ args [ 'row_label' ] ) && is_array ( $ args [ 'row_label' ] ) && ! empty ( $ args [ 'row_label' ] ) ) { if ( isset ( $ args [ 'row_label' ] [ 'type' ] ) && ( 'text' === $ args [ 'row_label' ] [ 'type' ] || 'field' === $ args [ 'row_label' ] [ 'type' ] ) ) { $ this -> row_label [ 'type' ] = $ args [ 'row_label' ] [ 'type' ] ; } if ( isset ( $ args [ 'row_label' ] [ 'value' ] ) && ! empty ( $ args [ 'row_label' ] [ 'value' ] ) ) { $ this -> row_label [ 'value' ] = esc_html ( $ args [ 'row_label' ] [ 'value' ] ) ; } 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 { $ this -> row_label [ 'type' ] = 'text' ; } } }
|
Validate row - labels .
|
9,160
|
public static function css ( $ field ) { 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 , ] , ] ; } self :: $ value = Values :: get_sanitized_field_value ( $ 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 .
|
9,161
|
public static function styles_parse ( $ css = [ ] ) { $ css = apply_filters ( 'kirki_styles_array' , $ 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 .
|
9,162
|
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 ) { 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 ; } 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 .
|
9,163
|
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 .
|
9,164
|
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 .
|
9,165
|
public static function remove_panel ( $ id = '' ) { if ( ! in_array ( $ id , self :: $ panels_to_remove , true ) ) { self :: $ panels_to_remove [ ] = $ id ; } }
|
Remove a panel .
|
9,166
|
public static function remove_section ( $ id = '' ) { if ( ! in_array ( $ id , self :: $ sections_to_remove , true ) ) { self :: $ sections_to_remove [ ] = $ id ; } }
|
Remove a section .
|
9,167
|
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' ) ; } if ( ! isset ( $ args [ 'type' ] ) ) { return ; } 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 .
|
9,168
|
public static function remove_control ( $ id ) { if ( ! in_array ( $ id , self :: $ controls_to_remove , true ) ) { self :: $ controls_to_remove [ ] = $ id ; } }
|
Remove a control .
|
9,169
|
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 .
|
9,170
|
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 .
|
9,171
|
public function add_section ( $ args ) { global $ wp_customize ; $ 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' ; } $ wp_customize -> add_section ( new $ section_classname ( $ wp_customize , $ args [ 'id' ] , $ args ) ) ; }
|
Adds the section using the WordPress Customizer API .
|
9,172
|
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 .
|
9,173
|
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 ) ; if ( ! empty ( $ _GET [ 'action' ] ) && 'kirki-reset-cache' === $ _GET [ 'action' ] ) { $ contents = false ; } if ( ! $ contents ) { $ contents = Helper :: get_remote_url_contents ( $ url , [ 'headers' => [ 'user-agent' => 'Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Firefox/21.0' , ] , ] ) ; $ font_display = apply_filters ( 'kirki_googlefonts_font_display' , 'swap' ) ; if ( $ contents ) { $ contents = str_replace ( '@font-face {' , '@font-face{' , $ contents ) ; $ contents = str_replace ( '@font-face{' , '@font-face{font-display:' . $ font_display . ';' , $ contents ) ; $ contents = str_replace ( [ ': ' , '; ' , '; ' , ' ' ] , [ ':' , ';' , ';' , ' ' ] , preg_replace ( "/\r|\n/" , '' , $ contents ) ) ; if ( apply_filters ( 'kirki_use_local_fonts' , true ) ) { $ contents = $ this -> use_local_files ( $ contents ) ; } set_site_transient ( $ transient_id , $ contents , WEEK_IN_SECONDS ) ; } } if ( $ contents ) { echo wp_strip_all_tags ( $ contents ) ; } } }
|
Webfont Loader script for Google Fonts .
|
9,174
|
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 .
|
9,175
|
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
|
9,176
|
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 .
|
9,177
|
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 .
|
9,178
|
public function override_load_textdomain ( $ override , $ domain , $ mofile ) { global $ l10n ; if ( isset ( $ l10n [ $ this -> get_theme_textdomain ( ) ] ) ) { $ l10n [ 'kirki' ] = $ l10n [ $ this -> get_theme_textdomain ( ) ] ; } if ( 'kirki' === $ domain ) { return true ; } return $ override ; }
|
Allows overriding the kirki textdomain from a theme .
|
9,179
|
private function get_theme_textdomain ( ) { if ( '' === $ this -> theme_textdomain ) { $ theme = wp_get_theme ( ) ; $ this -> theme_textdomain = $ theme -> get ( 'TextDomain' ) ; if ( ! $ this -> theme_textdomain ) { $ this -> theme_textdomain = get_template ( ) ; } } return $ this -> theme_textdomain ; }
|
Get the theme s textdomain .
|
9,180
|
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 .
|
9,181
|
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 .
|
9,182
|
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 .
|
9,183
|
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 .
|
9,184
|
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 .
|
9,185
|
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 .
|
9,186
|
public function include_sections_and_panels ( ) { $ 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 ; continue ; } $ path = str_replace ( 'class-kirki-sections-kirki-' , 'class-kirki-sections-' , $ path ) ; if ( file_exists ( $ path ) ) { include_once $ path ; } } } $ 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 ; continue ; } $ path = str_replace ( 'class-kirki-panels-kirki-' , 'class-kirki-panels-' , $ path ) ; if ( file_exists ( $ path ) ) { include_once $ path ; } } } }
|
Include the custom - section classes .
|
9,187
|
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 .
|
9,188
|
public static function sanitize ( $ value ) { foreach ( $ value as $ key => $ sub_value ) { $ value [ $ key ] = sanitize_text_field ( $ sub_value ) ; } return $ value ; }
|
Sanitizes the value .
|
9,189
|
public function filter_setting_args ( $ args , $ wp_customize ) { if ( $ args [ 'settings' ] !== $ args [ 'settings' ] ) { return $ args ; } if ( ! isset ( $ args [ 'sanitize_callback' ] ) || ! $ args [ 'sanitize_callback' ] ) { $ args [ 'sanitize_callback' ] = [ __CLASS__ , 'sanitize' ] ; if ( isset ( $ args [ 'mode' ] ) && 'hue' === $ args [ 'mode' ] ) { $ args [ 'sanitize_callback' ] = 'absint' ; } } return $ args ; }
|
Filter arguments before creating the setting .
|
9,190
|
public function filter_control_args ( $ args , $ wp_customize ) { if ( $ args [ 'settings' ] !== $ args [ 'settings' ] ) { return $ args ; } $ args = parent :: filter_control_args ( $ args , $ wp_customize ) ; $ args [ 'type' ] = 'kirki-color' ; if ( ! isset ( $ args [ 'choices' ] ) || ! \ is_array ( $ args [ 'choices' ] ) ) { $ args [ 'choices' ] = [ ] ; } $ args [ 'choices' ] [ 'alpha' ] = isset ( $ args [ 'choices' ] [ 'alpha' ] ) ? ( bool ) $ args [ 'choices' ] [ 'alpha' ] : false ; if ( ! isset ( $ args [ 'choices' ] [ 'mode' ] ) ) { $ args [ 'choices' ] [ 'mode' ] = isset ( $ args [ 'mode' ] ) ? $ args [ 'mode' ] : 'full' ; } return $ args ; }
|
Filter arguments before creating the control .
|
9,191
|
public function init ( ) { global $ wp_customize ; if ( ! $ wp_customize ) { return ; } $ config = apply_filters ( 'kirki_config' , [ ] ) ; if ( isset ( $ config [ 'disable_loader' ] ) && true === $ config [ 'disable_loader' ] ) { return ; } 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 .
|
9,192
|
final private function get_control_class_name ( $ args ) { $ class_name = 'WP_Customize_Control' ; 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 .
|
9,193
|
final protected function add_control ( $ args ) { $ class_name = $ this -> get_control_class_name ( $ args ) ; $ this -> wp_customize -> add_control ( new $ class_name ( $ this -> wp_customize , $ args [ 'settings' ] , $ args ) ) ; }
|
Adds the control .
|
9,194
|
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 .
|
9,195
|
public static function is_plugin ( ) { $ is_plugin = false ; if ( ! function_exists ( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php' ; } $ 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 ; } } if ( ! $ is_plugin ) { return false ; } include_once ABSPATH . 'wp-admin/includes/plugin.php' ; if ( $ _plugin && is_plugin_inactive ( $ _plugin ) ) { return false ; } return $ is_plugin ; }
|
Determine if Kirki is installed as a plugin .
|
9,196
|
public static function get_variables ( ) { $ variables = [ ] ; foreach ( Kirki :: $ fields as $ field ) { if ( isset ( $ field [ 'variables' ] ) && $ field [ 'variables' ] && ! empty ( $ field [ 'variables' ] ) ) { foreach ( $ field [ 'variables' ] as $ field_variable ) { if ( isset ( $ field_variable [ 'name' ] ) ) { $ variable_callback = ( isset ( $ field_variable [ 'callback' ] ) && is_callable ( $ field_variable [ 'callback' ] ) ) ? $ field_variable [ 'callback' ] : false ; $ 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' ] ) ) ; } } } } } return apply_filters ( 'kirki_variable' , $ variables ) ; }
|
Build the variables .
|
9,197
|
public function http_request ( $ request = [ ] , $ url = '' ) { 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 ; } } 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 .
|
9,198
|
public function enqueue_styles ( ) { $ args = [ 'action' => apply_filters ( 'kirki_styles_action_handle' , 'kirki-styles' ) , ] ; if ( is_admin ( ) && ! is_customize_preview ( ) ) { $ args [ 'editor' ] = '1' ; } wp_enqueue_style ( 'kirki-styles' , add_query_arg ( $ args , site_url ( ) ) , [ ] , KIRKI_VERSION ) ; 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 .
|
9,199
|
public function print_styles ( ) { $ 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 ) ) { echo wp_strip_all_tags ( $ styles ) ; } } do_action ( 'kirki_dynamic_css' ) ; }
|
Prints the styles .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.