mardi 2 novembre 2021

wordpress create modal popup based on post id

i have a plugin which creates a modal popup on the front page. currently i am hard coding the id of the post into the details because i have struggled to get the id of that specific post. i have managed to find the id but it only finds the correct id within the modal_add_custom_box function. i need to use the value for $id in the display_modal function. any ideas?

<?php
add_theme_support( 'post_thumbnail' );
add_post_type_support( 'modal', 'thumbnail' );

// modal Custom Post Type
function modal_init() {
  // set up modal labels
  $labels = array(
      'name' => 'Modal',
      'singular_name' => 'Modal',
      'add_new' => 'Add New Modal',
      'add_new_item' => 'Add New Modal',
      'edit_item' => 'Edit Modal',
      'new_item' => 'New Modal',
      'all_items' => 'All Modals',
      'view_item' => 'View Modals',
      'not_found' =>  'No Products Found',
      'not_found_in_trash' => 'No Products found in Trash',
      'parent_item_colon' => '',
      'menu_name' => 'Modal',
  );

  // register post type
  $args = array(
      'labels' => $labels,
      'public' => true,
      'has_archive' => true,
      'show_ui' => true,
      'capability_type' => 'post',
      'hierarchical' => false,
      'query_var' => true,
      'menu_icon' => 'dashicons-randomize',
      'supports' => array(
          'title',
          'thumbnail',
          'page-attributes',
      )
  );

  register_post_type( 'Modal', $args );
}
add_action( 'init', 'Modal_init' );

register_post_type( $post_type, $args );

//add meta box

function Modal_add_custom_box() {
  $screens = [ 'Modal' ];
  foreach ( $screens as $screen ) {
      add_meta_box(
          'Modal_box',                 // Unique ID
          'Modal Info',      // Box title
          'Modal_custom_box_html',  // Content callback, must be of type callable
          $screen                            // Post type
      );
  }
}
add_action( 'add_meta_boxes', 'Modal_add_custom_box' );

function Modal_custom_box_html() {
  //check if values are in database, if they are display them in the backend form
  $headline = get_post_meta(1408, 'headline', true);
  $sub_headline = get_post_meta(1408, 'sub_headline', true );
  $button_text = get_post_meta( 1408, 'button_text', true );
  $destination_url = get_post_meta(1408, 'destination_url', true);
  $id = get_the_ID();

  if(empty($headline)){
    $headline_display = "";
  }else{
    $headline_display = $headline;
  }
  if(empty($sub_headline)){
    $sub_headline_display = "";
  }else{
    $sub_headline_display = $button_text;
  }
  if(empty($button_text)){
    $button_text_display = "";
  }else{
    $button_text__display = $button_text;
  }
  ?>
  <P>
    If fields are left empty, nothing will display on modal box for that field
  </P>


  <div class="user-cont" id="user-cont">
    <div class="input-group">
      <label for="headline_field">Headline</label>
      <input type="text" name="headline" id="headline" value="<?php echo $headline_display; ?>"></input>
    </div>
    <div class="input-group">
      <label for="sub_headline_field">Sub-Headline</label>
      <input type="text" name="sub_headline" id="sub_headline" value="<?php echo $sub_headline_display; ?>"></input>
    </div>
    <div class="input-group">
      <label for="button_text_field">Button-Text</label>
      <input type="text" name="button_text" id="button_text" value="<?php echo $button_text; ?>"></input>
    </div>
    <div class="input-group">
      <label foor="desination">Destination URL</label>
      <input type="text" name="destination_url" id="destination_url"></input>
    </div>
    <div class="input-group checkbox">
      <label for="URL_tab">Open URL in new tab?</label>
      <select name="URL_tab">
        <option name="yes" id="yes">yes</option>
        <option name="no" id="no">no</option>
      </select>
    </div>
    <div class="input-group">
      <label for="date_live">date popup to go live</label>
      <input type="date" name="date_live" id="date_live"></input>
    </div>
    <div class="input-group">
      <label for="date_close">date popup to close</label>
      <input type="date" name="date_close" id="date_close"></input>
    </div>
    <div class="input-group">
      <input type="text" name="id" id="id" value="<?php echo $id; ?>"></input>
    </div>
  </div>

  <?php
  return $id;
}

