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

kmerhing on "e-mail sending page in Ninja form"

$
0
0

I'm using Ninja forms Version 2.9.56.2 and am wondering how I include the page the form is used on.
I'm using the same form on several different pages and need to know which page the form was used on. Any help would be appreciated.


janbrokes on "NExt and previous post links with #anchor"

$
0
0

HEllo this is part of code of previous link

$previous_post_link = get_previous_post_link( '%link', '<span class="meta-nav">' . esc_html( _x( '&larr;', 'Previous post link', 'et_builder' ) ) . '</span> ' . $previous_link_text, $in_same_term, '', $current_taxonomy );

I need to add at the end of url #anchor

so that link of previous post looks like http://www.domain.com/prev-post1/#anchor

Thansk in advance

Taro on "Search result based on menu category"

$
0
0

Hi All,

i'm looking for two pieces of code that can help me with the following:

I got posts and pages with a custom menu. These posts/pages got a custom template activated. The templates contains the menu for the specific posts and pages. This way i can order pages/posts in two different categories.

Now i like to change the search function; the search output should be based on the active custom menu category.

I named menu 1: Benelux and menu 2: International

1: First peace of code needs to be for the searchform.php
The code should look at the current active menu(category) and the search result should be based on the active menu.

If the menu is for example "Benelux" then the search result should only display pages/posts from the custom taxonomy that i made <input type="hidden" name="location" value="benelux" />
Or if the active menu is "International" then display pages/posts from the custom taxonomy <input type="hidden" name="location" value="international" />

I found the following code to get the menu category...not sure if this is useful..

(wp_nav_menu( array(
    'menu' => 'benelux'
) )

2: Second peace of code is needed for the search.php (header).
Because if the output should work correctly than we also need to change the menu for this search result page. Default the search.php uses the main menu.

So the following code needs to see if the pages/post contain taxonomy benelux or international and change the menu accordingly.

It would just be really awesome if this is possible.

Greatings,
Taro

Chris Huff on "Update progress bar from database"

$
0
0

I'm so very close to being able to release a free plugin.

Upon uploading media, my plugin automatically transfers audio and video files to an external server (Archive.org). The part that I'm hung up on is the progress bar, showing the progress of transferring the file to Archive.org. But instead of a smoothly growing progress bar, it stays at 0% and then jumps to 100% once it's done.

Relevant code from the plugin:

// Set all the options if they don't exist yet
add_option('aou_accesskey',"");
add_option('aou_secretkey',"");
add_option('aou_progress',"");
update_option('aou_progress','0');

function progressCallback( $download_size, $downloaded_size, $upload_size, $uploaded_size ){
    static $previousProgress = 0;

    if ( $upload_size == 0 )
        $progress = 0;
    else
        $progress = round( $uploaded_size * 100 / $upload_size );

    if ( $progress > $previousProgress){
        $previousProgress = $progress;
        update_option('aou_progress',$progress);
	    }
	}

function aou_upload_file($file) {
	$ias3accesskey = get_option('aou_accesskey',"");
	$ias3secretkey = get_option('aou_secretkey',"");

	$filename = str_replace(' ', '-', $file['name']);
	$file_no_ext = preg_replace('/\\.[^.\\s]{3,4}$/', '', $filename);

	$file_read = fopen($file['tmp_name'], 'r');
	$upload_file_url = 'http://archive.org/download/' . $filename . '/' . $filename;

	$headers = array(
'Authorization: LOW ' . $ias3accesskey . ':' . $ias3secretkey,
'x-amz-auto-make-bucket:1',
'x-archive-meta01-collection:opensource_' . $mediatype,
'x-archive-meta-title:' . $file['name']
);

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_HEADER, true);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($ch, CURLOPT_URL, 'http://s3.us.archive.org/' . $filename . '/' . $filename);
	curl_setopt($ch, CURLOPT_PUT, true);
	curl_setopt($ch, CURLOPT_INFILE, $file_read);
	curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file['tmp_name']));
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_VERBOSE, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_NOPROGRESS, false );
	curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'progressCallback');
	curl_setopt($ch, CURLOPT_BUFFERSIZE, 25);
	curl_exec($ch);
	curl_close($ch);
	fclose($file_read);

    return $file;
    }

