mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-07-18 22:13:20 +09:00
add taxonomies class
sets up featured image for taxonomies. not applied to output yet.
This commit is contained in:
@@ -31,6 +31,7 @@ require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesi
|
||||
require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis-output.php';
|
||||
require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis-rss.php';
|
||||
require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis-settings.php';
|
||||
require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis-taxonomies.php';
|
||||
|
||||
// Instantiate dependent classes
|
||||
$displayfeaturedimagegenesis_common = new Display_Featured_Image_Genesis_Common();
|
||||
@@ -38,13 +39,15 @@ $displayfeaturedimagegenesis_description = new Display_Featured_Image_Genesis_De
|
||||
$displayfeaturedimagegenesis_output = new Display_Featured_Image_Genesis_Output();
|
||||
$displayfeaturedimagegenesis_rss = new Display_Featured_Image_Genesis_RSS();
|
||||
$displayfeaturedimagegenesis_settings = new Display_Featured_Image_Genesis_Settings();
|
||||
$displayfeaturedimagegenesis_taxonomies = new Display_Featured_Image_Genesis_Taxonomies();
|
||||
|
||||
$displayfeaturedimage = new Display_Featured_Image_Genesis(
|
||||
$displayfeaturedimagegenesis_common,
|
||||
$displayfeaturedimagegenesis_description,
|
||||
$displayfeaturedimagegenesis_output,
|
||||
$displayfeaturedimagegenesis_rss,
|
||||
$displayfeaturedimagegenesis_settings
|
||||
$displayfeaturedimagegenesis_settings,
|
||||
$displayfeaturedimagegenesis_taxonomies
|
||||
);
|
||||
|
||||
$displayfeaturedimage->run();
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* settings for taxonomy pages
|
||||
*
|
||||
* @package DisplayFeaturedImageGenesis
|
||||
* @since x.y.z
|
||||
*/
|
||||
class Display_Featured_Image_Genesis_Taxonomies {
|
||||
|
||||
function set_taxonomy_meta() {
|
||||
$args = array( 'public' => true );
|
||||
$output = 'objects';
|
||||
$taxonomies = get_taxonomies( $args, $output );
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
add_action( $taxonomy->name . '_add_form_fields', array( $this, 'add_taxonomy_meta_fields' ), 5, 2 );
|
||||
add_action( $taxonomy->name . '_edit_form_fields', array( $this, 'edit_taxonomy_meta_fields' ), 5, 2 );
|
||||
add_action( 'edited_' . $taxonomy->name, array( $this, 'save_taxonomy_custom_meta' ), 10, 2 );
|
||||
add_action( 'create_' . $taxonomy->name, array( $this, 'save_taxonomy_custom_meta' ), 10, 2 );
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function add_taxonomy_meta_fields() {
|
||||
|
||||
//* this will add the custom meta field to the add new term page
|
||||
echo '<div class="form-field">';
|
||||
echo '<label for="term_meta[dfig_image]">' . __( 'Featured Image', 'display-featured-image-genesis' ) . '</label>';
|
||||
echo '<input type="url" id="default_image_url" name="term_meta[dfig_image]" value="" />';
|
||||
echo '<input id="upload_default_image" type="button" class="upload_term_meta_image button" value="' . __( 'Select Image', 'display-featured-image-genesis' ) . '" />';
|
||||
echo '<p>' . __( 'Set Featured Image for Taxonomy','display-featured-image-genesis' ) . '</p>';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
//* Edit term page
|
||||
function edit_taxonomy_meta_fields( $term ) {
|
||||
|
||||
//* put the term ID into a variable
|
||||
$t_id = $term->term_id;
|
||||
|
||||
//* retrieve the existing value(s) for this meta field. This returns an array
|
||||
$term_meta = get_option( "taxonomy_$t_id" );
|
||||
//* this will add the custom meta field to the add new term page
|
||||
echo '<tr class="form-field">';
|
||||
echo '<th scope="row" valign="top"><label for="term_meta[dfig_image]">' . __( 'Featured Image', 'display-featured-image-genesis' ) . '</label></th>';
|
||||
echo '<td>';
|
||||
if ( ! empty( $term_meta['dfig_image'] ) ) {
|
||||
$id = Display_Featured_Image_Genesis_Common::get_image_id( $term_meta['dfig_image'] );
|
||||
$preview = wp_get_attachment_image_src( $id, 'medium' );
|
||||
echo '<div id="upload_logo_preview">';
|
||||
echo '<img src="' . esc_url( $preview[0] ) . '" width="300" />';
|
||||
echo '</div>';
|
||||
}
|
||||
echo '<input type="url" id="default_image_url" name="term_meta[dfig_image]" value="' . esc_url( $term_meta['dfig_image'] ) . '" />';
|
||||
echo '<input id="upload_default_image" type="button" class="upload_default_image button" value="' . __( 'Select Image', 'display-featured-image-genesis' ) . '" />';
|
||||
echo '<p>' . __( 'Set Featured Image for Taxonomy', 'display-featured-image-genesis' ) . '</p>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
//* Save extra taxonomy fields callback function.
|
||||
function save_taxonomy_custom_meta( $term_id ) {
|
||||
if ( isset( $_POST['term_meta'] ) ) {
|
||||
$t_id = $term_id;
|
||||
$term_meta = get_option( "taxonomy_$t_id" );
|
||||
$cat_keys = array_keys( $_POST['term_meta'] );
|
||||
foreach ( $cat_keys as $key ) {
|
||||
if ( isset ( $_POST['term_meta'][$key] ) ) {
|
||||
$term_meta[$key] = $_POST['term_meta'][$key];
|
||||
}
|
||||
}
|
||||
//* Save the option array.
|
||||
update_option( "taxonomy_$t_id", $term_meta );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* enqueue admin scripts
|
||||
* @return scripts to use image uploader
|
||||
*
|
||||
* @since 1.2.1
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
$version = Display_Featured_Image_Genesis_Common::$version;
|
||||
|
||||
wp_register_script( 'displayfeaturedimage-upload', plugins_url( '/includes/js/settings-upload.js', dirname( __FILE__ ) ), array( 'jquery', 'media-upload', 'thickbox' ), $version );
|
||||
|
||||
if ( ! empty( get_current_screen()->taxonomy ) ) {
|
||||
wp_enqueue_media();
|
||||
wp_enqueue_script( 'displayfeaturedimage-upload' );
|
||||
wp_localize_script( 'displayfeaturedimage-upload', 'objectL10n', array(
|
||||
'text' => __( 'Choose Image', 'display-featured-image-genesis' ),
|
||||
) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,12 +16,13 @@
|
||||
*/
|
||||
class Display_Featured_Image_Genesis {
|
||||
|
||||
function __construct( $common, $description, $output, $rss, $settings ) {
|
||||
$this->common = $common;
|
||||
$this->archive = $description;
|
||||
$this->output = $output;
|
||||
$this->rss = $rss;
|
||||
$this->settings = $settings;
|
||||
function __construct( $common, $description, $output, $rss, $settings, $taxonomies ) {
|
||||
$this->common = $common;
|
||||
$this->archive = $description;
|
||||
$this->output = $output;
|
||||
$this->rss = $rss;
|
||||
$this->settings = $settings;
|
||||
$this->taxonomies = $taxonomies;
|
||||
}
|
||||
|
||||
public function run() {
|
||||
@@ -33,6 +34,7 @@ class Display_Featured_Image_Genesis {
|
||||
|
||||
add_action( 'init', array( $this, 'add_plugin_supports' ) );
|
||||
add_action( 'admin_init', array( $this, 'check_settings' ) );
|
||||
add_action( 'admin_init', array( $this->taxonomies, 'set_taxonomy_meta' ), 10, 2 );
|
||||
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
|
||||
add_action( 'admin_menu', array( $this->settings, 'do_submenu_page' ) );
|
||||
add_action( 'get_header', array( $this->output, 'manage_output' ) );
|
||||
|
||||
Reference in New Issue
Block a user