* @copyright Copyright (c) 2008 - 2017, Justin Tadlock * @link https://themehybrid.com/hybrid-core * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ /** * Singleton class for handling the term layout feature. * * @since 4.0.0 * @access public */ final class Hybrid_Admin_Term_Layout { /** * Returns the instance. * * @since 4.0.0 * @access public * @return object */ public static function get_instance() { static $instance = null; if ( is_null( $instance ) ) { $instance = new self; $instance->setup_actions(); } return $instance; } /** * Constructor method. * * @since 4.0.0 * @access private * @return void */ private function __construct() {} /** * Sets up initial actions. * * @since 4.0.0 * @access private * @return void */ private function setup_actions() { if ( ! current_theme_supports( 'theme-layouts', 'term_meta' ) ) return; // Load on the edit tags screen. add_action( 'load-tags.php', array( $this, 'load' ) ); add_action( 'load-edit-tags.php', array( $this, 'load' ) ); // Update term meta. add_action( 'create_term', array( $this, 'save' ) ); add_action( 'edit_term', array( $this, 'save' ) ); } /** * Runs on the load hook and sets up what we need. * * @since 4.0.0 * @access public * @return void */ public function load() { if ( ! current_user_can( 'edit_theme_options' ) ) return; $screen = get_current_screen(); // Add the form fields. add_action( "{$screen->taxonomy}_add_form_fields", array( $this, 'add_form_fields' ) ); add_action( "{$screen->taxonomy}_edit_form_fields", array( $this, 'edit_form_fields' ) ); // Enqueue scripts/styles. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); } /** * Enqueues scripts/styles. * * @since 4.0.0 * @access public * @return void */ public function enqueue() { wp_enqueue_style( 'hybrid-admin' ); add_action( 'admin_footer', 'hybrid_layout_field_inline_script' ); } /** * Displays the layout selector in the new term form. * * @since 4.0.0 * @access public * @return void */ public function add_form_fields() { ?>