* * @return none */ function awtw_install() { global $awtw_plugin_version; // Run SQL Query to create a new Table Awtw_DB::createTable(); // Add plugin version to Options table in WordPress add_option( "awtw_plugin_db_version", $awtw_plugin_version ); // Default settings $args = array( 'awtw_label_text' => __('What should we write about next?', 'awtw_plugin'), 'awtw_min_length' => 10, 'awtw_num_entry' => 10, 'awtw_post_content' => 1 ); // store in Options table update_option('awtw_options',$args); } /** * When plugin is activated run awtw_install() */ register_activation_hook( __FILE__, 'awtw_install' ); function plugin_settings_page( $links ) { $settings_link = ''.__( 'Settings', 'awtw_plugin' ).''; array_unshift( $links, $settings_link ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'plugin_settings_page' ); /************************************************************************************/ /* Plugin form HTML */ /************************************************************************************/ function awtw_plugin_html() { $options = get_option('awtw_options'); $form_html = '
'; return $form_html; } /** * Attach Form HTML after post content. * * @version 1.0 * @since AWTW 1.0 * @author Ritesh Sanap * * @param string $post * @return string */ function awtw_plugin_html_content($post){ if(is_single()){ $form_html = awtw_plugin_html(); return $post.$form_html; } return $post; } $options = get_option('awtw_options'); // get Options /** * If Attach to post content is enabled. * add the filter. */ if(isset($options['awtw_post_content'])) { add_filter('the_content','awtw_plugin_html_content'); } /************************************************************************************/ /* AJAX script */ /************************************************************************************/ add_action('wp_enqueue_scripts','awtw_feedback_scripts'); function awtw_feedback_scripts(){ if(is_single()){ /* Get Options */ $options = get_option('awtw_options'); if(!is_array($options)) $options = array(); extract($options); $plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)); wp_enqueue_script('awtw-feedback-js', "$plugin_url/awtw-ajax.js", array('jquery')); //Set params for JS $params = array('url' => admin_url( 'admin-ajax.php' ).'/awtw-ajax.php', 'minLenght' => $awtw_min_length); wp_localize_script( 'awtw-feedback-js', 'awtw_params', $params); wp_enqueue_style('awtw-feedback-css', "$plugin_url/awtw.css"); } } function awtw_plugin_ajax() { $output =' '; return $output; } add_action('wp_enqueue_scripts', 'awtw_plugin_ajax'); /************************************************************************************/ /* Admin Page Registration */ /************************************************************************************/ add_action('admin_menu','awtw_feedback_add_options'); function awtw_feedback_add_options(){ add_menu_page('Advanced What to write', 'What to Write', 'administrator', 'awtw-feedback-options', 'awtw_feedback_options_page'); } function awtw_feedback_save_options($args){ update_option('awtw_options',$args); } function awtw_feedback_options_page(){ echo '
'; echo '

'; _e('Advanced What to write next ?', 'awtw_plugin'); echo '

'; echo '
'; } /************************************************************************************/ /* AWTW Styling CSS */ /************************************************************************************/ /** * Admin panel CSS * * @version 1.0 * @since AWTW 1.0 * @author Ritesh Sanap * * @return string */ function awtw_table_style() { ?> * * @return none */ function awtw_ajax() { $action = $_POST['actions']; $id = $_POST['id']; switch ($action) { case 'mark_spam': // send as Spam Awtw_Akismet::submit($id, 'spam'); break; case 'mark_approve': // send as a HAM Awtw_Akismet::submit($id, 'ham'); break; case 'mark_pending': // Mark as pending Awtw_DB::statusUpdate($id, 0); break; case 'delete': // Function for delete Awtw_DB::delete($id); break; } } /************************************************************************************/ /* Handle request sent by AJAX from front end */ /************************************************************************************/ function awtw_ajax_front() { global $wpdb; $tablename = $wpdb->prefix. 'awtw_plugin'; /** * When nonce is verified, store all the data in the database and * then Send it to Akismet to check whether it is spam or not. */ if( wp_verify_nonce($_POST['awtw-feedback-nonce']) ) { $feedback = $_POST['awtw-feedback-msg']; $source_url = $_SERVER['HTTP_REFERER']; $ip_address = $_SERVER["REMOTE_ADDR"]; $user_agent = $_SERVER["HTTP_USER_AGENT"]; if(!empty($feedback)) { /** * Insert all the data into the database. */ $rows_affected = $wpdb->insert( $tablename, array( 'ip_address' => $ip_address, 'source_url' => $source_url, 'agent' => $user_agent, 'created_at' => current_time('mysql'), 'status' => 0, 'feedback' => stripslashes_deep($feedback), ) ); $result = Awtw_Akismet::check($wpdb->insert_id); // Check if it is SPAM ! echo $result; //return true; die(); } // End if !empty() return false; } // End if WP_verify_nonce() } /** * Add AJAX action for front end AJAX script */ add_action( 'wp_ajax_awtw_ajax_front', 'awtw_ajax_front' ); add_action( 'wp_ajax_nopriv_awtw_ajax_front', 'awtw_ajax_front' ); /************************************************************************************/ /* Load Files */ /************************************************************************************/ // Load all SQL queries require_once('awtw-sql.php'); //Load Admin Table to display feedback require_once('awtw-table.php'); // Load Akismet require_once('awtw-akismet.php'); /************************************************************************************/ /* THE END. Thank you for everything */ /************************************************************************************/ ?>