idx int64 0 60.3k | question stringlengths 99 4.85k | target stringlengths 5 718 |
|---|---|---|
43,300 | public function minifyCSS ( ) { $ css_dir = './css' ; if ( is_dir ( $ css_dir ) ) { foreach ( glob ( "$css_dir/*.css" ) as $ css_file ) { if ( ! $ this -> endsWith ( $ css_file , 'min.css' ) ) { $ this -> taskMinify ( $ css_file ) -> to ( str_replace ( '.css' , '.min.css' , $ css_file ) ) -> type ( 'css' ) -> run ( ) ;... | Minify CSS stylesheets |
43,301 | public function minifyJS ( ) { $ js_dir = './js' ; if ( is_dir ( $ js_dir ) ) { foreach ( glob ( "$js_dir/*.js" ) as $ js_file ) { if ( ! $ this -> endsWith ( $ js_file , 'min.js' ) ) { $ this -> taskMinify ( $ js_file ) -> to ( str_replace ( '.js' , '.min.js' , $ js_file ) ) -> type ( 'js' ) -> run ( ) ; } } } return ... | Minify JavaScript files stylesheets |
43,302 | public function codeCs ( $ file = null , $ options = [ 'autofix' => false , 'strict' => false , ] ) { if ( $ file === null ) { $ file = implode ( ' ' , $ this -> csfiles ) ; } $ csignore = '' ; if ( count ( $ this -> csignore ) ) { $ csignore .= '--ignore=' ; $ csignore .= implode ( ',' , $ this -> csignore ) ; } $ str... | Code sniffer . |
43,303 | public function doRequest ( $ endpoint , callable $ callback ) { if ( $ result = $ this -> getFromCache ( ) ) { return $ result ; } $ request = new Request ( 'GET' , $ endpoint ) ; $ failureMessage = 'Could not obtain information about module. ' ; try { $ response = $ this -> getGuzzleClient ( ) -> send ( $ request , $... | Perform an HTTP request for module health information |
43,304 | protected function getFromCache ( ) { $ cacheKey = $ this -> getCacheKey ( ) ; $ result = $ this -> getCache ( ) -> get ( $ cacheKey , false ) ; if ( $ result === false ) { return false ; } return Convert :: json2array ( $ result ) ; } | Attempts to load something from the cache and deserializes from JSON if successful |
43,305 | protected function setToCache ( $ cacheKey , $ value , $ ttl = null ) { $ value = Convert :: raw2json ( $ value ) ; return $ this -> getCache ( ) -> set ( $ cacheKey , $ value , $ ttl ) ; } | Given a value set it to the cache with the given key after serializing the value as JSON |
43,306 | protected function handleCacheFromResponse ( Response $ response , $ result ) { if ( $ cacheControl = $ response -> getHeader ( 'Cache-Control' ) ) { $ cacheControl = implode ( ', ' , $ cacheControl ) ; if ( strpos ( $ cacheControl , 'no-store' ) === false && preg_match ( '/(?:max-age=)(\d+)/i' , $ cacheControl , $ mat... | Check the API response for cache control headers and respect them internally in the SilverStripe cache if found |
43,307 | protected function createRequest ( $ uri , $ method = 'GET' ) { $ headers = [ ] ; $ version = $ this -> resolveVersion ( ) ; if ( ! empty ( $ version ) ) { $ headers [ 'Silverstripe-Framework-Version' ] = $ version ; } return new Request ( $ method , $ uri , $ headers ) ; } | Create a request with some standard headers |
43,308 | public function getModuleHealthInfo ( ) { $ addons = $ this -> getModuleNames ( ) ; $ endpoint = 'addons.silverstripe.org/api/ratings?addons=' . implode ( ',' , $ addons ) ; return $ this -> doRequest ( $ endpoint , function ( $ responseBody ) { return isset ( $ responseBody ) ? $ responseBody [ 'ratings' ] : [ ] ; } )... | Return the list of supported addons as provided by addons . silverstripe . org |
43,309 | public function process ( ) { $ updateTask = Injector :: inst ( ) -> create ( UpdatePackageInfoTask :: class ) ; $ updateTask -> run ( null ) ; $ this -> isComplete = true ; } | Processes the task as a job |
43,310 | public function parseData ( $ data , array $ modes , $ key = null ) { $ return = [ ] ; uksort ( $ modes , function ( $ a , $ b ) { return substr_count ( $ b , '.' ) - substr_count ( $ a , '.' ) ; } ) ; if ( Utility :: isCollection ( $ data ) ) { $ parsed = $ this -> parseCollection ( $ modes , $ data , $ return ) ; } e... | Parse a collection using given modes . |
43,311 | private function parseCollection ( array $ modes , $ collection , & $ root , $ fullPropertyPath = '' ) { if ( is_array ( $ collection ) ) { foreach ( $ collection as $ i => $ resource ) { $ collection [ $ i ] = $ this -> parseResource ( $ modes , $ resource , $ root , $ fullPropertyPath ) ; } } elseif ( $ collection in... | Parse a collection using given modes |
43,312 | private function parseResource ( array $ modes , & $ resource , & $ root , $ fullPropertyPath = '' ) { foreach ( $ modes as $ relation => $ mode ) { $ modeResolver = $ this -> resolveMode ( $ mode ) ; $ steps = explode ( '.' , $ relation ) ; $ property = array_shift ( $ steps ) ; if ( is_array ( $ resource ) ) { if ( $... | Parse a single resource using given modes |
43,313 | private function resolveMode ( $ mode ) { if ( ! isset ( $ this -> modeResolers [ $ mode ] ) ) { $ this -> modeResolvers [ $ mode ] = $ this -> createModeResolver ( $ mode ) ; } return $ this -> modeResolvers [ $ mode ] ; } | Resolve a mode resolver class if it has not been resolved before |
43,314 | public function handleAction ( GridField $ gridField , $ actionName , $ arguments , $ data ) { if ( $ actionName == 'refresh' ) { return $ this -> handleRefresh ( $ gridField ) ; } } | Handle the refresh action . |
43,315 | public function handleRefresh ( ) { if ( $ this -> hasPendingJob ( ) ) { return ; } $ job = Injector :: inst ( ) -> create ( CheckForUpdatesJob :: class ) ; $ jobDescriptorId = $ this -> getQueuedJobService ( ) -> queueJob ( $ job , null , null , QueuedJob :: IMMEDIATE ) ; $ jobDescriptor = QueuedJobDescriptor :: get (... | Handle the refresh for both the action button and the URL |
43,316 | public function run ( $ request ) { $ memoryLimit = $ this -> config ( ) -> get ( 'memory_limit' ) ; if ( $ memoryLimit ) { if ( Environment :: getMemoryLimitMax ( ) < Convert :: memstring2bytes ( $ memoryLimit ) ) { Environment :: setMemoryLimitMax ( $ memoryLimit ) ; } Environment :: increaseMemoryLimitTo ( $ memoryL... | Update database cached information about this site . |
43,317 | public function getPackageInfo ( $ packageList ) { $ formatInfo = function ( $ package ) { $ package = get_object_vars ( $ package ) ; return array_combine ( array_map ( 'ucfirst' , array_keys ( $ package ) ) , $ package ) ; } ; $ packageList = array_map ( $ formatInfo , $ packageList ) ; $ this -> extend ( 'updatePack... | Fetch information about the installed packages . |
43,318 | public function getSupportedPackages ( ) { try { return $ this -> getSupportedAddonsLoader ( ) -> getAddonNames ( ) ? : [ ] ; } catch ( RuntimeException $ exception ) { echo $ exception -> getMessage ( ) . PHP_EOL ; } return null ; } | Return an array of supported modules as fetched from addons . silverstripe . org . Outputs a message and returns null if an error occurs |
43,319 | public function getHealthIndicator ( array $ moduleNames ) { try { return $ this -> getModuleHealthLoader ( ) -> setModuleNames ( $ moduleNames ) -> getModuleHealthInfo ( ) ? : [ ] ; } catch ( RuntimeException $ exception ) { echo $ exception -> getMessage ( ) . PHP_EOL ; } return null ; } | Return an array of module health information as fetched from addons . silverstripe . org . Outputs a message and returns null if an error occurs |
43,320 | public function initDatetimeObject ( $ datetimeOrTimestamp = null , $ inputTimezone = null , $ outputTimezone = null ) { if ( ! $ inputTimezone ) { $ inputTimezone = $ this -> serverTimezone ; } if ( ! $ outputTimezone ) { $ outputTimezone = $ this -> clientTimezone ; } if ( strlen ( $ datetimeOrTimestamp ) == 10 ) { $... | Init standard \ DateTime object configured to outputTimezone corresponding to inputTimezone |
43,321 | public function serverDate ( $ serverDatetimeOrTimestamp = null ) { return $ this -> format ( $ serverDatetimeOrTimestamp , self :: ISO_DATE_FORMAT , $ this -> serverTimezone ) ; } | Get date in YYYY - MM - DD format in server timezone |
43,322 | public function serverTime ( $ serverDatetimeOrTimestamp = null ) { return $ this -> format ( $ serverDatetimeOrTimestamp , self :: ISO_TIME_FORMAT , $ this -> serverTimezone ) ; } | Get date in HH - II - SS format in server timezone |
43,323 | protected function getTimezoneObject ( $ timezone ) { if ( ! isset ( $ this -> timezonesObjects [ $ timezone ] ) ) { $ this -> timezonesObjects [ $ timezone ] = new \ DateTimezone ( $ timezone ) ; } return $ this -> timezonesObjects [ $ timezone ] ; } | Get Datetimezone object by timezone name |
43,324 | public function build ( ) { $ basePath = $ this -> getBasePath ( ) ; $ composerJson = file_get_contents ( $ basePath . '/composer.json' ) ; $ composerLock = file_get_contents ( $ basePath . '/composer.lock' ) ; if ( ! $ composerJson || ! $ composerLock ) { throw new Exception ( 'composer.json or composer.lock could not... | Load and build the composer . json and composer . lock files |
43,325 | public function removeFilterOption ( $ name ) { $ this -> filterOptions -> remove ( $ this -> filterOptions -> find ( 'name' , $ name ) ) ; return $ this ; } | Remove a filter option with the given name |
43,326 | public static function setProperty ( & $ objectOrArray , $ property , $ value ) { if ( $ objectOrArray instanceof EloquentModel ) { if ( $ property ) { if ( $ objectOrArray -> relationLoaded ( $ property ) && ! Utility :: isPrimitive ( $ value ) ) { $ objectOrArray -> setRelation ( $ property , $ value ) ; } else { uns... | Set a property of an Eloquent model normal object or array |
43,327 | public function resolve ( $ property , & $ object , & $ root , $ fullPropertyPath ) { if ( is_array ( $ object ) ) { $ arrayCopy = $ object ; $ firstElement = array_shift ( $ arrayCopy ) ; if ( Utility :: isPrimitive ( $ firstElement ) ) { return ( int ) Utility :: getProperty ( $ object , 'id' ) ; } return array_map (... | Map through the collection and convert it to a collection of ids |
43,328 | public function getReportField ( ) { Requirements :: css ( 'bringyourownideas/silverstripe-maintenance: client/dist/styles/bundle.css' ) ; Requirements :: javascript ( 'bringyourownideas/silverstripe-maintenance: client/dist/js/bundle.js' ) ; $ grid = parent :: getReportField ( ) ; $ config = $ grid -> getConfig ( ) ; ... | Add a button row including link out to the SilverStripe addons repository and export button |
43,329 | protected function getDropdownFilter ( ) { $ dropdownFilter = Injector :: inst ( ) -> create ( GridFieldDropdownFilter :: class , 'addonFilter' , 'buttons-before-right' , _t ( __CLASS__ . '.ShowAllModules' , 'Show all modules' ) ) ; $ dropdownFilter -> addFilterOption ( 'supported' , _t ( __CLASS__ . '.FilterSupported'... | Returns a dropdown filter with user configurable options in it |
43,330 | protected function getInfoLink ( ) { return Injector :: inst ( ) -> create ( GridFieldHtmlFragment :: class , 'buttons-before-right' , DBField :: create_field ( 'HTMLFragment' , ArrayData :: create ( [ 'Link' => 'https://addons.silverstripe.org/add-ons/bringyourownideas/silverstripe-maintenance' , 'Label' => _t ( __CLA... | Returns a link to more information on this module on the addons site |
43,331 | protected function resolveCmsVersion ( ) { $ versionModules = [ 'silverstripe/framework' => 'Framework' , 'silverstripe/cms' => 'CMS' , ] ; $ this -> extend ( 'updateVersionModules' , $ versionModules ) ; $ records = $ this -> sourceRecords ( ) -> filter ( 'Name' , array_keys ( $ versionModules ) ) ; $ versionParts = [... | Extract CMS and Framework version details from the records in the report |
43,332 | public function getLastUpdated ( ) { $ packages = Package :: get ( ) -> limit ( 1 ) ; if ( ! $ packages -> count ( ) ) { return '' ; } $ datetime = $ packages -> first ( ) -> dbObject ( 'LastEdited' ) ; return $ datetime -> Date ( ) . ' ' . $ datetime -> Time12 ( ) ; } | Get the last updated date for the report . This is based on the modified date of any of the records since they are regenerated when the report is generated . |
43,333 | public function resolve ( $ property , & $ object , & $ root , $ fullPropertyPath ) { $ this -> addCollectionToRoot ( $ root , $ object , $ fullPropertyPath ) ; return $ this -> idsResolver -> resolve ( $ property , $ object , $ root , $ fullPropertyPath ) ; } | Move all relational resources to the root element and use idsResolver to replace them with a collection of identifiers |
43,334 | private function addCollectionToRoot ( & $ root , & $ object , $ fullPropertyPath ) { $ isResource = false ; if ( is_array ( $ object ) ) { $ copy = $ object ; $ values = array_values ( $ copy ) ; $ firstPropertyOrResource = array_shift ( $ values ) ; if ( Utility :: isPrimitive ( $ firstPropertyOrResource ) ) { $ isRe... | Add the collection to the root array |
43,335 | public function getDataSchema ( ) { $ schema = [ 'description' => $ this -> Description , 'link' => 'https://addons.silverstripe.org/add-ons/' . $ this -> Name , 'linkTitle' => _t ( __CLASS__ . '.ADDONS_LINK_TITLE' , 'View {package} on addons.silverstripe.org' , [ 'package' => $ this -> Title ] ) , 'rating' => ( int ) ... | Returns a JSON data schema for the frontend React components to use |
43,336 | public function requireDefaultRecords ( ) { parent :: requireDefaultRecords ( ) ; $ pendingJobs = QueuedJobDescriptor :: get ( ) -> filter ( [ 'Implementation' => CheckForUpdatesJob :: class , 'JobStatus' => [ QueuedJob :: STATUS_NEW , QueuedJob :: STATUS_INIT , QueuedJob :: STATUS_RUN , ] , ] ) ; if ( $ pendingJobs ->... | Queue up a job to check for updates to packages if there isn t a pending job in the queue already |
43,337 | public function getBundeled ( ) : array { $ directory = MODULARITY_PATH . 'source/php/Module/' ; $ bundeled = array ( ) ; foreach ( @ glob ( $ directory . "*" , GLOB_ONLYDIR ) as $ folder ) { $ bundeled [ $ folder ] = basename ( $ folder ) ; } return $ bundeled ; } | Gets bundeled modules |
43,338 | public static function prefixSlug ( string $ slug ) : string { if ( substr ( $ slug , 0 , strlen ( self :: MODULE_PREFIX ) ) !== self :: MODULE_PREFIX ) { $ slug = self :: MODULE_PREFIX . $ slug ; } if ( strlen ( $ slug ) > 20 ) { $ slug = substr ( $ slug , 0 , 20 ) ; } $ slug = strtolower ( $ slug ) ; return $ slug ; ... | Prefixes module post type slug if needed |
43,339 | public function getIcon ( string $ path , $ class ) : string { if ( file_exists ( $ path . '/assets/icon.svg' ) ) { return file_get_contents ( $ path . '/assets/icon.svg' ) ; } if ( file_exists ( $ path . preg_replace ( '/\s+/' , '' , ucwords ( $ class -> nameSingular ) ) . '/assets/icon.svg' ) ) { return file_get_cont... | Get bundeled icon |
43,340 | public function hideTitleCheckbox ( ) { global $ post ; if ( substr ( $ post -> post_type , 0 , 4 ) != 'mod-' ) { return ; } $ current = self :: $ moduleSettings [ $ post -> post_type ] [ 'hide_title' ] ; if ( strlen ( get_post_meta ( $ post -> ID , 'modularity-module-hide-title' , true ) ) > 0 ) { $ current = boolval ... | Adds checkbox to post edit page to hide title |
43,341 | public function saveHideTitleCheckbox ( $ postId , $ post ) { if ( substr ( $ post -> post_type , 0 , 4 ) != 'mod-' ) { return ; } if ( ! isset ( $ _POST [ 'modularity-module-hide-title' ] ) ) { update_post_meta ( $ post -> ID , 'modularity-module-hide-title' , 0 ) ; return ; } update_post_meta ( $ post -> ID , 'modula... | Saves the hide title checkboc |
43,342 | public function whereUsedMetaBox ( ) { if ( empty ( self :: $ enabled ) ) { return ; } global $ post ; $ module = $ this ; if ( is_null ( $ post ) ) { return ; } $ usage = self :: getModuleUsage ( $ post -> ID ) ; add_meta_box ( 'modularity-usage' , 'Module usage' , function ( ) use ( $ module , $ usage ) { if ( count ... | Metabox that shows where the module is used |
43,343 | public static function getModuleUsage ( $ id , $ limit = false ) { global $ wpdb ; $ query = " SELECT {$wpdb->postmeta}.post_id, {$wpdb->posts}.post_title, {$wpdb->posts}.post_type FROM {$wpdb->postmeta} LEFT JOIN {$wpdb->posts... | Search database for where the module is used |
43,344 | public function descriptionMetabox ( ) { if ( empty ( self :: $ enabled ) ) { return ; } add_meta_box ( 'modularity-description' , __ ( 'Module description' , 'modularity' ) , function ( ) { $ description = get_post_meta ( get_the_id ( ) , 'module-description' , true ) ; include MODULARITY_TEMPLATE_PATH . 'editor/modul... | Description metabox content |
43,345 | public function setupListTableField ( $ slug ) { add_filter ( 'manage_edit-' . $ slug . '_columns' , array ( $ this , 'listTableColumns' ) ) ; add_action ( 'manage_' . $ slug . '_posts_custom_column' , array ( $ this , 'listTableColumnContent' ) , 10 , 2 ) ; add_filter ( 'manage_edit-' . $ slug . '_sortable_columns' , ... | Setup list table fields |
43,346 | public function listTableColumnContent ( $ column , $ postId ) { switch ( $ column ) { case 'description' : $ description = get_post_meta ( $ postId , 'module-description' , true ) ; echo ! empty ( $ description ) ? $ description : '' ; break ; case 'usage' : $ usage = self :: getModuleUsage ( $ postId , 3 ) ; if ( cou... | List table column content |
43,347 | public function getFeedContents ( $ rss , $ items = 10 , $ order = '' ) : array { $ entries = array ( ) ; if ( ! empty ( $ rss ) ) { $ rss = fetch_feed ( $ rss ) ; } else { $ entries [ 'error' ] = __ ( 'RSS feed URL is missing' , 'modularity' ) ; return $ entries ; } if ( is_wp_error ( $ rss ) ) { if ( is_admin ( ) || ... | Returns the RSS entries |
43,348 | public static function getRssAuthor ( $ author ) { if ( is_object ( $ author ) ) { $ author = $ author -> get_name ( ) ; $ author = esc_html ( strip_tags ( $ author ) ) ; } else { $ author = '' ; } return $ author ; } | Sanitize author name |
43,349 | public static function getRssSummary ( $ summary = '' ) { $ summary = @ html_entity_decode ( $ summary , ENT_QUOTES , get_option ( 'blog_charset' ) ) ; $ summary = esc_attr ( wp_trim_words ( $ summary , 50 , ' […]' ) ) ; if ( '[...]' == substr ( $ summary , - 5 ) ) { $ summary = substr ( $ summary , 0 , - 5 ) . ... | Sanitize and trim summary |
43,350 | public static function getTemplate ( $ prefix = '' , $ slug = '' , $ error = true ) { $ paths = apply_filters ( 'Modularity/Module/TemplatePath' , array ( get_stylesheet_directory ( ) . '/templates/' , get_template_directory ( ) . '/templates/' , MODULARITY_PATH . 'templates/' , ) ) ; $ slug = apply_filters ( 'Modulari... | Tries to get the template path Checks the plugin s template folder the parent theme s templates folder and the current theme s template folder |
43,351 | public static function isThickBox ( ) { $ referer = ( isset ( $ _SERVER [ 'HTTP_REFERER' ] ) ) ? $ _SERVER [ 'HTTP_REFERER' ] : null ; if ( ( isset ( $ _GET [ 'is_thickbox' ] ) && $ _GET [ 'is_thickbox' ] == 'true' ) || strpos ( $ referer , 'is_thickbox=true' ) > - 1 ) { return true ; } else { return false ; } } | Check if the add question form is opened in thickbox iframe |
43,352 | public static function getArchiveSlug ( ) { global $ wp_query ; if ( $ wp_query && ! is_tax ( ) && ( is_post_type_archive ( ) || is_archive ( ) || is_home ( ) || is_search ( ) || is_404 ( ) ) ) { $ postType = get_post_type ( ) ; if ( isset ( $ wp_query -> query_vars [ 'post_type' ] ) && ! empty ( $ wp_query -> query_va... | Fetches current archive slug |
43,353 | public function isModularityPage ( ) { global $ current_screen ; $ result = true ; if ( strpos ( $ current_screen -> id , 'modularity' ) === false && strpos ( $ current_screen -> id , 'mod-' ) === false && ( $ current_screen -> action != 'add' && ( isset ( $ _GET [ 'action' ] ) && $ _GET [ 'action' ] != 'edit' ) ) && $... | Check if current page is a modularity page |
43,354 | public function acfLocationSelect ( $ title , $ post , $ field , $ post_id ) { $ address = get_permalink ( $ post -> ID , false ) ; if ( ! empty ( $ address ) ) { $ title .= '<br/><span class="inlay-list-url-helper"> ( ' . str_replace ( home_url ( ) , "" , $ address ) . ' ) </span>' ; } return $ title ; } | Adding address to Location select box |
43,355 | public function output ( ) { if ( ! $ this -> shouldOutput ( ) ) { return false ; } echo '<h2 class="modularity-nav-tab-wrapper" id="modularity-tabs">' ; $ requestUri = str_replace ( '&message=1' , '' , $ _SERVER [ 'REQUEST_URI' ] ) ; foreach ( $ this -> tabs as $ tab => $ url ) { if ( strpos ( $ url , $ requestUri ) !... | Outputs the tabbar html |
43,356 | protected function shouldOutput ( ) { global $ current_screen ; $ options = get_option ( 'modularity-options' ) ; $ enabled = isset ( $ options [ 'enabled-post-types' ] ) && is_array ( $ options [ 'enabled-post-types' ] ) ? $ options [ 'enabled-post-types' ] : array ( ) ; $ validPostType = in_array ( $ current_screen -... | Check if tabs should be outputted |
43,357 | public function avoidDuplicatePostName ( $ data , $ postarr ) { if ( ! isset ( $ data [ 'post_type' ] ) || ( isset ( $ data [ 'post_type' ] ) && substr ( $ data [ 'post_type' ] , 0 , 4 ) != 'mod-' ) ) { return $ data ; } $ data [ 'post_name' ] = $ data [ 'post_type' ] . '_' . uniqid ( ) . '_' . sanitize_title ( $ data ... | Avoid duplicate post_name in db |
43,358 | public function adminBar ( ) { if ( isset ( $ _GET [ 'id' ] ) ) { if ( is_numeric ( $ _GET [ 'id' ] ) && $ _GET [ 'id' ] > 0 ) { $ post = get_post ( $ _GET [ 'id' ] ) ; if ( ! $ post ) { return ; } setup_postdata ( $ post ) ; add_action ( 'admin_bar_menu' , function ( ) use ( $ post ) { global $ wp_admin_bar ; $ wp_adm... | Handle admin bar stuff |
43,359 | public function registerTabs ( ) { global $ post ; if ( ! $ post && ! isset ( $ _GET [ 'page_for' ] ) ) { return ; } if ( ! $ post && isset ( $ _GET [ 'page_for' ] ) && ! empty ( $ _GET [ 'page_for' ] ) ) { $ post = get_post ( $ _GET [ 'page_for' ] ) ; } $ modulesEditorId = false ; if ( $ post ) { $ modulesEditorId = $... | Registers navigation tabs |
43,360 | public function registerEditorPage ( ) { $ this -> register ( $ pageTitle = __ ( 'Modularity editor' ) , $ menuTitle = __ ( 'Editor' ) , $ capability = 'edit_posts' , $ menuSlug = 'modularity-editor' , $ iconUrl = null , $ position = 1 , $ parent = 'options.php' ) ; } | Register an option page for the editor |
43,361 | public function addMetaBoxes ( ) { add_meta_box ( 'modularity-mb-editor-publish' , __ ( 'Save modules' , 'modularity' ) , function ( ) { include MODULARITY_TEMPLATE_PATH . 'editor/modularity-publish.php' ; } , $ this -> screenHook , 'side' ) ; add_meta_box ( 'modularity-mb-modules' , __ ( 'Enabled modules' , 'modularit... | Adds meta boxes to the options page |
43,362 | public function addSidebarsMetaBoxes ( ) { global $ wp_registered_sidebars ; $ template = \ Modularity \ Helper \ Post :: getPostTemplate ( ) ; $ sidebars = null ; $ activeAreas = $ this -> getActiveAreas ( $ template ) ; if ( is_array ( $ activeAreas ) && count ( $ activeAreas ) === 0 ) { add_meta_box ( 'no-sidebars' ... | Loops registered sidebars and creates metaboxes for them |
43,363 | public function metaBoxSidebar ( $ post , $ args ) { global $ post ; $ options = null ; if ( \ Modularity \ Helper \ Post :: isArchive ( ) ) { global $ archive ; $ options = get_option ( 'modularity_' . $ archive . '_sidebar-options' ) ; } else { if ( $ post ) { $ options = get_post_meta ( $ post -> ID , 'modularity-si... | The content for sidebar metabox |
43,364 | public static function getPostModules ( $ postId ) { $ modules = array ( ) ; $ retModules = array ( ) ; $ postId = self :: pageForPostTypeTranscribe ( $ postId ) ; $ available = \ Modularity \ ModuleManager :: $ available ; $ enabled = \ Modularity \ ModuleManager :: $ enabled ; $ moduleIds = array ( ) ; $ moduleSideba... | Get modules added to a specific post |
43,365 | public function save ( ) { if ( ! $ this -> isValidPostSave ( ) ) { return ; } if ( ! isset ( $ _REQUEST [ 'id' ] ) || empty ( $ _REQUEST [ 'id' ] ) ) { return trigger_error ( 'Invalid post id. Please contact system administrator.' ) ; } $ this -> savePost ( ) ; if ( defined ( 'DOING_AJAX' ) && DOING_AJAX ) { echo "suc... | Saves the selected modules |
43,366 | public function savePost ( ) { $ key = $ _REQUEST [ 'id' ] ; if ( is_numeric ( $ key ) ) { return $ this -> saveAsPostMeta ( $ key ) ; } if ( \ Modularity \ Helper \ Post :: isArchive ( ) ) { global $ archive ; $ key = $ archive ; } return $ this -> saveAsOption ( $ key ) ; } | Saves post modules |
43,367 | public function saveAsOption ( $ key ) { $ key = 'modularity_' . $ key ; $ optionName = $ key . '_modules' ; if ( isset ( $ _POST [ 'modularity_modules' ] ) ) { $ data = $ this -> sanitizeModuleData ( $ _POST [ 'modularity_modules' ] ) ; if ( get_option ( $ optionName ) ) { update_option ( $ optionName , $ data ) ; } e... | Saves archive modules |
43,368 | public function getWidthOptions ( ) { $ markup = '<option value="">' . __ ( 'Inherit' , 'modularity' ) . '</option>' . "\n" ; foreach ( self :: widthOptions ( ) as $ key => $ value ) { $ markup .= '<option value="' . $ key . '">' . $ value . '</option>' . "\n" ; } return $ markup ; } | Get column width options |
43,369 | public function registerScopeMetaBox ( $ postType , $ choises ) { if ( ! is_string ( $ postType ) ) { return WP_Error ( "Post type variable must be of the type string." ) ; } if ( ! is_array ( $ choises ) ) { return WP_Error ( "Choises variable must be of the type assoc array." ) ; } if ( ! function_exists ( 'acf_add_l... | Registers a scope metabox |
43,370 | public function sanitizeModuleData ( $ sidebars ) { foreach ( $ sidebars as & $ sidebar ) { if ( ! empty ( $ sidebar ) && is_array ( $ sidebar ) ) { foreach ( $ sidebar as & $ module ) { $ module [ 'hidden' ] = isset ( $ module [ 'hidden' ] ) && $ module [ 'hidden' ] == 'hidden' ; } } } return $ sidebars ; } | Sanitize module data |
43,371 | private function post_type_options ( ) { $ args = array ( 'public' => true ) ; $ post_types = get_post_types ( $ args , 'objects' ) ; $ output = array ( ) ; foreach ( $ post_types as $ post_type ) { $ output [ ] = array ( 'value' => $ post_type -> name , 'label' => $ post_type -> label ) ; } return $ output ; } | Outputs Post Types in HTML option tags |
43,372 | public function widget ( $ args , $ instance ) { if ( ! isset ( $ instance [ 'module_id' ] ) || ! is_numeric ( $ instance [ 'module_id' ] ) ) { return false ; } $ display = \ Modularity \ App :: $ display ; $ columnWidth = ( isset ( $ instance [ 'module_size' ] ) ) ? $ instance [ 'module_size' ] : 'grid-md-4' ; if ( is... | Outputs the widget content |
43,373 | public static function getArchiveTemplateSlugs ( ) { $ archives = get_post_types ( array ( 'has_archive' => true ) , 'names' ) ; $ templates = array ( ) ; foreach ( $ archives as $ archive ) { $ template = \ Modularity \ Helper \ Wp :: findCoreTemplates ( array ( 'archive-' . $ archive ) ) ; if ( $ template ) { $ templ... | Get list of currently available archives slugs that has a template |
43,374 | public static function getNamespace ( string $ path ) : string { $ source = file_get_contents ( $ path ) ; if ( $ source === false ) { add_action ( 'admin_notices' , function ( ) use ( $ path ) { $ malfunctionalPlugin = array_pop ( get_plugins ( "/" . explode ( '/' , plugin_basename ( $ path ) ) [ 0 ] ) ) ; printf ( '<... | Get PHP namespace from file |
43,375 | public function isActiveSidebar ( $ isActiveSidebar , $ sidebar ) { $ widgets = wp_get_sidebars_widgets ( ) ; $ widgets = array_map ( 'array_filter' , $ widgets ) ; $ visibleModules = false ; if ( isset ( $ this -> modules [ $ sidebar ] ) && count ( $ this -> modules [ $ sidebar ] ) > 0 ) { foreach ( $ this -> modules ... | New is_active_sidebar logic which includes module check |
43,376 | public function outputBefore ( $ sidebar ) { if ( ! isset ( $ this -> options [ $ sidebar ] [ 'hook' ] ) || $ this -> options [ $ sidebar ] [ 'hook' ] != 'before' ) { return false ; } $ this -> output ( $ sidebar ) ; } | Check if modules should be outputted before widgets |
43,377 | public function outputAfter ( $ sidebar ) { if ( isset ( $ this -> options [ $ sidebar ] [ 'hook' ] ) && $ this -> options [ $ sidebar ] [ 'hook' ] != 'after' ) { return false ; } $ this -> output ( $ sidebar ) ; } | Check if modules should be outputted after widgets |
43,378 | public function output ( $ sidebar ) { if ( ! isset ( $ this -> modules [ $ sidebar ] ) || ! $ this -> isModularitySidebarActive ( $ sidebar ) ) { return ; } $ modules = $ this -> modules [ $ sidebar ] ; $ sidebarArgs = $ this -> getSidebarArgs ( $ sidebar ) ; foreach ( $ modules [ 'modules' ] as $ module ) { if ( ! is... | Outputs the modules of a specific sidebar |
43,379 | public function fillMissingParams ( $ module , $ moduleSettings ) { if ( empty ( $ module -> slug ) ) { foreach ( $ moduleSettings as $ key => $ value ) { $ module -> $ key = $ value ; } $ module -> isLegacy = true ; } return $ module ; } | Fills module object with missing params if needed |
43,380 | public function outputModule ( $ module , $ args = array ( ) , $ moduleSettings = array ( ) , $ echo = true ) { if ( ! isset ( $ args [ 'id' ] ) ) { $ args [ 'id' ] = 'no-id' ; } if ( ! is_object ( $ module ) ) { return false ; } $ class = \ Modularity \ ModuleManager :: $ classes [ $ module -> post_type ] ; $ module =... | Outputs a specific module |
43,381 | public function shortcodeDisplay ( $ args ) { $ args = shortcode_atts ( array ( 'id' => false , 'inline' => true ) , $ args ) ; if ( ! is_numeric ( $ args [ 'id' ] ) ) { return ; } $ module = \ Modularity \ Editor :: getModule ( $ args [ 'id' ] ) ; if ( ! is_object ( $ module ) || empty ( $ module -> post_type ) ) { re... | Display module with shortcode |
43,382 | public function filterNestedModuleShortocde ( $ post ) { if ( is_admin ( ) ) { return $ post ; } if ( substr ( $ post -> post_type , 0 , 4 ) != 'mod-' ) { return $ post ; } $ post -> post_content = preg_replace ( '/\[modularity(.*)\]/' , '' , $ post -> post_content ) ; return $ post ; } | Removes nested shortcodes |
43,383 | public function addGridToSidebar ( $ markup , $ module ) { $ sidebars = apply_filters ( 'Modularity/Module/Container/Sidebars' , array ( ) ) ; $ modules = apply_filters ( 'Modularity/Module/Container/Modules' , array ( ) ) ; $ template = apply_filters ( 'Modularity/Module/Container/Template' , '<div class="container"><... | Add container grid to specified modules in specified sidebars |
43,384 | public function getRenderedPostModules ( $ post ) { if ( ! $ post ) { return ; } if ( is_array ( $ post ) ) { $ postId = $ post [ 'ID' ] ; } else { $ postId = $ post -> ID ; } $ modules = \ Modularity \ Editor :: getPostModules ( $ postId ) ; $ onlyModules = array ( ) ; foreach ( $ modules as $ sidebar => $ item ) { if... | Render all modules on post |
43,385 | public function addAlgoliaModuleAttribute ( $ attributes , $ post ) { $ rendered = strip_tags ( $ this -> getRenderedPostModules ( $ post ) ) ; if ( ! empty ( $ rendered ) ) { $ attributes [ 'modules' ] = substr ( $ rendered , 0 , 7000 ) ; } return $ attributes ; } | Add a attribute to algolia search |
43,386 | public function moduleSearchModuleDescription ( $ search ) { global $ wpdb ; if ( $ this -> isModuleSearch ( ) ) { $ like = '%' . $ wpdb -> esc_like ( $ _GET [ 's' ] ) . '%' ; $ meta_description = $ wpdb -> prepare ( "OR ({$wpdb->postmeta}.meta_value LIKE %s)" , $ like ) ; $ search = str_replace ( 'OR' , $ meta_descrip... | Adds the OR condition to search the module description on module edit pages . |
43,387 | public function isModuleSearch ( ) { global $ pagenow ; if ( $ pagenow == 'edit.php' && isset ( $ _GET [ 's' ] ) && $ _GET [ 's' ] !== '' ) { $ enabled = \ Modularity \ ModuleManager :: $ enabled ; if ( in_array ( $ _GET [ 'post_type' ] , $ enabled ) ) { return true ; } } return false ; } | Helper method to determine if a module search is performed on a module edit page . |
43,388 | public function appendToArray ( array $ array , $ key , array $ new ) { $ keys = array_keys ( $ array ) ; $ index = array_search ( $ key , $ keys ) ; $ pos = false === $ index ? count ( $ array ) : $ index + 1 ; return array_merge ( array_slice ( $ array , 0 , $ pos ) , $ new , array_slice ( $ array , $ pos ) ) ; } | Appends items to array after specific key |
43,389 | public function createCacheKey ( $ type , $ url , $ data = null , $ contentType = 'json' , $ headers = null ) { $ this -> cacheKey = "curl_cache_" . md5 ( $ type . $ url . ( is_array ( $ data ) ? implode ( $ data , "" ) : $ data ) . $ contentType . ( is_array ( $ headers ) ? implode ( $ headers , "" ) : $ headers ) ) ;... | Create Cache key |
43,390 | public function prepareItems ( $ items ) { if ( is_array ( $ items ) && ! empty ( $ items ) ) { foreach ( $ items as $ key => & $ item ) { $ postData = is_object ( $ item [ 'page' ] ) ? $ item [ 'page' ] : false ; if ( $ item [ 'link_type' ] == 'external' ) { $ item [ 'permalink' ] = $ item [ 'link_url' ] ; } elseif ( ... | Get additional data for index posts |
43,391 | public function parseExcerpt ( $ postContent ) { if ( strpos ( $ postContent , "<!--more ) ) { return strip_tags ( substr ( $ postContent , 0 , strpos ( $ postContent , "<!--more ) ) ) ; } return wp_trim_words ( strip_tags ( apply_filters ( 'get_the_excerpt' , $ postContent ) ) , 55 , "…" ) ; } | Parse the excerpt from the content . |
43,392 | public function getThumbnail ( $ item ) { if ( $ item [ 'image_display' ] == 'custom' || $ item [ 'link_type' ] == 'external' ) { return wp_get_attachment_image_src ( $ item [ 'custom_image' ] [ 'ID' ] , apply_filters ( 'Modularity/index/image' , municipio_to_aspect_ratio ( '16:9' , $ this -> thumbnailSize ) , $ this -... | Get post thumbnail in correct size |
43,393 | public function getImageDimension ( $ columnClass ) { switch ( $ columnClass ) { case "grid-md-12" : $ this -> thumbnailSize = array ( 1200 , 900 ) ; return $ this -> thumbnailSize ; case "grid-md-6" : $ this -> thumbnailSize = array ( 800 , 600 ) ; return $ this -> thumbnailSize ; default : $ this -> thumbnailSize = a... | Get wanted image dimensions based on column class |
43,394 | public function postObjectQuery ( $ args , $ field , $ post_id ) { $ post_types = array ( 'post' , 'page' ) ; $ custom_post_types = get_field ( 'avabile_dynamic_post_types' , 'option' ) ; if ( is_array ( $ custom_post_types ) && ! empty ( $ custom_post_types ) ) { foreach ( $ custom_post_types as $ post_type ) { $ post... | Return results from certain post types |
43,395 | public function addJsVariables ( ) { global $ current_screen ; global $ post ; global $ archive ; $ id = isset ( $ post -> ID ) ? $ post -> ID : "'" . $ archive . "'" ; if ( substr ( $ current_screen -> post_type , 0 , 4 ) == 'mod-' && ( $ current_screen -> action == 'add' || $ current_screen -> action == '' ) ) { echo... | Adds required javascript variables to the thickbox page |
43,396 | public function enqueue ( ) { wp_register_script ( 'modularity-thickbox' , MODULARITY_URL . '/dist/js/modularity-editor-modal.' . \ Modularity \ App :: $ assetSuffix . '.js' , false , '1.0.0' , true ) ; wp_enqueue_script ( 'modularity-thickbox' ) ; wp_register_style ( 'modularity-thickbox' , MODULARITY_URL . '/dist/css... | Enqueue scripts and styles specific for the Thickbox content |
43,397 | public static function getPostTemplate ( $ id = null , $ trim = false ) { if ( $ archive = self :: isArchive ( ) ) { return $ archive ; } global $ post ; if ( ! $ post && isset ( $ _GET [ 'id' ] ) && is_numeric ( $ _GET [ 'id' ] ) ) { $ post = get_post ( $ _GET [ 'id' ] ) ; if ( ! $ post ) { throw new \ Error ( 'The re... | Gets the post template of the current editor page |
43,398 | public static function detectCoreTemplate ( $ post ) { if ( ( int ) get_option ( 'page_on_front' ) == ( int ) $ post -> ID ) { return \ Modularity \ Helper \ Wp :: findCoreTemplates ( array ( 'front-page' , 'page' ) ) ; } switch ( $ post -> post_type ) { case 'post' : return 'single' ; break ; case 'page' : return 'pag... | Detects core templates |
43,399 | public static function isArchive ( ) { global $ archive ; global $ post ; if ( defined ( 'DOING_AJAX' ) && DOING_AJAX ) { $ archive = ! is_numeric ( $ _POST [ 'id' ] ) ? $ _POST [ 'id' ] : '' ; } if ( substr ( $ archive , 0 , 8 ) == 'archive-' || is_search ( ) ) { return $ archive ; } if ( is_archive ( ) && ( is_object... | Verifies if the current page is an archive or search result page |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.