add_filter('wp_handle_upload_prefilter','aou_upload_file');

function aou_css_head() {
	global $pagenow;

	if ($pagenow == 'media-new.php'){ ?>
		<style type="text/css">
		#aou_progress {
		  display:block;
		  height:15px;
		  background-color:#ddd;
		  text-align:right;
		  overflow:hidden;
		  font-size:10px;
		  color:#aaa;
		  position:relative;
		  padding-right:3px;
		}
		#aou_progress_bar {
		  position:absolute;
		  top:0;
		  left:0;
		  width:0%;
		  height:15px;
		  background-color:#cdf;
		  padding-right:3px;
	      overflow:hidden;
	    }
	    </style>

	    <script>

		window.setInterval(function(){
			var xhttp = new XMLHttpRequest();
			xhttp.onreadystatechange = function() {
				var progressElement = document.getElementById('aou_progress_bar');
				if (xhttp.readyState == 4 && xhttp.status == 200 && progressElement.innerHTML != '100%') {
					progressElement.style.width = xhttp.responseText + '%';
					progressElement.innerHTML = xhttp.responseText + '%';
					}
				};
			xhttp.open("GET", "http://<?php echo $_SERVER['SERVER_NAME']; ?>/wp-content/plugins/archiveorg-uploads/progress.php", true);
			xhttp.send();
			}, 125);

		</script>
<?php
    	}
    }

add_action('admin_head', 'aou_css_head');

function aou_progress_bar() {
    global $pagenow;
    if ($pagenow == 'media-new.php'){
	    echo '<div id="aou_progress">Archive.org Uploads Progress<div id="aou_progress_bar">0%</div></div>';
		}
	}

