How do I handle the "WP_Customize_Cropped_Image_Control" callback?

I want to make a logo manager in the Customizer, but how do I set different image sizes with the WP_Customize_Cropped_Image_Control class? Example from Make WordPress Core: $wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'cropped_image', array( 'section' => 'background_image', 'label' => __( 'Croppable Image' ), 'flex_width' => true, // Allow any width, making the specified value recommended. False by default. 'flex_height' => false, // Require the resulting image to be exactly as tall as the height attribute (default). 'width' => 1920, 'height' => …
Category: Web

Classifier with a single 1 value per year

Let's say I want to find the probabilities of winning the best movie category in the Oscars. I know to following rules: There is only 1 winner per year. Logically, the sum of the predicted probabilities for each year should add up to be 1. I can have a year feature in my classifier but that does not mean that 1 and 2 are enforced. If I use a simple classifier like logistic regression I also don't see how having …
Category: Data Science

Display featured image of post type category

I inherited a website that had a significant number of customized PHP files. I have removed many since, however, this is one of the few that still seemed relevant. The code below displays 1 image at random from a particular post type (gallery) in the website footer. There was only one post type category prior to me working on the website. Now I have added more gallery categories, but the footer is displaying images from all categories. How can I …
Category: Web

Cannot use WordPress Application Passwords: "code": "rest_no_route" "status":404 for /wp-json/wp/v2/users/me/application-passwords

I am trying to use Application Passwords on Wordpress 5.9 for the development of a client app. The page https://www.example.com/wp-admin/authorize-application.php shows the Application Passwords confirmation prompt, but if I click generate "Approve the connection" for the app, an error is shown: "No Path provides a match between the URL and the requested method." I also tried to GET the path "/wp-json/wp/v2/users/me/application-passwords?_locale=user" that is supposed to answer the request, but it says 404 error. The base path for wp api works …
Category: Web

Custom regularisation for logistics regression

My understanding of l2 regularisation: Weights of the model are assumed to have a prior guassian distribution centered around 0. Then MAP estimate over data adds an extra penalty in cost function. My problem statement: I am making a reasonable assumption(based on domain knowledge) that my features are independent which means I can use the weights of the features to infer the importance of features in influencing Y. From domain knowledge, I want to assume priors about the ratio of …
Category: Data Science

Prevent users to delete comments from trash

As told in the title, I am looking for a way to prevent users to delete comments from the trash. Only admins should be able to. I tested the scripts at: Function to prevent users from trashing comments But it doesn't work, probably since 2013 a few things have changed :) Thank you for help!
Category: Web

Dynamic Sections

I'm trying to build a page which has three filters. What I want to achieve is that some sections on the page change depending on what filters the user will choose. Can somebody help me out with this? I'm either looking for a plugin (can be paid) or some explanation about how to implement some custom code. GOAL: have users choose filters and based on the filters some sections on the page will change. Usability: The feature should be implemented …
Category: Web

Scaling and handling highly correlated features in tabular data for regression

I am working on a regression problem trying to predict a target variable with seven predictor variables. I have a tabular dataset of 1400 rows. Before delving into the machine learning to build a predictor, I did an EDA(exploratory data analysis) and I got the below correlation coefficients (Pearson r) in my data. Note that I have included both the numerical predictor variables and the target variable. I am wondering about the the following questions: We see that pv3 is …
Category: Data Science

Adding machine learning classifier at the end of CNN layer

I wanted to use the CNN as feature extractor for my images and then fed these features to some machine learning classifiers such as SVM, decision tree and KNN. However when I was trying with SVM I got this error message: File "C:\Users\Afef-\Anaconda3\lib\site-packages\sklearn\svm\base.py", line 521, in _validate_targets " class" % len(cls)) ValueError: The number of classes has to be greater than one; got 1 class This is my code : import os import numpy as np from sklearn.metrics import confusion_matrix …
Category: Data Science

Only admin should run wordpress plugin shortcode

