Commit realizado el 12:13:52 08-04-2024
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* The admin-side code for the BuddyPress module.
|
||||
*
|
||||
* @since 1.0.32
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\BuddyPress
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\BuddyPress;
|
||||
|
||||
use RankMath\Traits\Hooker;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Admin class
|
||||
*/
|
||||
class Admin {
|
||||
|
||||
use Hooker;
|
||||
|
||||
/**
|
||||
* The Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->filter( 'rank_math/settings/title', 'add_title_settings' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new tab in the Titles & Meta settings for the BuddyPress module.
|
||||
*
|
||||
* @param array $tabs Array of option panel tabs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_title_settings( $tabs ) {
|
||||
$tabs['buddypress'] = [
|
||||
'title' => esc_html__( 'BuddyPress:', 'rank-math' ),
|
||||
'type' => 'seprator',
|
||||
];
|
||||
|
||||
$tabs['buddypress-groups'] = [
|
||||
'icon' => 'rm-icon rm-icon-users',
|
||||
'title' => esc_html__( 'Groups', 'rank-math' ),
|
||||
'desc' => esc_html__( 'This tab contains SEO options for BuddyPress Group pages.', 'rank-math' ),
|
||||
'file' => dirname( __FILE__ ) . '/views/options-titles.php',
|
||||
];
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
}
|
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
/**
|
||||
* The BuddyPress Module.
|
||||
*
|
||||
* @since 1.0.32
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\BuddyPress
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\BuddyPress;
|
||||
|
||||
use RankMath\Traits\Hooker;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* BuddyPress class.
|
||||
*/
|
||||
class BuddyPress {
|
||||
|
||||
use Hooker;
|
||||
|
||||
/**
|
||||
* The Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
if ( is_admin() ) {
|
||||
new Admin();
|
||||
}
|
||||
|
||||
$this->filter( 'rank_math/paper/hash', 'paper' );
|
||||
$this->action( 'rank_math/vars/register_extra_replacements', 'register_replacements' );
|
||||
$this->filter( 'rank_math/json_ld', 'json_ld', 11 );
|
||||
$this->filter( 'rank_math/frontend/title', 'change_activate_title' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter to change the Activate page title.
|
||||
*
|
||||
* @param string $title Page title.
|
||||
*/
|
||||
public function change_activate_title( $title ) {
|
||||
if ( function_exists( 'bp_is_current_component' ) && bp_is_current_component( 'activate' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add BuddyPress class.
|
||||
*
|
||||
* @param array $hash Paper Hash.
|
||||
*/
|
||||
public function paper( $hash ) {
|
||||
$bp_data = [
|
||||
'BP_User' => bp_is_user(),
|
||||
'BP_Group' => ! is_singular() && bp_is_groups_component(),
|
||||
];
|
||||
|
||||
return array_merge( $bp_data, $hash );
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect data to output in JSON-LD.
|
||||
*
|
||||
* @param array $data An array of data to output in JSON-LD.
|
||||
*/
|
||||
public function json_ld( $data ) {
|
||||
if ( ! bp_is_user() ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
if ( isset( $data['richSnippet'] ) ) {
|
||||
unset( $data['richSnippet'] );
|
||||
}
|
||||
|
||||
$user_id = bp_displayed_user_id();
|
||||
|
||||
$data['ProfilePage'] = [
|
||||
'@type' => 'ProfilePage',
|
||||
'@id' => get_author_posts_url( $user_id ),
|
||||
'headline' => sprintf( 'About %s', get_the_author_meta( 'display_name', $user_id ) ),
|
||||
'about' => [
|
||||
'@type' => 'Person',
|
||||
'name' => get_the_author_meta( 'display_name', $user_id ),
|
||||
'url' => esc_url( bp_core_get_user_domain( $user_id ) ),
|
||||
'description' => get_the_author_meta( 'description', $user_id ),
|
||||
'image' => [
|
||||
'@type' => 'ImageObject',
|
||||
'url' => get_avatar_url( $user_id, 96 ),
|
||||
'height' => 96,
|
||||
'width' => 96,
|
||||
],
|
||||
],
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register variable replacements for BuddyPress groups.
|
||||
*/
|
||||
public function register_replacements() {
|
||||
rank_math_register_var_replacement(
|
||||
'group_name',
|
||||
[
|
||||
'name' => esc_html__( 'Group name.', 'rank-math' ),
|
||||
'description' => esc_html__( 'Group name of the current group', 'rank-math' ),
|
||||
'variable' => 'group_name',
|
||||
'example' => $this->get_group_name(),
|
||||
],
|
||||
[ $this, 'get_group_name' ]
|
||||
);
|
||||
|
||||
rank_math_register_var_replacement(
|
||||
'group_desc',
|
||||
[
|
||||
'name' => esc_html__( 'Group Description.', 'rank-math' ),
|
||||
'description' => esc_html__( 'Group description of the current group', 'rank-math' ),
|
||||
'variable' => 'group_desc',
|
||||
'example' => $this->get_group_desc(),
|
||||
],
|
||||
[ $this, 'get_group_desc' ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the group name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_group_name() {
|
||||
$group = $this->get_group();
|
||||
if ( ! is_object( $group ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $group->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the group description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_group_desc() {
|
||||
$group = $this->get_group();
|
||||
if ( ! is_object( $group ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $group->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group object when the current page is the group page.
|
||||
*
|
||||
* @return null|Object
|
||||
*/
|
||||
private function get_group() {
|
||||
if ( ! function_exists( 'groups_get_current_group' ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$group = groups_get_current_group();
|
||||
if ( ! is_object( $group ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* The BuddyPress group class for the BuddyPress module.
|
||||
*
|
||||
* @since 1.0.32
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
use RankMath\Helper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* BP_Group class.
|
||||
*/
|
||||
class BP_Group implements IPaper {
|
||||
|
||||
/**
|
||||
* Retrieves the SEO title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title() {
|
||||
return Paper::get_from_options( 'bp_group_title' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the SEO description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function description() {
|
||||
return Paper::get_from_options( 'bp_group_description' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the robots meta value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function robots() {
|
||||
$robots = [];
|
||||
if ( Helper::get_settings( 'titles.bp_group_custom_robots' ) ) {
|
||||
$robots = Helper::get_settings( 'titles.bp_group_robots' );
|
||||
}
|
||||
|
||||
return Paper::robots_combine( $robots, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the advanced robots meta values.
|
||||
*
|
||||
* @return array The advanced robots meta values for the group.
|
||||
*/
|
||||
public function advanced_robots() {
|
||||
$robots = [];
|
||||
if ( Helper::get_settings( 'titles.bp_group_custom_robots' ) ) {
|
||||
$robots = Helper::get_settings( 'titles.bp_group_advanced_robots' );
|
||||
}
|
||||
|
||||
return Paper::advanced_robots_combine( $robots, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default canonical URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function canonical() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default meta keywords.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function keywords() {
|
||||
return '';
|
||||
}
|
||||
}
|
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* The BuddyPress user class for the BuddyPress module.
|
||||
*
|
||||
* @since 1.0.32
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
use RankMath\User;
|
||||
use RankMath\Helper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* BP_User class.
|
||||
*/
|
||||
class BP_User implements IPaper {
|
||||
|
||||
/**
|
||||
* Retrieves the SEO title set in the user metabox.
|
||||
*
|
||||
* @return string The SEO title for the user.
|
||||
*/
|
||||
public function title() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the SEO description set in the user metabox.
|
||||
*
|
||||
* @return string The SEO description for the user.
|
||||
*/
|
||||
public function description() {
|
||||
$description = User::get_meta( 'description', bp_displayed_user_id() );
|
||||
if ( '' !== $description ) {
|
||||
return $description;
|
||||
}
|
||||
|
||||
return Paper::get_from_options( 'author_archive_description' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the robots set in the user metabox.
|
||||
*
|
||||
* @return string The robots for the specified user.
|
||||
*/
|
||||
public function robots() {
|
||||
$robots = Paper::robots_combine( User::get_meta( 'robots', bp_displayed_user_id() ) );
|
||||
|
||||
if ( empty( $robots ) && Helper::get_settings( 'titles.author_custom_robots' ) ) {
|
||||
$robots = Paper::robots_combine( Helper::get_settings( 'titles.author_robots' ), true );
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the advanced robots set in the user metabox.
|
||||
*
|
||||
* @return array The advanced robots for the specified user.
|
||||
*/
|
||||
public function advanced_robots() {
|
||||
$robots = Paper::advanced_robots_combine( User::get_meta( 'advanced_robots', bp_displayed_user_id() ) );
|
||||
|
||||
if ( empty( $robots ) && Helper::get_settings( 'titles.author_custom_robots' ) ) {
|
||||
$robots = Paper::advanced_robots_combine( Helper::get_settings( 'titles.author_advanced_robots' ), true );
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default canonical URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function canonical() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default keywords.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function keywords() {
|
||||
return User::get_meta( 'focus_keyword', bp_displayed_user_id() );
|
||||
}
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* The BuddyPress groups settings.
|
||||
*
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Settings
|
||||
*/
|
||||
|
||||
use RankMath\Helper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$cmb->add_field(
|
||||
[
|
||||
'id' => 'bp_group_title',
|
||||
'type' => 'text',
|
||||
'name' => esc_html__( 'Group Title', 'rank-math' ),
|
||||
'desc' => esc_html__( 'Title tag for groups', 'rank-math' ),
|
||||
'classes' => 'rank-math-supports-variables rank-math-title',
|
||||
'default' => '',
|
||||
'sanitization_cb' => [ '\RankMath\CMB2', 'sanitize_textfield' ],
|
||||
'attributes' => [ 'data-exclude-variables' => 'seo_title,seo_description' ],
|
||||
]
|
||||
);
|
||||
|
||||
$cmb->add_field(
|
||||
[
|
||||
'id' => 'bp_group_description',
|
||||
'type' => 'textarea',
|
||||
'name' => esc_html__( 'Group Description', 'rank-math' ),
|
||||
'desc' => esc_html__( 'BuddyPress group description', 'rank-math' ),
|
||||
'classes' => 'rank-math-supports-variables rank-math-description',
|
||||
'attributes' => [
|
||||
'data-exclude-variables' => 'seo_title,seo_description',
|
||||
'rows' => 2,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$cmb->add_field(
|
||||
[
|
||||
'id' => 'bp_group_custom_robots',
|
||||
'type' => 'toggle',
|
||||
'name' => esc_html__( 'Group Robots Meta', 'rank-math' ),
|
||||
'desc' => __( 'Select custom robots meta for Group archive pages. Otherwise the default meta will be used, as set in the Global Meta tab.', 'rank-math' ),
|
||||
'options' => [
|
||||
'off' => esc_html__( 'Default', 'rank-math' ),
|
||||
'on' => esc_html__( 'Custom', 'rank-math' ),
|
||||
],
|
||||
'default' => $custom_default,
|
||||
'classes' => 'rank-math-advanced-option',
|
||||
]
|
||||
);
|
||||
|
||||
$cmb->add_field(
|
||||
[
|
||||
'id' => 'bp_group_robots',
|
||||
'type' => 'multicheck',
|
||||
'name' => esc_html__( 'Group Robots Meta', 'rank-math' ),
|
||||
'desc' => esc_html__( 'Custom values for robots meta tag on groups page.', 'rank-math' ),
|
||||
'options' => Helper::choices_robots(),
|
||||
'select_all_button' => false,
|
||||
'dep' => [ [ 'bp_group_custom_robots', 'on' ] ],
|
||||
'classes' => 'rank-math-advanced-option',
|
||||
]
|
||||
);
|
||||
|
||||
$cmb->add_field(
|
||||
[
|
||||
'id' => 'bp_group_advanced_robots',
|
||||
'type' => 'advanced_robots',
|
||||
'name' => esc_html__( 'Group Advanced Robots Meta', 'rank-math' ),
|
||||
'sanitization_cb' => [ '\RankMath\CMB2', 'sanitize_advanced_robots' ],
|
||||
'dep' => [ [ 'bp_group_custom_robots', 'on' ] ],
|
||||
'classes' => 'rank-math-advanced-option',
|
||||
]
|
||||
);
|
Reference in New Issue
Block a user