Guest User

Untitled

a guest
Apr 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.20 KB | None | 0 0
  1. function dwwp_register_post_type(){
  2.  
  3. $singular = 'Speaker';
  4. $plural = 'Speakers';
  5.  
  6. $labels = array(
  7. 'name' => $plural,
  8. 'singular_name' => $singular,
  9. 'add_name' => 'Add New',
  10. 'add_new_item' => 'Add New '.$singular,
  11. 'edit' => 'Edit',
  12. 'edit_item' => 'Edit '.$singular,
  13. 'new_item' => 'New '.$singular,
  14. 'view' => 'View '.$singular,
  15. 'view_item' => 'View '.$singular,
  16. 'search_term' => 'Search '.$plural,
  17. 'parent' => 'Parent '.$singular,
  18. 'not_found' => 'No '.$plural.' Found',
  19. 'not_found_in_trash' => 'No '.$plural.' in Trash',
  20. );
  21.  
  22.  
  23. $args = array(
  24. 'labels' => $labels,
  25. 'public' => true,
  26. 'publicly_queryable' => true,
  27. 'exclude_from_search' => false,
  28. 'show_in_nav_menus' => true,
  29. 'show_ui' => true,
  30. 'show_in_menu' => true,
  31. 'show_in_admin_bar' => true,
  32. 'menu_position' => 6,
  33. 'menu_icon' => 'dashicons-businessman',
  34. 'can_export' => true,
  35. 'delete_with_user' => false,
  36. 'hierarchical' => false,
  37. 'has_archive' => true,
  38. 'query_var' => true,
  39. 'capability_type' => 'post',
  40. 'map_meta_cap' => true,
  41. 'rewrite' => array(
  42. 'slug' => 'speakers',
  43. 'with_front' => true,
  44. 'pages' => true,
  45. 'feeds' => true,
  46. ),
  47. 'supports' => array(
  48. 'title',
  49. //'editor',
  50. //'author',
  51. //'custom-fields',
  52. 'thumbnail'
  53. )
  54. );
  55.  
  56. register_post_type('speakers', $args);
  57. }
  58. add_action('init', 'dwwp_register_post_type');
  59.  
  60. function dwwp_register_taxonomy(){
  61.  
  62. $plural = 'Years';
  63. $singular = 'Year';
  64.  
  65. $labels = array(
  66. 'name' => $plural,
  67. 'singular_name' => $singular,
  68. 'search_items' => 'Search '.$plural,
  69. 'popular_items' => 'Popular '.$plural,
  70. 'all_items' => 'All '.$plural,
  71. 'parent_item' => null,
  72. 'parent_item_colon' => null,
  73. 'edit_item' => 'Edit '.$singular,
  74. 'update_item' => 'Update '.$singular,
  75. 'add_new_item' => 'Add New '.$singular,
  76. 'new_item_name' => 'New '.$singular.' Name',
  77. 'separate_items_with_commas' => 'Separate '.$plural.' with commas',
  78. 'add_or_remove_items' => 'Add or Remove '.$plural,
  79. 'choose_from_most_used' => 'Choose from the most used '.$plural,
  80. 'not_found' => 'No '.$plural.' found',
  81. 'menu_name' => $plural,
  82. );
  83.  
  84. $args = array(
  85. 'hierarchical' => true,
  86. 'labels' => $labels,
  87. 'show_ui' => true,
  88. 'show_admin_column' => true,
  89. 'update_count_callback' => '_update_post_term_count',
  90. 'query_var' => true,
  91. 'rewrite' => array(
  92. 'slug' => 'year'
  93. )
  94. );
  95.  
  96. register_taxonomy('year', 'speakers', $args);
  97.  
  98. }
  99. add_action('init', 'dwwp_register_taxonomy');
  100.  
  101. function dwwp_add_custom_metabox(){
  102. add_meta_box('dwwp_meta', 'Speakers Description', 'dwwp_meta_callback', 'speakers', 'normal', 'core');
  103. }
  104.  
  105. add_action('add_meta_boxes', 'dwwp_add_custom_metabox');
  106.  
  107. function dwwp_meta_callback( $post ){
  108.  
  109. wp_nonce_field(basename(__FILE__), 'dwwp_speakers_nonce');
  110. $dwwp_stored_meta = get_post_meta($post->ID);
  111. ?>
  112. <div class="meta-th">
  113. <div class="meta-th">
  114. <span>Short Description</span>
  115. </div>
  116. <div class="meta-editor"></div>
  117. <?php
  118. $content = get_post_meta($post->ID, 'short-description', true);
  119. $editor = 'short-description';
  120. $settings = array(
  121. 'textarea_rows' => 5,
  122.  
  123. );
  124. wp_editor($content, $editor, $settings);
  125. ?>
  126. </div>
  127. <div class="meta-th">
  128. <div class="meta-th">
  129. <span>Long Description</span>
  130. </div>
  131. <div class="meta-editor"></div>
  132. <?php
  133. $content = get_post_meta($post->ID, 'long-description', true);
  134. $editor = 'long-description';
  135. $settings = array(
  136. 'textarea_rows' => 10,
  137.  
  138. );
  139. wp_editor($content, $editor, $settings);
  140. ?>
  141. </div>
  142.  
  143. <?php }
  144.  
  145. function dwwp_meta_save($post_id){
  146. $is_autosave = wp_is_post_autosave($post_id);
  147. $is_revision = wp_is_post_revision($post_id);
  148. $is_valid_nonce = (isset($_POST['dwwp_speakers_nonce']) && wp_verify_nonce($_POST['dwwp_speakers_nonce'], basename(__FILE__))) ? 'true' : 'false' ;
  149.  
  150. if ($is_autosave || $is_revision || !$is_valid_nonce){
  151. return;
  152. }
  153.  
  154. if (isset($_POST['short-description'])){
  155. update_post_meta($post_id, 'short-description', sanitize_text_field($_POST['short-description']));
  156. }
  157.  
  158. if (isset($_POST['long-description'])){
  159. update_post_meta($post_id, 'long-description', sanitize_text_field($_POST['long-description']));
  160. }
  161. }
  162. add_action('save_post', 'dwwp_meta_save');
  163.  
  164. <?php
  165.  
  166. /*
  167. ==============================================
  168. Display the speakers in a grid system
  169. ==============================================
  170. */
  171.  
  172. function speakers_grid_display($atts, $content = null){
  173.  
  174. $atts = shortcode_atts(
  175. array(
  176. 'years' => array('2018', '2017', '2016')
  177. ), $atts
  178. );
  179.  
  180. $return_args[] = '<div id="section3">
  181. <div class="animation-element slide slide-left testimonial">
  182. <div class="row text-center">
  183. <h1 class="heading-1">Speakers</h1>
  184. </div>
  185. </div>
  186. <div class="container gal-container">';
  187.  
  188. $args = array(
  189. 'post_type' => 'speakers',
  190. 'orderby' => 'menu_order',
  191. 'order' => 'ASC',
  192. 'post_per_page' => -1,
  193. 'tax_query' => array(
  194. array(
  195. 'taxonomy' => 'year',
  196. 'field' => 'name',
  197. 'terms' => $atts['years']
  198. ),
  199. ),
  200. );
  201.  
  202. $speakers_list = new WP_Query($args);
  203.  
  204. if ($speakers_list->have_posts()):
  205. while ($speakers_list->have_posts()): $speakers_list->the_post();
  206.  
  207. $return_args[] = '<div class="gal-item show_info">
  208. <div class="box" style="background-image: url('.get_the_post_thumbnail_url(get_the_ID()).')">
  209. <div class="overlay">
  210. <div class="text">
  211. <span class="name">'.get_the_title().'</span>
  212. <br />
  213. </div>
  214. </div>
  215. </div>
  216. </div>';
  217.  
  218. endwhile;
  219. endif;
  220.  
  221. $return_args[] = '</div></div>';
  222.  
  223. $args = join($return_args);
  224. return $args;
  225. }
  226. add_shortcode('speakers-grid-display', 'speakers_grid_display');
  227.  
  228. /*
  229. =============================================================
  230. Display speakers with pop ups
  231. =============================================================
  232. */
  233.  
  234. function speakers_popup($atts, $content = null){
  235.  
  236. $atts = shortcode_atts(
  237. array(
  238. 'years' => array('2018', '2017', '2016')
  239. ), $atts
  240. );
  241.  
  242. $return_args[] = '<div id="section3">
  243. <div class="animation-element slide slide-left testimonial">
  244. <div class="row text-center">
  245. <h1 class="heading-1">Speakers</h1>
  246. </div>
  247. </div>
  248. <div class="container gal-container">';
  249.  
  250. $args = array(
  251. 'post_type' => 'speakers',
  252. 'orderby' => 'menu_order',
  253. 'order' => 'ASC',
  254. 'post_per_page' => -1,
  255. 'tax_query' => array(
  256. array(
  257. 'taxonomy' => 'year',
  258. 'field' => 'name',
  259. 'terms' => $atts['years']
  260. ),
  261. ),
  262. );
  263.  
  264. $speakers_list = new WP_Query($args);
  265.  
  266. $i = 1;
  267.  
  268. if ($speakers_list->have_posts()):
  269. while ($speakers_list->have_posts()): $speakers_list->the_post();
  270.  
  271. $return_args[] = '<a href="#" data-target="#div'.$i.'" class="gal-item show_info">
  272. <div class="box" style="background-image: url('.get_the_post_thumbnail_url(get_the_ID()).')">
  273. <div class="overlay">
  274. <div class="text">
  275. <span class="name">'.get_the_title().'</span>
  276. <br />
  277. </div>
  278. </div>
  279. </div>
  280. </a>';
  281.  
  282. $i++;
  283. endwhile;
  284. endif;
  285.  
  286. $return_args[] = '</div></div>';
  287.  
  288. $speakers_list = new WP_Query($args);
  289.  
  290. $i = 1;
  291.  
  292. if ($speakers_list->have_posts()):
  293. while ($speakers_list->have_posts()): $speakers_list->the_post();
  294. $return_args[] = '<div id="div'.$i.'" class="show_speakers_info" style="display:none;">
  295. <div class="profile-header-container">
  296. <div class="profile-header-img">
  297. <img src="'.get_the_post_thumbnail_url(get_the_ID()).'" />
  298. <!-- badge -->
  299. <div class="profile-heading">
  300. <h3 class="heading-2">'.get_the_title().'</h3>
  301. <em>'.get_post_meta(get_the_ID(), "short-description", true).'</em>
  302. </div>
  303. </div>
  304. </div>
  305. <div class="text-justify">
  306. '.get_post_meta(get_the_ID(), "long-description", true).'
  307. </div>
  308. </div>';
  309.  
  310. $i++;
  311.  
  312. endwhile;
  313. endif;
  314.  
  315. $return_args = join($return_args);
  316.  
  317. return $return_args;
  318.  
  319.  
  320.  
  321.  
  322. }
  323. add_shortcode('speakers-popup', 'speakers_popup');
  324.  
  325. <?php
  326. //Add submenu
  327. function dwwp_add_submenu_page(){
  328. add_submenu_page(
  329. 'edit.php?post_type=speakers',
  330. 'Reorder Speakers',
  331. 'Reorder Speakers',
  332. 'manage_options',
  333. 'reorder_speakers',
  334. 'reorder_callback'
  335. );
  336. }
  337. add_action('admin_menu', 'dwwp_add_submenu_page');
  338.  
  339.  
  340. //Reorder speakers
  341. function reorder_callback(){
  342.  
  343. $args = array(
  344. 'post_type' => 'speakers',
  345. 'orderby' => 'menu_order',
  346. 'order' => 'ASC',
  347. 'no_found_rows' => true,
  348. 'update_post_term_cache' => false,
  349. 'post_per_page' => 50
  350. );
  351.  
  352. $speakers_list = new WP_Query($args);?>
  353.  
  354. <div id="speakers-sort" class="sort">
  355. <div id="icon-job-admin" class="icon32"><br/></div>
  356. <h2>Reorder Speakers
  357. <img src = "<?php echo esc_url(admin_url() .'/images/loading.gif'); ?>" alt="loading.gif" id="loading-animation" ></h2>
  358.  
  359. <?php
  360. if ($speakers_list->have_posts()): ?>
  361. <ul id="custom-type-list">
  362. <?php
  363. while ($speakers_list->have_posts()): $speakers_list->the_post();
  364. ?>
  365. <li id="<?php the_id(); ?>">
  366. <?php the_title(); ?>
  367. </li>
  368. <?php endwhile; ?>
  369. </ul>
  370. <?php else: ?>
  371. <p>No Speakers</p>
  372. <?php endif; ?>
  373. </div>
  374.  
  375.  
  376. <?php
  377. }
  378.  
  379. function dwwp_save_reorder(){
  380.  
  381. if (!check_ajax_referer('wp-speakers-order', 'security')){
  382. return wp_send_json_error('Invalid Nonce');
  383. }
  384.  
  385. if (!current_user_can('manage_options')){
  386. return wp_send_json_error( 'You are not allowed to do this.' );
  387. }
  388.  
  389. $order = $_POST['order'];
  390. $count = 0;
  391. foreach( $order as $item_id ){
  392.  
  393. $post = array(
  394. 'ID' => (int)$item_id,
  395. 'menu_order' => $count
  396. );
  397. wp_update_post($post);
  398. $count++;
  399. }
  400.  
  401. wp_send_json_success('Post Saved.');
  402.  
  403. }
  404. add_action('wp_ajax_save_post', 'dwwp_save_reorder');
  405.  
  406. <?php
  407. /*
  408. Plugin Name: Speakers
  409. Plugin URI: Speakers
  410. Author: Speakers
  411. Version: 1.0.0
  412. */
  413.  
  414. if (!defined('ABSPATH')){
  415. exit;
  416. }
  417.  
  418. require ( plugin_dir_path(__FILE__) . 'speakers_custom_post_type.php' );
  419. require ( plugin_dir_path(__FILE__) . 'speakers_custom_meta_box.php' );
  420. require ( plugin_dir_path(__FILE__) . 'speakers_reorder_submenu.php' );
  421. require ( plugin_dir_path(__FILE__) . 'speakers_shortcode.php');
  422.  
  423. function dwwp_admin_enqueue_scripts(){
  424. global $pagenow, $typenow;
  425.  
  426. if ($typenow == 'speakers'){
  427. wp_enqueue_style('dwwp-admin-css', plugins_url('css/style.css', __FILE__));
  428. wp_enqueue_script('dwwp-admin-js', plugins_url('js/style.js', __FILE__), array( 'jquery' , 'jquery-ui-datepicker' ), '1.0.0', true);
  429. }
  430.  
  431. if (($pagenow == 'post.php' || $pagenow == 'post-new.php') && $typenow == 'speakers'){
  432. wp_enqueue_style('dwwp-admin-css', plugins_url('css/style.css', __FILE__));
  433. wp_enqueue_script('dwwp-admin-js', plugins_url('js/reorder.js', __FILE__), array( 'jquery' , 'jquery-ui-datepicker' ), '1.0.0', true);
  434. }
  435.  
  436. if ($pagenow == 'edit.php' && $typenow == 'speakers'){
  437. wp_enqueue_script('dwwp-reorder-admin-js', plugins_url('js/reorder.js', __FILE__), array( 'jquery' , 'jquery-ui-sortable' ), '1.0.0', true);
  438. wp_localize_script('dwwp-reorder-admin-js', 'WP_SPEAKERS_LISTING', array(
  439. 'security' => wp_create_nonce('wp-speakers-order'),
  440. 'success' => __('Speakers sort order has been saved.'),
  441. 'failure' => __('There was an error saving the sort order, or you do not have priviledges')
  442. ));
  443. }
  444. }
  445. add_action('admin_enqueue_scripts', 'dwwp_admin_enqueue_scripts');
Add Comment
Please, Sign In to add comment