Current File : //var/www/tusveterinarios/wp-content/plugins/joinchat-plus/includes/class-joinchat-remove-brand.php |
<?php
/**
* Join.chat Remove Brand
*
* Add Join.chat admin field for apply remove brand
* and remove "Powered by Join.chat" if enabled.
*
* @version 2.0.0
* @package JoinChat Remove Brand
* @author Creame <hola@crea.me>
*/
if ( ! class_exists( 'JoinChatRemoveBrand' ) ) {
class JoinChatRemoveBrand {
/**
* Initialize the class and set init hook.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct() {
add_action( 'joinchat_run_pre', array( $this, 'init' ) );
}
/**
* Initialize all hooks
*
* @since 1.0.0
* @param array $joinchat JoinChat object.
* @return void
*/
public function init( $joinchat ) {
$loader = $joinchat->get_loader();
$loader->add_filter( 'joinchat_extra_settings', $this, 'extra_settings' );
$loader->add_filter( 'joinchat_tab_general_sections', $this, 'get_sections' );
$loader->add_filter( 'joinchat_field_output', $this, 'field_output', 10, 3 );
$loader->add_filter( 'joinchat_settings_validate', $this, 'settings_validate' );
$loader->add_filter( 'joinchat_get_settings', $this, 'get_settings', 10, 2 );
}
/**
* Add "remove brand" extra setting default
*
* @since 1.0.0
* @param array $extra current settings.
* @return array
*/
public function extra_settings( $extra ) {
return array_merge( $extra, array( 'remove_brand' => 'no' ) );
}
/**
* Add "remove brand" setting for chat section
*
* @since 1.0.0
* @param array $sections sections and fields.
* @return array
*/
public function get_sections( $sections ) {
$sections['chat'] = array_merge( $sections['chat'], array( 'remove_brand' => __( 'Logo', 'creame-whatsapp-me' ) ) );
return $sections;
}
/**
* "remove brand" field HTML output
*
* @since 1.0.0
* @since 2.0.0 change to radio fields
* @param string $output current field output.
* @param string $field_id current field id.
* @param array $settings current joinchat settings.
* @return string
*/
public function field_output( $output, $field_id, $settings ) {
if ( 'remove_brand' === $field_id ) {
$value = isset( $settings['remove_brand'] ) ? $settings['remove_brand'] : 'no';
$output = '<fieldset><legend class="screen-reader-text"><span>' . __( 'Logo', 'creame-whatsapp-me' ) . '</span></legend>' .
'<label><input id="joinchat_remove_brand" name="joinchat[remove_brand]" value="no" type="radio"' . checked( 'no', $value, false ) . '> ' .
__( 'Powered by Join.chat', 'creame-whatsapp-me' ) . '</label><br>' .
'<label><input id="joinchat_remove_brand" name="joinchat[remove_brand]" value="wa" type="radio"' . checked( 'wa', $value, false ) . '> ' .
__( 'WhatsApp', 'creame-whatsapp-me' ) . '</label><br>' .
'<label><input id="joinchat_remove_brand" name="joinchat[remove_brand]" value="yes" type="radio"' . checked( 'yes', $value, false ) . '> ' .
__( 'None', 'creame-whatsapp-me' ) . '</label>' .
'</fieldset>';
}
return $output;
}
/**
* "remove brand" setting validation
*
* @since 1.0.0
* @param array $input form input.
* @return array
*/
public function settings_validate( $input ) {
$valid = array( 'yes', 'no', 'wa' );
$input['remove_brand'] = isset( $input['remove_brand'] ) && in_array( $input['remove_brand'], $valid ) ? $input['remove_brand'] : 'no';
return $input;
}
/**
* Apply remove brand if set and clear setting
*
* @since 1.0.0
* @since 2.0.0 added 'whatsapp_brand'
* @param array $settings current settings.
* @return array
*/
public function get_settings( $settings, $obj ) {
if ( isset( $settings['remove_brand'] ) ) {
if ( 'no' !== $settings['remove_brand'] ) {
add_filter( 'joinchat_copy', '__return_false' );
}
if ( 'wa' === $settings['remove_brand'] ) {
add_filter( 'joinchat_html_output', array( $this, 'whatsapp_brand' ) );
}
unset( $settings['remove_brand'] );
}
return $settings;
}
/**
* Insert WhatsApp logo in Chat Window header
*
* @since 2.0.0
* @param string $output current html otput.
* @return string
*/
public function whatsapp_brand( $output ) {
$from = strpos( $output, '<div class="joinchat__header">' );
if ( false !== $from ) {
$from += strlen( '<div class="joinchat__header">' );
$length = strpos( $output, '<div class="joinchat__close"' ) - $from;
$replace = '<span class="joinchat__copy" aria-label="WhatsApp"><svg viewBox="0 0 120 28" style="height:28px; vertical-align:-45%;">' .
'<path d="M117.2 17c0 .4-.2.7-.4 1-.1.3-.4.5-.7.7l-1 .2c-.5 0-.9 0-1.2-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6.3.4.4 1 .4 1.8v5.5h2.7v-6c0-.6 0-1.2-.2-1.6 0-.5-.3-1-.5-1.3zm-14 4.7l-2.3-9.2h-2.8l-2.3 9-2.2-9h-3l3.6 13.4h3l2.2-9.2 2.3 9.2h3l3.6-13.4h-3l-2.1 9.2zm-24.5.2L18 15.6c-.3-.1-.6-.2-.8.2A20 20 0 0 1 16 17c-.2.2-.4.3-.7.1-.4-.2-1.5-.5-2.8-1.7-1-1-1.7-2-2-2.4-.1-.4 0-.5.2-.7l.5-.6.4-.6v-.6L10.4 8c-.3-.6-.6-.5-.8-.6H9c-.2 0-.6.1-.9.5C7.8 8.2 7 9 7 10.7c0 1.7 1.3 3.4 1.4 3.6.2.3 2.5 3.7 6 5.2l1.9.8c.8.2 1.6.2 2.2.1.6-.1 2-.8 2.3-1.6.3-.9.3-1.5.2-1.7l-.7-.4zM14 25.3c-2 0-4-.5-5.8-1.6l-.4-.2-4.4 1.1 1.2-4.2-.3-.5A11.5 11.5 0 0 1 22.1 5.7 11.5 11.5 0 0 1 14 25.3zM14 0A13.8 13.8 0 0 0 2 20.7L0 28l7.3-2A13.8 13.8 0 1 0 14 0z"/></svg></span>';
$output = substr_replace( $output, $replace, $from, $length );
}
return $output;
}
}
new JoinChatRemoveBrand();
}