v1.2.0
This commit is contained in:
parent
ddaaff71ad
commit
3bb9ed33e1
12 changed files with 1762 additions and 409 deletions
|
|
@ -69,6 +69,14 @@ class Robotstxt_OG_Image_Fallback {
|
|||
*/
|
||||
private Robotstxt_OG_Meta_Box $meta_box;
|
||||
|
||||
/**
|
||||
* Term meta instance.
|
||||
*
|
||||
* @since 1.2.0
|
||||
* @var Robotstxt_OG_Term_Meta
|
||||
*/
|
||||
private Robotstxt_OG_Term_Meta $term_meta;
|
||||
|
||||
/**
|
||||
* Get singleton instance.
|
||||
*
|
||||
|
|
@ -103,6 +111,9 @@ class Robotstxt_OG_Image_Fallback {
|
|||
* @return void
|
||||
*/
|
||||
public function init(): void {
|
||||
// Load bundled translations (required for non-wordpress.org distribution).
|
||||
load_plugin_textdomain( 'robotstxt-og', false, basename( ROBOTSTXT_OG_PATH ) . '/languages' );
|
||||
|
||||
// Load dependencies.
|
||||
$this->load_dependencies();
|
||||
|
||||
|
|
@ -121,6 +132,10 @@ class Robotstxt_OG_Image_Fallback {
|
|||
$this->meta_box = new Robotstxt_OG_Meta_Box();
|
||||
$this->meta_box->init();
|
||||
|
||||
// Initialize term meta (category/tag OG fields on term.php).
|
||||
$this->term_meta = new Robotstxt_OG_Term_Meta();
|
||||
$this->term_meta->init();
|
||||
|
||||
// Initialize admin settings if in admin context.
|
||||
if ( is_admin() ) {
|
||||
$this->admin_settings = new Robotstxt_OG_Admin_Settings( $this->resolver );
|
||||
|
|
@ -157,6 +172,7 @@ class Robotstxt_OG_Image_Fallback {
|
|||
require_once ROBOTSTXT_OG_PATH . 'includes/class-robotstxt-og-tags.php';
|
||||
require_once ROBOTSTXT_OG_PATH . 'includes/class-robotstxt-og-rest-api.php';
|
||||
require_once ROBOTSTXT_OG_PATH . 'includes/class-robotstxt-og-meta-box.php';
|
||||
require_once ROBOTSTXT_OG_PATH . 'includes/class-robotstxt-og-term-meta.php';
|
||||
|
||||
// Load admin class if in admin context.
|
||||
if ( is_admin() ) {
|
||||
|
|
@ -297,8 +313,10 @@ class Robotstxt_OG_Image_Fallback {
|
|||
foreach ( $posts as $post_id ) {
|
||||
$og_title = get_post_meta( $post_id, '_og_title', true );
|
||||
$og_desc = get_post_meta( $post_id, '_og_description', true );
|
||||
$creator = get_post_meta( $post_id, '_twitter_creator', true );
|
||||
$og_alt = get_post_meta( $post_id, '_og_image_alt', true );
|
||||
|
||||
if ( empty( $og_title ) && empty( $og_desc ) ) {
|
||||
if ( empty( $og_title ) && empty( $og_desc ) && empty( $creator ) && empty( $og_alt ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -318,6 +336,20 @@ class Robotstxt_OG_Image_Fallback {
|
|||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $creator ) && is_string( $creator ) ) {
|
||||
$item_data[] = array(
|
||||
'name' => __( 'Twitter Author Handle', 'robotstxt-og' ),
|
||||
'value' => $creator,
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $og_alt ) && is_string( $og_alt ) ) {
|
||||
$item_data[] = array(
|
||||
'name' => __( 'Custom OG Image Alt', 'robotstxt-og' ),
|
||||
'value' => $og_alt,
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $item_data ) ) {
|
||||
$data[] = array(
|
||||
'group_id' => 'robotstxt-og-post-meta',
|
||||
|
|
@ -374,10 +406,15 @@ class Robotstxt_OG_Image_Fallback {
|
|||
$items_removed = 0;
|
||||
|
||||
foreach ( $posts as $post_id ) {
|
||||
$deleted_title = delete_post_meta( $post_id, '_og_title' );
|
||||
$deleted_desc = delete_post_meta( $post_id, '_og_description' );
|
||||
$removed = false;
|
||||
|
||||
if ( $deleted_title || $deleted_desc ) {
|
||||
foreach ( array( '_og_title', '_og_description', '_twitter_creator', '_og_image_alt' ) as $meta_key ) {
|
||||
if ( delete_post_meta( $post_id, $meta_key ) ) {
|
||||
$removed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $removed ) {
|
||||
++$items_removed;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue