Skip to content

Releases: lipemat/wordpress-libs

Persistent Memoize Method

06 Feb 19:29
Compare
Choose a tag to compare

Introducing Memoize::persistant

Simple persistent value caching using the object cache is now available via the Memoize trait using the persistent method.

Same functionality as the Memoize::memoize with the different of being persistent across runs. The data is automatically added to the object cache for the specified length of time and will pull from the cache if the arguments are the same for the life of the cache.

Replaces the boilerplate "check cache" if empty "retrieve data" then "add to cache".

   public function get_something_this_is_normally_the_same( $version, $option ) : array {
   	return $this->persistent( function ( $version, $option ) {
   		return [
   			'version' => $version,
   			'option' => $option,
   		];
   	}, __METHOD__ , 0, $version, $option );
  }

CMB2 and Meta Enhancements

14 Jan 23:22
Compare
Choose a tag to compare

Open last used tab after saving CMB2 options page with tabs.

Now saving option pages with tabs will bring you back where you left off after saving instead of reloading with the first tab active.

Support selectively enabling CMB2 fields in rest API.

Leaving show_in_rest set to false on a box and setting it to
a truthy value on a field now automatically sets the box to true
and false for any non specified field.

Introduce new show_in_rest method to the Field class.

Meta repo enhancements

Fallback to default meta handling for non registered meta fields.

Previously to access the meta data from classes using the Mutator trait, you were required to register the field with CMB2 using the helper classes. Now, registering the fields is optional.

You may access any meta data field registered or not using the same methods or array access and repo will fall back to the default WordPress get_metadata automatically.

Add support for accessing an object properties directly.

The various object type traits which extend the mutator trait have now been enhanced to allow for accessing their object properties directly. For instance when using the Post_Object_Trait you may access any of the $post properties directly.

The only requirement for this functionality to work, is the class using the mutator trait must have a get_object() method which returns the object who's properties you want to access. To honor this pattern the previous methods such as get_post(), get_user(), get_term(), etc. have been deprecated in favor of using get_object() on each.

Call defined escape_cb or sanitize_cb arguments when accessing meta values.

When registering CMB2 fields we may specify escape_cb for retrieval and sanitize_cb for saving. Typically these callbacks are only called during meta box saving or retrieval.

The meta repo now honors both these callbacks during get or update. If a callback is not specified the meta repo continues without sanitization or escaping like before.

Introduce `Util\Colors` class

13 Nov 16:44
Compare
Choose a tag to compare

New Utility Class for working with colors.

Most useful when dealing with transparency conversions.

Util\Colors::hex_to_rgba( '#cb5699', 0.8 ); // Returns `rgba(203, 86, 153, 0.8)`
Util\Colors::rgba_to_hex( 'rgba(203, 86, 153, 0.8)', 0.8 ); // Returns `#cb5699`

Script and Style improvements

06 Nov 21:02
Compare
Choose a tag to compare

Various improvements to the Theme\Styles class

New methods for enabling "async" and "defer" on registered scripts.

Helper methods to add the necessary attributes to any script cue via wp_enqueue_script.

/**
	 * Async an enqueued script by handle.
	 *
	 * May be called before or after `wp_enqueue_script` but must be called
	 * before either `wp_print_scripts()` or `wp_print_footer_scripts() depending
	 * on if enqueued for footer of header.
	 *
	 * Downloads the file during HTML execution and executes it only after HTML parsing is completed.
	 * Will not block the browser during download.
	 * Good replacement for any script which uses a `jQuery(document).ready` or window.onload.
	 * Defer scripts are also guaranteed to execute in the order they appear in the document
	 * but after any non defer script.
	 *
	 * A positive effect of this attribute is that the DOM will be available for your script.
	 *
	 *
	 * @param string $handle - The handle used to enqueued this script.
	 *
	 *
	 * @return void
	 */
Styles::in()->defer_javascript( $handle );


/**
	 * Defer an enqueued script by handle.
	 *
	 * May be called before or after `wp_enqueue_script` but must be called
	 * before either `wp_print_scripts()` or `wp_print_footer_scripts() depending
	 * on if enqueued for footer of header.
	 *
	 * Downloads the file during HTML execution and executes it when finished downloading.
	 * Will not block the browser during download.
	 * Executes at an unpredictable time so must be self contained.
	 * Good for scripts such as Google Analytics.
	 *
	 *
	 * @param string $handle - The handle used to enqueued this script.
	 *
	 * @return void
	 */
Styles::in()->async_javascript( $handle );

Live reload now loads asynchronously.

When using the live_reload method the script is now loaded with the "async" attribute added to prevent any render blocking. This is especially useful when you don't have a watch running.

Support for adding a body classes.

Helper method to quickly add a body class to the currently loading page/template.

/**
	 * Add a class to the body.
	 *
	 * Must be called before `get_body_class` which is most likely called
	 * in the theme's "header.php".
	 *
	 *
	 * @param string $class
         *
         * @return void
	 */
Styles::in()->body_class( $class );

