Issues calling rest api from a custom plugin javascript

So, I have a custom plugin I’m working on for a WordPress site. I need to make an ajax call when a button is clicked. But when I make the call, nothing happens. So far I got this:

  1. I’ve already registered the rest route like this on the plugin php file:

    register_rest_route( $ base_path, ‘/agencias-all/’, array( ‘methods’ => ‘GET’, ‘callback’ => array( $ this, ‘get_agencias_all_sorted’ ), ));

  2. Got this code on the plugin main js file (which is already enqueued, and the function is available for me on the front end)

    function getAgenciasSorted(){ $ ("#agencias").addClass("loading"); console.log(‘test’);

    $ .get(mypath + ‘agencias-all’).done( response =>{ console.log(‘test 1’);
    console.log(response); }).complete( ()=>{ $ ("#agencias").removeClass("loading"); }) }

And I’m at lost here. The function runs, the console shows the first log "test". But doesn’t shows the second log of "test 1" nor the response. But what’s weird is that if I go to the network tabs in the dev tools, and look for the get_all call, it’s there, and it shows the response there. However, for some reason, it’s not running any code inside the .done

The rest of the api calls are run while the page loads, and those work fine. I’m just struggling to get this one in particular working. Any tips or help would be strongly appreciated, as I’m just starting to work with custom plugins.

Calling RPCs on actors with no owning connection

Is there any easier workaround for calling RPCs from actors that are not owned by a net connection?

Currently, I have a component that is attached to my player controller and some actors in the game world. Whenever I need to send an RPC I pass my player controller component reference to the actor in the game world, it does reroute the RPC to be called from the player controller.

But this way forces me to implement everything in the base component class in case if I needed to inherit.

ODBC Calling Fill – Unexpected closed connection after 2 hours

