name = __( 'Social Meta', 'all-in-one-seo-pack' ); // Human-readable name of the plugin.
$this->prefix = 'aiosp_opengraph_'; // option prefix.
$this->file = __FILE__; // the current file.
$this->fb_object_types = array(
'Activities' => array(
'activity' => __( 'Activity', 'all-in-one-seo-pack' ),
'sport' => __( 'Sport', 'all-in-one-seo-pack' ),
),
'Businesses' => array(
'bar' => __( 'Bar', 'all-in-one-seo-pack' ),
'company' => __( 'Company', 'all-in-one-seo-pack' ),
'cafe' => __( 'Cafe', 'all-in-one-seo-pack' ),
'hotel' => __( 'Hotel', 'all-in-one-seo-pack' ),
'restaurant' => __( 'Restaurant', 'all-in-one-seo-pack' ),
),
'Groups' => array(
'cause' => __( 'Cause', 'all-in-one-seo-pack' ),
'sports_league' => __( 'Sports League', 'all-in-one-seo-pack' ),
'sports_team' => __( 'Sports Team', 'all-in-one-seo-pack' ),
),
'Organizations' => array(
'band' => __( 'Band', 'all-in-one-seo-pack' ),
'government' => __( 'Government', 'all-in-one-seo-pack' ),
'non_profit' => __( 'Non Profit', 'all-in-one-seo-pack' ),
'school' => __( 'School', 'all-in-one-seo-pack' ),
'university' => __( 'University', 'all-in-one-seo-pack' ),
),
'People' => array(
'actor' => __( 'Actor', 'all-in-one-seo-pack' ),
'athlete' => __( 'Athlete', 'all-in-one-seo-pack' ),
'author' => __( 'Author', 'all-in-one-seo-pack' ),
'director' => __( 'Director', 'all-in-one-seo-pack' ),
'musician' => __( 'Musician', 'all-in-one-seo-pack' ),
'politician' => __( 'Politician', 'all-in-one-seo-pack' ),
'profile' => __( 'Profile', 'all-in-one-seo-pack' ),
'public_figure' => __( 'Public Figure', 'all-in-one-seo-pack' ),
),
'Places' => array(
'city' => __( 'City', 'all-in-one-seo-pack' ),
'country' => __( 'Country', 'all-in-one-seo-pack' ),
'landmark' => __( 'Landmark', 'all-in-one-seo-pack' ),
'state_province' => __( 'State Province', 'all-in-one-seo-pack' ),
),
'Products and Entertainment' => array(
'album' => __( 'Album', 'all-in-one-seo-pack' ),
'book' => __( 'Book', 'all-in-one-seo-pack' ),
'drink' => __( 'Drink', 'all-in-one-seo-pack' ),
'food' => __( 'Food', 'all-in-one-seo-pack' ),
'game' => __( 'Game', 'all-in-one-seo-pack' ),
'movie' => __( 'Movie', 'all-in-one-seo-pack' ),
'product' => __( 'Product', 'all-in-one-seo-pack' ),
'song' => __( 'Song', 'all-in-one-seo-pack' ),
'tv_show' => __( 'TV Show', 'all-in-one-seo-pack' ),
'episode' => __( 'Episode', 'all-in-one-seo-pack' ),
),
'Websites' => array(
'article' => __( 'Article', 'all-in-one-seo-pack' ),
'website' => __( 'Website', 'all-in-one-seo-pack' ),
),
);
parent::__construct();
if ( is_admin() ) {
add_action( 'admin_init', array( $this, 'admin_init' ), 5 );
} else {
add_action( 'wp', array( $this, 'type_setup' ) );
}
if ( ! is_admin() || wp_doing_ajax() || defined( 'AIOSEOP_UNIT_TESTING' ) ) {
$this->do_opengraph();
}
// Set variables after WordPress load.
add_action( 'init', array( &$this, 'init' ), 999999 );
// Avoid having duplicate meta tags.
add_filter( 'jetpack_enable_open_graph', '__return_false' );
// Force refresh of Facebook cache.
add_action( 'post_updated', array( &$this, 'force_fb_refresh_update' ), 10, 3 );
add_action( 'transition_post_status', array( &$this, 'force_fb_refresh_transition' ), 10, 3 );
add_action( 'edited_term', array( &$this, 'save_tax_data' ), 10, 3 );
// Adds special filters.
add_filter( 'aioseop_opengraph_placeholder', array( &$this, 'filter_placeholder' ) );
add_action( 'aiosp_activate_opengraph', array( $this, 'activate_module' ) );
add_action( 'created_term', array( $this, 'created_term' ), 10, 3 );
// Call to init to generate menus.
$this->init();
}
/**
* Sets the terms defaults after a new term is created.
*
* @param int $term_id Term ID.
* @param int $tt_id Term taxonomy ID.
* @param string $taxonomy Taxonomy slug.
*/
function created_term( $term_id, $tt_id, $taxonomy_name ) {
$k = 'settings';
$prefix = $this->get_prefix( $k );
$tax = get_taxonomy( $taxonomy_name );
$this->set_object_type_for_taxonomy( $prefix, $k, $taxonomy_name, $tax, false, array( $term_id ) );
}
/**
* Sets the defaults for a taxonomy.
*
* @param string $prefix The prefix of this module.
* @param string $k The key against which the options will be determined/set.
* @param string $taxonomy_name The name of the taxonomy.
* @param Object $tax The taxonomy object.
* @param bool $bail_if_no_terms Bail if the taxonomy has no terms.
* @param array $terms The terms in the taxonomy.
*/
private function set_object_type_for_taxonomy( $prefix, $k, $taxonomy_name, $tax, $bail_if_no_terms = false, $terms = null ) {
$object_type = null;
if ( ! $terms ) {
$terms = get_terms(
$taxonomy_name,
array(
'meta_query' => array(
array(
'key' => '_' . $prefix . $k,
'compare' => 'NOT EXISTS',
),
),
'number' => PHP_INT_MAX,
'fields' => 'ids',
'hide_empty' => false,
)
);
}
if ( empty( $terms ) && $bail_if_no_terms ) {
return false;
}
if ( true === $tax->_builtin ) {
$object_type = 'article';
} else {
// custom taxonomy. Let's get a post against this to determine its post type.
$posts = get_posts(
array(
'numberposts' => 1,
'post_type' => 'any',
'tax_query' => array(
array(
'taxonomy' => $taxonomy_name,
'field' => 'term_id',
'terms' => $terms,
),
),
)
);
if ( $posts ) {
global $aioseop_options;
$post_type = $posts[0]->post_type;
if ( isset( $aioseop_options['modules'] ) && isset( $aioseop_options['modules'][ $this->prefix . 'options' ] ) ) {
$og_options = $aioseop_options['modules'][ $this->prefix . 'options' ];
// now let's see what default object type is set for this post type.
$object_type_set = $og_options[ $this->prefix . $post_type . '_fb_object_type' ];
if ( ! empty( $object_type_set ) ) {
$object_type = $object_type_set;
}
}
}
}
if ( $object_type ) {
$opts[ $prefix . $k . '_category' ] = $object_type;
foreach ( $terms as $term_id ) {
update_term_meta( $term_id, '_' . $prefix . $k, $opts );
}
}
return true;
}
/**
* Called when this module is activated.
*/
public function activate_module() {
if ( null !== $this->locations ) {
foreach ( $this->locations as $k => $v ) {
if ( ! isset( $v['type'] ) || 'metabox' !== $v['type'] ) {
continue;
}
$this->set_virgin_tax_terms( $k );
}
}
}
/**
* This iterates over all taxonomies that do not have a opengraph setting defined and sets the defaults.
*
* @param string $k The key against which the options will be determined/set.
*/
private function set_virgin_tax_terms( $k ) {
$prefix = $this->get_prefix( $k );
$opts = $this->default_options( $k );
$taxonomies = get_taxonomies( array( 'public' => true ), 'object' );
if ( ! $taxonomies ) {
return;
}
foreach ( $taxonomies as $name => $tax ) {
$this->set_object_type_for_taxonomy( $prefix, $k, $name, $tax, true, null );
}
}
/**
* Hook called after WordPress has been loaded.
*
* @since 2.4.14
*/
public function init() {
$count_desc = __( ' characters. We recommend a maximum of %1$s chars for the %2$s.', 'all-in-one-seo-pack' );
// Create default options.
$this->default_options = array(
'scan_header' => array(
'name' => __( 'Scan Header', 'all-in-one-seo-pack' ),
'type' => 'custom',
'save' => true,
),
'setmeta' => array(
'name' => __( 'Use AIOSEO Title and Description', 'all-in-one-seo-pack' ),
'type' => 'checkbox',
),
'key' => array(
'name' => __( 'Facebook Admin ID', 'all-in-one-seo-pack' ),
'default' => '',
'type' => 'text',
),
'appid' => array(
'name' => __( 'Facebook App ID', 'all-in-one-seo-pack' ),
'default' => '',
'type' => 'text',
),
'title_shortcodes' => array(
'name' => __( 'Run Shortcodes In Title', 'all-in-one-seo-pack' ),
),
'description_shortcodes' => array(
'name' => __( 'Run Shortcodes In Description', 'all-in-one-seo-pack' ),
),
'sitename' => array(
'name' => __( 'Site Name', 'all-in-one-seo-pack' ),
'default' => get_bloginfo( 'name' ),
'type' => 'text',
),
'hometitle' => array(
'name' => __( 'Home Title', 'all-in-one-seo-pack' ),
'default' => '',
'type' => 'text',
'count' => true,
'count_desc' => $count_desc,
'size' => 95,
'condshow' => array(
'aiosp_opengraph_setmeta' => array(
'lhs' => 'aiosp_opengraph_setmeta',
'op' => '!=',
'rhs' => 'on',
),
),
),
'description' => array(
'name' => __( 'Home Description', 'all-in-one-seo-pack' ),
'default' => '',
'type' => 'textarea',
'count' => true,
'count_desc' => $count_desc,
'size' => 200,
'condshow' => array(
'aiosp_opengraph_setmeta' => array(
'lhs' => 'aiosp_opengraph_setmeta',
'op' => '!=',
'rhs' => 'on',
),
),
),
'homeimage' => array(
'name' => __( 'Home Image', 'all-in-one-seo-pack' ),
'type' => 'image',
),
'generate_descriptions' => array(
'name' => __( 'Use Content For Autogenerated OG Descriptions', 'all-in-one-seo-pack' ),
'default' => 0,
),
'defimg' => array(
'name' => __( 'Select OG:Image Source', 'all-in-one-seo-pack' ),
'type' => 'select',
'initial_options' => array(
'' => __( 'Default Image', 'all-in-one-seo-pack' ),
'featured' => __( 'Featured Image', 'all-in-one-seo-pack' ),
'attach' => __( 'First Attached Image', 'all-in-one-seo-pack' ),
'content' => __( 'First Image In Content', 'all-in-one-seo-pack' ),
'custom' => __( 'Image From Custom Field', 'all-in-one-seo-pack' ),
'author' => __( 'Post Author Image', 'all-in-one-seo-pack' ),
'auto' => __( 'First Available Image', 'all-in-one-seo-pack' ),
),
),
'fallback' => array(
'name' => __( 'Use Default If No Image Found', 'all-in-one-seo-pack' ),
'type' => 'checkbox',
),
'dimg' => array(
'name' => __( 'Default OG:Image', 'all-in-one-seo-pack' ),
'default' => AIOSEOP_PLUGIN_IMAGES_URL . 'default-user-image.png',
'type' => 'image',
),
'dimgwidth' => array(
'name' => __( 'Default Image Width', 'all-in-one-seo-pack' ),
'type' => 'text',
'default' => '',
),
'dimgheight' => array(
'name' => __( 'Default Image Height', 'all-in-one-seo-pack' ),
'type' => 'text',
'default' => '',
),
'meta_key' => array(
'name' => __( 'Use Custom Field For Image', 'all-in-one-seo-pack' ),
'type' => 'text',
'default' => '',
),
'image' => array(
'name' => __( 'Image', 'all-in-one-seo-pack' ),
'type' => 'radio',
'initial_options' => array(
0 => '',
),
),
'customimg' => array(
'name' => __( 'Custom Image', 'all-in-one-seo-pack' ),
'type' => 'image',
),
'imagewidth' => array(
'name' => __( 'Specify Image Width', 'all-in-one-seo-pack' ),
'type' => 'text',
'default' => '',
),
'imageheight' => array(
'name' => __( 'Specify Image Height', 'all-in-one-seo-pack' ),
'type' => 'text',
'default' => '',
),
'video' => array(
'name' => __( 'Custom Video', 'all-in-one-seo-pack' ),
'type' => 'text',
),
'videowidth' => array(
'name' => __( 'Specify Video Width', 'all-in-one-seo-pack' ),
'type' => 'text',
'default' => '',
'condshow' => array(
'aioseop_opengraph_settings_video' => array(
'lhs' => 'aioseop_opengraph_settings_video',
'op' => '!=',
'rhs' => '',
),
),
),
'videoheight' => array(
'name' => __( 'Specify Video Height', 'all-in-one-seo-pack' ),
'type' => 'text',
'default' => '',
'condshow' => array(
'aioseop_opengraph_settings_video' => array(
'lhs' => 'aioseop_opengraph_settings_video',
'op' => '!=',
'rhs' => '',
),
),
),
'defcard' => array(
'name' => __( 'Default Twitter Card', 'all-in-one-seo-pack' ),
'type' => 'select',
'default' => 'summary',
'initial_options' => array(
'summary' => __( 'Summary', 'all-in-one-seo-pack' ),
'summary_large_image' => __( 'Summary Large Image', 'all-in-one-seo-pack' ),
/*
* REMOVING THIS TWITTER CARD TYPE FROM SOCIAL META MODULE
* 'photo' => __( 'Photo', 'all-in-one-seo-pack' )
*/
),
),
'setcard' => array(
'name' => __( 'Twitter Card Type', 'all-in-one-seo-pack' ),
'type' => 'select',
'initial_options' => array(
'summary_large_image' => __( 'Summary Large Image', 'all-in-one-seo-pack' ),
'summary' => __( 'Summary', 'all-in-one-seo-pack' ),
/*
* REMOVING THIS TWITTER CARD TYPE FROM SOCIAL META MODULE
* 'photo' => __( 'Photo', 'all-in-one-seo-pack' )
*/
),
),
'twitter_site' => array(
'name' => __( 'Twitter Site', 'all-in-one-seo-pack' ),
'type' => 'text',
'default' => '',
),
'twitter_creator' => array(
'name' => __( 'Show Twitter Author', 'all-in-one-seo-pack' ),
),
'twitter_domain' => array(
'name' => __( 'Twitter Domain', 'all-in-one-seo-pack' ),
'type' => 'text',
'default' => '',
),
'customimg_twitter' => array(
'name' => __( 'Custom Twitter Image', 'all-in-one-seo-pack' ),
'type' => 'image',
),
'gen_tags' => array(
'name' => __( 'Automatically Generate Article Tags', 'all-in-one-seo-pack' ),
),
'gen_keywords' => array(
'name' => __( 'Use Keywords In Article Tags', 'all-in-one-seo-pack' ),
'default' => 'on',
'condshow' => array( 'aiosp_opengraph_gen_tags' => 'on' ),
),
'gen_categories' => array(
'name' => __( 'Use Categories In Article Tags', 'all-in-one-seo-pack' ),
'default' => 'on',
'condshow' => array( 'aiosp_opengraph_gen_tags' => 'on' ),
),
'gen_post_tags' => array(
'name' => __( 'Use Post Tags In Article Tags', 'all-in-one-seo-pack' ),
'default' => 'on',
'condshow' => array( 'aiosp_opengraph_gen_tags' => 'on' ),
),
'types' => array(
'name' => __( 'Enable Facebook Meta for Post Types', 'all-in-one-seo-pack' ),
'type' => 'multicheckbox',
'default' => array(
'post' => 'post',
'page' => 'page',
),
'initial_options' => $this->get_post_type_titles( array( '_builtin' => false ) ),
),
'title' => array(
'name' => __( 'Title', 'all-in-one-seo-pack' ),
'default' => '',
'type' => 'text',
'size' => 95,
'count' => 1,
'count_desc' => $count_desc,
),
'desc' => array(
'name' => __( 'Description', 'all-in-one-seo-pack' ),
'default' => '',
'type' => 'textarea',
'cols' => 50,
'rows' => 4,
'count' => 1,
'count_desc' => $count_desc,
),
'category' => array(
'name' => __( 'Facebook Object Type', 'all-in-one-seo-pack' ),
'type' => 'select',
'style' => '',
'default' => '',
'initial_options' => $this->fb_object_types,
),
'facebook_debug' => array(
'name' => __( 'Facebook Debug', 'all-in-one-seo-pack' ),
'type' => 'html',
'save' => false,
'default' => '' . __( 'Debug This Post', 'all-in-one-seo-pack' ) . '',
),
'section' => array(
'name' => __( 'Article Section', 'all-in-one-seo-pack' ),
'type' => 'text',
'default' => '',
'condshow' => array( 'aioseop_opengraph_settings_category' => 'article' ),
),
'tag' => array(
'name' => __( 'Article Tags', 'all-in-one-seo-pack' ),
'type' => 'text',
'default' => '',
'condshow' => array( 'aioseop_opengraph_settings_category' => 'article' ),
),
'facebook_publisher' => array(
'name' => __( 'Show Facebook Publisher on Articles', 'all-in-one-seo-pack' ),
'type' => 'text',
'default' => '',
),
'facebook_author' => array(
'name' => __( 'Show Facebook Author on Articles', 'all-in-one-seo-pack' ),
),
);
// load initial options / set defaults.
$this->update_options();
$display = array();
if ( isset( $this->options['aiosp_opengraph_types'] ) && ! empty( $this->options['aiosp_opengraph_types'] ) ) {
$display = $this->options['aiosp_opengraph_types'];
}
$this->locations = array(
'opengraph' => array(
'name' => $this->name,
'prefix' => 'aiosp_',
'type' => 'settings',
'options' => array(
'scan_header',
'setmeta',
'key',
'appid',
'sitename',
'title_shortcodes',
'description_shortcodes',
'hometitle',
'description',
'homeimage',
'generate_descriptions',
'defimg',
'fallback',
'dimg',
'dimgwidth',
'dimgheight',
'meta_key',
'defcard',
'twitter_site',
'twitter_creator',
'twitter_domain',
'gen_tags',
'gen_keywords',
'gen_categories',
'gen_post_tags',
'types',
'facebook_publisher',
'facebook_author',
),
),
'settings' => array(
'name' => __( 'Social Settings', 'all-in-one-seo-pack' ),
'type' => 'metabox',
'help_link' => 'https://semperplugins.com/documentation/social-meta-settings-individual-pagepost-settings/',
'options' => array(
'title',
'desc',
'image',
'customimg',
'imagewidth',
'imageheight',
'video',
'videowidth',
'videoheight',
'category',
'facebook_debug',
'section',
'tag',
'setcard',
'customimg_twitter',
),
'display' => apply_filters( 'aioseop_opengraph_display', $display ),
'prefix' => 'aioseop_opengraph_',
),
);
$this->layout = array(
'home' => array(
'name' => __( 'Home Page Settings', 'all-in-one-seo-pack' ),
'help_link' => 'https://semperplugins.com/documentation/social-meta-module/#use-aioseo-title-and-description',
'options' => array( 'setmeta', 'sitename', 'hometitle', 'description', 'homeimage' ),
),
'image' => array(
'name' => __( 'Image Settings', 'all-in-one-seo-pack' ),
'help_link' => 'https://semperplugins.com/documentation/social-meta-module/#select-og-image-source',
'options' => array( 'defimg', 'fallback', 'dimg', 'dimgwidth', 'dimgheight', 'meta_key' ),
),
'facebook' => array(
'name' => __( 'Facebook Settings', 'all-in-one-seo-pack' ),
'help_link' => 'https://semperplugins.com/documentation/social-meta-module/#facebook-settings',
'options' => array(
'key',
'appid',
'types',
'gen_tags',
'gen_keywords',
'gen_categories',
'gen_post_tags',
'facebook_publisher',
'facebook_author',
),
),
'twitter' => array(
'name' => __( 'Twitter Settings', 'all-in-one-seo-pack' ),
'help_link' => 'https://semperplugins.com/documentation/social-meta-module/#default-twitter-card',
'options' => array( 'defcard', 'setcard', 'twitter_site', 'twitter_creator', 'twitter_domain' ),
),
'default' => array(
'name' => __( 'Advanced Settings', 'all-in-one-seo-pack' ),
'help_link' => 'https://semperplugins.com/documentation/social-meta-module/',
// this is set below, to the remaining options -- pdb.
'options' => array(),
),
'scan_meta' => array(
'name' => __( 'Scan Social Meta', 'all-in-one-seo-pack' ),
'help_link' => 'https://semperplugins.com/documentation/social-meta-module/#scan_meta',
'options' => array( 'scan_header' ),
),
);
$other_options = array();
foreach ( $this->layout as $k => $v ) {
$other_options = array_merge( $other_options, $v['options'] );
}
$this->layout['default']['options'] = array_diff( array_keys( $this->default_options ), $other_options );
}
/**
* Forces FaceBook OpenGraph to refresh its cache when a post is changed to
*
* @param $new_status
* @param $old_status
* @param $post
*
* @todo this and force_fb_refresh_update can probably have the remote POST extracted out.
*
* @see https://developers.facebook.com/docs/sharing/opengraph/using-objects#update
* @since 2.3.11
*/
function force_fb_refresh_transition( $new_status, $old_status, $post ) {
if ( 'publish' !== $new_status ) {
return;
}
if ( 'future' !== $old_status ) {
return;
}
$current_post_type = get_post_type();
// Only ping Facebook if Social SEO is enabled on this post type.
if ( $this->option_isset( 'types' ) && is_array( $this->options['aiosp_opengraph_types'] ) && in_array( $current_post_type, $this->options['aiosp_opengraph_types'] ) ) {
$post_url = aioseop_get_permalink( $post->ID );
$endpoint = sprintf(
'https://graph.facebook.com/?%s',
http_build_query(
array(
'id' => $post_url,
'scrape' => true,
)
)
);
wp_remote_post( $endpoint, array( 'blocking' => false ) );
}
}
/**
* Forces FaceBook OpenGraph refresh on update.
*
* @param $post_id
* @param $post_after
*
* @see https://developers.facebook.com/docs/sharing/opengraph/using-objects#update
* @since 2.3.11
*/
function force_fb_refresh_update( $post_id, $post_after ) {
$current_post_type = get_post_type();
// Only ping Facebook if Social SEO is enabled on this post type.
if ( 'publish' === $post_after->post_status && $this->option_isset( 'types' ) && is_array( $this->options['aiosp_opengraph_types'] ) && in_array( $current_post_type, $this->options['aiosp_opengraph_types'] ) ) {
$post_url = aioseop_get_permalink( $post_id );
$endpoint = sprintf(
'https://graph.facebook.com/?%s',
http_build_query(
array(
'id' => $post_url,
'scrape' => true,
)
)
);
wp_remote_post( $endpoint, array( 'blocking' => false ) );
}
}
function settings_page_init() {
add_filter( 'aiosp_output_option', array( $this, 'display_custom_options' ), 10, 2 );
}
function filter_options( $options, $location ) {
if ( 'settings' == $location ) {
$prefix = $this->get_prefix( $location ) . $location . '_';
list( $legacy, $images ) = $this->get_all_images( $options );
if ( isset( $options ) && isset( $options[ "{$prefix}image" ] ) ) {
$thumbnail = $options[ "{$prefix}image" ];
if ( ctype_digit( (string) $thumbnail ) || ( 'post' == $thumbnail ) ) {
if ( 'post' == $thumbnail ) {
$thumbnail = $images['post1'];
} elseif ( ! empty( $legacy[ $thumbnail ] ) ) {
$thumbnail = $legacy[ $thumbnail ];
}
}
$options[ "{$prefix}image" ] = $thumbnail;
}
if ( empty( $options[ $prefix . 'image' ] ) ) {
$img = array_keys( $images );
if ( ! empty( $img ) && ! empty( $img[1] ) ) {
$options[ $prefix . 'image' ] = $img[1];
}
}
}
return $options;
}
/**
* Applies filter to module settings.
*
* @since 2.3.11
* @since 2.4.14 Added filter for description and title placeholders.
* @since 2.3.15 do_shortcode on description.
*
* @see [plugin]\admin\aioseop_module_class.php > display_options()
*/
function filter_settings( $settings, $location, $current ) {
global $aiosp, $post;
if ( 'opengraph' == $location || 'settings' == $location ) {
$prefix = $this->get_prefix( $location ) . $location . '_';
if ( 'opengraph' == $location ) {
return $settings;
}
if ( 'settings' == $location ) {
list( $legacy, $settings[ $prefix . 'image' ]['initial_options'] ) = $this->get_all_images( $current );
$opts = array( 'title', 'desc' );
$current_post_type = get_post_type();
if ( isset( $this->options[ "aiosp_opengraph_{$current_post_type}_fb_object_type" ] ) ) {
$flat_type_list = array();
foreach ( $this->fb_object_types as $k => $v ) {
if ( is_array( $v ) ) {
$flat_type_list = array_merge( $flat_type_list, $v );
} else {
$flat_type_list[ $k ] = $v;
}
}
$default_fb_type = $this->options[ "aiosp_opengraph_{$current_post_type}_fb_object_type" ];
// https://github.com/semperfiwebdesign/all-in-one-seo-pack/issues/1013
// if 'blog' is the selected type but because it is no longer a schema type, we use 'website' instead.
if ( 'blog' === $default_fb_type ) {
$default_fb_type = 'website';
}
if ( isset( $flat_type_list[ $default_fb_type ] ) ) {
$default_fb_type = $flat_type_list[ $default_fb_type ];
}
$settings[ $prefix . 'category' ]['initial_options'] = array_merge(
array(
$this->options[ "aiosp_opengraph_{$current_post_type}_fb_object_type" ] => __( 'Default ', 'all-in-one-seo-pack' ) . ' - ' . $default_fb_type,
),
$settings[ $prefix . 'category' ]['initial_options']
);
}
if ( isset( $this->options['aiosp_opengraph_defcard'] ) ) {
$settings[ $prefix . 'setcard' ]['default'] = $this->options['aiosp_opengraph_defcard'];
}
$info = $aiosp->get_page_snippet_info();
$title = $info['title'];
$description = $info['description'];
// Description options.
if ( is_object( $post ) ) {
// Always show excerpt.
$description = empty( $this->options['aiosp_opengraph_generate_descriptions'] )
? $aiosp->trim_excerpt_without_filters(
$aiosp->internationalize( preg_replace( '/\s+/', ' ', $post->post_excerpt ) ),
200
)
: $aiosp->trim_excerpt_without_filters(
$aiosp->internationalize( preg_replace( '/\s+/', ' ', $post->post_content ) ),
200
);
}
// #1308 - we want to make sure we are ignoring php version only in the admin area
// while editing the post, so that it does not impact #932.
$screen = get_current_screen();
$ignore_php_version = is_admin() && isset( $screen->id ) && 'post' == $screen->id;
// Add filters.
$description = apply_filters( 'aioseop_description', $description, false, $ignore_php_version );
// Add placholders.
$settings[ "{$prefix}title" ]['placeholder'] = apply_filters( 'aioseop_opengraph_placeholder', $title );
$settings[ "{$prefix}desc" ]['placeholder'] = apply_filters( 'aioseop_opengraph_placeholder', $description );
}
if ( isset( $current[ $prefix . 'setmeta' ] ) && $current[ $prefix . 'setmeta' ] ) {
foreach ( $opts as $opt ) {
if ( isset( $settings[ $prefix . $opt ] ) ) {
$settings[ $prefix . $opt ]['type'] = 'hidden';
$settings[ $prefix . $opt ]['label'] = 'none';
unset( $settings[ $prefix . $opt ]['count'] );
}
}
}
}
return $settings;
}
/**
* Applies filter to module options.
* These will display in the "Social Settings" object tab.
* filter:{prefix}override_options
*
* @since 2.3.11
* @since 2.4.14 Overrides empty og:type values.
*
* @see [plugin]\admin\aioseop_module_class.php > display_options()
*
* @global array $aioseop_options Plugin options.
*
* @param array $options Current options.
* @param string $location Location where filter is called.
* @param array $settings Settings.
*
* @return array
*/
function override_options( $options, $location, $settings ) {
global $aioseop_options;
// Prepare default and prefix.
$prefix = $this->get_prefix( $location ) . $location . '_';
$opts = array();
foreach ( $settings as $k => $v ) {
if ( $v['save'] ) {
$opts[ $k ] = $v['default'];
}
}
foreach ( $options as $k => $v ) {
switch ( $k ) {
case $prefix . 'category':
if ( empty( $v ) ) {
// Get post type.
$type = isset( get_current_screen()->post_type )
? get_current_screen()->post_type
: null;
// Assign default from plugin options.
if ( ! empty( $type )
&& isset( $aioseop_options['modules'] )
&& isset( $aioseop_options['modules']['aiosp_opengraph_options'] )
&& isset( $aioseop_options['modules']['aiosp_opengraph_options'][ 'aiosp_opengraph_' . $type . '_fb_object_type' ] )
) {
$options[ $prefix . 'category' ] =
$aioseop_options['modules']['aiosp_opengraph_options'][ 'aiosp_opengraph_' . $type . '_fb_object_type' ];
}
}
break;
}
if ( null === $v ) {
unset( $options[ $k ] );
}
}
$options = wp_parse_args( $options, $opts );
// @issue #1013 ( https://github.com/semperfiwebdesign/all-in-one-seo-pack/issues/1013 ).
$post_types = $this->get_post_type_titles();
foreach ( $post_types as $slug => $name ) {
$field = 'aiosp_opengraph_' . $slug . '_fb_object_type';
if ( isset( $options[ $field ] ) && 'blog' === $options[ $field ] ) {
$options[ $field ] = 'website';
}
}
return $options;
}
/**
* Applies filter to metabox settings before they are saved.
* Sets custom as default if a custom image is uploaded.
* filter:{prefix}filter_metabox_options
* filter:{prefix}filter_term_metabox_options
*
* @since 2.3.11
* @since 2.4.14 Fixes for aioseop-pro #67 and other bugs found.
*
* @see [plugin]\admin\aioseop_module_class.php > save_post_data()
* @see [this file] > save_tax_data()
*
* @param array $options List of current options.
* @param string $location Location where filter is called.
* @param int $id Either post_id or term_id.
*
* @return array
*/
function filter_metabox_options( $options, $location, $post_id ) {
if ( 'settings' == $location ) {
$prefix = $this->get_prefix( $location ) . $location . '_';
if ( isset( $options[ $prefix . 'customimg_checker' ] )
&& $options[ $prefix . 'customimg_checker' ]
) {
$options[ $prefix . 'image' ] = $options[ $prefix . 'customimg' ];
}
}
return $options;
}
/** Custom settings **/
function display_custom_options( $buf, $args ) {
if ( 'aiosp_opengraph_scan_header' == $args['name'] ) {
$buf .= '