From 419caaf740690fe37c09ee0bb8265f8ce768d1e1 Mon Sep 17 00:00:00 2001
From: Ben Huson
+
+ current_user_can_edit() ) {
+ return;
+ }
+
+ if ( isset( $_POST[ 'wps_subtitle' ] ) ) {
+ $term_subtitle->update_subtitle( $_POST[ 'wps_subtitle' ] );
+ }
+
+ }
+
+ /**
+ * Get Supported Taxonomies
+ *
+ * @return array
+ */
+ private static function get_supported_taxonomies() {
+
+ return apply_filters( 'plugins/wp_subtitle/supported_taxonomies', array( 'category' ) );
+
+ }
+
+}
diff --git a/plugin/includes/class-api.php b/plugin/includes/class-api.php
index e078b04..68b00ad 100644
--- a/plugin/includes/class-api.php
+++ b/plugin/includes/class-api.php
@@ -34,6 +34,9 @@ public function setup_hooks() {
add_action( 'plugins/wp_subtitle/the_subtitle', array( $this, 'the_subtitle' ) );
add_filter( 'plugins/wp_subtitle/get_subtitle', array( $this, 'get_subtitle' ), 10, 2 );
+ add_action( 'plugins/wp_subtitle/the_term_subtitle', array( $this, 'the_term_subtitle' ) );
+ add_filter( 'plugins/wp_subtitle/get_term_subtitle', array( $this, 'get_term_subtitle' ), 10, 2 );
+
}
/**
@@ -62,11 +65,7 @@ public function the_subtitle( $args = '' ) {
*/
public function get_subtitle( $default_subtitle, $args = '' ) {
- $args = wp_parse_args( $args, array(
- 'post_id' => get_the_ID(), // Post ID
- 'before' => '', // Before subtitle HTML output
- 'after' => '' // After subtitle HTML output
- ) );
+ $args = $this->post_parse_args( $args );
$subtitle_obj = new WP_Subtitle( $args['post_id'] );
$subtitle = $subtitle_obj->get_subtitle( $args );
@@ -79,4 +78,85 @@ public function get_subtitle( $default_subtitle, $args = '' ) {
}
+ /**
+ * The Term Subtitle (Action)
+ *
+ * @param array $args Display args.
+ */
+ public function the_term_subtitle( $args = '' ) {
+
+ echo apply_filters( 'plugins/wp_subtitle/get_term_subtitle', '', $args );
+
+ }
+
+ /**
+ * The Subtitle (Filter)
+ *
+ * @param string $subtitle Subtitle.
+ * @param array $args Display args.
+ * @return string Subtitle.
+ */
+ public function get_term_subtitle( $subtitle = '', $args = '' ) {
+
+ $args = $this->term_parse_args( $args );
+
+ $subtitle = new WP_Subtitle_Term( $args['term_id'] );
+
+ return $this->get_display( $subtitle->get_meta_value(), $args );
+
+ }
+
+ /**
+ * Get Display
+ *
+ * @param string $subtitle Subtitle.
+ * @param array $args Display args.
+ * @return string Subtitle.
+ */
+ protected function get_display( $subtitle, $args ) {
+
+ if ( ! empty( $subtitle ) ) {
+ $subtitle = $args['before'] . $subtitle . $args['after'];
+ }
+
+ return $subtitle;
+
+ }
+
+ /**
+ * Post Parse Args
+ *
+ * @param array $args Args.
+ * @return array Args.
+ */
+ protected function post_parse_args( $args = '' ) {
+
+ $args = wp_parse_args( $args, array(
+ 'post_id' => get_the_ID(), // Post ID
+ 'before' => '', // Before subtitle HTML output
+ 'after' => '' // After subtitle HTML output
+ ) );
+
+ return $args;
+
+ }
+
+ /**
+ * Term Parse Args
+ *
+ * @param array $args Args.
+ * @return array Args.
+ */
+ protected function term_parse_args( $args = '' ) {
+
+ $args = wp_parse_args( $args, array(
+ 'term_id' => is_category() || is_tag() || is_tax() ? get_queried_object_id() : 0,
+ 'before' => '',
+ 'after' => ''
+ ) );
+
+ return $args;
+
+ }
+
}
diff --git a/plugin/includes/subtitle-term.php b/plugin/includes/subtitle-term.php
new file mode 100644
index 0000000..4c0b9b7
--- /dev/null
+++ b/plugin/includes/subtitle-term.php
@@ -0,0 +1,98 @@
+object_id = absint( $term->term_id );
+ } else {
+ $this->object_id = absint( $term );
+ }
+
+ }
+
+ /**
+ * Get Meta Value
+ *
+ * @return string The subtitle meta value.
+ */
+ public function get_meta_value() {
+
+ return get_term_meta( $this->object_id, $this->get_meta_key(), true );
+
+ }
+
+ /**
+ * Update Subtitle
+ *
+ * @param string $subtitle Subtitle.
+ * @return integer|WP_Error|bool Meta ID if new entry. True if updated, false if not updated or the same
+ * as current value. WP_Error when term_id is ambiguous between taxonomies.
+ */
+ public function update_subtitle( $subtitle ) {
+
+ $subtitle = trim( sanitize_text_field( $subtitle ) );
+
+ if ( '' == $subtitle ) {
+ return $this->delete_subtitle();
+ }
+
+ return update_term_meta( $this->object_id, $this->get_meta_key(), $subtitle );
+
+ }
+
+ /**
+ * Delete Subtitle
+ *
+ * @return boolean True if deleted, false if failed.
+ */
+ protected function delete_subtitle() {
+
+ return delete_term_meta( $this->object_id, $this->get_meta_key() );
+
+ }
+
+ /**
+ * Get Meta Key
+ *
+ * @return string The subtitle meta key.
+ */
+ protected function get_meta_key() {
+
+ return 'wps_subtitle';
+
+ }
+
+ /**
+ * Current User Can Edit
+ *
+ * @return boolean
+ */
+ public function current_user_can_edit() {
+
+ $term = get_term( $this->object_id );
+ $tax = get_taxonomy( $term->taxonomy );
+
+ return current_user_can( $tax->cap->edit_terms );
+
+ }
+
+}
diff --git a/plugin/plugin.php b/plugin/plugin.php
index 09f193d..b560332 100644
--- a/plugin/plugin.php
+++ b/plugin/plugin.php
@@ -14,6 +14,7 @@
// Includes
include_once( WPSUBTITLE_DIR . 'includes/class-api.php' );
include_once( WPSUBTITLE_DIR . 'includes/subtitle.php' );
+require_once( WPSUBTITLE_DIR . 'includes/subtitle-term.php' );
include_once( WPSUBTITLE_DIR . 'includes/deprecated.php' );
include_once( WPSUBTITLE_DIR . 'includes/shortcode.php' );
include_once( WPSUBTITLE_DIR . 'includes/rest.php' );
@@ -24,6 +25,8 @@
// Include admin-only functionality
if ( is_admin() ) {
require_once( WPSUBTITLE_DIR . 'admin/admin.php' );
+ require_once( WPSUBTITLE_DIR . 'admin/admin-terms.php' );
+
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
// Load AJAX functions here if required...
} else {
From cb49d9d96ada36a709e034246c029f58525e9703 Mon Sep 17 00:00:00 2001
From: Ben Huson
+
+
', // Before subtitle HTML output (default empty string) + * 'after' => '
', // After subtitle HTML output (default empty string) + * 'term_id' => 0, // Term ID (default to none) + * 'default_value' => '' // Default output (if no subtitle) + * ) ); + * + * // Example: Get term subtitle display + * $subtitle = apply_filters( 'plugins/wp_subtitle/get_term_subtitle', '', array( + * 'before' => '', // Before subtitle HTML output (default empty string) + * 'after' => '
', // After subtitle HTML output (default empty string) + * 'term_id' => 0 // Term ID (default to none) + * ) ); + * + * // Example: Display archive subtitle + * do_action( 'plugins/wp_subtitle/the_archive_subtitle', array( + * 'before' => '', // Before subtitle HTML output (default empty string) + * 'after' => '
', // After subtitle HTML output (default empty string) + * 'default_value' => '' // Default output (if no subtitle) + * ) ); + * + * // Example: Get archive subtitle display + * $subtitle = apply_filters( 'plugins/wp_subtitle/get_archive_subtitle', '', array( + * 'before' => '', // Before subtitle HTML output (default empty string) + * 'after' => '
', // After subtitle HTML output (default empty string) + * ) ); */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -123,6 +151,9 @@ public function the_archive_subtitle( $args = '' ) { /** * The Archive Subtitle (Filter) * + * If the main blog page when posts page is set, get the subtitle of the page. + * If a categiry/tag/term archive, get the term subtitle. + * * @param string $subtitle Subtitle. * @param array $args Display args. * @return string Subtitle.