这个插件php wordpress中的全局类名是什么?

时间:2015-03-31 05:51:01

标签: javascript php wordpress

我正试图从这个插件中remove_filter,作为wordpress refrence

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_Avatarglobal BuddyPress_First_Letter_Avata, 它给了我错误。



<?php
class BuddyPress_First_Letter_Avatar {

	// Setup (these values always stay the same):
	const BPFLA_IMAGES_PATH = 'images'; // avatars root directory
	const BPFLA_GRAVATAR_URL = 'https://secure.gravatar.com/avatar/';    // default url for gravatar - we're using HTTPS to avoid annoying warnings

	// Default configuration (this is the default configuration only for the first plugin usage):
	const BPFLA_USE_PROFILE_AVATAR = TRUE;  // TRUE: if user has his profile avatar, use it; FALSE: use custom avatars or Gravatars
	const BPFLA_USE_GRAVATAR = TRUE;  // TRUE: if user has Gravatar, use it; FALSE: use custom avatars or user's profile avatar
	const BPFLA_AVATAR_SET = 'default'; // directory where avatars are stored
	const BPFLA_LETTER_INDEX = 0;  // 0: first letter; 1: second letter; -1: last letter, etc.
	const BPFLA_IMAGES_FORMAT = 'png';   // file format of the avatars
	const BPFLA_ROUND_AVATARS = FALSE;     // TRUE: use rounded avatars; FALSE: dont use round avatars
	const BPFLA_IMAGE_UNKNOWN = 'mystery';    // file name (without extension) of the avatar used for users with usernames beginning
										// with symbol other than one from a-z range
	// variables duplicating const values (will be changed in constructor after reading config from DB):
	private $use_profile_avatar = self::BPFLA_USE_PROFILE_AVATAR;
	private $use_gravatar = self::BPFLA_USE_GRAVATAR;
	private $avatar_set = self::BPFLA_AVATAR_SET;
	private $letter_index = self::BPFLA_LETTER_INDEX;
	private $images_format = self::BPFLA_IMAGES_FORMAT;
	private $round_avatars = self::BPFLA_ROUND_AVATARS;
	private $image_unknown = self::BPFLA_IMAGE_UNKNOWN;



	public function __construct(){

		// add Settings link to plugins page:
		add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'bpfla_add_settings_link'));

		// add stylesheets/scripts:
		add_action('wp_enqueue_scripts', array($this, 'bpfla_add_scripts'));

		// add filter to get_avatar:
		add_filter('get_avatar', array($this, 'set_comment_avatar'), 10, 5); // this will only be used for anonymous WordPress comments

		// add filter to bp_core_fetch_avatar:
		add_filter('bp_core_fetch_avatar', array($this, 'set_buddypress_avatar'), 10, 1);

		// get plugin configuration from database:
		$options = get_option('bpfla_settings');
		if (empty($options)){
			// no records in DB, use default (const) values to save plugin config:
			$settings = array(
				'bpfla_use_profile_avatar' => self::BPFLA_USE_PROFILE_AVATAR,
				'bpfla_use_gravatar' => self::BPFLA_USE_GRAVATAR,
				'bpfla_avatar_set' => self::BPFLA_AVATAR_SET,
				'bpfla_letter_index' => self::BPFLA_LETTER_INDEX,
				'bpfla_file_format' => self::BPFLA_IMAGES_FORMAT,
				'bpfla_round_avatars' => self::BPFLA_ROUND_AVATARS,
				'bpfla_unknown_image' => self::BPFLA_IMAGE_UNKNOWN
			);
			add_option('bpfla_settings', $settings);
		} else {
			// there are records in DB for our plugin, let's assign them to our variables:
			$this->use_profile_avatar = $options['bpfla_use_profile_avatar'];
			$this->use_gravatar = $options['bpfla_use_gravatar'];
			$this->avatar_set = $options['bpfla_avatar_set'];
			$this->letter_index = $options['bpfla_letter_index'];
			$this->images_format = $options['bpfla_file_format'];
			$this->round_avatars = $options['bpfla_round_avatars'];
			$this->image_unknown = $options['bpfla_unknown_image'];
		}

	}


?>public function set_buddypress_avatar($html_data = ''){

		$html_doc = new DOMDocument();
		$html_doc->loadHTML($html_data);
		$image = $html_doc->getElementsByTagName('img');
		foreach($image as $data) {
			$original_image = $data->getAttribute('src');
			$size = $data->getAttribute('width');
			$alt = $data->getAttribute('alt');
		    
			if (stripos($alt, 'Profile picture of ') === 0){ // if our alt attribute has "profile picture of" in the beginning...
				$name = str_replace('Profile picture of ', '', $alt);
			   
			} else if (stripos($alt, 'Profile photo of ') === 0){ // or profile photo of...
				$name = str_replace('Profile photo of ', '', $alt);
			    
			} else { // if there is some problem - just assign alt to name
				$name = $alt;
			    
			}
		}

		// something went wrong, just return what came in function argument:
		if (empty($original_image) || empty($size) || empty($name) || empty($alt)){
			return $html_data;
		}

		// if there is no gravatar URL it means that user has set his own profila avatar,
		// so we're gonna see if we should be using it;
		// if we should, just return the input data and leave the avatar as it was:
		if ($this->use_profile_avatar == TRUE){
			if (stripos($original_image, 'gravatar.com/avatar') === FALSE){
				return $html_data;
			}
		}

		// check whether Gravatar should be used at all:
		if ($this->use_gravatar == TRUE){
			// gravatar used as default option, now check whether user's gravatar is set:
			if ($this->gravatar_exists_uri($original_image)){
				// gravatar is set, return input data (nothing changes):
				return $html_data;
			} else {
				// gravatar is not set, proceed to choose custom avatar:
				$avatar_output = $this->choose_custom_avatar($name, $size, $alt,$gender);
			}
		} else {
			// gravatar is not used as default option, only custom avatars will be used; proceed to choose custom avatar:
			$avatar_output = $this->choose_custom_avatar($name, $size, $alt,$gender);
		}

		return $avatar_output;

	}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

你有没有试过这样的东西

remove_filter( 'the_content', array('BuddyPress_First_Letter_Avatar ', 'class_filter_function') );