idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
12,000 | protected function installTheme ( string $ name ) { $ this -> info ( 'Downloading theme...' ) ; $ this -> files -> put ( $ this -> temp , fopen ( $ this -> option ( 'url' ) , 'r' ) ) ; if ( true !== $ this -> zip -> open ( $ this -> temp ) ) { $ this -> error ( 'Cannot open theme zip file.' ) ; } $ this -> zip -> extractTo ( themes_path ( ) ) ; $ this -> zip -> close ( ) ; $ this -> files -> move ( themes_path ( $ this -> option ( 'dir' ) ) , themes_path ( str_replace ( ' ' , '-' , $ name ) ) ) ; $ this -> files -> delete ( $ this -> temp ) ; } | Install theme . |
12,001 | protected function setupTheme ( string $ name ) { $ this -> info ( 'Set [style.css] file...' ) ; $ theme = ucwords ( str_replace ( [ '-' , '_' ] , ' ' , $ name ) ) ; $ textdomain = str_replace ( [ '-' , ' ' ] , '_' , strtolower ( $ name ) ) ; $ content = <<<STYLES/*Theme Name: $themeTheme URI: https://framework.themosis.com/Author: ThemosisAuthor URI: https://www.themosis.com/Description: The Themosis framework base theme.Version: 1.0.0License: GPL-2.0-or-laterLicense URI: http://www.gnu.org/licenses/gpl-2.0.htmlTags: easy, organized, expressive.Text Domain: $textdomainDomain Path: languages*/STYLES ; $ this -> files -> put ( themes_path ( $ name . '/style.css' ) , $ content ) ; } | Setup basic theme information . |
12,002 | protected function setAsDefaultTheme ( string $ name ) { if ( ! file_exists ( $ file = config_path ( 'wordpress.php' ) ) ) { $ this -> warn ( 'Cannot update default theme configuration.' ) ; return ; } $ this -> info ( 'Set default theme constant...' ) ; $ lines = file ( $ file ) ; $ content = array_map ( function ( $ line ) use ( $ name ) { if ( stristr ( $ line , 'WP_DEFAULT_THEME' ) ) { return "define('WP_DEFAULT_THEME', '{$name}');\r\n" ; } return $ line ; } , $ lines ) ; $ this -> files -> put ( $ file , implode ( '' , $ content ) ) ; } | Set default theme constant in main wordpress . php config file . |
12,003 | public function load ( array $ directories ) { $ manifest = $ this -> loadManifest ( ) ; if ( $ this -> shouldRecompile ( $ manifest , $ directories ) ) { $ manifest = $ this -> compileManifest ( $ directories ) ; } foreach ( $ manifest as $ plugin => $ headers ) { $ path = sprintf ( '%s/%s' , $ plugin , $ headers [ 'root' ] ) ; $ this -> app -> registerPlugin ( $ path ) ; $ this -> app [ 'events' ] -> dispatch ( new PluginLoaded ( $ plugin , $ headers ) ) ; } } | Load application must - use plugins . |
12,004 | public function compileManifest ( array $ directories ) { $ manifest = [ ] ; foreach ( $ directories as $ directory ) { if ( $ payload = $ this -> getPlugin ( $ directory ) ) { $ manifest [ $ directory ] = $ payload ; } } return $ this -> writeManifest ( $ manifest ) ; } | Compile a new plugin manifest . |
12,005 | public function getPlugin ( string $ directory ) { $ files = $ this -> files -> files ( $ this -> app -> mupluginsPath ( $ directory ) ) ; foreach ( $ files as $ file ) { $ headers = $ this -> headers ( $ file -> getRealPath ( ) , $ this -> headers ) ; if ( ! empty ( $ headers [ 'name' ] ) ) { return array_merge ( [ 'root' => $ file -> getFilename ( ) ] , $ headers ) ; break ; } } } | Get the plugin . Find the root file and return its headers . |
12,006 | public function loadManifest ( ) { if ( $ this -> files -> exists ( $ this -> manifestPath ) ) { return $ this -> files -> getRequire ( $ this -> manifestPath ) ; } return null ; } | Return plugins manifest . |
12,007 | public function load ( string $ path ) : ThemeManager { $ this -> setThemeDirectory ( ) ; $ this -> setThemeConstants ( ) ; $ this -> loadThemeConfiguration ( $ path ) ; $ this -> setThemeAutoloading ( ) ; return $ this ; } | Load the theme . Setup theme requirements . |
12,008 | public function assets ( array $ locations ) { $ finder = $ this -> app -> bound ( 'asset.finder' ) ? $ this -> app [ 'asset.finder' ] : null ; if ( ! is_null ( $ finder ) ) { $ finder -> addLocations ( $ locations ) ; } return $ this ; } | Define theme assets directories . |
12,009 | public function getUrl ( string $ path = '' ) { if ( is_multisite ( ) && defined ( SUBDOMAIN_INSTALL ) && SUBDOMAIN_INSTALL ) { return sprintf ( '%s/%s/themes/%s' , get_home_url ( ) , CONTENT_DIR , $ this -> getDirectory ( ) ) . ( $ path ? '/' . $ path : $ path ) ; } return get_template_directory_uri ( ) . ( $ path ? '/' . $ path : $ path ) ; } | Return the theme root URL . |
12,010 | protected function setThemeDirectory ( ) { $ pos = strrpos ( $ this -> dirPath , DIRECTORY_SEPARATOR ) ; $ this -> directory = substr ( $ this -> dirPath , $ pos + 1 ) ; } | Set the theme directory name property . |
12,011 | protected function setThemeAutoloading ( ) { foreach ( $ this -> config -> get ( 'theme.autoloading' , [ ] ) as $ ns => $ path ) { $ path = $ this -> dirPath . '/' . trim ( $ path , '\/' ) ; $ this -> loader -> addPsr4 ( $ ns , $ path ) ; } $ this -> loader -> register ( ) ; } | Load theme classes . |
12,012 | public function providers ( array $ providers = [ ] ) { foreach ( $ providers as $ provider ) { $ this -> app -> register ( new $ provider ( $ this -> app ) ) ; } return $ this ; } | Register theme services providers . |
12,013 | public function views ( array $ paths = [ ] ) { if ( ! $ this -> app -> has ( 'view' ) ) { return $ this ; } if ( empty ( $ paths ) ) { return $ this ; } $ factory = $ this -> app -> make ( 'view' ) ; $ twigLoader = $ this -> app -> make ( 'twig.loader' ) ; foreach ( $ paths as $ path ) { $ uri = $ this -> dirPath . '/' . trim ( $ path , '\/' ) ; $ factory -> getFinder ( ) -> prependLocation ( $ uri ) ; $ twigLoader -> addPath ( $ uri ) ; } return $ this ; } | Register theme views path . |
12,014 | protected function setThemeConstants ( ) { $ this -> parsedHeaders = $ this -> headers ( $ this -> dirPath . '/style.css' , $ this -> headers ) ; $ textdomain = ( isset ( $ this -> parsedHeaders [ 'text_domain' ] ) && ! empty ( $ this -> parsedHeaders [ 'text_domain' ] ) ) ? $ this -> parsedHeaders [ 'text_domain' ] : 'themosis_theme' ; defined ( 'THEME_TD' ) ? THEME_TD : define ( 'THEME_TD' , $ textdomain ) ; } | Register theme constants . |
12,015 | public function sidebars ( $ sidebars = [ ] ) { if ( empty ( $ sidebars ) ) { return $ this ; } if ( function_exists ( 'register_sidebar' ) ) { foreach ( $ sidebars as $ sidebar ) { register_sidebar ( $ sidebar ) ; } } return $ this ; } | Register theme sidebars . |
12,016 | public function run ( $ hook , $ args = null ) { if ( is_array ( $ args ) ) { $ this -> doActionRefArray ( $ hook , $ args ) ; } else { $ this -> doAction ( $ hook , $ args ) ; } return $ this ; } | Run all actions registered with the hook . |
12,017 | protected function addEventListener ( $ name , $ callback , $ priority , $ accepted_args ) { $ this -> hooks [ $ name ] = [ $ callback , $ priority , $ accepted_args ] ; $ this -> addAction ( $ name , $ callback , $ priority , $ accepted_args ) ; } | Add an action event for the specified hook . |
12,018 | protected function addAction ( $ name , $ callback , $ priority , $ accepted_args ) { add_action ( $ name , $ callback , $ priority , $ accepted_args ) ; } | Calls the WordPress add_action function to listen on a hook event . |
12,019 | protected function detectConsoleEnvironment ( Closure $ callback , array $ args ) { if ( ! is_null ( $ value = $ this -> getEnvironmentArgument ( $ args ) ) ) { return head ( array_slice ( explode ( '=' , $ value ) , 1 ) ) ; } return $ this -> detectWebEnvironment ( $ callback ) ; } | Set the application environment for a command - line request . |
12,020 | public function make ( string $ slug , string $ plural , string $ singular ) : PostTypeInterface { $ postType = ( new PostType ( $ slug , $ this -> action , $ this -> filter ) ) -> setLabels ( [ 'name' => $ plural , 'singular_name' => $ singular , 'add_new_item' => sprintf ( 'Add New %s' , $ singular ) , 'edit_item' => sprintf ( 'Edit %s' , $ singular ) , 'new_item' => sprintf ( 'New %s' , $ singular ) , 'view_item' => sprintf ( 'View %s' , $ singular ) , 'view_items' => sprintf ( 'View %s' , $ plural ) , 'search_items' => sprintf ( 'Search %s' , $ plural ) , 'not_found' => sprintf ( 'No %s found' , $ plural ) , 'not_found_in_trash' => sprintf ( 'No %s found in Trash' , $ plural ) , 'parent_item_colon' => sprintf ( 'Parent %s:' , $ singular ) , 'all_items' => sprintf ( 'All %s' , $ plural ) , 'archives' => sprintf ( '%s Archives' , $ singular ) , 'attributes' => sprintf ( '%s Attributes' , $ singular ) , 'insert_into_item' => sprintf ( 'Insert into %s' , strtolower ( $ singular ) ) , 'uploaded_to_this_item' => sprintf ( 'Uploaded to this %s' , strtolower ( $ singular ) ) , 'filter_items_list' => sprintf ( 'Filter %s list' , strtolower ( $ plural ) ) , 'items_list_navigation' => sprintf ( '%s list navigation' , $ plural ) , 'items_list' => sprintf ( '%s list' , $ plural ) ] ) -> setArguments ( [ 'public' => true , 'show_in_rest' => true , 'menu_position' => 20 , 'supports' => [ 'title' ] , 'has_archive' => true ] ) ; $ abstract = sprintf ( 'themosis.posttype.%s' , $ slug ) ; if ( ! $ this -> container -> bound ( $ abstract ) ) { $ this -> container -> instance ( $ abstract , $ postType ) ; } else { throw new PostTypeException ( 'The post type [' . $ slug . '] already exists.' ) ; } return $ postType ; } | Create a new post type instance . |
12,021 | public function command ( $ signature , \ Closure $ callback ) { $ command = new ClosureCommand ( $ signature , $ callback ) ; Console :: starting ( function ( $ console ) use ( $ command ) { $ console -> add ( $ command ) ; } ) ; return $ command ; } | Register a closure based command with the application . |
12,022 | protected function getConsole ( ) { if ( is_null ( $ this -> console ) ) { $ console = new Console ( $ this -> app , $ this -> events , $ this -> app -> version ( ) ) ; $ console -> setName ( 'Themosis Framework' ) ; return $ this -> console = $ console -> resolveCommands ( $ this -> commands ) ; } return $ this -> console ; } | Return the console application instance . |
12,023 | public function call ( $ command , array $ parameters = [ ] , $ outputBuffer = null ) { $ this -> bootstrap ( ) ; return $ this -> getConsole ( ) -> call ( $ command , $ parameters , $ outputBuffer ) ; } | Run a console command by name . |
12,024 | protected function renderException ( $ output , \ Exception $ e ) { $ this -> app [ ExceptionHandler :: class ] -> renderForConsole ( $ output , $ e ) ; } | Render the exception . |
12,025 | protected function setLayout ( $ expanded = false , $ multiple = false ) { if ( $ expanded && false === $ multiple ) { $ this -> layout = 'radio' ; } elseif ( $ expanded && $ multiple ) { $ this -> layout = 'checkbox' ; } return $ this ; } | Set the field layout option . |
12,026 | public function getOptions ( array $ excludes = null ) : array { $ options = parent :: getOptions ( $ excludes ) ; $ choices = $ this -> getOption ( 'choices' , [ ] ) ; if ( $ choices instanceof ChoiceListInterface ) { $ choices = $ choices -> format ( ) -> get ( ) ; } return array_merge ( $ options , [ 'choices' => $ choices , 'layout' => $ this -> getLayout ( ) ] ) ; } | Return choice type field options . |
12,027 | public function metaboxSave ( $ value , int $ post_id ) { $ this -> setValue ( $ value ) ; if ( ! $ this -> getOption ( 'multiple' , false ) ) { $ this -> saveSingleValue ( $ this -> getRawValue ( ) , $ post_id ) ; } else { $ this -> saveMultipleValue ( $ this -> getRawValue ( ) , $ post_id ) ; } } | Handle metabox field value registration . |
12,028 | public function metaboxGet ( int $ post_id ) { $ value = get_post_meta ( $ post_id , $ this -> getName ( ) , ! $ this -> getOption ( 'multiple' , false ) ) ; if ( ! empty ( $ value ) ) { $ this -> setValue ( $ value ) ; } } | Initialize metabox field value . |
12,029 | protected function saveSingleValue ( $ value , int $ post_id ) { $ previous = get_post_meta ( $ post_id , $ this -> getName ( ) , true ) ; if ( is_null ( $ value ) || empty ( $ value ) ) { delete_post_meta ( $ post_id , $ this -> getName ( ) ) ; } elseif ( empty ( $ previous ) ) { add_post_meta ( $ post_id , $ this -> getName ( ) , $ value , true ) ; } else { update_post_meta ( $ post_id , $ this -> getName ( ) , $ value , $ previous ) ; } } | Save a single value . |
12,030 | protected function saveTermSingleValue ( $ value , int $ term_id ) { $ previous = get_term_meta ( $ term_id , $ this -> getName ( ) , true ) ; if ( is_null ( $ value ) || empty ( $ value ) ) { delete_term_meta ( $ term_id , $ this -> getName ( ) ) ; } elseif ( empty ( $ previous ) ) { add_term_meta ( $ term_id , $ this -> getName ( ) , $ value , true ) ; } else { update_term_meta ( $ term_id , $ this -> getName ( ) , $ value , $ previous ) ; } } | Handle field single term meta registration . |
12,031 | protected function saveTermMultipleValue ( $ value , int $ term_id ) { $ previous = get_term_meta ( $ term_id , $ this -> getName ( ) , false ) ; if ( is_null ( $ value ) || empty ( $ value ) ) { delete_term_meta ( $ term_id , $ this -> getName ( ) ) ; } elseif ( empty ( $ previous ) && is_array ( $ value ) ) { array_walk ( $ value , function ( $ val ) use ( $ term_id ) { add_term_meta ( $ term_id , $ this -> getName ( ) , $ val , false ) ; } ) ; } else { delete_term_meta ( $ term_id , $ this -> getName ( ) ) ; array_walk ( $ value , function ( $ val ) use ( $ term_id ) { add_term_meta ( $ term_id , $ this -> getName ( ) , $ val , false ) ; } ) ; } } | Handle field multiple term meta registration . |
12,032 | protected function saveUserSingleValue ( $ value , int $ user_id ) { $ previous = get_user_meta ( $ user_id , $ this -> getName ( ) , true ) ; if ( is_null ( $ value ) || empty ( $ value ) ) { delete_user_meta ( $ user_id , $ this -> getName ( ) ) ; } elseif ( empty ( $ previous ) ) { add_user_meta ( $ user_id , $ this -> getName ( ) , $ value , true ) ; } else { update_user_meta ( $ user_id , $ this -> getName ( ) , $ value , $ previous ) ; } } | Handle field user meta single data registration . |
12,033 | protected function saveUserMultipleValue ( $ value , int $ user_id ) { $ previous = get_user_meta ( $ user_id , $ this -> getName ( ) , false ) ; if ( is_null ( $ value ) || empty ( $ value ) ) { delete_user_meta ( $ user_id , $ this -> getName ( ) ) ; } elseif ( empty ( $ previous ) && is_array ( $ value ) ) { array_walk ( $ value , function ( $ val ) use ( $ user_id ) { add_user_meta ( $ user_id , $ this -> getName ( ) , $ val , false ) ; } ) ; } else { delete_user_meta ( $ user_id , $ this -> getName ( ) ) ; array_walk ( $ value , function ( $ val ) use ( $ user_id ) { add_user_meta ( $ user_id , $ this -> getName ( ) , $ val , false ) ; } ) ; } } | Handle field user meta multiple data registration . |
12,034 | public function transform ( MetaboxInterface $ metabox ) { return [ 'id' => $ metabox -> getId ( ) , 'context' => $ metabox -> getContext ( ) , 'l10n' => $ metabox -> getTranslations ( ) , 'locale' => $ metabox -> getLocale ( ) , 'priority' => $ metabox -> getPriority ( ) , 'screen' => $ this -> getScreen ( $ metabox -> getScreen ( ) ) , 'title' => $ metabox -> getTitle ( ) , ] ; } | Transform the metabox to a resource . |
12,035 | protected function getScreen ( $ screen ) { if ( is_string ( $ screen ) && function_exists ( 'convert_to_screen' ) ) { $ screen = convert_to_screen ( $ screen ) ; } if ( $ screen instanceof \ WP_Screen ) { return [ 'id' => $ screen -> id , 'post_type' => $ screen -> post_type ] ; } return [ 'id' => $ screen , 'post_type' => $ screen ] ; } | Get the metabox screen data . |
12,036 | public function includeFields ( MetaboxInterface $ metabox ) { return $ this -> collection ( $ metabox -> repository ( ) -> all ( ) , function ( FieldTypeInterface $ field ) { $ field = $ field -> setResourceTransformerFactory ( new Factory ( ) ) ; $ transformer = $ field -> getResourceTransformerFactory ( ) -> make ( $ field -> getResourceTransformer ( ) ) ; return $ transformer -> transform ( $ field ) ; } ) ; } | Return the metabox fields . |
12,037 | public function transform ( $ data ) { if ( is_null ( $ data ) ) { return false ; } if ( ! is_string ( $ data ) ) { throw new DataTransformerException ( 'A string value is expected.' ) ; } if ( empty ( $ data ) ) { return false ; } if ( in_array ( $ data , [ 'off' , 'no' ] , true ) ) { return false ; } return true ; } | Convert a string to a boolean value . |
12,038 | public function setType ( string $ filename , $ type = null ) : AssetFileInterface { if ( ! is_null ( $ type ) && in_array ( $ type , $ this -> extensions , true ) ) { $ this -> type = $ this -> findType ( $ type ) ; return $ this ; } $ ext = $ this -> files -> extension ( $ filename ) ; if ( ! empty ( $ ext ) && in_array ( $ ext , $ this -> extensions , true ) ) { $ this -> type = $ this -> findType ( $ ext ) ; } return $ this ; } | Set the asset file type . |
12,039 | public function registerMetabox ( ) { $ this -> app -> bind ( 'metabox' , function ( $ app ) { $ resource = new MetaboxResource ( $ app -> bound ( 'league.fractal' ) ? $ app [ 'league.fractal' ] : new Manager ( ) , new ArraySerializer ( ) , new MetaboxTransformer ( ) ) ; return new Factory ( $ app , $ app [ 'action' ] , $ app [ 'filter' ] , $ resource ) ; } ) ; } | Register the metabox factory . |
12,040 | public function add ( $ field , SectionInterface $ section = null ) : UserFieldContract { if ( $ field instanceof SectionInterface ) { $ section = $ field ; if ( $ section -> hasItems ( ) ) { foreach ( $ section -> getItems ( ) as $ item ) { $ item -> setOptions ( [ 'group' => $ section -> getId ( ) ] ) ; $ this -> add ( $ item , $ section ) ; } } return $ this ; } $ field -> setTheme ( 'themosis.users' ) ; $ field -> setPrefix ( $ this -> options [ 'prefix' ] ) ; $ this -> repository -> addField ( $ field , $ this -> getSection ( $ field , $ section ) ) ; return $ this ; } | Add a user field . |
12,041 | protected function getSection ( FieldTypeInterface $ field , $ section = null ) : SectionInterface { if ( is_null ( $ section ) ) { if ( $ this -> repository -> hasGroup ( $ field -> getOption ( 'group' ) ) ) { $ section = $ this -> repository -> getGroup ( $ field -> getOption ( 'group' ) ) ; } else { $ section = new Section ( $ field -> getOption ( 'group' ) ) ; } $ section -> addItem ( $ field ) ; } return $ section ; } | Get section for given field . |
12,042 | public function set ( ) : UserFieldContract { $ this -> action -> add ( [ 'user_new_form' , 'show_user_profile' , 'edit_user_profile' ] , [ $ this , 'display' ] ) ; $ this -> action -> add ( [ 'user_register' , 'profile_update' ] , [ $ this , 'save' ] ) ; return $ this ; } | Set the user fields . |
12,043 | public function display ( $ user ) { foreach ( $ this -> repository -> getGroups ( ) as $ group ) { $ fields = $ group -> getItems ( ) ; if ( is_a ( $ user , 'WP_User' ) ) { array_walk ( $ fields , function ( $ field ) use ( $ user ) { $ field -> userGet ( $ user -> ID ) ; } ) ; } echo $ this -> factory -> make ( 'themosis.users.main' , [ 'section' => $ group , 'fields' => $ fields ] ) -> render ( ) ; } } | Display user meta fields . |
12,044 | public function save ( $ user_id ) { $ validator = $ this -> validator -> make ( $ this -> getUserData ( app ( 'request' ) ) , $ this -> getUserRules ( ) , $ this -> getUserMessages ( ) , $ this -> getUserPlaceholders ( ) ) ; $ validation = $ validator -> valid ( ) ; foreach ( $ this -> repository -> all ( ) as $ field ) { $ field -> setErrorMessageBag ( $ validator -> errors ( ) ) ; if ( method_exists ( $ field , 'userSave' ) ) { $ field -> userSave ( $ validation [ $ field -> getName ( ) ] ?? null , $ user_id ) ; } else { throw new UserException ( 'Unable to save [' . $ field -> getName ( ) . ']. The [userSave] method is missing.' ) ; } } } | Save user meta . |
12,045 | protected function getUserData ( Request $ request ) { $ data = [ ] ; foreach ( $ this -> repository -> all ( ) as $ field ) { $ data [ $ field -> getName ( ) ] = $ request -> get ( $ field -> getName ( ) ) ; } return $ data ; } | Return request user meta data . |
12,046 | protected function getUserRules ( ) { $ rules = [ ] ; foreach ( $ this -> repository -> all ( ) as $ field ) { $ rules [ $ field -> getName ( ) ] = $ field -> getOption ( 'rules' ) ; } return $ rules ; } | Return user validation rules . |
12,047 | protected function getUserMessages ( ) { $ messages = [ ] ; foreach ( $ this -> repository -> all ( ) as $ field ) { foreach ( $ field -> getOption ( 'messages' ) as $ rule => $ message ) { $ messages [ $ field -> getName ( ) . '.' . $ rule ] = $ message ; } } return $ messages ; } | Return user validation messages . |
12,048 | protected function getUserPlaceholders ( ) { $ placeholders = [ ] ; foreach ( $ this -> repository -> all ( ) as $ field ) { $ placeholders [ $ field -> getName ( ) ] = $ field -> getOption ( 'placeholder' ) ; } return $ placeholders ; } | Return user validation placeholders . |
12,049 | public function text ( string $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new TextType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return a text type instance . |
12,050 | public function password ( string $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new PasswordType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return a password type instance . |
12,051 | public function number ( string $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new NumberType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return a number field type instance . |
12,052 | public function integer ( string $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new IntegerType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return an integer field type instance . |
12,053 | public function email ( string $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new EmailType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return an email type instance . |
12,054 | public function date ( $ name , array $ features = [ ] , array $ attributes = [ ] ) { $ properties = [ 'features' => $ features , 'atts' => array_merge ( [ 'class' => 'newtag' ] , $ attributes , [ 'data-field' => 'date' ] ) , 'name' => $ name , ] ; return $ this -> make ( 'Themosis\\Field\\Fields\\DateField' , $ properties ) ; } | Return a DateField instance . |
12,055 | public function textarea ( string $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new TextareaType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return a textarea type instance . |
12,056 | public function checkbox ( string $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new CheckboxType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return a checkbox type instance . |
12,057 | public function choice ( string $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new ChoiceType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return a choice type instance . |
12,058 | public function media ( $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new MediaType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return a media type instance . |
12,059 | public function editor ( $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new EditorType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return an editor type instance . |
12,060 | public function collection ( $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new CollectionType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return a collection type instance . |
12,061 | public function color ( $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new ColorType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return a color type instance . |
12,062 | public function button ( string $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new ButtonType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return a button type instance . |
12,063 | public function submit ( string $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new SubmitType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return a submit type instance . |
12,064 | public function hidden ( string $ name , array $ options = [ ] ) : FieldTypeInterface { return ( new HiddenType ( $ name ) ) -> setLocale ( $ this -> app -> getLocale ( ) ) -> setViewFactory ( $ this -> viewFactory ) -> setOptions ( $ options ) ; } | Return a hidden type instance . |
12,065 | public function metaboxSave ( $ value , int $ post_id ) { $ this -> setValue ( $ value ) ; $ previous = get_post_meta ( $ post_id , $ this -> getName ( ) , true ) ; if ( is_null ( $ this -> getValue ( ) ) || empty ( $ this -> getValue ( ) ) ) { delete_post_meta ( $ post_id , $ this -> getName ( ) ) ; } elseif ( empty ( $ previous ) ) { add_post_meta ( $ post_id , $ this -> getName ( ) , $ this -> getRawValue ( ) , true ) ; } else { update_post_meta ( $ post_id , $ this -> getName ( ) , $ this -> getRawValue ( ) , $ previous ) ; } } | Handle integer field post meta registration . |
12,066 | public function make ( string $ slug , $ objects , string $ plural , string $ singular ) : TaxonomyInterface { $ taxonomy = ( new Taxonomy ( $ slug , ( array ) $ objects , $ this -> container , $ this -> action ) ) -> setLabels ( [ 'name' => $ plural , 'singular_name' => $ singular , 'search_items' => sprintf ( 'Search %s' , $ plural ) , 'popular_items' => sprintf ( 'Popular %s' , $ plural ) , 'all_items' => sprintf ( 'All %s' , $ plural ) , 'parent_item' => sprintf ( 'Parent %s' , $ singular ) , 'parent_item_colon' => sprintf ( 'Parent %s:' , $ singular ) , 'edit_item' => sprintf ( 'Edit %s' , $ singular ) , 'view_item' => sprintf ( 'View %s' , $ singular ) , 'update_item' => sprintf ( 'Update %s' , $ singular ) , 'add_new_item' => sprintf ( 'Add New %s' , $ singular ) , 'new_item_name' => sprintf ( 'New %s Name' , $ singular ) , 'separate_items_with_commas' => sprintf ( 'Separate %s with commas' , strtolower ( $ plural ) ) , 'add_or_remove_items' => sprintf ( 'Add or remove %s' , strtolower ( $ plural ) ) , 'choose_from_most_used' => sprintf ( 'Choose from the most used %s' , strtolower ( $ plural ) ) , 'not_found' => sprintf ( 'No %s found' , strtolower ( $ plural ) ) , 'no_terms' => sprintf ( 'No %s' , strtolower ( $ plural ) ) , 'items_list_navigation' => sprintf ( '%s list navigation' , $ plural ) , 'items_list' => sprintf ( '%s list' , $ plural ) , 'most_used' => 'Most Used' , 'back_to_items' => sprintf ( 'Back to %s' , $ plural ) ] ) -> setArguments ( [ 'public' => true , 'show_in_rest' => true , 'show_admin_column' => true ] ) ; $ abstract = sprintf ( 'themosis.taxonomy.%s' , $ slug ) ; if ( ! $ this -> container -> bound ( $ abstract ) ) { $ this -> container -> instance ( $ abstract , $ taxonomy ) ; } else { throw new TaxonomyException ( 'The taxonomy [' . $ slug . '] already exists.' ) ; } return $ taxonomy ; } | Register a taxonomy . |
12,067 | protected function createDirectories ( ) { if ( ! $ this -> files -> isDirectory ( $ directory = app_path ( 'Forms/Auth/Passwords' ) ) ) { $ this -> files -> makeDirectory ( $ directory , 0755 , true ) ; } if ( ! $ this -> files -> isDirectory ( $ directory = app_path ( 'Http/Controllers/Auth' ) ) ) { $ this -> files -> makeDirectory ( $ directory , 0755 , true ) ; } if ( ! $ this -> files -> isDirectory ( $ directory = resource_path ( 'views/auth/passwords' ) ) ) { $ this -> files -> makeDirectory ( $ directory , 0755 , true ) ; } if ( ! $ this -> files -> isDirectory ( $ directory = resource_path ( 'views/settings' ) ) ) { $ this -> files -> makeDirectory ( $ directory , 0755 , true ) ; } } | Create auth necessary directories . |
12,068 | protected function exportViews ( ) { foreach ( $ this -> views as $ pathIn => $ pathOut ) { if ( $ this -> files -> exists ( $ view = resource_path ( 'views/' . $ pathOut ) ) && ! $ this -> option ( 'force' ) ) { if ( ! $ this -> confirm ( "The [{$pathOut}] view already exists. Do you want to overwrite it?" ) ) { continue ; } } $ this -> files -> copy ( __DIR__ . '/stubs/make/views/' . $ pathIn , $ view ) ; } } | Export authentication default views . |
12,069 | protected function exportControllers ( ) { foreach ( $ this -> controllers as $ pathIn => $ pathOut ) { if ( $ this -> files -> exists ( $ controller = app_path ( 'Http/Controllers/' . $ pathOut ) ) && ! $ this -> option ( 'force' ) ) { if ( ! $ this -> confirm ( "The [{$pathOut}] controller already exists. Do you want to overwrite it?" ) ) { continue ; } } $ this -> files -> put ( $ controller , $ this -> compileStub ( $ this -> files -> get ( __DIR__ . '/stubs/make/controllers/' . $ pathIn ) ) ) ; } } | Export authentication default controllers . |
12,070 | protected function exportForms ( ) { foreach ( $ this -> forms as $ pathIn => $ pathOut ) { if ( $ this -> files -> exists ( $ form = app_path ( 'Forms/' . $ pathOut ) ) && ! $ this -> option ( 'force' ) ) { if ( ! $ this -> confirm ( "The [{$pathOut}] form already exists. Do you want to overwrite it?" ) ) { continue ; } } $ this -> files -> put ( $ form , $ this -> compileStub ( $ this -> files -> get ( __DIR__ . '/stubs/make/forms/' . $ pathIn ) ) ) ; } } | Export authentication default forms . |
12,071 | public function get ( ) { $ wordpressUri = trim ( config ( 'app.wp.dir' , 'cms' ) , '\/' ) ; $ route = $ this -> router -> any ( $ wordpressUri . '/wp-admin/{any?}' , function ( ) { return new Response ( ) ; } ) ; $ route -> middleware ( 'admin' ) ; $ route -> bind ( $ this -> request ) ; return $ route ; } | Return the catch - all WordPress administration route . |
12,072 | public function setDirectory ( ) { $ pos = strrpos ( $ this -> dirPath , DIRECTORY_SEPARATOR ) ; $ this -> directory = substr ( $ this -> dirPath , $ pos + 1 ) ; } | Set the plugin directory name . |
12,073 | public function getPath ( string $ path = '' ) : string { return $ this -> dirPath . ( $ path ? DIRECTORY_SEPARATOR . $ path : $ path ) ; } | Return the plugin root path . |
12,074 | public function config ( string $ key , $ default = null ) { $ fullnameKey = $ this -> getNamespace ( ) . '_' . $ key ; return $ this -> config -> get ( $ fullnameKey , $ default ) ; } | Return a plugin configuration value . |
12,075 | protected function setConstants ( ) { $ this -> parsedHeaders = $ this -> headers ( $ this -> filePath , $ this -> headers ) ; $ domainVar = $ this -> parsedHeaders [ 'domain_var' ] ?? 'PLUGIN_TD' ; $ domainVar = strtoupper ( $ domainVar ) ; $ textDomain = $ this -> parsedHeaders [ 'text_domain' ] ?? 'plugin-textdomain' ; if ( ! defined ( $ domainVar ) ) { define ( $ domainVar , $ textDomain ) ; } } | Set plugin headers and plugin text domain constant . |
12,076 | protected function loadPluginConfiguration ( string $ configPath ) { $ this -> app -> loadConfigurationFiles ( $ this -> config , $ this -> dirPath . '/' . trim ( $ configPath , '\/' ) ) ; } | Load plugin configuration files . |
12,077 | protected function setPluginAutoloading ( ) { foreach ( $ this -> config ( 'plugin.autoloading' , [ ] ) as $ ns => $ path ) { $ path = $ this -> dirPath . '/' . trim ( $ path , '\/' ) ; $ this -> loader -> addPsr4 ( $ ns , $ path ) ; } $ this -> loader -> register ( ) ; } | Load plugin classes . |
12,078 | public function run ( $ hook , $ args = null ) { if ( is_array ( $ args ) ) { return $ this -> applyFiltersRefArray ( $ hook , $ args ) ; } return $ this -> applyFilters ( $ hook , $ args ) ; } | Run all filters registered with the hook . |
12,079 | protected function addEventListener ( $ name , $ callback , $ priority , $ accepted_args ) { $ this -> hooks [ $ name ] = [ $ callback , $ priority , $ accepted_args ] ; $ this -> addFilter ( $ name , $ callback , $ priority , $ accepted_args ) ; } | Add a filter event for the specified hook . |
12,080 | protected function addFilter ( $ name , $ callback , $ priority , $ accepted_args ) { add_filter ( $ name , $ callback , $ priority , $ accepted_args ) ; } | Calls the WordPress add_filter function in order to listen to a filter hook . |
12,081 | protected function parse ( array $ options ) { $ templates = [ 'page' => [ ] ] ; foreach ( $ options as $ slug => $ properties ) { if ( is_int ( $ slug ) ) { $ templates [ 'page' ] [ $ properties ] = $ this -> formatName ( $ properties ) ; } else { if ( is_string ( $ properties ) ) { $ templates [ 'page' ] [ $ slug ] = $ properties ; } if ( is_array ( $ properties ) && ! empty ( $ properties ) ) { if ( 1 === count ( $ properties ) && is_string ( $ properties [ 0 ] ) ) { $ templates [ 'page' ] [ $ slug ] = $ properties [ 0 ] ; } if ( 2 === count ( $ properties ) ) { $ post_types = ( array ) $ properties [ 1 ] ; foreach ( $ post_types as $ post_type ) { $ post_type = trim ( $ post_type ) ; if ( ! isset ( $ templates [ $ post_type ] ) ) { $ templates [ $ post_type ] = [ ] ; } $ templates [ $ post_type ] [ $ slug ] = is_string ( $ properties [ 0 ] ) ? trim ( $ properties [ 0 ] ) : $ this -> formatName ( $ slug ) ; } } } } } return $ templates ; } | Parse templates . |
12,082 | public function register ( ) { foreach ( $ this -> templates as $ post_type => $ templates ) { if ( empty ( $ templates ) ) { continue ; } $ this -> filter -> add ( "theme_{$post_type}_templates" , function ( $ registered ) use ( $ templates ) { return array_merge ( $ registered , $ templates ) ; } ) ; } } | Register theme templates . |
12,083 | public function getDefaultOptions ( ) : array { $ this -> defaultOptions [ 'rules' ] = $ this -> rules ; $ this -> defaultOptions [ 'messages' ] = $ this -> messages ; $ this -> defaultOptions [ 'placeholder' ] = $ this -> placeholder ?? $ this -> getBaseName ( ) ; $ this -> defaultOptions [ 'label' ] = $ this -> label ?? ucfirst ( str_replace ( [ '-' , '_' ] , ' ' , $ this -> getBaseName ( ) ) ) ; return $ this -> defaultOptions ; } | Return the list of default options . |
12,084 | public function getOptions ( array $ excludes = null ) : array { if ( ! is_null ( $ excludes ) ) { return array_filter ( $ this -> options , function ( $ key ) use ( $ excludes ) { return ! in_array ( $ key , $ excludes , true ) ; } , ARRAY_FILTER_USE_KEY ) ; } return $ this -> options ; } | Return field options . |
12,085 | public function render ( ) : string { $ view = $ this -> viewFactory -> make ( $ this -> getView ( ) , $ this -> getFieldData ( ) ) ; $ this -> rendered = true ; return $ view -> render ( ) ; } | Output the entity as HTML . |
12,086 | public function getView ( bool $ prefixed = true ) : string { if ( $ prefixed && ! is_null ( $ theme = $ this -> getOption ( 'theme' ) ) ) { return $ this -> buildViewPath ( $ theme , $ this -> view ) ; } return $ this -> view ; } | Return the view instance used by the entity . |
12,087 | public function setValue ( $ value ) : FieldTypeInterface { $ this -> value = $ this -> transformer -> transform ( $ value ) ; return $ this ; } | Set the value property of the field . |
12,088 | public function getRawValue ( ) { $ value = $ this -> transformer -> reverseTransform ( $ this -> value ) ; if ( $ this -> getOption ( 'flush' , false ) ) { return '' ; } return $ value ; } | Retrieve the field raw value . |
12,089 | public function error ( string $ name = '' , bool $ first = false ) { $ errors = $ this -> errors ( ) ; if ( empty ( $ name ) ) { $ name = $ this -> getName ( ) ; } if ( $ first ) { return $ errors -> first ( $ name ) ; } return $ errors -> get ( $ name ) ; } | Retrieve the field error messages . |
12,090 | protected function unauthenticated ( $ request , AuthenticationException $ e ) { return $ request -> expectsJson ( ) ? response ( ) -> json ( [ 'message' => $ e -> getMessage ( ) ] , 401 ) : redirect ( ) -> guest ( $ e -> redirectTo ( ) ?? route ( 'login' ) ) ; } | Convert an authentication exception into a response . |
12,091 | protected function convertExceptionToResponse ( Exception $ e ) { $ headers = $ this -> isHttpException ( $ e ) ? $ e -> getHeaders ( ) : [ ] ; $ statusCode = $ this -> isHttpException ( $ e ) ? $ e -> getStatusCode ( ) : 500 ; try { $ content = config ( 'app.debug' ) && class_exists ( Whoops :: class ) ? $ this -> renderExceptionWithWhoops ( $ e ) : $ this -> renderExceptionWithSymfony ( $ e , config ( 'app.debug' ) ) ; } catch ( Exception $ e ) { $ content = $ content ?? $ this -> renderExceptionWithSymfony ( $ e , config ( 'app.debug' ) ) ; } return SymfonyResponse :: create ( $ content , $ statusCode , $ headers ) ; } | Convert an exception to a response instance . |
12,092 | protected function renderExceptionWithWhoops ( Exception $ e ) { return tap ( new Whoops ( ) , function ( $ whoops ) { $ whoops -> pushHandler ( $ this -> whoopsHandler ( ) ) ; $ whoops -> writeToOutput ( false ) ; $ whoops -> allowQuit ( false ) ; } ) -> handleException ( $ e ) ; } | Render an exception using Whoops . |
12,093 | protected function whoopsHandler ( ) { return tap ( new PrettyPageHandler ( ) , function ( $ handler ) { $ files = new Filesystem ( ) ; $ handler -> handleUnconditionally ( true ) ; foreach ( config ( 'app.debug_blacklist' , [ ] ) as $ key => $ secrets ) { foreach ( $ secrets as $ secret ) { $ handler -> blacklist ( $ key , $ secret ) ; } } if ( config ( 'app.editor' , false ) ) { $ handler -> setEditor ( config ( 'app.editor' ) ) ; } $ handler -> setApplicationPaths ( array_flip ( Arr :: except ( array_flip ( $ files -> directories ( base_path ( ) ) ) , [ base_path ( 'vendor' ) ] ) ) ) ; } ) ; } | Get the Whoops handler for the application . |
12,094 | protected function context ( ) { try { return [ 'userId' => Auth :: id ( ) , 'email' => Auth :: user ( ) ? Auth :: user ( ) -> email : null ] ; } catch ( Throwable $ e ) { return [ ] ; } } | Get the default context variables for logging . |
12,095 | public function listen ( $ action , $ callback , $ logged = 'both' ) : AjaxInterface { if ( $ logged === false || $ logged === 'no' ) { $ this -> action -> add ( 'wp_ajax_nopriv_' . $ action , $ callback ) ; } if ( $ logged === true || $ logged === 'yes' ) { $ this -> action -> add ( 'wp_ajax_' . $ action , $ callback ) ; } if ( $ logged === 'both' ) { $ this -> action -> add ( [ 'wp_ajax_nopriv_' . $ action , 'wp_ajax_' . $ action ] , $ callback ) ; } return $ this ; } | Listen to AJAX API calls . |
12,096 | public function boot ( ) { if ( $ this -> app -> runningInConsole ( ) ) { $ this -> publishes ( [ __DIR__ . '/../../../dist' => web_path ( 'dist' ) ] , 'themosis' ) ; $ this -> publishes ( [ __DIR__ . '/../Exceptions/views' => resource_path ( 'views/errors/' ) ] , 'themosis-errors' ) ; } } | Publish core assets . |
12,097 | public function registerTwigEnvironment ( ) { $ this -> app -> singleton ( 'twig' , function ( $ app ) { $ twig = new \ Twig_Environment ( $ app [ 'twig.loader' ] , [ 'auto_reload' => true , 'cache' => $ app [ 'config' ] [ 'view.twig' ] ] ) ; $ twig -> addExtension ( new \ Twig_Extension_Debug ( ) ) ; if ( $ app [ 'config' ] [ 'app.debug' ] ) { $ twig -> enableDebug ( ) ; } $ twig -> addExtension ( new WordPress ( ) ) ; return $ twig ; } ) ; } | Register Twig Environment . |
12,098 | public function registerTwigEngine ( ) { $ factory = $ this -> app [ 'view' ] ; $ factory -> addExtension ( 'twig' , 'twig' , function ( ) { return new Twig ( $ this -> app [ 'twig' ] , $ this -> app [ 'view.finder' ] ) ; } ) ; } | Register the Twig engine implementation . |
12,099 | protected function setDefaultOptions ( ) : array { $ default = [ 'limit' => 0 , 'type' => [ 'image' , 'application' ] ] ; if ( function_exists ( '_x' ) ) { $ default [ 'l10n' ] = [ 'add' => _x ( 'Add Media' , 'field' , Application :: TEXTDOMAIN ) , 'button' => _x ( 'Insert' , 'field' , Application :: TEXTDOMAIN ) , 'remove' => _x ( 'Remove Selected' , 'field' , Application :: TEXTDOMAIN ) , 'title' => _x ( 'Insert Multiple Media' , 'field' , Application :: TEXTDOMAIN ) ] ; } return array_merge ( $ this -> defaultOptions , $ default ) ; } | Set field default options values . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.