_type == 'page'){ $page_list = isset($individual_options['pages']) ? $individual_options['pages'] : array(); $current_page = ( $page_path !== '/' ) ? get_page_by_path( trim($page_path, '/'), 'OBJECT', 'page' ) : null; if(in_array('all_pages,all_pages', $page_list) && ( $is_front_page || (!empty($current_page) && $current_page->post_status === 'publish') )){ $remove_plugins[] = $plugin; } else { foreach($page_list as $page_info){ $page_info_arr = explode(',', $page_info); $page_id = $page_info_arr[0]; $page_link = htpm_strip_host( $page_info_arr[1] ); if( $page_link && $page_link == $page_path ){ $remove_plugins[] = $plugin; } } } } if($uri_type == 'post'){ $post_list = isset($individual_options['posts']) ? $individual_options['posts'] : array(); $current_page = get_page_by_path( basename($page_path), 'OBJECT', 'post' ); if(in_array('all_posts,all_posts', $post_list) && !empty($current_page) && $current_page->post_status === 'publish'){ $remove_plugins[] = $plugin; } else { foreach($post_list as $post_info){ $post_info_arr = explode(',', $post_info); $post_id = $post_info_arr[0]; $post_link = htpm_strip_host( $post_info_arr[1] ); if( $post_link && $post_link == $page_path ){ $remove_plugins[] = $plugin; } } } } if($uri_type == 'page_post'){ $page_list = isset($individual_options['pages']) ? $individual_options['pages'] : array(); $post_list = isset($individual_options['posts']) ? $individual_options['posts'] : array(); $page_nd_post_list = array_merge($page_list, $post_list ); $current_page = ( $page_path !== '/' ) ? get_page_by_path( trim($page_path, '/'), 'OBJECT', 'page' ) : null; $current_post = get_page_by_path( basename($page_path), 'OBJECT', 'post' ); if(in_array('all_pages,all_pages', $page_nd_post_list) && ( $is_front_page || (!empty($current_page) && $current_page->post_status === 'publish') )){ $remove_plugins[] = $plugin; } elseif(in_array('all_posts,all_posts', $page_nd_post_list) && !empty($current_post) && $current_post->post_status === 'publish'){ $remove_plugins[] = $plugin; } else { foreach($page_nd_post_list as $post_info){ $post_info_arr = explode(',', $post_info); $post_id = $post_info_arr[0]; $post_link = htpm_strip_host( $post_info_arr[1] ); if( $post_link && $post_link == $page_path ){ $remove_plugins[] = $plugin; } } } } if( $uri_type == 'custom' ){ $condition_list = array( 'name' => array(), 'value' => array() ); $condition_list = $individual_options['condition_list'] ? $individual_options['condition_list'] : array( 'name' => array(), 'value' => array() ); $individual_condition_list = array(); for( $i = 0; $i < count($condition_list['name']); $i++ ){ $individual_condition_list[] = $condition_list['name'][$i] . ',' . $condition_list['value'][$i]; } foreach($individual_condition_list as $item){ $item = explode(',', $item); $name = $item[0]; $value = trim($item[1], '/'); if($name == 'uri_equals'){ if($current_page_slug == $value){ $remove_plugins[] = $plugin; } } if($name == 'uri_not_equals'){ if($value && $current_page_slug != $value){ $remove_plugins[] = $plugin; } } if($name == 'uri_contains'){ if($value && strpos( $current_page_url, $value )){ $remove_plugins[] = $plugin; } } if($name == 'uri_not_contains'){ if($value && !strpos( $current_page_url, $value )){ $remove_plugins[] = $plugin; } } } } } } return $remove_plugins; } /** * Strips protocol + domain from a stored "id,url" link, leaving just the * relative path. A page/post picked in the Select Pages/Posts dropdown is * stored with the domain it was configured on baked in — on a single site * that's always this site's own domain, but a rule configured once at * Network Admin level and inherited by every subsite would otherwise never * match, since each subsite has its own domain. Comparing paths only keeps * single-site matching identical (a site's own domain always matches itself) * while making the rule portable across a network's subsites. * * @param string $link * @return string */ function htpm_strip_host( $link ) { $link = str_replace( array( 'http://', 'https://' ), '', $link ); $link = trim( $link, '/' ); $slash_pos = strpos( $link, '/' ); $path = ( false === $slash_pos ) ? '' : trim( substr( $link, $slash_pos + 1 ), '/' ); // A WordPress install in a subdirectory (example.com/blog) carries that // directory in the stored link, but the current path this is compared // against is already measured relative to the site root — so drop the // same prefix here to keep both sides comparable. $base_path = trim( (string) wp_parse_url( get_bloginfo('url'), PHP_URL_PATH ), '/' ); if ( '' !== $base_path ) { if ( 0 === strpos( $path, $base_path . '/' ) ) { $path = trim( substr( $path, strlen( $base_path ) + 1 ), '/' ); } elseif ( $path === $base_path ) { $path = ''; } } return ( '' === $path ) ? '/' : $path; } function htpm_filter_plugins( $plugins ){ $remove_plugins = htpm_get_plugins_to_remove(); if ( empty( $remove_plugins ) ) { return $plugins; } return array_diff( $plugins, $remove_plugins ); } /** * Same rules as htpm_filter_plugins(), applied to the network-wide active * plugins list instead (keyed by plugin file => activation timestamp). * * @param array $plugins * @return array */ function htpm_filter_network_active_plugins( $plugins ){ $remove_plugins = htpm_get_plugins_to_remove(); if ( empty( $remove_plugins ) ) { return $plugins; } return array_diff_key( $plugins, array_flip( $remove_plugins ) ); } azeite – CGGP
Filtro de Daltonismo