I have created a simple plugin that locks down content for users not logged in and it is working fine. However any user on a multi-author site could use the same short code in his post to lock down content too. I do not want this to happen. How may I restrict this functionality to administrators only? This current code thows up a fatal error:Fatal error: Call to undefined function wp_get_current_user() public function check_user_role() { if(current_user_can( 'activate_plugins' )) { return …
Category: Web

redirect after submiting post for review

I have a frontend page that allows "Tutor Instructor" role, to create a course and this course is a custom type post called courses, when the Tutor Instructor finishes creating the course he must click submit for review. when he clicks that button, the page will refresh and change the link to the editing link of the course (https://**************.com/dashboard/create-course/?course_ID=13865). I want when the Tutor Instructor clicks submit for review the page redirects him to another page for example (https://**************.com/thank-you). How …
Category: Web

Custom Loop and Infinite Scroll

I am using customized version of _s theme where I have Product CPT. In the following files, I need to use Infinite scroll (provided by Jetpack) - archive-products.php taxonomy-[tax-name].php home.php archive.php Now, the problem is most of these templates use custom loop (using WP_Query which ends with pagination after while()). I have used following code in functions.php after activating jetpack and Photon module - function vg_infinite_scroll_init() { add_theme_support( 'infinite-scroll', array( 'container' => 'page-content', 'footer' => 'page', 'type' => 'click', 'render' …
Category: Web

String together a set of tokens into a sequence

I have this problem scenario - Given a set of tokens, string them or a subset of the tokens together using stop words into a sequence. I am clear that I can have potentially infinite pre-training data for this problem. For example, given the set of tokens {cat, jump, mouse} - possible outputs might be: a. the cat jumped on a mouse, b. the cat and the mouse jumped, c. cats jump and so on... I am not sure if …
Category: Data Science

How to disable edit post option?

I have a WordPress LMS site, and the Tutor Instructor role can create posts as courses and these posts are custom post types called courses, and I want to disallow the Tutor Instructor to edit their courses after they publish them. I saw this How to disable edit post option after period of time? It doesn't work. I changed the role to Tutor Instructor and made it 1 hour but still not working, maybe because the post type is not …
Category: Web

What's the difference between home_url() and site_url()

My understanding is that site_url() returns the location where the WordPress core files are. If my blog is hosted at http://example.com/blog then site_url() returns http://example.com/blog But then how does home_url() differ? For me, home_url() returns the same thing: http://example.com/blog If that's correct, then can I get WordPress to return http://example.com/ ?
Category: Web

WooCommerce product permalink changed

my product structure was like the following before: https://example.com/producto/product-name/ Now, I've done some updates to the translations and this is how the product urls appear now: https://example.com/product/product-name/ (without the 'o' in product) It's actually OK to me, but on my shop page the URLs kept the final 'o', redirecting to 404 my products. How can I fix this?
Category: Web

Optimal input setup for character-level text classification RNN

I want to classify 500-character long text samples as to whether they look like natural language using a character-level RNN. I'm unsure as to the best way to feed the input to the RNN. Here are two approaches I've thought of: Provide the whole 500 characters (one per time step) to the RNN, and predict a binary class, $\{0,1\}$. Provide shorter overlapping segments (e.g. 10 characters) and predict the next (e.g. 11th) character. Convert this to classification by taking the …
Category: Data Science

Insert Custom Post Types

I am learning WordPress plugin development. I need to insert Custom Post Type. I registered custom post type using register_post_type(). I am getting below Form when I would like to insert a New Csutom Post Types (News). How can I customize this Form ? I would like to add some radio buttons and text fields here.
Category: Web

Custom Fields - How to create a list from multi-line entries of a single value

If I have the following name/value pair for a custom field.... ...is there a PHP loop process I can apply that will allow me to display them on the front-end as individual values because there is a line-break between each item? or do I have to create multiple name/value pairs for each item? The end goal in my case is to create a list on the front end of these items that are being pulled from this value area. Thanks …
Category: Web

cannot import name 'LSHForest' from 'sklearn.neighbors'

from sklearn.neighbors import NearestNeighbors, LSHForest ImportError: cannot import name 'LSHForest' from 'sklearn.neighbors' I came to know that LSHForest is depreciated. So how can use it. do we have any other alternative. I'm using Sklearn version 1.0.1
Topic: scikit-learn
Category: Data Science

How to remove Base URL Duplication?

I have an issue in the download link, the URL getting duplicate. Like this http://localhost/test/files/http://localhost/test/files/2016/05/testonly.docx same as the live website: http://www.homecredit.ph/wp-content/uploads/home1/homecre1/public_html/files/News-26.jpg, the URL messed up How to fix this? I didn't add anything in the .htaccess .htaccess: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /test/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /test/index.php [L] </IfModule> # END WordPress Here's the code for download link: functions.php function upload_user_file($file = array()){ require_once(ABSPATH . 'wp-admin/includes/admin.php'); $file_return = …
Category: Web

How to resample

I have to deal with a small dataset. I thought that I maght take advantage of resamplin methods to enlarge the population and improve the performance of my regression algorithm. I heard about SMOTE, but it is used for classification in imbalanced datasets. Is there any method to create synthetic data of a small size dataset? Thanks.
Category: Data Science

How to optimize Pandas DataFrame reorganizing?

I have a DataFrame which looks like this: date person value 2022-05-01 A 5 2022-05-01 B 4 2022-05-02 A 5 2022-05-02 B 9 I want to convert it to that form: date person A person B 2022-05-01 5 4 2022-05-02 5 9 I have implemented that code to colve the task: raw_data = ... # data in the original form people = raw_data["person"].unique() dates = raw_data["date"].unique() new_data = pd.DataFrame(columns=people, index=dates) for person in people: for date in dates: new_data.loc[date, person] …
Category: Data Science

wp_insert_user always tries the same user name

The page name with my form is "Register", which means the slug is "register". That is the first piece of info that is tied to my theory about my error. When I run wp_insert_user I get a success the first time, but the user name is "register". So subsequent submissions try to create the user "register", so it errors out with a "User with that user name exists" error. I've checked my data over and over again to verify that …
Category: Web

focal loss function help

I am working on a relation extraction and classification problem. The data is in the form of text files. The data is imbalanced. I want to use focal loss function to address class imbalance problem in the data. My question is: Can focal loss be utilized for extraction and classification task to increase the accuracy? Focal loss has been applied on object detection task and for image classification task. The link is below. I want to use this on text …
Category: Data Science

Custom post type archive pagination with HTML5Blank theme?

Can't get the pagination to work. Here's my archive-work.php: <?php get_header(); ?> <main role="main"> <!-- section --> <section> <h1><?php _e( 'Work', 'html5blank' ); ?></h1> <?php get_template_part('loop', 'work'); ?> <?php get_template_part('pagination'); ?> </section> <!-- /section --> </main> <?php get_sidebar(); ?> <?php get_footer(); ?> loop-work.php: <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $work = array( 'post_type' => 'work' ,'numberposts' => -1 ,'posts_per_page' => 2 ,'paged' => $paged ); $loop = new WP_Query( $work ); if ($loop->have_posts()): while ($loop->have_posts()) : $loop->the_post(); ?> …
Category: Web

How plugins_loaded works?

I am developing a plugin for woocommerce payment gateway. When I put the code of class definition inside the callback function who is fired by 'plugins_loaded',it works. <?php add_action('plugins_loaded','WC_test_gateway_plugin'); function WC_test_gateway_plugin{ class my_gateway extends WC_Payment_Gateways{ //code } } ?> But when I put it into global scope, it will show that the WC_Payment_Gateways is undefined. <?php class my_gateway extends WC_Payment_Gateways{ //code } ?> What's the difference between these 2 practices? Is it a bad practice to put class definition inside …
Category: Web

What is the reason behind the minimum image size in the Keras InceptionResNetV2 model?

In Keras' documentation for the InceptionResNetV2 model, it says the following: input_shape: (...). It should have exactly 3 inputs channels, and width and height should be no smaller than 139. I'm trying to figure out the reason behind the minimum size of 139px for this model, because I'm looking to train this model on smaller images (128px for starters). I can't find any clues in the model's source code or in the paper which describes the model. Assuming this number …
Category: Data Science

Place image caption outside of figure tag (Gutenburg Image Markup)

I format my single.php images to a perceived 3:2 ratio like this: <figure style="position:relative; width:100%; padding-bottom:66%;"> <img style="position:absolute; width:100%; height:100%; object-fit:cover;"> <figcaption>some text</figcaption> </figure> With Gutenberg, this sticks my caption behind my image or on top of my image (if I position figcaption relative or absolute). I'd like it to be below my image. Before gutenberg, I could customize my image markup. No longer can. Now I am trying to figure out how to make my image caption the next …
Category: Web

wp_nav_menu doesn't seem to work on custom post type pages

I'm working on something someone else set up, and on the index page, the nav appears, but on custom post type pages, it does not. The nav menu: wp_nav_menu([ 'menu' => 'Primary Menu', 'theme_location' => 'primary', 'depth' => 3, 'container' => 'div', 'container_class' => 'a', 'container_id' => 'b', 'menu_class' => 'nav navbar-nav', 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', 'walker' => new wp_bootstrap_navwalker() ]); I've seen it suggested that I place this in a function and use an if statement to do something and …
Category: Web

HuggingFace Transformers is giving loss: nan - accuracy: 0.0000e+00

I am a HuggingFace Newbie and I am fine-tuning a BERT model (distilbert-base-cased) using the Transformers library but the training loss is not going down, instead I am getting loss: nan - accuracy: 0.0000e+00. My code is largely per the boiler plate on the [HuggingFace course][1]:- model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=3) opt = Adam(learning_rate=lr_scheduler) model.compile(optimizer=opt, loss=loss, metrics=['accuracy']) model.fit( encoded_train.data, np.array(y_train), validation_data=(encoded_val.data, np.array(y_val)), batch_size=8, epochs=3 ) Where my loss function is:- loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True) The learning rate is calculated like so:- lr_scheduler …
Category: Data Science

Word-level text generation with word embeddings – outputting a word vector instead of a probability distribution

I am currently researching the topic of text generation for my university project. I decided (ofc) to go with a RNN getting a sequence of tokens as input with a target of predicting the next token given the sequence. I have been reading through a number of tutorials and there is one thing that I am wondering about. The sources I have read, regardless of how they encode the X sequences (one-hot or word embeddings), encode the y target tokens …
Category: Data Science

Visualization with many lines, colors, and markers

I have a bunch of plots as the one reported below. The data is from measurements performed on different times and different days. In the plot (which is a cumulative distribution function, if that matters), the colors differentiate data relevant to different days; the markers are used to further differentiate the data within each day. The problem is that the plot is very crowded and a bit ugly. Some markers can be barely seen. Question: Any idea how I can …
Category: Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.