Ubuntu 18.04LTS apache2 parse php in html

on ubuntu 16.04LTS the following lines added to apache2.conf via IncludeOptional prevent indexing and allow parsing of php in html files

    Options FollowSymLinks
    AllowOverride None
</Directory>

<Directory /var/www/>
    Options -Indexes +FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

AddType application/x-httpd-php .php .htm .html

The same code added on a 18.04LTS server prevent indexing but wont parse php in html.
It’s a long time since I set up the 16.06 Is there a change in 18.04 or am I forgetting something.

Go to Source
Author: FRANK POLAN

Where to find documentation for CPT block template? (PHP)

I have been searching for a day and still carn’t seem to find the right documentation for what arguments I can pass to core components when attempting to configure a CPT block template in php. This is what I have but I want to take this further by nesting buttons and custom html etc. but carnt find the docs I need.

'template' => array(
    array( 'core/columns', array(), array(
        array( 'core/column', array("width" => "60"), array(
            array( 'core/image', array() ),
        ) ),
        array( 'core/column', array("width" => "40"), array(
            array( 'core/image', array() ),
            array( 'core/heading', array(
                'placeholder' => 'Add a inner paragraph'
            ) ),
        ) ),
    )
)       

Found everything needed to create bespoke blocks in JSX but blegh, Not got the time to learn the wizardry ways of JSX just yet and I dont really want new blocks just want the existing one bound as a template to a custom post type.

A good way to example my question, how did this person find the answer on how set the width of this template columns.

How to set column widths in a CPT block template?

How did the person find this answer ? did they have to dive in to the JS scripts of the component and work it out or is there some documentation on this or am I missing something all together.

Any help would be greatly appreciated.

Go to Source
Author: Johnny

WordPress Plugin Development – get_option error

I am trying to put the option on selected with the built in function of wordpress called selected. I have tried to change the key from opt to different key names for every select field and it still didn’t work.

At the moment i am stuck, see my code below:

$taxonomy_args = array(
    'public'    =>  true,
    '_builtin'  =>  false
);

$taxonomy_names = get_taxonomies($taxonomy_args);

$select_field = get_option('select_field');


echo "<form id='example_details' method='post' action''>";
    foreach( $taxonomy_names as $taxonomy_name ) {
        echo "<div class='div_fields'>";
        $taxonomy_name_lc = strtolower($taxonomy_name);
        echo "<label for='${taxonomy_name_lc}_select_field'>${taxonomy_name}</label>";
            echo "<select class='example_form_select' name='details_select_field[opt]' id='${taxonomy_name_lc}_select_field'>";
                echo "<option></option>";
                $terms = get_terms( array( 
                    'hide_empty'    => false,
                    'taxonomy'      => $taxonomy_name
                ) );
                
                foreach ($terms as $term) {
                    echo "<option id='" . $term->name . "' value='" . $term->name . "' " . selected(isset($select_field['opt']), $term->name) . ">" . $term->name . "</option>";
                }


            echo "</select>";
        echo "</div>";
    }
    wp_nonce_field( $this->plugin, 'details_nonce' );
echo "</form>"; 

I did a var_dump on the $select_field variable but that one returns a boolean of false.

Go to Source
Author: Otto

What is the correct way to call a PHP Function with multiple parameters from the AJAX Handler?

Q: What is the correct way to call a PHP Function with multiple parameters from the AJAX Handler?

Q: Am I calling the php function correctly?


Page Element
The user clicks a button.

Action:
The click should connect to an external server using the following params:

  1. User Name 2. IP Address 3. Port 4. Public Key 5. Service

Purpose:
Send an vote string (from host A) to an external Gaming server (host B).
I do not need to update any wordpress content.

WordPress Version: 5.4.1
I put my custom php code into “/wp-contents/plugins/my-plugin/votifier.php”

I made sure the custom plugin is activated.

I have WordPress in Debug mode. i.e. Debug mode is true.

The Button

<div id="frm_field_61_container">
<button type="button">Try it</button>
</div>

WordPress JQuery with AJAX

jQuery(document).ready( function($) {
 $("#frm_field_61_container").click(function(){

      jQuery.ajax({

         type : "post",

         dataType : "json",

         url : myAjax.ajaxurl,

         data : {    action: "my_vote_count"
                    ,username: $('input[name="item_meta[59]"]').val()
                    ,key: $.trim($("#field_yjr62").val())
                    ,ip: $('input[name="item_meta[40]"]').val()
                    ,port: $('input[name="item_meta[42]"]').val()
                    ,service: "Votifier"
                },

        success:    function(data,status,xhr){
                    alert("Data: " + data);
                    alert("Status: " + status);
                    alert("xhr: " + xhr);
                }
      });   
   });
});

My Custom PHP Script

<?php


function mainVotifier($username, $public_key, $server_ip, $port, $service_name) {

define( 'VOTE_FORMAT', 'VOTEn%sn%sn%sn%dn' );
define( 'PUBLIC_KEY_FORMAT', '-----BEGIN PUBLIC KEY-----n%sn-----END PUBLIC KEY-----' );

$key    = wordwrap($public_key, 65, "n", true);
$key    = sprintf(PUBLIC_KEY_FORMAT, $key);


  if (php_sapi_name() !== 'cli') {
            //Detect proxy and use correct IP.
            $address = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
        } else {
            //Script is run via CLI, use server name.
            $address = $_SERVER['SERVER_NAME'];
        }

    $data = sprintf(VOTE_FORMAT, $service_name, $username, $address, time());
    openssl_public_encrypt($data, $crypted, $key);
    $socket = @fsockopen($server_ip, $port);

    if ($socket) {
        if (fwrite($socket, $crypted)) {
            fclose($socket);
            return true;
        }
    }

}

?>

/* ===== WP_ENQUEUE SCRIPTS ==== */

/* ===== JQuery Ajax Script to call votifier.php ==== */
add_action( 'wp_enqueue_scripts', 'my_script_enqueuer' );
function my_script_enqueuer() {

   wp_enqueue_script( 'my_voter_script',  plugins_url('sendvote.js', __FILE__), array( 'jquery'),   '1.0', true);

   wp_localize_script( 'my_voter_script', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));

}

/* ===== My AJAX Handler ==== */

/* add_action( 'wp_ajax_nopriv_my_vote_count', 'my_ajax_handler' ); */ 
add_action( 'wp_ajax_my_vote_count', 'my_ajax_handler');
function my_ajax_handler() {

/*  check_ajax_referer('votifier_response_key'); */

    $username       = $_POST["username"];
    $public_key     = $_POST['key'];
    $server_ip      = $_POST["ip"];
    $port           = $_POST["port"];   
    $service_name   = $_POST["service"];

   echo "mainVotifier("" . $username . "", "" . $public_key . "", "" . $server_ip . "", "" . $port . "", "" . $service_name . "");";


    wp_die(); // All ajax handlers die when finished

}

Console Results

The console results are good, but the other server is not responding.
I tested the PHP code locally from my personal computer and Server B is responding.


Request URL:https://bestminecraftserverlist.com/wp-admin/admin-ajax.php
Request Method:POST
Remote Address:192.169.170.42:443
Status Code:
200
Version:HTTP/2

Go to Source
Author: ScottUSA