_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
33
8k
language
stringclasses
1 value
meta_information
dict
q25400
PluginInstallCommand.installPlugin
train
protected function installPlugin(string $name) { $this->info('Downloading plugin...'); $this->files->copy($this->option('url'), $this->temp); if (true !== $this->zip->open($this->temp)) { $this->error('Cannot open plugin zip file.'); return;
php
{ "resource": "" }
q25401
PluginInstallCommand.setPluginHeaders
train
protected function setPluginHeaders(string $name, array $headers) { $this->info('Set plugin headers...'); $path = $this->path($name.'/plugin-name.php'); $handle = fopen($path, 'r'); $content = []; while (($line = fgets($handle)) !== false) {
php
{ "resource": "" }
q25402
PluginInstallCommand.parseLine
train
protected function parseLine(string $line, array $headers) { foreach ($this->headers as $field => $regex) { if (preg_match('/^[ \t\/*#@]*'.preg_quote($regex, '/').':(.*)$/mi', $line, $match) && $match[0]
php
{ "resource": "" }
q25403
PluginInstallCommand.setPluginRootFile
train
protected function setPluginRootFile(string $name) { $this->info('Set plugin root file...');
php
{ "resource": "" }
q25404
PluginInstallCommand.setConfigurationFile
train
protected function setConfigurationFile(string $name, array $headers) { $this->info('Set plugin configuration...'); $prefix = trim($headers['plugin_prefix'], '\/_-'); $from = $this->path($name.'/config/prefix_plugin.php');
php
{ "resource": "" }
q25405
PluginInstallCommand.setTranslationFile
train
protected function setTranslationFile($name, array $headers) { $this->info('Set plugin translation file...'); $textdomain = trim($headers['text_domain'], '\/ _-'); $from = $this->path($name.'/languages/plugin-textdomain-en_US.po');
php
{ "resource": "" }
q25406
PluginInstallCommand.setProviders
train
protected function setProviders(string $name, array $headers) { $this->info('Set default route provider...'); $this->replaceFileContent(
php
{ "resource": "" }
q25407
PluginInstallCommand.replaceFileContent
train
protected function replaceFileContent($path, array $headers) { $content = $this->files->get($path); $this->files->put($path, str_replace([ 'DummyNamespace', 'DummyAutoload', 'dummy_path' ], [
php
{ "resource": "" }
q25408
User.update
train
public function update(array $data): User { $user = wp_update_user(array_merge($data, [ 'ID' => $this->ID ])); if (is_a($user, 'WP_Error')) {
php
{ "resource": "" }
q25409
User.updateMetaData
train
public function updateMetaData(string $key, string $value): User { $previous = get_user_meta($this->ID, $key, true); if ($previous === $value) { return $this; } $update = update_user_meta($this->ID, $key, $value, $previous);
php
{ "resource": "" }
q25410
DownCommand.getDuration
train
protected function getDuration() { $time = $this->option('time');
php
{ "resource": "" }
q25411
FieldsRepository.addField
train
public function addField(FieldTypeInterface $field, SectionInterface $group): FieldsRepositoryInterface { // We store all fields together // as well as per group. On each form, // there is a "default" group defined where // all fields are attached to. A user can specify // a ...
php
{ "resource": "" }
q25412
FieldsRepository.getField
train
public function getField(string $name = '', string $group = 'default') { /** @var SectionInterface $section */ $section = $this->groups[$group]; $foundItems = array_filter($section->getItems(), function (FieldTypeInterface $item) use ($name) {
php
{ "resource": "" }
q25413
PageFactory.make
train
public function make(string $slug, string $title): PageInterface { $view = (new PageView($this->view)) ->setTheme('themosis.pages') ->setLayout('default') ->setView('page'); $page = new Page($this->action, $this->filter, $view, new PageSettingsRepository(), $this...
php
{ "resource": "" }
q25414
ThemeInstallCommand.installTheme
train
protected function installTheme(string $name) { $this->info('Downloading theme...'); $this->files->put($this->temp, fopen($this->option('url'), 'r')); if (true !== $this->zip->open($this->temp)) { $this->error('Cannot open theme zip file.'); }
php
{ "resource": "" }
q25415
ThemeInstallCommand.setupTheme
train
protected function setupTheme(string $name) { $this->info('Set [style.css] file...'); $theme = ucwords(str_replace(['-', '_'], ' ', $name)); $textdomain = str_replace(['-', ' '], '_', strtolower($name)); $content = <<<STYLES /* Theme Name: $theme Theme URI: https://framework.themos...
php
{ "resource": "" }
q25416
ThemeInstallCommand.setAsDefaultTheme
train
protected function setAsDefaultTheme(string $name) { if (! file_exists($file = config_path('wordpress.php'))) { $this->warn('Cannot update default theme configuration.'); return; } $this->info('Set default theme constant...'); $lines = file($file); ...
php
{ "resource": "" }
q25417
PluginsRepository.load
train
public function load(array $directories) { $manifest = $this->loadManifest(); if ($this->shouldRecompile($manifest, $directories)) { $manifest = $this->compileManifest($directories); } // Load plugins defined in the manifest. // Dispatch an event with loaded plu...
php
{ "resource": "" }
q25418
PluginsRepository.compileManifest
train
public function compileManifest(array $directories) { $manifest = []; foreach ($directories as $directory) { // Find the root file of each plugin. // As we load the plugins from the mu-plugins directory // we do not need to get their header. Only the file
php
{ "resource": "" }
q25419
PluginsRepository.getPlugin
train
public function getPlugin(string $directory) { $files = $this->files->files($this->app->mupluginsPath($directory)); foreach ($files as $file) { $headers = $this->headers($file->getRealPath(), $this->headers); if (! empty($headers['name'])) {
php
{ "resource": "" }
q25420
PluginsRepository.loadManifest
train
public function loadManifest() { if ($this->files->exists($this->manifestPath)) {
php
{ "resource": "" }
q25421
ThemeManager.load
train
public function load(string $path): ThemeManager { $this->setThemeDirectory(); $this->setThemeConstants();
php
{ "resource": "" }
q25422
ThemeManager.assets
train
public function assets(array $locations) { $finder = $this->app->bound('asset.finder') ? $this->app['asset.finder'] : null;
php
{ "resource": "" }
q25423
ThemeManager.getUrl
train
public function getUrl(string $path = '') { if (is_multisite() && defined(SUBDOMAIN_INSTALL) && SUBDOMAIN_INSTALL) { return sprintf( '%s/%s/themes/%s', get_home_url(),
php
{ "resource": "" }
q25424
ThemeManager.setThemeDirectory
train
protected function setThemeDirectory() { $pos = strrpos($this->dirPath, DIRECTORY_SEPARATOR);
php
{ "resource": "" }
q25425
ThemeManager.setThemeAutoloading
train
protected function setThemeAutoloading() { foreach ($this->config->get('theme.autoloading', []) as $ns => $path)
php
{ "resource": "" }
q25426
ThemeManager.providers
train
public function providers(array $providers = []) { foreach ($providers as
php
{ "resource": "" }
q25427
ThemeManager.views
train
public function views(array $paths = []) { if (! $this->app->has('view')) { return $this; } if (empty($paths)) { return $this; } $factory = $this->app->make('view'); $twigLoader = $this->app->make('twig.loader'); foreach ($paths as $...
php
{ "resource": "" }
q25428
ThemeManager.setThemeConstants
train
protected function setThemeConstants() { $this->parsedHeaders = $this->headers($this->dirPath.'/style.css', $this->headers); // Theme text domain. $textdomain = (isset($this->parsedHeaders['text_domain']) && ! empty($this->parsedHeaders['text_domain'])) ?
php
{ "resource": "" }
q25429
ThemeManager.sidebars
train
public function sidebars($sidebars = []) { if (empty($sidebars)) { return $this; } if (function_exists('register_sidebar')) { foreach ($sidebars as
php
{ "resource": "" }
q25430
ActionBuilder.run
train
public function run($hook, $args = null) { if (is_array($args)) { $this->doActionRefArray($hook, $args); } else {
php
{ "resource": "" }
q25431
ActionBuilder.addEventListener
train
protected function addEventListener($name, $callback, $priority, $accepted_args) { $this->hooks[$name] = [$callback, $priority, $accepted_args];
php
{ "resource": "" }
q25432
ActionBuilder.addAction
train
protected function addAction($name, $callback, $priority, $accepted_args) {
php
{ "resource": "" }
q25433
EnvironmentDetector.detectConsoleEnvironment
train
protected function detectConsoleEnvironment(Closure $callback, array $args) { if (! is_null($value = $this->getEnvironmentArgument($args))) {
php
{ "resource": "" }
q25434
Factory.make
train
public function make(string $slug, string $plural, string $singular): PostTypeInterface { $postType = (new PostType($slug, $this->action, $this->filter)) ->setLabels([ 'name' => $plural, 'singular_name' => $singular, 'add_new_item' => sprintf('Add ...
php
{ "resource": "" }
q25435
Kernel.command
train
public function command($signature, \Closure $callback) { $command = new ClosureCommand($signature, $callback);
php
{ "resource": "" }
q25436
Kernel.getConsole
train
protected function getConsole() { if (is_null($this->console)) { $console = new Console($this->app, $this->events, $this->app->version()); $console->setName('Themosis Framework');
php
{ "resource": "" }
q25437
Kernel.call
train
public function call($command, array $parameters = [], $outputBuffer = null) { $this->bootstrap();
php
{ "resource": "" }
q25438
Kernel.renderException
train
protected function renderException($output, \Exception $e) {
php
{ "resource": "" }
q25439
ChoiceType.setLayout
train
protected function setLayout($expanded = false, $multiple = false) { if ($expanded && false === $multiple) { $this->layout = 'radio';
php
{ "resource": "" }
q25440
ChoiceType.getOptions
train
public function getOptions(array $excludes = null): array { $options = parent::getOptions($excludes); /* * Let's add the choices in a readable format as * well as the layout property. */ $choices = $this->getOption('choices', []); if ($choices instanceof ...
php
{ "resource": "" }
q25441
ChoiceType.metaboxSave
train
public function metaboxSave($value, int $post_id) { $this->setValue($value); if (! $this->getOption('multiple', false)) { // Store single value. $this->saveSingleValue($this->getRawValue(), $post_id); } else {
php
{ "resource": "" }
q25442
ChoiceType.metaboxGet
train
public function metaboxGet(int $post_id) { $value = get_post_meta($post_id, $this->getName(), ! $this->getOption('multiple', false));
php
{ "resource": "" }
q25443
ChoiceType.saveSingleValue
train
protected function saveSingleValue($value, int $post_id) { $previous = get_post_meta($post_id, $this->getName(), true); if (is_null($value) || empty($value)) { delete_post_meta($post_id, $this->getName()); } elseif (empty($previous)) {
php
{ "resource": "" }
q25444
ChoiceType.saveTermSingleValue
train
protected function saveTermSingleValue($value, int $term_id) { $previous = get_term_meta($term_id, $this->getName(), true); if (is_null($value) || empty($value)) { delete_term_meta($term_id, $this->getName()); } elseif (empty($previous)) {
php
{ "resource": "" }
q25445
ChoiceType.saveTermMultipleValue
train
protected function saveTermMultipleValue($value, int $term_id) { $previous = get_term_meta($term_id, $this->getName(), false); if (is_null($value) || empty($value)) { delete_term_meta($term_id, $this->getName()); } elseif (empty($previous) && is_array($value)) { arra...
php
{ "resource": "" }
q25446
ChoiceType.saveUserSingleValue
train
protected function saveUserSingleValue($value, int $user_id) { $previous = get_user_meta($user_id, $this->getName(), true); if (is_null($value) || empty($value)) { delete_user_meta($user_id, $this->getName()); } elseif (empty($previous)) {
php
{ "resource": "" }
q25447
ChoiceType.saveUserMultipleValue
train
protected function saveUserMultipleValue($value, int $user_id) { $previous = get_user_meta($user_id, $this->getName(), false); if (is_null($value) || empty($value)) { delete_user_meta($user_id, $this->getName()); } elseif (empty($previous) && is_array($value)) { arra...
php
{ "resource": "" }
q25448
MetaboxTransformer.transform
train
public function transform(MetaboxInterface $metabox) { return [ 'id' => $metabox->getId(), 'context' => $metabox->getContext(), 'l10n' =>
php
{ "resource": "" }
q25449
MetaboxTransformer.getScreen
train
protected function getScreen($screen) { if (is_string($screen) && function_exists('convert_to_screen')) { $screen = convert_to_screen($screen); } if ($screen instanceof \WP_Screen) {
php
{ "resource": "" }
q25450
MetaboxTransformer.includeFields
train
public function includeFields(MetaboxInterface $metabox) { return $this->collection( $metabox->repository()->all(), function (FieldTypeInterface $field) { $field = $field->setResourceTransformerFactory(new Factory());
php
{ "resource": "" }
q25451
StringToBooleanTransformer.transform
train
public function transform($data) { if (is_null($data)) { return false; } if (! is_string($data)) { throw new DataTransformerException('A string value is expected.'); } if (empty($data)) {
php
{ "resource": "" }
q25452
File.setType
train
public function setType(string $filename, $type = null): AssetFileInterface { if (! is_null($type) && in_array($type, $this->extensions, true)) { // We first listen to a defined asset type. // If no type is defined, let's try to discover it. $this->type = $this->findType(...
php
{ "resource": "" }
q25453
MetaboxServiceProvider.registerMetabox
train
public function registerMetabox() { $this->app->bind('metabox', function ($app) { $resource = new MetaboxResource( $app->bound('league.fractal') ? $app['league.fractal'] : new Manager(), new ArraySerializer(),
php
{ "resource": "" }
q25454
UserField.add
train
public function add($field, SectionInterface $section = null): UserFieldContract { if ($field instanceof SectionInterface) { $section = $field; if ($section->hasItems()) { foreach ($section->getItems() as $item) { /** @var FieldTypeInterface $item...
php
{ "resource": "" }
q25455
UserField.getSection
train
protected function getSection(FieldTypeInterface $field, $section = null): SectionInterface { if (is_null($section)) { if ($this->repository->hasGroup($field->getOption('group'))) { $section = $this->repository->getGroup($field->getOption('group')); } else {
php
{ "resource": "" }
q25456
UserField.set
train
public function set(): UserFieldContract { $this->action->add([ 'user_new_form', 'show_user_profile', 'edit_user_profile' ], [$this, 'display']); $this->action->add([
php
{ "resource": "" }
q25457
UserField.display
train
public function display($user) { foreach ($this->repository->getGroups() as $group) { /** @var SectionInterface $group */ $fields = $group->getItems(); if (is_a($user, 'WP_User')) { // Initiate the value (edit screens only). array_walk($fi...
php
{ "resource": "" }
q25458
UserField.save
train
public function save($user_id) { $validator = $this->validator->make( $this->getUserData(app('request')), $this->getUserRules(), $this->getUserMessages(), $this->getUserPlaceholders() ); $validation = $validator->valid(); foreach ($th...
php
{ "resource": "" }
q25459
UserField.getUserData
train
protected function getUserData(Request $request) { $data = []; foreach ($this->repository->all() as
php
{ "resource": "" }
q25460
UserField.getUserRules
train
protected function getUserRules() { $rules = []; foreach ($this->repository->all() as
php
{ "resource": "" }
q25461
UserField.getUserMessages
train
protected function getUserMessages() { $messages = []; foreach ($this->repository->all() as $field) { foreach ($field->getOption('messages') as $rule => $message) {
php
{ "resource": "" }
q25462
UserField.getUserPlaceholders
train
protected function getUserPlaceholders() { $placeholders = []; foreach ($this->repository->all() as
php
{ "resource": "" }
q25463
Factory.text
train
public function text(string $name, array $options = []): FieldTypeInterface { return (new TextType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25464
Factory.password
train
public function password(string $name, array $options = []): FieldTypeInterface { return (new PasswordType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25465
Factory.number
train
public function number(string $name, array $options = []): FieldTypeInterface { return (new NumberType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25466
Factory.integer
train
public function integer(string $name, array $options = []): FieldTypeInterface { return (new IntegerType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25467
Factory.email
train
public function email(string $name, array $options = []): FieldTypeInterface { return (new EmailType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25468
Factory.date
train
public function date($name, array $features = [], array $attributes = []) { $properties = [ 'features' => $features, 'atts' => array_merge(['class' => 'newtag'], $attributes, ['data-field' => 'date']),
php
{ "resource": "" }
q25469
Factory.textarea
train
public function textarea(string $name, array $options = []): FieldTypeInterface { return (new TextareaType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25470
Factory.checkbox
train
public function checkbox(string $name, array $options = []): FieldTypeInterface { return (new CheckboxType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25471
Factory.choice
train
public function choice(string $name, array $options = []): FieldTypeInterface { return (new ChoiceType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25472
Factory.media
train
public function media($name, array $options = []): FieldTypeInterface { return (new MediaType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25473
Factory.editor
train
public function editor($name, array $options = []): FieldTypeInterface { return (new EditorType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25474
Factory.collection
train
public function collection($name, array $options = []): FieldTypeInterface { return (new CollectionType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25475
Factory.color
train
public function color($name, array $options = []): FieldTypeInterface { return (new ColorType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25476
Factory.button
train
public function button(string $name, array $options = []): FieldTypeInterface { return (new ButtonType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25477
Factory.submit
train
public function submit(string $name, array $options = []): FieldTypeInterface { return (new SubmitType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25478
Factory.hidden
train
public function hidden(string $name, array $options = []): FieldTypeInterface { return (new HiddenType($name)) ->setLocale($this->app->getLocale())
php
{ "resource": "" }
q25479
IntegerType.metaboxSave
train
public function metaboxSave($value, int $post_id) { $this->setValue($value); $previous = get_post_meta($post_id, $this->getName(), true); if (is_null($this->getValue()) || empty($this->getValue())) { delete_post_meta($post_id, $this->getName()); } elseif (empty($previou...
php
{ "resource": "" }
q25480
Factory.make
train
public function make(string $slug, $objects, string $plural, string $singular): TaxonomyInterface { $taxonomy = (new Taxonomy($slug, (array) $objects, $this->container, $this->action)) ->setLabels([ 'name' => $plural, 'singular_name' => $singular, ...
php
{ "resource": "" }
q25481
AuthMakeCommand.createDirectories
train
protected function createDirectories() { if (! $this->files->isDirectory($directory = app_path('Forms/Auth/Passwords'))) { $this->files->makeDirectory($directory, 0755, true); } if (! $this->files->isDirectory($directory = app_path('Http/Controllers/Auth'))) { $this-...
php
{ "resource": "" }
q25482
AuthMakeCommand.exportViews
train
protected function exportViews() { foreach ($this->views as $pathIn => $pathOut) { if ($this->files->exists($view = resource_path('views/'.$pathOut)) && ! $this->option('force')) {
php
{ "resource": "" }
q25483
AuthMakeCommand.exportControllers
train
protected function exportControllers() { foreach ($this->controllers as $pathIn => $pathOut) { if ($this->files->exists($controller = app_path('Http/Controllers/'.$pathOut)) && ! $this->option('force')) { if (! $this->confirm("The [{$pathOut}] controller already e...
php
{ "resource": "" }
q25484
AuthMakeCommand.exportForms
train
protected function exportForms() { foreach ($this->forms as $pathIn => $pathOut) { if ($this->files->exists($form = app_path('Forms/'.$pathOut)) && ! $this->option('force')) { if (! $this->confirm("The [{$pathOut}] form already exists. Do you want to overwrite it?")) { ...
php
{ "resource": "" }
q25485
AdminRoute.get
train
public function get() { $wordpressUri = trim(config('app.wp.dir', 'cms'), '\/'); $route = $this->router->any($wordpressUri.'/wp-admin/{any?}', function ()
php
{ "resource": "" }
q25486
PluginManager.setDirectory
train
public function setDirectory() { $pos = strrpos($this->dirPath, DIRECTORY_SEPARATOR);
php
{ "resource": "" }
q25487
PluginManager.getPath
train
public function getPath(string $path = ''): string {
php
{ "resource": "" }
q25488
PluginManager.config
train
public function config(string $key, $default = null) { $fullnameKey = $this->getNamespace().'_'.$key;
php
{ "resource": "" }
q25489
PluginManager.setConstants
train
protected function setConstants() { $this->parsedHeaders = $this->headers($this->filePath, $this->headers); $domainVar = $this->parsedHeaders['domain_var'] ?? 'PLUGIN_TD'; $domainVar = strtoupper($domainVar);
php
{ "resource": "" }
q25490
PluginManager.loadPluginConfiguration
train
protected function loadPluginConfiguration(string $configPath) {
php
{ "resource": "" }
q25491
PluginManager.setPluginAutoloading
train
protected function setPluginAutoloading() { foreach ($this->config('plugin.autoloading', []) as $ns => $path) { $path = $this->dirPath.'/'.trim($path, '\/');
php
{ "resource": "" }
q25492
FilterBuilder.run
train
public function run($hook, $args = null) { if (is_array($args)) {
php
{ "resource": "" }
q25493
FilterBuilder.addEventListener
train
protected function addEventListener($name, $callback, $priority, $accepted_args) { $this->hooks[$name] = [$callback, $priority, $accepted_args];
php
{ "resource": "" }
q25494
FilterBuilder.addFilter
train
protected function addFilter($name, $callback, $priority, $accepted_args) {
php
{ "resource": "" }
q25495
Templates.parse
train
protected function parse(array $options) { $templates = [ 'page' => [] ]; foreach ($options as $slug => $properties) { // 1 - $slug is int -> meaning it's only for pages // and $properties is the slug name. if (is_int($slug)) { ...
php
{ "resource": "" }
q25496
Templates.register
train
public function register() { foreach ($this->templates as $post_type => $templates) { if (empty($templates)) { continue;
php
{ "resource": "" }
q25497
BaseType.getDefaultOptions
train
public function getDefaultOptions(): array { // Setup default validation rules. $this->defaultOptions['rules'] = $this->rules; // Setup default messages. $this->defaultOptions['messages'] = $this->messages; // Setup default placeholder. $this->defaultOptions['placeh...
php
{ "resource": "" }
q25498
BaseType.getOptions
train
public function getOptions(array $excludes = null): array { if (! is_null($excludes)) { return array_filter($this->options, function ($key) use ($excludes) {
php
{ "resource": "" }
q25499
BaseType.render
train
public function render(): string { $view = $this->viewFactory->make($this->getView(), $this->getFieldData()); // Indicates that the form has been rendered at
php
{ "resource": "" }