JUst trying to re-implement a code that i used to used

hi,

JUst trying to re-implement a code that i used to used on previous pro site versions, however i have looked at the new function code its totally different. I'd like to implement this function within pro-sites/pro-sites-files/modules/posting-quota.php between line 110-141. the below code i used it to tell users how many products they have left on their account in the product page, any help on allowing pro site to tell the user how many products they have left will be greatly appreciated . THanks in advanced.

function message() {
          global $psts, $current_screen,  $blog_id;
          $post_type ="product";
          if ( is_pro_site( false, $psts->get_setting( 'pq_level', 1 ) ) ) {
               return;
          }
          $quota_settings = $psts->get_setting( "pq_quotas" );
          if ( isset ( $quota_settings[ $post_type ] ) ) {
               if ( in_array( $current_screen->id, array( $post_type, 'edit-' . $post_type ) ) ) {
                    if ( is_array( $quota_settings ) ) {
                         if ( isset( $quota_settings[ $post_type ] ) ) {
                              if ( is_numeric( @$quota_settings[ $post_type ]['quota'] ) && wp_count_posts( $post_type )->publish >= @$quota_settings[ $post_type ]['quota'] ) {
                                   $notice = str_replace( 'LEVEL', $psts->get_level_setting( $psts->get_setting( 'pq_level', 1 ), 'name' ), @$quota_settings[ $post_type ]['message'] );
                                   echo '<div class="error"><p><a href="' . $psts->checkout_url( $blog_id ) . '">' . $notice . '</a></p></div>';
                              }else{
                                   $published_post = wp_count_posts( $post_type )->publish;
                                   $allowed_post = $quota_settings[ $post_type ]['quota'];
                                   echo '<div class="error"><p>You have <b>'. ( $allowed_post - $published_post ) .'</b> ' . $post_type ."'s". ' left.</p></div>';
                              }
                         }
                    }
               }
          }
     }
  • Tom Whittaker

    Hi @Anang,

    i know where the function is located, i just wanted to override it with my function, because the "function message" that i have here, i used to used it so that i can show to users how many woocommerce products they have left. but with the current function that is located in the prosite is totally different with the one that i have. because the old version pro site used to have the exact "function message" , but with this new update, its a bit different. dont know if you understand what am trying to achieve.

    THanks.

  • Anang

    Hi @Thomas Whittaker

    I got your point :slight_smile: If I read the code above it will displayed products quota on products dashboard page only, and didn't display other post quotas on other page. Am I right ?

    Here is your modified code :

    function message() {
    		global $psts, $current_screen, $post_type, $blog_id;
    		$post_type ="product";
    		//Get quota settings
    		$quota_settings = $psts->get_setting( "pq_quotas" );
    
    		//if limit not set for post type
    		if ( ! empty( $post_type ) && ! isset( $quota_settings[ $post_type ] ) ) {
    			return;
    		}
    
    		//If we are not on post type new screen
    		if ( ! empty( $post_type ) && ! in_array( $current_screen->id, array( $post_type, 'edit-' . $post_type ) ) ) {
    			return;
    		}
    
    		//For media Screen post type variable is not set, if no quota set or it is unlimited
    		if ( empty( $post_type ) && ( empty( $quota_settings['attahcment'] ) || $quota_settings['attahcment'] == 'unlimited' ) ) {
    			return;
    		}
    
    		//Finally if post type was not set, and its not media screen
    		if ( empty( $post_type ) && ! in_array( $current_screen->base, array( 'upload', 'media' ) ) ) {
    			return;
    		}
    
    		$limit = $quota_settings[ $post_type ]['quota'];
    		if ( isset ( $quota_settings[ $post_type ] ) ) {
                   if ( in_array( $current_screen->id, array( $post_type, 'edit-' . $post_type ) ) ) {
                        if ( is_array( $quota_settings ) ) {
                             if ( isset( $quota_settings[ $post_type ] ) ) {
                                  if ( is_numeric($limit ) && wp_count_posts( $post_type )->publish >= $limit ) {
                                       $notice = str_replace( 'LEVEL', $psts->get_level_setting( $psts->get_setting( 'pq_level', 1 ), 'name' ), @$quota_settings[ $post_type ]['message'] );
                                       echo '<div class="error"><p><a href="' . $psts->checkout_url( $blog_id ) . '">' . $notice . '</a></p></div>';
                                  }else{
                                       $published_post = wp_count_posts( $post_type )->publish;
                                       $allowed_post = $limit;
                                       echo '<div class="error"><p>You have <b>'. ( $allowed_post - $published_post ) .'</b> ' . $post_type ."'s". ' left.</p></div>';
                                  }
                             }
                        }
                   }
              }
    	}

    Let me know if it's works :slight_smile:

    Best Regards

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.