wordpress - WP Shortcodes not being added -


i creating wordpress plugin user enters in information, , able generate shortcodes. not quite sure shortcodes supposed go - current setup class-based, , want able create shortcode when ajax request being made, , successful. following 2 methods in same file in class.

this method gets called via admin-ajax.php file:

public static function processajax() {      global $wpdb;     $event_data = $_post['obj'];      $event_title = $event_data[0];     $event_subdomain = $event_data[1];     $result_events = $wpdb->get_results("select * wp_shortcode_plugin subdomain = '{$event_subdomain}'", object);     if (sizeof($result_events)>0) {         echo "duplicate";     } else {         add_shortcode($event_subdomain, 'getembed');         $results = $wpdb->insert('wp_shortcode_plugin', array("event_name"=>$event_title, "subdomain"=>$event_subdomain));         echo json_encode($_post['obj']);     }      die(); } 

and here getembed() method call.

public static function getembed() {     return 'test'; } 

it seems shortcodes not being created, however. missing here? also, possible pass value getembed function add_shortcode() method?

instead of adding shortcode directly ajax, should use update_option store in information shortcode loaded. if option doesn't exist, created.

than simple use wp_init hook load of shortcodes need load in function.php file theme or plugin php file.

you should use get_option within wp_init hook , check values in there. need have function(s) associated shortcodes, can autogenerated in php using create_function or can route them through 1 function (defined in php file) have $atts , $content parameters defined , whatever depending on value of get_option send function.

add_shortcode function should defined within wp_init hook, after checking value of get_option function. need give option name , add via ajax function. option want array, wordpress automatically serialize. use array returned get_option loop through array of shortcodes, , call add_shortcode many times need there. requires setting option array has shortcode tag defined in each index of array. would, personally, make shortcode tag key of array , attributes of shortcode, imo, array of array.

hope helps started on this.


Comments