Forum Replies Created

Viewing 10 replies - 181 through 190 (of 190 total)
  • actually on further thought you can’t do option 1 above just like that, as the cache.php needs to be updated from the new browscap.ini… does not seem that easy to trigger… I have:

    global $browscap;
    $browscap->localFile = WP_PLUGIN_DIR.'/php-browser-detection/cache/php_browscap.ini';
    $browscap->updateCache();
    exit;

    but it crashes at this line (of all places?) in _getRemoteIniFile
    $browscap = explode("\n", $browscap);

    perhaps this is the memory usage issue talked about..? it is a rather big file to split like that. so I’d like to propose some alternatives…

    1. use substr instead of explode… as content variable gets bigger, browscap variable gets smaller the, saving memory…

    // $browscap = explode("\n", $browscap);
    
    $pattern  = self::REGEX_DELIMITER . '(' . self::VALUES_TO_QUOTE . ')="?([^"]*)"?$' . self::REGEX_DELIMITER;
    
    if (strstr($browscap,"\n")) {
    	while (strstr($browscap,"\n")) {
    		$pos = strpos($browscap,"\n");
    		$subject = trim(substr($browscap,0,$pos));
    		$content .= preg_replace($pattern, '$1="$2"', $subject)."\n";
    		$browscap = substr($browscap,($pos+1));
    	}
    	if ($browscap != '') {
    		$subject = trim($browscap);
    		$content .= preg_replace($pattern, '$1="$2"', $subject)."\n";
    	}
    } else {throw new Exception("No lines found.");}

    2. change the _getRemoteData function to write the file contents to a file, and then use fgets on the local file to retrieve it line by line…

    $pattern  = self::REGEX_DELIMITER . '(' . self::VALUES_TO_QUOTE . ')="?([^"]*)"?$' . self::REGEX_DELIMITER;
    $content = '';
    $fh = fopen($url,'r');
    while (!feof($fh)) {
    	$subject = trim(fgets($fh));
    	$content .= preg_replace($pattern, '$1="$2"', $subject) . "\n";
    }
    if (!file_put_contents($path, $content)) {
    	throw new Exception("Could not write .ini content to $path");
    }

    the first example seems rather slow, but it does finish eventually. the second seems much faster but I’m not totally sure if the end result is the same or not (and again only works for local file source at the moment.)

    either way I’m stuck here for now… as the resulting prepared file is still not processed into a working cache.php file for reasons unknown as yet… in any case I hope this input helps resolve the memory issue.

    oh yeah and a filter for $remoteIniUrl as well, so the “full” version could be used instead if that is wanted. heck, why not add filters to all the config variables just for the heck of it, lol.

    @hommealone, here are two alternatives…

    1. you can always update the browscap.ini manually yourself by downloading and replacing it… https://browscap.org/stream?q=PHP_BrowscapINI

    2. or just turn on the auto-update switch in /inc/Browscap.php
    $doautoUpdate = true;
    and adjust the update interval…
    $updateInterval = 432000;

    as the existing update functions are still in place, just turned off.

    as for improving the plugin itself, I think that there could be filters on these values so they can be set from outside the class and persist between plugin updates. eg:
    $doAutoUpdate = apply_filters('browsercap_updates',false);
    $updateInterval = apply_filters('browsercap_update_interval',2592000);

    and make note of these in the readme.txt, rather than adding a UI just for them which is probably not necessary.

    thanks for a great plugin by the way. ??

    assuming your page slug is ‘downloads’…

    if (is_page('downloads')) {
       if(is_ie() && get_browser_version() <= 8) {
          wp_redirect('https://www.example.com/update-your-browser/', 301);
          exit;
       }
    }
    Thread Starter Tony Hayes

    (@majick)

    that will teach me to read the support forum before fixing something myself, lol:
    https://www.ads-software.com/support/topic/display-debug-bar-only-to-admins

    The difference is one can be used for capabilities and the other for roles, ah well I guess this way I got to forking the github version so it can be updated too. ??

    Thread Starter Tony Hayes

    (@majick)

    just noticed there is a some alternative styling to move the admin bar to the bottom here too:
    https://www.ads-software.com/support/topic/blackbox-on-the-bottom-instead-of-top

    perhaps having a “disable” switch for the entire SMTP/API transport could still be a good idea, otherwise you still need to disable the plugin completely to revert back to the default mailer…

    it could be helpful in testing so you can still access the plugin, run the connection test and diagnostics and debug settings etc. on a live site, while knowing (especially if you’re having problems) that your default mail is still going out as it normally would (php_mailer without SMTP) in the meanwhile.

    well, that is something I was doing the other night while testing a different plugin before I found yours (WP Mail SMTP) that has such a switch… it was *kinda* useful, in the sense of being able to send test emails with the SMTP setting *before* those settings are actually applied live.

    so it *could* avoid loss of emails while setting up the plugin… and maybe a similar case would be changing the SMTP settings to a different server and testing those. I guess a similar idea is being able to disable a site cache without deactivating the cache plugin entirely. my 2c.

    (total props on a great plugin by the way!)

    Awesome, just what I was looking for… thank you!

    didn’t work with the create_function though, I just got an error of “class ‘WP_Widget_Text’ not found.” … seems it is trying to extend the class before it exists this way…

    so I just wrapped the class in a function and worked fine.

    function CreateHackadelicDiscreetTextWidget() {
    class HackadelicDiscreetTextWidget extends WP_Widget_Text
    {
    	function HackadelicDiscreetTextWidget() {
    		$widget_ops = array('classname' => 'discreet_text_widget', 'description' => __('Arbitrary text or HTML, only shown if not empty'));
    		$control_ops = array('width' => 400, 'height' => 350);
    		$this->WP_Widget('discrete_text', __('Discreet Text'), $widget_ops, $control_ops);
    	}
    
    	function widget( $args, $instance ) {
    		extract($args, EXTR_SKIP);
    		$text = apply_filters( 'widget_text', $instance['text'] );
    		if (empty($text)) return;
    		$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
    		echo $before_widget;
    		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
    			<div class="textwidget"><?php echo $instance['filter'] ? wpautop($text) : $text; ?></div>
    		<?php
    		echo $after_widget;
    	}
    }
    return register_widget("HackadelicDiscreetTextWidget");
    }
    
    add_action('widgets_init', 'CreateHackadelicDiscreetTextWidget');

    Seems to me that WordPress could do this itself in not displaying all empty widgets anyway, not just text ones… ah well.

    Was just looking to do this myself, here’s my solution…
    Put this is the “Display when no related posts found” field:
    <style>.related_post,.related_post_title{display:none;}</style>
    ??

    I just had this same problem when I tried to install Feedburner Feedsmith on WP 2.7
    I think it is something to do with the plugin (auto?) installation process, wordpress somehow creates a weird directory called wp-content/plugins/__MACOSX/ and then when the page reloads it thinks it is a plugin and can’t open it properly because the file in it is garbled.
    Well, that’s what happened to me…
    Just delete wp-content/plugins/__MACOSX/ and any files in it and the error will go away. Plugin should still activate and work fine, nothing seems wrong with *it’s* files. ??

Viewing 10 replies - 181 through 190 (of 190 total)