<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mithun Biswas</title>
    <description>The latest articles on DEV Community by Mithun Biswas (@bhootbiswas).</description>
    <link>https://dev.to/bhootbiswas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F180994%2Fc1193cbb-69b2-4805-92b2-526839b3bca7.jpeg</url>
      <title>DEV Community: Mithun Biswas</title>
      <link>https://dev.to/bhootbiswas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bhootbiswas"/>
    <language>en</language>
    <item>
      <title>How to Customize Paginated Links for BuddyPress Members &amp; Groups Directory Pages</title>
      <dc:creator>Mithun Biswas</dc:creator>
      <pubDate>Mon, 24 Jun 2019 07:34:37 +0000</pubDate>
      <link>https://dev.to/upnrunnhq/how-to-customize-paginated-links-for-buddypress-members-groups-directory-pages-3bjf</link>
      <guid>https://dev.to/upnrunnhq/how-to-customize-paginated-links-for-buddypress-members-groups-directory-pages-3bjf</guid>
      <description>&lt;p&gt;BuddyPress is using the &lt;a href="https://codex.wordpress.org/Function_Reference/paginate_links"&gt;paginate_links()&lt;/a&gt; function for building paginated navigation links on members and groups directory pages. The &lt;a href="https://codex.wordpress.org/Function_Reference/paginate_links"&gt;paginate_links()&lt;/a&gt; function is working fine on directory pages but we want to customize the output a little bit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IBuTVWxL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xcxdyz1g2v31ko0udsd8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IBuTVWxL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xcxdyz1g2v31ko0udsd8.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’d like to add the following changes to the default output of the &lt;a href="https://codex.wordpress.org/Function_Reference/paginate_links"&gt;paginate_links()&lt;/a&gt; function.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We will display the number of total items.&lt;/li&gt;
&lt;li&gt;Instead of disabling the current page link, we will add text input so the user can put any number to navigate pages easily.&lt;/li&gt;
&lt;li&gt;We have links for previous and next page but will also add two additional links to navigate to the first and last page easily and remove unnecessary links.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s start.‌&lt;/p&gt;

&lt;p&gt;First, we will prepare our main function which will display pagination links based on parameters. We have customized the WordPress’s existing &lt;a href="https://codex.wordpress.org/Function_Reference/paginate_links"&gt;paginate_links()&lt;/a&gt; function to create our own &lt;code&gt;my_theme_buddypress_paginate_links()&lt;/code&gt; function.‌&lt;/p&gt;

&lt;p&gt;You can check WordPress Codex to learn more about how &lt;a href="https://codex.wordpress.org/Function_Reference/paginate_links"&gt;paginate_links()&lt;/a&gt; function works.‌&lt;/p&gt;

&lt;p&gt;Let’s start with &lt;code&gt;my_theme_buddypress_paginate_links()&lt;/code&gt; function which will return empty string for now instead of paginated links.&lt;/p&gt;

&lt;p&gt;We will define our default arguments which will be parsed with the arguments you pass when calling the function. You can pass an array of arguments for generating paginated links, and your arguments will be parsed with the defaults.&lt;/p&gt;

&lt;p&gt;Conditionally we have to disable first, previous, next and last buttons, so the user can’t click on these buttons to navigate. Let’s add conditions to update our arguments.&lt;/p&gt;

&lt;p&gt;Now update the &lt;code&gt;$output&lt;/code&gt; variable to display the number of total items.&lt;/p&gt;

&lt;p&gt;We will save our paginated links in an array and add these to the output using the &lt;code&gt;join()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;We have added a class &lt;code&gt;button&lt;/code&gt; to each link, this will prevent running BuddyPress’s default JavaScript function for our custom paginated links.‌&lt;/p&gt;

&lt;p&gt;Now we have our own &lt;code&gt;my_theme_buddypress_paginate_links()&lt;/code&gt; function, and it’s ready to use when filtering the BuddyPress members and groups pagination links before getting displayed.‌&lt;/p&gt;

