idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
12,100
public function metaboxSave ( $ value , int $ post_id ) { $ this -> setValue ( $ value ) ; $ previous = get_post_meta ( $ post_id , $ this -> getName ( ) , false ) ; if ( is_null ( $ value ) || empty ( $ value ) ) { delete_post_meta ( $ post_id , $ this -> getName ( ) ) ; } elseif ( empty ( $ previous ) && is_array ( $ value ) ) { array_walk ( $ value , function ( $ val ) use ( $ post_id ) { add_post_meta ( $ post_id , $ this -> getName ( ) , $ val , false ) ; } ) ; } else { delete_post_meta ( $ post_id , $ this -> getName ( ) ) ; array_walk ( $ value , function ( $ val ) use ( $ post_id , $ previous ) { add_post_meta ( $ post_id , $ this -> getName ( ) , $ val , false ) ; } ) ; } }
Handle collection field post meta registration .
12,101
public function reverseTransform ( $ data ) { $ value = parent :: reverseTransform ( $ data ) ; return ! is_null ( $ value ) ? ( int ) $ value : null ; }
Convert a localized string to an integer value .
12,102
protected function parseNumeric ( $ value ) { if ( is_numeric ( $ value ) ) { if ( false !== strrpos ( $ value , '.' ) ) { return ( float ) $ value ; } return ( int ) $ value ; } return $ value ; }
Parse if a value is numeric and cast it to its correct type .
12,103
public function loadManifest ( ) { if ( $ this -> files -> exists ( $ this -> manifestPath ) ) { $ manifest = $ this -> files -> getRequire ( $ this -> manifestPath ) ; if ( $ manifest ) { return array_merge ( [ 'when' => [ ] ] , $ manifest ) ; } } }
Load the service provider manifest file .
12,104
public function compileManifest ( array $ providers ) { $ manifest = $ this -> freshManifest ( $ providers ) ; foreach ( $ providers as $ provider ) { $ instance = $ this -> createProvider ( $ provider ) ; if ( $ instance -> isDeferred ( ) ) { foreach ( $ instance -> provides ( ) as $ service ) { $ manifest [ 'deferred' ] [ $ service ] = $ provider ; } $ manifest [ 'when' ] [ $ provider ] = $ instance -> when ( ) ; } else { $ manifest [ 'eager' ] [ ] = $ provider ; } } return $ this -> writeManifest ( $ manifest ) ; }
Compile the application service manifest file .
12,105
public function writeManifest ( array $ manifest ) { if ( ! is_writable ( dirname ( $ this -> manifestPath ) ) ) { throw new Exception ( 'The bootstrap/cache directory must be present and writable.' ) ; } $ this -> files -> put ( $ this -> manifestPath , '<?php return ' . var_export ( $ manifest , true ) . ';' ) ; return array_merge ( [ 'when' => [ ] ] , $ manifest ) ; }
Write the service manifest file .
12,106
public function transform ( $ data ) { if ( is_null ( $ data ) || '' === $ data ) { return '' ; } if ( ! is_numeric ( $ data ) ) { throw new DataTransformerException ( 'A numeric value is expected.' ) ; } $ formatter = $ this -> getFormatter ( ) ; $ value = $ formatter -> format ( $ data ) ; if ( intl_is_failure ( $ formatter -> getErrorCode ( ) ) ) { throw new DataTransformerException ( $ formatter -> getErrorMessage ( ) ) ; } return str_replace ( "\xc2\xa0" , ' ' , $ value ) ; }
Convert a numeric value to a localized string .
12,107
public function reverseTransform ( $ data ) { if ( is_null ( $ data ) || empty ( $ data ) ) { return '' ; } $ formatter = $ this -> getFormatter ( ) ; $ value = $ formatter -> parse ( $ data ) ; if ( intl_is_failure ( $ formatter -> getErrorCode ( ) ) ) { throw new DataTransformerException ( $ formatter -> getErrorMessage ( ) ) ; } return $ value ; }
Convert a localized string to a numeric value .
12,108
protected function getFormatter ( ) { $ formatter = new \ NumberFormatter ( $ this -> locale , \ NumberFormatter :: DECIMAL ) ; $ precision = $ this -> field -> getOption ( 'precision' , 0 ) ; if ( $ precision ) { $ formatter -> setAttribute ( \ NumberFormatter :: FRACTION_DIGITS , $ precision ) ; } return $ formatter ; }
Retrieve a NumberFormatter instance .
12,109
public function make ( TaxonomyInterface $ taxonomy , array $ options = [ ] ) : TaxonomyField { $ this -> taxonomy = $ taxonomy ; $ this -> options = $ options ; return $ this ; }
Attach a taxonomy in order to add custom fields .
12,110
public function add ( FieldTypeInterface $ field ) : TaxonomyField { $ field -> setTheme ( 'themosis.taxonomy' ) ; $ field -> setPrefix ( $ this -> options [ 'prefix' ] ?? 'th_' ) ; $ this -> repository -> add ( $ field ) ; return $ this ; }
Add a taxonomy custom field .
12,111
public function set ( ) { if ( function_exists ( 'current_filter' ) && 'init' === current_filter ( ) ) { call_user_func ( $ this -> register ( ) ) ; } else { $ this -> action -> add ( 'init' , $ this -> register ( ) ) ; } $ this -> action -> add ( $ this -> taxonomy -> getName ( ) . '_add_form_fields' , $ this -> outputAddFields ( ) ) ; $ this -> action -> add ( $ this -> taxonomy -> getName ( ) . '_edit_form_fields' , $ this -> outputEditFields ( ) ) ; $ this -> action -> add ( [ 'create_' . $ this -> taxonomy -> getName ( ) , 'edit_' . $ this -> taxonomy -> getName ( ) ] , $ this -> save ( ) ) ; }
Set taxonomy custom fields .
12,112
protected function register ( ) { return function ( ) { foreach ( $ this -> repository as $ field ) { register_meta ( 'term' , $ field -> getName ( ) , [ 'type' => $ field -> getOption ( 'data_type' , 'string' ) , 'single' => ! $ field -> getOption ( 'multiple' , false ) , 'show_in_rest' => $ field -> getOption ( 'show_in_rest' , false ) , 'sanitize_callback' => $ this -> sanitize ( $ field ) ] ) ; } } ; }
Return the callback used to register term meta .
12,113
protected function sanitize ( FieldTypeInterface $ field ) { return function ( $ value , $ key , $ type ) use ( $ field ) { $ validator = $ this -> validator -> make ( [ $ key => $ value ] , $ this -> getTermRules ( ) , $ this -> getTermMessages ( ) , $ this -> getTermPlaceholders ( ) ) ; $ validation = $ validator -> valid ( ) ; return $ validation [ $ key ] ?? null ; } ; }
Sanitize term meta value .
12,114
protected function save ( ) { return function ( $ term_id ) { $ validator = $ this -> validator -> make ( $ this -> getTermData ( app ( 'request' ) ) , $ this -> getTermRules ( ) , $ this -> getTermMessages ( ) , $ this -> getTermPlaceholders ( ) ) ; $ validation = $ validator -> valid ( ) ; foreach ( $ this -> repository -> all ( ) as $ field ) { $ field -> setErrorMessageBag ( $ validator -> errors ( ) ) ; if ( method_exists ( $ field , 'termSave' ) ) { $ field -> termSave ( $ validation [ $ field -> getName ( ) ] ?? null , $ term_id ) ; } else { throw new TaxonomyException ( 'Unable to save [' . $ field -> getName ( ) . ']. The [termSave] method is missing.' ) ; } } } ; }
Return the function managing term meta registration .
12,115
protected function getTermData ( Request $ request ) { $ data = [ ] ; foreach ( $ this -> repository as $ field ) { $ data [ $ field -> getName ( ) ] = $ request -> get ( $ field -> getName ( ) ) ; } return $ data ; }
Fetch raw data from the request .
12,116
protected function getTermRules ( ) { $ rules = [ ] ; foreach ( $ this -> repository as $ field ) { $ rules [ $ field -> getName ( ) ] = $ field -> getOption ( 'rules' ) ; } return $ rules ; }
Return terms rules .
12,117
protected function getTermMessages ( ) { $ messages = [ ] ; foreach ( $ this -> repository as $ field ) { foreach ( $ field -> getOption ( 'messages' ) as $ rule => $ message ) { $ messages [ $ field -> getName ( ) . '.' . $ rule ] = $ message ; } } return $ messages ; }
Return terms errors messages .
12,118
protected function getTermPlaceholders ( ) { $ placeholders = [ ] ; foreach ( $ this -> repository as $ field ) { $ placeholders [ $ field -> getName ( ) ] = $ field -> getOption ( 'placeholder' ) ; } return $ placeholders ; }
Return terms placeholders .
12,119
protected function outputEditFields ( ) { return function ( $ term ) { foreach ( $ this -> repository as $ field ) { if ( method_exists ( $ field , 'termGet' ) ) { $ field -> termGet ( $ term -> term_id ) ; } } echo $ this -> factory -> make ( 'themosis.taxonomy.edit' , [ 'fields' => $ this -> repository ] ) -> render ( ) ; } ; }
Handle display of fields on edit term screen .
12,120
public function getDefaultOptions ( ) : array { $ options = parent :: getDefaultOptions ( ) ; if ( ! isset ( $ options [ 'attributes' ] [ 'type' ] ) ) { $ options [ 'attributes' ] [ 'type' ] = 'submit' ; } $ options [ 'mapped' ] = false ; return $ options ; }
Get default button options .
12,121
public function make ( string $ id , $ screen = 'post' ) : MetaboxInterface { $ metabox = ( new Metabox ( $ id , $ this -> action , $ this -> filter , new FieldsRepository ( ) ) ) -> setContainer ( $ this -> container ) -> setTitle ( $ this -> setDefaultTitle ( $ id ) ) -> setScreen ( $ screen ) -> setContext ( 'normal' ) -> setPriority ( 'default' ) -> setArguments ( [ '__block_editor_compatible_meta_box' => true , '__back_compat_meta_box' => false ] ) -> setResource ( $ this -> resource ) -> setLocale ( $ this -> container -> getLocale ( ) ) ; $ this -> setMetaboxTranslations ( $ metabox ) ; $ abstract = sprintf ( 'themosis.metabox.%s' , $ id ) ; if ( ! $ this -> container -> bound ( $ abstract ) ) { $ this -> container -> instance ( $ abstract , $ metabox ) ; } else { throw new MetaboxException ( 'The metabox with an ID of [' . $ id . '] is already bound.' ) ; } return $ metabox ; }
Create a new metabox instance .
12,122
protected function setMetaboxTranslations ( MetaboxInterface $ metabox ) { if ( ! function_exists ( '__' ) ) { return $ this ; } $ metabox -> addTranslation ( 'done' , __ ( 'Saved' , Application :: TEXTDOMAIN ) ) ; $ metabox -> addTranslation ( 'error' , __ ( 'Saved with errors' , Application :: TEXTDOMAIN ) ) ; $ metabox -> addTranslation ( 'saving' , __ ( 'Saving' , Application :: TEXTDOMAIN ) ) ; $ metabox -> addTranslation ( 'submit' , sprintf ( '%s %s' , __ ( 'Save' , Application :: TEXTDOMAIN ) , $ metabox -> getTitle ( ) ) ) ; return $ this ; }
Set metabox translations strings .
12,123
public function set ( ) : PageInterface { $ hook = $ this -> isNetwork ( ) ? 'network_admin_menu' : 'admin_menu' ; $ this -> action -> add ( $ hook , [ $ this , 'build' ] ) ; $ this -> action -> add ( 'admin_init' , [ $ this , 'configureSettings' ] ) ; return $ this ; }
Set the page . Display it on the WordPress administration .
12,124
protected function findParentHook ( ) : string { if ( ! $ this -> hasParent ( ) ) { return '' ; } if ( false !== $ pos = strpos ( $ this -> getParent ( ) , 'post_type=' ) ) { return substr ( $ this -> getParent ( ) , $ pos + 10 ) ; } elseif ( 'edit.php' === trim ( $ this -> getParent ( ) , '\/?&' ) ) { return 'posts' ; } $ abstract = 'page.' . $ this -> getParent ( ) ; if ( $ this -> ui ( ) -> factory ( ) -> getContainer ( ) -> bound ( $ abstract ) ) { $ parent = $ this -> ui ( ) -> factory ( ) -> getContainer ( ) -> make ( $ abstract ) ; return strtolower ( $ parent -> getMenu ( ) ) ; } return '' ; }
Find the page parent hook if any .
12,125
public function build ( ) { if ( is_null ( $ this -> getParent ( ) ) ) { add_menu_page ( $ this -> getTitle ( ) , $ this -> getMenu ( ) , $ this -> getCapability ( ) , $ this -> getSlug ( ) , [ $ this , 'render' ] , $ this -> getIcon ( ) , $ this -> getPosition ( ) ) ; } else { add_submenu_page ( $ this -> getParent ( ) , $ this -> getTitle ( ) , $ this -> getMenu ( ) , $ this -> getCapability ( ) , $ this -> getSlug ( ) , [ $ this , 'render' ] ) ; } }
Build the WordPress pages .
12,126
public function with ( $ key , $ value = null ) : PageInterface { $ this -> ui ( ) -> getView ( ) -> with ( $ key , $ value ) ; return $ this ; }
Add data to the page view .
12,127
public function addSections ( array $ sections ) : PageInterface { $ sections = array_merge ( $ this -> repository ( ) -> getSections ( ) -> all ( ) , $ sections ) ; array_walk ( $ sections , function ( $ section ) { if ( empty ( $ section -> getView ( ) ) ) { $ section -> setView ( 'section' ) ; } } ) ; $ this -> repository ( ) -> setSections ( $ sections ) ; return $ this ; }
Add sections to the page .
12,128
public function addSettings ( $ section , array $ settings = [ ] ) : PageInterface { $ currentSettings = $ this -> repository ( ) -> getSettings ( ) -> all ( ) ; if ( is_array ( $ section ) ) { $ settings = array_merge ( $ currentSettings , $ section ) ; } else { $ settings = array_merge ( $ currentSettings , [ $ section => $ settings ] ) ; } $ this -> repository ( ) -> setSettings ( $ settings ) ; if ( 'page' === $ this -> ui ( ) -> getViewPath ( ) ) { $ this -> ui ( ) -> setView ( 'options' ) ; } return $ this ; }
Add settings to the page .
12,129
public function setPrefix ( string $ prefix ) : PageInterface { $ this -> prefix = $ prefix ; $ this -> repository ( ) -> getSettings ( ) -> collapse ( ) -> each ( function ( $ setting ) use ( $ prefix ) { $ setting -> setPrefix ( $ prefix ) ; } ) ; return $ this ; }
Set the page settings name prefix .
12,130
public function configureSettings ( ) { $ settings = $ this -> repository ( ) -> getSettings ( ) ; $ sections = $ this -> repository ( ) -> getSections ( ) ; if ( $ settings -> isEmpty ( ) && $ sections -> isEmpty ( ) ) { return ; } $ sections -> each ( function ( $ section ) { add_settings_section ( $ section -> getId ( ) , $ section -> getTitle ( ) , [ $ this , 'renderSections' ] , $ this -> getSlug ( ) ) ; } ) ; foreach ( $ settings -> all ( ) as $ slug => $ fields ) { foreach ( $ fields as $ setting ) { $ setting = $ this -> prepareSetting ( $ setting ) ; add_settings_field ( $ setting -> getName ( ) , $ setting -> getOption ( 'label' ) , [ $ this , 'renderSettings' ] , $ this -> getSlug ( ) , $ slug , $ setting ) ; $ showInRest = $ this -> isShownInRest ( ) ; if ( $ setting -> getOption ( 'show_in_rest' , false ) ) { $ showInRest = true ; } register_setting ( $ this -> getSlug ( ) , $ setting -> getName ( ) , [ 'sanitize_callback' => [ $ this , 'sanitizeSetting' ] , 'default' => $ setting -> getOption ( 'data' , '' ) , 'show_in_rest' => $ showInRest , 'type' => $ setting -> getOption ( 'data_type' , 'string' ) ] ) ; } } }
Configure page settings if any . Called by the admin_init hook .
12,131
protected function prepareSetting ( FieldTypeInterface $ setting ) { if ( empty ( $ setting -> getTheme ( ) ) || is_array ( $ setting -> getTheme ( ) ) ) { $ setting -> setTheme ( 'themosis.pages' ) ; } $ setting -> setPrefix ( $ this -> getPrefix ( ) ) ; $ setting -> setOptions ( [ 'label' => $ setting -> getOption ( 'label' , ucfirst ( $ setting -> getBaseName ( ) ) ) , 'placeholder' => $ setting -> getOption ( 'placeholder' , $ setting -> getBaseName ( ) ) ] ) ; $ attributes = array_merge ( [ 'class' => 'regular-text' ] , $ setting -> getAttributes ( ) ) ; $ setting -> setAttributes ( $ attributes ) ; return $ setting ; }
Prepare the setting .
12,132
public function sanitizeSetting ( $ value ) { $ keys = $ this -> repository ( ) -> getSettings ( ) -> collapse ( ) -> map ( function ( $ setting ) { return $ setting -> getName ( ) ; } ) ; $ settingName = $ keys -> slice ( $ this -> offset , 1 ) -> first ( ) ; $ lastSetting = $ this -> repository ( ) -> getSettings ( ) -> collapse ( ) -> last ( ) ; $ data = collect ( $ _POST ) ; if ( $ this -> offset > $ keys -> count ( ) - 1 ) { if ( empty ( $ value ) ) { return '' ; } $ settingName = $ data -> search ( $ value , true ) ; if ( ! $ settingName ) { return '' ; } $ this -> errors ++ ; } $ setting = $ this -> repository ( ) -> getSettingByName ( $ settingName ) ; $ validator = $ this -> validator -> make ( $ data -> all ( ) , [ $ setting -> getName ( ) => $ setting -> getOption ( 'rules' ) ] , $ this -> getSettingMessages ( $ setting ) , $ this -> getSettingPlaceholder ( $ setting ) ) ; $ this -> offset ++ ; if ( $ validator -> fails ( ) ) { $ this -> errors ++ ; add_settings_error ( $ this -> getSlug ( ) , $ setting -> getName ( ) , $ validator -> getMessageBag ( ) -> first ( $ setting -> getName ( ) ) , 'error' ) ; return '' ; } if ( $ settingName === $ lastSetting -> getName ( ) && ! $ this -> errors ) { add_settings_error ( $ this -> getSlug ( ) , 'settings_updated' , __ ( 'Settings saved.' ) , 'updated' ) ; } return $ value ; }
Sanitize the setting before save .
12,133
protected function getSettingMessages ( FieldTypeInterface $ setting ) : array { $ messages = [ ] ; foreach ( $ setting -> getOption ( 'messages' , [ ] ) as $ attr => $ message ) { $ messages [ $ setting -> getName ( ) . '.' . $ attr ] = $ message ; } return $ messages ; }
Return the setting custom error messages .
12,134
protected function getSettingPlaceholder ( FieldTypeInterface $ setting ) : array { $ placeholder = $ setting -> getOption ( 'placeholder' ) ; if ( is_null ( $ placeholder ) ) { return [ ] ; } return [ $ setting -> getName ( ) => $ placeholder ] ; }
Return the setting placeholder .
12,135
public function renderSections ( array $ args ) { $ section = $ this -> repository ( ) -> getSectionByName ( $ args [ 'id' ] ) ; $ view = sprintf ( '%s.%s.%s' , $ this -> ui ( ) -> getTheme ( ) , $ this -> ui ( ) -> getLayout ( ) , $ section -> getView ( ) ) ; echo $ this -> ui ( ) -> factory ( ) -> make ( $ view ) -> with ( $ section -> getViewData ( ) ) -> render ( ) ; }
Output the section HTML .
12,136
public function renderSettings ( $ setting ) { $ value = get_option ( $ setting -> getName ( ) , null ) ; if ( ! is_null ( $ value ) ) { $ setting -> setValue ( $ value ) ; } $ view = sprintf ( '%s.%s' , $ this -> ui ( ) -> getTheme ( ) , $ setting -> getView ( false ) ) ; echo $ this -> ui ( ) -> factory ( ) -> make ( $ view ) -> with ( [ '__field' => $ setting , '__page' => $ this ] ) -> render ( ) ; }
Output the setting HTML .
12,137
public function getSettingError ( string $ name ) : array { $ errors = get_settings_errors ( $ this -> getSlug ( ) ) ; if ( empty ( $ errors ) ) { return [ ] ; } return collect ( $ errors ) -> first ( function ( $ error ) use ( $ name ) { return $ error [ 'code' ] === $ name ; } ) ; }
Return the setting error from its name .
12,138
public function setView ( string $ name , bool $ useShortPath = false ) : PageInterface { $ this -> ui ( ) -> useShortPath ( $ useShortPath ) -> setView ( $ name ) ; return $ this ; }
Set the page view path .
12,139
public function parseGetRoute ( ) { $ request = $ this -> getRequest ( ) ; if ( is_null ( $ request ) || ! isset ( $ this -> routes [ 'get' ] ) ) { return ; } $ action = $ request -> get ( 'action' , '/' ) ; if ( in_array ( $ action , array_keys ( $ this -> routes [ 'get' ] ) ) ) { $ callback = $ this -> routes [ 'get' ] [ $ action ] ; $ response = $ this -> handleCallback ( $ callback ) ; if ( ! is_a ( $ response , Renderable :: class ) ) { throw new \ Exception ( 'The controller method must return a view instance.' ) ; } $ this -> ui ( ) -> setViewInstance ( $ response ) ; } }
Parse page GET requests .
12,140
public function parsePostRoute ( ) { if ( empty ( $ this -> routes ) || ! isset ( $ this -> routes [ 'post' ] ) ) { return ; } foreach ( $ this -> routes [ 'post' ] as $ action => $ callback ) { $ this -> action -> add ( 'admin_post_' . $ action , $ callback ) ; } }
Parse page POST requests .
12,141
public function route ( string $ action , $ callback , string $ method = 'get' , string $ title = '' ) : PageInterface { $ method = strtolower ( $ method ) ; $ action = $ this -> parseAction ( $ action , $ method ) ; $ this -> routes [ $ method ] [ $ action ] = $ callback ; $ this -> titles [ $ action ] = ! empty ( $ title ) ? $ title : $ this -> getTitle ( ) ; $ this -> registerRouteActions ( ) ; return $ this ; }
Register page routes .
12,142
protected function registerRouteActions ( ) { $ this -> action -> add ( 'load-toplevel_page_' . $ this -> getSlug ( ) , [ $ this , 'parseGetRoute' ] ) ; $ this -> action -> add ( 'load-admin_page_' . $ this -> getSlug ( ) , [ $ this , 'parseGetRoute' ] ) ; $ this -> action -> add ( 'load-' . $ this -> findParentHook ( ) . '_page_' . $ this -> getSlug ( ) , [ $ this , 'parseGetRoute' ] ) ; $ this -> action -> add ( 'admin_init' , [ $ this , 'parsePostRoute' ] ) ; $ this -> filter -> add ( 'admin_title' , [ $ this , 'handleTitle' ] ) ; }
Register page routes actions and filters .
12,143
protected function parseAction ( string $ action , string $ method ) : string { if ( 'post' === $ method ) { return $ this -> getSlug ( ) . '_' . $ action ; } return $ action ; }
Format the action name .
12,144
public function handleTitle ( $ title ) { if ( is_null ( $ request = $ this -> getRequest ( ) ) || empty ( $ this -> titles ) ) { return $ title ; } if ( in_array ( $ action = $ request -> get ( 'action' ) , array_keys ( $ this -> titles ) ) ) { return $ this -> titles [ $ action ] ; } return $ title ; }
Called by the admin_title filter . Handle the page titles .
12,145
public function getContainer ( ) : Container { if ( is_null ( $ this -> container ) ) { $ this -> container = $ this -> ui ( ) -> factory ( ) -> getContainer ( ) ; } return $ this -> container ; }
Return the service container instance .
12,146
public function setCharset ( $ charset = null ) { if ( ! is_null ( $ charset ) ) { $ this -> charset = $ charset ; } elseif ( defined ( 'THEMOSIS_CHARSET' ) ) { $ this -> charset = THEMOSIS_CHARSET ; } elseif ( function_exists ( 'get_bloginfo' ) ) { $ this -> charset = get_bloginfo ( 'charset' ) ; } return $ this ; }
Set the encoding charset . Defaults to UTF8 .
12,147
protected function attributeElement ( $ key , $ value ) { if ( is_numeric ( $ key ) ) { return $ value ; } if ( is_bool ( $ value ) && $ key !== 'value' ) { return $ value ? $ key : '' ; } if ( ! is_null ( $ value ) ) { return $ key . '="' . $ this -> special ( $ value ) . '"' ; } return null ; }
Build the attribute .
12,148
public function thumbnailUrl ( $ size = null , $ icon = false ) { $ data = wp_get_attachment_image_src ( get_post_thumbnail_id ( $ this -> id ( ) ) , $ size , $ icon ) ; return ( empty ( $ data ) ) ? null : $ data [ 0 ] ; }
Get thumbnail url of current post .
12,149
public function setConditions ( array $ conditions = [ ] ) { $ this -> conditions = $ conditions ; $ this -> condition = $ this -> parseCondition ( $ this -> uri ( ) ) ; $ this -> conditionParams = $ this -> parseConditionParams ( $ this -> getAction ( ) ) ; return $ this ; }
Set route WordPress conditions rules .
12,150
protected function parseCondition ( string $ condition ) : string { $ conditions = $ this -> getConditions ( ) ; foreach ( $ conditions as $ signature => $ conds ) { $ conds = is_array ( $ conds ) ? $ conds : [ $ conds ] ; if ( in_array ( $ condition , $ conds , true ) ) { return $ signature ; } } return '' ; }
Parse the route condition based on global list of conditions . Return the WordPress conditional function .
12,151
protected function parseConditionParams ( array $ action ) : array { if ( empty ( $ this -> condition ) ) { return [ ] ; } $ params = Arr :: first ( $ action , function ( $ value , $ key ) { return is_numeric ( $ key ) ; } ) ; return [ $ params ] ; }
Parse route action and get any WordPress conditional parameters if any defined .
12,152
public function setSettings ( array $ settings ) : SettingsRepositoryInterface { $ this -> parseCompatibleSettings ( $ settings ) ; $ this -> settings = $ settings ; return $ this ; }
Set the page repository settings .
12,153
public function getSettingByName ( string $ name ) : FieldTypeInterface { return $ this -> getSettings ( ) -> collapse ( ) -> first ( function ( $ setting ) use ( $ name ) { return $ name === $ setting -> getName ( ) ; } ) ; }
Return the setting instance based on its name .
12,154
public function getSectionByName ( string $ name ) : SectionInterface { return $ this -> getSections ( ) -> first ( function ( $ section ) use ( $ name ) { return $ name === $ section -> getId ( ) ; } ) ; }
Return the section instance based on its name .
12,155
protected function parseCompatibleSettings ( array $ settings ) { $ settings = collect ( $ settings ) -> collapse ( ) -> all ( ) ; foreach ( $ settings as $ setting ) { if ( $ setting instanceof CanHandlePageSettings ) { $ setting -> settingGet ( ) ; } } }
Parse page settings . Throw an exception if user is using a field not supported .
12,156
public function getView ( ) : View { $ path = $ this -> useShortViewPath ? $ this -> getViewPath ( ) : sprintf ( '%s.%s.%s' , $ this -> getTheme ( ) , $ this -> getLayout ( ) , $ this -> getViewPath ( ) ) ; if ( is_null ( $ this -> viewInstance ) ) { $ this -> viewInstance = $ this -> factory -> make ( $ path ) ; } return $ this -> viewInstance ; }
Return the page view .
12,157
public function addLocation ( string $ path , string $ url ) : Finder { $ path = rtrim ( $ path , '\/' ) ; $ url = rtrim ( $ url , '\/' ) ; $ this -> locations [ $ path ] = $ url ; return $ this ; }
Add a base location in order to find an asset .
12,158
public function addLocations ( array $ paths ) : Finder { foreach ( $ paths as $ path => $ url ) { $ this -> addLocation ( $ path , $ url ) ; } return $ this ; }
Add multiple locations . The key is the asset path and the value its URL .
12,159
public function find ( string $ path ) : AssetFileInterface { if ( $ this -> isExternal ( $ path ) ) { return ( new File ( $ this -> files ) ) -> setPath ( '' ) -> setUrl ( $ path ) -> setExternal ( true ) -> setType ( $ path ) ; } $ path = trim ( $ path , '\/' ) ; foreach ( $ this -> locations as $ dir => $ url ) { if ( $ this -> files -> exists ( $ fullPath = $ dir . '/' . $ path ) ) { return ( new File ( $ this -> files ) ) -> setPath ( $ fullPath ) -> setUrl ( $ url . '/' . $ path ) -> setExternal ( false ) -> setType ( $ fullPath ) ; } } throw new AssetException ( 'Unable to find the asset with the following path: ' . $ path ) ; }
Return an asset file instance if found .
12,160
protected function isExternal ( string $ path ) : bool { foreach ( $ this -> schemes as $ scheme ) { if ( strpos ( $ path , $ scheme ) !== false ) { return true ; } } return false ; }
Check if given path is an external asset or not .
12,161
public function make ( $ dataClass = null , $ options = [ ] , $ builder = FormBuilder :: class ) : FormBuilderInterface { $ dataMapperManager = new DataMapperManager ( PropertyAccess :: createPropertyAccessor ( ) ) ; $ form = new Form ( $ dataClass , new FieldsRepository ( ) , $ this -> validation , $ this -> viewer , $ dataMapperManager ) ; $ form -> setManager ( $ this -> manager ) ; $ form -> setResourceTransformerFactory ( $ this -> factory ) ; $ form -> setAttributes ( $ this -> attributes ) ; $ form -> setOptions ( $ options ) ; $ this -> builder = new $ builder ( $ form , $ dataMapperManager , $ dataClass ) ; return $ this -> builder ; }
Create a FormBuilderInterface instance .
12,162
protected function handleCallback ( $ callback , array $ args = [ ] ) { $ response = null ; if ( $ callback instanceof \ Closure || is_array ( $ callback ) ) { $ response = call_user_func ( $ callback , $ args ) ; } elseif ( is_string ( $ callback ) ) { if ( false !== strpos ( $ callback , '@' ) || class_exists ( $ callback ) ) { $ callbackArray = $ this -> handleClassCallback ( $ callback ) ; $ response = call_user_func ( $ callbackArray , $ args ) ; } else { $ response = call_user_func ( $ callback , $ args ) ; } } return $ response ; }
Handle the callback to execute .
12,163
protected function getDefaultColors ( ) { $ colors = [ [ 'name' => 'Pale pink' , 'color' => '#f78da7' ] , [ 'name' => 'Vivid red' , 'color' => '#cf2e2e' ] , [ 'name' => 'Luminous vivid orange' , 'color' => '#ff6900' ] , [ 'name' => 'Luminous vivid amber' , 'color' => '#fcb900' ] , [ 'name' => 'Light green cyan' , 'color' => '#7bdcb5' ] , [ 'name' => 'Vivid green cyan' , 'color' => '#00d084' ] , [ 'name' => 'Pale cyan blue' , 'color' => '#8ed1fc' ] , [ 'name' => 'Vivid cyan blue' , 'color' => '#0693e3' ] , [ 'name' => 'Very light gray' , 'color' => '#eeeeee' ] , [ 'name' => 'Cyan bluish gray' , 'color' => '#abb8c3' ] , [ 'name' => 'Very dark gray' , 'color' => '#313131' ] ] ; return array_map ( function ( array $ color ) { return [ 'name' => function_exists ( '__' ) ? __ ( $ color [ 'name' ] , Application :: TEXTDOMAIN ) : $ color [ 'name' ] , 'color' => $ color [ 'color' ] ] ; } , $ colors ) ; }
Return a list of default colors for the field .
12,164
protected function registerTaxonomyField ( ) { $ this -> app -> bind ( 'taxonomy.field' , function ( $ app ) { $ viewFactory = $ app [ 'view' ] ; $ viewFactory -> addLocation ( __DIR__ . '/views' ) ; return new TaxonomyField ( new TaxonomyFieldRepository ( ) , $ viewFactory , $ app [ 'validator' ] , $ app [ 'action' ] ) ; } ) ; }
Register taxonomy field .
12,165
public function formatUrl ( string $ url , string $ delimiter = 'wp-admin' , string $ fragment = 'cms' ) { if ( strrpos ( $ url , $ fragment ) !== false ) { return $ url ; } $ fragments = explode ( $ delimiter , $ url ) ; array_splice ( $ fragments , 1 , 0 , "{$fragment}/{$delimiter}" ) ; $ url = array_reduce ( $ fragments , function ( $ carry , $ item ) { return $ carry .= $ item ; } ) ; return $ url ; }
Format the URL . If the URL is missing the WordPress directory fragment it adds it before the common delimiter .
12,166
public function formatNetworkUrl ( string $ url , string $ delimiter = 'wp-admin' , string $ fragment = 'cms' ) { return $ this -> formatUrl ( $ url , $ delimiter , $ fragment ) ; }
Format the network URL . If the URL is missing the WordPress directory fragment it adds it before the common delimiter .
12,167
public function setLabels ( array $ labels ) : PostTypeInterface { if ( isset ( $ this -> args [ 'labels' ] ) ) { $ this -> args [ 'labels' ] = array_merge ( $ this -> args [ 'labels' ] , $ labels ) ; } else { $ this -> args [ 'labels' ] = $ labels ; } return $ this ; }
Set the post type labels .
12,168
public function setArguments ( array $ args ) : PostTypeInterface { $ this -> args = array_merge ( $ this -> args , $ args ) ; return $ this ; }
Set the post type arguments .
12,169
public function register ( ) { $ this -> instance = register_post_type ( $ this -> slug , $ this -> getArguments ( ) ) ; $ this -> registerStatus ( ) ; }
Register post type hook callback .
12,170
public function setTitlePlaceholder ( string $ title ) : PostTypeInterface { $ this -> filter -> add ( 'enter_title_here' , function ( $ default ) use ( $ title ) { $ screen = get_current_screen ( ) ; if ( $ this -> slug === $ screen -> post_type ) { return $ title ; } return $ default ; } ) ; return $ this ; }
Set the post type title input placeholder .
12,171
protected function registerStatus ( ) { if ( empty ( $ this -> status ) ) { return ; } foreach ( $ this -> status as $ key => $ args ) { register_post_status ( $ key , $ args ) ; } Metabox :: make ( 'themosis_publish' , $ this -> slug ) -> setTitle ( __ ( 'Publish' ) ) -> setContext ( 'side' ) -> setPriority ( 'core' ) -> setCallback ( function ( $ args ) { echo view ( '_themosisPublishMetabox' , [ 'statuses' => $ this -> status , '__post' => $ args [ 'post' ] ] ) ; } ) -> set ( ) ; }
Register the custom status if any .
12,172
public function status ( $ status , array $ args = [ ] ) : PostTypeInterface { if ( is_array ( $ status ) ) { foreach ( $ status as $ key => $ params ) { if ( is_int ( $ key ) ) { $ this -> status ( $ params ) ; } elseif ( is_string ( $ key ) && is_array ( $ params ) ) { $ this -> status ( $ key , $ params ) ; } } return $ this ; } $ this -> prepareStatus ( $ status , $ args ) ; return $ this ; }
Set post type custom status .
12,173
protected function prepareStatus ( string $ status , array $ args ) { $ this -> status [ $ status ] = $ this -> parseStatusArguments ( $ status , $ args ) ; $ this -> action -> add ( 'add_meta_boxes' , function ( ) { remove_meta_box ( 'submitdiv' , $ this -> slug , 'side' ) ; } ) ; $ this -> filter -> add ( [ 'pre_post_status' , 'status_save_pre' ] , [ $ this , 'applyStatus' ] ) ; $ this -> filter -> add ( 'themosis_admin_global' , function ( $ data ) { $ status [ 'draft' ] = $ this -> parseStatusArguments ( 'draft' , [ 'publish_text' => __ ( 'Save Draft' ) ] ) ; $ data [ 'post_types' ] [ $ this -> slug ] = [ 'statuses' => array_merge ( $ status , $ this -> status ) ] ; return $ data ; } ) ; $ this -> filter -> add ( "views_edit-{$this->slug}" , function ( $ views ) { if ( array_key_exists ( 'trash' , $ views ) ) { $ trash = $ views [ 'trash' ] ; unset ( $ views [ 'trash' ] ) ; end ( $ views ) ; $ views [ 'trash' ] = $ trash ; } return $ views ; } ) ; }
Register custom post type status .
12,174
protected function parseStatusArguments ( string $ status , array $ args ) : array { $ name = ucfirst ( $ status ) ; return wp_parse_args ( $ args , [ 'label' => $ name , 'public' => true , 'exclude_from_search' => false , 'show_in_admin_all_list' => true , 'show_in_admin_status_list' => true , 'label_count' => _n_noop ( $ name . ' <span class="count">(%s)</span>' , $ name . ' <span class="count">(%s)</span>' ) , 'publish_text' => __ ( 'Apply Changes' ) ] ) ; }
Parse the status arguments .
12,175
public function applyStatus ( string $ value ) { if ( isset ( $ _POST [ 'post_type' ] ) && $ this -> slug === $ _POST [ 'post_type' ] && ! empty ( $ this -> status ) ) { if ( ( isset ( $ _POST [ 'post_status' ] ) && 'publish' === $ _POST [ 'post_status' ] ) && ( isset ( $ _REQUEST [ 'post_status' ] ) && 'draft' === $ _REQUEST [ 'post_status' ] ) ) { $ statuses = array_keys ( $ this -> status ) ; return esc_attr ( array_shift ( $ statuses ) ) ; } elseif ( isset ( $ _REQUEST [ 'post_status' ] ) && ! empty ( $ _REQUEST [ 'post_status' ] ) ) { if ( isset ( $ _POST [ '_status' ] ) && ! empty ( $ _POST [ '_status' ] ) ) { return esc_attr ( $ _POST [ '_status' ] ) ; } return esc_attr ( $ _REQUEST [ 'post_status' ] ) ; } } return esc_attr ( $ value ) ; }
Apply the selected status on post save .
12,176
public function setConditions ( array $ conditions = [ ] ) { $ config = $ this -> container -> has ( 'config' ) ? $ this -> container -> make ( 'config' ) : null ; if ( ! is_null ( $ config ) ) { $ this -> conditions = array_merge ( $ config -> get ( 'app.conditions' , [ ] ) , $ conditions ) ; } else { $ this -> conditions = $ conditions ; } }
Setup WordPress conditions .
12,177
public function addWordPressBindings ( $ route ) { global $ post , $ wp_query ; foreach ( compact ( 'post' , 'wp_query' ) as $ key => $ value ) { $ route -> setParameter ( $ key , $ value ) ; } return $ route ; }
Add WordPress default parameters if WordPress route .
12,178
public function auth ( array $ options = [ ] ) { $ this -> get ( 'auth/login' , 'Auth\LoginController@showLoginForm' ) -> name ( 'login' ) ; $ this -> post ( 'auth/login' , 'Auth\LoginController@login' ) ; $ this -> post ( 'auth/logout' , 'Auth\LoginController@logout' ) -> name ( 'logout' ) ; if ( $ options [ 'register' ] ?? true ) { $ this -> get ( 'auth/register' , 'Auth\RegisterController@showRegistrationForm' ) -> name ( 'register' ) ; $ this -> post ( 'auth/register' , 'Auth\RegisterController@register' ) ; } if ( $ options [ 'reset' ] ?? true ) { $ this -> resetPassword ( ) ; } if ( $ options [ 'verify' ] ?? false ) { $ this -> emailVerification ( ) ; } }
Register the typical authentication routes for an application . Avoid WordPress default endpoints .
12,179
public function transform ( FieldTypeInterface $ form ) { return [ 'attributes' => $ form -> getAttributes ( ) , 'flush' => $ form -> getOption ( 'flush' , true ) , 'locale' => $ form -> getLocale ( ) , 'nonce' => $ form -> getOption ( 'nonce' , '_themosisnonce' ) , 'referer' => $ form -> getOption ( 'referer' , true ) , 'tags' => $ form -> getOption ( 'tags' , true ) , 'theme' => $ form -> getOption ( 'theme' , 'themosis' ) , 'type' => $ form -> getType ( ) , 'validation' => [ 'errors' => $ form -> getOption ( 'errors' , true ) , 'isValid' => $ form -> isValid ( ) ] ] ; }
Transform single form .
12,180
public function includeGroups ( FieldTypeInterface $ form ) { return $ this -> collection ( $ form -> repository ( ) -> getGroups ( ) , $ form -> getResourceTransformerFactory ( ) -> make ( 'GroupTransformer' ) ) ; }
Include groups property to resource .
12,181
public function setType ( string $ type ) : AssetInterface { $ path = $ this -> file -> isExternal ( ) ? $ this -> getUrl ( ) : $ this -> getPath ( ) ; $ this -> file -> setType ( $ path , $ type ) ; return $ this ; }
Set the asset type . Override the auto - discovered type if any .
12,182
public function setArgument ( $ arg = null ) : AssetInterface { if ( ! is_null ( $ arg ) ) { $ this -> argument = $ arg ; return $ this ; } if ( 'style' === $ this -> getType ( ) ) { $ this -> argument = 'all' ; } if ( 'script' === $ this -> getType ( ) ) { $ this -> argument = true ; } return $ this ; }
Set the asset argument .
12,183
public function to ( $ locations = 'front' ) : AssetInterface { if ( is_string ( $ locations ) ) { $ locations = [ $ locations ] ; } foreach ( $ locations as $ location ) { $ hook = array_search ( $ location , $ this -> locations , true ) ; if ( $ hook ) { $ this -> install ( $ hook ) ; } } return $ this ; }
Load the asset on the defined area . Default to front - end .
12,184
public function enqueue ( ) { if ( is_null ( $ this -> getType ( ) ) ) { throw new AssetException ( 'The asset must have a type defined. Null given.' ) ; } if ( 'script' === $ this -> getType ( ) ) { $ this -> enqueueScript ( ) ; } else { $ this -> enqueueStyle ( ) ; } }
Enqueue asset .
12,185
protected function enqueueScript ( ) { wp_enqueue_script ( $ this -> getHandle ( ) , $ this -> getUrl ( ) , $ this -> getDependencies ( ) , $ this -> getVersion ( ) , $ this -> getArgument ( ) ) ; if ( ! empty ( $ this -> localize ) ) { foreach ( $ this -> localize as $ name => $ data ) { wp_localize_script ( $ this -> getHandle ( ) , $ name , $ data ) ; } } if ( ! empty ( $ this -> inline ) ) { foreach ( $ this -> inline as $ code ) { wp_add_inline_script ( $ this -> getHandle ( ) , $ code [ 'code' ] , $ code [ 'position' ] ) ; } } }
Enqueue a script asset .
12,186
protected function enqueueStyle ( ) { wp_enqueue_style ( $ this -> getHandle ( ) , $ this -> getUrl ( ) , $ this -> getDependencies ( ) , $ this -> getVersion ( ) , $ this -> getArgument ( ) ) ; if ( ! empty ( $ this -> inline ) ) { foreach ( $ this -> inline as $ code ) { wp_add_inline_style ( $ this -> getHandle ( ) , $ code [ 'code' ] ) ; } } }
Enqueue a style asset .
12,187
public function localize ( string $ name , array $ data ) : AssetInterface { $ this -> localize [ $ name ] = $ data ; return $ this ; }
Localize the asset .
12,188
public function inline ( string $ code , bool $ after = true ) : AssetInterface { $ this -> inline [ ] = [ 'code' => $ code , 'position' => $ after ? 'after' : 'before' ] ; return $ this ; }
Add asset inline code .
12,189
public function attributes ( array $ attributes ) : AssetInterface { if ( is_null ( $ this -> getType ( ) ) ) { throw new AssetException ( 'The asset must have a type.' ) ; } $ hook = 'script' === $ this -> getType ( ) ? 'script_loader_tag' : 'style_loader_tag' ; $ key = strtolower ( trim ( $ this -> getHandle ( ) ) ) ; $ attributes = $ this -> html -> attributes ( $ attributes ) ; $ this -> filter -> add ( $ hook , function ( $ tag , $ handle ) use ( $ attributes , $ key ) { if ( $ key !== $ handle ) { return $ tag ; } return preg_replace ( '/(src|href)(.+>)/' , $ attributes . '$1$2' , $ tag ) ; } ) ; return $ this ; }
Add asset attributes .
12,190
public function add ( $ field ) { if ( is_array ( $ field ) ) { foreach ( $ field as $ item ) { $ this -> add ( $ item ) ; } } else { $ this -> fields [ ] = $ field ; } }
Add a field to the taxonomy .
12,191
public function getFieldByName ( string $ name ) { $ found = array_filter ( $ this -> fields , function ( $ field ) use ( $ name ) { return $ name === $ field -> getBaseName ( ) ; } ) ; if ( ! empty ( $ found ) ) { return array_pop ( $ found ) ; } throw new TaxonomyFieldNotFoundException ( "Taxonomy field with a name of {$name} not found." ) ; }
Return a field instance by name .
12,192
public function getFilters ( ) { return [ new \ Twig_Filter ( 'wpantispam' , function ( $ email , $ encoding = 0 ) { return antispambot ( $ email , $ encoding ) ; } ) , new \ Twig_Filter ( 'wpautop' , function ( $ text , $ br = true ) { return wpautop ( $ text , $ br ) ; } ) , new \ Twig_Filter ( 'wpnofollow' , function ( $ text ) { return wp_rel_nofollow ( $ text ) ; } ) , new \ Twig_Filter ( 'wptrimexcerpt' , function ( $ text ) { return wp_trim_excerpt ( $ text ) ; } ) , new \ Twig_Filter ( 'wptrimwords' , function ( $ text , $ num_words = 55 , $ more = null ) { return wp_trim_words ( $ text , $ num_words , $ more ) ; } ) , new \ Twig_Filter ( 'zeroise' , function ( $ number , $ treshold = 4 ) { return zeroise ( $ number , $ treshold ) ; } ) ] ; }
Register a list of WordPress filters for use inside Twig templates .
12,193
protected function dispatchBodyClass ( Route $ route ) { return function ( $ classes ) use ( $ route ) { if ( $ route -> hasCondition ( ) ) { return $ classes ; } $ tokens = array_filter ( array_map ( function ( $ token ) use ( $ route ) { switch ( $ type = $ token [ 0 ] ) { case 'variable' : if ( isset ( $ token [ 3 ] ) && $ route -> hasParameter ( $ paramKey = $ token [ 3 ] ) ) { $ param = $ route -> parameter ( $ paramKey ) ; return is_string ( $ param ) ? sprintf ( '%s-%s' , $ paramKey , sanitize_title ( $ param ) ) : false ; } return false ; break ; case 'text' : return sanitize_title ( $ token [ 1 ] ) ; break ; default : return false ; } } , array_reverse ( $ route -> getCompiled ( ) -> getTokens ( ) ) ) ) ; if ( ! empty ( $ tokens ) ) { return array_filter ( array_merge ( $ tokens , $ classes ) , function ( $ class ) { return 'error404' !== $ class ; } ) ; } return $ classes ; } ; }
Return the callback managing route body CSS classes .
12,194
protected function parseChoice ( $ choice ) { list ( $ type , $ value ) = explode ( ': ' , strip_tags ( $ choice ) ) ; if ( $ type === 'Provider' ) { $ this -> provider = $ value ; } elseif ( $ type === 'Tag' ) { $ this -> tags = [ $ value ] ; } }
Parse the answer that was given via the prompt .
12,195
protected function parse ( array $ features ) { $ allowed = [ ] ; foreach ( $ features as $ feature => $ value ) { if ( is_int ( $ feature ) ) { if ( ! in_array ( $ value , $ this -> mustHaveProperties , true ) ) { $ allowed [ $ value ] = $ value ; } else { throw new \ InvalidArgumentException ( 'The theme feature [' . $ value . '] must have a defined property in order to work.' ) ; } } else { $ allowed [ $ feature ] = $ value ; } } return $ allowed ; }
Parse theme features .
12,196
public function register ( ) { if ( ! function_exists ( 'add_theme_support' ) || empty ( $ this -> features ) ) { return ; } foreach ( $ this -> features as $ feature => $ value ) { add_theme_support ( $ feature , $ value ) ; } }
Register theme support .
12,197
public function transform ( FieldTypeInterface $ field ) { return [ 'attributes' => $ field -> getAttributes ( ) , 'basename' => $ field -> getBaseName ( ) , 'component' => $ field -> getComponent ( ) , 'data_type' => $ field -> getOption ( 'data_type' , '' ) , 'default' => $ field -> getOption ( 'data' , '' ) , 'name' => $ field -> getName ( ) , 'options' => $ this -> getOptions ( $ field ) , 'label' => [ 'inner' => $ field -> getOption ( 'label' ) , 'attributes' => $ field -> getOption ( 'label_attr' , [ ] ) ] , 'theme' => $ field -> getTheme ( ) , 'type' => $ field -> getType ( ) , 'validation' => [ 'errors' => $ field -> getOption ( 'errors' , true ) , 'messages' => $ field -> errors ( ) -> toArray ( ) , 'placeholder' => $ field -> getOption ( 'placeholder' ) , 'rules' => $ field -> getOption ( 'rules' , '' ) ] , 'value' => 'checkbox' === $ field -> getType ( ) ? $ field -> getRawValue ( ) : $ field -> getValue ( '' ) , ] ; }
Transform single field .
12,198
protected function getOptions ( FieldTypeInterface $ field ) { $ options = parent :: getOptions ( $ field ) ; $ options [ 'items' ] = array_map ( function ( $ id ) { return [ 'attributes' => wp_prepare_attachment_for_js ( $ id ) , 'id' => $ id ] ; } , ( array ) $ field -> getValue ( ) ) ; return $ options ; }
Transform field options .
12,199
public function setPrefix ( string $ prefix ) : FieldTypeInterface { $ this -> prefix = $ prefix ; foreach ( $ this -> repository -> all ( ) as $ field ) { $ field -> setPrefix ( $ prefix ) ; } return $ this ; }
Set the form prefix . If fields are attached to the form all fields are updated with the given prefix .