';
}
/**
* Render taxonomy metabox content.
*
* @param WP_Term $term Current term object.
* @param string $taxonomy Current taxonomy slug.
*/
public function render_taxonomy_metabox( $term, $taxonomy ) {
// Add nonce for security.
wp_nonce_field( 'rank_math_save_term_meta', 'rank_math_term_metabox_nonce' );
?>
metabox_id . '_link_suggestions',
esc_html__( 'Link Suggestions', 'rank-math' ),
[ $this, 'render_link_suggestion_metabox' ],
$allowed_post_types,
'side',
'default'
);
}
/**
* Render link suggestion metabox content.
*
* @param WP_Post $post Current post object.
*/
public function render_link_suggestion_metabox( $post ) {
echo '
';
echo wp_kses_post( Admin_Helper::get_tooltip( esc_html__( 'Click on the button to copy URL or insert link in content. You can also drag and drop links in the post content.', 'rank-math' ) ) );
echo '
';
$suggestions = rank_math()->admin->get_link_suggestions( $post );
if ( empty( $suggestions ) ) {
echo '' . esc_html__( 'We can\'t show any link suggestions for this post. Try selecting categories and tags for this post, and mark other posts as Pillar Content to make them show up here.', 'rank-math' ) . '';
return;
}
echo wp_kses_post( rank_math()->admin->get_link_suggestions_html( $suggestions ) );
}
/**
* Save post meta handler.
*
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
*/
public function save_meta( $post_id, $post ) {
// Verify nonce.
$nonce = isset( $_POST['rank_math_metabox_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['rank_math_metabox_nonce'] ) ) : '';
if ( ! $nonce || ! wp_verify_nonce( $nonce, 'rank_math_save_meta' ) ) {
return;
}
// Check autosave.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Check permissions.
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
/**
* Hook into save handler for main metabox.
*
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
*/
$this->do_action( 'metabox/process_fields', $post_id, $post );
}
/**
* Save term meta handler.
*
* @param int $term_id Term ID.
* @param int $tt_id Term taxonomy ID.
* @param string $taxonomy Taxonomy slug.
*/
public function save_term_meta( $term_id, $tt_id, $taxonomy ) {
// Verify nonce.
$nonce = isset( $_POST['rank_math_term_metabox_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['rank_math_term_metabox_nonce'] ) ) : '';
if ( ! $nonce || ! wp_verify_nonce( $nonce, 'rank_math_save_term_meta' ) ) {
return;
}
/**
* Hook into save handler for taxonomy metabox.
*
* @param int $term_id Term ID.
* @param int $tt_id Term taxonomy ID.
* @param string $taxonomy Taxonomy slug.
*/
$this->do_action( 'metabox/process_term_fields', $term_id, $tt_id, $taxonomy );
}
/**
* Invalidate facebook object cache for the post.
*
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
*/
public function invalidate_facebook_object_cache( $post_id, $post ) {
// Check if any Facebook meta fields were updated.
$facebook_fields = [ 'rank_math_facebook_title', 'rank_math_facebook_image', 'rank_math_facebook_description' ];
$has_update = false;
foreach ( $facebook_fields as $field ) {
if ( isset( $_POST[ $field ] ) ) {
$has_update = true;
break;
}
}
// Early Bail!
if ( ! $has_update ) {
return;
}
$app_id = Helper::get_settings( 'titles.facebook_app_id' );
$secret = Helper::get_settings( 'titles.facebook_secret' );
// Early bail!
if ( ! $app_id || ! $secret ) {
return;
}
wp_remote_post(
'https://graph.facebook.com/',
[
'body' => [
'id' => get_permalink( $post_id ),
'scrape' => true,
'access_token' => $app_id . '|' . $secret,
],
]
);
}
/**
* Add taxonomy metabox hooks.
*/
public function add_taxonomy_metabox_hooks() {
if ( $this->can_add_metabox() ) {
return;
}
$taxonomies = Helper::get_allowed_taxonomies();
if ( empty( $taxonomies ) ) {
return;
}
$this->screen->get_object_types();
// Add metabox for taxonomies.
foreach ( $taxonomies as $taxonomy ) {
// For editing existing terms - renders after the table.
add_action( "{$taxonomy}_edit_form", [ $this, 'render_taxonomy_metabox' ], 10, 2 );
}
}
/**
* Add SEO metabox on the User profile page.
*/
public function add_user_profile_metabox() {
if ( $this->can_add_metabox() ) {
return;
}
?>