ext = null ) {
$hide_html = '';
$hide_html .= '';
if ( $localized_text ) {
$hide_html .= esc_html( $localized_text );
} else {
$hide_html .= esc_html__( 'Hide this notice.', 'sitepress' );
}
$hide_html .= '';
return $hide_html;
}
/**
* @param null|string $localized_text
*
* @return string
*/
private function get_dismiss_html( $localized_text = null ) {
$dismiss_html = '';
$dismiss_html .= '';
$dismiss_html .= '';
if ( $localized_text ) {
$dismiss_html .= esc_html( $localized_text );
} else {
$dismiss_html .= esc_html__( 'Dismiss this notice.', 'sitepress' );
}
$dismiss_html .= '';
return $dismiss_html;
}
/**
* @param string|null $localized_text
*
* @return string
*/
private function get_collapse_html( $localized_text = null ) {
$hide_html = '';
if ( $localized_text ) {
$hide_html .= esc_html( $localized_text );
} else {
$hide_html .= esc_html__( 'Hide this notice.', 'sitepress' );
}
$hide_html .= '';
return $hide_html;
}
/**
* @param WPML_Notice $notice
* @param string|null $localized_text
*
* @return string
*/
private function get_collapsed_html( WPML_Notice $notice, $localized_text = null ) {
$content = '
%s
';
$content = sprintf(
$content,
$notice->get_collapsed_text(),
$localized_text ? esc_html( $localized_text ) : esc_html__( 'Show this notice.', 'sitepress' ),
$notice->get_text()
);
return $content;
}
/**
* @param WPML_Notice_Action $action
*
* @return string
*/
private function get_action_html( $action ) {
$action_html = '';
if ( $action->can_hide() ) {
$action_html .= $this->get_hide_html( $action->get_text() );
$this->hide_html_added = true;
} elseif ( $action->can_dismiss() ) {
$action_html .= $this->get_dismiss_html( $action->get_text() );
$this->dismiss_html_added = true;
} else {
if ( $action->get_url() ) {
$action_html .= $this->get_action_anchor( $action );
} else {
$action_html .= $action->get_text();
}
}
return $action_html;
}
/**
* @param WPML_Notice_Action $action
*
* @return string
*/
private function get_action_anchor( WPML_Notice_Action $action ) {
$anchor_attributes = array();
$action_url = 'get_url() );
if ( $action->get_link_target() ) {
$anchor_attributes['target'] = $action->get_link_target();
}
$action_url_classes = array( 'notice-action' );
if ( $action->must_display_as_button() ) {
$button_style = 'button-secondary';
if ( is_string( $action->must_display_as_button() ) ) {
$button_style = $action->must_display_as_button();
}
$action_url_classes[] = esc_attr( $button_style );
$action_url_classes[] = 'notice-action-' . esc_attr( $button_style );
} else {
$action_url_classes[] = 'notice-action-link';
}
$anchor_attributes['class'] = implode( ' ', $action_url_classes );
if ( $action->get_group_to_dismiss() ) {
$anchor_attributes['data-dismiss-group'] = esc_attr( $action->get_group_to_dismiss() );
}
if ( $action->get_js_callback() ) {
$anchor_attributes['data-js-callback'] = esc_attr( $action->get_js_callback() )
. '"';
}
foreach ( $anchor_attributes as $name => $value ) {
$action_url .= ' ' . $name . '="' . $value . '"';
}
$action_url .= $this->get_data_nonce_attribute();
$action_url .= '>';
$action_url .= $action->get_text();
$action_url .= '';
return $action_url;
}
/**
* @return string
*/
private function get_data_nonce_attribute() {
return ' data-nonce="' . wp_create_nonce( WPML_Notices::NONCE_NAME ) . '"';
}
/**
* @param WPML_Notice $notice
*
* @return bool
*/
private function is_current_screen_allowed( WPML_Notice $notice ) {
$allow_current_screen = true;
$restrict_to_screen_ids = $notice->get_restrict_to_screen_ids();
if ( $restrict_to_screen_ids && function_exists( 'get_current_screen' ) ) {
$screen = get_current_screen();
$allow_current_screen = $screen && in_array( $screen->id, $restrict_to_screen_ids, true );
}
return $allow_current_screen;
}
/**
* @param WPML_Notice $notice
* @param string $current_page
*
* @return bool
*/
private function is_current_page_prefix_allowed( WPML_Notice $notice, $current_page ) {
$restrict_to_page_prefixes = $notice->get_restrict_to_page_prefixes();
if ( $current_page && $restrict_to_page_prefixes ) {
$allow_current_page_prefix = false;
foreach ( $restrict_to_page_prefixes as $restrict_to_prefix ) {
if ( stripos( $current_page, $restrict_to_prefix ) === 0 ) {
$allow_current_page_prefix = true;
break;
}
}
return $allow_current_page_prefix;
}
return true;
}
/**
* @param WPML_Notice $notice
*
* @return bool
*/
private function is_current_page_allowed( WPML_Notice $notice ) {
$current_page = array_key_exists( 'page', $_GET ) ? $_GET['page'] : null;
if ( ! $this->is_current_screen_allowed( $notice ) ) {
return false;
}
if ( $current_page ) {
$exclude_from_pages = $notice->get_exclude_from_pages();
if ( $exclude_from_pages && in_array( $current_page, $exclude_from_pages, true ) ) {
return false;
}
if ( ! $this->is_current_page_prefix_allowed( $notice, $current_page ) ) {
return false;
}
$restrict_to_pages = $notice->get_restrict_to_pages();
if ( $restrict_to_pages && ! in_array( $current_page, $restrict_to_pages, true ) ) {
return false;
}
}
return true;
}
/**
* @param WPML_Notice $notice
*
* @return bool
*/
private function is_allowed_by_callback( WPML_Notice $notice ) {
$allow_by_callback = true;
$display_callbacks = $notice->get_display_callbacks();
if ( $display_callbacks ) {
$allow_by_callback = false;
foreach ( $display_callbacks as $callback ) {
if ( is_callable( $callback ) && call_user_func( $callback ) ) {
$allow_by_callback = true;
break;
}
}
}
return $allow_by_callback;
}
}