&lt;p&gt;We will filter &lt;code&gt;bp_get_members_pagination_links&lt;/code&gt; and &lt;code&gt;bp_get_groups_pagination_links&lt;/code&gt; hooks.‌&lt;/p&gt;

&lt;p&gt;The following code is for adding a hook callback to filter the members’ pagination links.&lt;/p&gt;

&lt;p&gt;The following code is for adding a hook callback to filter the members’ pagination links.&lt;/p&gt;

&lt;p&gt;We are almost done! ‌&lt;/p&gt;

&lt;p&gt;Pagination links will not work properly until we add some Javascript to send Ajax request to update the results.‌&lt;/p&gt;

&lt;p&gt;Let’s add inline Javascript in the footer of your website with WordPress &lt;a href="https://developer.wordpress.org/reference/functions/wp_footer/"&gt;wp_footer&lt;/a&gt;hook.&lt;/p&gt;

&lt;p&gt;The above Javascript will listen to onclick JavaScript event when you click on paginated links and send Ajax filter request to display the updated results of the current page.‌&lt;/p&gt;

&lt;p&gt;Let’s update the &lt;code&gt;my_theme_footer_scripts&lt;/code&gt; callback function with the following code.&lt;/p&gt;

&lt;p&gt;The above Javascript will listen to onchange JavaScript event when you enter a new value in the input field of the current page and send Ajax filter request to display the updated results of the current page.‌&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/upnrunnHQ/bp-custom-pagination"&gt;Full source code&lt;/a&gt; is available to download on GitHub as a WordPress plugin, you can download or clone the repository easily.‌&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://upnrunn.com/blog/2019/06/how-to-customize-paginated-links-for-buddypress-directory-pages/"&gt;How to Customize Paginated Links for BuddyPress Members &amp;amp; Groups Directory Pages&lt;/a&gt; appeared first on &lt;a href="https://upnrunn.com"&gt;upnrunn® | Build &amp;amp; Deploy Powerful Application&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>buddypress</category>
    </item>
    <item>
      <title>How To Extend WP REST API From Your Custom Plugin: Part 4</title>
      <dc:creator>Mithun Biswas</dc:creator>
      <pubDate>Wed, 17 Oct 2018 06:14:25 +0000</pubDate>
      <link>https://dev.to/upnrunnhq/how-to-extend-wp-rest-api-from-your-custom-plugin-part-4-4elh</link>
      <guid>https://dev.to/upnrunnhq/how-to-extend-wp-rest-api-from-your-custom-plugin-part-4-4elh</guid>
      <description>&lt;p&gt;&lt;strong&gt;This is article 4 of 5 in the series “How To Extend WP REST API From Your Custom Plugin”&lt;/strong&gt;. In case you missed the previous tutorials check the list below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://upnrunn.com/blog/2018/02/extend-wp-rest-api-custom-plugin-part-1/"&gt;How To Extend WP REST API From Your Custom Plugin (Part 1)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://upnrunn.com/blog/2018/02/extend-wp-rest-api-custom-plugin-part-2/"&gt;How To Extend WP REST API From Your Custom Plugin (Part 2)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/kish2011_/how-to-extend-wp-rest-api-from-your-custom-plugin-part-3-4mbk-temp-slug-5990155"&gt;How To Extend WP REST API From Your Custom Plugin (Part 3)&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We have created a controller class in the last tutorial to fetch restaurant items and a single restaurant item. A controller class helps to handle the functionality of an endpoint easily. You can learn more about the controller class by reading the REST API Handbook regarding Controller Classes.&lt;/p&gt;

&lt;p&gt;In this tutorial, we will write a few controller methods to update or delete a single restaurant item. Make sure you have installed WP Restaurant Listings and the custom plugins we created in the last tutorials.&lt;/p&gt;

&lt;p&gt;First, we will add a delete method to the existing route where we can send HTTP request to delete a restaurant item.&lt;/p&gt;

&lt;p&gt;The delete method we have just added accepts one argument to choose whether to bypass trash and force deletion. However, we have to add two missing methods &lt;code&gt;delete_item&lt;/code&gt; and &lt;code&gt;delete_item_permissions_check&lt;/code&gt; also.&lt;/p&gt;

