Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix main class, allows loading on options pages #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Once you have the post data for the post ID, you can proceed with the desired fu

## Changelog

### 1.2.5
* Update to allow usage on options pages. Props [JayWood](https://github.com/jaywood/)

### 1.2.4
* Add support for attaching Users instead of Posts/Custom Posts. Props [mckernanin](https://github.com/mckernanin) ([#27](https://github.com/WebDevStudios/cmb2-attached-posts/pull/27)).

Expand Down
66 changes: 22 additions & 44 deletions cmb2-attached-posts-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* Loader versioning: http://jtsternberg.github.io/wp-lib-loader/
*/

if ( ! class_exists( 'WDS_CMB2_Attached_Posts_Field_124', false ) ) {
if ( ! class_exists( 'WDS_CMB2_Attached_Posts_Field_125', false ) ) {

/**
* Versioned loader class-name
Expand All @@ -61,14 +61,20 @@
* @link https://github.com/WebDevStudios/cmb2-attached-posts
* @since 1.2.3
*/
class WDS_CMB2_Attached_Posts_Field_124 {
class WDS_CMB2_Attached_Posts_Field_125 {

/**
* Instance of WDS_CMB2_Attached_Posts_Field_125
* @var WDS_CMB2_Attached_Posts_Field_125
*/
public static $instance = null;

/**
* WDS_CMB2_Attached_Posts_Field version number
* @var string
* @since 1.2.3
*/
const VERSION = '1.2.4';
const VERSION = '1.2.5';

/**
* Current version hook priority.
Expand All @@ -79,18 +85,15 @@ class WDS_CMB2_Attached_Posts_Field_124 {
*/
const PRIORITY = 9998;

/**
* Starts the version checking process.
* Creates CMB2_ATTACHED_POSTS_FIELD_LOADED definition for early detection by
* other scripts.
*
* Hooks WDS_CMB2_Attached_Posts_Field inclusion to the cmb2_attached_posts_field_load hook
* on a high priority which decrements (increasing the priority) with
* each version release.
*
* @since 1.2.3
*/
public function __construct() {
public static function init() {
if ( null == self::$instance ) {
self::$instance = new self();
}

return self::$instance;
}

private function __construct() {
if ( ! defined( 'CMB2_ATTACHED_POSTS_FIELD_LOADED' ) ) {
/**
* A constant you can use to check if WDS_CMB2_Attached_Posts_Field is loaded
Expand All @@ -102,34 +105,10 @@ public function __construct() {
define( 'CMB2_ATTACHED_POSTS_FIELD_LOADED', self::PRIORITY );
}

// Use the hook system to ensure only the newest version is loaded.
add_action( 'cmb2_attached_posts_field_load', array( $this, 'include_lib' ), self::PRIORITY );

// Use the hook system to ensure only the newest version is loaded.
add_action( 'after_setup_theme', array( $this, 'do_hook' ) );
}

/**
* Fires the cmb2_attached_posts_field_load action hook
* (from the after_setup_theme hook).
*
* @since 1.2.3
*/
public function do_hook() {
// Then fire our hook.
do_action( 'cmb2_attached_posts_field_load' );
add_action( 'cmb2_init', array( $this, 'include_attached_posts' ) );
}

/**
* A final check if WDS_CMB2_Attached_Posts_Field exists before kicking off
* our WDS_CMB2_Attached_Posts_Field loading.
*
* CMB2_ATTACHED_POSTS_FIELD_VERSION and CMB2_ATTACHED_POSTS_FIELD_DIR constants are
* set at this point.
*
* @since 1.2.3
*/
public function include_lib() {
public function include_attached_posts() {
if ( class_exists( 'WDS_CMB2_Attached_Posts_Field', false ) ) {
return;
}
Expand All @@ -151,9 +130,8 @@ public function include_lib() {
// Include and initiate WDS_CMB2_Attached_Posts_Field.
require_once CMB2_ATTACHED_POSTS_FIELD_DIR . 'init.php';
}

}

// Kick it off.
new WDS_CMB2_Attached_Posts_Field_124;
// Load similarly to CMB2
WDS_CMB2_Attached_Posts_Field_125::init();
}