_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
33
8k
language
stringclasses
1 value
meta_information
dict
q200
Term.getOneWhere
train
public static function getOneWhere($args = array()) { $args['number'] = 1; $result = static::getWhere($args);
php
{ "resource": "" }
q201
Term.find
train
public static function find($term_id) { $instance = Post\Factory::create(get_called_class());
php
{ "resource": "" }
q202
Loader.loadAll
train
public static function loadAll() { global $taxonomies_infos; // Classes $subclasses = self::getSubclasses(); foreach ($subclasses as $class) { $instance = new $class; $taxonomies_infos = array_merge(
php
{ "resource": "" }
q203
Loader.load
train
public static function load($class) { $instance = new $class; $post_type = $instance->getPostType(); // WordPress has a limit of 20 characters per if (strlen($post_type) > 20) { throw new \Exception('Post Type name exceeds maximum 20 characters: '.$post_type); } // This might happen if you're introducing a middle class between your post type and TacoPost // Ex: Foo extends \ClientTacoPost extends Taco\Post if (!$post_type) { return false; } //add_action('init', array($instance, 'registerPostType')); $instance->registerPostType(); add_action('save_post', array($instance, 'addSaveHooks')); if (is_admin()) { // If we're in the edit screen, we want the post loaded // so that TacoPost::getFields knows which post it's working with. // This helps if you want TacoPost::getFields to use conditional logic // based on which post is currently being edited. $is_edit_screen = ( is_array($_SERVER) && preg_match('/post.php\?post=[\d]{1,}/i', $_SERVER['REQUEST_URI']) && !Arr::iterable($_POST) ); $is_edit_save = ( preg_match('/post.php/i', $_SERVER['REQUEST_URI']) && Arr::iterable($_POST) ); $post = null; if ($is_edit_screen && array_key_exists('post', $_GET)) { $post = get_post($_GET['post']); } elseif ($is_edit_save) { $post = get_post($_POST['post_ID']); } if ($post && $post->post_type === $instance->getPostType()) { $instance->load($post); } add_action('admin_menu', array($instance, 'addMetaBoxes')); add_action(sprintf('manage_%s_posts_columns', $post_type), array($instance, 'addAdminColumns'), 10, 2); add_action(sprintf('manage_%s_posts_custom_column', $post_type), array($instance,
php
{ "resource": "" }
q204
Loader.getSubclasses
train
public static function getSubclasses() { $subclasses = array(); foreach (get_declared_classes() as $class) { if (method_exists($class, 'isLoadable') && $class::isLoadable() === false) { continue; }
php
{ "resource": "" }
q205
Haversine.calculate
train
public function calculate(N\LatLong $point1, N\LatLong $point2) { $celestialBody = $this->getCelestialBody(); $deltaLat = $point2->getLatitude()->get() - $point1->getLatitude()->get(); $deltaLong = $point2->getLongitude()->get() - $point1->getLongitude()->get(); $a = sin($deltaLat / 2) * sin($deltaLat /
php
{ "resource": "" }
q206
Participant.update
train
public function update($params = []) { $response = Guzzle::put("tournaments/{$this->tournament_slug}/participants/{$this->id}",
php
{ "resource": "" }
q207
Transformer.transform
train
public function transform($object) { if (($collection = $this->normalize($object)) instanceof Collection) { return $this->transformCollection($collection); } // If there are relations setup, transform it along with the object. if ($this->relatedCount) { return $this->transformWithRelated($object); }
php
{ "resource": "" }
q208
Transformer.normalize
train
protected function normalize($object) { // If its a paginator instance, create a collection with its items. if ($object instanceof Paginator) { return collect($object->items()); } elseif (is_array($object)) {
php
{ "resource": "" }
q209
Transformer.transformWithRelated
train
public function transformWithRelated($item) { $transformedItem = $this->getTransformation($item);
php
{ "resource": "" }
q210
Transformer.with
train
public function with($relation) { $this->reset(); if (func_num_args() > 1) { return $this->with(func_get_args()); } if (is_array($relation)) { $this->related = array_merge($this->related, $relation); } else {
php
{ "resource": "" }
q211
Transformer.setTransformation
train
public function setTransformation($transformation) { if (is_callable($transformation)) { $this->transformationMethod = $transformation; return $this; } // replace just to avoid wrongly passing the name containing "Transformation". $methodName = str_replace('Transformation', '', $transformation) . "Transformation"; if (! method_exists($this, $methodName)) {
php
{ "resource": "" }
q212
Transformer.transformRelated
train
protected function transformRelated($itemTransformation, $item) { foreach ($this->related as $relation) { // get direct relation name. $relationName = explode('.', $relation, 2)[0];
php
{ "resource": "" }
q213
Transformer.getRelatedTransformation
train
protected function getRelatedTransformation($item, $relation) { // get nested relations separated by the dot notation. // we only get one relation at a time because recursion handles the remaining relations. $nestedRelations = explode('.', $relation, 2); $relation = $nestedRelations[0]; $result = $item->{$relation}; $related = $result; $transformer = null; if (! is_object($related)) { return $related; } // if its a collection switch the object to the first item. if ($related instanceof Collection) { if ($related->count()) { $result = $result[0]; } else { return []; } } $transformer = $this->resolveTransformer($result); // If no transformer was resolved.
php
{ "resource": "" }
q214
GreatCircle.calculate
train
public function calculate(N\LatLong $point1, N\LatLong $point2) { $celestialBody = $this->getCelestialBody(); $degrees = acos(sin($point1->getLatitude()->get()) * sin($point2->getLatitude()->get()) + cos($point1->getLatitude()->get()) * cos($point2->getLatitude()->get()) *
php
{ "resource": "" }
q215
Gravatar.image
train
public static function image($sEmail, $iSize = null, $sDefaultImage = null, $sRating = null, $sExtension = null, $bForceDefault = false) { $gravatarImage = (new Image()) ->setEmail($sEmail) ->setSize($iSize)
php
{ "resource": "" }
q216
Gravatar.images
train
public static function images(array $aEmail, $iSize = null, $sDefaultImage = null, $sRating = null, $sExtension = null, $bForceDefault = false) { $aImages = []; foreach ($aEmail as $sEmail) { $gravatarImage = (new Image()) ->setEmail($sEmail)
php
{ "resource": "" }
q217
Gravatar.profiles
train
public static function profiles(array $aEmail, $sFormat = null) { $aProfils = []; foreach ($aEmail as $sEmail) { $gravatarProfil = (new Profile()) ->setEmail($sEmail)
php
{ "resource": "" }
q218
Gravatar.email
train
public function email($sEmail = null) { if (null === $sEmail) { return $this->getEmail();
php
{ "resource": "" }
q219
Factory.create
train
public static function create($post, $load_terms = true) { // Ex: Taco\Post\Factory::create('Video') if (is_string($post) && class_exists($post)) { return new $post; } $original_post = $post; if (!is_object($post)) { $post = get_post($post); } if (!is_object($post)) { throw new \Exception(sprintf('Post %s not
php
{ "resource": "" }
q220
Factory.createMultiple
train
public static function createMultiple($posts, $load_terms = true) { if (!Arr::iterable($posts)) { return $posts; } $out = array(); foreach ($posts as $k => $post) { if (!get_post_status($post)) {
php
{ "resource": "" }
q221
Dm_Image.draw
train
public function draw(Dm_Image $image,$x=0,$y=0,$width=null,$height=null) { $srcImageResource = $image->getImageResource(); if (is_null($width)) $width = $image->getWidth(); if (is_null($height)) $height
php
{ "resource": "" }
q222
Dm_Image.saveTo
train
public function saveTo($path , $type='png', $quality=null) { if (!$path) return false;
php
{ "resource": "" }
q223
Dm_Image.destroy
train
public function destroy() { imagedestroy($this->_imageResource); $this->graphics->destroy();
php
{ "resource": "" }
q224
Dm_Image.toDataSchemeURI
train
public function toDataSchemeURI() { $md5 = md5(microtime(1).rand(10000, 99999)); $filePath = $this->tempDirPath() . DIRECTORY_SEPARATOR . "temp".$md5.".png";
php
{ "resource": "" }
q225
Server.serve
train
public function serve($salt = '') { $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; if ($input = $this->findInput()) { $output = $this->cacheName($salt . $input); $etag = $noneMatch = trim($this->getIfNoneMatchHeader(), '"'); if ($this->needsCompile($output, $etag)) { try { list($css, $etag) = $this->compile($input, $output); $lastModified = gmdate('D, d M Y H:i:s', filemtime($output)) . ' GMT'; header('Last-Modified: ' . $lastModified); header('Content-type: text/css'); header('ETag: "' . $etag . '"'); echo $css; } catch (\Exception $e) { if ($this->showErrorsAsCSS) { header('Content-type: text/css'); echo $this->createErrorCSS($e); } else { header($protocol . ' 500 Internal Server Error'); header('Content-type: text/plain'); echo 'Parse error: ' . $e->getMessage() . "\n"; } } return; } header('X-SCSS-Cache: true'); header('Content-type: text/css'); header('ETag: "' . $etag . '"'); if ($etag === $noneMatch) {
php
{ "resource": "" }
q226
Base.getPrefixGroupedMetaBoxes
train
public function getPrefixGroupedMetaBoxes() { $fields = $this->getFields(); // Just group by the field key prefix // Ex: home_foo would go in the Home section by default $groups = array(); foreach ($fields as $k => $field) { $prefix = current(explode('_', $k));
php
{ "resource": "" }
q227
Base.replaceMetaBoxGroupMatches
train
public function replaceMetaBoxGroupMatches($meta_boxes) { if (!Arr::iterable($meta_boxes)) { return $meta_boxes; } foreach ($meta_boxes as $k => $group) { $group = (is_array($group)) ? $group : array($group); if (array_key_exists('fields', $group)) { continue; } $fields = $this->getFields(); $new_group = array(); foreach ($group as $pattern_key => $pattern) { if (!preg_match('/\*$/', $pattern)) { $new_group[] = $pattern; continue; } $prefix = preg_replace('/\*$/', '', $pattern); $regex = sprintf('/^%s/', $prefix);
php
{ "resource": "" }
q228
Base.getMetaBoxConfig
train
public function getMetaBoxConfig($config, $key = null) { // allow shorthand if (!array_key_exists('fields', $config)) { $fields = array(); foreach ($config as $field) { // Arbitrary HTML is allowed if (preg_match('/^\</', $field) && preg_match('/\>$/', $field)) { $fields[md5(mt_rand())] = array( 'type'=>'html', 'label'=>null, 'value'=>$field, ); continue; } $fields[$field] = $this->getField($field); } $config = array('fields'=>$fields); } if (Arr::iterable($config['fields'])) { $fields = array(); foreach ($config['fields'] as $k => $v) { if (is_array($v)) { $fields[$k] = $v;
php
{ "resource": "" }
q229
Base.assign
train
public function assign($vals) { if (count($vals) === 0) { return 0; }
php
{ "resource": "" }
q230
Base.isValid
train
public function isValid($vals) { $fields = $this->getFields(); if (!Arr::iterable($fields)) { return true; } $result = true; // validate each field foreach ($fields as $k => $field) { // check if required if ($this->isRequired($field)) { if (!array_key_exists($k, $vals) || is_null($vals[$k]) || $vals[$k] === '' || $vals[$k] === false || ($field['type'] === 'checkbox' && empty($vals[$k])) ) { $result = false; $this->_messages[$k] = $this->getFieldRequiredMessage($k); continue; } } // check maxlength if (array_key_exists('maxlength', $field)) { if (strlen($vals[$k]) > $field['maxlength']) { $result = false; $this->_messages[$k] = 'Value too long'; continue; } } // after this point, we're only checking values based on type if (!array_key_exists($k, $vals)) { continue; } if (!array_key_exists('type', $field)) { continue; } // Select if ($field['type'] === 'select') { if (!array_key_exists($vals[$k], $field['options'])) { $result = false; $this->_messages[$k] = 'Invalid option'; } continue;
php
{ "resource": "" }
q231
Base.getMetaBoxTitle
train
public function getMetaBoxTitle($key = null) { return ($key) ? Str::human($key) :
php
{ "resource": "" }
q232
Base.scrubAttributes
train
private static function scrubAttributes($field, $type = null) { $invalid_keys = [ 'default', 'description', 'label', 'options', ]; if ($type && $type ==='textarea') { $invalid_keys[] = 'value';
php
{ "resource": "" }
q233
Base.getCheckboxDisplay
train
public function getCheckboxDisplay($column_name) { $displays = $this->getCheckboxDisplays(); if (array_key_exists($column_name, $displays)) {
php
{ "resource": "" }
q234
Base.renderAdminColumn
train
public function renderAdminColumn($column_name, $item_id) { $columns = $this->getAdminColumns(); if (!in_array($column_name, $columns)) { return; } $field = $this->getField($column_name); if (is_array($field)) { $class = get_called_class(); $entry = new $class; $entry->load($item_id); $out = $entry->get($column_name); if (isset($field['type'])) { switch ($field['type']) { case 'checkbox': $checkbox_display = $entry->getCheckboxDisplay($column_name); $out = ($entry->get($column_name)) ? reset($checkbox_display) : end($checkbox_display); break; case 'image': $out = Html::image($entry->get($column_name), $entry->get($column_name), array('class'=>'thumbnail'));
php
{ "resource": "" }
q235
Base.makeAdminColumnsSortable
train
public function makeAdminColumnsSortable($columns) { $admin_columns = $this->getAdminColumns(); if (!Arr::iterable($admin_columns)) {
php
{ "resource": "" }
q236
Base.getPlural
train
public function getPlural() { $singular = $this->getSingular(); if (preg_match('/y$/', $singular)) {
php
{ "resource": "" }
q237
Base.getThe
train
public function getThe($key, $convert_value = false, $return_wrapped = true) { if ($return_wrapped) { return apply_filters('the_content', $this->get($key, $convert_value)); } // Apply the_content filter without wrapping lines in <p> tags
php
{ "resource": "" }
q238
Base.getLabelText
train
public function getLabelText($field_key) { $field = $this->getField($field_key); if (!is_array($field)) { return null; } return (array_key_exists('label', $field))
php
{ "resource": "" }
q239
Base.getRenderLabel
train
public function getRenderLabel($field_key, $required_mark = ' <span class="required">*</span>') { return sprintf( '<label for="%s">%s%s</label>', $field_key,
php
{ "resource": "" }
q240
Base.isRequired
train
public function isRequired($field_key) { $field = (is_array($field_key)) ? $field_key : $this->getField($field_key);
php
{ "resource": "" }
q241
DmsParser.parse
train
public function parse($coord) { $coordinate = null; $matches = array(); preg_match($this->input_format, $coord, $matches); if (count($matches) == 5) { $degrees = $matches[1]; $minutes = $matches[2] * (1 / 60); $seconds = $matches[3] * (1 / 60 * 1 / 60); $coordinate = ''; if (isset($matches[4])) { if ($matches[4] == 'S' or $matches[4] == 'W') {
php
{ "resource": "" }
q242
DmsParser.get
train
public function get($coord) { $coord = rad2deg($coord); $degrees = (integer) $coord; $compass = ''; if ($this->direction == N::LAT) { if ($degrees < 0) $compass = 'S'; elseif ($degrees > 0) $compass = 'N'; }elseif ($this->direction == N::LONG) { if ($degrees < 0)
php
{ "resource": "" }
q243
SqlTable.convertRow
train
protected function convertRow(array $row, Connection $connection, Table $table) { $result = []; foreach ($row as $key => $value) { $type = $table->getColumn($key)->getType(); $val = $type->convertToPHPValue($value, $connection->getDatabasePlatform()); if ($type instanceof Types\DateTimeType) { $val = $val->format(\DateTime::RFC3339); } elseif ($type instanceof Types\DateTimeTzType) { $val = $val->format(\DateTime::RFC3339_EXTENDED); } elseif ($type instanceof Types\TimeType) {
php
{ "resource": "" }
q244
LoadRegisterViewHelper.renderStatic
train
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $key = $arguments['key']; $value = $arguments['value']; array_push($GLOBALS['TSFE']->registerStack, $GLOBALS['TSFE']->register); $GLOBALS['TSFE']->register[$key] = $value; $content = $renderChildrenClosure(); if ($content) {
php
{ "resource": "" }
q245
Coordinate.guessParser
train
public function guessParser($coord) { if (!is_numeric($coord) and !is_null($coord))
php
{ "resource": "" }
q246
TranslatableUtility.Master
train
public function Master() { if (Translatable::get_current_locale() != Translatable::default_locale()) {
php
{ "resource": "" }
q247
Factory.create
train
public static function create($term, $taxonomy = null) { // Ex: Taco\Term\Factory::create('Keyword') if (is_string($term) && class_exists($term)) { return new $term; } if (!is_object($term)) { $term = get_term($term, $taxonomy); } // TODO Refactor how this works to be more explicit and less guess
php
{ "resource": "" }
q248
Factory.createMultiple
train
public static function createMultiple($terms, $taxonomy = null) { if (!Arr::iterable($terms)) { return $terms; } $out = array(); foreach ($terms as $term) {
php
{ "resource": "" }
q249
RegistersUsers.signupUpdate
train
public function signupUpdate(Request $request) { $this->middleware('auth:api'); $data = $request->all(); $validator = Validator::make($data, [ 'firstname' => 'sometimes|required|max:255', 'surname' => 'sometimes|required|max:255', 'email' => 'sometimes|required|email|max:255|unique:users', 'mobile_number' => 'sometimes|min:10|unique:signup_data', 'password' => 'sometimes|required|min:6', 'gender' => 'sometimes|required', 'user_id' => 'required|integer', ]); if (!empty($validator->errors()->messages())) { return new Response([ 'status' => 'FAIL', 'message' => 'Fail to update user signup data', 'Errors' => $validator->errors() ], 500); } else { try { unset($data['_method']);
php
{ "resource": "" }
q250
JSON.encode
train
public static function encode($value, $options = 0, $depth = 512) { // multi-characters supported by default $options |= JSON_UNESCAPED_UNICODE; $data = version_compare(PHP_VERSION, '5.5.0', '>=') ? json_encode($value, $options, $depth) : json_encode($value, $options); if (JSON_ERROR_NONE !== json_last_error()) {
php
{ "resource": "" }
q251
ConfigurationUtility.getExtensionConfig
train
public static function getExtensionConfig(): array { $supportedMimeTypes = self::DEFAULT_SUPPORTED_MIME_TYPES; $desktopWidth = self::DEFAULT_DESKTOP_WIDTH; $tabletWidth = self::DEFAULT_TABLET_WIDTH; $smartphoneWidth = self::DEFAULT_SMARTPHONE_WIDTH; if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['responsive_images'])) { $supportedMimeTypes = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['responsive_images']['supportedMimeTypes'] ?? self::DEFAULT_SUPPORTED_MIME_TYPES; $desktopWidth = (int)$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['responsive_images']['maxDesktopImageWidth'] ?? self::DEFAULT_DESKTOP_WIDTH; $tabletWidth = (int)$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['responsive_images']['maxTabletImageWidth'] ?? self::DEFAULT_TABLET_WIDTH; $smartphoneWidth = (int)$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['responsive_images']['maxSmartphoneImageWidth'] ?? self::DEFAULT_SMARTPHONE_WIDTH; } elseif (isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['responsive_images'])) { try { $extConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['responsive_images']); if (!empty($extConfig['supportedMimeTypes'])) { $supportedMimeTypes = $extConfig['supportedMimeTypes']; } if (isset($extConfig['maxDesktopImageWidth']) && is_numeric($extConfig['maxDesktopImageWidth'])) {
php
{ "resource": "" }
q252
Loader.load
train
public static function load($class) { $instance = new $class; $taxonomy_key = $instance->getTaxonomyKey(); if (is_admin()) { add_action(sprintf('created_%s', $taxonomy_key), array($instance, 'addSaveHooks')); add_action(sprintf('edited_%s', $taxonomy_key), array($instance, 'addSaveHooks')); add_action(sprintf('%s_add_form_fields', $taxonomy_key), array($instance, 'addMetaBoxes')); add_action(sprintf('%s_edit_form_fields', $taxonomy_key), array($instance, 'addMetaBoxes')); add_action(sprintf('manage_edit-%s_columns', $taxonomy_key), array($instance, 'addAdminColumns'), 10, 3);
php
{ "resource": "" }
q253
CompletePurchaseResponse.calculateHash
train
private function calculateHash() { $hashType = $this->getHashType(); if ($hashType == 'sign') { throw new InvalidResponseException('Control sign forming method "SIGN" is not supported'); } elseif ($hashType == null) { throw new InvalidResponseException('Invalid signature type'); } return strtoupper(hash( $hashType, $this->data['LMI_PAYEE_PURSE']. $this->data['LMI_PAYMENT_AMOUNT']. $this->data['LMI_PAYMENT_NO'].
php
{ "resource": "" }
q254
Post.load
train
public function load($id, $load_terms = true) { $info = (is_object($id)) ? $id : get_post($id); if (!is_object($info)) { return false; } // Handle how WordPress converts special chars out of the DB // b/c even when you pass 'raw' as the 3rd partam to get_post, // WordPress will still encode the values. if (isset($info->post_title) && preg_match('/[&]{1,}/', $info->post_title)) { $info->post_title = html_entity_decode($info->post_title); } $this->_info = (array) $info; // meta $meta = get_post_meta($this->_info[self::ID]);
php
{ "resource": "" }
q255
Post.loadTerms
train
public function loadTerms() { $taxonomy_keys = $this->getTaxonomyKeys(); if (!Arr::iterable($taxonomy_keys)) { return false; } // TODO Move this to somewhere more efficient // Check if this should be an instance of TacoTerm. // If not, the object will just be a default WP object from wp_get_post_terms below. $taxonomies_subclasses = array(); $subclasses = Term\Loader::getSubclasses(); foreach ($subclasses as $subclass) { $term_instance = new $subclass; $term_instance_taxonomy_key = $term_instance->getKey(); foreach ($taxonomy_keys as $taxonomy_key) { if (array_key_exists($taxonomy_key, $taxonomies_subclasses)) { continue; } if ($term_instance_taxonomy_key !== $taxonomy_key) { continue; } $taxonomies_subclasses[$taxonomy_key] = $subclass;
php
{ "resource": "" }
q256
Post.getDefaults
train
public function getDefaults() { global $user; return array( 'post_type' => $this->getPostType(), 'post_author' => (is_object($user)) ? $user->ID : null,
php
{ "resource": "" }
q257
Post.registerPostType
train
public function registerPostType() { $config = $this->getPostTypeConfig();
php
{ "resource": "" }
q258
Post.getTaxonomy
train
public function getTaxonomy($key) { $taxonomies = $this->getTaxonomies(); if (!Arr::iterable($taxonomies)) { return false; } $taxonomy = (array_key_exists($key, $taxonomies)) ? $taxonomies[$key] : false; if (!$taxonomy) { return false; } // Handle all of these: // return array('one', 'two', 'three'); // return array('one'=>'One Category', 'two', 'three'); // return array( // 'one'=>array('label'=>'One Category'), // 'two'=>array('rewrite'=>array('slug'=>'foobar')), // 'three' // ); if (is_string($taxonomy)) { $taxonomy = (is_numeric($key))
php
{ "resource": "" }
q259
Post.getTaxonomyKeys
train
public function getTaxonomyKeys() { $taxonomies = $this->getTaxonomies(); if (!Arr::iterable($taxonomies)) { return array(); } $out = array(); foreach ($taxonomies as $k => $taxonomy) {
php
{ "resource": "" }
q260
Post.getTaxonomyKey
train
public function getTaxonomyKey($key, $taxonomy = array()) { if (is_string($key)) { return $key; } if (is_array($taxonomy) && array_key_exists('label', $taxonomy)) {
php
{ "resource": "" }
q261
Post.getTaxonomiesInfo
train
public function getTaxonomiesInfo() { $taxonomies = $this->getTaxonomies(); if (!Arr::iterable($taxonomies)) { return array(); } $out = array(); foreach ($taxonomies as $k => $taxonomy) {
php
{ "resource": "" }
q262
Post.getPostTypeConfig
train
public function getPostTypeConfig() { if (in_array($this->getPostType(), array('post', 'page'))) { return null; } return array( 'labels' => array( 'name' => _x($this->getPlural(), 'post type general name'), 'singular_name' => _x($this->getSingular(), 'post type singular name'), 'add_new' => _x('Add New', $this->getSingular()), 'add_new_item' => __(sprintf('Add New %s', $this->getSingular())), 'edit_item' => __(sprintf('Edit %s', $this->getSingular())), 'new_item' => __(sprintf('New %s', $this->getPlural())), 'view_item' => __(sprintf('View %s', $this->getSingular())), 'search_items' => __(sprintf('Search %s', $this->getPlural())), 'not_found' => __(sprintf('No %s found', $this->getPlural())), 'not_found_in_trash'=> __(sprintf('No %s found in Trash', $this->getPlural())), 'parent_item_colon' => '' ), 'hierarchical'
php
{ "resource": "" }
q263
Post.getMenuIcon
train
public function getMenuIcon() { // Look for these files by default // If your plugin directory contains an [post-type].png file, that will by default be the icon // Ex: hot-sauce.png $reflector = new \ReflectionClass(get_called_class()); $dir = basename(dirname($reflector->getFileName())); $post_type = $this->getPostType(); $fnames = array( $post_type.'.png', $post_type.'.gif', $post_type.'.jpg' );
php
{ "resource": "" }
q264
Post.sortAdminColumns
train
public function sortAdminColumns($vars) { if (!isset($vars['orderby'])) { return $vars; } $admin_columns = $this->getAdminColumns(); if (!Arr::iterable($admin_columns)) { return $vars; } foreach ($admin_columns as $k) { if ($vars['orderby'] !== $k) { continue; }
php
{ "resource": "" }
q265
Post.makeAdminTaxonomyColumnsSortable
train
public function makeAdminTaxonomyColumnsSortable($clauses, $wp_query) { global $wpdb; // Not sorting at all? Get out. if (!array_key_exists('orderby', $wp_query->query)) { return $clauses; } if ($wp_query->query['orderby'] !== 'meta_value') { return $clauses; } if (!array_key_exists('meta_key', $wp_query->query)) { return $clauses; } // No taxonomies defined? Get out. $taxonomies = $this->getTaxonomies(); if (!Arr::iterable($taxonomies)) { return $clauses; } // Not sorting by a taxonomy? Get out. $sortable_taxonomy_key = null; foreach ($taxonomies as $taxonomy_key => $taxonomy) { $taxonomy_key = (is_int($taxonomy_key)) ? $taxonomy : $taxonomy_key; if ($wp_query->query['meta_key'] !== $taxonomy_key) { continue; }
php
{ "resource": "" }
q266
Post.getHideTitleFromAdminColumns
train
public function getHideTitleFromAdminColumns() { if (in_array('title', $this->getAdminColumns())) { return false; } $supports = $this->getSupports();
php
{ "resource": "" }
q267
Post.getPostType
train
public function getPostType() { $called_class_segments = explode('\\', get_called_class()); $class_name = end($called_class_segments); return (is_null($this->post_type))
php
{ "resource": "" }
q268
Post.getPairs
train
public static function getPairs($args = array()) { $called_class = get_called_class(); $instance = Post\Factory::create($called_class); // Optimize the query if no args // Unfortunately, WP doesn't provide a clean way to specify which columns to select // If WP allowed that, this custom SQL wouldn't be necessary if (!Arr::iterable($args)) { global $wpdb; $sql = sprintf( "SELECT p.ID, p.post_title FROM $wpdb->posts p WHERE p.post_type = '%s' AND (p.post_status = 'publish') ORDER BY p.post_title ASC", $instance->getPostType() ); $results = $wpdb->get_results($sql); if (!Arr::iterable($results)) { return array(); } return array_combine( Collection::pluck($results, 'ID'),
php
{ "resource": "" }
q269
Post.getWhere
train
public static function getWhere($args = array(), $load_terms = true) { $instance = Post\Factory::create(get_called_class()); // Allow sorting both by core fields and custom fields // See: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters $default_orderby = $instance->getDefaultOrderBy(); $default_order = $instance->getDefaultOrder(); $default_args = array( 'post_type' => $instance->getPostType(), 'numberposts'=> -1, 'orderby' => $default_orderby, 'order' => $default_order, ); // Sometimes you will specify a default orderby using getDefaultOrderBy if ($default_orderby !== 'menu_order') { $fields = $instance->getFields(); if (array_key_exists($default_orderby, $fields)) { $default_args['meta_key'] = $default_orderby; // Number fields should be sorted numerically, not alphabetically // Of course, this currently requires you to use type=number to achieve numeric sorting $default_args['orderby'] = ($fields[$default_orderby]['type'] === 'number') ? 'meta_value_num' : 'meta_value';
php
{ "resource": "" }
q270
Post.getByTerm
train
public static function getByTerm($taxonomy, $terms, $field = 'slug', $args = array(), $load_terms = true) { $args = array_merge($args, array( 'tax_query'=>array(
php
{ "resource": "" }
q271
Post.getOneByTerm
train
public static function getOneByTerm($taxonomy, $terms, $field = 'slug', $args = array(), $load_terms = true) { $args['numberposts'] = 1; $result = static::getByTerm($taxonomy,
php
{ "resource": "" }
q272
Post.getPage
train
public static function getPage($page = 1, $args = array(), $load_terms = true) { $instance = Post\Factory::create(get_called_class()); $criteria = array( 'post_type' => $instance->getPostType(),
php
{ "resource": "" }
q273
Post.setTerms
train
public function setTerms($term_ids, $taxonomy = null, $append = false) { $taxonomy = ($taxonomy) ? $taxonomy : 'post_tag'; if (!is_array($this->_terms)) { $this->_terms = array(); } if (!array_key_exists($taxonomy, $this->_terms)) { $this->_terms[$taxonomy] = array();
php
{ "resource": "" }
q274
Post.getTerms
train
public function getTerms($taxonomy = null) { if ($taxonomy) { return (array_key_exists($taxonomy, $this->_terms)) ?
php
{ "resource": "" }
q275
Post.hasTerm
train
public function hasTerm($term_id) { $taxonomy_terms = $this->getTerms(); if (!Arr::iterable($taxonomy_terms)) { return false; } foreach ($taxonomy_terms as $taxonomy_key => $terms) { if (!Arr::iterable($terms)) { continue; } foreach ($terms as $term) {
php
{ "resource": "" }
q276
Post.getPostAttachment
train
public function getPostAttachment($size = 'full', $property = null) { $post_id = $this->get('ID'); if (!has_post_thumbnail($post_id)) { return false; } $attachment_id = get_post_thumbnail_id($post_id); $image_properties = array( 'url', 'width', 'height', 'is_resized' ); $image_array =
php
{ "resource": "" }
q277
Post.getRenderPublicField
train
public function getRenderPublicField($key, $field = null, $load_value = true) { $class = get_called_class(); if ($key === self::KEY_CLASS) { $attribs = array('type'=>'hidden', 'name'=>$key, 'value'=>$class); return Html::tag('input', null, $attribs); } if ($key === self::KEY_NONCE) {
php
{ "resource": "" }
q278
Post.getPublicFormKey
train
public function getPublicFormKey($suffix = null) { $val = sprintf('%s_public_form', $this->getPostType());
php
{ "resource": "" }
q279
Post.find
train
public static function find($post_id, $load_terms = true) { $instance = Post\Factory::create(get_called_class());
php
{ "resource": "" }
q280
Post.getLinkURL
train
public function getLinkURL($field) { $link_attr = self::decodeLinkObject($this->get($field)); if(!is_object($link_attr)) { return $this->get($field); } if(!(strlen($link_attr->href) && strlen($link_attr->title) && strlen($link_attr->target))) {
php
{ "resource": "" }
q281
Post.linkAttribsToHTMLString
train
public function linkAttribsToHTMLString($link_attr, $body = '', $classes = '', $id = '', $styles = '') { $link_text = null; if (strlen($link_attr->title)) { $link_text = $link_attr->title; } elseif (strlen($body)) { $link_text = $body; } else { $link_text = $link_attr->href; } return Html::link( $link_attr->href, $link_text,
php
{ "resource": "" }
q282
Post.getLinkHTMLFromObject
train
public static function getLinkHTMLFromObject($object_string, $body = '', $classes = '', $id = '', $styles = '') { return self::linkAttribsToHTMLString( self::decodeLinkObject($object_string),
php
{ "resource": "" }
q283
Passwordless.generateToken
train
public function generateToken($save = false) { $attributes = [ 'token' => str_random(16), 'is_used' => false, 'user_id' => $this->id, 'created_at' => time() ];
php
{ "resource": "" }
q284
QueryBuilderVisitor.enterExpression
train
public function enterExpression(Expression $expr) { $hash = spl_object_hash($expr); if ($expr instanceof Key) { if (!count($this->hashes)) { $this->qb->andWhere($this->toExpr($expr)); } else { $lastHash = end($this->hashes); $this->map[$lastHash][] = $this->toExpr($expr); } } elseif ($expr instanceof OrX) { $this->hashes[] =
php
{ "resource": "" }
q285
QueryBuilderVisitor.leaveExpression
train
public function leaveExpression(Expression $expr) { if ($expr instanceof OrX || $expr instanceof AndX) { $hash = spl_object_hash($expr); if ($expr instanceof OrX) { $composite = $this->qb->expr()->orX(); $composite->addMultiple($this->map[$hash]); } else { $composite = $this->qb->expr()->andX(); $composite->addMultiple($this->map[$hash]); } unset($this->hashes[array_search($hash, $this->hashes)]);
php
{ "resource": "" }
q286
QueryBuilderVisitor.shouldJoin
train
public function shouldJoin($key, $prefix = null) { $parts = explode('.', $key); if (!$prefix) { $prefix = $this->getRootAlias(); } if (!in_array($parts[0], $this->qb->getAllAliases())) { $this->qb->leftJoin($prefix.'.'.$parts[0], $parts[0]); } // If the key consists of multiple . parts, we also need to add joins for the
php
{ "resource": "" }
q287
Rsa.validateKey
train
private function validateKey($key) { $details = openssl_pkey_get_details($key); if (!isset($details['key']) || $details['type'] !== OPENSSL_KEYTYPE_RSA) { throw
php
{ "resource": "" }
q288
DownloadsBlockService.downloadMediaAction
train
public function downloadMediaAction($filename) { $media = $this->mediaManager->getRepository()->findOneByReference($filename); $provider = $this->container->get('opifer.media.provider.pool')->getProvider($media->getProvider()); $mediaUrl = $provider->getUrl($media); $fileSystem = $provider->getFileSystem(); $file = $fileSystem->read($media->getReference());
php
{ "resource": "" }
q289
DisplayLogicType.getDisplayLogicPrototypes
train
protected function getDisplayLogicPrototypes(BlockInterface $block) { $collection = new PrototypeCollection([ new OrXPrototype(), new AndXPrototype(), new EventPrototype('click_event', 'Click Event', 'event.type.click'), new TextPrototype('dom_node_id', 'DOM Node Id', 'node.id') ]); $owner = $block->getOwner(); if ($owner) { // Avoid trying to add display logic for blocks when the current block has no owner (e.g. shared blocks) $blockChoices = []; foreach ($owner->getBlocks() as $member) { try { $properties = $member->getProperties(); if ($member instanceof ChoiceFieldBlock) { if (empty($member->getName())) { continue; } if (!isset($properties['options'])) { continue; } $choices = []; foreach ($properties['options'] as $option) { if (empty($option['key'])) { continue; } $choices[] = new Choice($option['key'], $option['value']); } $collection->add(new SelectPrototype($member->getName(), $properties['label'], $member->getName(), $choices)); } elseif
php
{ "resource": "" }
q290
AuthenticationSuccessHandler.onAuthenticationSuccess
train
public function onAuthenticationSuccess(Request $request, TokenInterface $token) { if ($user = $token->getUser()) { if (!$user->getFirstName() || !$user->getLastName()) {
php
{ "resource": "" }
q291
Deserializer.fromBase64URL
train
public function fromBase64URL($data) { if ($remainder = strlen($data) % 4) { $data .= str_repeat('=', 4 -
php
{ "resource": "" }
q292
MailPlusProvider.synchronise
train
public function synchronise(Subscription $subscription) { try { $contact = [ 'update' => true, 'purge' => false, 'contact' => [ 'externalId' => $subscription->getId(), 'properties' => [ 'email' => $subscription->getEmail(), ], ], ]; $response = $this->post('contact', $contact); if ($response->getStatusCode() == '204') { //Contact added successfully status code $this->subscriptionManager->updateStatus($subscription, Subscription::STATUS_SYNCED);
php
{ "resource": "" }
q293
Token.getHeader
train
public function getHeader($name, $default = null) { if ($this->hasHeader($name)) { return $this->getHeaderValue($name); } if ($default === null) { throw
php
{ "resource": "" }
q294
Token.getHeaderValue
train
private function getHeaderValue($name) { $header = $this->headers[$name]; if ($header instanceof Claim) {
php
{ "resource": "" }
q295
Token.getClaim
train
public function getClaim($name, $default = null) { if ($this->hasClaim($name)) { return $this->claims[$name]->getValue(); } if ($default === null) { throw
php
{ "resource": "" }
q296
Token.verify
train
public function verify(Signer $signer, $key) { if ($this->signature === null) { throw new \BadMethodCallException('This token is not signed'); } if ($this->headers['alg'] !== $signer->getAlgorithmId()) {
php
{ "resource": "" }
q297
Token.validate
train
public function validate(ValidationData $data) { foreach ($this->getValidatableClaims() as $claim) { if (!$claim->validate($data)) {
php
{ "resource": "" }
q298
Token.getValidatableClaims
train
private function getValidatableClaims() { $claims = array(); foreach ($this->claims as $claim)
php
{ "resource": "" }
q299
Issue.create
train
public function create($projectKey, $issueTypeName) { $fieldsMetadata = $this->getCreateMetadataFields($projectKey, $issueTypeName); $fluentIssueCreate = new FluentIssueCreate($this->client, $fieldsMetadata);
php
{ "resource": "" }