/is', $links['deactivate'], $result ) === 1 ) $links['deactivate'] = preg_replace( '/()/s', '$1 cn-deactivate-plugin-modal$2', $links['deactivate'] ); else $links['deactivate'] = preg_replace( '/(/s', '$1 class="cn-deactivate-plugin-modal">', $links['deactivate'] ); // link already contains href attribute? if ( preg_match( '//is', $links['deactivate'], $result ) === 1 ) { if ( ! empty( $result[2] ) ) $this->deactivaion_url = $result[2]; } } // skip settings link if plugin is activated from main site if ( ! ( $this->is_network_admin() && ! $this->is_plugin_network_active() ) ) { $url = $this->is_network_admin() ? network_admin_url( 'admin.php?page=cookie-notice' ) : admin_url( 'admin.php?page=cookie-notice' ); // put settings link at start array_unshift( $links, sprintf( '%s', esc_url( $url ), esc_html__( 'Settings', 'cookie-notice' ) ) ); } // get cookie compliance status $status = $this->get_status(); if ( is_multisite() ) { $check_status = empty( $status ) && ( ( $this->is_network_admin() && $this->is_plugin_network_active() && $this->network_options['general']['global_override'] ) || ( ! $this->is_network_admin() && ( ( $this->is_plugin_network_active() && ! $this->network_options['general']['global_override'] ) || ! $this->is_plugin_network_active() ) ) ); } else $check_status = empty( $status ); // add upgrade link if ( $check_status ) { $url = $this->is_network_admin() ? network_admin_url( 'admin.php?page=cookie-notice&welcome=1' ) : admin_url( 'admin.php?page=cookie-notice&welcome=1' ); $links[] = sprintf( '%s', esc_url( $url ), esc_html__( 'Free Upgrade', 'cookie-notice' ) ); } } return $links; } /** * Deactivation modal HTML template. * * @global string $pagenow * * @return void */ public function deactivate_plugin_template() { global $pagenow; // display only for plugins page if ( $pagenow !== 'plugins.php' ) return; echo ' '; } /** * Send data about deactivation of the plugin. * * @return void */ public function deactivate_plugin() { // check permissions if ( ! current_user_can( 'install_plugins' ) || wp_verify_nonce( $_POST['nonce'], 'cn-deactivate-plugin' ) === false ) return; if ( isset( $_POST['option_id'] ) ) { $option_id = (int) $_POST['option_id']; // avoid fake submissions if ( $option_id === 8 ) { $other = isset( $_POST['other'] ) ? sanitize_textarea_field( $_POST['other'] ) : ''; // no reason? if ( $other === '' ) wp_send_json_success(); } wp_remote_post( 'https://hu-manity.co/wp-json/api/v1/forms/', [ 'timeout' => 15, 'blocking' => true, 'headers' => [], 'body' => [ 'id' => 1, 'option' => $option_id, 'other' => $other, 'referrer' => get_site_url() ] ] ); wp_send_json_success(); } wp_send_json_error(); } /** * Get allowed script blocking HTML. * * @param string $type * @return array */ public function get_allowed_html( $type = 'head' ) { // default allowed html for both types $allowed_html = [ 'script' => [ 'type' => true, 'src' => true, 'charset' => true, 'async' => true, 'defer' => true, 'crossorigin' => true, 'fetchpriority' => true, 'referrerpolicy' => true, 'nomodule' => true, 'nonce' => true, 'integrity' => true, 'class' => true, 'id' => true ], 'noscript' => [ 'class' => true, 'id' => true ], 'style' => [ 'type' => true, 'media' => true, 'nonce' => true, 'class' => true, 'id' => true ] ]; if ( $type === 'head' ) { // allow links for head $allowed_html['link'] = [ 'as' => true, 'crossorigin' => true, 'fetchpriority' => true, 'imagesizes' => true, 'imagesrcset' => true, 'referrerpolicy' => true, 'sizes' => true, 'integrity' => true, 'href' => true, 'hreflang' => true, 'rel' => true, 'type' => true, 'title' => true, 'media' => true, 'class' => true, 'id' => true ]; } elseif ( $type === 'body' ) { // allow ifarmes for body $allowed_html['iframe'] = [ 'src' => true, 'srcdoc' => true, 'height' => true, 'width' => true, 'class' => true, 'id' => true, 'allow' => true, 'loading' => true, 'name' => true, 'title' => true, 'referrerpolicy' => true, 'sandbox' => true, 'allowfullscreen' => true ]; } // combine allowed tags with default post allowed tags return apply_filters( 'cn_refuse_code_allowed_html', array_merge( wp_kses_allowed_html( 'post' ), $allowed_html ), $type ); } /** * Merge multidimensional associative arrays. * Works only with strings, integers and arrays as keys. Values can be any type but they have to have same type to be kept in the final array. * Every array should have the same type of elements. Only keys from $defaults array will be kept in the final array unless $siblings are not empty. * $siblings examples: array( '=>', 'only_first_level', 'first_level=>second_level', 'first_key=>next_key=>sibling' ) and so on. * Single '=>' means that all siblings of the highest level will be kept in the final array. * * @param array $defaults Array with defaults values * @param array $array Array to merge * @param bool|array $siblings Whether to allow "string" siblings to copy from $array if they do not exist in $defaults, false otherwise * @return array */ public function multi_array_merge( $defaults, $array, $siblings = false ) { // make a copy for better performance and to prevent $default override in foreach $copy = $defaults; // prepare siblings for recursive deeper level $new_siblings = []; // allow siblings? if ( ! empty( $siblings ) && is_array( $siblings ) ) { foreach ( $siblings as $sibling ) { // highest level siblings if ( $sibling === '=>' ) { // copy all non-existent string siblings foreach( $array as $key => $value ) { if ( is_string( $key ) && ! array_key_exists( $key, $defaults ) ) { $defaults[$key] = null; } } // sublevel siblings } else { // explode siblings $ex = explode( '=>', $sibling ); // copy all non-existent siblings foreach ( array_keys( $array[$ex[0]] ) as $key ) { if ( ! array_key_exists( $key, $defaults[$ex[0]] ) ) $defaults[$ex[0]][$key] = null; } // more than one sibling child? if ( count( $ex ) > 1 ) $new_siblings[$ex[0]] = [ substr_replace( $sibling, '', 0, strlen( $ex[0] . '=>' ) ) ]; // no more sibling children else $new_siblings[$ex[0]] = false; } } } // loop through first array foreach ( $defaults as $key => $value ) { // integer key? if ( is_int( $key ) ) { $copy = array_unique( array_merge( $defaults, $array ), SORT_REGULAR ); break; // string key? } elseif ( is_string( $key ) && isset( $array[$key] ) ) { // string, boolean, integer or null values? if ( ( is_string( $value ) && is_string( $array[$key] ) ) || ( is_bool( $value ) && is_bool( $array[$key] ) ) || ( is_int( $value ) && is_int( $array[$key] ) ) || is_null( $value ) ) $copy[$key] = $array[$key]; // arrays elseif ( is_array( $value ) && isset( $array[$key] ) && is_array( $array[$key] ) ) { if ( empty( $value ) ) $copy[$key] = $array[$key]; else $copy[$key] = $this->multi_array_merge( $defaults[$key], $array[$key], ( isset( $new_siblings[$key] ) ? $new_siblings[$key] : false ) ); } } } return $copy; } /** * Indicate if current page is the Cookie Policy page. * * @return bool */ public function is_cookie_policy_page() { // get privacy policy options $see_more = $this->options['general']['see_more_opt']; // custom link? if ( $see_more['link_type'] !== 'page' ) return false; // get current object $current_page = sanitize_post( $GLOBALS['wp_the_query']->get_queried_object() ); // check if current page is privacy policy page return $current_page->post_name === get_post_field( 'post_name', $see_more['id'] ); } } /** * Initialize Cookie Notice. * * @return object */ function Cookie_Notice() { static $instance; // first call to instance() initializes the plugin if ( $instance === null || ! ( $instance instanceof Cookie_Notice ) ) $instance = Cookie_Notice::instance(); return $instance; } Cookie_Notice();