Using PostgreSQL 12.3 (Ubuntu 12.3-1.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, 64-bit I use driver PostgresSQL Unicode(x64) version 13.00.00.00

I have a query that is executed through an ODBC connection in a Powershell 5.1 script. I use the Fill() method to retreive about 3500 records daily. When the script works, it takes 2-5 minutes to execute and retrieve data when it works. Problem is that the script "fails" half of the time approx. When this occurs, the Powershell script does stop only after 2h and 30 seconds.

We double checked the postgres logs and when this occurs, we see that the query successfully completed within 6 minutes always. I don’t know what to look for. any Idea?

Below is the error got:

Executed as user: NT Service\SQLSERVERAGENT. A job step received an error at line 94 in a PowerShell script. The corresponding line is ‘(New-Object system.Data.odbc.odbcDataAdapter($ cmd)).fill($ ds) | out-null ‘. Correct the script and reschedule the job. The error information returned by PowerShell is: ‘Exception calling "Fill" with "1" argument(s): "The connection has been disabled." ‘. Process Exit Code -1.

Not too familiar with postgreSQL.

Thanks!

Calling a plugin function in a template [closed]

I’m using the WP-property plugin with the import addon. It imports properties from a local MLS. In the property edit screen, it displays the last import time and date in the meta box. I need to display this on the font end. (The plugin docs don’t provide a way to do this).

I found the function that displays this time and date (it is edited to suit my needs for a font-end display). The class name is class_wpp_property_import

      static public function wpp_publish_box_options( $  id ) {     global $  post, $  wp_properties;      if( !$  wpp_import_schedule_id = get_post_meta( $  post->ID, 'wpp_import_schedule_id', true ) ) {       return;     }      //** Get time stamp from new format ( Version 2.6.0+ ) */     $  import_time = get_post_meta( $  post->ID, 'wpp_import_time', true );      //** Get time stamp from old meta_key ( pre-version 2.6.0 ) if new meta_key does not exist */     if( empty( $  import_time ) ) {       $  import_time = get_post_meta( $  post->ID, 'wpp_xml_import', true );     }      if( !empty( $  import_time ) ) {       $  import_time = date_i18n( __( 'M j, Y @ G:i', ud_get_wpp_importer()->domain ), strtotime( $  import_time ) );       ?>        <div class="misc-pub-section xml_import_time misc-pub-section-last">         <span class="wpp_i_time_stamp"><?php printf( __( 'Imported on: <b>%1$  s</b>', ud_get_wpp_importer()->domain ), $  import_time, $  import_url, $  import_name ); ?>           <b></b></span>       </div>     <?php     }    } 

But when I add this (as a shortcode) I get a critical error. I’m using another plugin to create the shortcode easily.

I’ve also tried just using the HTML within the divs (also via shortcode) hoping that the function is firing anyhow, but no go. I’m wondering if it only fires on the backend.

Any help on this? I’ve been at it for a while and I think my brain is fried.

I tried calling the class, still get a critical error:

    class class_wpp_property_import {   static public function wpp_publish_box_options( $  id ) {     global $  post, $  wp_properties;      if( !$  wpp_import_schedule_id = get_post_meta( $  post->ID, 'wpp_import_schedule_id', true ) ) {       return;     }      //** Get time stamp from new format ( Version 2.6.0+ ) */     $  import_time = get_post_meta( $  post->ID, 'wpp_import_time', true );      //** Get time stamp from old meta_key ( pre-version 2.6.0 ) if new meta_key does not exist */     if( empty( $  import_time ) ) {       $  import_time = get_post_meta( $  post->ID, 'wpp_xml_import', true );     }      if( !empty( $  import_time ) ) {       $  import_time = date_i18n( __( 'M j, Y @ G:i', ud_get_wpp_importer()->domain ), strtotime( $  import_time ) );       ?>        <div class="misc-pub-section xml_import_time misc-pub-section-last">         <span class="wpp_i_time_stamp"><?php printf( __( 'Imported on: <b>%1$  s</b>', ud_get_wpp_importer()->domain ), $  import_time, $  import_url, $  import_name ); ?>           <b></b></span>       </div>     <?php     }    }}  

Calling PHP function with AJAX

I am creating a plugin for wordpress for the backend. I when the admin press a button a js function is being called. In this js function, I am calling an API, and then I want to call a PHP with the result and the order id as a parms. so I have done this: action.php

function openpopup($  order_id) {         ?>       <button id="shipping360_create_delivery" data-id= "<?php echo $  order_id?>"              style="background-color: #2e4453; color:#fff; border-radius: 5px;text-align: center;width:100px;height:auto;font-size:10px; line-height: 1.5em;  border: none;-webkit-appearance: none; outline: none; padding:10px;cursor: pointer;">create</button>     <?php             popup($  order_id);      }   add_action('wp_ajax_update_order', 'update_order');   function update_order() {           $  order_id = isset($  _POST['id']) ? $  _POST['id'] : 0;     $  shipping_number = isset($  _POST['shipping_num']) ? $  _POST['shipping_num'] : "";     $  order = wc_get_order($  order_id);      update_post_meta($  order_id, 'shipping_number', $  shipping_number);     $  order->add_order_note($  shipping_number);     die();   }  

the popup function opens a pop-up with the order details. inside the popup function I have a button with the id "create_order" (this function has a lot of HTML and doesn’t really matter – the point is the button). Now for the app.js file

(function ($  ) {  $  (document).ready(function () {         $  ('#close').click(function () { //this is closing the pop-up             document.body.style = "overflow: scroll";              $  ('#order-model').hide();         });         $  ("#createorder").click(function () { /// this is the call for the main function              createDelivery();         });          $  ("#shipping360_create_delivery").click(function () { // this is opening the pop-up             $  ('#order-model').show();             document.body.style = "overflow: hidden;margin: 0;";          })     }) }(jQuery));     function createDelivery() {     // creates new delivery      const URL = BASE + "/shipping";      const distributor = document.getElementById("distributor").value;     const token = document.getElementById("ordertoken").innerHTML;     const companyid = document.getElementById("ordercompanyid").innerHTML;     const direction = "1";     const type = document.getElementById("ordertype").innerHTML;     const order_id = document.getElementById("ordernumber").innerHTML;      if (distributor == "") {         alert("Please fill all fields")     }      else {         senderinfo = "";//have data -- does not really matte         receiverinfo = ""; // have data -- does not really matter         const Data = {             senderinfo: senderinfo,             receiverinfo: receiverinfo,             type: type,             distributor: distributor,             companyid: companyid,             token: token,             direction: direction         }         const otherPram = {             headers: { "Content-Type": "application/json; charset=UTF-8" },             body: JSON.stringify(Data),             method: 'POST'         };         console.log(URL)         fetch(URL, otherPram)             .then(data => {                 return data.json()             })             .then(res => {                 body = res["body"]; //////////////////-----------------------/////////////////////////////// up to this point everything is working fine                 (function ($  ) {                     $  .ajax({                         type: "POST",                         url: ajaxurl,                         cache: false,                         data: {                             'action': 'update_order',                             'id': order_id,                             'shipping_num': body,                         },                         success: function (response) {                             location.reload();                             alert(response);  // not popping up                         },                         fail: function () {                             alert("helllo");  // I have put this and the one below just for checking  // not popping up                         },                         complete: function () {                             alert("hiii") // when I call my function this is that only on the pops up                         }                     });                 })(jQuery);               }).catch(function (error) {                 alert("Got an error:", error);               });       }  }      

Thanks for the help

Calling javascript in javascript works for some but not all scripts [migrated]

I have the following code in a script.js file that I call in my html file:

function loadScript(url) {         var head = document.getElementsByTagName('head')[0];     var script = document.createElement('script');     script.type = 'text/javascript';     script.src = url;     script.async = false;     head.appendChild(script); }  loadScript('https://polyfill.io/v3/polyfill.min.js?features=es6') loadScript('https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js') loadScript('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js')  hljs.initHighlightingOnLoad(); 

I use this code because I want to call only one .js file in my html instead of multiple .js files.

The first two scripts that I load to call MathJax work fine. The third script to call highlight.js however does not run.

When I paste all the code from the file ‘highlight.min.js’ into the my script.js file, the javascript does run normally when I open the html.

I don’t understand why loading the ‘highlight.min.js’ file with the loadScript() does not work, or what I can do to get it to work. Any help is appreciated.

CSRF token not sent when calling the back-end?

My system composes of NuxtJs and AdonisJs application. Adonis handles csrf tokens for us by sending:

set-cookie: adonis-session=XXX; Path=/; HttpOnly set-cookie: XSRF-TOKEN=XXX; Max-Age=7200; Path=/; SameSite=Strict set-cookie: adonis-session-values=XXX; Path=/; HttpOnly 

Now from what I can see, it will set a cookie that can be sent only by a browser. And only if the host is the same. From my understanding, from that point on, browser is the one who will auto attach cookies like that to each request. The problem is, when Nuxt application is making an API request to the back-end I do not see any csrf token being sent when looking at the traffic trough BurpSuite.

And naturally adonis will reply with "Invalid CSRF Token", and respond with status code 500.

I’m not sure what am I missing, I fail to understand why browser is not sending that cookie. And just as the extra information I’ve failed to find it trough browser’s inspector window (Storage tab). Is it possible that the cookie is not set or?

I’ve seen other posts regarding this issue, but they where not helpful because the solution was composed of reading a cookie and manually sending it as the header. Which I do not advise, and is not the model I’m going to implement. I would rather leave it to the back-end framework and browser to do the job for me, because as we all know, there would be less room for me to make a mistake.

Thank you for reading this.

calling a protected method in other packages [closed]

package com.example.sample; public class Test1; {     public enum EncodingFormat     {         _7Bits,_8Bits,Unknown;         protected String tosdkString()         {             switch(this)             {                 case _7Bits: return "7";                 case _8Bits: return "8";             }             return "";         }         static protected EncodingFormat fromString(String source)         {             switch(source)             {                 case "7": return _7Bits;                 case "8": return _8Bits;             }             return Unknown;         }     } } 
package com.example.destination;  import com.example.sample.test1;  public class Test2 extends Test1 {     protected Test2(SDK sdk)     {         m_sdk = sdk;     }      }     private void write(EncodingFormat encodeFormat) throws SdkException, WriteException     {          m_rbasdk.SetParam(PARAMETER_ID.P62_REQ_ENCODING_FORMAT, encodeFormat.tosdkString());     }  } 

Here I am getting error as tosdkString() has protected access in com.example.sample.test1.EncodingFormat. Can some one help me in resolving this issue.

Calling a function that creates records and referencing the created records in a join

I have a function that creates records for different tables that are referenced with each other. The function returns the record from the "parent" table. So I am using that function in the FROM of my query so that I can then perform JOIN on the associated records so that I can piece the tables together. My problem is that the associated records aren’t getting returned and I know for certain that they are getting created.

From what I understand, FROM and JOIN are pretty much executed at the same time so it makes sense that the FROM‘s creation of the records that are used in the JOIN would not exist.

So how can I ensure that the call to the function is executed first before the JOIN is executed? I tried doing this with CTE but no avail.

SELECT   i.invoice_id,   i.invoice_date,   i.invoice_due_date,   i.created_by_id,   i.currency_id,   i.created_at,   si.supplier_info,   bi.billing_info FROM invoices.create_shift_invoice(   CAST(NULLIF($  invoice_date, NULL) AS TIMESTAMP),   CAST(NULLIF($  invoice_due_date, NULL) AS TIMESTAMP),   CAST(NULLIF($  currency_id, '') AS INT8),   CAST(NULLIF($  created_by_id, '') AS INT8),   CAST(NULLIF($  supplier_info, NULL) AS JSONB),   CAST(NULLIF($  billing_info, NULL) AS JSONB),   CAST(NULLIF($  invoice_items_shifts, NULL) AS JSONB) ) i JOIN (   SELECT     _si.invoice_id,     json_build_object(       'supplier_info_id', CAST(_si.supplier_info_id AS VARCHAR),       'invoice_id', CAST(_si.invoice_id AS VARCHAR),       'suppler_name', _si.supplier_name     ) AS supplier_info   FROM invoices.supplier_infos _si ) si USING (invoice_id) JOIN (   SELECT     _bi.invoice_id,     json_build_object(       'billing_info_id', CAST(_bi.billing_info_id AS VARCHAR),       'invoice_id', CAST(_bi.invoice_id AS VARCHAR),       'customer_id', CAST(_bi.customer_id AS VARCHAR)     ) AS billing_info   FROM invoices.billing_infos _bi ) bi USING (invoice_id) 

And here’s my attempt at a CTE:

WITH create_shift_invoice AS (   SELECT *   FROM invoices.create_shift_invoice(     CAST(NULLIF($  invoice_date, NULL) AS TIMESTAMP),     CAST(NULLIF($  invoice_due_date, NULL) AS TIMESTAMP),     CAST(NULLIF($  currency_id, '') AS INT8),     CAST(NULLIF($  created_by_id, '') AS INT8),     CAST(NULLIF($  supplier_info, NULL) AS JSONB),     CAST(NULLIF($  billing_info, NULL) AS JSONB),     CAST(NULLIF($  invoice_items_shifts, NULL) AS JSONB)   ) )  SELECT   i.invoice_id,   i.invoice_date,   i.invoice_due_date,   i.created_by_id,   i.currency_id,   i.created_at,   si.supplier_info,   bi.billing_info FROM create_shift_invoice i LEFT JOIN (   SELECT     _si.invoice_id,     json_build_object(       'supplier_info_id', CAST(_si.supplier_info_id AS VARCHAR),       'invoice_id', CAST(_si.invoice_id AS VARCHAR),       'suppler_name', _si.supplier_name     ) AS supplier_info   FROM invoices.supplier_infos _si ) si USING (invoice_id) LEFT JOIN (   SELECT     _bi.invoice_id,     json_build_object(       'billing_info_id', CAST(_bi.billing_info_id AS VARCHAR),       'invoice_id', CAST(_bi.invoice_id AS VARCHAR),       'customer_id', CAST(_bi.customer_id AS VARCHAR)     ) AS billing_info   FROM invoices.billing_infos _bi ) bi USING (invoice_id)