//save meta data


function Modal_save_meta_box( $post_id ) {
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
  if ( $parent_id = wp_is_post_revision( $post_id ) ) {
      $post_id = $parent_id;
  }




  $fields = [
      'headline',
      'sub_headline',
      'button_text',
      'date_live',
      'date_close',
      'destination_url',
      'URL_tab',
      'yes',
      'no',
      'id'
  ];

  foreach ( $fields as $field ) {
      if ( array_key_exists( $field, $_POST ) ) {
          update_post_meta( $post_id, $field, sanitize_text_field( $_POST[$field] ) );
      }
   }
}

  add_action( 'save_post', 'Modal_save_meta_box' );

//display custom field on front page

function display_modal(){
$post_id = get_the_ID();
$headline = get_post_meta(1408, 'headline', true);
$sub_headline = get_post_meta(1408, 'sub_headline', true );
$button_text = get_post_meta( 1408, 'button_text', true );
$destination_url = get_post_meta(1408, 'destination_url', true);
$selected_yes = get_post_meta(1408, 'url_tab', true);
$featured_image =  wp_get_attachment_image_src( get_post_thumbnail_id( 1408 ));


if($selected_yes == 'yes'){
  $url_target= 'target="_blank" ';
}else{
  $url_target= 'target="_self" ';
}

echo $post_id;

?>

<div class="modal style-accent-bg <?php echo $color_opacity; ?>" id="modal">
  <button class="close" id="close"></button>
  <div class="img">
    <img src="<?php echo $featured_image[0]; ?>" class="modal_image">
  </div>
  <div class="details">
    <h1><?php echo $headline; ?></h1>
    <h2><?php echo $sub_headline; ?></h2>
    <p>



    </p>
    <a href="<?php echo $destination_url ?>" <?php echo $url_target ?>class="button-link btn btn-default color-accent-color style-color-gyho-bg"><?php echo $button_text;?></a>
  </div>
</div>
<?php

}


function check_page(){
  if(is_front_page()){
    display_modal();
  }else{
    ;
  }
}
?>



Disable a button until the user clicks on a check box | JavaScript

I'd love to achieve that the button below the User-Id is disabled until the user agrees with the rules for the game by clicking on a checkbox. I already have a code which was sent by a friend. But my problem is that it doesn't work on the actual page. I assume it doesn't because the JS-Script isn't connect correctly in the HTML script. How do I connect correctly the script?

Here’s the code of JavaScript:

function input(event) {
    const checked = document.getElementById("startgame").checked;
    const button = document.getElementById("startbutton");

    if (checked) {
        button.disabled = false;
        return;
        alert("Herzlichen Glückwunsch! Sie haben sich erfolgreich angemeldet. Das Spiel beginnt, sobald sie den Knopf betätigen.")
    } else

        button.disabled = true;
    alert("Es tut us leid. Jedoch müssen Sie zuerst unsere Regeln akzeptieren.")
}

