Forum Replies Created

Viewing 15 replies - 1 through 15 (of 62 total)
  • Anyone?

    get_option is part of the WordPress API, it retrieves saved “options” (the things you get in settings for example) from the WP DB (if they exist).

    The one I have set up there for example retrieves the letter A.

    I previously had ‘From: LoadPress <email@example.com>’ . “\r\n” which worked fine, but the client wants to have it so they can change it at will using the editor I have built.

    The problem is (I think (wild stab in the dark really)) that it doesn’t have any of the correct formatting (probably wrong).

    So, I’m not sure at all what is wrong really (oh if I had a penny…).

    Thanks for this.

    Can I access these variables from outside that specific page or not? can’t seem to find any info on the dev docs.

    This didn’t really help me much, I have set everything up but “Members” seems to be:
    A) Displaying my capability names incorrectly, and possibly gathering them incorrectly.
    B) Not giving access to the post type after ticking all boxes in my custom post type section of Members

    yeah i was wondering if the variables were passing to the form, but sweet glad u got it working.

    I got the wording working, the main issue I am having is that the button doesn’t trigger the event, which I need it to.

    The main issue for me is that somewhere:
    1) The button isn’t triggering the AJAX
    2) The JQuery isn’t getting the email value
    3) The JQuery isn’t able to change the iFrame source
    4) The iFrame isn’t working

    I think one of these is causing the button clicking to not work, but no errors are thrown, and there is no email sent, unless I force it to send by manually calling the URL (which users won’t do as it would take too long and they don’t have access to info such as the post ID).

    The button was the main issue I was having, the wording not appearing and attachment was secondary.

    The emails are still not sending by clicking the button and that is the bit I need to get working.

    Horray for small victories…
    I have solved the attachment and wording problem by passing the post ID through the URL as a query string.

    The only thing left to work out is why the button doesn’t seem to get the input value and call it.

    /*		AJAX		*/
    
    add_action('wp_ajax_download_email_send','download_email_send');
    add_action('wp_ajax_nopriv_download_email_send','download_email_send');
    
    // note $_REQUEST will work with $_POST or $_GET methods
    function download_email_send() {
    
        $to = $_REQUEST['emailValue'];
    
        // preferably add some email address format validation here
        // $validate = some_email_validate_function($to);
        // if ($validated) {$message = 'Please check your email for typos.';}
        // else {
            $post_id = $_REQUEST['postID'];
    
    	$page = get_post($post_id);
    	$postName = $page->post_title;
    
            // ! you would need to redefine $intro here !
    	$intro = get_post_meta($post_id, $key = 'podcast_file', true);
    	$path = str_replace("http://com.areonline.co.uk/wp-content","",$intro);
            $subject = 'Download for '.$postName;
            $msg = 'Your download for '.$postName.' ('.basename($intro).') is attached to this email.';
            $headers = 'From: Free The Blobs <noreply@freetheblobs.com>' . "\r\n";
            $mail_attachment = array(WP_CONTENT_DIR . $path);
            $send = wp_mail($to, $subject, $msg, $headers, $mail_attachment);
    
            if ($send) {$message = 'Success! Your download has been sent to your email address.';}
            else {$message = 'Error: Mail sending failed. Please contact the website administrator using the contact page.';}
        // }
    
        // alert the user to the result
        echo "<script>alert('".$message."');</script>";
        exit;

    Oh, you got that from the initial post…
    I didn’t put that in there, that was wp.org’s code tag thing.

    My code is as below:

    /*		Shortcode		*/
    
    function file_download(){
    
    	ob_start();
    		?>
    		<style>
    			.downloadHolder {
        				background: #181D25;
        				box-shadow: inset 0 0 42px 0 rgba(100,100,100,0.1);
        				margin: 0 0 2.5rem 0;
        				padding: 20px 40px;
        				text-shadow: 0 1px 1px #000000;
        				text-align: center;
    			}
    			.downloadBtn {
        				background-color: #005dac;
        				background-image: -webkit-linear-gradient(top,#0077b3,#0036a3 100%);
        				background-image: linear-gradient(to bottom,#0077b3,#0036a3 100%);
        				color: #fff;
        				text-decoration: none;
        				border-radius: 3px;
        				border: 1px solid;
        				box-shadow: inset 0 1px 0 rgba(255,255,255,0.22),0 1px 2px rgba(0,0,0,0.05);
        				text-shadow: 0 1px 0 rgba(0,0,0,0.5);
        				padding: .5rem 1rem;
        				font-size: 1.125rem;
    				border-color: #002a80 #002a80 #013013;
    			}
    				.downloadBtn:hover {
        					background-color: #006dcc;
        					background-image: -webkit-linear-gradient(top,#08c,#04c 100%);
        					background-image: linear-gradient(to bottom,#08c,#04c 100%);
        					border-color: #0036a3 #0036a3 #026;
    				}
    			.demoBtn {
        				background-color: #fafafa;
    	    			background-image: -webkit-linear-gradient(top,#fefefe,#f4f4f4 100%);
    				background-image: linear-gradient(to bottom,#fefefe,#f4f4f4 100%);
        				color: #333;
        				text-decoration: none;
        				border-radius: 3px;
        				border: 1px solid;
        				box-shadow: inset 0 1px 0 rgba(255,255,255,0.22),0 1px 2px rgba(0,0,0,0.05);
        				text-shadow: 0 1px 0 rgba(255,255,255,0.5);
        				padding: .5rem 1rem;
        				font-size: 1.125rem;
    				border-color: #e0e0e0 #e0e0e0 #c1c1c1;
    			}
    				.demoBtn:hover {
        					background-color: #ffffff;
        					background-image: -webkit-linear-gradient(top,#F3F3F3, #E1E1E1 100%);
        					background-image: linear-gradient(to bottom,#F3F3F3, #E1E1E1 100%);
        					border-color: #F3F3F3 #F3F3F3 #E1E1E1;
    				}
    			.emailInput	{
    				width: 100%;
    				height: 40px;
    				border-radius: 0px !important;
    				border: 0px solid #000 !important;
    				margin-top: 14px !important;
    				margin-bottom: 8px !important;
    				background-color: #eeeeee !important;
    				font-size: 18px;
    				color: #999999 !important;
    			}
    		</style>
    <?php
    global $intro;
    global $path;
    global $post;
    $intro = get_post_meta($post -> ID, $key = 'podcast_file', true);
    $path = str_replace("http://com.areonline.co.uk/wp-content","",$intro);
    ?>
    		<div class="downloadHolder">
    			<h3>Download <?php echo $post->post_title ?> (<?php echo basename($intro, ".ftb") ?>)</h3>
    			<p style="margin-bottom: 20px;">Please note: FTB files can only be used if you have Free The Blobs (Full Version) on Android or iOS.</p>
      			<a href="<?php echo $intro;?>" download="<?php echo basename($intro) ?>" class="demoBtn">Download <?php echo basename($intro, ".ftb") ?> for PC</a>
      			<!--<a href="#" class="demoBtn">Demo</a>--><br>
    			<input type="text" name="emailValue" id="emailValue" placeholder="Email Address" class="emailInput" style="text-align: center;">
    			<button  onclick="javascript:emailsend();" class="downloadBtn" style="margin-top: 0px; width: 100%;">Email for Mobile</button>
    			<span>(We do NOT collect email addresses.)</span>
    			<script>
    				function emailsend() {
    		    			$email = document.getElementById('emailValue').value;
        					$downloadurl = '<?php admin_url('admin-ajax.php');?>?action=download_email_send&postId=<?php echo $post->ID; ?>&emailValue='+$email;
        					document.getElementById('emailsendframe').src = $downloadurl;
    				}
    			</script>
    <!-- iframe for submitting to -->
    <iframe name="emailsendframe" id="emailsendframe" src="javascript:void(0);" style="display:none;"></iframe>
    		</div>
    	<?php
    return ob_get_clean();
    }
    add_shortcode('level', 'file_download');
    
    /*		AJAX		*/
    
    add_action('wp_ajax_download_email_send','download_email_send');
    add_action('wp_ajax_nopriv_download_email_send','download_email_send');
    
    // note $_REQUEST will work with $_POST or $_GET methods
    function download_email_send() {
    	$intro = get_post_meta($post -> ID, $key = 'podcast_file', true);
        $to = $_REQUEST['emailValue'];
    
        // preferably add some email address format validation here
        // $validate = some_email_validate_function($to);
        // if ($validated) {$message = 'Please check your email for typos.';}
        // else {
            $post_id = $_REQUEST['postID'];
    
            // ! you would need to redefine $intro here !
            $subject = 'Download for'.basename($intro);
            $msg = 'Your download for '.basename($intro).' is attached to this email.';
            $headers = 'From: Free The Blobs <noreply@freetheblobs.com>' . "\r\n";
            $mail_attachment = array(WP_CONTENT_DIR . $path);
            $send = wp_mail($to, $subject, $msg, $headers, $mail_attachment);
    
            if ($send) {$message = 'Success! Check you email address.';}
            else {$message = 'Error: Mail sending failed.';}
        // }
    
        // alert the user to the result
        echo "<script>alert('".$message."');</script>";
        exit;
    }

    Update: removing that line removes the action required for calling that URL, so that would remove the ability to even access the AJAX function to send emails.

    Hmm, I haven’t been getting any errors on it.

    I did remove it though and it doesn’t seem to make the slightest bit of difference 🙁

    Any ideas as to what might be wrong?

    I have found that if I set the iframe’s src to the email URL (hardcode it), the email sends when the page loads, but again, no custom text, no attachment 🙁

    Both redefining and setting them as global didn’t seem to do anything to rectify the situation.

    I am fairly certain that all the problems I have stem from not being able to trigger the AJAX from the button (so getting any information currently on that page doesn’t work as I have to call the function manually through a URL).

    At the moment, my email send button:
    <button onclick="emailsend();" class="downloadBtn" style="margin-top: 0px; width: 100%;">Email for Mobile</button>

    Doesn’t do anything when clicked apart from make the page reload, nothing sends and nothing is in the console.

    I think my issues are that as I have to call the function from a URL outside of that page to get it to send an email, it no longer has access to any of the stuff it is trying to get, such as $intro and all the others.

    I am not sure what is wrong with it, I’m a C# developer but am trying to move into a little PHP but do far I absolutely hate it (not the point).

    Can anyone tell me what I have done wrong to prevent the button from actually sending the email?

    I don’t get any errors at all unfortunately.

    I don’t know how I would get $intro in there, would I just redefine it the same way I did before, but in the AJAX code?

    Ah, that worked.
    Thank you very much for this, been bugging me for the last day and a bit.

    I changed it slightly to allow for in-line text, and changed this to the table name, but it is registering it as “offline” constantly.

    I know it exists as I am looking at it in MySql at the moment.

    global $wpdb;
    	$table_name = $wpdb->prefix.'ftbstatistics';
    	if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
         		echo "<h3>Database Status: <span style='color: green;'>Online</span></h3>";
    	}
    	else{
    		echo "<h3>Database Status: <span style='color: red;'>Offline</span></h3>";
    	}

    I tried to wrap the wpdb update call in an if statement, but it doesn’t work, it just returns false.

    From what I can see, this should call the update function and if there is nothing to update, it will add it, but if I add the same values twice, I just get a new entry, and not an increment to the “count”.

    function stat_submit_function($atts, $content = null) {
    
    	global $wp_query;
    if (isset($wp_query->query_vars['level']))
    {
    if (isset($wp_query->query_vars['moves']))
    {
    if ($wp_query->query_vars['validate'] === "TH19wJxhjezyIr83KMMnW510Um4D74S0")
    {
    /*require_once('../../../wp-load.php');*/
    global $wpdb;
    $table_name = $wpdb->prefix . "ftbstatistics";
    $level = $wp_query->query_vars['level'];
    $moves = $wp_query->query_vars['moves'];
    
    if($wpdb->update($table_name, array('level' => $level,'moves' => $moves,'count' => '1')) === false)
    {
    $wpdb->insert($table_name, array('level' => $level,'moves' => $moves,'count' => '1'));
    }
    echo "Successful Connection - Your Stats Have Been Saved!";
    echo "<br/>";
    echo "Level=" . $wp_query->query_vars['level'] . " - " . "Moves=" . $wp_query->query_vars['moves'];
    }
    }
    }
    }
Viewing 15 replies - 1 through 15 (of 62 total)