PluginProbe
Page & Post Notes / trunk
Page & Post Notes vtrunk
trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5
page-post-notes / index.php

index.php in Page & Post Notes trunk, at index.php

159 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?>
2 <?php
3 /*
4 Plugin Name: YYDevelopment - Page & Post Notes
5 Plugin URI: https://www.yydevelopment.com/yydevelopment-wordpress-plugins/
6 Description: Simple plugin that allow you to notes on pages and posts
7 Version: 1.3.5
8 Author: YYDevelopment
9 Author URI: https://www.yydevelopment.com/
10 */
11
12 include_once('include/settings.php');
13 require_once('include/functions.php');
14
15 // ================================================
16 // Creating Database when the plugin is activated
17 // ================================================
18
19 function yydev_notes_create_database() {
20
21 require_once('include/install.php');
22
23 } // function yydev_notes_create_database() {
24
25 register_activation_hook(__FILE__, 'yydev_notes_create_database'); // run on plugin update
26
27 // ================================================
28 // display the plugin we have create on the wordpress
29 // post blog and pages
30 // ================================================
31
32 // function that will output the code to the page
33 function yydev_notes_output_plugin($term) {
34
35 include('include/style.php');
36 include('include/script.php');
37 include('include/admin-output.php');
38
39 } // function yydev_notes_output_plugin() {
40
41 function yydev_notes_register_meta_boxes() {
42 add_meta_box( 'yydev_notes', 'Page Notes', 'yydev_notes_output_plugin',null ,'side');
43 } // function yydev_notes_register_meta_boxes() {
44
45 add_action( 'add_meta_boxes', 'yydev_notes_register_meta_boxes' );
46
47 // ================================================
48 // Adding the comments to the dashboard page
49 // ================================================
50
51 // function that will output the code to the page
52 function yydev_notes_output_plugin_dashbaord($term) {
53
54 $yydev_notes_active_dashbaord = 1;
55
56 include('include/style.php');
57 include('include/script.php');
58 include('include/admin-output.php');
59
60 } // function yydev_notes_output_plugin() {
61
62 function yydev_notes_dashboard_widgets() {
63 wp_add_dashboard_widget('yydevelopment_notes', 'Dashboard Notes', 'yydev_notes_output_plugin_dashbaord');
64 } // function yydev_notes_dashboard_widgets() {
65
66 add_action('wp_dashboard_setup', 'yydev_notes_dashboard_widgets');
67
68 // ================================================
69 // function that will insert the code to the database
70 // once the post or page is updated
71 // ================================================
72
73 function yydev_notes_insert_to_database( $post_id ) {
74
75 // Check if user has capability to edit this specific post
76 if ( ! current_user_can( 'edit_post', $post_id ) ) {
77 return;
78 }
79
80 // Verify nonce
81 if ( ! isset( $_POST['yydev_notes_nonce'] ) || ! wp_verify_nonce( $_POST['yydev_notes_nonce'], 'yydev_notes_action' ) ) {
82 return;
83 }
84
85 include('include/insert-to-db.php');
86
87 } // function yydev_notes_insert_to_database() {
88
89 add_action('pre_post_update', 'yydev_notes_insert_to_database');
90
91 // ================================================
92 // ajax function to save the data in the database
93 // ================================================
94
95 function yydev_notes_save_dashboard_data() {
96
97 // Check if user has capability to edit posts/pages
98 if ( ! current_user_can( 'edit_posts' ) ) {
99 wp_send_json_error( array( 'message' => 'You do not have permission to perform this action.' ) );
100 wp_die();
101 }
102
103 // Verify nonce for CSRF protection
104 if ( ! isset( $_POST['yydev_notes_nonce'] ) || ! wp_verify_nonce( $_POST['yydev_notes_nonce'], 'yydev_notes_action' ) ) {
105 wp_send_json_error( array( 'message' => 'Security check failed.' ) );
106 wp_die();
107 }
108
109 // If this is for a specific page/post (not dashboard), verify user can edit that specific post
110 if ( isset( $_POST['yydev_notes_page_id'] ) && intval( $_POST['yydev_notes_page_id'] ) > 0 ) {
111 $page_id = intval( $_POST['yydev_notes_page_id'] );
112
113 // Check if user can edit this specific post/page
114 if ( ! current_user_can( 'edit_post', $page_id ) ) {
115 wp_send_json_error( array( 'message' => 'You do not have permission to edit notes for this page.' ) );
116 wp_die();
117 }
118 }
119
120 include('include/insert-to-db.php');
121 echo "Saved";
122 wp_die();
123
124 } // function yydev_notes_save_dashboard_data() {
125
126 add_action( 'wp_ajax_yydev_notes_save_dashboard_data', 'yydev_notes_save_dashboard_data' ); // create ajax function we can call with javascript
127 // Removed nopriv action - only logged in users with proper capabilities should access this
128 // add_action( 'wp_ajax_nopriv_yydev_notes_save_dashboard_data', 'yydev_notes_save_dashboard_data' );
129
130 // ================================================
131 // Add donate page to the plugin menu info
132 // ================================================
133
134 add_filter( 'plugin_action_links', function($actions, $plugin_file) {
135
136 static $plugin;
137
138 if (!isset($plugin)) { $plugin = plugin_basename(__FILE__); }
139
140 if ($plugin == $plugin_file) {
141
142 $admin_page_url = esc_url( menu_page_url( 'page-post-notes', false ) );
143 $donate = array('donate' => '<a target="_blank" href="https://www.yydevelopment.com/coffee-break/?plugin=page-post-notes">Donate</a>');
144
145 $actions = array_merge($donate, $actions);
146
147 } // if ($plugin == $plugin_file) {
148
149 return $actions;
150
151 }, 10, 5 );
152
153 // ================================================
154 // including admin notices flie
155 // ================================================
156
157 if( is_admin() ) {
158 include_once('notices.php');
159 } // if( is_admin() ) {