Here’s my HTML script:

            <div class="quiz-menu" data-aos="fade-up" data-aos-duration="3000">
            <div class="rules">
                <h1 class="rules-title"><i class="fas fa-scroll"></i>&nbsp;RULES!</h1>
                <p class="rules-text">
                    <center>
                        <b>
                            Damit das Quiz Ihnen nicht zu einfach gemacht wird; gibt es ein paar Regeln. Lesen Sie diese bitte durch:
                        </b>
                    </center>
                </p>
                <p class="rules-list">
                    1. Hilfsmittel (wie z.B. Websiten) werden blockiert;
                    <br>
                    <br />
                    2. Sie haben <i>alle Zeit der Welt</i>. Überstressen Sie sich also nicht und denken sie mit Ruhe nach.
                    <br><br />
                    3. Seien Sie nicht enttäuscht, wenn sie fehler haben. Sie können diesen Test jeder Zeit wiederholen -
                    und sich verbessern.
                </p>
            </div>
            <div class="user-id">
                <div class="user-background" data-aos="flip-down" data-aos-duration="3000">
                    <h2 class="user-title">USER-ID</h2>
                    <p class="user-text">
                        Damit Sie unseren Highscore auch richtig nutzen können,
                        bitten wir sie, dass sie sich einen Usernamen ausdenken.
                    </p>
                    <form action="/action_page.php" class="quizform">
                        <label for="nname" class="formtext"><b>Nickname:</b></label><br>
                        <input type="text" id="fname" name="nname" value="Dein Username">
                        <br><br />
                        <input type="checkbox" id="startgame" name="startgame" value="startgame">
                        <label for="startgame"> Um das Spiel zu starten, muss du die Checkbox ankreuzen</label><br>
                        <br>
                    </form>
                </div>
            </div>
            <div>
                <a href="kategorieeins.html" class="quiz-button" id="startbutton"><span><i class="fas fa-play"></i>&nbsp;&nbsp;quiz starten</span></a>
            </div>
        </div>



How can i open and run a project in laravel that isnt mine?

I have to comment and optimize a Laravel project that is made by the previous back end developer that was at the firm im working at. The problem is that i am a junior developer and i dont really know where to check for it. I donwgraded my php version because it required php 7.2.5 or 7.3. I changed the .env db name, host, etc and migrated all the migrations. But it still doesnt work. What should i check next? and where? Its a big project for a consulting website.

it cant connect to the database i think, like i get a white page, no frontend loaded at all, i will paste here the env and a ss to the database:


APP_NAME=your-consult
APP_ENV=local
APP_KEY=base64:93DE6wrEWKiM8q2EtC6TanandzVydkkFPNeSRqYBbeE=
APP_DEBUG=false
APP_URL=http://localhost:8000
APP_API_URL=http://localhost:8000


LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=admin_yourconsultdb
DB_USERNAME=root
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=your-consult.com
MAIL_PORT=465
MAIL_USERNAME=no-reply@your-consult.com
MAIL_PASSWORD=TestareYouCo1@
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=no-reply@your-consult.com
MAIL_FROM_NAME=Your-Consult.Com

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

MIX_URL=http://localhost:8000
MIX_API_URL=http://localhost:8000/api
MIX_API_STORAGE=http://localhost:8000/storage
MIX_ASSETS=assets

MIX_STRIPE_PUBLIC_KEY=pk_live_51HKjElD55LzIx6Do5Cf5tRoklBwZ6DCpo3iA15zN7tDJFTAnOqjAfpgcRwn5apeaYO7Z6iidg3U8QaN6UjW3PLfI001nPJzryy
MIX_STRIPE_SECRET_KEY=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
SUCCESS_URL=https://your-consult.com/comanda-finalizata
CANCEL_URL=https://your-consult.com/comanda-nefinalizata
EURO_VAL=5
PAYMENT_REFERENCE=false

JWT_SECRET=BrDqF6W8G5zkchvFOVIHXmtkRu0n30B1YnwyJWFuObzf8UPRdq7WpDPFozqgHo8i

COMPANY_VAT_CODE=39382763

SERIES_NAME=YC
SERIES_NAME_PROF=PROF
CURRENCY=RON
LANGUAGE=RO

DOCUSIGN_USERNAME=sales@your-consult.com
DOCUSIGN_AUTH_PATH=account.docusign.com
DOCUSIGN_URL=https://eu.docusign.net/restapi
DOCUSIGN_INTEGRATOR_KEY=c2c2099a-0565-407d-826e-dc80a94eae0c
DOCUSIGN_API_ACCOUNT_ID=8c4086f6-d3ab-4d9b-b92d-669a9c2e7433
DOCUSIGN_API_USERNAME=79e0084e-5e71-4de1-b900-4fd8ad7afb7e


