Forum Replies Created

Viewing 15 replies - 1 through 15 (of 15 total)
  • john-lang-86

    (@johnlang-1)

    A quick and unsupported way to achieve this can be done with tweaks to the v1.5.0 code base of the plugin.

    Disclaimer: The below code tweaks are a hint for exploration and understanding where the solution would be applied to the plugin; because the next time the plugin is updated, all the custom code tweaks would be wiped out.

    Who is this for? The below solution is for developers who know what they are doing, understand all the risks and are willing to experiment on staging sites (not live sites).

    Outcome – Ability to use the WordPress media library with an image served from an S3 Bucket via an SEO friendly custom subdomain; not from the WordPress /wp-content/uploads/ folder.

    Use [Show in Media Library] button
    Notice the ‘File URL’ (aka GUID) is usinf the SSU_BUCKET_DOMAIN as the host
    Media Library image available to be used as a Featured Image in Posts/Pages
    Notice the same Featured Image media library file is available to use in a content block

    Proof of solution is the generated content at https://www.learnbw.com/loading/0recordmode-in-transformations/

    Notice the end user experience (client side web browser) using the SEO friendly custom subdomain

    Benefit – The images are served from the S3 network, significantly reducing the number of calls to the WordPress server itself.

    Prerequisites: For the below tweak to work, all the AWS S3 and DNS configuration needs to be ready … you need to already be publicly serving your bucket content to anyone on the internet via an SEO friendly subdomain.

    • [Done] AWS S3 bucket created.
    • [Done] AWS Cloudfront distribution created.
      • With the free SSL certificate enabling HTPPS traffic.
      • And pointing to the S3 bucket to be the origin server.
    • [Done] Your domains DNS configured with a CNAME record pointing to the AWS Cloudfront distribution.
      • Note that this CNAME is the DNS subdomain part of the fully qualified domain name. It is the RDN of rdn.dataprofessionals.com.au in the example below.
      • Note that rdn.dataprofessionals.com.au has additional configuration to make it a Referrer Delivery Network (RDN) subdomain. While it is publicly available, it expects the caller to use the ‘referrer’ HTTP Header to identify themselves; acknowledging that this type of hot-link protection is not a replacement for true security.

    Step 1 – Define a new constant in wp-config.php. Replacing domain-name with the externally publicly available sub-domain (SEO friendly) that you have already configured.

    define('SSU_BUCKET_DOMAIN', 'domain-name');

    This sample wp-config.php is pointing to an AWS S3 bucket which is called the same name as the publicly available sub-domain.

    /** Plugin - S3 Smart Uploader. */
    define('SSU_PROVIDER', 'aws');
    define('SSU_KEY', 'XXX');
    define('SSU_SECRET', 'XXX');
    define('SSU_BUCKET', 'rdn.dataprofessionals.com.au');
    define('SSU_BUCKET_DOMAIN', 'rdn.dataprofessionals.com.au'); // optional
    define('SSU_FOLDER', 'XXX');                                 // optional
    define('SSU_REGION', 'XXX');
    define('SSU_SURL_EXPIRY', 60);                               // in seconds

    Step 2 – The /wp-content/plugins/wp-s3-smart-upload/includes/class-s3-smart-upload-s3-service.php file has two methods to be tweaked.

    		/**
    		 * Create media attachment from s3 link
    		 *
    		 * @param mixed  $file      File object.
    		 * @param string $signed_url S3 Link.
    		 *
    		 * @return array $metadata Attachment ID
    		 */
    		public function create_media_attachment_from_s3_url( $file, $signed_url ) {
    			$file_name          = sanitize_text_field( $file['name'] );
    			// Get public URL from signed URL to fix the special character case.
    			$public_url = $this->get_public_url_from_signed_url( $signed_url );
    			$wp_filetype        = wp_check_filetype( $file_name );
    
    
    
                // v1.5.1 Use custom domain for S3 bucket.
                $metadata_should_get = false;
                $s3_bucket_url = $public_url;
                if (defined('SSU_BUCKET_DOMAIN')) {
                    $metadata_should_get = true;
                    $public_url_host = parse_url($public_url, PHP_URL_HOST);
                    $public_url = str_replace($public_url_host, SSU_BUCKET_DOMAIN, $public_url);
                }
    
    
    
                $attachment         = array(
    				'post_mime_type' => $wp_filetype['type'],
    				'guid'           => urldecode( $public_url ),
    				'post_title'     => preg_replace( '/\.[^.]+$/', '', $file_name ),
    				'post_content'   => '',
    				'post_status'    => 'inherit',
    			);
    
    			$attachment_id = wp_insert_attachment( $attachment, $file_name );
    			add_post_meta( $attachment_id, 's3_public_url', $public_url );
    
    
    
                // v1.5.1 Use custom domain for S3 bucket.
                // $metadata = $this->generate_attachment_metadata_for_s3_link( $attachment_id, $file, $public_url );
    			$metadata = $this->generate_attachment_metadata_for_s3_link( $attachment_id, $file, $s3_bucket_url, $metadata_should_get );
    
    
    
    			wp_update_attachment_metadata( $attachment_id, $metadata );
    
    			return $metadata;
    		}
    		/**
    		 * Create media attachment from s3 link
    		 *
    		 * @param mixed  $file_name File name.
    		 * @param string $url       S3 Link.
    		 *
    		 * @return array $metadata Attachment metadata
    		 * @throws Exception
    		 * @since 1.2.0
    		 */
    		public function create_media_attachment( $file_name, $url ) {
    			$file_name = sanitize_text_field( $file_name );
    			$url       = sanitize_url( $url );
    			$mime_type = ssu_get_mime_type( $file_name );
    
    
    
                // v1.5.1 Use custom domain for S3 bucket.
                $s3_bucket_url = $url;
                if (defined('SSU_BUCKET_DOMAIN')) {
                    $url_host = parse_url($url, PHP_URL_HOST);
                    $url = str_replace($url_host, SSU_BUCKET_DOMAIN, $url);
                }
    
    
    
    			$attachment = array(
    				'post_mime_type' => $mime_type,
    				'guid'           => $url,
    				'post_title'     => wp_basename( $file_name ),
    				'post_content'   => '',
    				'post_status'    => 'inherit',
    			);
    
    			$attachment_id = wp_insert_attachment( $attachment, $file_name );
    			if ( is_wp_error( $attachment_id ) ) {
    				throw new Exception( 'Can not insert attachment' );
    			}
    			add_post_meta( $attachment_id, 's3_public_url', $url );
    
    
    
                // v1.5.1 Use custom domain for S3 bucket; use original S3 bucket for attachment metadata (width/height)
    			$metadata = $this->generate_attachment_metadata_for_s3_link(
    				$attachment_id,
    				array(
    					'name'   => $file_name,
    					'size'   => 0,
    					'width'  => 0,
    					'height' => 0,
    				),
    			// 	$url,   v1.5.0
                    $s3_bucket_url,
    				true
    			);
    
    
    
    			wp_update_attachment_metadata( $attachment_id, $metadata );
                
    			return $metadata;
    		}

    Hope this helps … happy exploring.

    • This reply was modified 2 years ago by john-lang-86. Reason: Add captions to the images

    Hi Bennett, Awesome. Confirmed that v2.13.5 has fixed the issue running on PHP 8.0/8.1.

    Hi Bennett, Welcome to a new year and thank you for taking the time to configure the pre-requisite conditions to reproduce the error (PHP v8 runtime environment).

    1. Navigate to the ‘Search Meter’ settings page at /wp-admin/options-general.php?page=search-meter%2Fadmin.php
    2. Click the [Save Changes] button.
      Note that you don’t have to make any changes.
    3. This should now show a “There has been a critical error on this website. Please check your site admin email inbox for instructions” message and send an email to the site administrator (if wordpress is configured to send out through an email provider).

    The critical error occurs because the ‘Search Meter’ plugin uses a PHP function that was depreciated/removed from the PHP runtime environment. get_magic_quotes_gpc() no longer exists to be called or used and needs to be removed. The intention of what the plugin code was doing is just fine, it’s the function called to fulfil that intention that needs to be changed.

    This Stack Overflow discussion has lots of useful background information supporting the proposed solution.
    https://stackoverflow.com/questions/61054418/php-7-4-deprecated-get-magic-quotes-gpc-function-alternative

    Hi Bennett, The critical error when saving the settings is related to a depreciated php function; for those who have upgraded the server to PHP v8+.
    Uncaught Error: Call to undefined function get_magic_quotes_gpc()

    An error of type E_ERROR was caused in line 519 of the file /home/_____._____.com/_____/public_html/wp-content/plugins/search-meter/admin.php.

    Error Details
    =============
    An error of type E_ERROR was caused in line 519 of the file /home/_____._____.com/_____/public_html/wp-content/plugins/search-meter/admin.php.
    Error message: Uncaught Error: Call to undefined function get_magic_quotes_gpc() in /home/_____._____.com/_____/public_html/wp-content/plugins/search-meter/admin.php:519
    Stack trace:
    #0 /home/_____._____.com/_____/public_html/wp-includes/class-wp-hook.php(307): tguy_sm_options_page()
    #1 /home/_____._____.com/_____/public_html/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters()
    #2 /home/_____._____.com/_____/public_html/wp-includes/plugin.php(476): WP_Hook->do_action()
    #3 /home/_____._____.com/_____/public_html/wp-admin/admin.php(259): do_action()
    #4 /home/_____._____.com/_____/public_html/wp-admin/options-general.php(10): require_once('/home/_____.__...')
    #5 {main}
      thrown

    Hope this helps.

    Hi Giulio, After disabling the plugin, like you did, you might also need to clear any server side caching capability (like Varnish) and you might also need to clear your browser cache. It has been occasionally noticed that these additional steps were required to be able to actually load the wp-login page. The issue was not the plugin in WordPress, but more about the various caching mechanism not being invalidated (server level and browser level) which then display a stale page from the cache and not from the live server.

    Here are a few links to instructions to clear a few of the available types of cache; obviously it will all depend upon which hosting and caching services you are using for your domain. For Example:

    If it is still not ok, then can you please consider posting the domain name (???) and perhaps links to screen shots to provide further details for analysis.

    • This reply was modified 2 years, 7 months ago by john-lang-86.

    Hi happyches and caseyfriday,

    Try:
    wget -q -O - "https://www.domain.com/wp-cron.php?doing_wp_cron&2443c3564fe7d464a62b923211244116" > /dev/null 2>&1

    [Obviously replace the domain name and the secret key]

    Notes:
    (1) The “-O -” parameters instruct wget to write the output to stdout. This will help stop the many files from being created.
    (2) The “> /dev/null 2>&1” parameters are *nix command line parameters that basically capture all output and ignore it. Nothing gets captured or kept anywhere.

    I was getting heaps of files created on the file system (GoDaddy Hosting @ the time). After adding these two parameter options the file creation stopped with the outcome of the cron job still being run successfully.

    Kind regards,
    John.

    Hi Cataliades,

    This message is from the WordPress virtual cron program itself (wp-cron.php). It is an attempt to stop too many instances of the cron events being fired/triggered at the same time.

    You need to ensure your real cron job that you scheduled in cPanel is set to run every 2 minutes or more, never every minute.

    Once you have the real cron job running in cPanel, make sure you disable the WordPress virtual cron job from triggering when web pages are served to web browsers of your site. This is done by adding a line to the wp-config.php file.
    define( 'DISABLE_WP_CRON', true );

    Further Reading: https://wp.tutsplus.com/articles/insights-into-wp-cron-an-introduction-to-scheduling-tasks-in-wordpress/

    Kind regards,
    John.

    Hi dogwasher,

    You only have to add the cron job to the cpanel of your hosting.

    The addition of disable_wp_cron to the wp-config.php file is an optional extra that you could do. I recommend you do this as well.

    Further Reading: https://wp.tutsplus.com/articles/insights-into-wp-cron-an-introduction-to-scheduling-tasks-in-wordpress/

    Kind regards,
    John.

    Hi klihelp,

    The analytics.js example at google.com shows only two parameters being used.

    ga('create', 'UA-XXXX-Y');

    When the full block of js code is copied out of the official Google Analytics administration panel, it does have a third parameter.

    ga('create', 'UA-XXXX-Y', 'DOMAIN.TLD');

    This would explain the plugin upgrade instructions to no longer use just the UA code but to have everyone update their ‘WordPress’ -> ‘Settings’ -> ‘Google Universal Analytics’ option to be the full js code; no longer just the UA code itself.

    The main benefit of the earlier versions of this plugin was to allow us to only enter the UA code in the options and the plugin took care of the rest.

    Upgrading “Google Universal Analytics” plugin from v1-1 to v1-2 is NOT backwards compatible and effectively brakes the web site.

    So here is some code to make it backward compatible.

    The following code has been packaged into a WordPress plugin installable ZIP:

    function google_universal_analytics() {
      $web_property_id = get_option( 'web_property_id' );
    
      // Is the option just the UA id?
      $web_property_id_p1 = strtoupper( trim( $web_property_id ) );
      $web_property_id_p2 = '';
      if ( strpos( $web_property_id_p1, 'UA-' ) === 0 ) {
    
        // Does the option have a second parameter? (Comma separator)
        $web_property_id_p2_pos = strpos( $web_property_id, ',');
        if ( $web_property_id_p2_pos !== false ) {
    
          // Isolate the first parameter.
          $web_property_id_p1_pos = strpos( $web_property_id_p1, ',');
          if ( $web_property_id_p1_pos !== false ) {
            $web_property_id_p1 = substr( $web_property_id, 0, $web_property_id_p1_pos );
            if ( $web_property_id_p1 !== false ) {
              $web_property_id_p1 = strtoupper( trim( $web_property_id_p1 ) );
            } else {
              $web_property_id_p1 = '';
            }
          }
    
          // Isolate the second parameter.
          $web_property_id_p2_pos += 1;
          $web_property_id_p2 = substr( $web_property_id, $web_property_id_p2_pos );
          if ( $web_property_id_p2 !== false ) {
            $web_property_id_p2 = strtolower( trim( $web_property_id_p2 ) );
          } else {
            $web_property_id_p2 = '';
          }
        }
    
        // Build up a whitespace trimmed javascript that is the GA tracking script.
        // Include the option. One or two values.
        $web_property_id_js = '<script>';
        $web_property_id_js .= '(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){';
        $web_property_id_js .= '(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),';
        $web_property_id_js .= 'm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)';
        $web_property_id_js .= '})(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\');';
        $web_property_id_js .= 'ga(\'create\',\'' . $web_property_id_p1 . '\'';
        if ( strlen( $web_property_id_p2 ) > 1 ) {
          $web_property_id_js .= ',\'' . $web_property_id_p2 . '\'';
        }
        $web_property_id_js .= ');ga(\'send\',\'pageview\');';
        $web_property_id_js .= '</script>';
    
        $web_property_id = $web_property_id_js;
      }
      if ( strpos( $web_property_id, 'UA-' ) !== false ) {
        echo $web_property_id;
      }
    }

    Download: wordpress_plugin_google-universal-analytics_v1-2-0-2.zip

    Note: This ZIP is not officially endorsed by anyone. Use at your own discretion after a code review.

    Kind regards,
    John.

    Hi estepix,

    Thanks for the above code recommendation. It works exactly as you described and is working just fine in WordPress v3-6.

    The analytics.js reference provided is correct and only shows two of the available parameters being used.

    ga('create', 'UA-XXXX-Y');

    When the full block of js code is copied out of the official Google Analytics administration panel, it does have a third parameter.

    ga('create', 'UA-XXXX-Y', 'DOMAIN.TLD');

    This would explain the plugin upgrade instructions to no longer use just the UA code but to have everyone update their ‘WordPress’ -> ‘Settings’ -> ‘Google Universal Analytics’ option to be the full js code; no longer just the UA code itself.

    I agree this is sad because the whole point of the earlier versions of this plugin was to allow us to only enter the UA code in the options and the plugin took care of the rest.

    Upgrading “Google Universal Analytics” plugin from v1-1 to v1-2 is NOT backwards compatible and effectively brakes the web site.

    So here is some code to make it backward compatible.

    The following code has been packaged into a WordPress plugin installable ZIP:

    function google_universal_analytics() {
      $web_property_id = get_option( 'web_property_id' );
    
      // Is the option just the UA id?
      $web_property_id_p1 = strtoupper( trim( $web_property_id ) );
      $web_property_id_p2 = '';
      if ( strpos( $web_property_id_p1, 'UA-' ) === 0 ) {
    
        // Does the option have a second parameter? (Comma separator)
        $web_property_id_p2_pos = strpos( $web_property_id, ',');
        if ( $web_property_id_p2_pos !== false ) {
    
          // Isolate the first parameter.
          $web_property_id_p1_pos = strpos( $web_property_id_p1, ',');
          if ( $web_property_id_p1_pos !== false ) {
            $web_property_id_p1 = substr( $web_property_id, 0, $web_property_id_p1_pos );
            if ( $web_property_id_p1 !== false ) {
              $web_property_id_p1 = strtoupper( trim( $web_property_id_p1 ) );
            } else {
              $web_property_id_p1 = '';
            }
          }
    
          // Isolate the second parameter.
          $web_property_id_p2_pos += 1;
          $web_property_id_p2 = substr( $web_property_id, $web_property_id_p2_pos );
          if ( $web_property_id_p2 !== false ) {
            $web_property_id_p2 = strtolower( trim( $web_property_id_p2 ) );
          } else {
            $web_property_id_p2 = '';
          }
        }
    
        // Build up a whitespace trimmed javascript that is the GA tracking script.
        // Include the option. One or two values.
        $web_property_id_js = '<script>';
        $web_property_id_js .= '(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){';
        $web_property_id_js .= '(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),';
        $web_property_id_js .= 'm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)';
        $web_property_id_js .= '})(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\');';
        $web_property_id_js .= 'ga(\'create\',\'' . $web_property_id_p1 . '\'';
        if ( strlen( $web_property_id_p2 ) > 1 ) {
          $web_property_id_js .= ',\'' . $web_property_id_p2 . '\'';
        }
        $web_property_id_js .= ');ga(\'send\',\'pageview\');';
        $web_property_id_js .= '</script>';
    
        $web_property_id = $web_property_id_js;
      }
      if ( strpos( $web_property_id, 'UA-' ) !== false ) {
        echo $web_property_id;
      }
    }

    Download: wordpress_plugin_google-universal-analytics_v1-2-0-2.zip

    Note: This ZIP is not officially endorsed by anyone. Use at your own discretion after a code review.

    Kind regards,
    John.

    Hi,

    GoDaddy shared hosting works, use 1 of the 2 commands below.

    Command 1: Will send you an email with the output of the crawl that ran and the results will appear in the WordPress dashboard page for the Warm Cache plugin.

    /usr/bin/wget -O - -q -t 1 https://www.[Domain].com/?warm_cache=[Magic]

    Command 2: Will run but then trash the output. You won’t know what happened via email but the results will appear in the WordPress dashboard page for the Warm Cache plugin.

    /usr/bin/wget -O - -q -t 1 https://www.[Domain].com/?warm_cache=[Magic] >/dev/null 2>&1

    Note: Obviously you change the {Domain} and {Magic} values to match the url identified to be used in the WordPress dashboard page for the Warm Cache plugin.

    Want to know more then read the wget manual.

    Hope this helps,
    John.

    Hi Juli,

    I had a similar issue … the solution had two steps.

    (1) Set the cookie timeout to 0 days, like you have done.

    (2) Clear the web browser cache, completely. In chrome I had to give it a complete lobotomy before it started to appear again. Navigate ‘Tools’ -> ‘Clear Browsing Data’ then select ‘the beginning of time’ and tick EVERYTHING. This also logged me out of everything else I was doing at the time … oh, well.

    Close the web browser and re-start the application … then the scroll-triggered-box started to work again.

    Kind regards,
    John.

    Vote +1 for this feature. Yes, please.

    Hi Zhuo,

    Revision Cleaner v2-1-3 is working as expected in WordPress v3-4-1.

    Kind regards,
    John.

    Hi Jim,

    Edit the “wp-config.php” file to add this option:

    define('WP_DEBUG', true);

    More information can be found at: Debugging in WordPress

    Then run through the same steps to re-create the problem.

    This will at least allow you to identify the offending file that is generating the error.
    Then you have proof to take to the appropriate support team, instead of being told it is someone else’s problem.

    Kind regards,
    John.

Viewing 15 replies - 1 through 15 (of 15 total)