PHPackages                             radishlab/myc-getter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. radishlab/myc-getter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

radishlab/myc-getter
====================

A library to get and escape values in WordPress + ACF environments

1.2.0(5mo ago)116.6k↓44.2%GPL-2.0-or-laterPHPPHP ^8.0

Since Jul 31Pushed 5mo ago6 watchersCompare

[ Source](https://github.com/RadishLab/myc-getter)[ Packagist](https://packagist.org/packages/radishlab/myc-getter)[ RSS](/packages/radishlab-myc-getter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (17)Used By (0)

MYC Getter
==========

[](#myc-getter)

This class aims to facilitate the process of obtaining and sanitizing data from the post information (ID or object).

With MYC Getter, is possible to replace this:

```
$posts = [];
foreach ($query->posts as $post) {
  $genresObjects = get_the_terms($post, 'genre');
  $genres = [];
  if (is_array($genresObjects)) {
    foreach ($genresObjects as $genre) {
      $genres[] = [
        'name'      => esc_html($genre->name),
        'url'       => esc_url(get_term_link($genre)),
      ];
    }
  }

  $posts[] = [
      'title'     => esc_html($post->post_title),
      'url'       => esc_url(get_the_permalink($post)),
      'image'     => get_the_post_thumbnail($post, 'large'),
      'author'    => absint(get_field('author', $post)),
      'genres'    => $genres,
  ];
}
```

By this:

```
$args = [
  'acf'         => ['author' => 'string'],
  'taxonomies'  => ['genre' => 'link'],
];
$getter = new MycGetter($args);

$posts = [];
foreach ($query->posts as $post) {
  $posts[] = $getter->escapedContent($post);
}
```

Requirements
------------

[](#requirements)

- PHP &gt;= 8.0

Instalattion
------------

[](#instalattion)

```
composer require radishlab/myc-getter
```

Usage
-----

[](#usage)

```
use RadishLab\MycGetter\MycGetter;

class MyClass {
  public function MyMethod()
  {
    $getter = new MycGetter();
  }
}
```

The class accept two parameters:

1. `$args`
    - An array of arguments, listing the content you want to pull, or a preset name
    - If nothing is passed, the class will use the arguments of the preset `default`
2. `$context`
    - A string to identify where the class is being called
    - If nothing is passed, the class will use `default`

```
[
  'fields'        => ['title', 'url', 'image'],
  'image_size'    => 'large',
  'image_type'    => 'html',
  'acf'           => false,
  'taxonomies'    => false,
];
```

To overwrite the `default` preset, you just need to pass the keys you want to change:

```
$args = [
  'fields' => ['title'],
];
$getter = new MycGetter($args);

// The arguments used by the class will be:
[
  'fields'        => ['title'],
  'image_size'    => 'large',
  'image_type'    => 'html',
  'acf'           => false,
  'taxonomies'    => false,
];
```

If you're using the same arguments in multiples places, you can use the filter `myc_getter_presets` to create a new preset. Presets can also vary depend on `$context`:

```
add_filter('myc_getter_presets', function ($presets, $context) {
  $presets['new_preset'] = [
    'fields'    => ['title'],
    'image_size' => 'medium',
  ];

  return $presets;
}, 10, 2);
```

Then, you can use this new preset when instantiate the class:

```
$getter = new MycGetter('new_preset');
```

Modifying Settings After Instantiation
--------------------------------------

[](#modifying-settings-after-instantiation)

If you need to change the image size after creating the getter instance but before generating the image markup, you can use the `setImageSize()` method:

```
$getter = new MycGetter('my_preset');
$getter->setImageSize('thumbnail'); // Change from preset's image_size to 'thumbnail'
```

This method supports method chaining:

```
$getter = new MycGetter('my_preset');
$data = $getter->setImageSize('full')->escapedContent($post);
```

fields
------

[](#fields)

- Format: array

Each field provides a filter to modify the returned content. The filter has three parameters: `$value`, `$post_type` and `$post_id`. Image and URL filters have an additional parameter: `$context`.

### id

[](#id)

- Returns escaped content of `post->ID`
- Format: int
- Filter name: `myc_getter_get_id`

### slug

[](#slug)

- Returns escaped content of `post->post_name`
- Format: string
- Filter name: `myc_getter_get_slug`

### title

[](#title)

- Returns escaped content of `post->post_title`
- Format: string
- Filter name: `myc_getter_get_title`

### url

[](#url)

- Returns escaped permalink
- Format: string
- Filter name: `myc_getter_get_url`

### image

[](#image)

- Returns image markup or image URL based on the value of `image_type` and `image_size`
- Format: string
- Filter name: `myc_getter_get_image`

### text

[](#text)

- Returns escaped content of `post->post_content`
- Format: string
- Filter name: `myc_getter_get_text`

### excerpt

[](#excerpt)

- Returns escaped content of the function `get_the_excerpt($post)`
- Format: string
- Filter name: `myc_getter_get_excerpt`

### date

[](#date)

- Returns escaped dates of the post in two different format: using the global date format and using ISO 8601 (`c`) date format
- Format: array
- Filter name: `myc_getter_get_date`

### post\_type

[](#post_type)

- Returns the post type slug
- Format: string
- Filter name: `myc_getter_get_post_type` (to avoid redundancy, this filter has only two parameters)

image\_size
-----------

[](#image_size)

- Format: string

Use one of the default WordPress image sizes (`thumbnail`, `medium`, `medium_large`, `large`, `full`) or a custom image size created by `add_image_size()` function.

image\_type
-----------

[](#image_type)

- Format: string

Defines the format that the featured image will be returned: `html` or `url`.

acf
---

[](#acf)

- Format: array

List of key/value where the key is the field slug and the value is the field type.

Each field type provides a filter to modify the returned content. The filter has four parameters: `$value`, `$post_type`, `$post_id` and `$field_slug`.

### date

[](#date-1)

- Returns dates in two different format: using the global date format and using ISO 8601 (`c`) date format or `false` if it is empty or the date is not formatted correctly
- Format: array
- Filter name: `myc_getter_get_acf_date`

### time

[](#time)

- Returns time in global time format or `false` if it is empty or the time is not formatted correctly
- Format: string
- Filter name: `myc_getter_get_acf_time`

### datetime

[](#datetime)

- Returns date and time in global date and time format or `false` if it is empty or the value is not formatted correctly
- Format: string
- Filter name: `myc_getter_get_acf_datetime`

### url

[](#url-1)

- Returns escaped url using `esc_url()` function
- Format: string
- Filter name: `myc_getter_get_acf_url`

### link

[](#link)

- Returns escaped link info (`title`, `url`, `target`, `rel`) or `false` if it is empty
- Format: array
- Filter name: `myc_getter_get_acf_link`

### string

[](#string)

- Returns escaped content using `esc_html()` function or `false` if it is empty
- Format: string
- Filter name: `myc_getter_get_acf_string`

### attr

[](#attr)

- Returns escaped content using `esc_attr()` function or `false` if it is empty
- Format: string
- Filter name: `myc_getter_get_acf_attr`

### text

[](#text-1)

- Returns escaped content using `wp_kses_post()` function or `false` if it is empty
- Format: string
- Filter name: `myc_getter_get_acf_text`

### image

[](#image-1)

- Returns the image markup or `false` if the image doesn't exists
- This method also works with the Gallery field type
- Pass the image size inside the key using a pipe (e.g. `image_field|medium`)
- Format: string
- Filter name: `myc_getter_get_acf_image`

### image\_url

[](#image_url)

- Returns the escaped image url or `false` if the image doesn't exists
- Pass the image size inside the key using a pipe (e.g. `image_field|medium`)
- Format: string
- Filter name: `myc_getter_get_acf_image`

### int

[](#int)

- Returns the escaped integer value
- Format: int
- Filter name: `myc_getter_get_acf_int`

### email

[](#email)

- Returns the escaped email value using the function `antispambot()`
- Format: string
- Filter name: `myc_getter_get_acf_email`

### raw

[](#raw)

- Returns the content without any treatment
- Format: string
- Filter name: `myc_getter_get_acf_raw`

### repeater

[](#repeater)

- For repeater fields, pass an array as the value:

```
'acf'      => [
  'cards' => ['headline' => 'string', 'button' => 'link', 'text' => 'string']
],
```

taxonomies
----------

[](#taxonomies)

- Format: array

List of key/value where the key is the taxonomy slug and the value is the desired returned format.

Each format provides a filter to modify the returned content. The filter has four parameters: `$terms`, `$post_type`, `$post_id` and `$taxonomy`.

### all

[](#all)

- Returns the term object without any treatment
- Format: object
- Filter name: `myc_getter_get_terms_object`

### name

[](#name)

- Returns escaped content of `term->name`
- Format: string
- Filter name: `myc_getter_get_terms_name`

### link

[](#link-1)

- Returns escaped content of `term->name` and `get_term_link()` function
- Format: array
- Filter name: `myc_getter_get_terms_link`

### slug/name

[](#slugname)

- Returns escaped content of `term->slug` and `term->name`
- Format: array
- Filter name: `myc_getter_get_terms_slug_name`

### slug/id

[](#slugid)

- Returns escaped content of `term->term_id` and `term->name`
- Format: array
- Filter name: `myc_getter_get_terms_id_name`

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance69

Regular maintenance activity

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~60 days

Recently: every ~114 days

Total

15

Last Release

179d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0d654dde3983bcebf1a9d20c06abeabb95510433bd96f1e178529bebee3316f6?d=identicon)[marcelo2605](/maintainers/marcelo2605)

---

Top Contributors

[![marcelo2605](https://avatars.githubusercontent.com/u/2372927?v=4)](https://github.com/marcelo2605 "marcelo2605 (54 commits)")

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/radishlab-myc-getter/health.svg)

```
[![Health](https://phpackages.com/badges/radishlab-myc-getter/health.svg)](https://phpackages.com/packages/radishlab-myc-getter)
```

###  Alternatives

[lee-to/laravel-seo-by-url

Easy seo for Laravel and MoonShine

239.4k](/packages/lee-to-laravel-seo-by-url)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