TWILIO_AUTH_TOKEN=9a93920b0615907945b31249266c4b1b
TWILIO_ACCOUNT_SID=AC71d96e6a926df0c039acabcfdaad9b23
TWILIO_PHONE_NUMBER=+14439988274

NETOPIA_MOBILPAY_PAYMENT_URL=https://secure.mobilpay.ro
NETOPIA_MOBILPAY_PUBLIC_CERT=live.68FY-TQUB-RU29-67WK-HBGD.public.cer
NETOPIA_MOBILPAY_PRIVATE_KEY=live.68FY-TQUB-RU29-67WK-HBGDprivate.key

BITPAY_PRIVATE_KEY_PATH=bitpay.pri
BITPAY_PUBLIC_KEY_PATH=bitpay.pub
BITPAY_NETWORK=livenet
BITPAY_KEY_STORAGE_PASSWORD=Lamunca123
BITPAY_TOKEN=5WgNp6eNogQXyMYBs5GdSBZ5ePcP7thViD4ZGLZ285Ah

CREATIVE_SMS_TOKEN=I2kPdRTL3pvtH9oX1A25E9vztKvR1U3D4Atx9nmyjVJcceH7fbEjilM1rIhf




the database image




Redirect in chrome responsive simulator changing user agent

When I do a request to a page that returns a 302 redirect in the chrome responsive simulator I see a new request with a different user agent string.

Here you see the user-agent with 'Android 7.1.1' enter image description here enter image description here

Here the user-agent string is changed. enter image description here




Someone facing Indusft Web Studio 8.1 Mobile Access Task DOWN?

I deploy in an apache server a mobile access project, after accesing from local network using an iphone12 is ok but when trying to open the screens or the trends the mobile access go off




flutter Web) User model cannot be uploaded to firestore after signup

I'm going to upload the user model to the database after signing up as a member through firebase Auth on the flutter web. If sign up, I can register well with Firebase Auth. However, after that, an error is output while uploading to the database.

pubspec.uaml

    environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  firebase_core: ^0.5.0 #웹을 위해 추가?
  firebase_auth: ^0.18.0 #0.16.1
  cloud_firestore: ^0.14.0 #0.13.7
  firebase_storage: ^4.0.0 #3.1.6
  flutter_web_frame: ^0.0.2 #웹에서 최대 사이즈를 지정해주는 패키지
  carousel_slider: ^3.0.0
  get: ^3.3.0
  cached_network_image: ^2.2.0+1
  provider: ^4.3.3

auth and firestore code

    class Transformers {
  //DocumentSnapshot -> UserModel Transform
  final toUser = StreamTransformer<DocumentSnapshot, UserModel>.fromHandlers(
    handleData: (snapshot, sink) async {
      sink.add(UserModel.fromSnapShot(snapshot));
    }
  );
}


class UserNetworkRepo with Transformers{
  //When signing up, check if user model is registered in the firestore and upload if not.
  Future<void> attempCreatUser({String userKey, String userEmail}) async {
    final DocumentReference userRef =
    FirebaseFirestore.instance.collection(COLLECTION_USERS).doc(userKey);

    //get user document
    DocumentSnapshot snapshot = await userRef.get();
    //check user database
    if (!snapshot.exists) {
      return await userRef.set(UserModel.getMapForCreatUser(userEmail));
    }
  }

