繁体   English   中英

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

What is the global class name in this plugin php wordpress?

提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供   中文繁体   英文版本   中英对照 版本,有任何建议请联系yoyou2525@163.com。

我正在尝试从此插件中remove_filter ,因为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_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 az 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; } 

1 个回复

你有没有尝试过这样的事情

remove_filter( 'the_content', array('BuddyPress_First_Letter_Avatar ', 'class_filter_function') ); 
1 php类作为wordpress中的插件

我怎样才能编写一个插件,只打算提供其他插件调用的类。 例如,如果我有这样的类: 然后在wordpress envrionement中,我们将能够调用Test::testMethod(); 以下是否有效? 我不认为这是一种正确的方法。 任何输入都表示赞赏。 ...

2 在Wordpress插件中创建PHP类的实例

我想在不使用名称空间的Wordpress-Plugin(事件日历专业版)中使用PHP类的功能。 我这样做没有问题,但我担心该插件的开发人员将来会重新组织其插件目录,结果是类文件将位于不同的位置=&gt;意味着我的代码将被破坏。 我可以在PHP或Wordpress中做些什么,让我在插件目录 ...

3 为什么这个php全局不会在Wordpress插件中回显

我是PHP的新手,我不确定为什么这行不通。 我已经完成了此页面上所说的所有操作,例如http://php.net/manual/en/language.variables.scope.php (示例#1使用全局)...为什么不起作用? 令人沮丧。 这是Wordpress插件的首次尝试。 ...

5 “应用全局类名”是什么意思?

我正在尝试使用 Material-UI 构建我的界面(当前版本是 3.1.2。) 不久前,当我使用 Bootstrap4 时,我在head标签中添加了style="overflow-y: scroll; height: 100%"以始终显示滚动条以阻止应用在页面内容增长超过屏幕时跳转. 现在我正 ...

9 那么如何在PHP中使类名全局化?

我有一个名为“用户”的类,具有一个函数“ createAccount”。 我喜欢在其中通过PostageApp :: mail访问另一个类 但是由于此类不在范围内,因此无法访问。 global接缝仅适用于变量。 那么,如何使一个类名全局? ...

10 是否可以替换WordPress插件的PHP类中的函数?

我读到“除非原始函数被覆盖,否则。这是基本的PHP。” 但我试图在不编辑插件文件的情况下编辑WooCommerce插件,以便可以在不丢失更改的情况下更新插件。 我已经设置了一个子主题并在functions.php中完成了以下操作,但它不起作用... functions.php ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2022 STACKOOM.COM