Я пытаюсь remove_filter
из этого плагина, так как WordPress refrenceЧто такое имя глобального класса в этом плагине php wordpress?
global $my_class;
remove_filter('the_content', array($my_class, 'class_filter_function'));
В этом коде есть 'add_filter('bp_core_fetch_avatar', array($this, 'set_buddypress_avatar'), 10, 1);'
, что я хотел бы remove_filter, большая проблема здесь, что $this
? Я не могу глобальный $this
, так что же такое $my_class
в следующем коде?
Я пробовал global $BuddyPress_First_Letter_Avatar
и global BuddyPress_First_Letter_Avata
, Это дало мне ошибку.
<?php
class BuddyPress_First_Letter_Avatar {
\t // Setup (these values always stay the same):
\t const BPFLA_IMAGES_PATH = 'images'; // avatars root directory
\t const BPFLA_GRAVATAR_URL = 'https://secure.gravatar.com/avatar/'; // default url for gravatar - we're using HTTPS to avoid annoying warnings
\t // Default configuration (this is the default configuration only for the first plugin usage):
\t const BPFLA_USE_PROFILE_AVATAR = TRUE; // TRUE: if user has his profile avatar, use it; FALSE: use custom avatars or Gravatars
\t const BPFLA_USE_GRAVATAR = TRUE; // TRUE: if user has Gravatar, use it; FALSE: use custom avatars or user's profile avatar
\t const BPFLA_AVATAR_SET = 'default'; // directory where avatars are stored
\t const BPFLA_LETTER_INDEX = 0; // 0: first letter; 1: second letter; -1: last letter, etc.
\t const BPFLA_IMAGES_FORMAT = 'png'; // file format of the avatars
\t const BPFLA_ROUND_AVATARS = FALSE; // TRUE: use rounded avatars; FALSE: dont use round avatars
\t const BPFLA_IMAGE_UNKNOWN = 'mystery'; // file name (without extension) of the avatar used for users with usernames beginning
\t \t \t \t \t \t \t \t \t \t // with symbol other than one from a-z range
\t // variables duplicating const values (will be changed in constructor after reading config from DB):
\t private $use_profile_avatar = self::BPFLA_USE_PROFILE_AVATAR;
\t private $use_gravatar = self::BPFLA_USE_GRAVATAR;
\t private $avatar_set = self::BPFLA_AVATAR_SET;
\t private $letter_index = self::BPFLA_LETTER_INDEX;
\t private $images_format = self::BPFLA_IMAGES_FORMAT;
\t private $round_avatars = self::BPFLA_ROUND_AVATARS;
\t private $image_unknown = self::BPFLA_IMAGE_UNKNOWN;
\t public function __construct(){
\t \t // add Settings link to plugins page:
\t \t add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'bpfla_add_settings_link'));
\t \t // add stylesheets/scripts:
\t \t add_action('wp_enqueue_scripts', array($this, 'bpfla_add_scripts'));
\t \t // add filter to get_avatar:
\t \t add_filter('get_avatar', array($this, 'set_comment_avatar'), 10, 5); // this will only be used for anonymous WordPress comments
\t \t // add filter to bp_core_fetch_avatar:
\t \t add_filter('bp_core_fetch_avatar', array($this, 'set_buddypress_avatar'), 10, 1);
\t \t // get plugin configuration from database:
\t \t $options = get_option('bpfla_settings');
\t \t if (empty($options)){
\t \t \t // no records in DB, use default (const) values to save plugin config:
\t \t \t $settings = array(
\t \t \t \t 'bpfla_use_profile_avatar' => self::BPFLA_USE_PROFILE_AVATAR,
\t \t \t \t 'bpfla_use_gravatar' => self::BPFLA_USE_GRAVATAR,
\t \t \t \t 'bpfla_avatar_set' => self::BPFLA_AVATAR_SET,
\t \t \t \t 'bpfla_letter_index' => self::BPFLA_LETTER_INDEX,
\t \t \t \t 'bpfla_file_format' => self::BPFLA_IMAGES_FORMAT,
\t \t \t \t 'bpfla_round_avatars' => self::BPFLA_ROUND_AVATARS,
\t \t \t \t 'bpfla_unknown_image' => self::BPFLA_IMAGE_UNKNOWN
\t \t \t);
\t \t \t add_option('bpfla_settings', $settings);
\t \t } else {
\t \t \t // there are records in DB for our plugin, let's assign them to our variables:
\t \t \t $this->use_profile_avatar = $options['bpfla_use_profile_avatar'];
\t \t \t $this->use_gravatar = $options['bpfla_use_gravatar'];
\t \t \t $this->avatar_set = $options['bpfla_avatar_set'];
\t \t \t $this->letter_index = $options['bpfla_letter_index'];
\t \t \t $this->images_format = $options['bpfla_file_format'];
\t \t \t $this->round_avatars = $options['bpfla_round_avatars'];
\t \t \t $this->image_unknown = $options['bpfla_unknown_image'];
\t \t }
\t }
?>public function set_buddypress_avatar($html_data = ''){
\t \t $html_doc = new DOMDocument();
\t \t $html_doc->loadHTML($html_data);
\t \t $image = $html_doc->getElementsByTagName('img');
\t \t foreach($image as $data) {
\t \t \t $original_image = $data->getAttribute('src');
\t \t \t $size = $data->getAttribute('width');
\t \t \t $alt = $data->getAttribute('alt');
\t \t
\t \t \t if (stripos($alt, 'Profile picture of ') === 0){ // if our alt attribute has "profile picture of" in the beginning...
\t \t \t \t $name = str_replace('Profile picture of ', '', $alt);
\t \t \t
\t \t \t } else if (stripos($alt, 'Profile photo of ') === 0){ // or profile photo of...
\t \t \t \t $name = str_replace('Profile photo of ', '', $alt);
\t \t \t
\t \t \t } else { // if there is some problem - just assign alt to name
\t \t \t \t $name = $alt;
\t \t \t
\t \t \t }
\t \t }
\t \t // something went wrong, just return what came in function argument:
\t \t if (empty($original_image) || empty($size) || empty($name) || empty($alt)){
\t \t \t return $html_data;
\t \t }
\t \t // if there is no gravatar URL it means that user has set his own profila avatar,
\t \t // so we're gonna see if we should be using it;
\t \t // if we should, just return the input data and leave the avatar as it was:
\t \t if ($this->use_profile_avatar == TRUE){
\t \t \t if (stripos($original_image, 'gravatar.com/avatar') === FALSE){
\t \t \t \t return $html_data;
\t \t \t }
\t \t }
\t \t // check whether Gravatar should be used at all:
\t \t if ($this->use_gravatar == TRUE){
\t \t \t // gravatar used as default option, now check whether user's gravatar is set:
\t \t \t if ($this->gravatar_exists_uri($original_image)){
\t \t \t \t // gravatar is set, return input data (nothing changes):
\t \t \t \t return $html_data;
\t \t \t } else {
\t \t \t \t // gravatar is not set, proceed to choose custom avatar:
\t \t \t \t $avatar_output = $this->choose_custom_avatar($name, $size, $alt,$gender);
\t \t \t }
\t \t } else {
\t \t \t // gravatar is not used as default option, only custom avatars will be used; proceed to choose custom avatar:
\t \t \t $avatar_output = $this->choose_custom_avatar($name, $size, $alt,$gender);
\t \t }
\t \t return $avatar_output;
\t }
«Я пытаюсь' remove_filter' из этого плагина». Что именно ** вы пытаетесь достичь? – D4V1D
пытается удалить этот add_filter ('bp_core_fetch_avatar', массив ($ this, 'set_buddypress_avatar'), 10, 1); в этом плагине – conan
Что произойдет, если вы это сделаете? – D4V1D