Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/baa63ccd77dbabc353d28a7161a635d0 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/baa63ccd77dbabc353d28a7161a635d0 to your computer and use it in GitHub Desktop.
[SmartCrawl] Add seo description field status column for taxonomy (this MU only check the SEO description field exist and check the length)
<?php
/**
* Plugin Name: [SmartCrawl] Add seo description field status column for taxonomy
* Description: [SmartCrawl] Add seo description field status column for taxonomy (this MU only check the SEO description field exist and check the length)
* Task: 0/11289012348292/1164940045529897
* Author: Thobk @ WPMUDEV
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) { exit; } elseif ( defined( 'WP_CLI' ) && WP_CLI ) { return; }
add_action( 'after_setup_theme', 'wpmudev_sc_seo_desc_status_column_func', 100 );
function wpmudev_sc_seo_desc_status_column_func() {
if( defined('SMARTCRAWL_VERSION') && class_exists( 'Smartcrawl_Autolinks' ) ){
if( ! is_admin() ) return;
class WPMUDEV_SM_DESC_Column_Status_For_Terms{
private $taxonomy;
private $tax_meta;
private $metadesc_length;
private $min;
private $max;
public function __construct( $current_screen ){
if( empty( $current_screen->taxonomy ) || 'edit-tags' !== $current_screen->base ) return;
$taxonomy = get_taxonomy( $current_screen->taxonomy );
if( ! current_user_can( $taxonomy->cap->manage_terms ) ){
return;
}
$this->taxonomy = $current_screen->taxonomy;
$tax_meta = get_option( 'wds_taxonomy_meta' );
$this->tax_meta = isset( $tax_meta[ $this->taxonomy ] ) ? $tax_meta[ $this->taxonomy ] : array();
$this->metadesc_length = new Smartcrawl_Check_Metadesc_Length();
$this->min = $this->metadesc_length->get_min();
$this->max = $this->metadesc_length->get_max();
add_filter( "manage_{$current_screen->id}_columns", array( $this, 'custom_columns') );
add_filter( "manage_{$current_screen->taxonomy}_custom_column", array( $this, 'column_values'), 10, 3 );
}
public function custom_columns( $columns ){
$columns['sc-desc-status'] = '<span class="dashicons dashicons-info" title="Seo description status"></span>';
return $columns;
}
public function column_values( $value, $column_name, $term_id ){
if( 'sc-desc-status' === $column_name ){
$value = '<span class="dashicons dashicons-%s" style="color:%s" title="%s"></span>';
$icon = 'no-alt';
$color = '#dc3232';
$title = __('Need improvement');
if( ! empty( $this->tax_meta[ $term_id ][ 'wds_desc' ] ) ){
$icon = 'yes';
$desc = $this->tax_meta[ $term_id ][ 'wds_desc' ];
}else{
$term = get_term( $term_id, $this->taxonomy );
$desc = $term->description;
}
if( $desc && $this->metadesc_length->is_within_char_length( $desc, $this->min, $this->max ) ){
$color = 'green';
$title = __('OK');
}
$value = sprintf( $value, $icon, $color, $title );
}
return $value;
}
}
add_action( 'current_screen', function( $current_screen ){
$run = new WPMUDEV_SM_DESC_Column_Status_For_Terms( $current_screen );
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment