Edit the columns displayed in Private Pages section

    • Shaun Bowen
      Membre
      # il y a 1 année et 9 mois

      Hi there, we are using the WP Customer Area plugin to gather dental referrals from a custom form. We have already integrated the form results into the database and individual private page displays, however we would like to edit the columns in the table displayed under Private Area > Pages.

      Is it possible to give me some help with displaying some of the new custom form fields and changing the default order of the columns (ie. to put the date first)?

      Are there any particular hooks of snippets of code I can use?

    • Thomas
      Maître des clés
      # il y a 1 année et 9 mois

      Hello,

      To do that, you’ll need to first create a custom WPCA plugin (see our code snippets documentation).

      Then, you could use this kind of code snippets, and arrange the functions to display what you need.

      /**
       * Register hooks required to edit listing columns in the admin area
       * @return void
       */
      function wpca_register_admin_column_hooks()
      {
      	if (!is_admin())
      	{
      		return;
      	}
      
      	$type = 'cuar_private_page';
      	add_filter("cuar/core/admin/container-list-table/column-content?post_type=$type",
      		'wpca_print_list_table_columns', 10, 4);
      	add_filter("cuar/core/admin/container-list-table/columns?post_type=$type",
      		'wpca_register_list_table_columns', 10, 2);
      
      	add_filter("cuar/core/admin/content-list-table/column-content?post_type=$type",
      		'wpca_print_list_table_columns', 10, 4);
      	add_filter("cuar/core/admin/content-list-table/columns?post_type=$type",
      		'wpca_register_list_table_columns', 10, 2);
      }
      add_action('cuar/core/addons/after-init', 'wpca_register_admin_column_hooks');
      
      /**
       * Customize the columns shown in the list table
       *
       * @param array          $columns
       * @param CUAR_ListTable $list_table
       *
       * @return array
       */
      function wpca_register_list_table_columns($columns, $list_table)
      {
      	// Here you can add a new column to the list table by adding an item to the array
      	$columns['custom_colum_slug'] = __('Custom column', 'plugin-textdomain');
      
      	// You could also change the order of the items into the array, to change the order of the columns
      
      	return $columns;
      }
      
      /**
       * Display the content of our custom columns in the list table
       *
       * @param string         $out
       * @param WP_Post        $item
       * @param string         $column_name
       * @param CUAR_ListTable $list_table
       *
       * @return string
       */
      function wpca_print_list_table_columns($out, $item, $column_name, $list_table)
      {
      	switch ($column_name)
      	{
      		case 'custom_colum_slug':
      			$post_id = $item->ID;
      
      			// Here you get the desired values. If it's a post_meta, you could simply do this
      			$out = get_post_meta($post_id, 'custom_meta_slug', true);
      			break;
      	}
      
      	return $out;
      }

      I hope that helps.

      Regards.

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

    • Shaun Bowen
      Membre
      # il y a 1 année et 8 mois

      Many thanks for the code snippet – I will get our programmer to give it a go.

      Could this also be added to the functions.php file in a child theme, rather than creating a plugin for it?

      Regards,

      Shaun

    • Thomas
      Maître des clés
      # il y a 1 année et 8 mois

      Hi,

      You’re welcome.

      It is highly recommended that you put all your WPCA code snippets into a plugin:

      • Putting code in a theme functions.php might sometimes not work because the themes are loaded too late in the WP execution process, and some of our hooks might have already been executed when this file is loaded. In the current case,  you can’t put it in your functions.php file because cuar/core/addons/after-init would have already been executed. Code would not work.
      • For easier maintainance, it’s better to keep all your WPCA tweaks structured into a single plugin. You could however keep theme-related tweak into your theme folder (such as CSS color changes). Just keep in mind that one day, you’ll maybe need to change your theme. Separating design and practical tweaks is always the way to go 🙂

      Follow our code snippets documentation to know how to use snippets in a custom plugin.

      Regards.

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

    • Shaun Bowen
      Membre
      # il y a 1 année et 8 mois

      Hi Thomas,

      You were absolutely right, it didn’t work in functions.php so we created a plugin as suggested and it worked perfectly!

      Many thanks for your assistance – I will mark this topic as closed.

      Shaun

    • Thomas
      Maître des clés
      # il y a 1 année et 8 mois

      Hi,

      You’re welcome.

      Do not hesitate if you need anything else.

      Also, if you’d like to leave a review for the plugin, that would be greatly appreciated and would help the community 🙂

      Best 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

The topic ‘Edit the columns displayed in Private Pages section’ is closed to new replies.