Miscellaneous

  1. Some Readme.md improvements.
  2. Improved styles for CMB2 group heading labels.

Crypt, Comment, and Meta

31 Aug 20:51
Compare
Choose a tag to compare

A bit of splatter-board release. :-)

Introducing a new Util/Crypt class for two-way encryption using custom keys.

$crypt = new Crypt( 'my special key that only this user knows');
$encrypted = $crypt->encrypt( 'I have a secret' );
echo $crypt->decrypt();

You get the idea. Customizing this class can be done by extending it and replacing any of the class constants. Beyond that it should meet all encryption needs.

Support Comments within Rest_Api\Initial_Data

Now you may use the same prerending for rest api results for comments just like you could before for posts.

echo json_encode( Initial_Data::in()->get_comments_data( [ WP_Comment::get_instance(1) ] ) );

Callback support for the various object's update_meta() methods. The previous value is passed the the callback.

Post_Object_Trait::factory( 1 )->update_meta( 'this-meta-key', function( $old_meta_value ) {
     return 'new meta value';
} );

Optionally you may pass a third argument which will be used as the default value whenget_meta is called.

Post_Object_Trait::factory( 1 )->update_meta( 'this-meta-key', function( array $old_meta_value ) {
     return 'new meta value';
}, array() );

Api Improvements and CMB2 Styles

12 Aug 17:26
Compare
Choose a tag to compare

Api Improvements

The majority of this release focused around giving the Api\Api functionality a face-lift and overcoming long term limitations with arguments.

Passing data as an associative array

The new \Lipe\Lib\Api\Api::get_url method accepts an associative array as the data parameter. If an associative array is passed, the endpoint will automatically:

  1. Spread the key => values into the url.
  2. Pass an associative array of key => value pairs to the registered action.
    If a numeric array is passed, the original behavior of new deprecated get_api_url will continue.

New Util\Arrays method called array_chunk_to_associative

This new method takes a numeric array and turns it into an associate array using the odd values as keys and even values as values.

For example this array [ 'page', '4', 'category', '6' ] turns into [ 'page' => '4', 'category' => '6' ].

Useful for situations where named data is being passed as a permalink such as /page/4/category/6.

Deprecate the Rest_Api\Post_Abstract class

80% of the functionality added by this class is now available via the CORE rest api. This class is also using an outdated pattern which doesn't really fit in with the rest of this namespace. If you are using this class, you should start porting any needed functionality into your parent classes this class will be removed in version 3.

Improved CMB2 Styles

  1. All default group layout to work when left as block.
  2. Improve Tab styles for option pages.
  3. Deprecate the useless parameter for file_list => show_text_input.

Support version 2 of WPCS

Now that VIP has launched version 2 of their coding standards, we can use version 2 of WPCS and version 3 of PHPCS. The phpcs.xml has been updated to support these new versions.

Prepare for version 3 of this library

Version 3 is going to be removing all deprecated everything from this library. If you have anything throwing deprecated notices and or being flagged as deprecated by your IDE, now is the time to refactor it to non deprecated usages.

Once version 3 is released, you will have no choice but to either stay on version 2 or refactor your usages to non deprecated usages. A full list will be published at that time.

Introducing `Version` Trait

08 Jul 18:53
Compare
Choose a tag to compare

Per class versioning now possible via new Version trait.

class Stuff_With_One_Time_Calls {
	use \Lipe\Lib\Traits\Version;

	public function __construct() {
		$this->run_for_version( [ $this, 'update_something' ], '1.0.0' );
	}

	public function update_something() : void {
		echo 'I ran only one time, on sites where the version for this class was < 1.0.0';
	}
}

Notice this example class holds it's own version and does not need to be aware of any other version anywhere in the application. Increment, the version in this class and it will only affect this class and it's calls.

CMB2 Tab Improvements

  1. Fix tabs that have a / in it's identifier.
  2. Gracefully handle when a tab and group layout are used together.

CMB2 Group Field Translations

19 Jun 12:30
Compare
Choose a tag to compare

No more manual translations of group fields!

Fields which are now part of a CMB2 group now receive the same treatment as top level fields when their values are retrieved or updated.

There is a very slight possibility of breaking changes if you were previously doing strict typing when retrieving values. To fix simply use the received post translation types.

Maintenance Release

03 Jun 16:45
Compare
Choose a tag to compare

Maintenance Release

  1. Add clear_memoize_cache method to the Memoize trait to allow for clearing cache programmatically.
  2. Improvement to phpdocs for Initital_Data rest api class.

Introducing Site_Trait

11 Apr 15:32
Compare
Choose a tag to compare

Brand New Namespace Called Site

Within this namespace you will find a new class called Site_Trait which may be used the same way as all the other object type traits.

  • Interact with a single site on a multisite install.
  • Gives quick access to the blogmeta table and any other properties available in the WP_Site class.

Other Additions

The Api\Api class got an overhaul to make it more encapsulated and easier to reference.

  1. The Query args is now namespaced.
  2. The internal methods are now "protected" and called via closures.
  3. New method called get_action was added to allow simple/stable retrieval of the correct action name.