add_action('all_admin_notices','aou_progress_bar');`

<strong>progress.php</strong>

<?php
require_once('../../../wp-load.php');
global $wpdb;
echo $wpdb->get_var( "SELECT option_value FROM wp_options WHERE option_name='aou_progress'" );
?>

So, so basically, the callback of the upload updates the aou_progress option in the database, and this option is written via progress.php, which should be checked for changes every 1/8 second, and the progress bar should grow.

But obviously I did something wrong here. I'm wondering if it can't check progress.php for a change while it's transferring the file via curl? If that's true, is there a way to get around it?

searay on "Parent and child pages in permalink"

$
0
0

I want to display child page preview with excerpt on a parent page. The child page will always have the same title, but the parent will be different.

At the moment Im using this code:

$page = get_page_by_title( 'Child Title' );
 $page_excerpt = $page->post_excerpt;
<header class="wpb_wrapper">
    <h4 class="gp-element-title xcpt">
        <a href="<?php echo esc_url( get_permalink( $page ) ); ?>">
            <?php echo $page_data->post_title; ?>
        </a>
    </h4>
</header>
    <div class="gp-entry-content xcpt page-layout"><?php echo $page_excerpt; ?><br/>
        <a href="<?php echo esc_url( get_permalink( $page ) ); ?>">Read More...</a>
    </div>

This code sits in the parent page template and every time I create new parent page the parent link stays the same, but I want it take the slug from the new parent page. So for example now there is http://www.example.com/parent/child and when I create new parent page called "new parent" I want it to be http://www.example.com/new-parent/child.

Also the excerpt doesnt work and I have to manually enter the text into metabox in admin, is there a way to display the excerpt dynamically? Thanks for any help!

marginaali on "Can users add things to posts/pages without going to edit mode?"

$
0
0

I am looking to create a website where user can add themselves as "present" in an event. This would be most practical (without my better knowledge) is a button which when an user presses, Wordpress adds the name of the user to a post/page, without user having to go to the editing mode and add it by hand.

Basically my question boils down to adding stuff to posts without going to editing mode.
Is this possible somehow with code or by a plugin?

Thanks for all the help.

octacian on "Creating a Table with WP_List_Table"

$
0
0

I'm trying to create a plugin that makes managing shortcodes much like managing posts, except (hopefully) much more intuitive. I have almost everything setup: admin page, general hooks (activation...), and a few other things. The issue I'm having, is that I can't figure out how to display the entries from the database as a HTML table like with plugins. I've tried several guides, but can't figure it out.

I also need to design the page for editing or creating new shortcodes, but this, obviously, has to come first.

Aumkar on "Callback for wp.autosave.server.triggerSave();"

$
0
0

I'm using following code to force WordPress page to save post as draft, is there any callback function for it, I want to alert a text after it complete saving post as draft.

if ( wp.autosave.server ) {
wp.autosave.server.triggerSave();
}

quadrochave on "Add filter according Post type"

$
0
0

Hellow !!
I researched a lot here in the forum and did not find a solution
I have a post type called playlist. I wanted to include a filter for customization the media upload window that works only for this post type
I've tried on in the functions.php:

if ('playlists' == get_post_type ()) {
  add_filter( 'media_view_strings', 'custom_media_uploader' );
}

I've tried too:

is_singular ('playlist'))
is_admin() && isset($request['post_type']) && $request['post_type']=='playlists'

The custom post type code :

function playlist_post_type() {

// Set UI labels for Custom Post Type
	$labels = array(
		'name'                => _x( 'Playlists', 'Post Type General Name', 'metanuvem' ),
		'singular_name'       => _x( 'Playlist', 'Post Type Singular Name', 'metanuvem' ),
		'menu_name'           => __( 'Playlists', 'metanuvem' ),
		'parent_item_colon'   => __( 'Parent Playlist', 'metanuvem' ),
		'all_items'           => __( 'Todos Playlists', 'metanuvem' ),
		'view_item'           => __( 'Ver Playlist', 'metanuvem' ),
		'add_new_item'        => __( 'Adicionar Novo Playlist', 'metanuvem' ),
		'add_new'             => __( 'Adicionar novo', 'metanuvem' ),
		'edit_item'           => __( 'Editar Playlist', 'metanuvem' ),
		'update_item'         => __( 'Atualizar Playlist', 'metanuvem' ),
		'search_items'        => __( 'Procurar Playlist', 'metanuvem' ),
		'not_found'           => __( 'Não encontrado', 'metanuvem' ),
		'not_found_in_trash'  => __( 'Não encontrado no lixo', 'metanuvem' ),
	);

// Set other options for Custom Post Type

	$args = array(
		'label'               => __( 'Playlists', 'metanuvem' ),
		'description'         => __( 'Playlist news and reviews', 'metanuvem' ),
		'labels'              => $labels,
		// Features this CPT supports in Post Editor
		'supports'            => array( 'title', 'editor', 'revisions' ),
		// You can associate this CPT with a taxonomy or custom taxonomy.
		'taxonomies'          => array( 'genres' ),

		'hierarchical'        => false,
		'public'              => true,
		'show_ui'             => true,
		'show_in_menu'        => true,
		'show_in_nav_menus'   => true,
		'show_in_admin_bar'   => true,
		'menu_position'       => 5,
		'can_export'          => true,
		'has_archive'         => true,
		'exclude_from_search' => false,
		'publicly_queryable'  => true,
		'capability_type'     => 'page',
	);

	// Registering your Custom Post Type
	register_post_type( 'Playlists', $args );

}

add_action( 'init', 'playlist_post_type', 0 );

Add the filter for custom media window:

function custom_media_uploader( $strings ) {
     //unset( $strings['selected'] );
     unset( $strings['insertMediaTitle'] ); //Insert Media
     unset( $strings['uploadFilesTitle'] ); //Upload Files
     unset( $strings['mediaLibraryTitle'] ); //Media Library
     unset( $strings['createGalleryTitle'] ); //Create Gallery
     unset( $strings['setFeaturedImageTitle'] ); //Set Featured Image
     unset( $strings['insertFromUrlTitle'] ); //Insert from URL  wordpress
     unset( $strings['url'] );
     return $strings;
}

lucile on "How to customize Revisions screen?"

$
0
0

Hi all,

I would like to customize the Revisions screen. For example, I don't want to see the revisions of a post that have been saved before post's publication: I only want the revisions from the publication date.
It's very easy to modify the function 'wp_get_post_revisions' in the file wp-includes\revision.php, and to remove the "draft revisions" from the $revisions list, but I would prefer not to modify WP core files, of course...

Does anyone have an idea on how to customize the 'wp_get_post_revisions' function?

Thanks!

herculesnetwork on "how to add values of a variable with string, within another variable also string"

$
0
0

add values of a variable with string, within another variable that also contains string, but insert in the middle of the text, eg
I have a text with 100 words, and I have another variable also with a string value, say a word, as I put that word in this text, and text in the center. say there position by 49 or 50 or 51 etc ...Thanks :)

pecernet on "associate a category to a post-type"

$
0
0

Hello,

I'd like your help with a question.

I use wordpress is I have several category

I wonder if it is possible to determined a category to a "post-type" specific?

Example

the category

Sports in a post-type Sport

I ask this because I have a post plugins that filter types -> Articles and page.

I would like the added post-type Sport

Articles
Page
Sport

Thanks

drned on "External Authentication of Users"

$
0
0

I have two questions. I am trying to authenticate WordPress users against an external database.
When I am able to authenticate against the external database, I cannot access the admin users. I would like to use WordPress login authentication for admins but external logins for members.
Also when I successfully authenticate against the external database, must I always create a specific user in Wordpress? Is it possible to create a generic user for all authenticated members?

nkpryor on "Classified Ads Website - Need code that'll prevent posts with "bad words""

$
0
0

So I use the "PreimumPress" Classifieds Blue child theme, and the code I have below will check if there is a “bad word” entered into the Keywords input/field and alerts the user about it once they click on the Save Listing button. The problem though is that it ONLY alerts the user when there is just ONE of the specified “bad words” in that field. It won’t trigger the alert when the “bad word” is found within a whole sentence. So I need help with two things…

– Can anyone help me tweak this code so that it will trigger the alert when the “bad word” is found ANYWHERE within that field, even if there are other words.
– Can anyone help me have this “alert” happen when the specified “bad words” are in ANY field, not just the “keywords” field.

*For reference, my website is http://www.lakomai.com

THANKS!!

<script>
jQuery(function() {
jQuery("#MainSaveBtn").on("click",function() {
    var name = jQuery("input:text[name='custom[post_tags]']").val();
        var badwords = ["word1", "word2", "bad word3"];

        if(jQuery.inArray(name, badwords) !==-1)
            {
                alert("Your Listing Contains Bad Words, Please Remove Them Before Proceeding");
                return false;
            }
});
});
</script>

jonrolph on "Placing a Form in the Password protect page"

$
0
0

Hi all,

My apologies if this is in the wrong place, or has already been covered. I did a quick search and couldn't find anything that matched my query.

I am looking to modify the default text of our site's "Password Protection page", and I know it's possible thanks to this FAQ, but my query is a little more specific. I would like to place a Form I have specially created into the page, to act as a kind of form-gate for us. Essentially a visitor will be required to fill in the form, and I can then forward them the password to progress further into the site.

For starters, is this even possible? And secondly, assuming it is possible, does anybody know if the confirmation will show properly, or will it freak out slightly due to the nature of the Password Protection page.

Many thanks for your responses in advance!


Ethan Jinks O'Sullivan on "How do I find images with no dimensions set?"

$
0
0

Backstory
Using the WordPress the_content tag, I am running a custom function to search for all images that do not have a width and height attribute set and insert the proper dimensions. Below is the function:

add_filter( 'the_content', 'add_img_dimensions' );

function add_img_dimensions( $image_no_dimensions ) { // Insert width & height to images missing dimensions
    if ( preg_match_all( '/<img [^>]+>/i', $image_no_dimensions, $result ) ) {
        // print_r( $result ); // DEBUG: print all images that don't have a dimension

        preg_match_all( '/(alt|title|src)=("[^"]*")/i', $image_no_dimensions, $img );
        list( $width, $height, $type, $attr ) = getimagesize( str_replace( "\"", "" , ( $img[2][0] ) ) );
        $imgname = str_replace( "\"", "" , ( $img[2][0] ) );
    }

    return sprintf( '<img src="%s" width="%dpx" height="%dpx" />', str_replace("\"", "" , ( $img[2][0] ) ), $width, $height );
}

For example, if there is an image on one of my pages that looks like the following:

<img src="https://link.to/sum/img.jpg" alt="Image Title" />

It will then insert the width and height of the actual image:

<img width="150" height="50" src="https://link.to/sum/img.jpg" alt="Image Title" />

This functions works as expected. However, the images that already have a width and height set disappear on the page for some reason. As you can see on line three of my code, I've added an if statement to run the function only to images with no dimensions set:

if ( preg_match_all( '/<img [^>]+>/i', $image_no_dimensions, $result ) )

Except I am having trouble figuring out the regular expression (regex) to use to have preg_match_all identify only images with no dimensions set.

Objective
What is the regex that I would need to use to identify images with no dimensions in my if statement? If there is a better way to identify it, please provide me your input.

Thanks.

dooge8 on "Connections plug-in with custom alphabetical pagination"

$
0
0

Hello.

I am using the Connection plug-in to import an excel file with 100's of entires for display on a website. While the plug-in is working properly, alphabetical pagination would make it easier for visitors to find an entry.

I know Connections offers premium templates that have pagination but I'd rather not pay for the integration since Connection supports it natively (if you know how to code).

I have the Connections plug-in on a page called with shortcode. All I need to do now is somehow place a paginated filter or even a show-hide when selecting letters at the top of that page that will sort them properly.

Thank you in advance.

cfurrow on "sidebar only on certain archive pages"

$
0
0

Hello!
I'm trying to add a sidebar to my archive pages, but only the archive pages for my custom post type 'teachings', and for the custom taxonomy pages that are correlated with that post type. I want to leave all the other pages and archives where a sidebar could go untouched, but I'm having a lot of difficulty.

The best solution I could come up with was downloading a plugin that allows you to add sidebars to pages by shortcode (the one I ended up using is Stag Custom Sidebars), then adding that to the archive pages using my child theme's functions.php file. So, I entered this:

add_action( 'pre_get_posts', 'filter_sidebar' );
function filter_sidebar(){
	if( is_post_type_archive('teachings') ) {
		echo do_shortcode( '[stag_sidebar id='filter']' );
	}
}

but every time i apply this it breaks my site. I can't figure out what I'm doing wrong...

The reason I want to use my child theme's functions.php is to avoid problems with updates to my theme in the future.

Maybe there's a better way to go about this. Any suggestions would be greatly appreciated.
Thank you so much for taking the time to read my question, and thank you in advance for your help!

theamountof on "Can't get jquery to work"

$
0
0

I am relatively new to getting using jquery, but a client wanted something where when you hover over a child div, the parent divs background would change. A rudimentary version of what I came up with for a solution can be found here jsfiddle.

But when I took the code and tried adding it to my site, it just will not work. I am not sure if I am missing something very simple, or something is way wrong with the code I was using. I have tried adding the script in the header, and also adding it as an external js file.

The site in question can be found here with the section "Explore" where the code is being used - http://www.aoftheibuild.com.php56-9.dfw3-2.websitetestlink.com/

dakrw1nd on "How to customize default wordpress search query"

$
0
0

Hello everyone!

I want to customize default search query in wordpress

I want search default data in another database.

Now I have 2 databases , one for wordpress and another base with copy of wp_posts content.

I want to change search query to secondary database.

How to do it via function?

Viewing all 8245 articles
Browse latest View live


Latest Images