Modifying the listing-created-date.php

I have 2 questions:

  1. I wanted to modify the html code in listing-created-date.php but didn’t want to make changes to the file directly. What are my options, I did not see a hook for this.

  2. I want to modify class-membership.php but could not find a hook for this in the HivePress Code Reference. Did I miss something, is there documentation for hooks specifically for the hivepress extension plugins?

Thank you.

1 Like

Hi,

If you mean to change the template parts, then please check this doc: How to override template parts - HivePress Help Center

1 Like

Hi Andrii,

I don’t believe the child theme will work since they’re located in the plugins directory. Please let me know if I’m wrong:

wp-content/plugins/hivepress/templates/listing/edit/block/listing-created-date.php
wp-content/plugins/hivepress-memberships/includes/controllers/class-membership.php

Sorry for the delay. Yes, it’s possible to override files located in the “templates” sub-directory of HivePress and it’s extensions, e.g. for the listing-created-date.php:

child-theme-directory/hivepress/listing/edit/block/listing-created-date.php

If you create this file keeping the directory structure it will override the plugin’s one.

1 Like

Great, thank you. Where would this membership extension go though?

wp-content/plugins/hivepress-memberships/includes/controllers/class-membership.php

Hi,

You can overwrite only template parts using a child theme, but not a framework file. It all depends on what exactly you need to change in this file, but in 99% of cases, it can be customized using hooks, for example: hivepress/v1/routes

1 Like

I wanted to modify this function inside:
wp-content/plugins/hivepress-memberships/includes/controllers/class-membership.php

public function redirect_membership_plan_select_page()

How can I do this?

Hi,

Please provide more details on what specific changes you need and we will try to provide more details (perhaps there is another way to make such changes).

1 Like

Hi Andrii,

I’m adding commands such as $wpdb->insert and modify/updating the postmeta table. I am also adding various commands like these throughout other functions in the class-membership.php file.

Sorry for the delay.

If possible describe the required functional changes, e.g. why adding $wpdb->insert is needed, I can recommend something depending on the desirable results. It’s better to use hooks if available or override template parts because any direct file changes will require disabling updates for HivePress or making these changes on every update.

The all-in-one solution is to use the hivepress/v1/routes hook to override the redirect and action functions for the routes (URLs which render templates) you want to customize, but replacing them completely will also cause an issue if the original functions in HivePress are updated someday.

Sure, so here’s an example of a modification I would like to make to the function reveal_membership in class-membership.php.

  1. Change this value to 5. Original value is 1.
if ( $membership->get_view_limit() > **5** ) {
$membership->set_view_limit( $membership->get_view_limit() - **5** )->save_view_limit();
  1. Add this code afterwards:
$result = $wpdb->insert(
		    "{$wpdb->prefix}custom_view", 
		    array(
		        'post_id' => $post_id,
                        'limit' => 5,
		        'user_id' => get_current_user_id()
		    ),

Are modifications like this possible without editing the original file?

  1. Please check if it’s possible to change it in the UI, e.g. for the free membership plan or extra premium plans (e.g. you can create a free plan for everyone to select with a limit of 5, this would be a workaround).

  2. This depends on when this code should run, is there a specific action or event? I can suggest a hook then which can be used to run this code via an external code snippet.

Hi ihor,

  1. This is not possible to set in the UI. The UI View Limit option is for how many views the user receives. The 5 figure I am trying to set is how many views it would subtract from the View Limit from the user.

  2. I would like to run this on line 159 in between $membership->set_view_limit… and elseif

if ( $membership->get_view_limit() > 1 ) {
// Update view limit.
$membership->set_view_limit( $membership->get_view_limit() - 1 )->save_view_limit();
<< ADD CODE HERE>>
} elseif ( $membership->is_default() ) {

  1. I recommend checking workarounds, e.g. increase the actual average price for a single reveal 5x, otherwise editing the code directly is required.

  2. You can try using this hook hivepress/v1/models/memebership/update_view_limit or hivepress/v1/models/membership/update but extra conditions may be required in the functions attached to these hooks to distinguish the initial update of the membership (when it’s created with a view limit) from the substraction.

Hope this helps