Support

Account

Forum Replies Created

  • acf_register_block_type says “(String) The path to a template file used to render the block HTML. This can either be a relative path to a file within the active theme or a full path to any file.” – so you were probably referencing a file in theme, not in your plugin by accident 🙂

    However if you use the block.json for the registering config as was recommended later, there’s this: renderTemplate (string) The path to a template file used to render the block HTML. This can either be a relative path to a file based on where your block.json file is located, or an absolute path.

    So either way, an absolute path in PHP should always work, because you leave no room for magic, however I recommend using the block.json in a similar way as WP does to be consistent – however **keep in mind** renderTemplate does NOT contain the ‘file:’ prefix! (like WP render’s does) so instead of

    `
    “renderTemplate”: “file:./render.php” // as you would do in WP render: …
    `

    you have to do

    `
    “renderTemplate”: “render.php”
    `

    and this file would be placed in the SAME directory as the block.json, so if block.json is in .../wp-content/themes/yourtheme/blocks/your-block/block.json, then the rendering file will be in .../wp-content/themes/yourtheme/blocks/your-block/render.php

    In .../wp-content/themes/yourtheme/functions.php you would register such block just with this:

    `
    add_action(‘init’, function () {
    register_block_type( __DIR__ . ‘/blocks/your-block’ );
    // or if you want to be more specific, then
    // register_block_type( __DIR__ . ‘/blocks/your-block/block.json’ );
    });
    `

    PHP note: __DIR__ is a special constant referencing AN ABSOLUTE PATH to the folder of the current code’s file (of the __FILE__). So for /system/wp-content/themes/yourtheme/functions.php it’s /system/wp-content/themes/yourtheme – this has been available since 5.3…

    If you don’t know how to setup block.json – see Create Your First ACF Block – Registering Blocks with block.json

  • @storm Well, in wp-admin/includes/plugin.php the get_plugin_page_hook()‘s doc.comments specifically state it’s a slug, get_plugin_page_hookname() also mentions those are slugs, and the code you’ve posted yourself is just storing the title – but – it is storing it under a slug – so the key of the hook is from the slug.

  • That is not a solution, but a workaround not usable in many cases.

  • So basically it’s a WordPress hook (not ACF hook), reference:

    
    Top level pages	admin.php?page={page_slug}	toplevel_page_{page_slug}
    Sub pages	admin.php?page={page_slug}	{parent_slug}_page_{page_slug}

    https://codex.wordpress.org/Plugin_API/Admin_Screen_Reference

    Thank you @hube2 for this ! 🙂


    @roby94
    reference says it is using slugs, and your final code does not corresponde with your initial code, so I just don’t believe it started using titles, that would be horrible approach.

  • Same happened to me,
    the site activation is for has to be the site of instalation (at least for first activation).
    My solution was: uninstall & remove plugin, reinstall and activate again – suddenly, updates were available.

  • @John Huebner actually @beee has a bad idea, it’s a better one, definitely do-able, but some thing are design-wrong there – you would need to fetch all the data, even if you are trying to add just a single email address.

    It is a quick solution, if you have a low rate emails/product (and you know it will ever be so – which you probably don’t and can’t know).

    acf/save_post is a good start, but I think you should store it to product/post meta table – one row per 1 email – they can have same key…

  • You are right and also not right.

    This is correct:
    “There is no save button.”

    This is not true:
    There has to be some field to be saved. Otherwise you cant save…

    Solution:
    Your widget class must implement not only __construct (and widget(...) for display), but also the minimum version of method form($instance) that returns the provided $instance:

    public function form($instance){ return $instance; }

  • Thanks Edir, you’ve inspired me to write a more general version.
    This version is based on “post_id” provided by ACF, which is actually an ACF-post_id (not a real wp_posts table ID)
    and also based on get_field() documentation, which is pretty steady in ACF-post_id formats.
    (Dis)advantage: uses global variable for taxonomy caching.

    //returns BOOLEAN false or a term id (int)
    $GLOBALS['taxonomies_for_acf_term_meta_filter'] = [];
    function my_acf_get_term_id_from_acf_post_id( $acf_post_id ){
      if( is_numeric($acf_post_id) ) return false; //not a special ID...
    
      if( empty($GLOBALS['taxonomies_for_acf_filter']) )
        $GLOBALS['taxonomies_for_acf_filter'] = get_taxonomies();
      
      $taxonomies = &$GLOBALS['taxonomies_for_acf_filter']; //shorthand
      $term_id = 0;
      foreach( $taxonomies as $taxonomy ){
        //special id is in format somestring_ID
        $term_id = str_replace( $taxonomy.'_', '', $acf_post_id );
    
        //If not numeric at all, or something is removed while cast type to int (must use "!=" !!!!!)
        //=> not a proper ID... => nothing to do here...
        if(  ! is_numeric($term_id) || ( ((int)$term_id) != $term_id )  ) continue;
          
        $term_id = (int)$term_id;
        break;     
      }
      
      if( $term_id < 1 ) return false; //not a proper ID...
      
      return $term_id;
    }
    function my_acf_update_term_meta($value, $post_id, $field) {
      //FILTER! ===> MUST ALWAYS RETURN $value !
    
      $term_id = my_acf_get_term_id_from_acf_post_id( $post_id );
      if( $term_id === false ) return $value; //not a proper ID... MUST USE "===" !!!!!
      
      update_term_meta($term_id, $field['name'], $value);
    	
      return $value;
    }
    add_filter('acf/update_value', 'my_acf_update_term_meta', 10, 3);
    add_filter('acf/update_value', 'my_acf_update_term_meta', 10, 3);
    
    function my_acf_load_term_meta($value, $post_id, $field) {
      //FILTER! ===> MUST ALWAYS RETURN $value !
    
      $term_id = my_acf_get_term_id_from_acf_post_id( $post_id );
      if( $term_id === false ) return $value; //not a proper ID... MUST USE "===" !!!!!
    	
      $value = get_term_meta($term_id, $field['name'], true);
    	
      return $value;
    }
    add_filter('acf/load_value', 'my_acf_load_term_meta', 10, 3);
    add_filter('acf/load_value', 'my_acf_load_term_meta', 10, 3);
Viewing 10 posts - 1 through 10 (of 10 total)