&lt;p&gt;Now, our &lt;code&gt;delete_item&lt;/code&gt; method is ready which is responsible for deleting a restaurant item. We will write logic in &lt;code&gt;delete_item_permissions_check&lt;/code&gt; method to check if a given request has access to delete a restaurant item.&lt;/p&gt;

&lt;p&gt;You have noticed that we are using the &lt;code&gt;get_restaurant&lt;/code&gt; method, let us add this method also.&lt;/p&gt;

&lt;p&gt;Finally, everything is ready to delete a restaurant item by sending a simple HTTP &lt;code&gt;DELETE&lt;/code&gt; request.&lt;/p&gt;

&lt;p&gt;Let’s send a HTTP &lt;code&gt;DELETE&lt;/code&gt; request to &lt;code&gt;wp-json/rest-tutorial/v1/restaurants/{id}&lt;/code&gt; endpoint. If the restaurant has been deleted successfully you will get the following response.&lt;/p&gt;

&lt;p&gt;When sending a request using &lt;a href="https://www.getpostman.com/"&gt;Postman&lt;/a&gt; make sure you have installed &lt;a href="https://github.com/WP-API/Basic-Auth"&gt;Basic Auth&lt;/a&gt; plugin for basic authentication.&lt;/p&gt;

&lt;p&gt;You also can set param &lt;code&gt;force=true&lt;/code&gt; to permanently delete item instead of moving to trash.&lt;/p&gt;

&lt;p&gt;In the next tutorials, we will learn how to create and update a restaurant item by sending the HTTP POST method.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://upnrunn.com/blog/2018/10/how-to-extend-wp-rest-api-from-your-custom-plugin-part-4/"&gt;How To Extend WP REST API From Your Custom Plugin: Part 4&lt;/a&gt; appeared first on &lt;a href="https://upnrunn.com"&gt;upnrunn® | Build &amp;amp; Deploy Powerful Application&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>blog</category>
    </item>
    <item>
      <title>How To Extend WP REST API From Your Custom Plugin: Part 3</title>
      <dc:creator>Mithun Biswas</dc:creator>
      <pubDate>Wed, 11 Apr 2018 14:09:47 +0000</pubDate>
      <link>https://dev.to/upnrunnhq/how-to-extend-wp-rest-api-from-your-custom-plugin-part-3-24m2</link>
      <guid>https://dev.to/upnrunnhq/how-to-extend-wp-rest-api-from-your-custom-plugin-part-3-24m2</guid>
      <description>&lt;p&gt;&lt;strong&gt;This is article 3 of 5 in the series “How To Extend WP REST API From Your Custom Plugin”&lt;/strong&gt;. In case you missed the previous tutorials check the list below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://upnrunn.com/blog/2018/02/extend-wp-rest-api-custom-plugin-part-1/"&gt;How To Extend WP REST API From Your Custom Plugin (Part 1)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://upnrunn.com/blog/2018/02/extend-wp-rest-api-custom-plugin-part-2/"&gt;How To Extend WP REST API From Your Custom Plugin (Part 2)&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the previous tutorials, we have created a basic plugin where we can write our code and learned how to extend REST API by modifying responses.&lt;/p&gt;

&lt;p&gt;WordPress REST API has default routes and endpoints. It also allows developers to add custom routes and endpoints. That’s great. In this tutorial, we will learn how to add custom endpoints.&lt;/p&gt;

&lt;p&gt;Recently, we have released a plugin called &lt;a href="https://wordpress.org/plugins/wp-restaurant-listings/"&gt;WP Restaurant Listings&lt;/a&gt; which you can use to add restaurant listing functionality to your WordPress site. This plugin doesn’t have builtin custom endpoints to access your restaurant site’s data through WP REST API. So, We are going to add custom endpoints in our plugin to access data by sending HTTP request easily.&lt;/p&gt;

