Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. <?php
  2. defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
  3. define( 'MY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
  4. define( 'MY_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
  5. register_activation_hook(__FILE__,'my_plugin_install');
  6. register_deactivation_hook( __FILE__, 'my_plugin_remove' );
  7. function my_plugin_install() {
  8. global $wpdb;
  9. $the_page_title = 'TEST';
  10. $the_page_name = 'test';
  11. delete_option("my_plugin_page_title");
  12. add_option("my_plugin_page_title", $the_page_title, '', 'yes');
  13. delete_option("my_plugin_page_name");
  14. add_option("my_plugin_page_name", $the_page_name, '', 'yes');
  15. delete_option("my_plugin_page_id");
  16. add_option("my_plugin_page_id", '0', '', 'yes');
  17. $the_page = get_page_by_title( $the_page_title );
  18. if ( ! $the_page ) {
  19. $_p = array();
  20. $_p['post_title'] = $the_page_title;
  21. $_p['post_content'] = "";
  22. $_p['post_status'] = 'publish';
  23. $_p['post_type'] = 'page';
  24. $_p['comment_status'] = 'closed';
  25. $_p['ping_status'] = 'closed';
  26. $_p['post_category'] = array(1);
  27. $the_page_id = wp_insert_post( $_p );
  28. }
  29. else {
  30. $the_page_id = $the_page->ID;
  31. $the_page->post_status = 'publish';
  32. $the_page_id = wp_update_post( $the_page );
  33. }
  34. delete_option( 'my_plugin_page_id' );
  35. add_option( 'my_plugin_page_id', $the_page_id );
  36. }
  37. function my_plugin_remove() {
  38. global $wpdb;
  39. $the_page_title = get_option("my_plugin_page_title");
  40. $the_page_name = get_option("my_plugin_page_name");
  41. $the_page_id = get_option('my_plugin_page_id');
  42. if( $the_page_id ){wp_delete_post( $the_page_id );}
  43. delete_option("my_plugin_page_title");
  44. delete_option("my_plugin_page_name");
  45. delete_option("my_plugin_page_id");
  46. }
  47. function custom_template($template){
  48. $template = plugin_dir_path( __FILE__ ) . 'my-custom-page.php';
  49. return $template;
  50. }
  51. if ( !is_admin() ) {
  52. if ( have_posts() ) {
  53. while ( have_posts() ) {
  54. the_post();
  55. if(get_the_ID() == get_option('my_plugin_page_id')){
  56. add_filter( 'template_include', 'custom_template' );
  57. }
  58. }
  59. }
  60. }
  61. ?>
  62.  
  63. Fatal error: Call to a member function have_posts() on a non-object in /var/www/html/wordpress/wp-includes/query.php on line 782
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement