Fügen Sie einer Methode im übergeordneten Thema einen Filter hinzu

Ich habe ein Kinderthema mit diesem Filter:

function translate_subscribe_btn() { $new_form = str_replace('Subscribe', 'إشترك الآن', $form); return $new_form; } add_filter(array('Raymond_NewsletterWidget', 'get_widget_form'), 'translate_subscribe_btn'); 

Die ursprüngliche Methode: class Raymond_NewsletterWidget erweitert WP_Widget {

 function __construct() { parent::__construct(false, $name = '@Raymond Newsletter', array('description' => 'Newsletter widget to add subscription forms on sidebars'), array('width' => '350px')); } static function get_widget_form( array $instance=array() ) { $options_profile = get_option('newsletter_profile'); $placeholder =( isset( $instance['placeholder'] ) ) ? $instance['placeholder'] : __('Email','raymond'); $email = is_email( $options_profile['email'] ) ? $options_profile['email'] : $placeholder; $form = NewsletterSubscription::instance()->get_form_javascript(); $form .= '
'; // Referrer $form .= ''; if ($options_profile['name_status'] == 2) $form .= '

'; if ($options_profile['surname_status'] == 2) $form .= '

'; $form .= '

'; if (isset($options_profile['sex_status']) && $options_profile['sex_status'] == 2) { $form .= '

'; $form .= '' . $options_profile['sex_male'] . ''; $form .= '' . $options_profile['sex_female'] . ''; $form .= '

'; } // Extra profile fields for ($i = 1; $i <= NEWSLETTER_PROFILE_MAX; $i++) { if ($options_profile['profile_' . $i . '_status'] != 2) continue; if ($options_profile['profile_' . $i . '_type'] == 'text') { $form .= '

'; } if ($options_profile['profile_' . $i . '_type'] == 'select') { $form .= '

' . $options_profile['profile_' . $i] . '
'; $opts = explode(',', $options_profile['profile_' . $i . '_options']); for ($t = 0; $t < count($opts); $t++) { $form .= '' . trim($opts[$t]) . ''; } $form .= '

'; } } $lists = ''; for ($i = 1; $i <= NEWSLETTER_LIST_MAX; $i++) { if ($options_profile['list_' . $i . '_status'] != 2) continue; $lists .= ' ' . $options_profile['list_' . $i] . '
'; } if (!empty($lists)) $form .= '

' . $lists . '

'; $extra = apply_filters('newsletter_subscription_extra', array()); foreach ($extra as &$x) { $form .= "

"; if (!empty($x['label'])) $form .= $x['label'] . "
"; $form .= $x['field'] . "

"; } if ($options_profile['privacy_status'] == 1) { if (!empty($options_profile['privacy_url'])) { $form .= '

 ' . $options_profile['privacy'] . '

'; } else $form .= '

 ' . $options_profile['privacy'] . '

'; } if (strpos($options_profile['subscribe'], 'http://') !== false) { $form .= '

'; } else { $subscribe_text = 'Subscribe'; /*if ( is_rtl() ) { $subscribe_text = 'إشترك الآن'; }*/ //$form .= '

'; $form .= '

'; } // hide popup $form .= '
' . esc_html__("Don't show this popup again","raymond") .'
'; $form .= '
'; return $form; }

} Die get_widget_form ist eine statische Methode. Jetzt, wenn ich die Hauptseite aktualisiere, hat die Schaltfläche immer noch den gleichen Wert ” Abonnieren “, meine Frage hier, warum der Filter den Wert nicht geändert hat?

Solutions Collecting From Web of "Fügen Sie einer Methode im übergeordneten Thema einen Filter hinzu"

Versuchen Sie es mit Init-Hook

 add_action ('init', 'child_theme_hooks');

 function child_theme_hooks () {
     add_filter (array ('Raymond_NewsletterWidget', 'get_widget_form'), 'translate_subscribe_btn');
 }

 function translate_subscribe_btn () {
     $ new_form = str_replace ('Subscribe', 'إشترك الآن', $ form);
     return $ neues_formular;
 }