&lt;p&gt;We will use the controller pattern, so we can organize our code easily. You can learn more about the &lt;a href="https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/#the-controller-pattern"&gt;controller pattern here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First, create a file called &lt;code&gt;class-rest-tutorial-restaurant-endpoint.php&lt;/code&gt; inside the &lt;code&gt;includes&lt;/code&gt; folder of the plugin we created in the previous tutorials with the following content.&lt;/p&gt;

&lt;p&gt;We did not register the route yet. To register the new route we will use the &lt;code&gt;register_rest_route&lt;/code&gt; function. We will pass in three parameters: the namespace, the route we want, and the options (an array of arrays for multiple methods) to this function. Inside the &lt;code&gt;register_routes method&lt;/code&gt;, let’s add the following code.&lt;/p&gt;

&lt;p&gt;We are using WP_REST_Server constants to set the method, it a common practice. So we are using WP_REST_Server::READABLE to set the method to ‘GET’. When users send ‘GET’ request to the registered route &lt;code&gt;get_items&lt;/code&gt; method of the class will be called. Let’s add that method.&lt;/p&gt;

&lt;p&gt;We also need to add &lt;code&gt;get_items_permissions_check&lt;/code&gt; method. To make restaurants readable by all users we need to make sure that &lt;code&gt;get_items_permissions_check&lt;/code&gt; return true.&lt;/p&gt;

&lt;p&gt;Next, we are going to add a method which will return an array of parameters. Our newly registered route will accept these parameters when sending ‘GET’ request to WP REST API.&lt;/p&gt;

&lt;p&gt;Finally, we need to add another method which will prepare restaurant data and return as an object.&lt;/p&gt;

&lt;p&gt;Now, our class &lt;code&gt;REST_TUTORIAL_Restaurnt_Endpoint&lt;/code&gt; is ready to do some cool things. We did not include this class yet, so we need to include it first. Add the following code inside the &lt;code&gt;rest-api-tutorial.php&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;We are checking if the &lt;a href="https://wordpress.org/plugins/wp-restaurant-listings/"&gt;WP_Restaurant_Listings&lt;/a&gt; plugin is installed or not. If the the plugin is not installed and active we will not include the &lt;code&gt;REST_TUTORIAL_Restaurnt_Endpoint&lt;/code&gt; class. So, it is required to install and activate &lt;a href="https://wordpress.org/plugins/wp-restaurant-listings/"&gt;WP_Restaurant_Listings&lt;/a&gt; plugin to make it work.&lt;/p&gt;

&lt;p&gt;We did an awesome job. Now if we send “GET’ request to &lt;code&gt;wp-json/rest-tutorial/v1/restaurants&lt;/code&gt; we will get the restaurants in simple JSON format as pictured below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RznA1JvK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/upnrunn.com/wp-content/uploads/2018/04/restaurants_data.png%3Fresize%3D1130%252C602%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RznA1JvK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/upnrunn.com/wp-content/uploads/2018/04/restaurants_data.png%3Fresize%3D1130%252C602%26ssl%3D1" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similarly, we can register another route to get single restaurant item. We’re going to have the route match anything with &lt;code&gt;/restaurants/{id}&lt;/code&gt;, where {id} is an integer. Check the following code.&lt;/p&gt;

&lt;p&gt;We are using the &lt;code&gt;get_items_permissions_check&lt;/code&gt; again to make restaurant readable by all users. Now, it’s time to retrieve the restaurant by adding the &lt;code&gt;get_item&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;Now, you can now easily get a restaurant data by sending HTTP “GET” request to &lt;code&gt;wp-json/rest-tutorial/v1/restaurants/{id}&lt;/code&gt; endpoint.&lt;/p&gt;

&lt;p&gt;In the next tutorials, I will show you how to register route with POST, PUT, DELETE methods to update or delete a restaurant.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://upnrunn.com/blog/2018/04/how-to-extend-wp-rest-api-from-your-custom-plugin-part-3/"&gt;How To Extend WP REST API From Your Custom Plugin: Part 3&lt;/a&gt; appeared first on &lt;a href="https://upnrunn.com"&gt;upnrunn® | Build &amp;amp; Deploy Powerful Application&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>blog</category>
    </item>
  </channel>
</rss>
