• Resolved hwuser

    (@hwuser)


    Hello,

    Is there any function to can use in functions.php to create a new level?

    Many thanks and congratulations for your plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter hwuser

    (@hwuser)

    Hello,
    I have some ideas about this response:
    https://www.ads-software.com/support/topic/restrict-user-access-manage-those-levels-as-metadata/

    I make this to create a new level:

    $your_title = “New Level”;
    $your_content = “”;
    $post_id = wp_insert_post(array (
    ‘post_type’ => ‘restriction’,
    ‘post_title’ => $your_title,
    ‘post_content’ => $your_content,
    ‘post_status’ => ‘publish’,
    ‘comment_status’ => ‘closed’, // if you prefer
    ‘ping_status’ => ‘closed’, // if you prefer
    ));

    To add a role member to this group I make this:

    add_post_meta( $post_id, ‘_ca_role’, ‘role_X’ );

    It’s well?

    Now I want to make a conditional logic restriction in one category or taxonomy. How can I do this?

    And if is posible, to extend this new level to another level that I choice.

    Thanks!

    Plugin Author Joachim Jensen

    (@intoxstudio)

    Apologies for the delayed response here.

    You are correct about how to add the level itself.

    When you have created the level, you can use rua_add_user_level($user_id:int,$level_id:int) to add users to it ??

    Unfortunately there is no quick way to add conditions programatically, but it is on my to-do list to expand the API to include that.

    Conditions are saved in the condition_group post type, which you can add the same way as you add an access level. Conditions themselves are saved as metadata or taxonomies on that post type.
    That means you can use this method to add a category condition: https://codex.www.ads-software.com/Function_Reference/wp_set_object_terms

    Thread Starter hwuser

    (@hwuser)

    Thanks for your answer. At the moment I do not need to add users to a level because I synchronize them with a role.

    What I do not understand is the conditions. I see in the database in the table “posts” the record that corresponds to the post type “condition_group”. I see that it is associated with the post id of the level that corresponds to it, but can’t see how the conditions are saved.

    In the “postmeta” table I see records like the meta_key _edit_lock are created and as meta_value a numbering of style 1539690142: 1 and other records like _ca_duration, _vc_post_settings etc.

    I understand that first I have to add the condition group record like this:

    $post_id = wp_insert_post(array (
    ‘post_type’ => ‘condition_group’,
    ‘post_title’ => $your_title,
    ‘post_content’ => $your_content,
    ‘post_status’ => ‘publish’,
    ‘post_parent’ => $id_post,
    ‘comment_status’ => ‘closed’, // if you prefer
    ‘ping_status’ => ‘closed’, // if you prefer
    ));
    add_post_meta( $post_id, ‘???????????’, ??????????);

    And second, I have to add the conditions with this function:
    <?php wp_set_object_terms( $object_id, $terms, $taxonomy, $append ); ?>

    If you have some time, could you clarify it or give me an example to restrict the post to a category?
    Thank you.

    Plugin Author Joachim Jensen

    (@intoxstudio)

    Any data in postmeta with prefix _ca_ you can be pretty sure comes from this plugin (or Content Aware Sidebars, which uses the same type of conditions)

    To restrict access to a specific post/page, you should do this:
    add_post_meta( $condition_group_id, 'ca_post_type', <post_id>);

    To restrict access to a specific category/taxonomy, you should use the method you mention:
    wp_set_object_terms( $condition_group_id, <term array>, <taxonomy name>, true )

    I do recommend looking at the files in restrict-user-access\lib\wp-content-aware-engine\module where you can get more information about each condition type (module)

    Thread Starter hwuser

    (@hwuser)

    Perfect!!! Many thanks!!!
    A correction for other users, I think in add_post_meta: ca_post_type is _ca_post_type.
    add_post_meta( $condition_group_id, ‘ca_post_type’, <post_id>);
    Is add_post_meta( $condition_group_id, ‘_ca_post_type’, <post_id>);

    Thanks for your support!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Function to create level’ is closed to new replies.