Skip to content

Releases: lipemat/wordpress-libs

CMB2 2.6.0 Support

09 Apr 16:38
Compare
Choose a tag to compare

Important! If you are going to use CMB2 2.6.0+ you must update to this version or newer or the group layouts will break.

Misc Improvments

21 Mar 16:16
Compare
Choose a tag to compare

1. Introduce a once method to the Memoize trait for methods that require constant memoized results.

2. Improve the field attributes for text_url fields.

3. Support the full range of labels when using Taxonomy_Extended

Memoize Trait

17 Mar 23:04
Compare
Choose a tag to compare

Brand new way to memorize method returns for methods which have rotating arguments.

  1. Use the trait in your class.
  2. Call $this->memoize
  3. Enjoy the free caching.
$test = new class {
	use \Lipe\Lib\Traits\Memoize;


	public function heavy( $text ) {
		return $this->memoize( function ( $text ) {
			echo 'called' . "\n";

			return $text;
		}, __METHOD__, $text );
	}
};
$test->heavy( 'as can be' . "\n" ); //called
$test->heavy( 'as can be x2' . "\n" ); //called
$test->heavy( 'aas can be X3' . "\n" ); // called
$test->heavy( 'as can be x2' . "\n" ); //Not called

ArrayAcesss Mutators For Object Types

12 Feb 21:11
Compare
Choose a tag to compare

Introducing delete_value and update_value from the Meta\Repo.

The full range of getting, setting, and deleting is now available from the Meta\Repo. class instead of previously only having a get_value method. Each method automatically translates the data into the correct format before saving as well as deleting all appropriate date when deleting.

Object traits now have delete_meta and update_meta methods available.

These method call the appropriate methods from the Meta\Repo to translate the data automatically.

$o = new Post_Object_Trait::factory( 1 );
$o->update_meta( 'test', 'ok' );
($o->get_meta('test') === 'ok' ) //true
$o->delete_meta('test');
($o->get_meta('test') === 'ok' ) //false

ArrayAccess Available for Object traits.

An optional feature has been added to all Object traits with support enabling ArrayAccess modifiers. You may opt into this functionality by implementing the \ArrayAccess interface on your classes which use the Object traits.

class Post implements \ArrayAccess {
	use Post_Object_Trait;
}

$o = Post::factory(1);
$o['test'] = 'ok'; //updates the post meta
echo $o['test']; //echos 'ok
unset($o['test']); //deletes the post meta

** Note: The ArrayAccess modifiers do use the same methods as the object trait to interact with Meta\Repo so all fields still need to be registered via the CMB2\Box. **

Fix Saving Of Meta Box Schema

31 Jan 19:28
Compare
Choose a tag to compare

When using the Schema/Meta_Box abstract the values were not saving correctly.

This fixes that issue.

Network Options And Singular Term Fields

30 Jan 20:18
Compare
Choose a tag to compare

This version enhances the handling of options and terms.

New network method on the CMB2\Options_Page class.

Calls this method to make the settings appear as network settings. Works the same as setting the admin_menu_hook property to network_admin_menu.

$box = new Options_Page( 'options-page-id', __( 'Theme Settings', 'lipe' ) );
$box->network();

Now objects using the Settings_Trait with automatically pull from the stored networks settings when calling get_option or update_option.

class Class_Using_Settings_Trait {
     use Settings_Trait;
     public const NAME = 'options-page-id';
}

$settings = new Class_Using_Settings_Trait();
$settings->get_option();

Taxonomy field improvements

Now returned values will be consistent whether the taxonomy field is within options or a meta box.

  1. All returned values will the full term objects.
  2. Singular term fields will return a single term or false.

Misc Enhancements

09 Jan 17:12
Compare
Choose a tag to compare

This release included a few improvements and enhancements

  1. Improved handling of flush_rewrite_rules when registering post_types.
  2. Bring back the Util\Url class.
  3. Support setting Gutenberg templates when registering post_types.

Misc Enhancements

04 Jan 16:46
Compare
Choose a tag to compare

A few improvements

  1. Notify with an error if trying to make a field repeatable which does not support repeating.
  2. Phpdoc improvements on Cron\Cron_Abstract.
  3. Modernize the Api\Api class.
  4. Support rest_value_cb in CMB2\Field.
  5. Add methods to CMB2\Field for sanitization_cb and escape_cb.

Array Utils

21 Dec 18:59
Compare
Choose a tag to compare

New Class Utils\Arrays

Beginnings if a central place to store specialize array handling. Starting with the first method array_merge_recursive which works like the native array_merge_recursive but it preserves data types. Think of it like wp_parse_args_recursive.

/**
	 * Works the same as `array_merge_recursive` except instead of turning
	 * duplicate array keys into arrays, this will favor the $args over
	 * the $defaults and clobber identical $default keys.
	 *
	 * @param array $args
	 * @param array $defaults
	 *
	 * @since 2.1.0
	 *
	 * @return array
	 */
	public function array_merge_recursive( array $args, array $defaults ) : array {

Improvements to Field_Type::textarea_code()

  1. Pass language as a parameter.
  2. Pass code_editor_arguments as a parameter.
/**
	 * Code textarea.
	 *
	 * The defaults are most likely what you want to use, but just in case
	 * there are arguments for specialize fine tuning
	 *
	 * @link https://github.com/CMB2/CMB2/wiki/Field-Types#textarea_code
	 * @link https://www.ibenic.com/wordpress-code-editor#file-code-editor-js
	 *
	 * @param bool   $disable_codemirror    - disable code mirror handling in favor or a basic textbox
	 * @param string $language              - [clike, css, diff, htmlmixed, http, javascript, jsx, markdown, gfm,
	 *                                      nginx, php, sass, shell, sql, xml, yaml]
	 * @param array  $code_editor_arguments - The arguments are then passed to `wp.codeEditor.initialize` method.
	 *
	 * @return Field
	 */
	public function textarea_code( bool $disable_codemirror = false, ?string $language = null, array $code_editor_arguments = [] ) : Field {

Version 2!

20 Dec 21:12
Compare
Choose a tag to compare

CAUTION! BREAKING CHANGES

Migration guide

A lot of structure has been re-done with the release:

  1. Some classes have been removed.
  2. Some classes have been moved.
  3. Some methods have changed.
  4. Some scopes have changed.

All of the basics still exist from version 1, it just may take a different path to use the functionality.

If you are going to switch an existing project to version 2, make sure you give yourself plenty of time to update and run your unit tests.

The most exciting change in this version is the new Meta\Repo

I was never quite satisfied with the old structure. It had too many layers and do many ways to extend the simple task of retrieving meta for an object. Not to mention, you had to track your own meta types and use custom methods to massage CMB2 data.

not any more

The new Meta\Repo now automatically tracks the fields that are registered via the CMB2\Field class. The type of fields is also tracked and the proper data type is automatically returned!

$value = Repo::instance()->get_value( $post_id, $key );