Support

Account

Forum Replies Created

  • I have a solution I wrote about here: https://anchor.host/2017/05/16/preloading-advanced-custom-fields-pro-license-key/. The custom code triggers after a wp search-replace cli command runs. Fits in nicely to my workflow seeing as the ACF Pro key needs reapplied any time the wp option get home or wp option get siteurl changes.

  • I’m sure there are more eloquent ways to pull this off however give this a try. This will only work on relationship fields which are pulling in choices from custom post types.

    function my_acf_load_value( $value, $post_id, $field ) {
    
    	// Loads current post
    	$post = get_post( $post_id );
    
    	// Check we are on the new screen
    	if ( $post->post_status == 'auto-draft' ) {
    
    		// Pull in custom post types from fields
    		$post_types = $field['post_type'];
    
    		// Fetches all post IDs choices
    		$post_ids = get_posts(
    			array(
    				'post_type'      => $post_types,
    				'posts_per_page' => '-1',
    				'fields'         => 'ids',
    			)
    		);
    
    		// Assign all choices as the default value
    		$value = $post_ids;
    
    	}
    
    	return $value;
    }
    
    add_filter( 'acf/load_value/type=relationship', 'my_acf_load_value', 10, 3 );
  • Sascha,

    ACF has many hooks to add custom functionality. I put something together which will apply a basic counter on all relationship fields. Looks like this: https://vimeo.com/259429957/f653eae345.

    In order to implement, put the following in your theme functions.php file.

    function my_acf_relationship_counter( $field ) {
    
    	echo '<p class="acf-relationship-counter alignright"></p>';
    
    }
    add_action( 'acf/render_field/type=relationship', 'my_acf_relationship_counter', 1, 1 );
    
    function my_acf_admin_enqueue_scripts() {
    
    	// register style
    	wp_enqueue_style( 'my-acf-input-css', get_stylesheet_directory_uri() . '/css/my-acf-input.css', false, '1.0.0' );
    
    	// register script
    	wp_enqueue_script( 'my-acf-input-js', get_stylesheet_directory_uri() . '/js/my-acf-input.js', false, '1.0.0' );
    
    }
    
    add_action( 'acf/input/admin_enqueue_scripts', 'my_acf_admin_enqueue_scripts' );

    Under your theme/js/my-acf-input.js

    jQuery(document).ready(function() {
    
      // Run on relationship update
      jQuery('.acf-field-relationship').change(function() {
        selected_count = jQuery(this).find(".values li").length;
        jQuery(this).find(".acf-relationship-counter").text(selected_count + " items");
      });
    
      // Run on startup
      jQuery(".acf-field-relationship").each(function() {
        selected_count = jQuery(this).find(".values li").length;
        jQuery(this).find(".acf-relationship-counter").text(selected_count + " items");
      });
    
    });

    Under your theme/css/my-acf-input.css

    .acf-field-relationship .acf-relationship-counter {
      position: absolute;
      right: 0;
      top: -42px;
    }
  • Yes this is still wanted. Recently had another large batch of websites lose their license keys. The custom code I previously used to reapply license keys stopped working. I assume something changed with the way ACF Pro activate license keys. I was able to get working by updating the custom code to match the code within ACF Pro itself.

    // Check if ACF is running
    if ( is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) {
    
      // Loads ACF plugin
      include_once( ABSPATH . 'wp-content/plugins/advanced-custom-fields-pro/acf.php');
    
      // connect
      $post = array(
        'acf_license'	=> "ACF_PRO_KEY",
        'acf_version'	=> acf_get_setting('version'),
        'wp_name'			=> get_bloginfo('name'),
        'wp_url'			=> home_url(),
        'wp_version'	=> get_bloginfo('version'),
        'wp_language'	=> get_bloginfo('language'),
        'wp_timezone'	=> get_option('timezone_string'),
      );
    
      // connect
      $response = acf_updates()->request('v2/plugins/activate?p=pro', $post);
    
      // ensure response is expected JSON array (not string)
      if( is_string($response) ) {
        $response = new WP_Error( 'server_error', esc_html($response) );
      }
    
      // success
      if( $response['status'] == 1 ) {
        acf_pro_update_license( $response['license'] ); // update license
      }
      echo $response['message']; // show message
    
    }

    Also wrote some code to make this automatically update after using a WP-CLI search-replace command. That’s typically where I’m seeing the license keys drop. https://anchor.host/2017/05/16/preloading-advanced-custom-fields-pro-license-key/

  • No it’s a one time run code which I deploy using: https://managewp.com/guide/manage/code-snippets. It has to be manually reapplied anytime the URLs change or the key get’s dropped for any other reason. Check out @jacobdubail comment for an example of how he uses it with an action hook. I got the idea from his code.

  • I agree but until then the following code snippet can be applied to a batch of sites via ManageWP’s code snippet feature. Just add in your key and bulk apply to all sites.

    <?php
    
     $save = array(
     'key' => "ACF_LICENSE_GOES_HERE",
     'url' => home_url()
     );
     $save = maybe_serialize($save);
     $save = base64_encode($save);
    
     update_option('acf_pro_license', $save);
    
     ?>
  • As for code, maybe do what Akismet does. In wp-config.php it looks like define( 'WPCOM_API_KEY', '238r9hsvdu8923' );. Doing a search for WPCOM_API_KEY over Akismet reveals the following related lines of code.

    
    /wp-content/plugins/akismet/class.akismet.php:
       61  
       62  	public static function get_api_key() {
       63: 		return apply_filters( 'akismet_get_api_key', defined('WPCOM_API_KEY') ? constant('WPCOM_API_KEY') : get_option('wordpress_api_key') );
       64  	}
       65  
    
    /wp-content/plugins/akismet/wrapper.php:
        1  <?php
        2  
        3: global $wpcom_api_key, $akismet_api_host, $akismet_api_port;
        4  
        5: $wpcom_api_key    = defined( 'WPCOM_API_KEY' ) ? constant( 'WPCOM_API_KEY' ) : '';
    
    /wp-content/plugins/akismet/views/config.php:
       59  									<table cellspacing="0" class="akismet-settings">
       60  										<tbody>
       61: 											<?php if ( !defined( 'WPCOM_API_KEY' ) ):?>
       62  											<tr>
       63  												<th class="akismet-api-key" width="10%" align="left" scope="row"><?php esc_html_e('API Key', 'akismet');?></th>
       ..
      138  								</div>
      139  								<div id="major-publishing-actions">
      140: 									<?php if ( !defined( 'WPCOM_API_KEY' ) ):?>
      141  									<div id="delete-action">
      142  										<a class="submitdelete deletion" href="<?php echo esc_url( Akismet_Admin::get_page_url( 'delete_key' ) ); ?>"><?php esc_html_e('Disconnect this account', 'akismet'); ?></a>
    
    
  • Been awhile since there was activity on this one, figured I’d followup. I’d also like a way to apply my ACF key from the wp-config.php file. Recently been batch installing Let’s Encrypt SSL on my customer sites. Whenever there is a url change (like http:// to https://), ACF Pro drops the license and makes me reactivate. Having it applied from wp-config.php would solve this.

    Another common scenario I run into is when I go from a development site to production (like newsite.wpengine.com to newsite.com). This also drops the license key and requires manually intervention to reapply.

  • I updated to the latest version and it appears to have fixed the old entries on all of my edit screens! They are now showing the correct time. With this I believe I’m good. Thanks so much.

  • Just tried out 5.3.9.2-RC1 on both of my affected sites and can confirmed everything is now working. Thanks!

  • I discovered this same error on another one of my sites with a different set of plugin conflicts. The really strange thing is that this one is working with The Events Calendar v4.2 and The Events Calendar PRO v4.2 installed and activated however does not work with SearchWP v2.6 active.

    For this site, the error is appearing on an ACF option page. This particular option page only has 2 fields as shown here: https://cloudup.com/c17oDtvAqNT. With the js error: https://cloudup.com/cuXmYGVQjBa the date select field does not display any selectable dates. For now I’ve downgraded from ACF v5.3.9.1 to v5.3.8.1 as a workaround.

  • I haven’t begun working on the frontend as the backend displays are wrong. Here is what I’m seeing.

    Old site running with these settings: https://cloudup.com/cojHB_KpIIk are displaying a 10:00 start time as shown here: https://cloudup.com/c6vO0wJ3GSu

    New site running with these settings: https://cloudup.com/cKh3nZzN7U1 are displaying a 21:05 start time as shown here: https://cloudup.com/cJuQ9A2AG9P on the same entry.

    In the database the start time field is set to 1465898400.

  • I have the same issue on a mutisite network where I’m using get_field in my header.php and a new user is hitting wp-activate.php.

    PHP Fatal error: Call to undefined function get_field() in /wp-content/themes/themename/header.php on line 24

  • This issue appears to have gone away with ACF Pro 5.2.4.

  • @elliot I tried out your revised code and yes it works on my install. Thanks for figuring this out.

  • I tested it out on one of my affected installs. Simply putting the restore_current_blog() inside the loop did not work. However through some trial and error I was able to get it working by keeping your original code and adding it inside the loop like so.

    
    		// loop through sites and find updates
    		$sites = wp_get_sites();
    		
    		if( $sites ) {
    			
    			foreach( $sites as $site ) {
    				
    				// switch blog
    				switch_to_blog( $site['blog_id'] );
    				
    				
    				// get site updates
    				$updates = acf_get_updates();
    				
    				if( $updates ) {
    				
    					$prompt = true;
    					break;
    					
    				}
    				
    				// restore
    				restore_current_blog();
    				
    			}
    
    		// restore
    		restore_current_blog();
    			
    		}
    
  • Same issue here. Ok so some more details on my situation here: https://wordpress.org/support/topic/wordpress-42-network-admin-multisite-redirect-loop?replies=4#post-6866952. I only noticed when I updated to WordPress 4.2 with ACF 5.2.3. Downgrading to ACF 5.2.2 fixed my redirect loop.

  • I have confirmed that this fix does work on my website. When upgrading directly to this from an old version (5.1.9.1), I didn’t have to do anything however when upgrading from 5.2.0 I did have to manually reassign to the Tax Term like so: https://cloudup.com/cJTeIzG5uqJ.

  • Ok I’m having similar issues with the screen options. Here is a video I took which shows the issues in more detail. Every time I select a custom taxonomy, it hides and shows my main category. Again this issue only started when I updated to ACF 5.2.0: https://cloudup.com/cPbcAb1yBfx. Any thoughts or suggestions?

Viewing 19 posts - 1 through 19 (of 19 total)