_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
33
8k
language
stringclasses
1 value
meta_information
dict
q21400
LocationManager.get_calling_script_file
train
public static function get_calling_script_file( $offset = 0 ) { $callers = array(); $backtrace = debug_backtrace(); foreach ( $backtrace as $trace ) { if ( array_key_exists('file', $trace) && $trace['file'] != __FILE__ ) {
php
{ "resource": "" }
q21401
LocationManager.get_calling_script_dir
train
public static function get_calling_script_dir( $offset = 0 ) { $caller = self::get_calling_script_file($offset); if ( !is_null($caller) ) {
php
{ "resource": "" }
q21402
Retina.filename
train
public function filename( $src_filename, $src_extension ) { $newbase = $src_filename.'@'.$this->factor.'x';
php
{ "resource": "" }
q21403
Timber.get_sites
train
public static function get_sites( $blog_ids = false ) { if ( !is_array($blog_ids) ) { global $wpdb; $blog_ids = $wpdb->get_col("SELECT blog_id
php
{ "resource": "" }
q21404
Timber.compile
train
public static function compile( $filenames, $data = array(), $expires = false, $cache_mode = Loader::CACHE_USE_DEFAULT, $via_render = false ) { if ( !defined('TIMBER_LOADED') ) { self::init(); } $caller = LocationManager::get_calling_script_dir(1); $loader = new Loader($caller); $file = $loader->choose_tem...
php
{ "resource": "" }
q21405
Timber.compile_string
train
public static function compile_string( $string, $data = array() ) { $dummy_loader = new Loader(); $twig = $dummy_loader->get_twig(); $template
php
{ "resource": "" }
q21406
Timber.fetch
train
public static function fetch( $filenames, $data = array(), $expires = false, $cache_mode = Loader::CACHE_USE_DEFAULT ) { $output = self::compile($filenames, $data, $expires,
php
{ "resource": "" }
q21407
Timber.render_string
train
public static function render_string( $string, $data = array() ) { $compiled
php
{ "resource": "" }
q21408
Timber.get_sidebar
train
public static function get_sidebar( $sidebar = 'sidebar.php', $data = array() ) { if ( strstr(strtolower($sidebar),
php
{ "resource": "" }
q21409
Timber.get_sidebar_from_php
train
public static function get_sidebar_from_php( $sidebar = '', $data ) { $caller = LocationManager::get_calling_script_dir(1); $uris = LocationManager::get_locations($caller); ob_start(); $found = false; foreach ( $uris as $uri ) { if ( file_exists(trailingslashit($uri).$sidebar) ) { include trailingslash...
php
{ "resource": "" }
q21410
Operation.hexrgb
train
public static function hexrgb( $hexstr ) { if ( !strstr($hexstr, '#') ) { $hexstr = '#'.$hexstr; } if ( strlen($hexstr) == 4 ) { $hexstr = '#'.$hexstr[1].$hexstr[1].$hexstr[2].$hexstr[2].$hexstr[3].$hexstr[3]; } $int =
php
{ "resource": "" }
q21411
Term.get_posts
train
public function get_posts( $numberposts_or_args = 10, $post_type_or_class = 'any', $post_class = '' ) { if ( !strlen($post_class) ) { $post_class = $this->PostClass; } $default_tax_query = array(array( 'field' => 'term_id', 'terms' => $this->ID, 'taxonomy' => $this->taxonomy, )); if ( is_string(...
php
{ "resource": "" }
q21412
QueryIterator.fix_number_posts_wp_quirk
train
public static function fix_number_posts_wp_quirk( $query ) { if ( isset($query->query) && isset($query->query['numberposts']) && !isset($query->query['posts_per_page']) ) {
php
{ "resource": "" }
q21413
QueryIterator.fix_cat_wp_quirk
train
public static function fix_cat_wp_quirk( $query ) { if ( isset($query->query) && isset($query->query['category']) && !isset($query->query['cat']) ) {
php
{ "resource": "" }
q21414
QueryIterator.handle_maybe_custom_posts_page
train
public static function handle_maybe_custom_posts_page( $query ) { if ( $custom_posts_page = get_option('page_for_posts') ) { if ( isset($query->query['p']) &&
php
{ "resource": "" }
q21415
Site.switch_to_blog
train
protected static function switch_to_blog( $site_name_or_id ) { if ( $site_name_or_id === null ) { $site_name_or_id = get_current_blog_id(); } $info
php
{ "resource": "" }
q21416
Site.init_as_singlesite
train
protected function init_as_singlesite() { $this->admin_email = get_bloginfo('admin_email'); $this->name = get_bloginfo('name'); $this->title = $this->name; $this->description
php
{ "resource": "" }
q21417
Comment.avatar
train
public function avatar( $size = 92, $default = '' ) { if ( !get_option('show_avatars') ) { return false; } if ( !is_numeric($size) ) { $size = '92'; } $email = $this->avatar_email(); $args = array('size' => $size, 'default' => $default); $args = apply_filters('pre_get_avatar_data', $args, $email);...
php
{ "resource": "" }
q21418
Comment.reply_link
train
public function reply_link( $reply_text = 'Reply' ) { if ( is_singular() && comments_open() && get_option('thread_comments') ) { wp_enqueue_script('comment-reply'); } // Get the comments depth option from the admin panel
php
{ "resource": "" }
q21419
Post.init
train
protected function init( $pid = false ) { if ( $pid === false ) { $pid = get_the_ID(); } if ( is_numeric($pid) ) { $this->ID = $pid;
php
{ "resource": "" }
q21420
Post.update
train
public function update( $field, $value ) { if ( isset($this->ID) ) {
php
{ "resource": "" }
q21421
Post.check_post_id
train
protected function check_post_id( $pid ) { if ( is_numeric($pid) && $pid === 0 ) { $pid = get_the_ID(); return $pid;
php
{ "resource": "" }
q21422
Post.get_info
train
protected function get_info( $pid ) { $post = $this->prepare_post_info($pid); if ( !isset($post->post_status) ) { return null; } do_action_ref_array('the_post', array(&$post, &$GLOBALS['wp_query'])); $post->status = $post->post_status;
php
{ "resource": "" }
q21423
Post.terms
train
public function terms( $args = array(), $merge = true, $term_class = '' ) { // Ensure backwards compatibility. if ( ! is_array( $args ) || isset( $args[0] ) ) { $args = array( 'query' => array( 'taxonomy' => $args, ), 'merge' => $merge, 'term_class' => $term_class, ); if ( empty( $arg...
php
{ "resource": "" }
q21424
Post.field_object
train
public function field_object( $field_name ) { $value = apply_filters('timber/post/meta_object_field',
php
{ "resource": "" }
q21425
Post.maybe_show_password_form
train
protected function maybe_show_password_form() { if ( $this->password_required() ) { $show_pw = false; $show_pw = apply_filters('timber/post/content/show_password_form_for_protected', $show_pw); if ( $show_pw ) {
php
{ "resource": "" }
q21426
Post.type
train
public function type() { if ( isset($this->custom['type']) ) { return $this->custom['type'];
php
{ "resource": "" }
q21427
Post.link
train
public function link() { if ( isset($this->_permalink) ) { return
php
{ "resource": "" }
q21428
Post.convert
train
public function convert( $data ) { if ( is_object($data) ) { $data = Helper::convert_wp_object($data); } else if ( is_array($data) ) { $func = __FUNCTION__;
php
{ "resource": "" }
q21429
Post.prev
train
public function prev( $in_same_term = false ) { if ( isset($this->_prev) && isset($this->_prev[$in_same_term]) ) { return $this->_prev[$in_same_term]; } global $post; $old_global = $post; $post = $this; $within_taxonomy = ($in_same_term) ? $in_same_term : 'category'; $adjacent = get_adjacent_post(($in_...
php
{ "resource": "" }
q21430
Post.gallery
train
public function gallery( $html = true ) { if ( isset($this->custom['gallery']) ) { return $this->custom['gallery']; } $galleries = get_post_galleries($this->ID, $html);
php
{ "resource": "" }
q21431
Post.audio
train
public function audio() { if ( isset($this->custom['audio']) ) { return $this->custom['audio']; } $audio = false; // Only get audio from the content if a playlist isn't present.
php
{ "resource": "" }
q21432
Post.video
train
public function video() { if ( isset($this->custom['video']) ) { return $this->custom['video']; } $video = false; // Only get video from the content if a playlist isn't present. if ( false === strpos($this->get_content(), 'wp-playlist-script') ) {
php
{ "resource": "" }
q21433
Post.get_terms
train
public function get_terms( $tax = '', $merge = true,
php
{ "resource": "" }
q21434
Post.get_comments
train
public function get_comments( $count = null, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'Timber\Comment' ) {
php
{ "resource": "" }
q21435
Helper.handle_transient_locking
train
protected static function handle_transient_locking( $slug, $callback, $transient_time, $lock_timeout, $force, $enable_transients ) { if ( $enable_transients && self::_is_transient_locked($slug) ) { $force = apply_filters('timber_force_transients', $force); $force = apply_filters('timber_force_transient_'.$slug,...
php
{ "resource": "" }
q21436
Helper.start_timer
train
public static function start_timer() { $time = microtime(); $time = explode(' ', $time);
php
{ "resource": "" }
q21437
Helper.stop_timer
train
public static function stop_timer( $start ) { $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0];
php
{ "resource": "" }
q21438
Helper.pluck
train
public static function pluck( $array, $key ) { $return = array(); foreach ( $array as $obj ) { if ( is_object($obj) && method_exists($obj, $key) ) { $return[] = $obj->$key(); } elseif ( is_object($obj) && property_exists($obj, $key) ) {
php
{ "resource": "" }
q21439
Helper.filter_array
train
public static function filter_array( $list, $args, $operator = 'AND' ) { if ( ! is_array($args) ) { $args = array( 'slug' => $args ); } if ( ! is_array( $list ) && ! is_a(
php
{ "resource": "" }
q21440
User.get_roles
train
protected function get_roles( $roles ) { if ( empty($roles) ) { // @codeCoverageIgnoreStart return null; // @codeCoverageIgnoreEnd } $wp_roles = wp_roles();
php
{ "resource": "" }
q21441
Timber_WP_CLI_Command.clear_cache
train
public function clear_cache( $mode = 'all' ) { $mode = $mode ? : 'all'; $cleared = Command::clear_cache( $mode ); if ( $cleared ) {
php
{ "resource": "" }
q21442
MenuItem.name
train
public function name() { if ( $title = $this->title() ) { return $title; } if (
php
{ "resource": "" }
q21443
MenuItem.slug
train
public function slug() { $mo = $this->master_object(); if ( $mo && $mo->post_name ) {
php
{ "resource": "" }
q21444
MenuItem.add_child
train
public function add_child( $item ) { if ( !$this->has_child_class ) { $this->add_class('menu-item-has-children'); $this->has_child_class = true; } $this->children[] = $item; $item->level =
php
{ "resource": "" }
q21445
MenuItem.import_classes
train
public function import_classes( $data ) { if ( is_array($data) ) { $data = (object) $data; } $this->classes = array_merge($this->classes, $data->classes); $this->classes = array_unique($this->classes); $this->classes
php
{ "resource": "" }
q21446
MenuItem.meta
train
public function meta( $key ) { if ( is_object($this->menu_object) && method_exists($this->menu_object,
php
{ "resource": "" }
q21447
MenuItem.link
train
public function link() { if ( !isset($this->url) || !$this->url ) { if ( isset($this->_menu_item_type) && $this->_menu_item_type == 'custom' ) { $this->url = $this->_menu_item_url; } else if ( isset($this->menu_object) &&
php
{ "resource": "" }
q21448
Revision.formatFieldName
train
private function formatFieldName($key) { $related_model = $this->revisionable_type; $related_model = new $related_model; $revisionFormattedFieldNames = $related_model->getRevisionFormattedFieldNames();
php
{ "resource": "" }
q21449
Revision.getValue
train
private function getValue($which = 'new') { $which_value = $which . '_value'; // First find the main model that was updated $main_model = $this->revisionable_type; // Load it, WITH the related model if (class_exists($main_model)) { $main_model = new $main_model; ...
php
{ "resource": "" }
q21450
Revision.isRelated
train
private function isRelated() { $isRelated = false; $idSuffix = '_id'; $pos = strrpos($this->key, $idSuffix); if ($pos !== false
php
{ "resource": "" }
q21451
Revision.getRelatedModel
train
private function getRelatedModel() { $idSuffix = '_id';
php
{ "resource": "" }
q21452
Revision.userResponsible
train
public function userResponsible() { if (empty($this->user_id)) { return false; } if (class_exists($class = '\Cartalyst\Sentry\Facades\Laravel\Sentry') || class_exists($class = '\Cartalyst\Sentinel\Laravel\Facades\Sentinel') ) { return $class::findUserById($this->user_...
php
{ "resource": "" }
q21453
FieldFormatter.format
train
public static function format($key, $value, $formats) { foreach ($formats as $pkey => $format) { $parts = explode(':', $format); if (sizeof($parts) === 1) { continue; } if ($pkey == $key) { $method = array_shift($parts); ...
php
{ "resource": "" }
q21454
FieldFormatter.isEmpty
train
public static function isEmpty($value, $options = array()) { $value_set =
php
{ "resource": "" }
q21455
FieldFormatter.string
train
public static function string($value, $format = null) { if (is_null($format)) { $format = '%s';
php
{ "resource": "" }
q21456
FieldFormatter.datetime
train
public static function datetime($value, $format = 'Y-m-d H:i:s') { if (empty($value)) { return null; }
php
{ "resource": "" }
q21457
Revisionable.changedRevisionableFields
train
private function changedRevisionableFields() { $changes_to_record = array(); foreach ($this->dirtyData as $key => $value) { // check that the field is revisionable, and double check // that it's actually new data in case dirty is, well, clean if ($this->isRevision...
php
{ "resource": "" }
q21458
Revisionable.isSoftDelete
train
private function isSoftDelete() { // check flag variable used in laravel 4.2+ if (isset($this->forceDeleting)) { return !$this->forceDeleting; } // otherwise, look for flag used in older versions
php
{ "resource": "" }
q21459
Command.search
train
public function search($options = []) { $query = $this->queryParts; if (empty($query)) { $query = '{}'; } if (is_array($query)) { $query = Json::encode($query); } $url = [$this->index !== null ? $this->index : '_all']; if
php
{ "resource": "" }
q21460
Command.deleteByQuery
train
public function deleteByQuery($options = []) { if (!isset($this->queryParts['query'])) { throw new InvalidCallException('Can not call deleteByQuery when no query is given.'); } $query = [ 'query' => $this->queryParts['query'], ]; if (isset($this->query...
php
{ "resource": "" }
q21461
Command.suggest
train
public function suggest($suggester, $options = []) { if (empty($suggester)) { $suggester = '{}'; } if (is_array($suggester)) { $suggester = Json::encode($suggester); } $url = [
php
{ "resource": "" }
q21462
Command.insert
train
public function insert($index, $type, $data, $id = null, $options = []) { if (empty($data)) { $body = '{}'; } else { $body = is_array($data) ? Json::encode($data) : $data; } if ($id !== null) {
php
{ "resource": "" }
q21463
Command.mget
train
public function mget($index, $type, $ids, $options = []) { $body = Json::encode(['ids' => array_values($ids)]);
php
{ "resource": "" }
q21464
Command.delete
train
public function delete($index, $type, $id, $options = []) {
php
{ "resource": "" }
q21465
Command.update
train
public function update($index, $type, $id, $data, $options = []) { $body = [ 'doc' => empty($data) ? new \stdClass() : $data, ]; if (isset($options["detect_noop"])) { $body["detect_noop"] = $options["detect_noop"];
php
{ "resource": "" }
q21466
Command.createIndex
train
public function createIndex($index, $configuration = null) { $body = $configuration !== null ?
php
{ "resource": "" }
q21467
Connection.selectActiveNode
train
protected function selectActiveNode() { $keys = array_keys($this->nodes);
php
{ "resource": "" }
q21468
Connection.createBulkCommand
train
public function createBulkCommand($config = []) { $this->open(); $config['db'] = $this;
php
{ "resource": "" }
q21469
Connection.post
train
public function post($url, $options = [], $body = null, $raw = false) {
php
{ "resource": "" }
q21470
Connection.decodeErrorBody
train
protected function decodeErrorBody($body) { try { $decoded = Json::decode($body); if (isset($decoded['error']) && !is_array($decoded['error'])) {
php
{ "resource": "" }
q21471
ActiveQuery.createModels
train
private function createModels($rows) { $models = []; if ($this->asArray) { if ($this->indexBy === null) { return $rows; } foreach ($rows as $row) { if (is_string($this->indexBy)) { $key = isset($row['fields'][$th...
php
{ "resource": "" }
q21472
ActiveFixture.resetIndex
train
protected function resetIndex() { $this->db->createCommand([ 'index' => $this->index, 'type' => $this->type,
php
{ "resource": "" }
q21473
Query.populate
train
public function populate($rows) { if ($this->indexBy === null) { return $rows; } $models = []; foreach ($rows as $key => $row) { if ($this->indexBy !== null) { if (is_string($this->indexBy)) { $key = isset($row['fields'][$th...
php
{ "resource": "" }
q21474
Query.delete
train
public function delete($db = null, $options = []) { if ($this->emulateExecution) {
php
{ "resource": "" }
q21475
Query.scalar
train
public function scalar($field, $db = null) { if ($this->emulateExecution) { return null; } $record = self::one($db); if ($record !== false) { if ($field === '_id') { return $record['_id']; } elseif (isset($record['_source'][$field])...
php
{ "resource": "" }
q21476
Query.column
train
public function column($field, $db = null) { if ($this->emulateExecution) { return []; } $command = $this->createCommand($db); $command->queryParts['_source'] = [$field]; $result = $command->search(); if (empty($result['hits']['hits'])) { retur...
php
{ "resource": "" }
q21477
Query.from
train
public function from($index, $type = null) { $this->index = $index;
php
{ "resource": "" }
q21478
Query.fields
train
public function fields($fields) { if (is_array($fields) || $fields === null) { $this->fields = $fields; } else {
php
{ "resource": "" }
q21479
Query.source
train
public function source($source) { if (is_array($source) || $source === null) { $this->source = $source; } else {
php
{ "resource": "" }
q21480
Query.options
train
public function options($options) { if (!is_array($options)) { throw new InvalidParamException('Array
php
{ "resource": "" }
q21481
Query.addOptions
train
public function addOptions($options) { if (!is_array($options)) { throw new InvalidParamException('Array parameter expected, ' . gettype($options) . ' received.'); }
php
{ "resource": "" }
q21482
QueryBuilder.buildOrderBy
train
public function buildOrderBy($columns) { if (empty($columns)) { return []; } $orders = []; foreach ($columns as $name => $direction) { if (is_string($direction)) { $column = $direction; $direction = SORT_ASC; } else ...
php
{ "resource": "" }
q21483
ElasticsearchTarget.prepareMessage
train
public function prepareMessage($message) { list($text, $level, $category, $timestamp) = $message; $result = [ 'category' => $category, 'level' => Logger::getLevelName($level), '@timestamp' => date('c', $timestamp), ]; if (isset($message[4])) { ...
php
{ "resource": "" }
q21484
ActiveDataProvider.getAggregation
train
public function getAggregation($name) { $aggregations = $this->getAggregations(); if (!isset($aggregations[$name])) {
php
{ "resource": "" }
q21485
ActiveRecord.filterCondition
train
private static function filterCondition($condition) { foreach($condition as $k => $v) { if (is_array($v)) { $condition[$k] = array_values($v); foreach($v as $vv) { if (is_array($vv)) {
php
{ "resource": "" }
q21486
ActiveRecord.get
train
public static function get($primaryKey, $options = []) { if ($primaryKey === null) { return null; } $command = static::getDb()->createCommand(); $result = $command->get(static::index(), static::type(), $primaryKey, $options); if ($result['found']) {
php
{ "resource": "" }
q21487
ActiveRecord.mget
train
public static function mget(array $primaryKeys, $options = []) { if (empty($primaryKeys)) { return []; } if (count($primaryKeys) === 1) { $model = static::get(reset($primaryKeys)); return $model === null ? [] : [$model]; } $command = stati...
php
{ "resource": "" }
q21488
ActiveRecord.insert
train
public function insert($runValidation = true, $attributes = null, $options = ['op_type' => 'create']) { if ($runValidation && !$this->validate($attributes)) { return false; } if (!$this->beforeSave(true)) { return false; } $values = $this->getDirtyAttr...
php
{ "resource": "" }
q21489
ActiveRecord.updateAllCounters
train
public static function updateAllCounters($counters, $condition = []) { $primaryKeys = static::primaryKeysByCondition($condition); if (empty($primaryKeys) || empty($counters)) { return 0; } $bulkCommand = static::getDb()->createBulkCommand([ "index" => static:...
php
{ "resource": "" }
q21490
BulkCommand.execute
train
public function execute() { //valid endpoints are /_bulk, /{index}/_bulk, and {index}/{type}/_bulk if ($this->index === null && $this->type === null) { $endpoint = ['_bulk']; } elseif ($this->index !== null && $this->type === null) { $endpoint = [$this->index, '_bulk'...
php
{ "resource": "" }
q21491
BulkCommand.addAction
train
public function addAction($line1, $line2 = null) { if (!is_array($this->actions)) {
php
{ "resource": "" }
q21492
BulkCommand.addDeleteAction
train
public function addDeleteAction($id, $index = null, $type = null) { $actionData = ['_id' => $id]; if (!empty($index)) { $actionData['_index'] = $index; } if (!empty($type))
php
{ "resource": "" }
q21493
ProtocolStreamWriter.flush
train
private function flush() { $keepWriting = true; while ($keepWriting) { $message = $this->messages[0]['message']; $promise = $this->messages[0]['promise']; $bytesWritten = @fwrite($this->output, $message); if ($bytesWritten > 0) { $mes...
php
{ "resource": "" }
q21494
PhpDocumentLoader.getOrLoad
train
public function getOrLoad(string $uri): Promise { return isset($this->documents[$uri]) ?
php
{ "resource": "" }
q21495
PhpDocumentLoader.create
train
public function create(string $uri, string $content): PhpDocument { return new PhpDocument( $uri,
php
{ "resource": "" }
q21496
PhpDocumentLoader.open
train
public function open(string $uri, string $content) { if (isset($this->documents[$uri])) { $document = $this->documents[$uri]; $document->updateContent($content); } else {
php
{ "resource": "" }
q21497
CompletionProvider.getUnqualifiedCompletions
train
private function getUnqualifiedCompletions( string $prefix, string $currentNamespace, array $importTables, bool $requireCanBeInstantiated ): \Generator { // Aliases list($namespaceAliases,,) = $importTables; // use Foo\Bar yield from $this->getCompleti...
php
{ "resource": "" }
q21498
CompletionProvider.getCompletionsForFqnPrefix
train
private function getCompletionsForFqnPrefix( string $prefix, bool $requireCanBeInstantiated, bool $insertFullyQualified ): \Generator { $namespace = nameGetParent($prefix); foreach ($this->index->getChildDefinitionsForFqn($namespace) as $fqn => $def) { if ($requir...
php
{ "resource": "" }
q21499
CompletionProvider.getCompletionsForAliases
train
private function getCompletionsForAliases( string $prefix, array $aliases, bool $requireCanBeInstantiated ): \Generator { foreach ($aliases as $alias => $aliasFqn) { if (!nameStartsWith($alias, $prefix)) { continue; } $definition = ...
php
{ "resource": "" }