ID, 'aeoora_nonce' );
$faq = Aeoora_Schema::get_faq( $post->ID );
$tldr = (string) get_post_meta( $post->ID, '_aeoora_tldr', true );
$exclude = (bool) get_post_meta( $post->ID, '_aeoora_exclude', true );
$seo = Aeoora_Seo::active_label();
$title = (string) get_post_meta( $post->ID, '_aeoora_meta_title', true );
$desc = (string) get_post_meta( $post->ID, '_aeoora_meta_desc', true );
$kw = (string) get_post_meta( $post->ID, '_aeoora_focus_kw', true );
$ai = Aeoora_Util::can_use_ai();
?>
–
post_status && Aeoora_Markdown::is_eligible( $post ) ) : ?>
$item ) {
self::faq_row( $i, $item['q'], $item['a'] );
}
?>
$row ) {
if ( is_array( $row ) && isset( $as_html[ $i ] ) && is_array( $as_html[ $i ] ) ) {
$faq[] = array(
'q' => isset( $row['q'] ) ? (string) $row['q'] : '',
'a' => isset( $as_html[ $i ]['a'] ) ? (string) $as_html[ $i ]['a'] : '',
);
}
}
Aeoora_Schema::set_faq( $post_id, $faq );
$tldr = isset( $_POST['aeoora_tldr'] ) ? sanitize_textarea_field( wp_unslash( $_POST['aeoora_tldr'] ) ) : '';
'' === $tldr ? delete_post_meta( $post_id, '_aeoora_tldr' ) : update_post_meta( $post_id, '_aeoora_tldr', $tldr );
empty( $_POST['aeoora_exclude'] ) ? delete_post_meta( $post_id, '_aeoora_exclude' ) : update_post_meta( $post_id, '_aeoora_exclude', 1 );
foreach ( array(
'aeoora_meta_title' => '_aeoora_meta_title',
'aeoora_meta_desc' => '_aeoora_meta_desc',
'aeoora_focus_kw' => '_aeoora_focus_kw',
) as $field => $key ) {
if ( isset( $_POST[ $field ] ) ) {
$v = sanitize_text_field( wp_unslash( $_POST[ $field ] ) );
'' === $v ? delete_post_meta( $post_id, $key ) : update_post_meta( $post_id, $key, $v );
}
}
Aeoora_Markdown::flush_post( $post_id );
}
/**
* Editor assets.
*
* @param string $hook Hook.
*/
public static function assets( $hook ) {
if ( ! in_array( $hook, array( 'post.php', 'post-new.php', 'edit.php' ), true ) ) {
return;
}
$screen = get_current_screen();
if ( ! $screen || ! in_array( $screen->post_type, self::types(), true ) ) {
return;
}
if ( 'edit.php' === $hook ) {
// Post list: the AEO score column only.
wp_enqueue_style( 'aeoora-columns', AEOORA_URL . 'assets/css/columns.css', array(), AEOORA_VERSION );
return;
}
wp_enqueue_style( 'aeoora-editor', AEOORA_URL . 'assets/css/editor.css', array(), AEOORA_VERSION );
wp_enqueue_script( 'aeoora-editor', AEOORA_URL . 'assets/js/editor.js', array( 'wp-api-fetch', 'wp-i18n' ), AEOORA_VERSION, true );
wp_set_script_translations( 'aeoora-editor', 'aeoora', AEOORA_DIR . 'languages' );
}
/**
* List columns.
*/
public static function columns() {
foreach ( self::types() as $type ) {
add_filter( "manage_{$type}_posts_columns", array( __CLASS__, 'add_column' ) );
add_action( "manage_{$type}_posts_custom_column", array( __CLASS__, 'column' ), 10, 2 );
add_filter( "manage_edit-{$type}_sortable_columns", array( __CLASS__, 'sortable' ) );
}
add_action( 'pre_get_posts', array( __CLASS__, 'sort_query' ) );
}
/**
* Add column.
*
* @param array $cols Columns.
* @return array
*/
public static function add_column( $cols ) {
$cols['aeoora_score'] = 'AEO';
return $cols;
}
/**
* Column value.
*
* @param string $col Column.
* @param int $post_id Post.
*/
public static function column( $col, $post_id ) {
if ( 'aeoora_score' !== $col ) {
return;
}
$score = get_post_meta( $post_id, '_aeoora_score', true );
if ( '' === $score ) {
echo '–';
return;
}
$score = (int) $score;
$cls = $score >= 80 ? 'great' : ( $score >= 55 ? 'good' : 'poor' );
echo '' . (int) $score . '';
}
/**
* Sortable.
*
* @param array $cols Columns.
* @return array
*/
public static function sortable( $cols ) {
$cols['aeoora_score'] = 'aeoora_score';
return $cols;
}
/**
* Sort by score.
*
* @param WP_Query $q Query.
*/
public static function sort_query( $q ) {
if ( is_admin() && $q->is_main_query() && 'aeoora_score' === $q->get( 'orderby' ) ) {
// LEFT JOIN keeps posts that were never scored in the list.
add_filter( 'posts_clauses', array( __CLASS__, 'sort_clauses' ), 10, 2 );
}
}
/**
* SQL for sorting by score with unscored posts kept (listed first when ascending).
*
* @param array $clauses Clauses.
* @param WP_Query $q Query.
* @return array
*/
public static function sort_clauses( $clauses, $q ) {
global $wpdb;
if ( ! $q->is_main_query() ) {
return $clauses;
}
remove_filter( 'posts_clauses', array( __CLASS__, 'sort_clauses' ), 10 );
$order = 'DESC' === strtoupper( (string) $q->get( 'order' ) ) ? 'DESC' : 'ASC';
$clauses['join'] .= $wpdb->prepare( ' LEFT JOIN %i aeo_s ON ( %i.ID = aeo_s.post_id AND aeo_s.meta_key = %s )', $wpdb->postmeta, $wpdb->posts, '_aeoora_score' );
$clauses['orderby'] = ( 'DESC' === $order ? 'CAST(aeo_s.meta_value AS SIGNED) DESC, ' : 'CAST(aeo_s.meta_value AS SIGNED) ASC, ' ) . $wpdb->prepare( '%i.post_date DESC', $wpdb->posts );
return $clauses;
}
}