Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/leadin/public
File: class-pagehooks.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Leadin;
[2] Fix | Delete
[3] Fix | Delete
use Leadin\data\Filters;
[4] Fix | Delete
use Leadin\AssetsManager;
[5] Fix | Delete
use Leadin\data\User;
[6] Fix | Delete
use Leadin\auth\OAuth;
[7] Fix | Delete
use Leadin\admin\Connection;
[8] Fix | Delete
use Leadin\data\Portal_Options;
[9] Fix | Delete
use Leadin\utils\ShortcodeRenderUtils;
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Class responsible of adding the script loader to the website, as well as rendering forms, live chat, etc.
[13] Fix | Delete
*/
[14] Fix | Delete
class PageHooks {
[15] Fix | Delete
/**
[16] Fix | Delete
* Class constructor, adds the necessary hooks.
[17] Fix | Delete
*/
[18] Fix | Delete
public function __construct() {
[19] Fix | Delete
add_action( 'init', array( $this, 'register_content_type_meta' ) );
[20] Fix | Delete
[21] Fix | Delete
add_action( 'wp_head', array( $this, 'add_page_analytics' ) );
[22] Fix | Delete
if ( Connection::is_connected() ) {
[23] Fix | Delete
add_action( 'wp_enqueue_scripts', array( $this, 'add_frontend_scripts' ) );
[24] Fix | Delete
}
[25] Fix | Delete
add_filter( 'script_loader_tag', array( $this, 'add_id_to_tracking_code' ), 10, 2 );
[26] Fix | Delete
add_filter( 'script_loader_tag', array( $this, 'add_defer_to_forms_script' ), 10, 2 );
[27] Fix | Delete
add_shortcode( 'hubspot', array( $this, 'leadin_add_hubspot_shortcode' ) );
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Register meta key for content type
[32] Fix | Delete
*/
[33] Fix | Delete
public function register_content_type_meta() {
[34] Fix | Delete
register_post_meta(
[35] Fix | Delete
'',
[36] Fix | Delete
'content-type', // meta key.
[37] Fix | Delete
array(
[38] Fix | Delete
'object_subtype' => 'post', // specify a post type here.
[39] Fix | Delete
'type' => 'string',
[40] Fix | Delete
'single' => true,
[41] Fix | Delete
'show_in_rest' => true,
[42] Fix | Delete
'auth_callback' => function () {
[43] Fix | Delete
return current_user_can( 'edit_posts' );
[44] Fix | Delete
},
[45] Fix | Delete
)
[46] Fix | Delete
);
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Adds the script loader to the page.
[51] Fix | Delete
*/
[52] Fix | Delete
public function add_frontend_scripts() {
[53] Fix | Delete
if ( Portal_Options::get_disable_internal_tracking() && ( is_user_logged_in() || current_user_can( 'install_plugins' ) ) ) {
[54] Fix | Delete
return;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
if ( is_single() ) {
[58] Fix | Delete
$page_type = 'post';
[59] Fix | Delete
} elseif ( is_front_page() ) {
[60] Fix | Delete
$page_type = 'home';
[61] Fix | Delete
} elseif ( is_archive() ) {
[62] Fix | Delete
$page_type = 'archive';
[63] Fix | Delete
} elseif ( is_page() ) {
[64] Fix | Delete
$page_type = 'page';
[65] Fix | Delete
} else {
[66] Fix | Delete
$page_type = 'other';
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
$leadin_wordpress_info = array(
[70] Fix | Delete
'userRole' => User::get_role(),
[71] Fix | Delete
'pageType' => $page_type,
[72] Fix | Delete
'leadinPluginVersion' => LEADIN_PLUGIN_VERSION,
[73] Fix | Delete
);
[74] Fix | Delete
[75] Fix | Delete
AssetsManager::enqueue_script_loader( $leadin_wordpress_info );
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Adds the script containing the information needed by the script loader.
[80] Fix | Delete
*/
[81] Fix | Delete
public function add_page_analytics() {
[82] Fix | Delete
$portal_id = Portal_Options::get_portal_id();
[83] Fix | Delete
[84] Fix | Delete
if ( empty( $portal_id ) ) {
[85] Fix | Delete
echo '<!-- HubSpot WordPress Plugin v' . esc_html( LEADIN_PLUGIN_VERSION ) . ': embed JS disabled as a portalId has not yet been configured -->';
[86] Fix | Delete
} else {
[87] Fix | Delete
$content_type = Filters::apply_page_content_type_filters();
[88] Fix | Delete
$page_id = get_the_ID();
[89] Fix | Delete
$post_meta = get_post_meta( $page_id );
[90] Fix | Delete
if ( isset( $post_meta['content-type'][0] ) && '' !== $post_meta['content-type'][0] ) {
[91] Fix | Delete
$content_type = $post_meta['content-type'][0];
[92] Fix | Delete
} elseif ( is_plugin_active( 'elementor/elementor.php' ) ) {
[93] Fix | Delete
$page_settings_manager = \Elementor\Core\Settings\Manager::get_settings_managers( 'page' );
[94] Fix | Delete
$page_settings_model = $page_settings_manager->get_model( $page_id );
[95] Fix | Delete
$elementor_content_type = $page_settings_model->get_settings( 'content_type' );
[96] Fix | Delete
if ( ! empty( $elementor_content_type ) ) {
[97] Fix | Delete
$content_type = $elementor_content_type;
[98] Fix | Delete
}
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
?>
[102] Fix | Delete
<!-- DO NOT COPY THIS SNIPPET! Start of Page Analytics Tracking for HubSpot WordPress plugin v<?php echo esc_html( LEADIN_PLUGIN_VERSION ); ?>-->
[103] Fix | Delete
<script class="hsq-set-content-id" data-content-id="<?php echo esc_html( $content_type ); ?>">
[104] Fix | Delete
var _hsq = _hsq || [];
[105] Fix | Delete
_hsq.push(["setContentType", "<?php echo esc_html( $content_type ); ?>"]);
[106] Fix | Delete
</script>
[107] Fix | Delete
<!-- DO NOT COPY THIS SNIPPET! End of Page Analytics Tracking for HubSpot WordPress plugin -->
[108] Fix | Delete
<?php
[109] Fix | Delete
}
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Add the required id to the script loader <script>
[114] Fix | Delete
*
[115] Fix | Delete
* @param String $tag tag name.
[116] Fix | Delete
* @param String $handle handle.
[117] Fix | Delete
*/
[118] Fix | Delete
public function add_id_to_tracking_code( $tag, $handle ) {
[119] Fix | Delete
if ( AssetsManager::TRACKING_CODE === $handle ) {
[120] Fix | Delete
$tag = str_replace( "id='" . $handle . "-js'", "async defer id='hs-script-loader'", $tag );
[121] Fix | Delete
}
[122] Fix | Delete
return $tag;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Add defer to leadin forms plugin
[127] Fix | Delete
*
[128] Fix | Delete
* @param String $tag tag name.
[129] Fix | Delete
* @param String $handle handle.
[130] Fix | Delete
*/
[131] Fix | Delete
public function add_defer_to_forms_script( $tag, $handle ) {
[132] Fix | Delete
if ( AssetsManager::FORMS_SCRIPT === $handle ) {
[133] Fix | Delete
$tag = str_replace( 'src', 'defer src', $tag );
[134] Fix | Delete
}
[135] Fix | Delete
return $tag;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Parse leadin shortcodes
[140] Fix | Delete
*
[141] Fix | Delete
* @param array $attributes Shortcode attributes.
[142] Fix | Delete
*/
[143] Fix | Delete
public function leadin_add_hubspot_shortcode( $attributes ) {
[144] Fix | Delete
return ShortcodeRenderUtils::render_shortcode( $attributes );
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function