Why wp_enqueue_script() not work in my plugin? - plugins

function user_enqueue_script() {
global $pluginsURI;
wp_enqueue_script('jquery');
wp_register_script( 'modernizr-script', $pluginsURI.'js/modernizr.custom.js', array( 'jquery' ) );
wp_enqueue_script( 'modernizr-script' );
}
add_action( 'wp_enqueue_scripts', 'user_enqueue_script' );

Try
plugins_url() . '/' . 'your_pluhin_folder'
Instead of your global $pluginsURI;
Thats the only thing I see that could go wrong there.

Related

Insert post from other site using wp_insert_post

I created a cron that will insert posts from the other site using the rest route and wp_insert_post. On the first cron run, the posts were inserted but when I added a new post from the source site and run the cron again, the new post is not added. I'm not sure what I'm doing wrong. If you could help me with this I would really appreciate it. Please see my code below.
add_action('create_posts_cron', function(){
$post_data = wp_remote_get( ' ' ); // inserted the rest route inside ''
$post_data_decode = json_decode( $post_data['body'] );
foreach ( $post_data_decode as $item ) {
$post_title = $item->title;
$customfield = $item->customfield;
$post_arr = array(
'post_title' => $post_title,
'post_status' => 'publish',
'post_type' => 'custompost',
);
if( !get_page_by_title( $post_title, OBJECT, 'custompost' ) ) {
$post_id = wp_insert_post( $post_arr );
update_field( 'customfield', $customfield, $post_id );
}
}
});

Integrating Gravity Forms with a 3rd Party (Eloqua)

I wondering if you guys could help. I am trying to integrate Gravity forms with Eloqua CRM. I've tried both '3rd Party Integration' plugin and I have also tried adding the gf after submission function in my functions.php file. However, I have not been able to get this to work. My code is below. I entered the url of my form in 'eloqua' (https://s1913652004.t.eloqua.com/e/f2) There is also a form id, but I don't see anywhere to put that.
add_action( 'gform_after_submission_1', 'post_to_third_party', 10, 2 ); function post_to_third_party( $entry, $form ) {
$post_url = 'https://s1913652004.t.eloqua.com/e/f2';
$body = array(
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar( $entry, '1.6' ),
'email' => rgar( $entry, '2' ),
'country' => rgar( $entry, '3' ),
);
GFCommon::log_debug( 'gform_after_submission_1: body => ' . print_r( $body, true ) );
$request = new WP_Http();`enter code here`
$response = $request->post( $post_url, array( 'body' => $body ) );
GFCommon::log_debug( 'gform_after_submission_1: response => ' . print_r( $response, true ) );
Use the Gravity Forms Eloqua Add-On. It's actively maintained.

Zend_Cache_Core showing when I am trying to create cache file in view file

I am trying to cache a view file content and I am using the following method inside a view file,
$frontendOptions = array(
'lifetime' => 3600,
'automatic_serialization' => false
);
$backendOptions = array(
'cache_dir' => '../cache'
);
$cache = Zend_Cache::factory(
'Core',
'File',
$frontendOptions,
$backendOptions
);
$cache->save('somebody', 'fileName', array('tag1', tag2));
it is not creating cache file and it is showing the error, the same is working fine in controller.
Any help will be appreciated.
Thanks,
Suresh
Replace
$cache->save('somebody', 'fileName', array('tag1', tag2));
by
$cache->save('somebody', 'fileName', array('tag1', 'tag2'));
and
'cache_dir' => '../cache'
by
'cache_dir' => APPLICATION_PATH . '/../caches'
with the cache directory at the same level as the application directory
K. V. Suresh you have to send the the Cache Object created by $cache->load(key) to your view's controller in order to access it there.
From your controller:
$data = $cache->load('somebody');
$this->view->cached_data = $data;
From view:
Zend_Debug::dump($this->cache_data);

I can't get htmlpurifier to allow anchors (a tag with name attribute)

I really can't get htmlpurifier to allow name attributes on a tags. I want to allow tinyMCE to function with anchors. I suppose the name attribute is deprecated an id should be used, but tinyMCE produces name attributes. Is there somehow I can either transform them into id="" or accept them?
Following the docs I try this but it doesn't work
require_once( 'HTMLPurifier.standalone.php' );
$config = HTMLPurifier_Config::createDefault();
$config->set( 'HTML.Doctype' , 'XHTML 1.0 Transitional' );
$config->set( 'Cache.DefinitionImpl', null ); // remove this later!
$config->set( 'Core.CollectErrors' , true );
$def = $config->getHTMLDefinition( true );
$def->addAttribute( 'a', 'name' , 'ID' );
// $def->addAttribute( 'a', 'name' , 'CDATA' ); // does not work either
// $def->addAttribute( 'a', 'name' , 'Text' ); // does not work either
$purifier = new HTMLPurifier( $config );
$purifier->purify( '<a name="test"></a>' );
echo $purifier->context->get( 'ErrorCollector' )->getHTMLFormatted( $config );
// output:
// Error Line 1, Column 0: name attribute on <a> removed
http://htmlpurifier.org/docs/enduser-id.html
(Oh, and remove the custom HTML definition and declarations.)

Zend cookie issue

I'm working on a Zend 1.11 webapp. I built a language-selector plugin for switching language (it & en) depending on the user input.
This is what I have:
class LS_Controller_Plugin_LangSelector extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if($request->getParam('lang'))
{
$lang=$request->getParam('lang');
setcookie('lang', $lang, time() + (3600));
echo "we just set a cookie";
}
else if (isset($_COOKIE['lang']))
{
$lang=$_COOKIE['lang'];
echo $lang;
}
else
{ echo 'We are here.But I can't understand why';
$lang='en';
var_dump($_COOKIE);
}
switch(strtolower($lang))
{
case 'en':
$locale="en_US";
break;
case 'it':
$locale="it_IT";
break;
default:
$locale="en_US";
}
$zl=new Zend_Locale();
$zl->setLocale($locale);
Zend_Registry::set('Zend_Locale',$zl);
$translate=new Zend_Translate(
array(
'adapter' => 'gettext',
'content' => APPLICATION_PATH.'/configs/languages/'.$locale.'.mo',
'locale' => 'en'
)
);
Zend_Registry::set('Zend_Translate',$translate);
}
}
[bootstrap.php]
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initRoutes()
{
$frontController=Zend_Controller_Front::getInstance();
$router=$frontController->getRouter();
$router->removeDefaultRoutes();
$router->setGlobalParam('lang','en');
$router->addRoute(
'lang',
new Zend_Controller_Router_Route('/:lang/:controller/:action',
array('lang'=>':lang',
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
$router->addRoute(
'langController',
new Zend_Controller_Router_Route('/:controller/:action',
array(
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
$router->addRoute(
'langIndex',
new Zend_Controller_Router_Route('/:lang',
array('lang'=>':lang',
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
$router->addRoute(
'langNothing',
new Zend_Controller_Router_Route('',
array('lang'=>'en',
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
}
}
The point is that:
I type in my browser the full URL mysite.com/it/index/index and I get echo out "we just set a cookie"..wich is fine I should be able to browse my website with the italian cookie set but I don't. Whenever I click over a link (Ex. /index/contactus..links do not specify the 'lang' parameter!) I navigate to that page but it's in english again (I get echoed out the message:"we are here.but I can't understand why").
Shouldn't the cookie be set?
The problem is, that you don't specify the path for your cookie. So it will set for the current page only.
If you browse to another (sub)site, then your cookie is not valid for this path and doesnt get transmitted. You should set your lang-cookie to the "/" Path.
See setcookie() documentation:
The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.