bp_gifts_admin

Bp_gifts_admin().

Description

bp_gifts_admin( (string) $message = '', (string) $type = 'error' ); 

Checks for form submission, saves component settings and outputs admin screen HTML.

Parameters (2)

0. $message — Optional. (string) => ''
The message.
1. $type — Optional. (string) => 'error'
The type.

Usage

  1. if ( !function_exists( 'bp_gifts_admin' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-gifts-latest-2014/includes/bp-gifts-admin.php'; 
  3.  
  4. // The message. 
  5. $message = ''; 
  6.  
  7. // The type. 
  8. $type = 'error'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_gifts_admin($message, $type); 
  12.  

Defined (2)

The function is defined in the following location(s).

/includes/bp-gifts-admin.php  
  1. function bp_gifts_admin($message = '', $type = error) { 
  2.  
  3. global $bp; 
  4.  
  5.  
  6.  
  7. if ( $message != '' ) { 
  8.  
  9. echo wp_specialchars( attribute_escape( $message ) ); 
  10.  
  11.  
  12.  
  13.  
  14. /** If the form has been submitted and the admin referrer checks out, save the settings */ 
  15.  
  16.  
  17.  
  18. /** check submit from edit gift data */ 
  19.  
  20. if ( isset( $_POST['submit'] ) && check_admin_referer('gifts-settings') ) { 
  21.  
  22. if (isset( $_POST['gift_id'])) { 
  23.  
  24. $gift = new BP_Gifts($_POST['gift_id']); 
  25.  
  26. $gift->gift_name = $_POST['gift_name']; 
  27.  
  28. $gift->category = $_POST['category']; 
  29.  
  30. $gift->point = $_POST['point']; 
  31.  
  32. $gift->save(); 
  33.  
  34. $updated = true; 
  35.  
  36. } elseif (isset( $_FILES['file']) && check_admin_referer('gifts-settings')) { /** check submit from gift upload */  
  37.  
  38. $message = sprintf( __('Gift item was upload successfully! <br/>', 'buddypress'), $type); 
  39.  
  40. $dir = WP_PLUGIN_DIR.'/buddypress-gifts-latest-2014/includes/images'; 
  41.  
  42. if (file_exists($dir.'/'.$_FILES["file"]["name"])) { 
  43.  
  44. echo "<div id='message' class='updated fade'><p>" . __( 'Gifts Image already exist!!', 'bp-gifts' ) . "</p></div>"; 
  45.  
  46. } elseif (!bp_core_check_avatar_type($_FILES)) { 
  47.  
  48. echo "<div id='message' class='updated fade'><p>" . __( 'Please upload only JPG GIF or PNG image!!', 'bp-gifts' ) . "</p></div>"; 
  49.  
  50. } else { 
  51.  
  52. move_uploaded_file($_FILES["file"]["tmp_name"], $dir.'/'.$_FILES["file"]["name"]); 
  53.  
  54. $giftname = explode(".", $_FILES["file"]["name"]); 
  55.  
  56. bp_gifts_newgift($giftname[0], $_FILES["file"]["name"]); 
  57.  
  58. $uploaded = true; 
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. ?> 
  71.  
  72.  
  73.  
  74. <?php 
  75.  
  76. // check if gift was chosed to edit or delete 
  77.  
  78. if ( isset($_GET['mode']) && isset($_GET['gift_id'])) { 
  79.  
  80. $gift = new BP_Gifts($_GET['gift_id']); 
  81.  
  82. if ($_GET['mode'] == 'delete') { 
  83.  
  84. if ($gift->delete()) { 
  85.  
  86. $message = sprintf( __('Gift item was deleted successfully!', 'buddypress'), $type); 
  87.  
  88. } else { $message = sprintf( __('Error !!! Can not delete gift item.', 'buddypress'), $type); } 
  89.  
  90. unset($_GET['mode']); 
  91.  
  92. bp_gifts_admin($message); 
  93.  
  94. } elseif ($_GET['mode'] == 'edit') { 
  95.  
  96. echo '<h1>'._e( 'Gifts Item Admin', 'bp-gifts' ).'</h1><br/>'; 
  97.  
  98. echo '<img src="' . bp_get_root_domain() .'/wp-content/plugins/buddypress-gifts-latest-2014/includes/images/'. $gift->gift_image .'" />'; 
  99.  
  100. ?> 
  101.  
  102. <form action="<?php echo site_url() . '/wp-admin/admin.php?page=bp-gifts-settings' ?>" name="gifts-settings-form" id="gifts-settings-form" method="post"> 
  103.  
  104.  
  105.  
  106. <table class="form-table"> 
  107.  
  108. <tr valign="top"> 
  109.  
  110. <th scope="row"><label for="target_uri"><?php _e( 'Gift name', 'bp-gifts' ) ?></label></th> 
  111.  
  112. <td> 
  113.  
  114. <input name="gift_name" type="text" id="gift_name" value="<?php esc_attr_e( $gift->gift_name ); ?>" size="30" /> 
  115.  
  116. </td> 
  117.  
  118. </tr> 
  119.  
  120. <th scope="row"><label for="target_uri"><?php _e( 'Category', 'bp-gifts' ) ?></label></th> 
  121.  
  122. <td> 
  123.  
  124. <input name="category" type="text" id="point" value="<?php echo esc_attr_e( $gift->category ); ?>" size="30" /> 
  125.  
  126. </td> 
  127.  
  128. </tr> 
  129.  
  130. <th scope="row"><label for="target_uri"><?php _e( 'Point', 'bp-gifts' ) ?></label></th> 
  131.  
  132. <td> 
  133.  
  134. <input name="point" type="text" id="point" value="<?php echo esc_attr_e( $gift->point ); ?>" size="30" /> 
  135.  
  136. </td> 
  137.  
  138. </tr> 
  139.  
  140. </table> 
  141.  
  142. <input type="hidden" name="gift_id" value="<?php echo $gift->id; ?>" /> 
  143.  
  144. <p class="submit"> 
  145.  
  146. <input type="submit" name="submit" value="<?php _e( 'Save Settings', 'bp-gifts' ) ?>"/> 
  147.  
  148. </p> 
  149.  
  150.  
  151.  
  152. <?php 
  153.  
  154. /** This is very important, don't leave it out. */ 
  155.  
  156. wp_nonce_field( 'gifts-settings' ); 
  157.  
  158. ?> 
  159.  
  160. </form> 
  161.  
  162. <?php 
  163.  
  164.  
  165. } else { 
  166.  
  167. ?> 
  168.  
  169.  
  170.  
  171. <!--------------- start main config admin panel --------------> 
  172.  
  173.  
  174.  
  175. <div class="wrap"> 
  176.  
  177. <h2><?php _e( 'Gifts Admin', 'bp-gifts' ) ?></h2> 
  178.  
  179. <br /> 
  180.  
  181.  
  182.  
  183. <?php if ( isset($updated) ) : ?><?php echo "<div id='message' class='updated fade'><p>" . __( 'Settings Updated.', 'bp-gifts' ) . "</p></div>" ?><?php endif; ?> 
  184.  
  185. <?php if ( isset($uploaded) ) : ?><?php echo "<div id='message' class='updated fade'><p>" . __( 'Gifts Uploaded.', 'bp-gifts' ) . "</p></div>" ?><?php endif; ?> 
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193. <form action="<?php echo site_url() . '/wp-admin/admin.php?page=bp-gifts-settings' ?>" method="post" enctype="multipart/form-data" name="gift-upload-form" id="gift-upload-form" >  
  194.  
  195. <br/> 
  196.  
  197. <label><?php _e('Select Gift Image to Upload *', 'bp-gifts' ) ?><br /> 
  198.  
  199. <input type="file" name="file" id="file"/></label> 
  200.  
  201. <p class="submit"> 
  202.  
  203. <input type="submit" name="submit" value="<?php _e( 'Upload', 'bp-gifts' ) ?>"/> 
  204.  
  205. </p> 
  206.  
  207. <input type="hidden" name="action" value="gifts_upload" /> 
  208.  
  209. <?php 
  210.  
  211. /** This is very important, don't leave it out. */ 
  212.  
  213. wp_nonce_field( 'gifts-settings' ); 
  214.  
  215. ?> 
  216.  
  217. </form> 
  218.  
  219. <br/> 
  220.  
  221.  
  222.  
  223. <?php /** return all gift item */ 
  224.  
  225. echo '<h3>Gift Item Editor :</h3>'; 
  226.  
  227. $allgift = bp_gifts_allgift(); 
  228.  
  229. echo '<div style="width:80%; padding:20px;">'; 
  230.  
  231. foreach ($allgift as $giftitem) { 
  232.  
  233. echo '<div style="float:left; width:10%; text-align:center;">'; 
  234.  
  235. echo '<img src="' . bp_get_root_domain() .'/wp-content/plugins/buddypress-gifts-latest-2014/includes/images/'. $giftitem->gift_image .'" /><br/>'; 
  236.  
  237. echo '<p style="text-align: center">'.$giftitem->gift_name.'</p>'; 
  238.  
  239. echo '<p style="text-align: center">'; 
  240.  
  241. echo '<a href="'. site_url() . '/wp-admin/admin.php?page=bp-gifts-settings&gift_id='.$giftitem->id.'&mode=edit" /> <img src="'. bp_get_root_domain() .'/wp-content/plugins/buddypress-gifts-latest-2014/includes/images/admin/edit.png" /></a>'; 
  242.  
  243. echo '<a href="'. site_url() . '/wp-admin/admin.php?page=bp-gifts-settings&gift_id='.$giftitem->id.'&mode=delete" /> <img src="'. bp_get_root_domain() .'/wp-content/plugins/buddypress-gifts-latest-2014/includes/images/admin/delete.png" /></a>'; 
  244.  
  245. echo '<p/>'; 
  246.  
  247. echo '</div>'; 
  248.  
  249.  
  250. echo '</div>'; 
  251.  
  252. ?> 
  253.  
  254.  
  255.  
  256. <!--<p class="submit"> 
  257.  
  258. <input type="submit" name="submit" value="<?php //_e( 'Save Settings', 'bp-gifts' ) ?>"/> 
  259.  
  260. </p>--> 
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. </div> 
  269.  
  270. <?php 
  271.  
  272.  
  273. ?> 
  274.  
  275. <?php 
  276.  
/includes/bp-gifts-admin-network.php  
  1. function bp_gifts_admin($message = '', $type = error) { 
  2.  
  3. global $bp; 
  4. global $wpdb; 
  5.  
  6.  
  7.  
  8. if ( $message != '' ) { 
  9.  
  10. echo wp_specialchars( attribute_escape( $message ) ); 
  11.  
  12.  
  13.  
  14.  
  15. /** If the form has been submitted and the admin referrer checks out, save the settings */ 
  16.  
  17.  
  18.  
  19. /** check submit from edit gift data */ 
  20.  
  21. if ( isset( $_POST['submit'] ) && check_admin_referer('gifts-settings') ) { 
  22.  
  23. if (isset( $_POST['gift_id'])) { 
  24.  
  25. $gift = new BP_Gifts($_POST['gift_id']); 
  26.  
  27. $gift->gift_name = $_POST['gift_name']; 
  28.  
  29. $gift->category = $_POST['category']; 
  30.  
  31. $gift->point = $_POST['point']; 
  32.  
  33. $gift->save(); 
  34.  
  35. $updated = true; 
  36.  
  37. } elseif (isset( $_FILES['file']) && check_admin_referer('gifts-settings')) { /** check submit from gift upload */  
  38.  
  39. $message = sprintf( __('Gift item was upload successfully! <br/>', 'buddypress'), $type); 
  40.  
  41. $dir = WP_PLUGIN_DIR.'/buddypress-gifts-latest-2014/includes/images'; 
  42.  
  43. if (file_exists($dir.'/'.$_FILES["file"]["name"])) { 
  44.  
  45. echo "<div id='message' class='updated fade'><p>" . __( 'Gifts Image already exist!!', 'bp-gifts' ) . "</p></div>"; 
  46.  
  47. } elseif (!bp_core_check_avatar_type($_FILES)) { 
  48.  
  49. echo "<div id='message' class='updated fade'><p>" . __( 'Please upload only JPG GIF or PNG image!!', 'bp-gifts' ) . "</p></div>"; 
  50.  
  51. } else { 
  52.  
  53. move_uploaded_file($_FILES["file"]["tmp_name"], $dir.'/'.$_FILES["file"]["name"]); 
  54.  
  55. $giftname = explode(".", $_FILES["file"]["name"]); 
  56.  
  57. bp_gifts_newgift($giftname[0], $_FILES["file"]["name"]); 
  58.  
  59. $uploaded = true; 
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. ?> 
  72.  
  73.  
  74.  
  75. <?php 
  76.  
  77. // check if gift was chosed to edit or delete 
  78.  
  79. if ( isset($_GET['mode']) && isset($_GET['gift_id'])) { 
  80.  
  81. $gift = new BP_Gifts($_GET['gift_id']); 
  82.  
  83. if ($_GET['mode'] == 'delete') { 
  84.  
  85. if ($gift->delete()) { 
  86.  
  87. $message = sprintf( __('Gift item was deleted successfully!', 'buddypress'), $type); 
  88.  
  89. } else { $message = sprintf( __('Error !!! Can not delete gift item.', 'buddypress'), $type); } 
  90.  
  91. unset($_GET['mode']); 
  92.  
  93. bp_gifts_admin($message); 
  94.  
  95. } elseif ($_GET['mode'] == 'edit') { 
  96.  
  97. echo '<h1>'._e( 'Gifts Item Admin', 'bp-gifts' ).'</h1><br/>'; 
  98.  
  99. echo '<img src="' . bp_get_root_domain() .'/wp-content/plugins/buddypress-gifts-latest-2014/includes/images/'. $gift->gift_image .'" />'; 
  100.  
  101. ?> 
  102.  
  103. <form action="<?php echo site_url() . '/wp-admin/network/admin.php?page=bp-gifts-settings' ?>" name="gifts-settings-form" id="gifts-settings-form" method="post"> 
  104.  
  105.  
  106.  
  107. <table class="form-table"> 
  108.  
  109. <tr valign="top"> 
  110.  
  111. <th scope="row"><label for="target_uri"><?php _e( 'Gift name', 'bp-gifts' ) ?></label></th> 
  112.  
  113. <td> 
  114.  
  115. <input name="gift_name" type="text" id="gift_name" value="<?php esc_attr_e( $gift->gift_name ); ?>" size="30" /> 
  116.  
  117. </td> 
  118.  
  119. </tr> 
  120.  
  121. <th scope="row"><label for="target_uri"><?php _e( 'Category', 'bp-gifts' ) ?></label></th> 
  122.  
  123. <td> 
  124.  
  125. <input name="category" type="text" id="point" value="<?php echo esc_attr_e( $gift->category ); ?>" size="30" /> 
  126.  
  127. </td> 
  128.  
  129. </tr> 
  130.  
  131. <th scope="row"><label for="target_uri"><?php _e( 'Point', 'bp-gifts' ) ?></label></th> 
  132.  
  133. <td> 
  134.  
  135. <input name="point" type="text" id="point" value="<?php echo esc_attr_e( $gift->point ); ?>" size="30" /> 
  136.  
  137. </td> 
  138.  
  139. </tr> 
  140.  
  141. </table> 
  142.  
  143. <input type="hidden" name="gift_id" value="<?php echo $gift->id; ?>" /> 
  144.  
  145. <p class="submit"> 
  146.  
  147. <input type="submit" name="submit" value="<?php _e( 'Save Settings', 'bp-gifts' ) ?>"/> 
  148.  
  149. </p> 
  150.  
  151.  
  152.  
  153. <?php 
  154.  
  155. /** This is very important, don't leave it out. */ 
  156.  
  157. wp_nonce_field( 'gifts-settings' ); 
  158.  
  159. ?> 
  160.  
  161. </form> 
  162.  
  163. <?php 
  164.  
  165.  
  166. } else { 
  167.  
  168. ?> 
  169.  
  170.  
  171.  
  172. <!--------------- start main config admin panel --------------> 
  173.  
  174.  
  175.  
  176. <div class="wrap"> 
  177.  
  178. <h2><?php _e( 'Gifts Admin', 'bp-gifts' ) ?></h2> 
  179.  
  180. <br /> 
  181.  
  182.  
  183.  
  184. <?php if ( isset($updated) ) : ?><?php echo "<div id='message' class='updated fade'><p>" . __( 'Settings Updated.', 'bp-gifts' ) . "</p></div>" ?><?php endif; ?> 
  185.  
  186. <?php if ( isset($uploaded) ) : ?><?php echo "<div id='message' class='updated fade'><p>" . __( 'Gifts Uploaded.', 'bp-gifts' ) . "</p></div>" ?><?php endif; ?> 
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194. <form action="<?php echo site_url() . '/wp-admin/network/admin.php?page=bp-gifts-settings' ?>" method="post" enctype="multipart/form-data" name="gift-upload-form" id="gift-upload-form" >  
  195.  
  196. <br/> 
  197.  
  198. <label><?php _e('Select Gift Image to Upload *', 'bp-gifts' ) ?><br /> 
  199.  
  200. <input type="file" name="file" id="file"/></label> 
  201.  
  202. <p class="submit"> 
  203.  
  204. <input type="submit" name="submit" value="<?php _e( 'Upload', 'bp-gifts' ) ?>"/> 
  205.  
  206. </p> 
  207.  
  208. <input type="hidden" name="action" value="gifts_upload" /> 
  209.  
  210. <?php 
  211.  
  212. /** This is very important, don't leave it out. */ 
  213.  
  214. wp_nonce_field( 'gifts-settings' ); 
  215.  
  216. ?> 
  217.  
  218. </form> 
  219.  
  220. <br/> 
  221.  
  222.  
  223.  
  224. <?php /** return all gift item */ 
  225.  
  226. echo '<h3>Gift Item Editor :</h3>'; 
  227.  
  228. $allgift = bp_gifts_allgift(); 
  229.  
  230.  
  231. echo '<div style="width:80%; padding:20px;">'; 
  232.  
  233.  
  234. foreach ($allgift as $giftitem) { 
  235.  
  236. echo '<div style="float:left; width:10%; text-align:center;">'; 
  237.  
  238. echo '<img src="' . bp_get_root_domain() .'/wp-content/plugins/buddypress-gifts-latest-2014/includes/images/'. $giftitem->gift_image .'" /><br/>'; 
  239.  
  240. echo '<p style="text-align: center">'.$giftitem->gift_name.'</p>'; 
  241.  
  242. echo '<p style="text-align: center">'; 
  243.  
  244. echo '<a href="'. site_url() . '/wp-admin/network/admin.php?page=bp-gifts-settings&gift_id='.$giftitem->id.'&mode=edit" /> <img src="'. bp_get_root_domain() .'/wp-content/plugins/buddypress-gifts-latest-2014/includes/images/admin/edit.png" /></a>'; 
  245.  
  246. echo '<a href="'. site_url() . '/wp-admin/network/admin.php?page=bp-gifts-settings&gift_id='.$giftitem->id.'&mode=delete" /> <img src="'. bp_get_root_domain() .'/wp-content/plugins/buddypress-gifts-latest-2014/includes/images/admin/delete.png" /></a>'; 
  247.  
  248. echo '<p/>'; 
  249.  
  250. echo '</div>'; 
  251.  
  252.  
  253. echo '</div>'; 
  254.  
  255. ?> 
  256.  
  257.  
  258.  
  259. <!--<p class="submit"> 
  260.  
  261. <input type="submit" name="submit" value="<?php //_e( 'Save Settings', 'bp-gifts' ) ?>"/> 
  262.  
  263. </p>--> 
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. </div> 
  272.  
  273. <?php 
  274.  
  275.  
  276. ?> 
  277.  
  278. <?php 
  279.