PluginProbe
Page & Post Notes / 1.3.3
Page & Post Notes v1.3.3
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 / include / insert-to-db.php

insert-to-db.php in Page & Post Notes 1.3.3, at include/insert-to-db.php

106 lines 4.3 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 if( isset($_POST['yydev_notes_nonce']) ) {
5
6 if( wp_verify_nonce($_POST['yydev_notes_nonce'], 'yydev_notes_action') ) {
7
8 include('settings.php');
9
10 // ====================================================
11 // Checking if this is a category/tags post or regular page/post
12 // ====================================================
13
14 if( isset($_POST['yydev_notes_page_id']) ) {
15 $page_id = intval($_POST['yydev_notes_page_id']);
16 } // if( isset($_POST['yydev_notes_page_id']) ) {
17
18 // ====================================================
19 // Add seo data to the database
20 // ====================================================
21
22 if( isset($page_id) ) {
23
24 // Checking if the data id exists
25 global $wpdb;
26 $check_database_exists = $wpdb->query("SELECT * FROM " . $table_name . " WHERE page_post_id = $page_id ");
27
28 // sanitize the data
29 $class_direction = $_POST['yydev_direction_class'];
30 $table_notes_post = $_POST['yydev_notes'];
31
32 $notes_count = count($table_notes_post);
33 $table_notes_data = '';
34 $table_notes_comain = '';
35
36 // converting the data and combine it
37 for ($i = 0; $i <= $notes_count; $i++) {
38
39 if( isset($table_notes_post[$i]) ) {
40
41 $table_notes_data_note = $table_notes_post[$i];
42 $table_notes_data_direction = $class_direction[$i];
43 $table_notes_comain .= $table_notes_data_note;
44
45 if( !empty($table_notes_data_note) ) {
46
47 if($i > 0) {
48 $table_notes_data .= "###";
49 } // if($i > 0) {
50
51 $table_notes_data .= $table_notes_data_note . "^^" . $table_notes_data_direction;
52 } // if( !empty($table_notes_data_note) ) {
53
54 } // if( isset($table_notes_post[$i]) ) {
55
56 } // for ($i = 0; $i <= $notes_count; $i++) {
57
58 $table_notes = sanitize_textarea_field($table_notes_data);
59 $notes_id = intval($_POST['yydev_notes_id']);
60
61 // checking if the notes are empty or not
62 if( empty($table_notes_comain) ) {
63 $there_is_data_here = 1;
64 } // if( empty($table_notes_comain) ) {
65
66 // adding the data into the database
67 if( $check_database_exists == 0 ) {
68
69 // if the post doesn't exists in the database we will
70 // make sure there is data and then we will insert it
71 if( !isset($there_is_data_here) ) {
72
73 // if the data not exists on the database insert new one
74 $wpdb->insert( $table_name,
75 array('page_post_id'=>$page_id,
76 'notes'=>$table_notes,
77 ), array('%d', '%s') );
78
79 } // if( !isset($there_is_data_here) ) {
80
81 } else { // if( $check_database_exists == 0 ) {
82
83 // If the current page data exists in the database we will update it
84 if( !isset($there_is_data_here) ) {
85
86 $wpdb->update( $table_name,
87 array('page_post_id'=>$page_id,
88 'notes'=>$table_notes,
89 ), array('page_post_id'=>$page_id), array('%d', '%s') );
90
91 } else { // if( !isset($there_is_data_here) ) {
92
93 // if there are no data at all (in notes and date as well) we will remove the line from the database
94 $wpdb->delete( $table_name, array('id'=>$notes_id) );
95
96 } // if( !isset($there_is_data_here) ) {
97
98 } // } else { // if($check_database_exists == 0 ) {
99
100 } // if( isset($page_id) ) {
101
102 } // if( wp_verify_nonce($_POST['yydev_notes_nonce'], 'yydev_notes_action') ) {
103
104 } // if( isset($_POST['yydev_notes_nonce']) ) {
105
106 ?>