Thanks Pros
]]>And of no method is available can you add that on future release?
]]>require_once(‘../../../wp-load.php’);
WordPress says that I need to use hooks instead. How do I call wp-load.php using a hook?
They sent me an email saying:
## Calling core loading files directly
Including wp-config.php, wp-blog-header.php, wp-load.php directly via an include is not permitted.
These calls are prone to failure as not all WordPress installs have the exact same file structure. In addition it opens your plugin to security issues, as WordPress can be easily tricked into running code in an unauthenticated manner.
Your code should always exist in functions and be called by action hooks. This is true even if you need code to exist outside of WordPress. Code should only be accessible to people who are logged in and authorized, if it needs that kind of access. Your plugin's pages should be called via the dashboard like all the other settings panels, and in that way, they'll always have access to WordPress functions.
? https://developer.www.ads-software.com/plugins/hooks/
If you need to have a ‘page’ accessed directly by an external service, you should use query_vars and/or rewrite rules to create a virtual page which calls a function.
? https://developer.www.ads-software.com/reference/hooks/query_vars/
? https://codepen.io/the_ruther4d/post/custom-query-string-vars-in-wordpress
If you're trying to use AJAX, please read this:
? https://developer.www.ads-software.com/plugins/javascript/ajax/
]]>What are some of the reasons that can happen? Any help would be highly appreciated.
If you need to take a look at the main plugin file code. Check here
]]>I have never built a WordPress plugin before, so I am not really sure where to start. The first feature I want to add is one that displays a button beneath the heading on single posts that allows users to delete the post if it links to a page that returns a 404 error. This feature is going to be used on aggregators and is intended for instances in which an article is removed from its source.
I have done this in the past by altering themes, but the way I did that depended on functions within the theme. I no longer use those themes and want to achieve the same result using a plugin that I can install on any site.
The next phase will be to add options to restrict which posts display the dead link removal button. That will be done by category and source URL, so if I only wanted to make that feature available for certain categories or where the source is from certain domains I could do that without it impacting other posts.
]]>I tried to make static id for each element or unique identifier but it does not work
I tried also to wrap the functions on PHP/JS with a class and call action functions with instance of that class but it does not work either
I am using “Elementor” if that is related.
Note : I am newbie to WordPress and PHP
This is a sample of my code in the custom plugin : PHP file which is ts.php
<?php
/*
Plugin Name: TS
description: A custom plugin to call and handle AJAX request
Version: 1.0.0
Author: y.w.
*/
function ts()
{
/* creating string variable to hold the content */
$content=''; /* create a string */
$content .='<div id="div_ts_form">';
$content .='<div id="div_ID">';
$content .='<input id="txt_ID" type="text" placeholder="your ID" />';
$content .='</div>';
$content .='<div id="div_btn">';
$content .='<input id="btn_submit" type="submit" name="btn_submit" value="Show Info" />';
$content .='</div>';
$content .='<div id="div_msg" ><mark id="m_msg"></mark></div>';
$content .='</div>';
return $content;
}
add_shortcode('tsform','ts');
/* Include CSS and Script */
add_action('wp_enqueue_scripts','plugin_css_jsscripts');
function plugin_css_jsscripts()
{
// JavaScript
wp_enqueue_script( 'script-js', plugins_url( '/ts.js', __FILE__ ),array('jquery'));
// Pass ajax_url to script.js
wp_localize_script( 'script-js', 'ts_object',
array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}
/* AJAX request */
## Search record
add_action( 'wp_ajax_searchTSList', 'searchTSList_callback' );
add_action( 'wp_ajax_nopriv_searchTSList', 'searchTSList_callback' );
function searchTSList_callback() {
$return = [];
$msg='';
$ts=array();
if( isset($_POST['tsSubmit']) && $_POST['tsSubmit']=='1')// data submission success
{
/*get information form the post submit */
$ID=($_POST['ID'] ?? '');
/* get data from database using CID or NID */
$path = $_SERVER['DOCUMENT_ROOT'];
include_once $path . '/pioneer/wp-load.php';
include_once $path . '/pioneer/wp-config.php';
$db = new mysqli(DB_HOST, DB_USER,DB_PASSWORD, DB_NAME); //connect to database
// Test the connection:
if (mysqli_connect_errno())// Connection Error
{
$msg=("**Couldn't connect to the database: ".mysqli_connect_error());
$return['success']=0;
$return['message']=$msg;
}
else //connection success
{
//query the database
$sql='';
$sql = "SELECT Full_Name,Type,Status,Note FROM Individual WHERE ID ='" . $ID ;
}
$result = $db->query($sql);
//get the result
$rowsNo=$result->num_rows;
if ( $rowsNo > 0) {
$en_data = array();
while($row = $result->fetch_assoc())// output data of each row
{
$ts[] = array( 'Name' => $row['Full_Name'],'Type' => $row['Type'], 'Status' =>$row['Status'], 'Note' => $row['Note']);
}
$msg .= $rowsNo . ' records are found.'; //record the number of records found
}else {
$msg.='**No records are found!';
}
//close connection to db
$db->close();
/* return info for the user */
$return['success']=1;
$return['message']=$msg;
$return['rows']= $ts;
}
}else // data submission error
{
$msg='**Your data was not submitted ! ';
$return['success']=0;
$return['message']=$msg;
}
echo json_encode($return,JSON_FORCE_OBJECT);
wp_die();
}
and this is the Script File : ts.js
jQuery(document).ready(function($){
// AJAX url
var ajax_url = ts_object.ajax_url;
// Search record
$('#btn_submit').click(function(){
var ID = $("#txt_ID").val();
if ( !validateID(ID))
{
return false; //exit process inputs
}
// Fetch filtered records (AJAX with parameter)
var data = {
'tsSubmit':'1',
'action': 'searchTSList',
'ID': ID
};
$.ajax({
url: ajax_url,
type: 'post',
data: data,
success: function(data){
// Add new rows to table
createmsg(data)
}
});
});
// validate ID
function validateID(ID)
{
//blank or empty or null or whitespace
if(!$.trim(ID))
{
$("#div_msg").css('display','block');
$("#m_msg").text('**You must enter your ID !');
return false;
}
//not digit
if(/\D/g.test(ID ))
{
$("#div_msg").css('display','block');
$("#m_msg").text('**You must enter digit ID !');
return false;
}
//not valid len
var validLen= 10;
if(ID.length != validLen)
{
$("#div_msg").css('display','block');
$("#m_msg").text('**You must valid length ID !');
return false;
}
return true;
}
// Add response object
function createmsg(data)
{
var jdata = JSON.parse(data);
if( jdata.success == 1) //submission sucess
{
$("#m_msg").text(jdata.message);
$("#div_msg").css('display','block');
}else //submission failed
{
var mess ='';
mess = '**Your information has not been submitted! ';
$("#div_msg").css('display','block');
$("#m_msg").text(mess);
}
}
});
]]>I would like to know whether there is anyway (either through custom code or free / paid plugins) that would enable me to customize my woocommerce estimated delivery dates based on each variable product’s attributes. Been trying to find high and low, but can’t seem to find any suitable ones.
For example, if I have a product that comes in 2 different colors, I would like to set different estimated delivery dates for each of the colors.
Thanks!
]]>I would like to know if I can buy a plugin and then ask a developer to customize its code to expand it’s functionality and meet my business requirements.
Is this legal?
What about safety? I was reading that if I do this, when the plugin gets updated the customization changes may be lost. But can’t I simply create my own custom plugin by copy/pasting the code from an existing plugin and use that as a base to start writing more code on top to build my plugin?
If the original plugin has some vulnerability, when hackers scan my website, they will not find that plugin but instead a custom one, so would that make it more secure because they know nothing about this plugin?
Or they scan for functions/scripts within the plugin?
I hope my questions are not too stupid… sorry if they are.
]]>