  Stream<UserModel> getUserModelStream(String userKey) {
    return FirebaseFirestore.instance
        .collection(COLLECTION_USERS)
        .doc(userKey)
        .snapshots()
        //documentSnapshot data -> UserNodel
        .transform(toUser);
  }

During the debug, the StreamTransformer brakes and then outputs the following errors.

TypeError: Cannot read properties of null (reading 'Symbol(dartx._get)')
at user_model.UserModel.fromSnapShot.user_model.UserModel.fromMap (http://localhost:65386/packages/omd_test/model/user_model.dart.lib.js:103:42)
at new user_model.UserModel.fromSnapShot (http://localhost:65386/packages/omd_test/model/user_model.dart.lib.js:113:34)
at http://localhost:65386/packages/omd_test/repo/helper/transformer.dart.lib.js:36:18
at Generator.next (<anonymous>)
at runBody (http://localhost:65386/dart_sdk.js:40666:34)
at Object._async [as async] (http://localhost:65386/dart_sdk.js:40697:7)
at http://localhost:65386/packages/omd_test/repo/helper/transformer.dart.lib.js:35:137
at _HandlerEventSink.new.add (http://localhost:65386/dart_sdk.js:39044:11)
at _SinkTransformerStreamSubscription.new.[_handleData] (http://localhost:65386/dart_sdk.js:38869:34)
at _RootZone.runUnaryGuarded (http://localhost:65386/dart_sdk.js:40429:11)
at _ForwardingStreamSubscription.new.[_sendData] (http://localhost:65386/dart_sdk.js:33989:22)
at _ForwardingStreamSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:33935:26)
at _ForwardingStreamSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:38197:20)
at _MapStream.new.[_handleData] (http://localhost:65386/dart_sdk.js:38328:19)
at _ForwardingStreamSubscription.new.[_handleData] (http://localhost:65386/dart_sdk.js:38225:37)
at _RootZone.runUnaryGuarded (http://localhost:65386/dart_sdk.js:40429:11)
at _ForwardingStreamSubscription.new.[_sendData] (http://localhost:65386/dart_sdk.js:33989:22)
at _ForwardingStreamSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:33935:26)
at _ForwardingStreamSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:38197:20)
at _HandleErrorStream.new.[_handleData] (http://localhost:65386/dart_sdk.js:38403:19)
at _ForwardingStreamSubscription.new.[_handleData] (http://localhost:65386/dart_sdk.js:38225:37)
at _RootZone.runUnaryGuarded (http://localhost:65386/dart_sdk.js:40429:11)
at _ForwardingStreamSubscription.new.[_sendData] (http://localhost:65386/dart_sdk.js:33989:22)
at _ForwardingStreamSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:33935:26)
at _ForwardingStreamSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:38197:20)
at _MapStream.new.[_handleData] (http://localhost:65386/dart_sdk.js:38328:19)
at _ForwardingStreamSubscription.new.[_handleData] (http://localhost:65386/dart_sdk.js:38225:37)
at _RootZone.runUnaryGuarded (http://localhost:65386/dart_sdk.js:40429:11)
at _BroadcastSubscription.new.[_sendData] (http://localhost:65386/dart_sdk.js:33989:22)
at _BroadcastSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:33935:26)
at _SyncBroadcastStreamController.new.[_sendData] (http://localhost:65386/dart_sdk.js:34655:34)
at _SyncBroadcastStreamController.new.add (http://localhost:65386/dart_sdk.js:34449:24)
at http://localhost:65386/packages/cloud_firestore_web/src/interop/utils/utils.dart.lib.js:367:22
at Object._checkAndCall (http://localhost:65386/dart_sdk.js:5586:16)
at Object.dcall (http://localhost:65386/dart_sdk.js:5591:17)
at Object.ret [as next] (http://localhost:65386/dart_sdk.js:62759:21)
at Object.next (https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js:1:320206)
at next (https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js:1:303665)
at https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js:1:244953
[2021-11-02T07:24:18.188Z]  @firebase/firestore:

I'm making the web and the app together, the app works well. Can I know the problem with this?

Thank you.




Spotify like, LIKE BUTTON in Notification Bar with MEDIA SESSION API in web

There are limited properties to setActionHandlers(). eg- Play pause, seekForward....

I want to add a like button apart from limited to play, pause, seekForward... in the notification bar of my web music player.

Similar, to Spotify Like Button in the Notification bar along with Media Controls......in web May be with Media Session Api

IMAGE