how can allow standalone page access wordpress functions without including/requiring wp_load or wp_config?
i developing plugin , need allow access wp database on standalone php page. page curl request returns full html page display. context, plugin list of jobs api need link full job ad (a full html page).
the code have (in jobad.php page):
$root = dirname(dirname(dirname(dirname(dirname(__file__))))); if (file_exists($root.'/wp-load.php')) { require_once($root.'/wp-load.php'); } this code pulled every answer have found on how accomplish this. including wordpress.org's own forums. stackoverflow answer, example: using wpdb in standalone script?
it works fine, when tried submit plugin wp directory, plugin rejected including wp_load.php in way. makes sense why not to, cannot find other way make file work within wordpress.
the outcome need
from list generated shortcode, each item has link return full html page. html page returned curl response--not url (or have each link drive iframe). context, building link way
$job_ad_link = plugins_url( 'includes/jobad.php' , dirname(__file__) ); $job_id = //id database; <a href="'.$job_ad_link.'?sgjobid='.$job_id.'">link</a> thus calling jobad.php run curl function correct job_id , display curl response. can run curl ajax , avoid problem, because full html page, cannot return curl in div. in iframe awkward , iffy , rather not use (and have had no success in trying).
for clarification, response wordpress:
including wp-config.php, wp-blog-header.php, wp-load.php, or pretty other wordpress > core file have call directly via include not idea , cannot > approve plugin unless has reason load file(s). > prone failure since not wordpress installs have exact same file structure.
i implemented couple of plugins provides ajax responses , needed able access wordpress functions php script. solved including wp_config.php file until core developer pointed out, how solve correctly.
as way not limited ajax calls, use render page facebook app, need have access wordpress functions. here how (just put functions.php or small plugin):
function full_job_ad_page() { global $wpdb; // how access database // ever want ability access wordpress functions. // asuming 1 item option, get_option $value_from_db = get_option( 'curl_value' ); // asuming value in other table, use $wpdb function $value_from_db = $wpdb->get_var( 'select value table' ); // include curl file echoing response include( plugin_dir_path( __file__ ) . 'curl-script.php' ); die(); // required return proper result } add_action( 'wp_ajax_full_job_ad_page', 'full_job_ad_page' ); add_action( 'wp_ajax_nopriv_full_job_ad_page', 'full_job_ad_page' ); than can use such url response function:
http://example.com/wp-admin/admin-ajax.php?action=full_job_ad_page
note: action in url has match end of first parameter of action hooks (the string after wp_ajax_ , wp_ajax_nopriv_).
Comments
Post a Comment