Customizing Pagination in WP Customer Area in the Admin Area

    • # il y a 3 mois et 1 semaine

      Hi,

      I am reaching out for assistance with the WP Customer Area plugin, specifically regarding the customization of pagination within the “All Files” list page (/wp-admin/admin.php?page=wpca-list%2Ccontent%2Ccuar_private_file).

      As an avid user of your plugin, purchasing almost all available add-ons, I have developed two PHP snippets in an attempt to modify the number of items displayed per page. Unfortunately, neither snippet seems to affect the pagination as intended. Below are the snippets I have used:

      1. The first snippet:
      add_filter(‘edit_posts_per_page’, function($per_page, $post_type) {
      if ($post_type == ‘cuar_private_file’) {
      $per_page = 100;
      }
      return $per_page;
      }, 10, 2);

      2. The second snippet:
      function custom_override_items_per_page($per_page, $option_name) {
      if ($option_name == ‘CUAR_PrivateContainerTable_per_page’) {
      $per_page = 100; // Set the number of items per page to 100
      }
      return $per_page;
      }
      add_filter(‘get_items_per_page’, ‘custom_override_items_per_page’, 10, 2);

      Despite these efforts, the pagination remains unchanged. I suspect there might be a specific subclass or another part of the plugin’s code that controls this functionality, which I might be overlooking.

      Could you kindly assist me in identifying the correct approach or provide any guidance on how to achieve this customization? Your expertise and support would be greatly appreciated, as I aim to enhance the functionality of WP Customer Area for my use case.

      Thank you for your time and the excellent work on the WP Customer Area plugin. Looking forward to your response.

      Best regards.

    • Thomas
      Maître des clés
      # il y a 3 mois et 1 semaine

      Hello,

      The first snippet should actually work, since the filter is called from customer-area/src/php/core-classes/Content/list-table.class.php, function prepare_items(), line 520:

      $items_per_page = $this->get_items_per_page(get_class($this) . '_per_page');
      1. You should probably make sure that you added this snippet in a custom plugin, rather than in your theme’s functions.php file.
      2. Also, you are trying to pass 2 arguments to the filter, but from what I can see from the core WP files, this filter only handle one argument. This is actually why your $post_type check doesn’t work. See wp-admin/includes/class-wp-list-table.php, function get_items_per_page(), line 933:
        return (int) apply_filters( "{$option}", $per_page );​

        Since the URL you are browsing contains a parameter like page=, you could probably use the WP get_current_screen() function and check if it contains the cuar_private_file post_type.

      Hope that helps.

      Regards.

      Want to help WP Customer Area? It only takes few seconds!
      Rate & review the plugin on WordPress.org 🙂

    • Thomas
      Maître des clés
      # il y a 3 mois et 1 semaine

      Oh, and sorry, I also missed that:

      $items_per_page = $this->get_items_per_page(get_class($this) . '_per_page');

      As you can see, we are passing the class name as the option, so you should probably replace the filter name edit_posts_per_page by CUAR_ListTable_per_page

      add_filter('CUAR_ListTable_per_page', function($per_page) {
      
      // Post_type parameter doesn't exist, use get_current_screen() function instead to retrieve the post_type from the URL
      /*
      if ($post_type == ‘cuar_private_file’) {
      $per_page = 100;
      }
      */
      
      return $per_page;
      }, 10, 1);

      Regards.

      Want to help WP Customer Area? It only takes few seconds!
      Rate & review the plugin on WordPress.org 🙂

    • Thomas
      Maître des clés
      # il y a 3 mois et 1 semaine

      And lastly, you could also try using the class CUAR_PrivateContainerTable’s name like you did since it extends CUAR_ListTable (except you have to use it as the filter name, not as filter argument).

      But this class is used to list containers objects (such as projects), so you might also want to take a look at the CUAR_PrivateContentTable class, which would be used to list private files.

      Regards.

      Want to help WP Customer Area? It only takes few seconds!
      Rate & review the plugin on WordPress.org 🙂

    • # il y a 3 mois et 1 semaine

      Hi Thomas, I edited the snippet as it follows, but unfortunately it isn’t working. Have you any suggestion to make it work? Thank you very much for your help.

      function custom_override_items_per_page() {
      add_filter(‘CUAR_PrivateContentTable_per_page’, function($per_page) {
      $screen = get_current_screen();
      if ($screen && $screen->post_type == ‘cuar_private_file’) {
      $per_page = 100; // Imposta il numero di elementi per pagina a 100
      }

      return $per_page;
      }, 99999);
      }

      add_action(‘admin_init’, ‘custom_override_items_per_page’);

    • Thomas
      Maître des clés
      # il y a 3 mois et 1 semaine

      Hi,

      Not sure why you’re adding a filter into a function bound to admin_init. It looks like a bit useless to me. You might also first try with CUAR_ListTable_per_page.

      add_filter('CUAR_ListTable_per_page', function($per_page) {
      $screen = get_current_screen();
      
      // Uncomment this line to make sure the snippet is actually triggerred on the appropriate pages
      // die(var_dump($screen));
      
      if ($screen && $screen->post_type == ‘cuar_private_file’) {
      $per_page = 100; // Imposta il numero di elementi per pagina a 100
      }
      
      return $per_page;
      }, 99999);

      Regards.

      Want to help WP Customer Area? It only takes few seconds!
      Rate & review the plugin on WordPress.org 🙂

Vous lisez 5 fils de discussion

You must be logged in to reply to this topic.