I am creating a like system in PHP . My code looks like this . <?php class Like_System { private $userid; private $postid; private $user_ko_like_count; private $post_ko_like_count; private $user_ko_dislike_count; private $post_ko_dislike_count; private $user_ip; public function __construct(){ } public function our_ajax_script(){ wp_enqueue_script( 'sb_like_post', get_template_directory_uri().'/data/js/post-like.min.js', false, '1.0', 1 ); wp_localize_script( 'sb_like_post', 'ajax_var', array( 'url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'like_system' ) ) ); } public function load_our_ajax_script(){ add_action( 'init', array($this,"our_ajax_script") ); add_action( 'wp_ajax_nopriv_like_system',array($this,"like_dislike_kernal")); add_action( 'wp_ajax_like_system',array($this,"like_dislike_kernal")); } public function verify_nonce($nonce){ if …
I am allowing Authors to delete their posts on the front end as they cant access the admin. I have this working, but what bothers me is the standard javascript onclick alert message - is there are way to style a js alert? From my understanding, no. Or to use jQuery for the message and use a modal window that I can style? Also, after deletion the user is returned to the same page which is good, but there is …
Thanks to some wonderful help here at stack exchange, I have built a comment section with a dropdown menu that adds comment_meta to the comments. I currently have a working filter that uses GET to trigger an if statement to query based on this comment_meta info. The thing I don't like is that it refreshes the page each time you click a button. I'm looking for a way to filter without having the page refresh. I think I need Javascript …
I'm running WordPress 6.0 and using the Block Editor to enable content editors to paste links that generate the embed/iframe preview, as described here. I've noticed from time to time (i.e. erratically) the embed script doesn't seem to run, and the link remains as static text without converting into the iframe preview. I'm also using Swup.js to handle page transitions throughout the site, and I'm wondering if wp-embed has a method of some kind that I can hook into to …
Hello Wordpress Developers. I create my own plugins, and I'm stuck about how to call php functions inside class, into javascript ajax functions. For example we have button with ID name clickme: <button id="clickMe">Click Me</button> And then I make a class with functions, example like this: <?php class myFunctions{ function a(){ $test = "Hello World from wp_send_json()"; wp_send_json($test); } } ?> and then I want to output the test variable, using ajax. Example like this: import $ from "jquery"; class …
I'm trying to create a dropdown selector on my CPT and CT archive page for a custom taxonomy called "location". I've managed to get the form to submit, however, it does not direct me to the archive page, rather it directs me to a URL that looks something like this https://example.com/?location=11 I'm wanting the destination URL to be this: https://example.com/location/term-name Bare with me as I have no background in Computer Science / IT so I'm learning on my own. Below …
I'm using the following JS code to open a wp.media window to allow users to select images and videos for a gallery. Everything is working as expected, but I'm unable to restrict the window to show images and videos only, it's showing everything. Any ideas on what might be wrong? Thanks in advance JS: $( '#add_item' ).on( 'click', function( e ) { var $el = $( this ); e.preventDefault(); // If the media frame already exists, reopen it. if ( …
I'm developing some custom blocks in the new Gutenberg editor experience, and I'm struggle to understand how to use some build-in components, mostly the Draggable components. What I would like to achieve is a list of items (let's say many li in a ul) and I want them to be orderable with a drag & drop feature. Here is my code: import { __ } from '@wordpress/i18n'; import { registerBlockType } from '@wordpress/blocks'; import { Draggable, Dashicon } from '@wordpress/components'; …
I have been trying to implement the translation to a couple of strings in a .js file but nothing has worked. First try to do it like I do in php, in the .js file add this variable var __ = wp.i18n.__; and I put the strings like __( 'Hello World', 'text-domain'), but it didn't work. After looking for information about it, I found a post where they talk about passing the translated strings with wp_localize_script something like that. // …
I'm trying to create a new panel in the edit-post sidebar (Wordpress Gutenberg), I already managed to set the panel with the title and the text in the content part but I need to add a button there and no I find a way to do it. var registerPlugin = wp.plugins.registerPlugin; var PluginDocumentSettingPanel = wp.editPost.PluginDocumentSettingPanel; // var btn = wp.element.createElement( 'button' ); var el = wp.element.createElement; var __ = wp.i18n.__; /* I tried to do it with a function, but …
I'm a noob. I have copied the header.php from the parent theme, I have added some snippets and things work. However, I would like to be able to add those same snippets either using a plugin or via functions.php so when/if the theme is updated, I don't need to redo everything. I've tried many things but none of them work. I wonder if the problem is where the snippets are placed by using a plugin or that the HTML element …
I need a hook or some way to detect when the window to select the file to upload is opened. I'm talking about the window that opens the browser to select the local files to upload. Context: On occasions, WordPress itself or some plugins directly open a window to select the local file to upload, without going through the WordPress library. I have a plugin that gives a custom path when uploading files and I need to launch a popup …
Short description: I try to translate strings in JS file. To test it I decided to create a simple test plugin. I have PHP and JS strings there. Translated PHP strings work fine, JS strings don't work. Tools and environment: WP-CLI 2.4.0 Wordpress 5.5.1 Ubuntu 20.04 Original languange: English (United States) Translate language: German Plugin PHP file content: <?php /* * Plugin Name: Test * Text Domain: test * Domain Path: /languages */ /** * Init all */ function run() …
I'm having a hard time figuring out why my repeatable fields javascript doesn't work. I'm using the following plugin: Rhyzz (repeatable-fields): http://www.rhyzz.com/repeatable-fields.html. I scraped the website and I see he ran the script inside html and also ran his javascript all on the same page. My website is a lot larger. I'm using Wordpress and I did the following to call the script in functions.php. wp_enqueue_script( 'jquery', 'https://code.jquery.com/jquery-1.11.2.min.js', array(), '20120206', true ); wp_enqueue_script( 'jquery-ui', 'https://code.jquery.com/ui/1.11.4/jquery-ui.min.js', array(), '20120206', true ); wp_enqueue_script( …
I am currently using Wordpress, and an element of user_registered returns the time of registration of the user. I have set the correct timezone, but don't know how to get the user_registered output to match my current time. So far, this is what I have. date_default_timezone_set('America/Los_Angeles'); $users = get_users(); foreach( $users as $user ) { $udata = get_userdata( $user->ID ); $registered = $udata->user_registered; printf( '%s member since %s<br>', $udata->data->display_name, date( "Y-m-d H:i:s", strtotime( $registered ) ) ); } echo('date below …
i have script.js file for html to wordpress conversion. In html it works, but in wordpress it does not work. This file contains slider, menus etc, I enable to convert html to wordpress without this file, the file has following contents function include(scriptUrl) { document.write('<script src="' + scriptUrl + '"></script>'); } function isIE() { var myNav = navigator.userAgent.toLowerCase(); return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false; }; /* cookie.JS ========================================================*/ include('js/jquery.cookie.js'); /* Easing library ========================================================*/ include('js/jquery.easing.1.3.js'); /* Stick up menus …
I'm making a plugin with a class and methods. This class gets called through the theme ( hard coded ) to enqueue and localize my js. it also prepares it for ajax. However, i keep getting ERROR: 400 POST http://www.devsite.local/wp-admin/admin-ajax.php 400 (Bad Request) I've ran ajax outside of a class in multiple plugins and at the functions.php with no issues, but i can't get it to work inside a class. This is my code: class CCYTFeatured { public function __construct(){ …